@ai-sdk/workflow 1.0.0-canary.84 → 1.0.0-canary.86

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,28 @@
1
1
  # @ai-sdk/workflow
2
2
 
3
+ ## 1.0.0-canary.86
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a5018ab]
8
+ - Updated dependencies [21d3d60]
9
+ - Updated dependencies [426dbbb]
10
+ - Updated dependencies [7fd3360]
11
+ - ai@7.0.0-canary.169
12
+
13
+ ## 1.0.0-canary.85
14
+
15
+ ### Patch Changes
16
+
17
+ - 1e4b350: Honor `tool.toModelOutput` in `WorkflowAgent`.
18
+
19
+ `WorkflowAgent` now routes successful local, provider-executed, and approved tool results through each tool's optional `toModelOutput` hook, matching `generateText`, `streamText`, and `ToolLoopAgent`. Previously the hook was ignored and results were always serialized as `text` or `json`.
20
+
21
+ Internally exports the shared tool-result model-output helpers from `ai/internal`, and uses the shared `getErrorMessage` behavior for workflow tool error results.
22
+
23
+ - Updated dependencies [1e4b350]
24
+ - ai@7.0.0-canary.168
25
+
3
26
  ## 1.0.0-canary.84
4
27
 
5
28
  ### Patch Changes
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/workflow-agent.ts
2
2
  import {
3
+ getErrorMessage,
3
4
  validateTypes
4
5
  } from "@ai-sdk/provider-utils";
