char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Sominitial commite6df845

main
1.9 KiB53 linesraw
1// A model for working on berry itself without spending tokens.
2
3import type { MutableModels } from "@earendil-works/pi-ai";
4import {
5  fauxAssistantMessage,
6  type FauxResponseFactory,
7  fauxText,
8  fauxThinking,
9  fauxToolCall,
10} from "@earendil-works/pi-ai/providers/faux";
11import { fauxProvider } from "@earendil-works/pi-ai/providers/faux";
12
13/**
14 * `dev/echo` echoes, thinks a little, and runs a message of the form `js <code>` as a codemode script. Its thinking
15 * about a message of the form `quiet <text>` is empty, as encrypted reasoning is.
16 */
17export function installDevModel(models: MutableModels) {
18  const faux = fauxProvider({
19    provider: "dev",
20    models: [{ id: "echo", name: "dev echo", reasoning: true }],
21    tokensPerSecond: 80,
22  });
23  const respond: FauxResponseFactory = (context) => {
24    faux.appendResponses([respond]);
25    // a section patch may follow the message being answered
26    const last = context.messages.findLast((message) => message.role !== "system");
27    if (last?.role === "toolResult") {
28      return fauxAssistantMessage(
29        `The script ${last.isError ? "failed" : "finished"}; its output is above.`,
30      );
31    }
32    const text = last?.role !== "user"
33      ? ""
34      : typeof last.content === "string"
35      ? last.content
36      : last.content.flatMap((block) => (block.type === "text" ? [block.text] : [])).join("\n");
37    if (text.startsWith("js ")) {
38      return fauxAssistantMessage(
39        [
40          fauxThinking("Running that in codemode."),
41          fauxToolCall("codemode", { code: text.slice(3) }),
42        ],
43        { stopReason: "toolUse" },
44      );
45    }
46    return fauxAssistantMessage([
47      fauxThinking(text.startsWith("quiet ") ? "" : `They wrote ${text.length} characters.`),
48      fauxText(`You said:\n\n> ${text}\n\nTry \`js return await tools.bash({ command: "ls" })\`.`),
49    ]);
50  };
51  faux.setResponses([respond]);
52  models.setProvider(faux.provider);
53}