@ai-sdk/workflow 1.0.0-beta.24 → 1.0.0-beta.27

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,65 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-beta.27
4
+
5
+ ### Patch Changes
6
+
7
+ - 29d8cf4: feat(ai): rename the core-event types
8
+ - a0ca584: fix (workflow): preserve invalid tool calls as errors instead of emitting synthetic success results
9
+ - Updated dependencies [785fe16]
10
+ - Updated dependencies [5f3749c]
11
+ - Updated dependencies [0a51f7d]
12
+ - Updated dependencies [71d3022]
13
+ - Updated dependencies [67df0a0]
14
+ - Updated dependencies [4181cfe]
15
+ - Updated dependencies [51ce232]
16
+ - Updated dependencies [cf93359]
17
+ - Updated dependencies [befb78c]
18
+ - Updated dependencies [29d8cf4]
19
+ - Updated dependencies [0458559]
20
+ - Updated dependencies [58a2ad7]
21
+ - Updated dependencies [5852c0a]
22
+ - Updated dependencies [37d69b2]
23
+ - Updated dependencies [1043274]
24
+ - Updated dependencies [7f59f04]
25
+ - Updated dependencies [7677c1e]
26
+ - Updated dependencies [116c89f]
27
+ - Updated dependencies [f58f9bc]
28
+ - Updated dependencies [e1bfb9c]
29
+ - Updated dependencies [e87d71b]
30
+ - Updated dependencies [9d486aa]
31
+ - Updated dependencies [9b0bc8a]
32
+ - Updated dependencies [fc92055]
33
+ - Updated dependencies [4e095b0]
34
+ - @ai-sdk/provider-utils@5.0.0-beta.27
35
+ - ai@7.0.0-beta.112
36
+
37
+ ## 1.0.0-beta.26
38
+
39
+ ### Major Changes
40
+
41
+ - 1949571: feat(ai): make experimental_telemetry stable
42
+
43
+ ### Patch Changes
44
+
45
+ - f32c750: refactoring(ai): simplify mergeAbortSignals
46
+ - Updated dependencies [f319fde]
47
+ - Updated dependencies [1949571]
48
+ - Updated dependencies [511902c]
49
+ - Updated dependencies [6542d93]
50
+ - Updated dependencies [2e98477]
51
+ - Updated dependencies [876fd3e]
52
+ - Updated dependencies [f32c750]
53
+ - ai@7.0.0-beta.111
54
+ - @ai-sdk/provider-utils@5.0.0-beta.26
55
+
56
+ ## 1.0.0-beta.25
57
+
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [72cb801]
61
+ - ai@7.0.0-beta.110
62
+
3
63
  ## 1.0.0-beta.24
4
64
 
5
65
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LanguageModelV4, SharedV4ProviderOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, LanguageModelV4StreamPart } from '@ai-sdk/provider';
2
- import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StopCondition, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, StreamTextOnStepFinishCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
2
+ import { ToolSet, LanguageModel, SystemModelMessage, ToolChoice, StopCondition, ActiveTools, LanguageModelResponseMetadata, LanguageModelUsage, FinishReason, ToolCallRepairFunction, StepResult, GenerateTextOnStepFinishCallback, ModelMessage, Experimental_LanguageModelStreamPart, UIMessage, UIMessageChunk, ChatTransport, PrepareSendMessagesRequest, PrepareReconnectToStreamRequest, ChatRequestOptions } from 'ai';
3
3
  export { Experimental_LanguageModelStreamPart as ModelCallStreamPart, Output, ToolCallRepairFunction } from 'ai';
4
4
 
5
5
  /**
@@ -15,10 +15,10 @@ type CompatibleLanguageModel = LanguageModelV4;
15
15
 
16
16
  /**
17
17
  * Callback function to be called after each step completes.
18
- * Alias for the AI SDK's StreamTextOnStepFinishCallback, using
18
+ * Alias for the AI SDK's GenerateTextOnStepFinishCallback, using
19
19
  * WorkflowAgent-consistent naming.
20
20
  */
