@sixb/agent 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/agent-prompt.d.ts +34 -28
  2. package/dist/agent-prompt.d.ts.map +1 -1
  3. package/dist/artifacts/publish-tool.d.ts +1 -1
  4. package/dist/attachments.d.ts +42 -1
  5. package/dist/attachments.d.ts.map +1 -1
  6. package/dist/child-files.d.ts +0 -5
  7. package/dist/child-files.d.ts.map +1 -1
  8. package/dist/computer-runner.d.ts +16 -7
  9. package/dist/computer-runner.d.ts.map +1 -1
  10. package/dist/context-budget.d.ts +23 -17
  11. package/dist/context-budget.d.ts.map +1 -1
  12. package/dist/context-compaction.d.ts +118 -18
  13. package/dist/context-compaction.d.ts.map +1 -1
  14. package/dist/context-guard.d.ts +69 -0
  15. package/dist/context-guard.d.ts.map +1 -0
  16. package/dist/conversation-messages.d.ts +33 -0
  17. package/dist/conversation-messages.d.ts.map +1 -0
  18. package/dist/execution-plan.d.ts +5 -1
  19. package/dist/execution-plan.d.ts.map +1 -1
  20. package/dist/failure.d.ts.map +1 -1
  21. package/dist/index.js +4916 -2697
  22. package/dist/index.js.map +41 -34
  23. package/dist/inline-images.d.ts +28 -0
  24. package/dist/inline-images.d.ts.map +1 -0
  25. package/dist/message-authors.d.ts +4 -4
  26. package/dist/message-authors.d.ts.map +1 -1
  27. package/dist/message-times.d.ts +4 -3
  28. package/dist/message-times.d.ts.map +1 -1
  29. package/dist/model-adapters.d.ts +6 -2
  30. package/dist/model-adapters.d.ts.map +1 -1
  31. package/dist/prompt-cache.d.ts +28 -0
  32. package/dist/prompt-cache.d.ts.map +1 -0
  33. package/dist/run-agent-turn.d.ts +33 -3
  34. package/dist/run-agent-turn.d.ts.map +1 -1
  35. package/dist/run-child.d.ts.map +1 -1
  36. package/dist/run-conversation-turn.d.ts.map +1 -1
  37. package/dist/run-environment.d.ts +35 -5
  38. package/dist/run-environment.d.ts.map +1 -1
  39. package/dist/run-files-lock.d.ts +16 -0
  40. package/dist/run-files-lock.d.ts.map +1 -0
  41. package/dist/run-subagent.d.ts +15 -1
  42. package/dist/run-subagent.d.ts.map +1 -1
  43. package/dist/run-workflow-agent-node.d.ts +5 -0
  44. package/dist/run-workflow-agent-node.d.ts.map +1 -1
  45. package/dist/sandbox-api-context.d.ts.map +1 -1
  46. package/dist/subagent-context.d.ts +50 -0
  47. package/dist/subagent-context.d.ts.map +1 -0
  48. package/dist/subagent-continuation.d.ts +10 -4
  49. package/dist/subagent-continuation.d.ts.map +1 -1
  50. package/dist/subagent-tools.d.ts +11 -0
  51. package/dist/subagent-tools.d.ts.map +1 -1
  52. package/dist/thread-context.d.ts +7 -2
  53. package/dist/thread-context.d.ts.map +1 -1
  54. package/dist/tools/bash.d.ts +8 -0
  55. package/dist/tools/bash.d.ts.map +1 -1
  56. package/dist/tools/model-spec.d.ts +7 -2
  57. package/dist/tools/model-spec.d.ts.map +1 -1
  58. package/dist/tools/result-media.d.ts +53 -10
  59. package/dist/tools/result-media.d.ts.map +1 -1
  60. package/dist/tools/result-output.d.ts +1 -1
  61. package/dist/tools/result-output.d.ts.map +1 -1
  62. package/dist/tools/tool-outputs.d.ts +63 -0
  63. package/dist/tools/tool-outputs.d.ts.map +1 -0
  64. package/dist/types.d.ts +9 -2
  65. package/dist/types.d.ts.map +1 -1
  66. package/package.json +4 -4
  67. package/src/agent-prompt.ts +178 -76
  68. package/src/attachments.ts +275 -84
  69. package/src/child-files.ts +1 -6
  70. package/src/computer-runner.ts +75 -23
  71. package/src/context-budget.ts +110 -94
  72. package/src/context-compaction.ts +1007 -187
  73. package/src/context-guard.ts +826 -0
  74. package/src/conversation-messages.ts +86 -0
  75. package/src/execution-plan.ts +22 -2
  76. package/src/failure.ts +11 -0
  77. package/src/inline-images.ts +69 -0
  78. package/src/message-authors.ts +5 -5
  79. package/src/message-times.ts +8 -5
  80. package/src/model-adapters.ts +59 -13
  81. package/src/prompt-cache.ts +40 -0
  82. package/src/run-agent-turn.ts +234 -72
  83. package/src/run-child.ts +30 -5
  84. package/src/run-conversation-turn.ts +16 -1
  85. package/src/run-environment.ts +553 -106
  86. package/src/run-files-lock.ts +118 -0
  87. package/src/run-subagent.ts +132 -46
  88. package/src/run-workflow-agent-node.ts +84 -10
  89. package/src/sandbox-api-context.ts +3 -0
  90. package/src/skills/sixb-artifacts/canvas.md +1 -1
  91. package/src/skills/sixb-artifacts/page.md +1 -1
  92. package/src/skills/sixb-artifacts/slides.md +1 -1
  93. package/src/subagent-context.ts +182 -0
  94. package/src/subagent-continuation.ts +11 -6
  95. package/src/subagent-tools.ts +73 -11
  96. package/src/thread-context.ts +9 -3
  97. package/src/tools/bash.ts +17 -1
  98. package/src/tools/model-spec.ts +9 -4
  99. package/src/tools/result-media.ts +286 -82
  100. package/src/tools/result-output.ts +4 -2
  101. package/src/tools/tool-outputs.ts +464 -0
  102. package/src/types.ts +14 -2
