@ai-sdk/workflow 1.0.38 → 1.0.40

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,26 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.40
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [c3782a6]
8
+ - ai@7.0.40
9
+
10
+ ## 1.0.39
11
+
12
+ ### Patch Changes
13
+
14
+ - 1cff1eb: feat(workflow): support dynamic tool descriptions
15
+ - b666f57: feat(workflow): add stream instructions and initial prepareStep inputs
16
+ - d56638a: feat(workflow): add prepareCall setting parity
17
+ - c1100c4: refactor(workflow): simplify prepareStep overrides
18
+ - Updated dependencies [0c464d9]
19
+ - Updated dependencies [09a52cb]
20
+ - Updated dependencies [c49380c]
21
+ - @ai-sdk/provider-utils@5.0.14
22
+ - ai@7.0.39
23
+
3
24
  ## 1.0.38
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageModelV4, LanguageModelV4CallOptions, SharedV4ProviderOptions, 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, Experimental_SandboxSession, 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, ModelMessage, StepResult, GenerateTextOnStepEndCallback, 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
  /**
@@ -172,6 +172,14 @@ interface PrepareStepInfo<TTools extends ToolSet = ToolSet, TRuntimeContext exte
172
172
  * The function should return a LanguageModelV4 instance.
173
173
  */
174
174
  model: LanguageModel;
175
+ /**
176
+ * The initial instructions passed to the stream.
177
+ */
178
+ initialInstructions: Instructions | undefined;
179
+ /**
180
+ * The initial messages passed to the stream.
181
+ */
182
+ initialMessages: Array<ModelMessage>;
175
183
  /**
176
184
  * The current step number (0-indexed).
177
185
  */
@@ -258,6 +266,9 @@ interface PrepareCallOptions<TTools extends ToolSet = ToolSet, TRuntimeContext e
258
266
  tools: TTools;
259
267
  instructions?: Instructions;
260
268
  toolChoice?: ToolChoice<TTools>;
269
+ stopWhen?: StopCondition<NoInfer<ToolSet>, any> | Array<StopCondition<NoInfer<ToolSet>, any>>;
270
+ activeTools?: ActiveTools<NoInfer<TTools>>;
271
+ experimental_download?: DownloadFunction;
261
272
  telemetry?: TelemetryOptions<TRuntimeContext, TTools>;
262
273
  /**
263
274
  * Runtime context that flows through the agent loop.
@@ -617,7 +628,13 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, TRuntimeContex
617
628
  prompt?: never;
618
629
  }) & {
619
630
  /**
620
- * Optional system prompt override. If provided, overrides the system prompt from the constructor.
631
+ * Instructions override for this stream call.
632
+ */
633
+ instructions?: Instructions;
634
+ /**
635
+ * Optional system prompt override.
636
+ *
637
+ * @deprecated Use `instructions` instead.
621
638
  */
622
639
  system?: string;
