/** @file The model, asked in code mode, writes code that drives the mower. */ import { env } from "cloudflare:workers"; import { expect, test } from "vitest"; import { codeModeMessages, extractCode } from "../src/code-mode.ts"; import { makeWorkersAiModel, MODEL } from "../src/model.ts"; import { aboutMower } from "../src/mower.ts"; test("lent a mower, the neighbor writes code to mow", async () => { const model = makeWorkersAiModel(env.AI, MODEL); const messages = codeModeMessages({ say: "you can use this mower for the weekend", about: { mower: aboutMower }, }); const code = extractCode(await model.complete(messages)); console.log(code); const calls = [...code.matchAll(/env\.mower\.(\w+)\(/g)].map(([, method]) => method); expect(calls).toContain("push"); for (const method of calls) expect(["start", "push", "turn", "stop"]).toContain(method); });