char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somadd a /compact command to misc2c01ad9

main
1.8 KiB55 linesraw
1import { defineExtension } from "@berry/api";
2import { contextCapCommand, registerContextCap } from "./context-cap.ts";
3
4export type State = { oaiFast: boolean };
5export type Event = { type: "oai-fast"; enabled: boolean };
6
7export default defineExtension<State, Event>({
8  name: "misc",
9  description: "miscellaneous utilities",
10  alwaysOn: true,
11  initial: () => ({ oaiFast: false }),
12  apply: (_, event) => ({ oaiFast: event.enabled }),
13  setup(ext) {
14    registerContextCap(ext);
15    return (conv) => {
16      conv.command(contextCapCommand());
17      conv.command({
18        name: "compact",
19        description: "compact this conversation's context: `/compact [instructions]`",
20        async execute(args, ctx) {
21          const instructions = args.trim();
22          await ctx.compact(instructions === "" ? undefined : instructions);
23          return "Compacting context\u2026";
24        },
25      });
26      conv.command({
27        name: "oai-fast",
28        description: "toggle or set OpenAI Codex priority processing",
29        async execute(args, ctx) {
30          const mode = args.trim();
31          if (mode !== "" && mode !== "on" && mode !== "off") {
32            return "Usage: /oai-fast [on|off]";
33          }
34          const enabled = mode === "" ? !ctx.state.oaiFast : mode === "on";
35          await ctx.emit({ type: "oai-fast", enabled });
36          return `OpenAI Codex fast mode ${enabled ? "enabled" : "disabled"}.`;
37        },
38      });
39      conv.onPayload((payload, model) => {
40        if (
41          !conv.state.oaiFast ||
42          model.provider !== "openai-codex" ||
43          typeof payload !== "object" ||
44          payload === null ||
45          Array.isArray(payload)
46        ) {
47          return;
48        }
49
50        // The Codex backend maps the legacy priority tier to Fast mode.
51        return { ...payload, service_tier: "priority" };
52      });
53    };
54  },
55});