623
640
  /**
package/dist/index.js CHANGED
@@ -80,16 +80,26 @@ import {
80
80
  } from "ai";
81
81
 
82
82
  // src/serializable-schema.ts
83
- import { asSchema, jsonSchema } from "@ai-sdk/provider-utils";
83
+ import {
84
+ asSchema,
85
+ jsonSchema
86
+ } from "@ai-sdk/provider-utils";
84
87
  import { tool } from "ai";
85
88
  import Ajv from "ajv";
86
- function serializeToolSet(tools) {
89
+ function serializeToolSet(tools, {
90
+ toolsContext = {},
91
+ experimental_sandbox: sandbox
92
+ } = {}) {
87
93
  return Object.fromEntries(
88
94
  Object.entries(tools).map(([name, t]) => {
89
95
  var _a;
90
96
  const def = {
91
- description: t.description,
92
- // TODO support tools with function descriptions
97
+ description: resolveToolDescription({
98
+ tool: t,
99
+ toolName: name,
100
+ toolsContext,
101
+ experimental_sandbox: sandbox
102
+ }),
93
103
  inputSchema: asSchema(t.inputSchema).jsonSchema
94
104
  };
95
105
  if (t.type === "provider") {
@@ -102,6 +112,17 @@ function serializeToolSet(tools) {
102
112
  })
103
113
  );
104
114
  }
115
+ function resolveToolDescription({
116
+ tool: tool2,
117
+ toolName,
118
+ toolsContext,
119
+ experimental_sandbox: sandbox
120
+ }) {
121
+ return tool2.description === void 0 ? void 0 : typeof tool2.description === "string" ? tool2.description : tool2.description({
122
+ context: toolsContext[toolName],
123
+ experimental_sandbox: sandbox
124
+ });
125
+ }
105
126
  function resolveSerializableTools(tools) {
106
127
  const ajv = new Ajv();
107
128
  return Object.fromEntries(
@@ -260,8 +281,33 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
260
281
  }
261
282
 
262
283
  // src/stream-text-iterator.ts
284
+ var prepareStepGenerationSettingKeys = [
285
+ "maxOutputTokens",
286
+ "temperature",
287
+ "topP",
288
+ "topK",
289
+ "presencePenalty",
290
+ "frequencyPenalty",
291
+ "stopSequences",
292
+ "seed",
293
+ "maxRetries",
294
+ "headers",
295
+ "reasoning",
296
+ "providerOptions"
297
+ ];
298
+ function mergePrepareStepGenerationSettings(current, overrides) {
299
+ const definedOverrides = {};
300
+ for (const key of prepareStepGenerationSettingKeys) {
301
+ if (overrides[key] !== void 0) {
302
+ Object.assign(definedOverrides, { [key]: overrides[key] });
303
+ }
304
+ }
305
+ return { ...current, ...definedOverrides };
306
+ }
263
307
  async function* streamTextIterator({
264
308
  prompt,
309
+ initialInstructions,
310
+ initialMessages = prompt,
265
311
  tools = {},
266
312
  writable,
267
313
  model,
@@ -308,6 +354,8 @@ async function* streamTextIterator({
308
354
  if (prepareStep) {
309
355
  const prepareResult = await prepareStep({
310
356
  model: currentModel,
357
+ initialInstructions,
358
+ initialMessages,
311
359
  stepNumber,
312
360
  steps,
313
361
  messages: conversationPrompt,
@@ -344,78 +392,10 @@ async function* streamTextIterator({
344
392
  if ((prepareResult == null ? void 0 : prepareResult.activeTools) !== void 0) {
345
393
  currentActiveTools = prepareResult.activeTools;
346
394
  }
347
- if ((prepareResult == null ? void 0 : prepareResult.maxOutputTokens) !== void 0) {
348
- currentGenerationSettings = {
349
- ...currentGenerationSettings,
350
- maxOutputTokens: prepareResult.maxOutputTokens
351
- };
352
- }
353
- if ((prepareResult == null ? void 0 : prepareResult.temperature) !== void 0) {
354
- currentGenerationSettings = {
355
- ...currentGenerationSettings,
356
- temperature: prepareResult.temperature
357
- };
358
- }
359
- if ((prepareResult == null ? void 0 : prepareResult.topP) !== void 0) {
360
- currentGenerationSettings = {
361
- ...currentGenerationSettings,
362
- topP: prepareResult.topP
363
- };
364
- }
365
- if ((prepareResult == null ? void 0 : prepareResult.topK) !== void 0) {
366
- currentGenerationSettings = {
367
- ...currentGenerationSettings,
368
- topK: prepareResult.topK
369
- };
370
- }
371
- if ((prepareResult == null ? void 0 : prepareResult.presencePenalty) !== void 0) {
372
- currentGenerationSettings = {
373
- ...currentGenerationSettings,
374
- presencePenalty: prepareResult.presencePenalty
375
- };
376
- }
377
- if ((prepareResult == null ? void 0 : prepareResult.frequencyPenalty) !== void 0) {
378
- currentGenerationSettings = {
379
- ...currentGenerationSettings,
380
- frequencyPenalty: prepareResult.frequencyPenalty
381
- };
382
- }
383
- if ((prepareResult == null ? void 0 : prepareResult.stopSequences) !== void 0) {
384
- currentGenerationSettings = {
385
- ...currentGenerationSettings,
386
- stopSequences: prepareResult.stopSequences
387
- };
388
- }
389
- if ((prepareResult == null ? void 0 : prepareResult.seed) !== void 0) {
390
- currentGenerationSettings = {
391
- ...currentGenerationSettings,
392
- seed: prepareResult.seed
393
- };
394
- }
395
- if ((prepareResult == null ? void 0 : prepareResult.maxRetries) !== void 0) {
396
- currentGenerationSettings = {
397
- ...currentGenerationSettings,
398
- maxRetries: prepareResult.maxRetries
399
- };
400
- }
401
- if ((prepareResult == null ? void 0 : prepareResult.headers) !== void 0) {
402
- currentGenerationSettings = {
403
- ...currentGenerationSettings,
404
- headers: prepareResult.headers
405
- };
406
- }
407
- if ((prepareResult == null ? void 0 : prepareResult.reasoning) !== void 0) {
408
- currentGenerationSettings = {
409
- ...currentGenerationSettings,
410
- reasoning: prepareResult.reasoning
411
- };
412
- }
413
- if ((prepareResult == null ? void 0 : prepareResult.providerOptions) !== void 0) {
414
- currentGenerationSettings = {
415
- ...currentGenerationSettings,
416
- providerOptions: prepareResult.providerOptions
417
- };
418
- }
395
+ currentGenerationSettings = mergePrepareStepGenerationSettings(
396
+ currentGenerationSettings,
397
+ prepareResult != null ? prepareResult : {}
398
+ );
419
399
  if ((prepareResult == null ? void 0 : prepareResult.toolChoice) !== void 0) {
420
400
  currentToolChoice = prepareResult.toolChoice;
421
401
  }
@@ -452,7 +432,10 @@ async function* streamTextIterator({
452
432
  tools,
453
433
  activeTools: currentActiveTools
454
434
  })) != null ? _d : tools : tools;
455
- const serializedTools = serializeToolSet(effectiveTools);
435
+ const serializedTools = serializeToolSet(effectiveTools, {
436
+ toolsContext: currentToolsContext,
437
+ experimental_sandbox: stepSandbox
438
+ });
456
439
  const modelCallInfo = getModelInfo(currentModel);
457
440
  await ((_e = telemetryDispatcher.onLanguageModelCallStart) == null ? void 0 : _e.call(telemetryDispatcher, {
458
441
  callId: "workflow-agent",
@@ -763,24 +746,30 @@ var WorkflowAgent = class {
763
746
  throw new Error("Not implemented");
764
747
  }
765
748
  async stream(options) {
766
- 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, _S;
749
+ 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, _S, _T;
767
750
  const { onFinish, onEnd = onFinish } = options;
768
751
  let effectiveModel = this.model;
769
- let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
752
+ let effectiveInstructions = (_b = (_a = options.instructions) != null ? _a : options.system) != null ? _b : this.instructions;
770
753
  let effectivePrompt = options.prompt;
771
754
  let effectiveMessages = options.messages;
772
755
  let effectiveGenerationSettings = { ...this.generationSettings };
773
- let effectiveRuntimeContext = (_c = (_b = options.runtimeContext) != null ? _b : this.runtimeContext) != null ? _c : {};
774
- let effectiveToolsContext = (_e = (_d = options.toolsContext) != null ? _d : this.toolsContext) != null ? _e : {};
775
- let effectiveToolChoiceFromPrepare = (_f = options.toolChoice) != null ? _f : this.toolChoice;
776
- let effectiveTelemetryFromPrepare = (_g = options.telemetry) != null ? _g : this.telemetry;
777
- const resolvedMessagesForPrepareCall = (_h = effectiveMessages != null ? effectiveMessages : typeof effectivePrompt === "string" ? [{ role: "user", content: effectivePrompt }] : effectivePrompt) != null ? _h : [];
756
+ let effectiveRuntimeContext = (_d = (_c = options.runtimeContext) != null ? _c : this.runtimeContext) != null ? _d : {};
757
+ let effectiveToolsContext = (_f = (_e = options.toolsContext) != null ? _e : this.toolsContext) != null ? _f : {};
758
+ let effectiveToolChoiceFromPrepare = (_g = options.toolChoice) != null ? _g : this.toolChoice;
759
+ let effectiveStopWhenFromPrepare = (_h = options.stopWhen) != null ? _h : this.stopWhen;
760
+ let effectiveActiveToolsFromPrepare = (_i = options.activeTools) != null ? _i : this.activeTools;
761
+ let effectiveDownloadFromPrepare = (_j = options.experimental_download) != null ? _j : this.experimentalDownload;
762
+ let effectiveTelemetryFromPrepare = (_k = options.telemetry) != null ? _k : this.telemetry;
763
+ const resolvedMessagesForPrepareCall = (_l = effectiveMessages != null ? effectiveMessages : typeof effectivePrompt === "string" ? [{ role: "user", content: effectivePrompt }] : effectivePrompt) != null ? _l : [];
778
764
  if (this.prepareCall) {
779
765
  const prepared = await this.prepareCall({
780
766
  model: effectiveModel,
781
767
  tools: this.tools,
782
768
  instructions: effectiveInstructions,
783
769
  toolChoice: effectiveToolChoiceFromPrepare,
770
+ stopWhen: effectiveStopWhenFromPrepare,
771
+ activeTools: effectiveActiveToolsFromPrepare,
772
+ experimental_download: effectiveDownloadFromPrepare,
784
773
  telemetry: effectiveTelemetryFromPrepare,
785
774
  runtimeContext: effectiveRuntimeContext,
786
775
  toolsContext: effectiveToolsContext,
@@ -800,6 +789,12 @@ var WorkflowAgent = class {
800
789
  effectiveToolsContext = prepared.toolsContext;
801
790
  if (prepared.toolChoice !== void 0)
802
791
  effectiveToolChoiceFromPrepare = prepared.toolChoice;
792
+ if (prepared.stopWhen !== void 0)
793
+ effectiveStopWhenFromPrepare = prepared.stopWhen;
794
+ if (prepared.activeTools !== void 0)
795
+ effectiveActiveToolsFromPrepare = prepared.activeTools;
796
+ if (prepared.experimental_download !== void 0)
797
+ effectiveDownloadFromPrepare = prepared.experimental_download;
803
798
  if (prepared.telemetry !== void 0)
804
799
  effectiveTelemetryFromPrepare = prepared.telemetry;
805
800
  if (prepared.maxOutputTokens !== void 0)
@@ -836,8 +831,8 @@ var WorkflowAgent = class {
836
831
  allowSystemInMessages: this.allowSystemInMessages,
837
832
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
838
833
  });
839
- const download = (_i = options.experimental_download) != null ? _i : this.experimentalDownload;
840
- const sandbox = (_j = options.experimental_sandbox) != null ? _j : this.experimentalSandbox;
834
+ const download = effectiveDownloadFromPrepare;
835
+ const sandbox = (_m = options.experimental_sandbox) != null ? _m : this.experimentalSandbox;
841
836
  const collectedApprovals = collectToolApprovals({
842
837
  messages: prompt.messages
843
838
  });
@@ -906,7 +901,7 @@ var WorkflowAgent = class {
906
901
  runtimeContext: effectiveRuntimeContext
907
902
  });
908
903
  if (policyDenied.length > 0) {
909
- revalidationReason = (_k = policyDenied[0].approvalResponse.reason) != null ? _k : "Tool approval denied";
904
+ revalidationReason = (_n = policyDenied[0].approvalResponse.reason) != null ? _n : "Tool approval denied";
910
905
  }
911
906
  } catch (error) {
912
907
  revalidationReason = getErrorMessage(error);
@@ -943,7 +938,7 @@ var WorkflowAgent = class {
943
938
  input: approval.input
944
939
  };
945
940
  const messages2 = prompt.messages;
946
- await ((_l = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _l.call(telemetryDispatcher, {
941
+ await ((_o = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _o.call(telemetryDispatcher, {
947
942
  toolCall: toolCallEvent,
948
943
  stepNumber: 0,
949
944
  messages: messages2,
@@ -961,7 +956,7 @@ var WorkflowAgent = class {
961
956
  toolCallId: approval.toolCallId,
962
957
  execute: executeApprovedTool
963
958
  }) : await executeApprovedTool();
964
- await ((_m = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _m.call(telemetryDispatcher, {
959
+ await ((_p = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _p.call(telemetryDispatcher, {
965
960
  toolCall: toolCallEvent,
966
961
  stepNumber: 0,
967
962
  durationMs: Date.now() - startTime,
@@ -993,7 +988,7 @@ var WorkflowAgent = class {
993
988
  });
994
989
  } catch (error) {
995
990
  const errorMessage = getErrorMessage(error);
996
- await ((_n = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _n.call(telemetryDispatcher, {
991
+ await ((_q = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _q.call(telemetryDispatcher, {
997
992
  toolCall: {
998
993
  type: "tool-call",
999
994
  toolCallId: approval.toolCallId,
@@ -1093,7 +1088,7 @@ var WorkflowAgent = class {
1093
1088
  download
1094
1089
  });
1095
1090
  const effectiveAbortSignal = mergeAbortSignals(
1096
- (_o = options.abortSignal) != null ? _o : effectiveGenerationSettings.abortSignal,
1091
+ (_r = options.abortSignal) != null ? _r : effectiveGenerationSettings.abortSignal,
1097
1092
  options.timeout
1098
1093
  );
1099
1094
  const mergedGenerationSettings = {
@@ -1129,12 +1124,12 @@ var WorkflowAgent = class {
1129
1124
  }
1130
1125
  };
1131
1126
  mergedGenerationSettings.headers = withUserAgentSuffix(
1132
- (_p = mergedGenerationSettings.headers) != null ? _p : {},
1127
+ (_s = mergedGenerationSettings.headers) != null ? _s : {},
1133
1128
  "ai-sdk-agent/workflow"
1134
1129
  );
1135
1130
  const mergedOnStepEnd = mergeCallbacks(
1136
1131
  this.constructorOnStepEnd,
1137
- (_q = options.onStepEnd) != null ? _q : options.onStepFinish
1132
+ (_t = options.onStepEnd) != null ? _t : options.onStepFinish
1138
1133
  );
1139
1134
  const mergedOnEnd = mergeCallbacks(
1140
1135
  this.constructorOnEnd,
@@ -1157,11 +1152,11 @@ var WorkflowAgent = class {
1157
1152
  options.onToolExecutionEnd
1158
1153
  );
1159
1154
  const effectiveToolChoice = effectiveToolChoiceFromPrepare;
1160
- const effectiveActiveTools = (_r = options.activeTools) != null ? _r : this.activeTools;
1161
- const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_s = filterActiveTools2({
1155
+ const effectiveActiveTools = effectiveActiveToolsFromPrepare;
1156
+ const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_u = filterActiveTools2({
1162
1157
  tools: this.tools,
1163
1158
  activeTools: effectiveActiveTools
1164
- })) != null ? _s : this.tools : this.tools;
1159
+ })) != null ? _u : this.tools : this.tools;
1165
1160
  const effectiveModelInfo = getModelInfo2(effectiveModel);
1166
1161
  let runtimeContext = effectiveRuntimeContext;
1167
1162
  let toolsContext = effectiveToolsContext;
@@ -1176,7 +1171,7 @@ var WorkflowAgent = class {
1176
1171
  toolsContext
1177
1172
  });
1178
1173
  }
1179
- await ((_v = telemetryDispatcher.onStart) == null ? void 0 : _v.call(telemetryDispatcher, {
1174
+ await ((_x = telemetryDispatcher.onStart) == null ? void 0 : _x.call(telemetryDispatcher, {
1180
1175
  callId: "workflow-agent",
1181
1176
  operationId: "ai.workflowAgent.stream",
1182
1177
  provider: effectiveModelInfo.provider,
@@ -1194,12 +1189,12 @@ var WorkflowAgent = class {
1194
1189
  frequencyPenalty: mergedGenerationSettings.frequencyPenalty,
1195
1190
  stopSequences: mergedGenerationSettings.stopSequences,
1196
1191
  seed: mergedGenerationSettings.seed,
1197
- maxRetries: (_t = mergedGenerationSettings.maxRetries) != null ? _t : 2,
1192
+ maxRetries: (_v = mergedGenerationSettings.maxRetries) != null ? _v : 2,
1198
1193
  timeout: void 0,
1199
1194
  headers: mergedGenerationSettings.headers,
1200
1195
  reasoning: mergedGenerationSettings.reasoning,
1201
1196
  providerOptions: mergedGenerationSettings.providerOptions,
1202
- output: (_u = options.output) != null ? _u : this.output,
1197
+ output: (_w = options.output) != null ? _w : this.output,
1203
1198
  runtimeContext,
1204
1199
  toolsContext
1205
1200
  }));
@@ -1349,7 +1344,7 @@ var WorkflowAgent = class {
1349
1344
  }
1350
1345
  }));
1351
1346
  };
1352
- if ((_w = mergedGenerationSettings.abortSignal) == null ? void 0 : _w.aborted) {
1347
+ if ((_y = mergedGenerationSettings.abortSignal) == null ? void 0 : _y.aborted) {
1353
1348
  if (options.onAbort) {
1354
1349
  await options.onAbort({ steps });
1355
1350
  }
@@ -1368,19 +1363,21 @@ var WorkflowAgent = class {
1368
1363
  tools: effectiveTools,
1369
1364
  writable: options.writable,
1370
1365
  prompt: modelPrompt,
1371
- stopConditions: (_x = options.stopWhen) != null ? _x : this.stopWhen,
1366
+ initialInstructions: effectiveInstructions,
1367
+ initialMessages: prompt.messages,
1368
+ stopConditions: effectiveStopWhenFromPrepare,
1372
1369
  onStepEnd: mergedOnStepEnd,
1373
1370
  onStepStart: mergedOnStepStart,
1374
1371
  onError: options.onError,
1375
- prepareStep: (_y = options.prepareStep) != null ? _y : this.prepareStep,
1372
+ prepareStep: (_z = options.prepareStep) != null ? _z : this.prepareStep,
1376
1373
  generationSettings: mergedGenerationSettings,
1377
1374
  toolChoice: effectiveToolChoice,
1378
1375
  runtimeContext,
1379
1376
  toolsContext,
1380
1377
  telemetry: effectiveTelemetry,
1381
- includeRawChunks: (_z = options.includeRawChunks) != null ? _z : false,
1382
- repairToolCall: (_B = (_A = options.repairToolCall) != null ? _A : options.experimental_repairToolCall) != null ? _B : this.repairToolCall,
1383
- responseFormat: await ((_D = (_C = options.output) != null ? _C : this.output) == null ? void 0 : _D.responseFormat),
1378
+ includeRawChunks: (_A = options.includeRawChunks) != null ? _A : false,
1379
+ repairToolCall: (_C = (_B = options.repairToolCall) != null ? _B : options.experimental_repairToolCall) != null ? _C : this.repairToolCall,
1380
+ responseFormat: await ((_E = (_D = options.output) != null ? _D : this.output) == null ? void 0 : _E.responseFormat),
1384
1381
  experimental_sandbox: sandbox
1385
1382
  });
1386
1383
  let finalMessages;
@@ -1389,7 +1386,7 @@ var WorkflowAgent = class {
1389
1386
  try {
1390
1387
  let result = await iterator.next();
1391
1388
  while (!result.done) {
1392
- if ((_E = mergedGenerationSettings.abortSignal) == null ? void 0 : _E.aborted) {
1389
+ if ((_F = mergedGenerationSettings.abortSignal) == null ? void 0 : _F.aborted) {
1393
1390
  wasAborted = true;
1394
1391
  if (options.onAbort) {
1395
1392
  await options.onAbort({ steps });
@@ -1521,12 +1518,12 @@ var WorkflowAgent = class {
1521
1518
  const messages2 = iterMessages;
1522
1519
  const lastStep2 = steps[steps.length - 1];
1523
1520
  const totalUsage2 = aggregateUsage(steps);
1524
- const finishReason2 = (_F = lastStep2 == null ? void 0 : lastStep2.finishReason) != null ? _F : "other";
1521
+ const finishReason2 = (_G = lastStep2 == null ? void 0 : lastStep2.finishReason) != null ? _G : "other";
1525
1522
  if (mergedOnEnd && !wasAborted) {
1526
1523
  await mergedOnEnd({
1527
1524
  steps,
1528
1525
  messages: messages2,
1529
- text: (_G = lastStep2 == null ? void 0 : lastStep2.text) != null ? _G : "",
1526
+ text: (_H = lastStep2 == null ? void 0 : lastStep2.text) != null ? _H : "",
1530
1527
  finishReason: finishReason2,
1531
1528
  usage: totalUsage2,
1532
1529
  totalUsage: totalUsage2,
@@ -1538,7 +1535,7 @@ var WorkflowAgent = class {
1538
1535
  if (!wasAborted && steps.length > 0) {
1539
1536
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1540
1537
  const lastTelemetryStep = telemetrySteps[telemetrySteps.length - 1];
1541
- await ((_H = telemetryDispatcher.onEnd) == null ? void 0 : _H.call(telemetryDispatcher, {
1538
+ await ((_I = telemetryDispatcher.onEnd) == null ? void 0 : _I.call(telemetryDispatcher, {
1542
1539
  ...lastTelemetryStep,
1543
1540
  steps: telemetrySteps,
1544
1541
  usage: totalUsage2,
@@ -1563,8 +1560,8 @@ var WorkflowAgent = class {
1563
1560
  }
1564
1561
  }
1565
1562
  if (options.writable) {
1566
- const sendFinish = (_I = options.sendFinish) != null ? _I : true;
1567
- const preventClose = (_J = options.preventClose) != null ? _J : false;
1563
+ const sendFinish = (_J = options.sendFinish) != null ? _J : true;
1564
+ const preventClose = (_K = options.preventClose) != null ? _K : false;
1568
1565
  if (sendFinish || !preventClose) {
1569
1566
  await closeStream(options.writable, preventClose, sendFinish);
1570
1567
  }
@@ -1690,10 +1687,10 @@ var WorkflowAgent = class {
1690
1687
  } else if (options.onError) {
1691
1688
  await options.onError({ error });
1692
1689
  }
1693
- await ((_K = telemetryDispatcher.onError) == null ? void 0 : _K.call(telemetryDispatcher, error));
1690
+ await ((_L = telemetryDispatcher.onError) == null ? void 0 : _L.call(telemetryDispatcher, error));
1694
1691
  }
1695
1692
  const messages = finalMessages != null ? finalMessages : prompt.messages;
1696
- const effectiveOutput = (_L = options.output) != null ? _L : this.output;
1693
+ const effectiveOutput = (_M = options.output) != null ? _M : this.output;
1697
1694
  let experimentalOutput = void 0;
1698
1695
  if (effectiveOutput && steps.length > 0) {
1699
1696
  const lastStep2 = steps[steps.length - 1];
@@ -1717,12 +1714,12 @@ var WorkflowAgent = class {
1717
1714
  }
1718
1715
  const lastStep = steps[steps.length - 1];
1719
1716
  const totalUsage = aggregateUsage(steps);
1720
- const finishReason = (_M = lastStep == null ? void 0 : lastStep.finishReason) != null ? _M : "other";
1717
+ const finishReason = (_N = lastStep == null ? void 0 : lastStep.finishReason) != null ? _N : "other";
1721
1718
  if (mergedOnEnd && !wasAborted) {
1722
1719
  await mergedOnEnd({
1723
1720
  steps,
1724
1721
  messages,
1725
- text: (_N = lastStep == null ? void 0 : lastStep.text) != null ? _N : "",
1722
+ text: (_O = lastStep == null ? void 0 : lastStep.text) != null ? _O : "",
1726
1723
  finishReason,
1727
1724
  usage: totalUsage,
1728
1725
  totalUsage,
@@ -1734,7 +1731,7 @@ var WorkflowAgent = class {
1734
1731
  if (!wasAborted && steps.length > 0) {
1735
1732
  const telemetrySteps = steps.map(normalizeStepForTelemetry2);
1736
1733
  const lastTelemetryStep = telemetrySteps[telemetrySteps.length - 1];
1737
- await ((_O = telemetryDispatcher.onEnd) == null ? void 0 : _O.call(telemetryDispatcher, {
1734
+ await ((_P = telemetryDispatcher.onEnd) == null ? void 0 : _P.call(telemetryDispatcher, {
1738
1735
  ...lastTelemetryStep,
1739
1736
  steps: telemetrySteps,
1740
1737
  usage: totalUsage,
@@ -1743,8 +1740,8 @@ var WorkflowAgent = class {
1743
1740
  }
1744
1741
  if (encounteredError) {
1745
1742
  if (options.writable) {
1746
- const sendFinish = (_P = options.sendFinish) != null ? _P : true;
1747
- const preventClose = (_Q = options.preventClose) != null ? _Q : false;
1743
+ const sendFinish = (_Q = options.sendFinish) != null ? _Q : true;
1744
+ const preventClose = (_R = options.preventClose) != null ? _R : false;
1748
1745
  if (sendFinish || !preventClose) {
1749
1746
  await closeStream(options.writable, preventClose, sendFinish);
1750
1747
  }
@@ -1752,8 +1749,8 @@ var WorkflowAgent = class {
1752
1749
  throw encounteredError;
1753
1750
  }
1754
1751
  if (options.writable) {
1755
- const sendFinish = (_R = options.sendFinish) != null ? _R : true;
1756
- const preventClose = (_S = options.preventClose) != null ? _S : false;
1752
+ const sendFinish = (_S = options.sendFinish) != null ? _S : true;
1753
+ const preventClose = (_T = options.preventClose) != null ? _T : false;
1757
1754
  if (sendFinish || !preventClose) {
1758
1755
  await closeStream(options.writable, preventClose, sendFinish);
1759
1756
  }