5
6
  import {
@@ -14,6 +15,55 @@ import {
14
15
  standardizePrompt
15
16
  } from "ai/internal";
16
17
 
18
+ // src/create-language-model-tool-result-output.ts
19
+ import {
20
+ createDefaultDownloadFunction,
21
+ createToolModelOutput,
22
+ downloadAssets,
23
+ mapToolResultOutput
24
+ } from "ai/internal";
25
+ async function createLanguageModelToolResultOutput({
26
+ toolCallId,
27
+ toolName,
28
+ input,
29
+ output,
30
+ tool: tool2,
31
+ errorMode,
32
+ supportedUrls,
33
+ download = createDefaultDownloadFunction(),
34
+ provider
35
+ }) {
36
+ const modelOutput = await createToolModelOutput({
37
+ toolCallId,
38
+ input,
39
+ output,
40
+ tool: tool2,
41
+ errorMode
42
+ });
43
+ const downloadedAssets = modelOutput.type === "content" ? await downloadAssets(
44
+ [
45
+ {
46
+ role: "tool",
47
+ content: [
48
+ {
49
+ type: "tool-result",
50
+ toolCallId,
51
+ toolName,
52
+ output: modelOutput
53
+ }
54
+ ]
55
+ }
56
+ ],
57
+ download,
58
+ supportedUrls
59
+ ) : {};
60
+ return mapToolResultOutput({
61
+ output: modelOutput,
62
+ provider,
63
+ downloadedAssets
64
+ });
65
+ }
66
+
17
67
  // src/stream-text-iterator.ts
18
68
  import {
19
69
  experimental_filterActiveTools as filterActiveTools
@@ -763,10 +813,12 @@ var WorkflowAgent = class {
763
813
  // TODO: consider exposing this as a parameter
764
814
  ...effectivePrompt != null ? { prompt: effectivePrompt } : { messages: effectiveMessages }
765
815
  });
816
+ const download = (_i = options.experimental_download) != null ? _i : this.experimentalDownload;
766
817
  const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovalsFromMessages(prompt.messages);
767
818
  if (approvedToolApprovals.length > 0 || deniedToolApprovals.length > 0) {
768
819
  const _toolResultMessages = [];
769
820
  const toolResultContent = [];
821
+ const approvedRawResults = [];
770
822
  for (const approval of approvedToolApprovals) {
771
823
  const tool2 = this.tools[approval.toolName];
772
824
  if (tool2 && typeof tool2.execute === "function") {
@@ -784,7 +836,7 @@ var WorkflowAgent = class {
784
836
  input: approval.input
785
837
  };
786
838
  const messages2 = prompt.messages;
787
- await ((_i = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _i.call(telemetryDispatcher, {
839
+ await ((_j = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _j.call(telemetryDispatcher, {
788
840
  toolCall: toolCallEvent,
789
841
  stepNumber: 0,
790
842
  messages: messages2,
@@ -801,7 +853,7 @@ var WorkflowAgent = class {
801
853
  toolCallId: approval.toolCallId,
802
854
  execute: executeApprovedTool
803
855
  }) : await executeApprovedTool();
804
- await ((_j = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _j.call(telemetryDispatcher, {
856
+ await ((_k = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _k.call(telemetryDispatcher, {
805
857
  toolCall: toolCallEvent,
806
858
  stepNumber: 0,
807
859
  durationMs: Date.now() - startTime,
@@ -814,10 +866,26 @@ var WorkflowAgent = class {
814
866
  type: "tool-result",
815
867
  toolCallId: approval.toolCallId,
816
868
  toolName: approval.toolName,
817
- output: typeof toolResult === "string" ? { type: "text", value: toolResult } : { type: "json", value: toolResult }
869
+ output: await createLanguageModelToolResultOutput({
870
+ toolCallId: approval.toolCallId,
871
+ toolName: approval.toolName,
872
+ input: approval.input,
873
+ output: toolResult,
874
+ tool: tool2,
875
+ errorMode: "none",
876
+ supportedUrls: {},
877
+ download
878
+ })
879
+ });
880
+ approvedRawResults.push({
881
+ toolCallId: approval.toolCallId,
882
+ toolName: approval.toolName,
883
+ input: approval.input,
884
+ output: toolResult
818
885
  });
819
886
  } catch (error) {
820
- await ((_k = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _k.call(telemetryDispatcher, {
887
+ const errorMessage = getErrorMessage(error);
888
+ await ((_l = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _l.call(telemetryDispatcher, {
821
889
  toolCall: {
822
890
  type: "tool-call",
823
891
  toolCallId: approval.toolCallId,
@@ -835,10 +903,22 @@ var WorkflowAgent = class {
835
903
  type: "tool-result",
836
904
  toolCallId: approval.toolCallId,
837
905
  toolName: approval.toolName,
838
- output: {
839
- type: "text",
840
- value: getErrorMessage(error)
841
- }
906
+ output: await createLanguageModelToolResultOutput({
907
+ toolCallId: approval.toolCallId,
908
+ toolName: approval.toolName,
909
+ input: approval.input,
910
+ output: errorMessage,
911
+ tool: tool2,
912
+ errorMode: "text",
913
+ supportedUrls: {},
914
+ download
915
+ })
916
+ });
917
+ approvedRawResults.push({
918
+ toolCallId: approval.toolCallId,
919
+ toolName: approval.toolName,
920
+ input: approval.input,
921
+ output: errorMessage
842
922
  });
843
923
  }
844
924
  }
@@ -882,21 +962,10 @@ var WorkflowAgent = class {
882
962
  }
883
963
  prompt.messages = cleanedMessages;
884
964
  if (options.writable && toolResultContent.length > 0) {
885
- const approvedResults = toolResultContent.filter((r) => r.output.type !== "execution-denied").map((r) => {
886
- var _a2;
887
- return {
888
- toolCallId: r.toolCallId,
889
- toolName: r.toolName,
890
- input: (_a2 = approvedToolApprovals.find(
891
- (a) => a.toolCallId === r.toolCallId
892
- )) == null ? void 0 : _a2.input,
893
- output: "value" in r.output ? r.output.value : void 0
894
- };
895
- });
896
965
  const deniedResults = toolResultContent.filter((r) => r.output.type === "execution-denied").map((r) => ({ toolCallId: r.toolCallId }));
897
966
  await writeApprovalToolResults(
898
967
  options.writable,
899
- approvedResults,
968
+ approvedRawResults,
900
969
  deniedResults
901
970
  );
902
971
  }
@@ -904,7 +973,7 @@ var WorkflowAgent = class {
904
973
  const modelPrompt = await convertToLanguageModelPrompt({
905
974
  prompt,
906
975
  supportedUrls: {},
907
- download: (_l = options.experimental_download) != null ? _l : this.experimentalDownload
976
+ download
908
977
  });
909
978
  const effectiveAbortSignal = mergeAbortSignals(
910
979
  (_m = options.abortSignal) != null ? _m : effectiveGenerationSettings.abortSignal,
@@ -1043,7 +1112,7 @@ var WorkflowAgent = class {
1043
1112
  const startTime = Date.now();
1044
1113
  let result;
1045
1114
  try {
1046
- const execute = () => executeTool(toolCall, tools, messages2, resolvedContext);
1115
+ const execute = () => executeTool(toolCall, tools, messages2, resolvedContext, download);
1047
1116
  result = telemetryDispatcher.executeTool != null ? await telemetryDispatcher.executeTool({
1048
1117
  callId: "workflow-agent",
1049
1118
  toolCallId: toolCall.toolCallId,
@@ -1075,8 +1144,7 @@ var WorkflowAgent = class {
1075
1144
  }
1076
1145
  const durationMs = Date.now() - startTime;
1077
1146
  if (mergedOnToolExecutionEnd) {
1078
- const isError = result.output && "type" in result.output && (result.output.type === "error-text" || result.output.type === "error-json");
1079
- if (isError) {
1147
+ if (result.isError) {
1080
1148
  await mergedOnToolExecutionEnd({
1081
1149
  toolCall: toolCallEvent,
1082
1150
  stepNumber: currentStepNumber,
@@ -1084,7 +1152,7 @@ var WorkflowAgent = class {
1084
1152
  messages: modelMessages,
1085
1153
  toolContext: resolvedContext,
1086
1154
  success: false,
1087
- error: "value" in result.output ? result.output.value : void 0
1155
+ error: result.rawOutput
1088
1156
  });
1089
1157
  } else {
1090
1158
  await mergedOnToolExecutionEnd({
@@ -1094,11 +1162,11 @@ var WorkflowAgent = class {
1094
1162
  messages: modelMessages,
1095
1163
  toolContext: resolvedContext,
1096
1164
  success: true,
1097
- output: result.output && "value" in result.output ? result.output.value : void 0
1165
+ output: result.rawOutput
1098
1166
  });
1099
1167
  }
1100
1168
  }
1101
- if (result.output && "type" in result.output && (result.output.type === "error-text" || result.output.type === "error-json")) {
1169
+ if (result.isError) {
1102
1170
  await ((_c2 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _c2.call(telemetryDispatcher, {
1103
1171
  toolCall: toolCallEvent,
1104
1172
  stepNumber: currentStepNumber,
@@ -1106,7 +1174,7 @@ var WorkflowAgent = class {
1106
1174
  messages: modelMessages,
1107
1175
  toolContext: resolvedContext,
1108
1176
  success: false,
1109
- error: "value" in result.output ? result.output.value : void 0
1177
+ error: result.rawOutput
1110
1178
  }));
1111
1179
  } else {
1112
1180
  await ((_d2 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _d2.call(telemetryDispatcher, {
@@ -1116,7 +1184,7 @@ var WorkflowAgent = class {
1116
1184
  messages: modelMessages,
1117
1185
  toolContext: resolvedContext,
1118
1186
  success: true,
1119
- output: result.output && "value" in result.output ? result.output.value : void 0
1187
+ output: result.rawOutput
1120
1188
  }));
1121
1189
  }
1122
1190
  return result;
@@ -1136,19 +1204,18 @@ var WorkflowAgent = class {
1136
1204
  messages: modelMessages,
1137
1205
  toolContext: void 0
1138
1206
  }));
1139
- const isError = result.output && "type" in result.output && (result.output.type === "error-text" || result.output.type === "error-json");
1140
1207
  await ((_b2 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _b2.call(telemetryDispatcher, {
1141
1208
  toolCall: toolCallEvent,
1142
1209
  stepNumber: currentStepNumber,
1143
1210
  durationMs: 0,
1144
1211
  messages: modelMessages,
1145
1212
  toolContext: void 0,
1146
- ...isError ? {
1213
+ ...result.isError ? {
1147
1214
  success: false,
1148
- error: result.output && "value" in result.output ? result.output.value : void 0
1215
+ error: result.rawOutput
1149
1216
  } : {
1150
1217
  success: true,
1151
- output: result.output && "value" in result.output ? result.output.value : void 0
1218
+ output: result.rawOutput
1152
1219
  }
1153
1220
  }));
1154
1221
  };
@@ -1262,10 +1329,14 @@ var WorkflowAgent = class {
1262
1329
  )
1263
1330
  )
1264
1331
  );
1265
- const providerResults = providerToolCalls.map(
1266
- (toolCall) => resolveProviderToolResult(
1267
- toolCall,
1268
- providerExecutedToolResults
1332
+ const providerResults = await Promise.all(
1333
+ providerToolCalls.map(
1334
+ (toolCall) => resolveProviderToolResult(
1335
+ toolCall,
1336
+ providerExecutedToolResults,
1337
+ effectiveTools,
1338
+ download
1339
+ )
1269
1340
  )
1270
1341
  );
1271
1342
  await Promise.all(
@@ -1282,8 +1353,8 @@ var WorkflowAgent = class {
1282
1353
  createInvalidToolResult
1283
1354
  );
1284
1355
  const resolvedResults = [
1285
- ...executableResults,
1286
- ...providerResults,
1356
+ ...executableResults.map((result2) => result2.modelResult),
1357
+ ...providerResults.map((result2) => result2.modelResult),
1287
1358
  ...continuationInvalidResults
1288
1359
  ];
1289
1360
  const executedResults = [...executableResults, ...providerResults];
@@ -1297,10 +1368,12 @@ var WorkflowAgent = class {
1297
1368
  var _a2;
1298
1369
  return {
1299
1370
  type: "tool-result",
1300
- toolCallId: r.toolCallId,
1301
- toolName: r.toolName,
1302
- input: (_a2 = toolCalls.find((tc) => tc.toolCallId === r.toolCallId)) == null ? void 0 : _a2.input,
1303
- output: "value" in r.output ? r.output.value : void 0
1371
+ toolCallId: r.modelResult.toolCallId,
1372
+ toolName: r.modelResult.toolName,
1373
+ input: (_a2 = toolCalls.find(
1374
+ (tc) => tc.toolCallId === r.modelResult.toolCallId
1375
+ )) == null ? void 0 : _a2.input,
1376
+ output: r.rawOutput
1304
1377
  };
1305
1378
  });
1306
1379
  if (resolvedResults.length > 0) {
@@ -1379,8 +1452,15 @@ var WorkflowAgent = class {
1379
1452
  )
1380
1453
  )
1381
1454
  );
1382
- const providerToolResults = providerToolCalls.map(
1383
- (toolCall) => resolveProviderToolResult(toolCall, providerExecutedToolResults)
1455
+ const providerToolResults = await Promise.all(
1456
+ providerToolCalls.map(
1457
+ (toolCall) => resolveProviderToolResult(
1458
+ toolCall,
1459
+ providerExecutedToolResults,
1460
+ effectiveTools,
1461
+ download
1462
+ )
1463
+ )
1384
1464
  );
1385
1465
  await Promise.all(
1386
1466
  providerToolCalls.map(
@@ -1395,34 +1475,40 @@ var WorkflowAgent = class {
1395
1475
  const continuationInvalidToolResults = invalidToolCalls.map(
1396
1476
  createInvalidToolResult
1397
1477
  );
1398
- const continuationToolResults = toolCalls.flatMap((tc) => {
1399
- const invalidResult = continuationInvalidToolResults.find(
1400
- (r) => r.toolCallId === tc.toolCallId
1401
- );
1402
- if (invalidResult) return [invalidResult];
1478
+ const executedToolResults = toolCalls.flatMap((tc) => {
1403
1479
  const clientResult = clientToolResults.find(
1404
- (r) => r.toolCallId === tc.toolCallId
1480
+ (r) => r.modelResult.toolCallId === tc.toolCallId
1405
1481
  );
1406
1482
  if (clientResult) return [clientResult];
1407
1483
  const providerResult = providerToolResults.find(
1408
- (r) => r.toolCallId === tc.toolCallId
1484
+ (r) => r.modelResult.toolCallId === tc.toolCallId
1409
1485
  );
1410
1486
  if (providerResult) return [providerResult];
1411
1487
  return [];
1412
1488
  });
1413
- const executedToolResults = continuationToolResults.filter(
1414
- (result2) => !invalidToolCalls.some((tc) => tc.toolCallId === result2.toolCallId)
1415
- );
1489
+ const continuationToolResults = toolCalls.flatMap((tc) => {
1490
+ const invalidResult = continuationInvalidToolResults.find(
1491
+ (r) => r.toolCallId === tc.toolCallId
1492
+ );
1493
+ if (invalidResult) return [invalidResult];
1494
+ const executedResult = executedToolResults.find(
1495
+ (r) => r.modelResult.toolCallId === tc.toolCallId
1496
+ );
1497
+ if (executedResult) return [executedResult.modelResult];
1498
+ return [];
1499
+ });
1416
1500
  if (options.writable) {
1417
1501
  await writeToolResultsWithStepBoundary(
1418
1502
  options.writable,
1419
1503
  executedToolResults.map((r) => {
1420
1504
  var _a2;
1421
1505
  return {
1422
- toolCallId: r.toolCallId,
1423
- toolName: r.toolName,
1424
- input: (_a2 = toolCalls.find((tc) => tc.toolCallId === r.toolCallId)) == null ? void 0 : _a2.input,
1425
- output: "value" in r.output ? r.output.value : void 0
1506
+ toolCallId: r.modelResult.toolCallId,
1507
+ toolName: r.modelResult.toolName,
1508
+ input: (_a2 = toolCalls.find(
1509
+ (tc) => tc.toolCallId === r.modelResult.toolCallId
1510
+ )) == null ? void 0 : _a2.input,
1511
+ output: r.rawOutput
1426
1512
  };
1427
1513
  })
1428
1514
  );
@@ -1437,10 +1523,12 @@ var WorkflowAgent = class {
1437
1523
  var _a2;
1438
1524
  return {
1439
1525
  type: "tool-result",
1440
- toolCallId: r.toolCallId,
1441
- toolName: r.toolName,
1442
- input: (_a2 = toolCalls.find((tc) => tc.toolCallId === r.toolCallId)) == null ? void 0 : _a2.input,
1443
- output: "value" in r.output ? r.output.value : void 0
1526
+ toolCallId: r.modelResult.toolCallId,
1527
+ toolName: r.modelResult.toolName,
1528
+ input: (_a2 = toolCalls.find(
1529
+ (tc) => tc.toolCallId === r.modelResult.toolCallId
1530
+ )) == null ? void 0 : _a2.input,
1531
+ output: r.rawOutput
1444
1532
  };
1445
1533
  });
1446
1534
  result = await iterator.next(continuationToolResults);
@@ -1654,47 +1742,46 @@ function aggregateUsage(steps) {
1654
1742
  totalTokens: inputTokens + outputTokens
1655
1743
  };
1656
1744
  }
1657
- function getErrorMessage(error) {
1658
- if (error == null) {
1659
- return "unknown error";
1660
- }
1661
- if (typeof error === "string") {
1662
- return error;
1663
- }
1664
- if (error instanceof Error) {
1665
- return error.message;
1666
- }
1667
- return JSON.stringify(error);
1668
- }
1669
- function resolveProviderToolResult(toolCall, providerExecutedToolResults) {
1745
+ async function resolveProviderToolResult(toolCall, providerExecutedToolResults, tools, download) {
1670
1746
  const streamResult = providerExecutedToolResults == null ? void 0 : providerExecutedToolResults.get(toolCall.toolCallId);
1671
1747
  if (!streamResult) {
1672
1748
  console.warn(
1673
1749
  `[WorkflowAgent] Provider-executed tool "${toolCall.toolName}" (${toolCall.toolCallId}) did not receive a result from the stream. This may indicate a provider issue.`
1674
1750
  );
1675
1751
  return {
1676
- type: "tool-result",
1677
- toolCallId: toolCall.toolCallId,
1678
- toolName: toolCall.toolName,
1679
- output: {
1680
- type: "text",
1681
- value: ""
1682
- }
1752
+ modelResult: {
1753
+ type: "tool-result",
1754
+ toolCallId: toolCall.toolCallId,
1755
+ toolName: toolCall.toolName,
1756
+ output: {
1757
+ type: "text",
1758
+ value: ""
1759
+ }
1760
+ },
1761
+ rawOutput: "",
1762
+ isError: false
1683
1763
  };
1684
1764
  }
1685
1765
  const result = streamResult.result;
1686
- const isString = typeof result === "string";
1766
+ const errorMode = streamResult.isError ? typeof result === "string" ? "text" : "json" : "none";
1687
1767
  return {
1688
- type: "tool-result",
1689
- toolCallId: toolCall.toolCallId,
1690
- toolName: toolCall.toolName,
1691
- output: isString ? streamResult.isError ? { type: "error-text", value: result } : { type: "text", value: result } : streamResult.isError ? {
1692
- type: "error-json",
1693
- value: result
1694
- } : {
1695
- type: "json",
1696
- value: result
1697
- }
1768
+ modelResult: {
1769
+ type: "tool-result",
1770
+ toolCallId: toolCall.toolCallId,
1771
+ toolName: toolCall.toolName,
1772
+ output: await createLanguageModelToolResultOutput({
1773
+ toolCallId: toolCall.toolCallId,
1774
+ toolName: toolCall.toolName,
1775
+ input: toolCall.input,
1776
+ output: result,
1777
+ tool: tools == null ? void 0 : tools[toolCall.toolName],
1778
+ errorMode,
1779
+ supportedUrls: {},
1780
+ download
1781
+ })
1782
+ },
1783
+ rawOutput: result,
1784
+ isError: streamResult.isError === true
1698
1785
  };
1699
1786
  }
1700
1787
  function createInvalidToolResult(toolCall) {
@@ -1713,7 +1800,7 @@ function getToolCallbackMessages(messages) {
1713
1800
  const withoutAssistantToolCall = ((_a = messages.at(-1)) == null ? void 0 : _a.role) === "assistant" ? messages.slice(0, -1) : messages;
1714
1801
  return withoutAssistantToolCall;
1715
1802
  }
1716
- async function executeTool(toolCall, tools, messages, context) {
1803
+ async function executeTool(toolCall, tools, messages, context, download) {
1717
1804
  const tool2 = tools[toolCall.toolName];
1718
1805
  if (!tool2) throw new Error(`Tool "${toolCall.toolName}" not found`);
1719
1806
  if (typeof tool2.execute !== "function") {
@@ -1722,33 +1809,57 @@ async function executeTool(toolCall, tools, messages, context) {
1722
1809
  );
1723
1810
  }
1724
1811
  const parsedInput = toolCall.input;
1812
+ let toolResult;
1725
1813
  try {
1726
1814
  const { execute } = tool2;
1727
- const toolResult = await execute(parsedInput, {
1815
+ toolResult = await execute(parsedInput, {
1728
1816
  toolCallId: toolCall.toolCallId,
1729
1817
  // Pass the conversation messages to the tool so it has context about the conversation
1730
1818
  messages,
1731
1819
  // Pass per-tool context to the tool (resolved from `toolsContext`)
1732
1820
  context
1733
1821
  });
1734
- const output = typeof toolResult === "string" ? { type: "text", value: toolResult } : { type: "json", value: toolResult };
1735
- return {
1736
- type: "tool-result",
1737
- toolCallId: toolCall.toolCallId,
1738
- toolName: toolCall.toolName,
1739
- output
1740
- };
1741
1822
  } catch (error) {
1823
+ const errorMessage = getErrorMessage(error);
1742
1824
  return {
1825
+ modelResult: {
1826
+ type: "tool-result",
1827
+ toolCallId: toolCall.toolCallId,
1828
+ toolName: toolCall.toolName,
1829
+ output: await createLanguageModelToolResultOutput({
1830
+ toolCallId: toolCall.toolCallId,
1831
+ toolName: toolCall.toolName,
1832
+ input: parsedInput,
1833
+ output: errorMessage,
1834
+ tool: tool2,
1835
+ errorMode: "text",
1836
+ supportedUrls: {},
1837
+ download
1838
+ })
1839
+ },
1840
+ rawOutput: errorMessage,
1841
+ isError: true
1842
+ };
1843
+ }
1844
+ return {
1845
+ modelResult: {
1743
1846
  type: "tool-result",
1744
1847
  toolCallId: toolCall.toolCallId,
1745
1848
  toolName: toolCall.toolName,
1746
- output: {
1747
- type: "error-text",
1748
- value: getErrorMessage(error)
1749
- }
1750
- };
1751
- }
1849
+ output: await createLanguageModelToolResultOutput({
1850
+ toolCallId: toolCall.toolCallId,
1851
+ toolName: toolCall.toolName,
1852
+ input: parsedInput,
1853
+ output: toolResult,
1854
+ tool: tool2,
1855
+ errorMode: "none",
1856
+ supportedUrls: {},
1857
+ download
1858
+ })
1859
+ },
1860
+ rawOutput: toolResult,
1861
+ isError: false
1862
+ };
1752
1863
  }
1753
1864
  function collectToolApprovalsFromMessages(messages) {
1754
1865
  var _a;