21
- type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = StreamTextOnStepFinishCallback<TTools, any>;
21
+ type WorkflowAgentOnStepFinishCallback<TTools extends ToolSet = ToolSet> = GenerateTextOnStepFinishCallback<TTools, any>;
22
22
  /**
23
23
  * Infer the type of the tools of a workflow agent.
24
24
  */
@@ -252,6 +252,10 @@ interface PrepareCallOptions<TTools extends ToolSet = ToolSet> extends Partial<G
252
252
  tools: TTools;
253
253
  instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
254
254
  toolChoice?: ToolChoice<TTools>;
255
+ telemetry?: TelemetryOptions;
256
+ /**
257
+ * @deprecated Use `telemetry` instead. This alias will be removed in a future major release.
258
+ */
255
259
  experimental_telemetry?: TelemetryOptions;
256
260
  experimental_context?: unknown;
257
261
  messages: ModelMessage[];
@@ -303,7 +307,13 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
303
307
  */
304
308
  toolChoice?: ToolChoice<TTools>;
305
309
  /**
306
- * Optional telemetry configuration (experimental).
310
+ * Optional telemetry configuration.
311
+ */
312
+ telemetry?: TelemetryOptions;
313
+ /**
314
+ * Optional telemetry configuration.
315
+ *
316
+ * @deprecated Use `telemetry` instead. This alias will be removed in a future major release.
307
317
  */
308
318
  experimental_telemetry?: TelemetryOptions;
309
319
  /**
@@ -327,7 +337,7 @@ interface WorkflowAgentOptions<TTools extends ToolSet = ToolSet> extends Generat
327
337
  *
328
338
  * Per-stream `activeTools` values passed to `stream()` override this default.
329
339
  */
330
- activeTools?: Array<keyof NoInfer<TTools>>;
340
+ activeTools?: ActiveTools<NoInfer<TTools>>;
331
341
  /**
332
342
  * Default output specification for structured outputs.
333
343
  * Use `Output.object({ schema })` for structured output or `Output.text()` for text output.
@@ -567,9 +577,15 @@ type WorkflowAgentStreamOptions<TTools extends ToolSet = ToolSet, OUTPUT = never
567
577
  * Limits the tools that are available for the model to call without
568
578
  * changing the tool call and result types in the result.
569
579
  */
570
- activeTools?: Array<keyof NoInfer<TTools>>;
580
+ activeTools?: ActiveTools<NoInfer<TTools>>;
581
+ /**
582
+ * Optional telemetry configuration.
583
+ */
584
+ telemetry?: TelemetryOptions;
571
585
  /**
572
- * Optional telemetry configuration (experimental).
586
+ * Optional telemetry configuration.
587
+ *
588
+ * @deprecated Use `telemetry` instead. This alias will be removed in a future major release.
573
589
  */
574
590
  experimental_telemetry?: TelemetryOptions;
