@ai-sdk/workflow 1.0.0-beta.102 → 1.0.0-beta.104

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,20 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-beta.104
4
+
5
+ ### Patch Changes
6
+
7
+ - 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.
8
+
9
+ ## 1.0.0-beta.103
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [0416e3e]
14
+ - @ai-sdk/provider@4.0.0-beta.20
15
+ - ai@7.0.0-beta.184
16
+ - @ai-sdk/provider-utils@5.0.0-beta.50
17
+
3
18
  ## 1.0.0-beta.102
4
19
 
5
20
  ### 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
@@ -365,9 +365,10 @@ async function* streamTextIterator({
365
365
  telemetry,
366
366
  includeRawChunks = false,
367
367
  repairToolCall,
368
- responseFormat
368
+ responseFormat,
369
+ experimental_sandbox: sandbox
369
370
  }) {
370
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
371
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
371
372
  let conversationPrompt = [...prompt];
372
373
  let currentModel = model;
373
374
  let currentGenerationSettings = generationSettings != null ? generationSettings : {};
@@ -390,6 +391,7 @@ async function* streamTextIterator({
390
391
  if ((_a = currentGenerationSettings.abortSignal) == null ? void 0 : _a.aborted) {
391
392
  break;
392
393
  }
394
+ let stepSandbox = sandbox;
393
395
  if (prepareStep) {
394
396
  const prepareResult = await prepareStep({
395
397
  model: currentModel,
@@ -397,8 +399,10 @@ async function* streamTextIterator({
397
399
  steps,
398
400
  messages: conversationPrompt,
399
401
  runtimeContext: currentRuntimeContext,
400
- toolsContext: currentToolsContext
402
+ toolsContext: currentToolsContext,
403
+ experimental_sandbox: sandbox
401
404
  });
405
+ stepSandbox = (_b = prepareResult == null ? void 0 : prepareResult.experimental_sandbox) != null ? _b : sandbox;
402
406
  if ((prepareResult == null ? void 0 : prepareResult.model) !== void 0) {
403
407
  currentModel = prepareResult.model;
404
408
  }
@@ -508,7 +512,7 @@ async function* streamTextIterator({
508
512
  });
509
513
  }
510
514
  const stepStartModelInfo = getModelInfo(currentModel);
511
- await ((_b = telemetryDispatcher.onStepStart) == null ? void 0 : _b.call(telemetryDispatcher, {
515
+ await ((_c = telemetryDispatcher.onStepStart) == null ? void 0 : _c.call(telemetryDispatcher, {
512
516
  callId: "workflow-agent",
513
517
  provider: stepStartModelInfo.provider,
514
518
  modelId: stepStartModelInfo.modelId,
@@ -525,13 +529,13 @@ async function* streamTextIterator({
525
529
  toolsContext: currentToolsContext
526
530
  }));
527
531
  try {
528
- const effectiveTools = currentActiveTools && currentActiveTools.length > 0 ? (_c = filterActiveTools({
532
+ const effectiveTools = currentActiveTools && currentActiveTools.length > 0 ? (_d = filterActiveTools({
529
533
  tools,
530
534
  activeTools: currentActiveTools
531
- })) != null ? _c : tools : tools;
535
+ })) != null ? _d : tools : tools;
532
536
  const serializedTools = serializeToolSet(effectiveTools);
533
537
  const modelCallInfo = getModelInfo(currentModel);
534
- await ((_d = telemetryDispatcher.onLanguageModelCallStart) == null ? void 0 : _d.call(telemetryDispatcher, {
538
+ await ((_e = telemetryDispatcher.onLanguageModelCallStart) == null ? void 0 : _e.call(telemetryDispatcher, {
535
539
  callId: "workflow-agent",
536
540
  provider: modelCallInfo.provider,
537
541
  modelId: modelCallInfo.modelId,
@@ -565,10 +569,10 @@ async function* streamTextIterator({
565
569
  stepNumber
566
570
  }
567
571
  );
568
- await ((_i = telemetryDispatcher.onLanguageModelCallEnd) == null ? void 0 : _i.call(telemetryDispatcher, {
572
+ await ((_j = telemetryDispatcher.onLanguageModelCallEnd) == null ? void 0 : _j.call(telemetryDispatcher, {
569
573
  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",
574
+ provider: (_g = (_f = step.model) == null ? void 0 : _f.provider) != null ? _g : "unknown",
575
+ modelId: (_i = (_h = step.model) == null ? void 0 : _h.modelId) != null ? _i : "unknown",
572
576
  finishReason: step.finishReason,
573
577
  usage: step.usage,
574
578
  content: step.content,
@@ -603,6 +607,7 @@ async function* streamTextIterator({
603
607
  step,
604
608
  runtimeContext: currentRuntimeContext,
605
609
  toolsContext: currentToolsContext,
610
+ experimental_sandbox: stepSandbox,
606
611
  providerExecutedToolResults
607
612
  };
608
613
  conversationPrompt.push({
@@ -647,7 +652,7 @@ async function* streamTextIterator({
647
652
  if (resolvedOnStepEnd) {
648
653
  await resolvedOnStepEnd(step);
649
654
  }
650
- await ((_j = telemetryDispatcher.onStepEnd) == null ? void 0 : _j.call(telemetryDispatcher, normalizeStepForTelemetry(step)));
655
+ await ((_k = telemetryDispatcher.onStepEnd) == null ? void 0 : _k.call(telemetryDispatcher, normalizeStepForTelemetry(step)));
651
656
  } catch (error) {
652
657
  if (onError) {
653
658
  await onError({ error });
@@ -661,7 +666,8 @@ async function* streamTextIterator({
661
666
  messages: conversationPrompt,
662
667
  step: lastStep,
663
668
  runtimeContext: currentRuntimeContext,
664
- toolsContext: currentToolsContext
669
+ toolsContext: currentToolsContext,
670
+ experimental_sandbox: sandbox
665
671
  };
666
672
  }
667
673
  return conversationPrompt;
@@ -715,6 +721,7 @@ var WorkflowAgent = class {
715
721
  this.output = options.output;
716
722
  this.experimentalRepairToolCall = options.experimental_repairToolCall;
717
723
  this.experimentalDownload = options.experimental_download;
724
+ this.experimentalSandbox = options.experimental_sandbox;
718
725
  this.prepareStep = options.prepareStep;
719
726
  this.constructorOnStepEnd = (_c = options.onStepEnd) != null ? _c : options.onStepFinish;
720
727
  const { onFinish, onEnd = onFinish } = options;
@@ -744,7 +751,7 @@ var WorkflowAgent = class {
744
751
  throw new Error("Not implemented");
745
752
  }
746
753
  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;
754
+ 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;
748
755
  const { onFinish, onEnd = onFinish } = options;
749
756
  let effectiveModel = this.model;
750
757
  let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
@@ -816,6 +823,7 @@ var WorkflowAgent = class {
816
823
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
817
824
  });
818
825
  const download = (_i = options.experimental_download) != null ? _i : this.experimentalDownload;
826
+ const sandbox = (_j = options.experimental_sandbox) != null ? _j : this.experimentalSandbox;
819
827
  const collectedApprovals = collectToolApprovals({
820
828
  messages: prompt.messages
821
829
  });
@@ -884,7 +892,7 @@ var WorkflowAgent = class {
884
892
  runtimeContext: effectiveRuntimeContext
885
893
  });
886
894
  if (policyDenied.length > 0) {
887
- revalidationReason = (_j = policyDenied[0].approvalResponse.reason) != null ? _j : "Tool approval denied";
895
+ revalidationReason = (_k = policyDenied[0].approvalResponse.reason) != null ? _k : "Tool approval denied";
888
896
  }
889
897
  } catch (error) {
890
898
  revalidationReason = getErrorMessage(error);
@@ -921,7 +929,7 @@ var WorkflowAgent = class {
921
929
  input: approval.input
922
930
  };
923
931
  const messages2 = prompt.messages;
924
- await ((_k = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _k.call(telemetryDispatcher, {
932
+ await ((_l = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _l.call(telemetryDispatcher, {
925
933
  toolCall: toolCallEvent,
926
934
  stepNumber: 0,
927
935
  messages: messages2,
@@ -931,14 +939,15 @@ var WorkflowAgent = class {
931
939
  const executeApprovedTool = () => execute(approval.input, {
932
940
  toolCallId: approval.toolCallId,
933
941
  messages: [],
934
- context: resolvedContext
942
+ context: resolvedContext,
943
+ experimental_sandbox: sandbox
935
944
  });
936
945
  const toolResult = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
937
946
  callId: "workflow-agent",
938
947
  toolCallId: approval.toolCallId,
939
948
  execute: executeApprovedTool
940
949
  }) : await executeApprovedTool();
941
- await ((_l = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _l.call(telemetryDispatcher, {
950
+ await ((_m = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _m.call(telemetryDispatcher, {
942
951
  toolCall: toolCallEvent,
943
952
  stepNumber: 0,
944
953
  durationMs: Date.now() - startTime,
@@ -970,7 +979,7 @@ var WorkflowAgent = class {
970
979
  });
971
980
  } catch (error) {
972
981
  const errorMessage = getErrorMessage(error);
973
- await ((_m = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _m.call(telemetryDispatcher, {
982
+ await ((_n = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _n.call(telemetryDispatcher, {
974
983
  toolCall: {
975
984
  type: "tool-call",
976
985
  toolCallId: approval.toolCallId,
@@ -1070,7 +1079,7 @@ var WorkflowAgent = class {
1070
1079
  download
1071
1080
  });
1072
1081
  const effectiveAbortSignal = mergeAbortSignals(
1073
- (_n = options.abortSignal) != null ? _n : effectiveGenerationSettings.abortSignal,
1082
+ (_o = options.abortSignal) != null ? _o : effectiveGenerationSettings.abortSignal,
1074
1083
  options.timeout
1075
1084
  );
1076
1085
  const mergedGenerationSettings = {
@@ -1106,7 +1115,7 @@ var WorkflowAgent = class {
1106
1115
  };
1107
1116
  const mergedOnStepEnd = mergeCallbacks(
1108
1117
  this.constructorOnStepEnd,
1109
- (_o = options.onStepEnd) != null ? _o : options.onStepFinish
1118
+ (_p = options.onStepEnd) != null ? _p : options.onStepFinish
1110
1119
  );
1111
1120
  const mergedOnEnd = mergeCallbacks(
1112
1121
  this.constructorOnEnd,
@@ -1129,11 +1138,11 @@ var WorkflowAgent = class {
1129
1138
  options.onToolExecutionEnd
1130
1139
  );
1131
1140
  const effectiveToolChoice = effectiveToolChoiceFromPrepare;
1132
- const effectiveActiveTools = (_p = options.activeTools) != null ? _p : this.activeTools;
1133
- const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_q = filterActiveTools2({
1141
+ const effectiveActiveTools = (_q = options.activeTools) != null ? _q : this.activeTools;
1142
+ const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_r = filterActiveTools2({
1134
1143
  tools: this.tools,
1135
1144
  activeTools: effectiveActiveTools
1136
- })) != null ? _q : this.tools : this.tools;
1145
+ })) != null ? _r : this.tools : this.tools;
1137
1146
  const effectiveModelInfo = getModelInfo2(effectiveModel);
1138
1147
  let runtimeContext = effectiveRuntimeContext;
1139
1148
  let toolsContext = effectiveToolsContext;
@@ -1148,7 +1157,7 @@ var WorkflowAgent = class {
1148
1157
  toolsContext
1149
1158
  });
1150
1159
  }
1151
- await ((_t = telemetryDispatcher.onStart) == null ? void 0 : _t.call(telemetryDispatcher, {
1160
+ await ((_u = telemetryDispatcher.onStart) == null ? void 0 : _u.call(telemetryDispatcher, {
1152
1161
  callId: "workflow-agent",
1153
1162
  operationId: "ai.workflowAgent.stream",
1154
1163
  provider: effectiveModelInfo.provider,
@@ -1166,15 +1175,15 @@ var WorkflowAgent = class {
1166
1175
  frequencyPenalty: mergedGenerationSettings.frequencyPenalty,
1167
1176
  stopSequences: mergedGenerationSettings.stopSequences,
1168
1177
  seed: mergedGenerationSettings.seed,
1169
- maxRetries: (_r = mergedGenerationSettings.maxRetries) != null ? _r : 2,
1178
+ maxRetries: (_s = mergedGenerationSettings.maxRetries) != null ? _s : 2,
1170
1179
  timeout: void 0,
1171
1180
  headers: mergedGenerationSettings.headers,
1172
1181
  providerOptions: mergedGenerationSettings.providerOptions,
1173
- output: (_s = options.output) != null ? _s : this.output,
1182
+ output: (_t = options.output) != null ? _t : this.output,
1174
1183
  runtimeContext,
1175
1184
  toolsContext
1176
1185
  }));
1177
- const executeToolWithCallbacks = async (toolCall, tools, messages2, perToolContexts, currentStepNumber = 0) => {
1186
+ const executeToolWithCallbacks = async (toolCall, tools, messages2, perToolContexts, currentStepNumber = 0, stepSandbox) => {
1178
1187
  var _a2, _b2, _c2, _d2;
1179
1188
  const toolCallEvent = {
1180
1189
  type: "tool-call",
@@ -1206,7 +1215,14 @@ var WorkflowAgent = class {
1206
1215
  const startTime = Date.now();
1207
1216
  let result;
1208
1217
  try {
1209
- const execute = () => executeTool(toolCall, tools, messages2, resolvedContext, download);
1218
+ const execute = () => executeTool(
1219
+ toolCall,
1220
+ tools,
1221
+ messages2,
1222
+ resolvedContext,
1223
+ download,
1224
+ stepSandbox
1225
+ );
1210
1226
  result = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
1211
1227
  callId: "workflow-agent",
1212
1228
  toolCallId: toolCall.toolCallId,
@@ -1313,7 +1329,7 @@ var WorkflowAgent = class {
1313
1329
  }
1314
1330
  }));
1315
1331
  };
1316
- if ((_u = mergedGenerationSettings.abortSignal) == null ? void 0 : _u.aborted) {
1332
+ if ((_v = mergedGenerationSettings.abortSignal) == null ? void 0 : _v.aborted) {
1317
1333
  if (options.onAbort) {
1318
1334
  await options.onAbort({ steps });
1319
1335
  }
@@ -1330,19 +1346,20 @@ var WorkflowAgent = class {
1330
1346
  tools: effectiveTools,
1331
1347
  writable: options.writable,
1332
1348
  prompt: modelPrompt,
1333
- stopConditions: (_v = options.stopWhen) != null ? _v : this.stopWhen,
1349
+ stopConditions: (_w = options.stopWhen) != null ? _w : this.stopWhen,
1334
1350
  onStepEnd: mergedOnStepEnd,
1335
1351
  onStepStart: mergedOnStepStart,
1336
1352
  onError: options.onError,
1337
- prepareStep: (_w = options.prepareStep) != null ? _w : this.prepareStep,
1353
+ prepareStep: (_x = options.prepareStep) != null ? _x : this.prepareStep,
1338
1354
  generationSettings: mergedGenerationSettings,
1339
1355
  toolChoice: effectiveToolChoice,
1340
1356
  runtimeContext,
1341
1357
  toolsContext,
1342
1358
  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)
1359
+ includeRawChunks: (_y = options.includeRawChunks) != null ? _y : false,
1360
+ repairToolCall: (_z = options.experimental_repairToolCall) != null ? _z : this.experimentalRepairToolCall,
1361
+ responseFormat: await ((_B = (_A = options.output) != null ? _A : this.output) == null ? void 0 : _B.responseFormat),
1362
+ experimental_sandbox: sandbox
1346
1363
  });
1347
1364
  let finalMessages;
1348
1365
  let encounteredError;
@@ -1350,7 +1367,7 @@ var WorkflowAgent = class {
1350
1367
  try {
1351
1368
  let result = await iterator.next();
1352
1369
  while (!result.done) {
1353
- if ((_B = mergedGenerationSettings.abortSignal) == null ? void 0 : _B.aborted) {
1370
+ if ((_C = mergedGenerationSettings.abortSignal) == null ? void 0 : _C.aborted) {
1354
1371
  wasAborted = true;
1355
1372
  if (options.onAbort) {
1356
1373
  await options.onAbort({ steps });
@@ -1363,8 +1380,10 @@ var WorkflowAgent = class {
1363
1380
  step,
1364
1381
  runtimeContext: yieldedRuntimeContext,
1365
1382
  toolsContext: yieldedToolsContext,
1383
+ experimental_sandbox: stepSandbox,
1366
1384
  providerExecutedToolResults
1367
1385
  } = result.value;
1386
+ const toolExecutionSandbox = stepSandbox != null ? stepSandbox : sandbox;
1368
1387
  const currentStepNumber = steps.length;
1369
1388
  if (step) {
1370
1389
  steps.push(step);
@@ -1419,7 +1438,8 @@ var WorkflowAgent = class {
1419
1438
  effectiveTools,
1420
1439
  iterMessages,
1421
1440
  toolsContext,
1422
- currentStepNumber
1441
+ currentStepNumber,
1442
+ toolExecutionSandbox
1423
1443
  )
1424
1444
  )
1425
1445
  );
@@ -1483,8 +1503,8 @@ var WorkflowAgent = class {
1483
1503
  await mergedOnEnd({
1484
1504
  steps,
1485
1505
  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",
1506
+ text: (_D = lastStep == null ? void 0 : lastStep.text) != null ? _D : "",
1507
+ finishReason: (_E = lastStep == null ? void 0 : lastStep.finishReason) != null ? _E : "other",
1488
1508
  usage: totalUsage,
1489
1509
  totalUsage,
1490
1510
  runtimeContext,
@@ -1496,7 +1516,7 @@ var WorkflowAgent = class {
1496
1516
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1497
1517
  const lastStep = telemetrySteps[telemetrySteps.length - 1];
1498
1518
  const totalUsage = aggregateUsage(steps);
1499
- await ((_E = telemetryDispatcher.onEnd) == null ? void 0 : _E.call(telemetryDispatcher, {
1519
+ await ((_F = telemetryDispatcher.onEnd) == null ? void 0 : _F.call(telemetryDispatcher, {
1500
1520
  ...lastStep,
1501
1521
  steps: telemetrySteps,
1502
1522
  usage: totalUsage,
@@ -1521,8 +1541,8 @@ var WorkflowAgent = class {
1521
1541
  }
1522
1542
  }
1523
1543
  if (options.writable) {
1524
- const sendFinish = (_F = options.sendFinish) != null ? _F : true;
1525
- const preventClose = (_G = options.preventClose) != null ? _G : false;
1544
+ const sendFinish = (_G = options.sendFinish) != null ? _G : true;
1545
+ const preventClose = (_H = options.preventClose) != null ? _H : false;
1526
1546
  if (sendFinish || !preventClose) {
1527
1547
  await closeStream(options.writable, preventClose, sendFinish);
1528
1548
  }
@@ -1542,7 +1562,8 @@ var WorkflowAgent = class {
1542
1562
  effectiveTools,
1543
1563
  iterMessages,
1544
1564
  toolsContext,
1545
- currentStepNumber
1565
+ currentStepNumber,
1566
+ toolExecutionSandbox
1546
1567
  )
1547
1568
  )
1548
1569
  );
@@ -1645,10 +1666,10 @@ var WorkflowAgent = class {
1645
1666
  } else if (options.onError) {
1646
1667
  await options.onError({ error });
1647
1668
  }
1648
- await ((_H = telemetryDispatcher.onError) == null ? void 0 : _H.call(telemetryDispatcher, error));
1669
+ await ((_I = telemetryDispatcher.onError) == null ? void 0 : _I.call(telemetryDispatcher, error));
1649
1670
  }
1650
1671
  const messages = finalMessages != null ? finalMessages : prompt.messages;
1651
- const effectiveOutput = (_I = options.output) != null ? _I : this.output;
1672
+ const effectiveOutput = (_J = options.output) != null ? _J : this.output;
1652
1673
  let experimentalOutput = void 0;
1653
1674
  if (effectiveOutput && steps.length > 0) {
1654
1675
  const lastStep = steps[steps.length - 1];
@@ -1676,8 +1697,8 @@ var WorkflowAgent = class {
1676
1697
  await mergedOnEnd({
1677
1698
  steps,
1678
1699
  messages,
1679
- text: (_J = lastStep == null ? void 0 : lastStep.text) != null ? _J : "",
1680
- finishReason: (_K = lastStep == null ? void 0 : lastStep.finishReason) != null ? _K : "other",
1700
+ text: (_K = lastStep == null ? void 0 : lastStep.text) != null ? _K : "",
1701
+ finishReason: (_L = lastStep == null ? void 0 : lastStep.finishReason) != null ? _L : "other",
1681
1702
  usage: totalUsage,
1682
1703
  totalUsage,
1683
1704
  runtimeContext,
@@ -1689,7 +1710,7 @@ var WorkflowAgent = class {
1689
1710
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1690
1711
  const lastStep = telemetrySteps[telemetrySteps.length - 1];
1691
1712
  const totalUsage = aggregateUsage(steps);
1692
- await ((_L = telemetryDispatcher.onEnd) == null ? void 0 : _L.call(telemetryDispatcher, {
1713
+ await ((_M = telemetryDispatcher.onEnd) == null ? void 0 : _M.call(telemetryDispatcher, {
1693
1714
  ...lastStep,
1694
1715
  steps: telemetrySteps,
1695
1716
  usage: totalUsage,
@@ -1698,8 +1719,8 @@ var WorkflowAgent = class {
1698
1719
  }
1699
1720
  if (encounteredError) {
1700
1721
  if (options.writable) {
1701
- const sendFinish = (_M = options.sendFinish) != null ? _M : true;
1702
- const preventClose = (_N = options.preventClose) != null ? _N : false;
1722
+ const sendFinish = (_N = options.sendFinish) != null ? _N : true;
1723
+ const preventClose = (_O = options.preventClose) != null ? _O : false;
1703
1724
  if (sendFinish || !preventClose) {
1704
1725
  await closeStream(options.writable, preventClose, sendFinish);
1705
1726
  }
@@ -1707,8 +1728,8 @@ var WorkflowAgent = class {
1707
1728
  throw encounteredError;
1708
1729
  }
1709
1730
  if (options.writable) {
1710
- const sendFinish = (_O = options.sendFinish) != null ? _O : true;
1711
- const preventClose = (_P = options.preventClose) != null ? _P : false;
1731
+ const sendFinish = (_P = options.sendFinish) != null ? _P : true;
1732
+ const preventClose = (_Q = options.preventClose) != null ? _Q : false;
1712
1733
  if (sendFinish || !preventClose) {
1713
1734
  await closeStream(options.writable, preventClose, sendFinish);
1714
1735
  }
@@ -1894,7 +1915,7 @@ function getToolCallbackMessages(messages) {
1894
1915
  const withoutAssistantToolCall = ((_a = messages.at(-1)) == null ? void 0 : _a.role) === "assistant" ? messages.slice(0, -1) : messages;
1895
1916
  return withoutAssistantToolCall;
1896
1917
  }
1897
- async function executeTool(toolCall, tools, messages, context, download) {
1918
+ async function executeTool(toolCall, tools, messages, context, download, sandbox) {
1898
1919
  const tool2 = tools[toolCall.toolName];
1899
1920
  if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);
1900
1921
  if (typeof tool2.execute !== "function") {
@@ -1911,7 +1932,8 @@ async function executeTool(toolCall, tools, messages, context, download) {
1911
1932
  // Pass the conversation messages to the tool so it has context about the conversation
1912
1933
  messages,
1913
1934
  // Pass per-tool context to the tool (resolved from `toolsContext`)
1914
- context
1935
+ context,
1936
+ experimental_sandbox: sandbox
1915
1937
  });
1916
1938
  } catch (error) {
1917
1939
  const errorMessage = getErrorMessage(error);