The Open Framework for Building Agents
feat(eve): let toModelOutput return file parts by URL (#5209)
roboeve[bot]f1656a50c405
diff --git a/.changeset/tool-output-file-urls.md b/.changeset/tool-output-file-urls.mdnew file mode 100644index 000000000..9d7c9201e--- /dev/null+++ b/.changeset/tool-output-file-urls.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Tools can now hand the model a file by URL. `toolOutputPart.fileUrl(url, { mediaType })` from `eve/tools` returns a `{ type: "file", data: { type: "url", url } }` content part from `toModelOutput`, so a large file such as a presigned PDF link reaches the model without being base64-encoded, staged into the sandbox, or stored in session history. Only `https:` URLs are accepted, and the URL must stay readable for the rest of the session because every later model call sends it again.diff --git a/docs/sandbox/index.mdx b/docs/sandbox/index.mdxindex 837755da0..bdfa7f7f3 100644--- a/docs/sandbox/index.mdx+++ b/docs/sandbox/index.mdx@@ -156,6 +156,8 @@ Docker mounts the compiled trees read-only under `/eve/resources`, copies workspeve writes byte-backed files that reach the agent into the sandbox under `/workspace/.eve/attachments/` and keeps only a reference in session history. This covers files attached to user messages and files that tools return to the model with `toolOutputPart.file` or as MCP image, audio, and blob content.+Files that tools return by URL with `toolOutputPart.fileUrl` are not staged: the model provider reads the URL directly. See [Send a file by URL](/docs/tools#send-a-file-by-url).+Before every model call, eve reads the referenced files back from the sandbox. Every file, whether attached to a message or returned by a tool, reaches the model with a label that names its sandbox path, such as `Attached file /workspace/.eve/attachments/<hash>/report.csv (text/csv)`. The agent can open that path with `read_file` or `bash`. The file's bytes follow its label only when every major provider reads the format natively:- A PNG, JPEG, GIF, or WebP image up to 3 MiB and at most 8000 pixels per side.diff --git a/docs/tools/overview.mdx b/docs/tools/overview.mdxindex 297abdbc8..00d240759 100644--- a/docs/tools/overview.mdx+++ b/docs/tools/overview.mdx@@ -339,6 +339,25 @@ eve writes each returned file to the session sandbox and keeps only a referenceWhen compaction drops older tool results, each file becomes a text reference such as `Attached file /workspace/.eve/attachments/<hash>/chart.png (image/png)`. The built-in `read_file` tool shows PNG, JPEG, GIF, and WebP images up to 3 MiB and PDFs up to 20 MiB to the model as files, so the agent can open a compacted image or PDF again.+#### Send a file by URL++For large files that already live in object storage, such as PDFs behind a presigned S3 link, return the URL instead of the bytes with `toolOutputPart.fileUrl`:++```ts+toModelOutput(output) {+ return toolOutput.content([+ toolOutputPart.text(`Contract ${output.id}:`),+ toolOutputPart.fileUrl(output.signedUrl, { mediaType: "application/pdf" }),+ ]);+},+```++eve keeps only the URL in session history and does not write the file to the sandbox. The model provider fetches the URL itself when it supports that for the file's type; otherwise the AI SDK downloads the file before the call. Only `https:` URLs are accepted.++Every later model call sends the same URL again, so it must stay readable for the rest of the session. A presigned URL that expires mid-session makes later model calls fail. The provider still counts the file's input tokens on each call, the same as an inline file.++Unlike a staged file, a URL part has no sandbox path to fall back on. When compaction drops the tool result, the file becomes `Attached file <filename> (<mediaType>)` and the URL is gone. If the agent may need the file again later, also return a text part with an id or path the tool can fetch it by.+Do not return secrets, credentials, unnecessary personal data, or unbounded sensitive content from tools. Filter, minimize, and redact tool outputs before returning them.## What to read nextdiff --git a/packages/eve/extension-contracts/compatibility/channel/v65.ts b/packages/eve/extension-contracts/compatibility/channel/v65.tsnew file mode 100644index 000000000..ac61fad04--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/channel/v65.ts@@ -0,0 +1,12 @@+import { defineChannel, POST } from "#public/channels/index.js";++// Epoch 65 tool content parts carried base64 file data only; epoch 66 adds file URLs, which is additive.+export default defineChannel({+ routes: [+ POST("/reports", async (_request, { from }) => {+ const { session } = await from("reports").create({ auth: null });+ await session.send("Summarize the attached screenshot.", { auth: null });+ return Response.json({ sessionId: session.id });+ }),+ ],+});diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v89.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v89.tsnew file mode 100644index 000000000..15b73e153--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v89.ts@@ -0,0 +1,15 @@+import { defineDynamic, defineTool, toolOutput, toolOutputPart } from "#public/tools/index.js";++// Epoch 89 file content parts carried base64 data only; epoch 90 adds file URLs, which is additive.+export default defineDynamic({+ events: {+ "turn.started": () =>+ defineTool({+ description: "Capture a screenshot.",+ inputSchema: { type: "object", properties: {} },+ execute: () => ({ png: "aGVsbG8=" }),+ toModelOutput: (output) =>+ toolOutput.content([toolOutputPart.file(output.png, { mediaType: "image/png" })]),+ }),+ },+});diff --git a/packages/eve/extension-contracts/compatibility/tool/v98.ts b/packages/eve/extension-contracts/compatibility/tool/v98.tsnew file mode 100644index 000000000..f5cc56225--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/tool/v98.ts@@ -0,0 +1,26 @@+// Epoch 98 of the tool capability: base64 file content parts still compile after file URLs were added.+import { defineTool, toolOutput, toolOutputPart } from "#public/tools/index.js";++export default defineTool({+ description: "Capture a screenshot.",+ inputSchema: {+ type: "object",+ properties: { page: { type: "string" } },+ required: ["page"],+ additionalProperties: false,+ },+ async execute(input: { page: string }) {+ return { page: input.page, png: "aGVsbG8=" };+ },+ toModelOutput(output) {+ return toolOutput.content([+ toolOutputPart.text(`Screenshot of ${output.page}:`),+ toolOutputPart.file(output.png, { mediaType: "image/png", filename: "page.png" }),+ {+ type: "file",+ data: { type: "data", data: output.png },+ mediaType: "image/png",+ },+ ]);+ },+});diff --git a/packages/eve/extension-contracts/reports/channel/v66.json b/packages/eve/extension-contracts/reports/channel/v66.jsonnew file mode 100644index 000000000..08f2c22b8--- /dev/null+++ b/packages/eve/extension-contracts/reports/channel/v66.json@@ -0,0 +1,24 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "channel",+ "epoch": 66,+ "sha256": "ab28320d74b485e2b1b328fc0d4bbd19e77a9944db9cc097ae8cd049934b915d",+ "exports": [+ "DELETE",+ "GET",+ "HEAD",+ "InvalidSessionHistoryError",+ "OPTIONS",+ "PATCH",+ "POST",+ "PUT",+ "SessionStrandedError",+ "WS",+ "attachmentError",+ "createWebSocketUpgradeServer",+ "defineChannel",+ "disableRoute",+ "isChannel",+ "isDisabledRouteSentinel"+ ]+}diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v90.json b/packages/eve/extension-contracts/reports/dynamicTool/v90.jsonnew file mode 100644index 000000000..08d2e4c7a--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicTool/v90.json@@ -0,0 +1,16 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicTool",+ "epoch": 90,+ "sha256": "d7d3693d88113877f4fdefdb5e3d650a770e4b42114bab74ae11f3c7f4e18508",+ "exports": [+ "DynamicToolEntry",+ "DynamicToolEvents",+ "DynamicToolResult",+ "DynamicToolSet",+ "auto",+ "defineDurableCallback",+ "defineDurableSchema",+ "defineDynamic"+ ]+}diff --git a/packages/eve/extension-contracts/reports/tool/v99.json b/packages/eve/extension-contracts/reports/tool/v99.jsonnew file mode 100644index 000000000..37d378049--- /dev/null+++ b/packages/eve/extension-contracts/reports/tool/v99.json@@ -0,0 +1,29 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "tool",+ "epoch": 99,+ "sha256": "d67b06625a26c2a1225c9616e37727a60dd9b36e312c6661603bd8b6ff6583ae",+ "exports": [+ "AgentRouterInput",+ "AgentRouterTool",+ "WorkflowStepToolContext",+ "WorkflowTool",+ "WorkflowToolDefinition",+ "WorkflowToolInput",+ "WorkflowToolOptions",+ "agentRouter",+ "decide",+ "defaultWebSearch",+ "defineTool",+ "defineWorkflowTool",+ "disableTool",+ "isDisabledToolSentinel",+ "isWebSearchToolDefinition",+ "serializeModelInputSchema",+ "toolOutput",+ "toolOutputPart",+ "toolResultFrom",+ "webSearch",+ "workflow"+ ]+}diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.tsindex d8d0ff93c..5243e92a2 100644--- a/packages/eve/src/compiler/extension-compatibility.ts+++ b/packages/eve/src/compiler/extension-compatibility.ts@@ -22,10 +22,10 @@ interface ExtensionCapabilityContract {const EXTENSION_CAPABILITY_CONTRACTS = {extension: { current: 1, supported: [1], dropped: {} },tool: {- current: 98,+ current: 99,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 29, 30, 31, 32, 34, 35, 76, 77, 78, 80, 81, 82, 84,- 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 97, 98,+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 97, 98, 99,],dropped: {14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",@@ -91,11 +91,11 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},dynamicTool: {- current: 89,+ current: 90,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 31, 32, 33, 52, 54,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,- 85, 86, 87, 89,+ 85, 86, 87, 89, 90,],dropped: {21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -137,10 +137,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},channel: {- current: 65,+ current: 66,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 29, 31, 36, 37, 38, 39, 40, 41, 42,- 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65,+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66,],dropped: {12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 550028dd4..1108e6d95 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -11085,6 +11085,94 @@ describe("createToolLoopHarness", () => {expect(JSON.stringify(modelCall.messages)).toContain(base64);});+ it("hands the model a file URL a tool projects without downloading or staging it", async () => {+ const { withParkedStep } = await import("#internal/testing/session-machine.js");+ const { toolOutput, toolOutputPart } = await import("#tools/model-output.js");+ setupMockAgent({+ finishReason: "stop",+ response: { messages: [{ content: "Read.", role: "assistant" }] },+ text: "Read.",+ toolCalls: [],+ toolResults: [],+ });+ const url = "https://bucket.example.com/report.pdf?X-Amz-Signature=abc";+ const tools: ToolLoopHarnessConfig["tools"] = new Map([+ [+ "fetch_report",+ {+ description: "Fetch a report.",+ inputSchema: jsonSchema({ type: "object" }),+ name: "fetch_report",+ toModelOutput: (output: unknown) =>+ toolOutput.content([+ toolOutputPart.fileUrl((output as { url: string }).url, {+ mediaType: "application/pdf",+ }),+ ]),+ workflowId: "workflow//./agent/tools/fetch_report//execute",+ },+ ],+ ]);+ const parked = withParkedStep(createTestSession(), {+ event: { sequence: 0, stepIndex: 0, turnId: "turn_0" },+ messages: [+ {+ content: [+ { input: {}, toolCallId: "report-1", toolName: "fetch_report", type: "tool-call" },+ ],+ role: "assistant",+ },+ ],+ tasks: [+ {+ callId: "report-1",+ entry: { entryPoint: "execute" },+ input: {},+ kind: "workflow-task",+ toolName: "fetch_report",+ workflowId: "workflow//./agent/tools/fetch_report//execute",+ },+ ],+ });+ const sandbox = mockSandbox({ id: "sbx_workflow_file_url" });+ const ctx = new ContextContainer();+ ctx.set(SandboxKey, sandbox.access);++ await contextStorage.run(ctx, () =>+ createToolLoopHarness(createTestConfig(undefined, { tools }))(parked, {+ runtimeActionResults: [+ {+ callId: "report-1",+ kind: "tool-result",+ output: { url },+ toolName: "fetch_report",+ },+ ],+ }),+ );++ expect(sandbox.writes).toHaveLength(0);+ const agent = vi.mocked(ToolLoopAgent).mock.results[0]?.value as+ | { stream: ReturnType<typeof vi.fn> }+ | undefined;+ const modelCall = agent?.stream.mock.calls[0]?.[0] as { messages: ModelMessage[] };+ const toolMessage = modelCall.messages.find((message) => message.role === "tool");+ expect(toolMessage?.content).toEqual([+ expect.objectContaining({+ output: {+ type: "content",+ value: [+ {+ data: { type: "url", url: new URL(url) },+ mediaType: "application/pdf",+ type: "file",+ },+ ],+ },+ }),+ ]);+ });+it("stages non-inlinable FilePart bytes into the sandbox and hands the model a text reference instead of bytes", async () => {setupMockAgent({finishReason: "stop",diff --git a/packages/eve/src/harness/tool-model-output.test.ts b/packages/eve/src/harness/tool-model-output.test.tsindex 5a4cac48a..58dd4dc18 100644--- a/packages/eve/src/harness/tool-model-output.test.ts+++ b/packages/eve/src/harness/tool-model-output.test.ts@@ -83,6 +83,51 @@ describe("normalizeToolModelOutput", () => {});});+ it("parses https file URLs into the AI SDK's URL shape", () => {+ const url = "https://bucket.example.com/report.pdf?X-Amz-Signature=abc";++ expect(+ normalize(+ toolOutput.content([+ toolOutputPart.fileUrl(url, { mediaType: "application/pdf", filename: "report.pdf" }),+ ]),+ ),+ ).toEqual({+ type: "content",+ value: [+ {+ type: "file",+ data: { type: "url", url: new URL(url) },+ mediaType: "application/pdf",+ filename: "report.pdf",+ },+ ],+ });+ });++ it.each([+ ["http URL", "http://minio.internal/a.pdf?X-Amz-Signature=secret", /received a http: URL/u],+ [+ "sandbox ref",+ "eve-sandbox:/workspace/.eve/attachments/a.pdf",+ /received a eve-sandbox: URL/u,+ ],+ ["data URL", "data:application/pdf;base64,aGVsbG8=", /received a data: URL/u],+ ["relative path", "/workspace/a.pdf", /received a value that is not a URL/u],+ ])("rejects a file url that is a %s without echoing it", (_label, url, expected) => {+ let error: unknown;+ try {+ normalize({+ type: "content",+ value: [{ type: "file", data: { type: "url", url }, mediaType: "application/pdf" }],+ });+ } catch (caught) {+ error = caught;+ }+ expect(String(error)).toMatch(expected);+ expect(String(error)).not.toContain(url);+ });+it.each([["raw Uint8Array payload",@@ -90,11 +135,6 @@ describe("normalizeToolModelOutput", () => {/base64 string, received raw bytes/u,],["raw untagged bytes", new Uint8Array([1, 2, 3]), /base64 string, received raw bytes/u],- [- "url file-data tag",- { type: "url", url: "https://example.com/a.png" },- /"url" is not supported yet/u,- ],["reference file-data tag",{ type: "reference", reference: "file_abc" },diff --git a/packages/eve/src/harness/tool-model-output.ts b/packages/eve/src/harness/tool-model-output.tsindex 1a073d744..a1447e65b 100644--- a/packages/eve/src/harness/tool-model-output.ts+++ b/packages/eve/src/harness/tool-model-output.ts@@ -9,13 +9,25 @@ import { withToolOutputSerializationError } from "#harness/tool-output-serializa/*** A validated {@link ToolModelOutput} in the AI SDK's expected shape:- * `json` values are proven JSON-serializable and `content` arrays are- * mutable so the value is assignable to the SDK's `ToolResultOutput`.+ * `json` values are proven JSON-serializable, `content` arrays are+ * mutable, and file URLs are parsed `URL`s so the value is assignable to+ * the SDK's `ToolResultOutput`.*/export type ToolModelOutputValue =| { readonly type: "json"; readonly value: JSONValue }| { readonly type: "text"; readonly value: string }- | { readonly type: "content"; readonly value: ToolModelOutputPart[] };+ | { readonly type: "content"; readonly value: ToolModelOutputValuePart[] };++type ToolModelOutputValuePart =+ | Extract<ToolModelOutputPart, { readonly type: "text" }>+ | {+ readonly type: "file";+ readonly data:+ | { readonly type: "data"; readonly data: string }+ | { readonly type: "url"; readonly url: URL };+ readonly mediaType: string;+ readonly filename?: string;+ };const log = createLogger("harness.tool-model-output");@@ -28,13 +40,16 @@ const log = createLogger("harness.tool-model-output");const CONTENT_FILE_WARN_BYTES = 3 * 1024 * 1024;/** File-data tags the AI SDK accepts but eve does not support yet. */-const UNSUPPORTED_FILE_DATA_TAGS = new Set(["url", "reference", "text"]);+const UNSUPPORTED_FILE_DATA_TAGS = new Set(["reference", "text"]);const toolModelOutputPartSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("text"), text: z.string() }),z.object({type: z.literal("file"),- data: z.object({ type: z.literal("data"), data: z.string() }),+ data: z.discriminatedUnion("type", [+ z.object({ type: z.literal("data"), data: z.string() }),+ z.object({ type: z.literal("url"), url: z.string() }),+ ]),mediaType: z.string().min(1),filename: z.string().optional(),}),@@ -103,17 +118,44 @@ export function normalizeToolModelOutput(input: {};}if (output.type === "content") {- for (const part of output.value) {- if (part.type === "file") {- warnOversizedFilePayload(part, input.toolName);- }- }+ return {+ type: "content",+ value: output.value.map((part) => normalizeContentPart(part, input.toolName)),+ };}return output;},);}+function normalizeContentPart(+ part: z.infer<typeof toolModelOutputPartSchema>,+ toolName: string,+): ToolModelOutputValuePart {+ if (part.type === "text") return part;+ if (part.data.type === "data") {+ warnOversizedFilePayload(part.data.data, part.mediaType, toolName);+ return { ...part, data: part.data };+ }+ return { ...part, data: { type: "url", url: parseFileUrl(part.data.url) } };+}++/**+ * Only `https:` URLs are accepted: the provider fetches them, and eve's+ * own attachment refs use internal schemes that must never be authored.+ * The error names only the scheme, since presigned URLs carry credentials.+ */+function parseFileUrl(value: string): URL {+ const url = URL.canParse(value) ? new URL(value) : undefined;+ if (url?.protocol !== "https:") {+ const received = url === undefined ? "a value that is not a URL" : `a ${url.protocol} URL`;+ throw new TypeError(+ `Expected file content part url to be an https: URL, received ${received}.`,+ );+ }+ return url;+}+/*** Asserts every file part's `data` is the supported form, covering the two* author mistakes the schema cannot explain well: raw bytes (which@@ -152,24 +194,21 @@ function assertSupportedFilePartData(output: unknown): void {if (typeof tag === "string" && UNSUPPORTED_FILE_DATA_TAGS.has(tag)) {throw new TypeError(`File content part data tag "${tag}" is not supported yet; ` +- 'only { type: "data" } with a base64 string is accepted.',+ 'use { type: "data" } with a base64 string or { type: "url" } with an https: URL.',);}}}-function warnOversizedFilePayload(- part: { readonly data: { readonly data: string }; readonly mediaType: string },- toolName: string,-): void {- const estimatedBytes = Math.floor((part.data.data.length * 3) / 4);+function warnOversizedFilePayload(base64: string, mediaType: string, toolName: string): void {+ const estimatedBytes = Math.floor((base64.length * 3) / 4);if (estimatedBytes <= CONTENT_FILE_WARN_BYTES) return;log.warn("content-part file payload exceeds the inline size guideline — it is persisted in " +"history and re-sent on every subsequent model call",{estimatedBytes,- mediaType: part.mediaType,+ mediaType,toolName,warnBytes: CONTENT_FILE_WARN_BYTES,},diff --git a/packages/eve/src/tools/model-output.ts b/packages/eve/src/tools/model-output.tsindex 8ae40ee6f..6ed085cbc 100644--- a/packages/eve/src/tools/model-output.ts+++ b/packages/eve/src/tools/model-output.ts@@ -15,17 +15,24 @@ export type ToolModelOutput =/*** One part of a `content` {@link ToolModelOutput}. Mirrors the AI SDK's* `ToolResultOutput` content parts narrowed to the JSON-safe subset:- * file data is the SDK's tagged `FileData` union restricted to- * `{ type: "data" }` with a base64 string, so persisted tool results- * survive the durable JSON boundary. Use the `toolOutputPart` builders- * from `eve/tools` to construct parts without hand-writing the nesting.+ * file data is the SDK's tagged `FileData` union restricted to a base64+ * `{ type: "data" }` payload or an `https:` `{ type: "url" }` string, so+ * persisted tool results survive the durable JSON boundary. Use the+ * `toolOutputPart` builders from `eve/tools` to construct parts without+ * hand-writing the nesting.*/export type ToolModelOutputPart =| { readonly type: "text"; readonly text: string }| {readonly type: "file";- /** Tagged file data; only JSON-safe base64 payloads are accepted. */- readonly data: { readonly type: "data"; readonly data: string };+ /**+ * Tagged file data: a base64 payload, or an `https:` URL the+ * provider fetches itself. A URL must stay readable for the whole+ * session because every later model call sends it again.+ */+ readonly data:+ | { readonly type: "data"; readonly data: string }+ | { readonly type: "url"; readonly url: string };/** IANA media type, e.g. `image/png`. */readonly mediaType: string;readonly filename?: string;@@ -91,19 +98,27 @@ export const toolOutputPart = {base64: string,options: { readonly mediaType: string; readonly filename?: string },): ToolModelOutputPart {- const part: {- type: "file";- data: { type: "data"; data: string };- mediaType: string;- filename?: string;- } = {- type: "file",- data: { type: "data", data: base64 },- mediaType: options.mediaType,- };- if (options.filename !== undefined) {- part.filename = options.filename;- }- return part;+ return filePart({ type: "data", data: base64 }, options);+ },+ /**+ * Builds a file part from an `https:` URL, e.g. a presigned object+ * storage link. The provider fetches the file, so eve neither downloads+ * it nor stores its bytes in session history. Every later model call+ * sends the URL again, so it must not expire before the session ends.+ */+ fileUrl(+ url: string,+ options: { readonly mediaType: string; readonly filename?: string },+ ): ToolModelOutputPart {+ return filePart({ type: "url", url }, options);},};++function filePart(+ data: Extract<ToolModelOutputPart, { readonly type: "file" }>["data"],+ options: { readonly mediaType: string; readonly filename?: string },+): ToolModelOutputPart {+ return options.filename === undefined+ ? { type: "file", data, mediaType: options.mediaType }+ : { type: "file", data, mediaType: options.mediaType, filename: options.filename };+}diff --git a/research/tool-model-output-file-urls.md b/research/tool-model-output-file-urls.mdnew file mode 100644index 000000000..dcd55d26f--- /dev/null+++ b/research/tool-model-output-file-urls.md@@ -0,0 +1,65 @@+---+issue: https://github.com/vercel/eve/issues/5202+status: proposed+last_updated: "2026-10-22"+---++# Tool model output file URLs++## Summary++`toModelOutput` content file parts accept only base64 `{ type: "data" }`.+A tool working with large files, such as PDFs in object storage, must+download them, base64-encode them, and let eve stage the bytes into the+sandbox and re-read them on every model call. The bundled AI SDK already+accepts `{ type: "url", url }` file data in tool results. This plan+exposes it.++## Authoring API++```ts+toModelOutput(output) {+ return toolOutput.content([+ toolOutputPart.fileUrl(output.signedUrl, { mediaType: "application/pdf" }),+ ]);+}+```++`ToolModelOutputPart` file data widens to+`{ type: "data"; data: string } | { type: "url"; url: string }`. The URL is+a string so the authored shape stays JSON-safe.++## Semantics++- Only `https:` URLs are accepted. This also rejects eve's internal+ attachment schemes (`eve-sandbox:`, `eve-url:`), which the hydrator+ trusts as sandbox reads and must never be authored.+- The harness parses the string into a `URL` when it normalizes the+ output, matching the AI SDK `FileData` shape. History already persists+ `URL` values for staged sandbox refs, so no new durable type is needed.+- URL parts skip sandbox staging and hydration. Compaction stubs them like+ any other file part, and token estimation already counts remote files.+- The AI SDK decides delivery per model: a URL the model supports is sent+ to the provider (Anthropic image or document URL sources, OpenAI+ Responses `file_url`/`image_url`, every URL through AI Gateway); any+ other URL is downloaded by the AI SDK before each call.+- The URL is replayed on every later model call. It must outlive the+ session; an expired presigned URL fails later calls. Providers still+ bill the file's input tokens on each call.++## Out of scope++- `{ type: "reference" }` provider file ids. In tool results, the+ Anthropic adapter drops them with a warning and the Google adapter+ turns them into JSON text, so a model fallback or provider switch would+ silently lose the file. Supporting them needs a loud failure for+ providers that cannot read them.+- `{ type: "text" }` file data.+- Re-signing or re-staging expired URLs.++## Verification++- Unit (`harness/tool-model-output.test.ts`): `fileUrl` parts normalize to+ a `URL`; non-`https:` URLs, including internal schemes, are rejected.+- Unit (`harness/tool-loop.test.ts`): a workflow tool's URL part reaches+ the model call unchanged without a sandbox write.