@@ -4,40 +4,78 @@ import type {
4
4
  PrepareModelStepInput,
5
5
  PrepareModelStepResult,
6
6
  } from "@sixb/core/internal/agents"
7
- import { isAgentToolResult } from "@sixb/core/internal/agents"
8
- import { modelSupportsInlineImages, prepareAgentToolFileProjection } from "../attachments"
7
+ import { agentMessageSteps, isAgentToolResult } from "@sixb/core/internal/agents"
8
+ import type { ModelFilePart, ModelMessage, ModelTextPart } from "@sixb/core/models"
9
+ import type { AgentMessageRecord } from "@sixb/core/storage"
10
+ import {
11
+ type AttachmentImageOutcome,
12
+ type AttachmentImageProjection,
13
+ attachmentKey,
14
+ modelSupportsInlineImages,
15
+ type PendingAttachmentImage,
16
+ type PreparedAgentAttachmentContext,
17
+ prepareAgentToolFileProjection,
18
+ settleAttachmentImages,
19
+ } from "../attachments"
9
20
  import { fileContentKey } from "../file-ref"
21
+ import { type InlineImageBudget, projectInOrder } from "../inline-images"
10
22
  import { type AgentToolModelOutput, agentToolResultToModelOutput } from "./result-output"
11
23
 
12
24
  const TOOL_RESULT_IMAGE_OMISSION_NOTE =
13
25
  "[Image is not embedded in the tool-result message; Sixb supplies it as a separate model input when the selected model supports images.]"
14
26
 
