@ai-sdk/workflow 1.0.0-beta.103 → 1.0.0-beta.105

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-beta.105
4
+
5
+ ### Patch Changes
6
+
7
+ - 75763b0: agents: tag outgoing requests with an ai-sdk-agent user-agent segment for usage attribution (tool-loop, workflow)
8
+ - Updated dependencies [75763b0]
9
+ - ai@7.0.0-beta.185
10
+
11
+ ## 1.0.0-beta.104
12
+
13
+ ### Patch Changes
14
+
15
+ - 43543dc: Add `experimental_sandbox` support to `WorkflowAgent`. The sandbox is passed to tool execution, configurable on the constructor or per stream, and available to `prepareStep` for per-step overrides.
16
+
3
17
  ## 1.0.0-beta.103
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
2
  import { Context, HasRequiredKey, InferToolSetContext } from '@ai-sdk/provider-utils';
3
- import { ToolSet, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, GenerateTextOnStepEndCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
3
+ import { ToolSet, LanguageModel, Instructions, ToolChoice, TelemetryOptions as TelemetryOptions$1, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, Experimental_SandboxSession, StepResult, GenerateTextOnStepEndCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
4
4
  export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
5
5
 
6
6
  /**
@@ -193,6 +193,10 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet, TRuntimeContext exte
193
193
  * `prepareStep` to update it for the current and subsequent steps.
194
194
  */
195
195
  toolsContext: InferToolSetContext<TTools>;
196
+ /**
197
+ * The sandbox environment that the step is operating in.
198
+ */
199
+ experimental_sandbox?: Experimental_SandboxSession;
196
200
  }
197
201
  /**
198
202
  * Return type from the prepareStep callback.
@@ -231,6 +235,10 @@ interface PrepareStepResult<TTools extends ToolSet = ToolSet, TRuntimeContext ex
231
235
  * Returning a value replaces the agent's tools context.
232
236
  */
233
237
  toolsContext?: InferToolSetContext<TTools>;
238
+ /**
239
+ * Override the sandbox environment for this step.
240
+ */
241
+ experimental_sandbox?: Experimental_SandboxSession;
234
242
  }
235
243
  /**
236
244
  * Callback function called before each step in the agent loop.
@@ -354,6 +362,13 @@ type WorkflowAgentOptions<TTools extends ToolSet = ToolSet, TRuntimeContext exte
354
362
  * Per-stream `experimental_download` values passed to `stream()` override this default.
355
363
  */
356
364
  experimental_download?: DownloadFunction;
365
+ /**
366
+ * Default sandbox environment passed through to tool execution as
367
+ * `experimental_sandbox`.
368
+ *
369
+ * Per-stream `experimental_sandbox` values passed to `stream()` override this default.
370
+ */
371
+ experimental_sandbox?: Experimental_SandboxSession;
357
372
  /**
358
373
  * Default callback function called before each step in the agent loop.
359
374
  * Use this to modify settings, manage context, or inject messages dynamically
@@ -703,6 +718,11 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
703
718
  * By default, files are downloaded if the model does not support the URL for the given media type.
704
719
  */
705
720
  experimental_download?: DownloadFunction;
721
+ /**
722
+ * Sandbox environment passed through to tool execution as
723
+ * `experimental_sandbox`. Overrides the constructor-level value if provided.
724
+ */
725
+ experimental_sandbox?: Experimental_SandboxSession;
706
726
  /**
707
727
  * Callback function to be called after each step completes.
708
728
  */
@@ -905,6 +925,7 @@ declare class WorkflowAgent<TBaseTools extends ToolSet = ToolSet, TRuntimeContex
905
925
  private output?;
906
926
  private experimentalRepairToolCall?;
907
927
  private experimentalDownload?;
928
+ private experimentalSandbox?;
908
929
  private prepareStep?;
909
930
  private allowSystemInMessages;
910
931
  private constructorOnStepEnd?;
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  // src/workflow-agent.ts
2
2
  import {
3
3
  getErrorMessage,
4
- validateTypes
4
+ validateTypes,
5
+ withUserAgentSuffix
5
6
  } from "@ai-sdk/provider-utils";
