import { defineExtension } from "@berry/api"; import { contextCapCommand, registerContextCap } from "./context-cap.ts"; export type State = { oaiFast: boolean }; export type Event = { type: "oai-fast"; enabled: boolean }; export default defineExtension({ name: "misc", description: "miscellaneous utilities", alwaysOn: true, initial: () => ({ oaiFast: false }), apply: (_, event) => ({ oaiFast: event.enabled }), setup(ext) { registerContextCap(ext); return (conv) => { conv.command(contextCapCommand()); conv.command({ name: "compact", description: "compact this conversation's context: `/compact [instructions]`", async execute(args, ctx) { const instructions = args.trim(); await ctx.compact(instructions === "" ? undefined : instructions); return "Compacting context\u2026"; }, }); conv.command({ name: "oai-fast", description: "toggle or set OpenAI Codex priority processing", async execute(args, ctx) { const mode = args.trim(); if (mode !== "" && mode !== "on" && mode !== "off") { return "Usage: /oai-fast [on|off]"; } const enabled = mode === "" ? !ctx.state.oaiFast : mode === "on"; await ctx.emit({ type: "oai-fast", enabled }); return `OpenAI Codex fast mode ${enabled ? "enabled" : "disabled"}.`; }, }); conv.onPayload((payload, model) => { if ( !conv.state.oaiFast || model.provider !== "openai-codex" || typeof payload !== "object" || payload === null || Array.isArray(payload) ) { return; } // The Codex backend maps the legacy priority tier to Fast mode. return { ...payload, service_tier: "priority" }; }); }; }, });