15
- interface PendingToolFile {
27
+ /** Whether the images a tool's results return reach the model after its step. */
28
+ export type SuppliesToolFiles = (toolName: string) => boolean
29
+
30
+ /** An image a step's tool returned, not projected yet. */
31
+ interface ToolFileCandidate {
32
+ readonly toolCallId: string
16
33
  readonly fileRef: FileRef
17
- readonly signal: AbortSignal
34
+ }
35
+
36
+ /** One tool call's durable result, as the step that ran it produced it. */
37
+ interface StepToolResult {
18
38
  readonly toolCallId: string
39
+ readonly toolName: string
40
+ readonly output: JsonValue | undefined
19
41
  }
20
42
 
21
- /** Move tool-created images into an ephemeral user message without changing their durable result. */
22
- export class AgentToolResultMediaBridge {
23
- readonly #pending: PendingToolFile[] = []
43
+ interface ToolFileProjectionInput {
44
+ readonly blobStorage: AgentRunFileStore
45
+ readonly signal: AbortSignal
46
+ /** Test seam; production uses the bounded attachment projector. */
47
+ readonly projectFile?: typeof prepareAgentToolFileProjection
48
+ }
24
49
 
50
+ /** What became of a step's image: inline, left out by the budget, or no image to project. */
51
+ type ToolFileDecision =
52
+ | { readonly kind: "inline"; readonly toolCallId: string; readonly file: ModelFilePart }
53
+ | { readonly kind: "budget"; readonly toolCallId: string; readonly name: string }
54
+ | { readonly kind: "none" }
55
+
56
+ /**
57
+ * Move tool-created images into a user message after their step without changing their durable
58
+ * result. The message is derived from the step's results alone, so a later turn derives the same
59
+ * one from the stored trace ({@link replayToolFiles}) and its request keeps the prefix. Its images
60
+ * take what the request's inline image budget has left, after the history's.
61
+ */
62
+ export class AgentToolResultMediaBridge {
25
63
  constructor(
26
- private readonly input: {
27
- readonly blobStorage: AgentRunFileStore
28
- readonly sandboxPathForFileRef?: (fileRef: FileRef) => string | undefined
29
- /** Test seam; production uses the bounded attachment projector. */
30
- readonly projectFile?: typeof prepareAgentToolFileProjection
64
+ private readonly input: Omit<ToolFileProjectionInput, "signal"> & {
65
+ readonly suppliesToolFiles: SuppliesToolFiles
66
+ readonly inlineImages: InlineImageBudget
67
+ readonly sandboxPathForFileRef?: (
68
+ fileRef: FileRef
69
+ ) => string | undefined | Promise<string | undefined>
31
70
  }
32
71
  ) {}
33
72
 
34
73
  async toModelOutput(input: {
35
74
  readonly output: JsonValue
36
75
  readonly signal: AbortSignal
37
- readonly toolCallId: string
38
76
  }): Promise<AgentToolModelOutput> {
39
77
  input.signal.throwIfAborted()
40
- const output = await agentToolResultToModelOutput({
78
+ return agentToolResultToModelOutput({
41
79
  output: input.output,
42
80
  blobStorage: this.input.blobStorage,
43
81
  signal: input.signal,
@@ -46,91 +84,257 @@ export class AgentToolResultMediaBridge {
46
84
  : { sandboxPathForFileRef: this.input.sandboxPathForFileRef }),
47
85
  imageOmissionNote: TOOL_RESULT_IMAGE_OMISSION_NOTE,
48
86
  })
49
-
50
- if (isAgentToolResult(input.output)) {
51
- for (const contentPart of input.output.content) {
52
- if (contentPart.type === "file" && isImageFile(contentPart.fileRef)) {
53
- this.#pending.push({
54
- fileRef: contentPart.fileRef,
55
- signal: input.signal,
56
- toolCallId: input.toolCallId,
57
- })
58
- }
59
- }
60
- }
61
- return output
62
87
  }
63
88
 
64
89
  readonly prepareStep = async ({
90
+ stepIndex,
65
91
  messages,
66
92
  model,
67
- signal: stepSignal,
93
+ signal,
68
94
  }: PrepareModelStepInput): Promise<PrepareModelStepResult | undefined> => {
69
- if (this.#pending.length === 0) return undefined
95
+ // Only after a step this loop ran: a replayed history holds its own steps' messages already,
96
+ // and a retried request keeps the one it added.
97
+ const results = messages.at(-1)
98
+ if (stepIndex === 0 || results?.role !== "tool" || !modelSupportsInlineImages(model)) {
99
+ return undefined
100
+ }
70
101
 
71
- const pending = this.#pending.slice()
72
- const signal = combinedSignal(pending, stepSignal)
73
102
  signal.throwIfAborted()
74
- const supportsImages = modelSupportsInlineImages(model)
75
- if (!supportsImages) {
76
- this.#pending.splice(0, pending.length)
77
- return undefined
103
+ const candidates = toolFileCandidates(
104
+ results.content.map((part) => ({
105
+ toolCallId: part.toolCallId,
106
+ toolName: part.toolName,
107
+ output:
108
+ part.originalOutput ??
109
+ (part.output.type === "text" || part.output.type === "json"
110
+ ? part.output.value
111
+ : undefined),
112
+ })),
113
+ this.input.suppliesToolFiles
114
+ )
115
+
116
+ const decisions: ToolFileDecision[] = []
117
+ await projectInOrder({
118
+ items: candidates,
119
+ budget: this.input.inlineImages,
120
+ project: (candidate) => projectToolFile(candidate, { ...this.input, signal }),
121
+ decide: (candidate, file) =>
122
+ decisions.push(decideToolFile(candidate, file, this.input.inlineImages)),
123
+ })
124
+
125
+ const message = toolFilesMessage(decisions)
126
+ return message ? { messages: [...messages, message] } : undefined
127
+ }
128
+ }
129
+
130
+ /** The key of a stored step's tool-files message: its message and its first local tool call. */
131
+ export function toolFilesStepKey(messageId: string, partIndex: number): string {
132
+ return `${messageId}:${partIndex}`
133
+ }
134
+
135
+ /**
136
+ * The images each stored step's tools returned, by {@link toolFilesStepKey}, not projected yet:
137
+ * {@link allocateInlineImages} projects them as far as the request's budget goes.
138
+ */
139
+ export function replayToolFiles(input: {
140
+ readonly messages: readonly AgentMessageRecord[]
141
+ readonly suppliesToolFiles: SuppliesToolFiles
142
+ readonly supportsImages: boolean
143
+ }): ReadonlyMap<string, readonly ToolFileCandidate[]> {
144
+ const replayed = new Map<string, readonly ToolFileCandidate[]>()
145
+ if (!input.supportsImages) return replayed
146
+
147
+ for (const message of input.messages) {
148
+ if (message.role !== "assistant") continue
149
+
150
+ for (const step of agentMessageSteps(message)) {
151
+ const first = step.localToolCalls[0]
152
+ if (!first) continue
153
+
154
+ const candidates = toolFileCandidates(
155
+ step.localToolCalls.map(({ part }) => ({
156
+ toolCallId: part.toolCallId,
157
+ toolName: part.toolName,
158
+ output: part.state === "output-available" ? part.output : undefined,
159
+ })),
160
+ input.suppliesToolFiles
161
+ )
162
+ if (candidates.length > 0) {
163
+ replayed.set(toolFilesStepKey(message.id, first.partIndex), candidates)
164
+ }
78
165
  }
166
+ }
167
+ return replayed
168
+ }
79
169
 
80
- const seen = new Set<string>()
81
- const content: Array<
82
- | { readonly type: "text"; readonly text: string }
83
- | {
84
- readonly type: "file"
85
- readonly data: URL
86
- readonly mediaType: string
87
- readonly filename?: string
88
- }
89
- > = []
90
- const toolCallIds: string[] = []
91
- for (const item of pending) {
92
- item.signal.throwIfAborted()
93
- const identity = fileContentKey(item.fileRef)
94
- if (seen.has(identity)) continue
95
- seen.add(identity)
170
+ /**
171
+ * Spend the request's inline image budget on the history, in thread order, oldest first: each user
172
+ * message's attachments, then the images after each step of the turn that answered it. Images are
173
+ * projected only while the budget is open, a few at a time; what does not fit reads as metadata.
174
+ * The run's own steps then take what is left, in the order a later replay walks them, so every
175
+ * turn takes the same decisions. Images are never stored: their bytes are projected again from
176
+ * their blobs, which is deterministic.
177
+ */
178
+ export async function allocateInlineImages(
179
+ input: ToolFileProjectionInput & {
180
+ readonly messages: readonly AgentMessageRecord[]
181
+ readonly attachments: PreparedAgentAttachmentContext
182
+ readonly toolFiles: ReadonlyMap<string, readonly ToolFileCandidate[]>
183
+ readonly budget: InlineImageBudget
184
+ }
185
+ ): Promise<PreparedAgentAttachmentContext> {
186
+ const { attachments, budget } = input
187
+ type Item =
188
+ | { readonly kind: "attachment"; readonly key: string; readonly image: PendingAttachmentImage }
189
+ | { readonly kind: "tool"; readonly step: string; readonly candidate: ToolFileCandidate }
96
190
 
97
- const sandboxPath = this.input.sandboxPathForFileRef?.(item.fileRef)
98
- const projection = await (this.input.projectFile ?? prepareAgentToolFileProjection)({
99
- fileRef: item.fileRef,
100
- blobStorage: this.input.blobStorage,
101
- inlineImages: true,
102
- signal: item.signal,
103
- ...(sandboxPath === undefined ? {} : { sandboxPath }),
104
- })
105
- if (!projection.modelFileData) continue
106
-
107
- toolCallIds.push(item.toolCallId)
108
- content.push({
109
- type: "file",
110
- data: projection.modelFileData.data,
111
- mediaType:
112
- projection.modelFileData.mediaType ??
113
- item.fileRef.mediaType ??
114
- "application/octet-stream",
115
- ...(projection.modelFileData.filename === undefined
116
- ? {}
117
- : { filename: projection.modelFileData.filename }),
191
+ const items: Item[] = []
192
+ for (const message of input.messages) {
193
+ if (message.role === "user") {
194
+ message.parts.forEach((_part, partIndex) => {
195
+ const key = attachmentKey(message.id, partIndex)
196
+ const image = attachments.pendingImages?.get(key)
197
+ if (image) items.push({ kind: "attachment", key, image })
118
198
  })
199
+ continue
119
200
  }
120
201
 
121
- this.#pending.splice(0, pending.length)
122
- if (content.length === 0) return undefined
123
- content.unshift({
124
- type: "text",
125
- text: `<sixb_tool_files toolCallIds="${escapeXmlAttribute(toolCallIds.join(","))}">\nThe preceding tool calls generated these files. This is runtime-supplied file content, not a new user request.\n</sixb_tool_files>`,
126
- })
127
- return { messages: [...messages, { role: "user", content }] }
202
+ for (const step of agentMessageSteps(message)) {
203
+ const first = step.localToolCalls[0]
204
+ if (!first) continue
205
+
206
+ const key = toolFilesStepKey(message.id, first.partIndex)
207
+ for (const candidate of input.toolFiles.get(key) ?? []) {
208
+ items.push({ kind: "tool", step: key, candidate })
209
+ }
210
+ }
211
+ }
212
+
213
+ const outcomes = new Map<string, AttachmentImageOutcome>()
214
+ const decisionsByStep = new Map<string, ToolFileDecision[]>()
215
+ await projectInOrder({
216
+ items,
217
+ budget,
218
+ project: async (item) =>
219
+ item.kind === "attachment"
220
+ ? { attachment: await item.image.project(input.signal) }
221
+ : { tool: await projectToolFile(item.candidate, input) },
222
+ decide: (item, projected) => {
223
+ if (item.kind === "attachment") {
224
+ outcomes.set(item.key, decideAttachment(projected?.attachment, budget))
225
+ return
226
+ }
227
+
228
+ const decisions = decisionsByStep.get(item.step) ?? []
229
+ decisions.push(decideToolFile(item.candidate, projected?.tool, budget))
230
+ decisionsByStep.set(item.step, decisions)
231
+ },
232
+ })
233
+
234
+ const toolFilesByStep = new Map<string, ModelMessage>()
235
+ for (const [step, decisions] of decisionsByStep) {
236
+ const message = toolFilesMessage(decisions)
237
+ if (message) toolFilesByStep.set(step, message)
128
238
  }
239
+ return { ...settleAttachmentImages(attachments, outcomes), toolFilesByStep }
240
+ }
241
+
242
+ /** An attachment's image fate: inline while it fits, metadata once the budget closed. */
243
+ function decideAttachment(
244
+ projection: AttachmentImageProjection | undefined,
245
+ budget: InlineImageBudget
246
+ ): AttachmentImageOutcome {
247
+ // One projected ahead of the budget's closing reads as one never projected.
248
+ if (budget.closed || !projection) return { kind: "budget" }
249
+ if (projection.kind !== "inline") return projection
250
+ return budget.take(projection.data.data) ? projection : { kind: "budget" }
251
+ }
252
+
253
+ /** A tool image's fate: inline while it fits, named once the budget closed. */
254
+ function decideToolFile(
255
+ candidate: ToolFileCandidate,
256
+ file: ModelFilePart | undefined,
257
+ budget: InlineImageBudget
258
+ ): ToolFileDecision {
259
+ const name = candidate.fileRef.fileName ?? "image"
260
+ if (budget.closed) return { kind: "budget", toolCallId: candidate.toolCallId, name }
261
+ if (!file) return { kind: "none" }
262
+ return budget.take(file.data)
263
+ ? { kind: "inline", toolCallId: candidate.toolCallId, file }
264
+ : { kind: "budget", toolCallId: candidate.toolCallId, name }
129
265
  }
130
266
 
131
- function combinedSignal(pending: readonly PendingToolFile[], stepSignal: AbortSignal): AbortSignal {
132
- const signals = [...new Set([stepSignal, ...pending.map((item) => item.signal)])]
133
- return signals.length === 1 ? stepSignal : AbortSignal.any(signals)
267
+ /** The image files a step's results returned, once each, in the order of the step's calls. */
268
+ function toolFileCandidates(
269
+ results: readonly StepToolResult[],
270
+ suppliesToolFiles: SuppliesToolFiles
271
+ ): ToolFileCandidate[] {
272
+ const seen = new Set<string>()
273
+ const candidates: ToolFileCandidate[] = []
274
+ for (const result of results) {
275
+ if (!suppliesToolFiles(result.toolName) || !isAgentToolResult(result.output)) continue
276
+
277
+ for (const contentPart of result.output.content) {
278
+ if (contentPart.type !== "file" || !isImageFile(contentPart.fileRef)) continue
279
+
280
+ const identity = fileContentKey(contentPart.fileRef)
281
+ if (seen.has(identity)) continue
282
+ seen.add(identity)
283
+ candidates.push({ toolCallId: result.toolCallId, fileRef: contentPart.fileRef })
284
+ }
285
+ }
286
+ return candidates
287
+ }
288
+
289
+ /** A tool image as the model reads it, or nothing when it cannot be projected. */
290
+ async function projectToolFile(
291
+ candidate: ToolFileCandidate,
292
+ input: ToolFileProjectionInput
293
+ ): Promise<ModelFilePart | undefined> {
294
+ input.signal.throwIfAborted()
295
+ const projection = await (input.projectFile ?? prepareAgentToolFileProjection)({
296
+ fileRef: candidate.fileRef,
297
+ blobStorage: input.blobStorage,
298
+ inlineImages: true,
299
+ signal: input.signal,
300
+ })
301
+ const data = projection.modelFileData
302
+ if (!data) return undefined
303
+
304
+ return {
305
+ type: "file",
306
+ data: data.data,
307
+ mediaType: data.mediaType ?? candidate.fileRef.mediaType ?? "application/octet-stream",
308
+ ...(data.filename === undefined ? {} : { filename: data.filename }),
309
+ }
310
+ }
311
+
312
+ /**
313
+ * The user message after a step with the images its tools returned, after a note that they are
314
+ * runtime input. An image past the inline image budget is named instead.
315
+ */
316
+ function toolFilesMessage(decisions: readonly ToolFileDecision[]): ModelMessage | undefined {
317
+ const images = decisions.filter((decision) => decision.kind !== "none")
318
+ if (images.length === 0) return undefined
319
+
320
+ const toolCallIds = [...new Set(images.map((image) => image.toolCallId))]
321
+ const files = images.flatMap((image) => (image.kind === "inline" ? [image.file] : []))
322
+ const leftOut = images.flatMap((image) => (image.kind === "budget" ? [image.name] : []))
323
+
324
+ const note: ModelTextPart = {
325
+ type: "text",
326
+ text: `<sixb_tool_files toolCallIds="${escapeXmlAttribute(toolCallIds.join(","))}">\nThe preceding tool calls generated these files. This is runtime-supplied file content, not a new user request.\n</sixb_tool_files>`,
327
+ }
328
+ const budgetNote: ModelTextPart[] =
329
+ leftOut.length === 0
330
+ ? []
331
+ : [
332
+ {
333
+ type: "text",
334
+ text: `[Images not inlined: ${leftOut.join(", ")}. The conversation's inline image budget is used up until it is compacted; each file is at the sandbox path its tool result names.]`,
335
+ },
336
+ ]
337
+ return { role: "user", content: [note, ...files, ...budgetNote] }
134
338
  }
135
339
 
136
340
  function isImageFile(fileRef: FileRef): boolean {
@@ -11,7 +11,9 @@ export async function agentToolResultToModelOutput(input: {
11
11
  readonly output: JsonValue
12
12
  readonly blobStorage: AgentRunFileStore
13
13
  readonly signal?: AbortSignal
14
- readonly sandboxPathForFileRef?: (fileRef: FileRef) => string | undefined
14
+ readonly sandboxPathForFileRef?: (
15
+ fileRef: FileRef
16
+ ) => string | undefined | Promise<string | undefined>
15
17
  readonly imageOmissionNote?: string
16
18
  }): Promise<AgentToolModelOutput> {
17
19
  if (!isAgentToolResult(input.output)) {
@@ -27,7 +29,7 @@ export async function agentToolResultToModelOutput(input: {
27
29
  continue
28
30
  }
29
31
 
30
- const sandboxPath = input.sandboxPathForFileRef?.(contentPart.fileRef)
32
+ const sandboxPath = await input.sandboxPathForFileRef?.(contentPart.fileRef)
31
33
  const projection = await prepareAgentToolFileProjection({
32
34
  fileRef: contentPart.fileRef,
33
35
  blobStorage: input.blobStorage,