6
7
  import {
7
8
  Output,
@@ -365,9 +366,10 @@ async function* streamTextIterator({
365
366
  telemetry,
366
367
  includeRawChunks = false,
367
368
  repairToolCall,
368
- responseFormat
369
+ responseFormat,
370
+ experimental_sandbox: sandbox
369
371
  }) {
370
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
372
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
371
373
  let conversationPrompt = [...prompt];
372
374
  let currentModel = model;
373
375
  let currentGenerationSettings = generationSettings != null ? generationSettings : {};
@@ -390,6 +392,7 @@ async function* streamTextIterator({
390
392
  if ((_a = currentGenerationSettings.abortSignal) == null ? void 0 : _a.aborted) {
391
393
  break;
392
394
  }
395
+ let stepSandbox = sandbox;
393
396
  if (prepareStep) {
394
397
  const prepareResult = await prepareStep({
395
398
  model: currentModel,
@@ -397,8 +400,10 @@ async function* streamTextIterator({
397
400
  steps,
398
401
  messages: conversationPrompt,
399
402
  runtimeContext: currentRuntimeContext,
400
- toolsContext: currentToolsContext
403
+ toolsContext: currentToolsContext,
404
+ experimental_sandbox: sandbox
401
405
  });
406
+ stepSandbox = (_b = prepareResult == null ? void 0 : prepareResult.experimental_sandbox) != null ? _b : sandbox;
402
407
  if ((prepareResult == null ? void 0 : prepareResult.model) !== void 0) {
403
408
  currentModel = prepareResult.model;
404
409
  }
@@ -508,7 +513,7 @@ async function* streamTextIterator({
508
513
  });
509
514
  }
510
515
  const stepStartModelInfo = getModelInfo(currentModel);
511
- await ((_b = telemetryDispatcher.onStepStart) == null ? void 0 : _b.call(telemetryDispatcher, {
516
+ await ((_c = telemetryDispatcher.onStepStart) == null ? void 0 : _c.call(telemetryDispatcher, {
512
517
  callId: "workflow-agent",
513
518
  provider: stepStartModelInfo.provider,
514
519
  modelId: stepStartModelInfo.modelId,
@@ -525,13 +530,13 @@ async function* streamTextIterator({
525
530
  toolsContext: currentToolsContext
526
531
  }));
527
532
  try {
528
- const effectiveTools = currentActiveTools && currentActiveTools.length > 0 ? (_c = filterActiveTools({
533
+ const effectiveTools = currentActiveTools && currentActiveTools.length > 0 ? (_d = filterActiveTools({
529
534
  tools,
530
535
  activeTools: currentActiveTools
531
- })) != null ? _c : tools : tools;
536
+ })) != null ? _d : tools : tools;
532
537
  const serializedTools = serializeToolSet(effectiveTools);
533
538
  const modelCallInfo = getModelInfo(currentModel);
534
- await ((_d = telemetryDispatcher.onLanguageModelCallStart) == null ? void 0 : _d.call(telemetryDispatcher, {
539
+ await ((_e = telemetryDispatcher.onLanguageModelCallStart) == null ? void 0 : _e.call(telemetryDispatcher, {
535
540
  callId: "workflow-agent",
536
541
  provider: modelCallInfo.provider,
537
542
  modelId: modelCallInfo.modelId,
@@ -565,10 +570,10 @@ async function* streamTextIterator({
565
570
  stepNumber
566
571
  }
567
572
  );
568
- await ((_i = telemetryDispatcher.onLanguageModelCallEnd) == null ? void 0 : _i.call(telemetryDispatcher, {
573
+ await ((_j = telemetryDispatcher.onLanguageModelCallEnd) == null ? void 0 : _j.call(telemetryDispatcher, {
569
574
  callId: step.callId,
570
- provider: (_f = (_e = step.model) == null ? void 0 : _e.provider) != null ? _f : "unknown",
571
- modelId: (_h = (_g = step.model) == null ? void 0 : _g.modelId) != null ? _h : "unknown",
575
+ provider: (_g = (_f = step.model) == null ? void 0 : _f.provider) != null ? _g : "unknown",
576
+ modelId: (_i = (_h = step.model) == null ? void 0 : _h.modelId) != null ? _i : "unknown",
572
577
  finishReason: step.finishReason,
573
578
  usage: step.usage,
574
579
  content: step.content,
@@ -603,6 +608,7 @@ async function* streamTextIterator({
603
608
  step,
604
609
  runtimeContext: currentRuntimeContext,
605
610
  toolsContext: currentToolsContext,
611
+ experimental_sandbox: stepSandbox,
606
612
  providerExecutedToolResults
607
613
  };
608
614
  conversationPrompt.push({
@@ -647,7 +653,7 @@ async function* streamTextIterator({
647
653
  if (resolvedOnStepEnd) {
648
654
  await resolvedOnStepEnd(step);
649
655
  }
650
- await ((_j = telemetryDispatcher.onStepEnd) == null ? void 0 : _j.call(telemetryDispatcher, normalizeStepForTelemetry(step)));
656
+ await ((_k = telemetryDispatcher.onStepEnd) == null ? void 0 : _k.call(telemetryDispatcher, normalizeStepForTelemetry(step)));
651
657
  } catch (error) {
652
658
  if (onError) {
653
659
  await onError({ error });
@@ -661,7 +667,8 @@ async function* streamTextIterator({
661
667
  messages: conversationPrompt,
662
668
  step: lastStep,
663
669
  runtimeContext: currentRuntimeContext,
664
- toolsContext: currentToolsContext
670
+ toolsContext: currentToolsContext,
671
+ experimental_sandbox: sandbox
665
672
  };
666
673
  }
667
674
  return conversationPrompt;
@@ -715,6 +722,7 @@ var WorkflowAgent = class {
715
722
  this.output = options.output;
716
723
  this.experimentalRepairToolCall = options.experimental_repairToolCall;
717
724
  this.experimentalDownload = options.experimental_download;
725
+ this.experimentalSandbox = options.experimental_sandbox;
718
726
  this.prepareStep = options.prepareStep;
719
727
  this.constructorOnStepEnd = (_c = options.onStepEnd) != null ? _c : options.onStepFinish;
720
728
  const { onFinish, onEnd = onFinish } = options;
@@ -744,7 +752,7 @@ var WorkflowAgent = class {
744
752
  throw new Error("Not implemented");
745
753
  }
746
754
  async stream(options) {
747
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
755
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R;
748
756
  const { onFinish, onEnd = onFinish } = options;
749
757
  let effectiveModel = this.model;
750
758
  let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
@@ -816,6 +824,7 @@ var WorkflowAgent = class {
816
824
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
817
825
  });
818
826
  const download = (_i = options.experimental_download) != null ? _i : this.experimentalDownload;
827
+ const sandbox = (_j = options.experimental_sandbox) != null ? _j : this.experimentalSandbox;
819
828
  const collectedApprovals = collectToolApprovals({
820
829
  messages: prompt.messages
821
830
  });
@@ -884,7 +893,7 @@ var WorkflowAgent = class {
884
893
  runtimeContext: effectiveRuntimeContext
885
894
  });
886
895
  if (policyDenied.length > 0) {
887
- revalidationReason = (_j = policyDenied[0].approvalResponse.reason) != null ? _j : "Tool approval denied";
896
+ revalidationReason = (_k = policyDenied[0].approvalResponse.reason) != null ? _k : "Tool approval denied";
888
897
  }
889
898
  } catch (error) {
890
899
  revalidationReason = getErrorMessage(error);
@@ -921,7 +930,7 @@ var WorkflowAgent = class {
921
930
  input: approval.input
922
931
  };
923
932
  const messages2 = prompt.messages;
924
- await ((_k = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _k.call(telemetryDispatcher, {
933
+ await ((_l = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _l.call(telemetryDispatcher, {
925
934
  toolCall: toolCallEvent,
926
935
  stepNumber: 0,
927
936
  messages: messages2,
@@ -931,14 +940,15 @@ var WorkflowAgent = class {
931
940
  const executeApprovedTool = () => execute(approval.input, {
932
941
  toolCallId: approval.toolCallId,
933
942
  messages: [],
934
- context: resolvedContext
943
+ context: resolvedContext,
944
+ experimental_sandbox: sandbox
935
945
  });
936
946
  const toolResult = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
937
947
  callId: "workflow-agent",
938
948
  toolCallId: approval.toolCallId,
939
949
  execute: executeApprovedTool
940
950
  }) : await executeApprovedTool();
941
- await ((_l = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _l.call(telemetryDispatcher, {
951
+ await ((_m = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _m.call(telemetryDispatcher, {
942
952
  toolCall: toolCallEvent,
943
953
  stepNumber: 0,
944
954
  durationMs: Date.now() - startTime,
@@ -970,7 +980,7 @@ var WorkflowAgent = class {
970
980
  });
971
981
  } catch (error) {
972
982
  const errorMessage = getErrorMessage(error);
973
- await ((_m = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _m.call(telemetryDispatcher, {
983
+ await ((_n = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _n.call(telemetryDispatcher, {
974
984
  toolCall: {
975
985
  type: "tool-call",
976
986
  toolCallId: approval.toolCallId,
@@ -1070,7 +1080,7 @@ var WorkflowAgent = class {
1070
1080
  download
1071
1081
  });
1072
1082
  const effectiveAbortSignal = mergeAbortSignals(
1073
- (_n = options.abortSignal) != null ? _n : effectiveGenerationSettings.abortSignal,
1083
+ (_o = options.abortSignal) != null ? _o : effectiveGenerationSettings.abortSignal,
1074
1084
  options.timeout
1075
1085
  );
1076
1086
  const mergedGenerationSettings = {
@@ -1104,9 +1114,13 @@ var WorkflowAgent = class {
1104
1114
  providerOptions: options.providerOptions
1105
1115
  }
1106
1116
  };
1117
+ mergedGenerationSettings.headers = withUserAgentSuffix(
1118
+ (_p = mergedGenerationSettings.headers) != null ? _p : {},
1119
+ "ai-sdk-agent/workflow"
1120
+ );
1107
1121
  const mergedOnStepEnd = mergeCallbacks(
1108
1122
  this.constructorOnStepEnd,
1109
- (_o = options.onStepEnd) != null ? _o : options.onStepFinish
1123
+ (_q = options.onStepEnd) != null ? _q : options.onStepFinish
1110
1124
  );
1111
1125
  const mergedOnEnd = mergeCallbacks(
1112
1126
  this.constructorOnEnd,
@@ -1129,11 +1143,11 @@ var WorkflowAgent = class {
1129
1143
  options.onToolExecutionEnd
1130
1144
  );
1131
1145
  const effectiveToolChoice = effectiveToolChoiceFromPrepare;
1132
- const effectiveActiveTools = (_p = options.activeTools) != null ? _p : this.activeTools;
1133
- const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_q = filterActiveTools2({
1146
+ const effectiveActiveTools = (_r = options.activeTools) != null ? _r : this.activeTools;
1147
+ const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_s = filterActiveTools2({
1134
1148
  tools: this.tools,
1135
1149
  activeTools: effectiveActiveTools
1136
- })) != null ? _q : this.tools : this.tools;
1150
+ })) != null ? _s : this.tools : this.tools;
1137
1151
  const effectiveModelInfo = getModelInfo2(effectiveModel);
1138
1152
  let runtimeContext = effectiveRuntimeContext;
1139
1153
  let toolsContext = effectiveToolsContext;
@@ -1148,7 +1162,7 @@ var WorkflowAgent = class {
1148
1162
  toolsContext
1149
1163
  });
1150
1164
  }
1151
- await ((_t = telemetryDispatcher.onStart) == null ? void 0 : _t.call(telemetryDispatcher, {
1165
+ await ((_v = telemetryDispatcher.onStart) == null ? void 0 : _v.call(telemetryDispatcher, {
1152
1166
  callId: "workflow-agent",
1153
1167
  operationId: "ai.workflowAgent.stream",
1154
1168
  provider: effectiveModelInfo.provider,
@@ -1166,15 +1180,15 @@ var WorkflowAgent = class {
1166
1180
  frequencyPenalty: mergedGenerationSettings.frequencyPenalty,
1167
1181
  stopSequences: mergedGenerationSettings.stopSequences,
1168
1182
  seed: mergedGenerationSettings.seed,
1169
- maxRetries: (_r = mergedGenerationSettings.maxRetries) != null ? _r : 2,
1183
+ maxRetries: (_t = mergedGenerationSettings.maxRetries) != null ? _t : 2,
1170
1184
  timeout: void 0,
1171
1185
  headers: mergedGenerationSettings.headers,
1172
1186
  providerOptions: mergedGenerationSettings.providerOptions,
1173
- output: (_s = options.output) != null ? _s : this.output,
1187
+ output: (_u = options.output) != null ? _u : this.output,
1174
1188
  runtimeContext,
1175
1189
  toolsContext
1176
1190
  }));
1177
- const executeToolWithCallbacks = async (toolCall, tools, messages2, perToolContexts, currentStepNumber = 0) => {
1191
+ const executeToolWithCallbacks = async (toolCall, tools, messages2, perToolContexts, currentStepNumber = 0, stepSandbox) => {
1178
1192
  var _a2, _b2, _c2, _d2;
1179
1193
  const toolCallEvent = {
1180
1194
  type: "tool-call",
@@ -1206,7 +1220,14 @@ var WorkflowAgent = class {
1206
1220
  const startTime = Date.now();
1207
1221
  let result;
1208
1222
  try {
1209
- const execute = () => executeTool(toolCall, tools, messages2, resolvedContext, download);
1223
+ const execute = () => executeTool(
1224
+ toolCall,
1225
+ tools,
1226
+ messages2,
1227
+ resolvedContext,
1228
+ download,
1229
+ stepSandbox
1230
+ );
1210
1231
  result = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
1211
1232
  callId: "workflow-agent",
1212
1233
  toolCallId: toolCall.toolCallId,
@@ -1313,7 +1334,7 @@ var WorkflowAgent = class {
1313
1334
  }
1314
1335
  }));
1315
1336
  };
1316
- if ((_u = mergedGenerationSettings.abortSignal) == null ? void 0 : _u.aborted) {
1337
+ if ((_w = mergedGenerationSettings.abortSignal) == null ? void 0 : _w.aborted) {
1317
1338
  if (options.onAbort) {
1318
1339
  await options.onAbort({ steps });
1319
1340
  }
@@ -1330,19 +1351,20 @@ var WorkflowAgent = class {
1330
1351
  tools: effectiveTools,
1331
1352
  writable: options.writable,
1332
1353
  prompt: modelPrompt,
1333
- stopConditions: (_v = options.stopWhen) != null ? _v : this.stopWhen,
1354
+ stopConditions: (_x = options.stopWhen) != null ? _x : this.stopWhen,
1334
1355
  onStepEnd: mergedOnStepEnd,
1335
1356
  onStepStart: mergedOnStepStart,
1336
1357
  onError: options.onError,
1337
- prepareStep: (_w = options.prepareStep) != null ? _w : this.prepareStep,
1358
+ prepareStep: (_y = options.prepareStep) != null ? _y : this.prepareStep,
1338
1359
  generationSettings: mergedGenerationSettings,
1339
1360
  toolChoice: effectiveToolChoice,
1340
1361
  runtimeContext,
1341
1362
  toolsContext,
1342
1363
  telemetry: effectiveTelemetry,
1343
- includeRawChunks: (_x = options.includeRawChunks) != null ? _x : false,
1344
- repairToolCall: (_y = options.experimental_repairToolCall) != null ? _y : this.experimentalRepairToolCall,
1345
- responseFormat: await ((_A = (_z = options.output) != null ? _z : this.output) == null ? void 0 : _A.responseFormat)
1364
+ includeRawChunks: (_z = options.includeRawChunks) != null ? _z : false,
1365
+ repairToolCall: (_A = options.experimental_repairToolCall) != null ? _A : this.experimentalRepairToolCall,
1366
+ responseFormat: await ((_C = (_B = options.output) != null ? _B : this.output) == null ? void 0 : _C.responseFormat),
1367
+ experimental_sandbox: sandbox
1346
1368
  });
1347
1369
  let finalMessages;
1348
1370
  let encounteredError;
@@ -1350,7 +1372,7 @@ var WorkflowAgent = class {
1350
1372
  try {
1351
1373
  let result = await iterator.next();
1352
1374
  while (!result.done) {
1353
- if ((_B = mergedGenerationSettings.abortSignal) == null ? void 0 : _B.aborted) {
1375
+ if ((_D = mergedGenerationSettings.abortSignal) == null ? void 0 : _D.aborted) {
1354
1376
  wasAborted = true;
1355
1377
  if (options.onAbort) {
1356
1378
  await options.onAbort({ steps });
@@ -1363,8 +1385,10 @@ var WorkflowAgent = class {
1363
1385
  step,
1364
1386
  runtimeContext: yieldedRuntimeContext,
1365
1387
  toolsContext: yieldedToolsContext,
1388
+ experimental_sandbox: stepSandbox,
1366
1389
  providerExecutedToolResults
1367
1390
  } = result.value;
1391
+ const toolExecutionSandbox = stepSandbox != null ? stepSandbox : sandbox;
1368
1392
  const currentStepNumber = steps.length;
1369
1393
  if (step) {
1370
1394
  steps.push(step);
@@ -1419,7 +1443,8 @@ var WorkflowAgent = class {
1419
1443
  effectiveTools,
1420
1444
  iterMessages,
1421
1445
  toolsContext,
1422
- currentStepNumber
1446
+ currentStepNumber,
1447
+ toolExecutionSandbox
1423
1448
  )
1424
1449
  )
1425
1450
  );
@@ -1483,8 +1508,8 @@ var WorkflowAgent = class {
1483
1508
  await mergedOnEnd({
1484
1509
  steps,
1485
1510
  messages: messages2,
1486
- text: (_C = lastStep == null ? void 0 : lastStep.text) != null ? _C : "",
1487
- finishReason: (_D = lastStep == null ? void 0 : lastStep.finishReason) != null ? _D : "other",
1511
+ text: (_E = lastStep == null ? void 0 : lastStep.text) != null ? _E : "",
1512
+ finishReason: (_F = lastStep == null ? void 0 : lastStep.finishReason) != null ? _F : "other",
1488
1513
  usage: totalUsage,
1489
1514
  totalUsage,
1490
1515
  runtimeContext,
@@ -1496,7 +1521,7 @@ var WorkflowAgent = class {
1496
1521
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1497
1522
  const lastStep = telemetrySteps[telemetrySteps.length - 1];
1498
1523
  const totalUsage = aggregateUsage(steps);
1499
- await ((_E = telemetryDispatcher.onEnd) == null ? void 0 : _E.call(telemetryDispatcher, {
1524
+ await ((_G = telemetryDispatcher.onEnd) == null ? void 0 : _G.call(telemetryDispatcher, {
1500
1525
  ...lastStep,
1501
1526
  steps: telemetrySteps,
1502
1527
  usage: totalUsage,
@@ -1521,8 +1546,8 @@ var WorkflowAgent = class {
1521
1546
  }
1522
1547
  }
1523
1548
  if (options.writable) {
1524
- const sendFinish = (_F = options.sendFinish) != null ? _F : true;
1525
- const preventClose = (_G = options.preventClose) != null ? _G : false;
1549
+ const sendFinish = (_H = options.sendFinish) != null ? _H : true;
1550
+ const preventClose = (_I = options.preventClose) != null ? _I : false;
1526
1551
  if (sendFinish || !preventClose) {
1527
1552
  await closeStream(options.writable, preventClose, sendFinish);
1528
1553
  }
@@ -1542,7 +1567,8 @@ var WorkflowAgent = class {
1542
1567
  effectiveTools,
1543
1568
  iterMessages,
1544
1569
  toolsContext,
1545
- currentStepNumber
1570
+ currentStepNumber,
1571
+ toolExecutionSandbox
1546
1572
  )
1547
1573
  )
1548
1574
  );
@@ -1645,10 +1671,10 @@ var WorkflowAgent = class {
1645
1671
  } else if (options.onError) {
1646
1672
  await options.onError({ error });
1647
1673
  }
1648
- await ((_H = telemetryDispatcher.onError) == null ? void 0 : _H.call(telemetryDispatcher, error));
1674
+ await ((_J = telemetryDispatcher.onError) == null ? void 0 : _J.call(telemetryDispatcher, error));
1649
1675
  }
1650
1676
  const messages = finalMessages != null ? finalMessages : prompt.messages;
1651
- const effectiveOutput = (_I = options.output) != null ? _I : this.output;
1677
+ const effectiveOutput = (_K = options.output) != null ? _K : this.output;
1652
1678
  let experimentalOutput = void 0;
1653
1679
  if (effectiveOutput && steps.length > 0) {
1654
1680
  const lastStep = steps[steps.length - 1];
@@ -1676,8 +1702,8 @@ var WorkflowAgent = class {
1676
1702
  await mergedOnEnd({
1677
1703
  steps,
1678
1704
  messages,
1679
- text: (_J = lastStep == null ? void 0 : lastStep.text) != null ? _J : "",
1680
- finishReason: (_K = lastStep == null ? void 0 : lastStep.finishReason) != null ? _K : "other",
1705
+ text: (_L = lastStep == null ? void 0 : lastStep.text) != null ? _L : "",
1706
+ finishReason: (_M = lastStep == null ? void 0 : lastStep.finishReason) != null ? _M : "other",
1681
1707
  usage: totalUsage,
1682
1708
  totalUsage,
1683
1709
  runtimeContext,
@@ -1689,7 +1715,7 @@ var WorkflowAgent = class {
1689
1715
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1690
1716
  const lastStep = telemetrySteps[telemetrySteps.length - 1];
1691
1717
  const totalUsage = aggregateUsage(steps);
1692
- await ((_L = telemetryDispatcher.onEnd) == null ? void 0 : _L.call(telemetryDispatcher, {
1718
+ await ((_N = telemetryDispatcher.onEnd) == null ? void 0 : _N.call(telemetryDispatcher, {
1693
1719
  ...lastStep,
1694
1720
  steps: telemetrySteps,
1695
1721
  usage: totalUsage,
@@ -1698,8 +1724,8 @@ var WorkflowAgent = class {
1698
1724
  }
1699
1725
  if (encounteredError) {
1700
1726
  if (options.writable) {
1701
- const sendFinish = (_M = options.sendFinish) != null ? _M : true;
1702
- const preventClose = (_N = options.preventClose) != null ? _N : false;
1727
+ const sendFinish = (_O = options.sendFinish) != null ? _O : true;
1728
+ const preventClose = (_P = options.preventClose) != null ? _P : false;
1703
1729
  if (sendFinish || !preventClose) {
1704
1730
  await closeStream(options.writable, preventClose, sendFinish);
1705
1731
  }
@@ -1707,8 +1733,8 @@ var WorkflowAgent = class {
1707
1733
  throw encounteredError;
1708
1734
  }
1709
1735
  if (options.writable) {
1710
- const sendFinish = (_O = options.sendFinish) != null ? _O : true;
1711
- const preventClose = (_P = options.preventClose) != null ? _P : false;
1736
+ const sendFinish = (_Q = options.sendFinish) != null ? _Q : true;
1737
+ const preventClose = (_R = options.preventClose) != null ? _R : false;
1712
1738
  if (sendFinish || !preventClose) {
1713
1739
  await closeStream(options.writable, preventClose, sendFinish);
1714
1740
  }
@@ -1894,7 +1920,7 @@ function getToolCallbackMessages(messages) {
1894
1920
  const withoutAssistantToolCall = ((_a = messages.at(-1)) == null ? void 0 : _a.role) === "assistant" ? messages.slice(0, -1) : messages;
1895
1921
  return withoutAssistantToolCall;
1896
1922
  }
1897
- async function executeTool(toolCall, tools, messages, context, download) {
1923
+ async function executeTool(toolCall, tools, messages, context, download, sandbox) {
1898
1924
  const tool2 = tools[toolCall.toolName];
1899
1925
  if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);
1900
1926
  if (typeof tool2.execute !== "function") {
@@ -1911,7 +1937,8 @@ async function executeTool(toolCall, tools, messages, context, download) {
1911
1937
  // Pass the conversation messages to the tool so it has context about the conversation
1912
1938
  messages,
1913
1939
  // Pass per-tool context to the tool (resolved from `toolsContext`)
1914
- context
1940
+ context,
1941
+ experimental_sandbox: sandbox
1915
1942
  });
1916
1943
  } catch (error) {
1917
1944
  const errorMessage = getErrorMessage(error);