575
591
  /**
package/dist/index.mjs CHANGED
@@ -28,12 +28,14 @@ import Ajv from "ajv";
28
28
  function serializeToolSet(tools) {
29
29
  return Object.fromEntries(
30
30
  Object.entries(tools).map(([name, t]) => {
31
+ var _a;
31
32
  const def = {
32
33
  description: t.description,
33
34
  inputSchema: asSchema(t.inputSchema).jsonSchema
34
35
  };
35
36
  if (t.type === "provider") {
36
37
  def.type = "provider";
38
+ def.isProviderExecuted = (_a = t.isProviderExecuted) != null ? _a : false;
37
39
  def.id = t.id;
38
40
  def.args = t.args;
39
41
  }
@@ -45,7 +47,7 @@ function resolveSerializableTools(tools) {
45
47
  const ajv = new Ajv();
46
48
  return Object.fromEntries(
47
49
  Object.entries(tools).map(([name, t]) => {
48
- var _a;
50
+ var _a, _b;
49
51
  if (t.type === "provider") {
50
52
  return [
51
53
  name,
@@ -53,6 +55,7 @@ function resolveSerializableTools(tools) {
53
55
  type: "provider",
54
56
  id: t.id,
55
57
  args: (_a = t.args) != null ? _a : {},
58
+ isProviderExecuted: (_b = t.isProviderExecuted) != null ? _b : false,
56
59
  inputSchema: jsonSchema(t.inputSchema)
57
60
  })
58
61
  ];
@@ -91,6 +94,7 @@ async function doStreamStep(conversationPrompt, modelInit, writable, serializedT
91
94
  // pre-converted LanguageModelV4Prompt. standardizePrompt inside
92
95
  // streamModelCall handles both formats.
93
96
  messages: conversationPrompt,
97
+ allowSystemInMessages: true,
94
98
  tools,
95
99
  toolChoice: options == null ? void 0 : options.toolChoice,
96
100
  includeRawChunks: options == null ? void 0 : options.includeRawChunks,
@@ -279,7 +283,7 @@ async function* streamTextIterator({
279
283
  generationSettings,
280
284
  toolChoice,
281
285
  experimental_context,
282
- experimental_telemetry,
286
+ telemetry,
283
287
  includeRawChunks = false,
284
288
  repairToolCall,
285
289
  responseFormat
@@ -427,7 +431,7 @@ async function* streamTextIterator({
427
431
  ...currentGenerationSettings,
428
432
  toolChoice: currentToolChoice,
429
433
  includeRawChunks,
430
- experimental_telemetry,
434
+ telemetry,
431
435
  repairToolCall,
432
436
  responseFormat
433
437
  }
@@ -544,13 +548,13 @@ function sanitizeProviderMetadataForToolCall(metadata) {
544
548
  // src/workflow-agent.ts
545
549
  var WorkflowAgent = class {
546
550
  constructor(options) {
547
- var _a, _b;
551
+ var _a, _b, _c;
548
552
  this.id = options.id;
549
553
  this.model = options.model;
550
554
  this.tools = (_a = options.tools) != null ? _a : {};
551
555
  this.instructions = (_b = options.instructions) != null ? _b : options.system;
552
556
  this.toolChoice = options.toolChoice;
553
- this.telemetry = options.experimental_telemetry;
557
+ this.telemetry = (_c = options.telemetry) != null ? _c : options.experimental_telemetry;
554
558
  this.experimentalContext = options.experimental_context;
555
559
  this.stopWhen = options.stopWhen;
556
560
  this.activeTools = options.activeTools;
@@ -584,7 +588,7 @@ var WorkflowAgent = class {
584
588
  throw new Error("Not implemented");
585
589
  }
586
590
  async stream(options) {
587
- 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;
591
+ 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;
588
592
  let effectiveModel = this.model;
589
593
  let effectiveInstructions = (_a = options.system) != null ? _a : this.instructions;
590
594
  let effectivePrompt = options.prompt;
@@ -592,14 +596,15 @@ var WorkflowAgent = class {
592
596
  let effectiveGenerationSettings = { ...this.generationSettings };
593
597
  let effectiveExperimentalContext = (_b = options.experimental_context) != null ? _b : this.experimentalContext;
594
598
  let effectiveToolChoiceFromPrepare = (_c = options.toolChoice) != null ? _c : this.toolChoice;
595
- let effectiveTelemetryFromPrepare = (_d = options.experimental_telemetry) != null ? _d : this.telemetry;
596
- const resolvedMessagesForPrepareCall = (_e = effectiveMessages != null ? effectiveMessages : typeof effectivePrompt === "string" ? [{ role: "user", content: effectivePrompt }] : effectivePrompt) != null ? _e : [];
599
+ let effectiveTelemetryFromPrepare = (_e = (_d = options.telemetry) != null ? _d : options.experimental_telemetry) != null ? _e : this.telemetry;
600
+ const resolvedMessagesForPrepareCall = (_f = effectiveMessages != null ? effectiveMessages : typeof effectivePrompt === "string" ? [{ role: "user", content: effectivePrompt }] : effectivePrompt) != null ? _f : [];
597
601
  if (this.prepareCall) {
598
602
  const prepared = await this.prepareCall({
599
603
  model: effectiveModel,
600
604
  tools: this.tools,
601
605
  instructions: effectiveInstructions,
602
606
  toolChoice: effectiveToolChoiceFromPrepare,
607
+ telemetry: effectiveTelemetryFromPrepare,
603
608
  experimental_telemetry: effectiveTelemetryFromPrepare,
604
609
  experimental_context: effectiveExperimentalContext,
605
610
  messages: resolvedMessagesForPrepareCall,
@@ -616,7 +621,9 @@ var WorkflowAgent = class {
616
621
  effectiveExperimentalContext = prepared.experimental_context;
617
622
  if (prepared.toolChoice !== void 0)
618
623
  effectiveToolChoiceFromPrepare = prepared.toolChoice;
619
- if (prepared.experimental_telemetry !== void 0)
624
+ if (prepared.telemetry !== void 0)
625
+ effectiveTelemetryFromPrepare = prepared.telemetry;
626
+ else if (prepared.experimental_telemetry !== void 0)
620
627
  effectiveTelemetryFromPrepare = prepared.experimental_telemetry;
621
628
  if (prepared.maxOutputTokens !== void 0)
622
629
  effectiveGenerationSettings.maxOutputTokens = prepared.maxOutputTokens;
@@ -641,6 +648,8 @@ var WorkflowAgent = class {
641
648
  }
642
649
  const prompt = await standardizePrompt({
643
650
  system: effectiveInstructions,
651
+ allowSystemInMessages: true,
652
+ // TODO: consider exposing this as a parameter
644
653
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
645
654
  });
646
655
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovalsFromMessages(prompt.messages);
@@ -737,11 +746,11 @@ var WorkflowAgent = class {
737
746
  const modelPrompt = await convertToLanguageModelPrompt({
738
747
  prompt,
739
748
  supportedUrls: {},
740
- download: (_f = options.experimental_download) != null ? _f : this.experimentalDownload
749
+ download: (_g = options.experimental_download) != null ? _g : this.experimentalDownload
741
750
  });
742
751
  const effectiveAbortSignal = mergeAbortSignals(
743
- (_g = options.abortSignal) != null ? _g : effectiveGenerationSettings.abortSignal,
744
- options.timeout != null ? AbortSignal.timeout(options.timeout) : void 0
752
+ (_h = options.abortSignal) != null ? _h : effectiveGenerationSettings.abortSignal,
753
+ options.timeout
745
754
  );
746
755
  const mergedGenerationSettings = {
747
756
  ...effectiveGenerationSettings,
@@ -800,11 +809,11 @@ var WorkflowAgent = class {
800
809
  );
801
810
  const effectiveToolChoice = effectiveToolChoiceFromPrepare;
802
811
  const effectiveTelemetry = effectiveTelemetryFromPrepare;
803
- const effectiveActiveTools = (_h = options.activeTools) != null ? _h : this.activeTools;
804
- const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_i = filterActiveTools2({
812
+ const effectiveActiveTools = (_i = options.activeTools) != null ? _i : this.activeTools;
813
+ const effectiveTools = effectiveActiveTools && effectiveActiveTools.length > 0 ? (_j = filterActiveTools2({
805
814
  tools: this.tools,
806
815
  activeTools: effectiveActiveTools
807
- })) != null ? _i : this.tools : this.tools;
816
+ })) != null ? _j : this.tools : this.tools;
808
817
  let experimentalContext = effectiveExperimentalContext;
809
818
  const steps = [];
810
819
  let lastStepToolCalls = [];
@@ -868,7 +877,7 @@ var WorkflowAgent = class {
868
877
  }
869
878
  return result;
870
879
  };
871
- if ((_j = mergedGenerationSettings.abortSignal) == null ? void 0 : _j.aborted) {
880
+ if ((_k = mergedGenerationSettings.abortSignal) == null ? void 0 : _k.aborted) {
872
881
  if (options.onAbort) {
873
882
  await options.onAbort({ steps });
874
883
  }
@@ -885,18 +894,18 @@ var WorkflowAgent = class {
885
894
  tools: effectiveTools,
886
895
  writable: options.writable,
887
896
  prompt: modelPrompt,
888
- stopConditions: (_k = options.stopWhen) != null ? _k : this.stopWhen,
897
+ stopConditions: (_l = options.stopWhen) != null ? _l : this.stopWhen,
889
898
  onStepFinish: mergedOnStepFinish,
890
899
  onStepStart: mergedOnStepStart,
891
900
  onError: options.onError,
892
- prepareStep: (_l = options.prepareStep) != null ? _l : this.prepareStep,
901
+ prepareStep: (_m = options.prepareStep) != null ? _m : this.prepareStep,
893
902
  generationSettings: mergedGenerationSettings,
894
903
  toolChoice: effectiveToolChoice,
895
904
  experimental_context: experimentalContext,
896
- experimental_telemetry: effectiveTelemetry,
897
- includeRawChunks: (_m = options.includeRawChunks) != null ? _m : false,
898
- repairToolCall: (_n = options.experimental_repairToolCall) != null ? _n : this.experimentalRepairToolCall,
899
- responseFormat: await ((_p = (_o = options.output) != null ? _o : this.output) == null ? void 0 : _p.responseFormat)
905
+ telemetry: effectiveTelemetry,
906
+ includeRawChunks: (_n = options.includeRawChunks) != null ? _n : false,
907
+ repairToolCall: (_o = options.experimental_repairToolCall) != null ? _o : this.experimentalRepairToolCall,
908
+ responseFormat: await ((_q = (_p = options.output) != null ? _p : this.output) == null ? void 0 : _q.responseFormat)
900
909
  });
901
910
  let finalMessages;
902
911
  let encounteredError;
@@ -904,7 +913,7 @@ var WorkflowAgent = class {
904
913
  try {
905
914
  let result = await iterator.next();
906
915
  while (!result.done) {
907
- if ((_q = mergedGenerationSettings.abortSignal) == null ? void 0 : _q.aborted) {
916
+ if ((_r = mergedGenerationSettings.abortSignal) == null ? void 0 : _r.aborted) {
908
917
  wasAborted = true;
909
918
  if (options.onAbort) {
910
919
  await options.onAbort({ steps });
@@ -926,10 +935,14 @@ var WorkflowAgent = class {
926
935
  experimentalContext = context;
927
936
  }
928
937
  if (toolCalls.length > 0) {
929
- const nonProviderToolCalls = toolCalls.filter(
938
+ const invalidToolCalls = toolCalls.filter((tc) => tc.invalid === true);
939
+ const validToolCalls = toolCalls.filter((tc) => tc.invalid !== true);
940
+ const nonProviderToolCalls = validToolCalls.filter(
930
941
  (tc) => !tc.providerExecuted
931
942
  );
932
- const providerToolCalls = toolCalls.filter((tc) => tc.providerExecuted);
943
+ const providerToolCalls = validToolCalls.filter(
944
+ (tc) => tc.providerExecuted
945
+ );
933
946
  const approvalNeeded = await Promise.all(
934
947
  nonProviderToolCalls.map(async (tc) => {
935
948
  const tool2 = effectiveTools[tc.toolName];
@@ -970,14 +983,22 @@ var WorkflowAgent = class {
970
983
  providerExecutedToolResults
971
984
  )
972
985
  );
973
- const resolvedResults = [...executableResults, ...providerResults];
986
+ const continuationInvalidResults = invalidToolCalls.map(
987
+ createInvalidToolResult
988
+ );
989
+ const resolvedResults = [
990
+ ...executableResults,
991
+ ...providerResults,
992
+ ...continuationInvalidResults
993
+ ];
994
+ const executedResults = [...executableResults, ...providerResults];
974
995
  const allToolCalls = toolCalls.map((tc) => ({
975
996
  type: "tool-call",
976
997
  toolCallId: tc.toolCallId,
977
998
  toolName: tc.toolName,
978
999
  input: tc.input
979
1000
  }));
980
- const allToolResults = resolvedResults.map((r) => {
1001
+ const allToolResults = executedResults.map((r) => {
981
1002
  var _a2;
982
1003
  return {
983
1004
  type: "tool-result",
@@ -999,8 +1020,8 @@ var WorkflowAgent = class {
999
1020
  await mergedOnFinish({
1000
1021
  steps,
1001
1022
  messages: messages2,
1002
- text: (_r = lastStep == null ? void 0 : lastStep.text) != null ? _r : "",
1003
- finishReason: (_s = lastStep == null ? void 0 : lastStep.finishReason) != null ? _s : "other",
1023
+ text: (_s = lastStep == null ? void 0 : lastStep.text) != null ? _s : "",
1024
+ finishReason: (_t = lastStep == null ? void 0 : lastStep.finishReason) != null ? _t : "other",
1004
1025
  totalUsage: aggregateUsage(steps),
1005
1026
  experimental_context: experimentalContext,
1006
1027
  output: void 0
@@ -1024,8 +1045,8 @@ var WorkflowAgent = class {
1024
1045
  }
1025
1046
  }
1026
1047
  if (options.writable) {
1027
- const sendFinish = (_t = options.sendFinish) != null ? _t : true;
1028
- const preventClose = (_u = options.preventClose) != null ? _u : false;
1048
+ const sendFinish = (_u = options.sendFinish) != null ? _u : true;
1049
+ const preventClose = (_v = options.preventClose) != null ? _v : false;
1029
1050
  if (sendFinish || !preventClose) {
1030
1051
  await closeStream(options.writable, preventClose, sendFinish);
1031
1052
  }
@@ -1052,26 +1073,31 @@ var WorkflowAgent = class {
1052
1073
  const providerToolResults = providerToolCalls.map(
1053
1074
  (toolCall) => resolveProviderToolResult(toolCall, providerExecutedToolResults)
1054
1075
  );
1055
- const toolResults = toolCalls.map((tc) => {
1076
+ const continuationInvalidToolResults = invalidToolCalls.map(
1077
+ createInvalidToolResult
1078
+ );
1079
+ const continuationToolResults = toolCalls.flatMap((tc) => {
1080
+ const invalidResult = continuationInvalidToolResults.find(
1081
+ (r) => r.toolCallId === tc.toolCallId
1082
+ );
1083
+ if (invalidResult) return [invalidResult];
1056
1084
  const clientResult = clientToolResults.find(
1057
1085
  (r) => r.toolCallId === tc.toolCallId
1058
1086
  );
1059
- if (clientResult) return clientResult;
1087
+ if (clientResult) return [clientResult];
1060
1088
  const providerResult = providerToolResults.find(
1061
1089
  (r) => r.toolCallId === tc.toolCallId
1062
1090
  );
1063
- if (providerResult) return providerResult;
1064
- return {
1065
- type: "tool-result",
1066
- toolCallId: tc.toolCallId,
1067
- toolName: tc.toolName,
1068
- output: { type: "text", value: "" }
1069
- };
1091
+ if (providerResult) return [providerResult];
1092
+ return [];
1070
1093
  });
1094
+ const executedToolResults = continuationToolResults.filter(
1095
+ (result2) => !invalidToolCalls.some((tc) => tc.toolCallId === result2.toolCallId)
1096
+ );
1071
1097
  if (options.writable) {
1072
1098
  await writeToolResultsWithStepBoundary(
1073
1099
  options.writable,
1074
- toolResults.map((r) => {
1100
+ executedToolResults.map((r) => {
1075
1101
  var _a2;
1076
1102
  return {
1077
1103
  toolCallId: r.toolCallId,
@@ -1088,7 +1114,7 @@ var WorkflowAgent = class {
1088
1114
  toolName: tc.toolName,
1089
1115
  input: tc.input
1090
1116
  }));
1091
- lastStepToolResults = toolResults.map((r) => {
1117
+ lastStepToolResults = executedToolResults.map((r) => {
1092
1118
  var _a2;
1093
1119
  return {
1094
1120
  type: "tool-result",
@@ -1098,7 +1124,7 @@ var WorkflowAgent = class {
1098
1124
  output: "value" in r.output ? r.output.value : void 0
1099
1125
  };
1100
1126
  });
1101
- result = await iterator.next(toolResults);
1127
+ result = await iterator.next(continuationToolResults);
1102
1128
  } else {
1103
1129
  lastStepToolCalls = [];
1104
1130
  lastStepToolResults = [];
@@ -1120,7 +1146,7 @@ var WorkflowAgent = class {
1120
1146
  }
1121
1147
  }
1122
1148
  const messages = finalMessages != null ? finalMessages : prompt.messages;
1123
- const effectiveOutput = (_v = options.output) != null ? _v : this.output;
1149
+ const effectiveOutput = (_w = options.output) != null ? _w : this.output;
1124
1150
  let experimentalOutput = void 0;
1125
1151
  if (effectiveOutput && steps.length > 0) {
1126
1152
  const lastStep = steps[steps.length - 1];
@@ -1147,8 +1173,8 @@ var WorkflowAgent = class {
1147
1173
  await mergedOnFinish({
1148
1174
  steps,
1149
1175
  messages,
1150
- text: (_w = lastStep == null ? void 0 : lastStep.text) != null ? _w : "",
1151
- finishReason: (_x = lastStep == null ? void 0 : lastStep.finishReason) != null ? _x : "other",
1176
+ text: (_x = lastStep == null ? void 0 : lastStep.text) != null ? _x : "",
1177
+ finishReason: (_y = lastStep == null ? void 0 : lastStep.finishReason) != null ? _y : "other",
1152
1178
  totalUsage: aggregateUsage(steps),
1153
1179
  experimental_context: experimentalContext,
1154
1180
  output: experimentalOutput
@@ -1156,8 +1182,8 @@ var WorkflowAgent = class {
1156
1182
  }
1157
1183
  if (encounteredError) {
1158
1184
  if (options.writable) {
1159
- const sendFinish = (_y = options.sendFinish) != null ? _y : true;
1160
- const preventClose = (_z = options.preventClose) != null ? _z : false;
1185
+ const sendFinish = (_z = options.sendFinish) != null ? _z : true;
1186
+ const preventClose = (_A = options.preventClose) != null ? _A : false;
1161
1187
  if (sendFinish || !preventClose) {
1162
1188
  await closeStream(options.writable, preventClose, sendFinish);
1163
1189
  }
@@ -1165,8 +1191,8 @@ var WorkflowAgent = class {
1165
1191
  throw encounteredError;
1166
1192
  }
1167
1193
  if (options.writable) {
1168
- const sendFinish = (_A = options.sendFinish) != null ? _A : true;
1169
- const preventClose = (_B = options.preventClose) != null ? _B : false;
1194
+ const sendFinish = (_B = options.sendFinish) != null ? _B : true;
1195
+ const preventClose = (_C = options.preventClose) != null ? _C : false;
1170
1196
  if (sendFinish || !preventClose) {
1171
1197
  await closeStream(options.writable, preventClose, sendFinish);
1172
1198
  }
@@ -1310,6 +1336,17 @@ function resolveProviderToolResult(toolCall, providerExecutedToolResults) {
1310
1336
  }
1311
1337
  };
1312
1338
  }
1339
+ function createInvalidToolResult(toolCall) {
1340
+ return {
1341
+ type: "tool-result",
1342
+ toolCallId: toolCall.toolCallId,
1343
+ toolName: toolCall.toolName,
1344
+ output: {
1345
+ type: "error-text",
1346
+ value: getErrorMessage(toolCall.error)
1347
+ }
1348
+ };
1349
+ }
1313
1350
  async function executeTool(toolCall, tools, messages, experimentalContext) {
1314
1351
  const tool2 = tools[toolCall.toolName];
1315
1352
  if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);