The Open Framework for Building Agents
fix(eve): give mockModel responders AI SDK v4 prompts (#4438)
Andrew Barbae3c509fb6e17
diff --git a/.changeset/mock-model-tool-result-files.md b/.changeset/mock-model-tool-result-files.mdnew file mode 100644index 000000000..af2c1e9db--- /dev/null+++ b/.changeset/mock-model-tool-result-files.md@@ -0,0 +1,5 @@+---+"eve": patch+---++`mockModel` responders see tool-result files again as `{ type: "file", data: { type: "data", data } }` parts in `toolResults[].output`. Since `[email protected]`, they had received legacy `file-data` parts, so a scripted model that looked for an image from `toModelOutput` could miss it and keep calling the tool.diff --git a/e2e/fixtures/agent-tools-hitl/agent/lib/continuation/model.ts b/e2e/fixtures/agent-tools-hitl/agent/lib/continuation/model.tsindex 1cae9d182..7f8e3ae49 100644--- a/e2e/fixtures/agent-tools-hitl/agent/lib/continuation/model.ts+++ b/e2e/fixtures/agent-tools-hitl/agent/lib/continuation/model.ts@@ -3,8 +3,8 @@ import { respond } from "./respond.ts";export function continuationModel() {const model = mockModel({ modelId: "hitl-continuation", respond });- if (typeof model === "string" || model.specificationVersion !== "v3") {- throw new Error("This fixture expects mockModel's v3 provider boundary.");+ if (typeof model === "string" || model.specificationVersion !== "v4") {+ throw new Error("This fixture expects mockModel's v4 provider boundary.");}const generate = model.doGenerate.bind(model);model.doGenerate = async (options) => {diff --git a/packages/eve/src/evals/mock-model.test.ts b/packages/eve/src/evals/mock-model.test.tsindex 4f289fa9b..cfe213b3c 100644--- a/packages/eve/src/evals/mock-model.test.ts+++ b/packages/eve/src/evals/mock-model.test.ts@@ -149,6 +149,43 @@ describe("mockModel", () => {]);});+ it("gives responders tool-result files in the tagged file shape", async () => {+ const png = Buffer.from("\x89PNG\r\n\x1a\n", "latin1").toString("base64");+ const requests: MockModelRequest[] = [];+ const model = mockModel((request) => {+ requests.push(request);+ return request.toolResults.length === 0 ? { toolCalls: [{ name: "screenshot" }] } : "Seen.";+ });++ await generateText({+ model,+ prompt: "Take a screenshot.",+ stopWhen: stepCountIs(2),+ tools: {+ screenshot: tool({+ execute: async () => ({ png }),+ inputSchema: jsonSchema({ type: "object" }),+ toModelOutput: ({ output }) => ({+ type: "content",+ value: [+ { text: "Screenshot:", type: "text" },+ { data: { data: output.png, type: "data" }, mediaType: "image/png", type: "file" },+ ],+ }),+ }),+ },+ });++ expect(requests[1]!.toolResults[0]!.output).toEqual([+ { text: "Screenshot:", type: "text" },+ expect.objectContaining({+ data: { data: png, type: "data" },+ mediaType: "image/png",+ type: "file",+ }),+ ]);+ });+it("rejects empty advanced responses", async () => {await expect(generateText({diff --git a/packages/eve/src/evals/mock-model.ts b/packages/eve/src/evals/mock-model.tsindex 5d2e14f44..8b4601fa2 100644--- a/packages/eve/src/evals/mock-model.ts+++ b/packages/eve/src/evals/mock-model.ts@@ -1,13 +1,15 @@import type { LanguageModel } from "ai";-import { MockLanguageModelV3 } from "ai/test";+import { MockLanguageModelV4 } from "ai/test";import { markMockModel } from "#internal/mock-model-identity.js";import { TASK_RESULT_TAG, TASKS_NOTE_LABEL } from "#execution/tasks/render.js";import { isPendingApprovalsSnippet } from "#harness/hitl/approval-prompt.js";-type GenerateOptions = Parameters<MockLanguageModelV3["doGenerate"]>[0];-type GenerateResult = Awaited<ReturnType<MockLanguageModelV3["doGenerate"]>>;-type StreamResult = Awaited<ReturnType<MockLanguageModelV3["doStream"]>>;+// A V4 model receives the prompt as the AI SDK builds it; a V3 model gets a+// downgraded copy where tool-result files become legacy `file-data` parts.+type GenerateOptions = Parameters<MockLanguageModelV4["doGenerate"]>[0];+type GenerateResult = Awaited<ReturnType<MockLanguageModelV4["doGenerate"]>>;+type StreamResult = Awaited<ReturnType<MockLanguageModelV4["doStream"]>>;type StreamPart = StreamResult["stream"] extends ReadableStream<infer Part> ? Part : never;type PromptPart = Exclude<GenerateOptions["prompt"][number]["content"], string>[number];type ToolResultOutput = Extract<PromptPart, { type: "tool-result" }>["output"];@@ -127,7 +129,7 @@ export function mockModel(const modelId = options.modelId ?? DEFAULT_MODEL_ID;return markMockModel(- new MockLanguageModelV3({+ new MockLanguageModelV4({modelId,provider: options.provider ?? DEFAULT_PROVIDER,doGenerate: async (callOptions) =>