@ai-sdk/workflow 2.0.72 → 2.0.73
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 +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -24
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/build-model-step-result.ts +6 -1
- package/src/do-generate-step.ts +15 -1
- package/src/do-stream-step.ts +28 -2
- package/src/model-call-iterator.ts +219 -4
- package/src/model-call-telemetry.ts +3 -3
- package/src/model-call.ts +14 -0
- package/src/serializable-schema.ts +18 -6
- package/src/test/telemetry-workflows.ts +30 -4
- package/src/to-ui-message-chunk.ts +3 -0
- package/src/workflow-agent.ts +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ai-sdk/workflow
|
|
2
2
|
|
|
3
|
+
## 2.0.73
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 88ea0d7: fix(workflow): pass runtime context allowed by 'telemetry.includeRuntimeContext'
|
|
8
|
+
- 6ac1ee1: fix(workflow): validate and normalize tool inputs with the original tool schema in `WorkflowAgent`, matching `streamText`. Defaults, transforms, coercion, refinements, unknown-key handling, custom validators, `repairToolCall`, and lifecycle callbacks now behave the same in durable runs, and approval requests retain the pre-transform input so transforms do not run twice on resume.
|
|
9
|
+
- Updated dependencies [2e89fa4]
|
|
10
|
+
- Updated dependencies [88ea0d7]
|
|
11
|
+
- @ai-sdk/provider-utils@5.0.60
|
|
12
|
+
- ai@7.0.141
|
|
13
|
+
|
|
3
14
|
## 2.0.72
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ type ModelCallStreamPart<TTools extends ToolSet = ToolSet> = Experimental_Langua
|
|
|
8
8
|
approvalId: string;
|
|
9
9
|
toolCallId: string;
|
|
10
10
|
signature?: string;
|
|
11
|
+
/** Raw input before the original tool schema transformed it. */
|
|
12
|
+
inputSchemaInput?: unknown;
|
|
11
13
|
} | {
|
|
12
14
|
type: 'reset-step';
|
|
13
15
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["CoreTelemetryOptions","SandboxSession","ToolCallRepairFunction"],"sources":["../src/model-call.ts","../src/types.ts","../src/workflow-agent.ts","../src/to-ui-message-chunk.ts","../src/normalize-ui-message-stream.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["CoreTelemetryOptions","SandboxSession","ToolCallRepairFunction"],"sources":["../src/model-call.ts","../src/types.ts","../src/workflow-agent.ts","../src/to-ui-message-chunk.ts","../src/normalize-ui-message-stream.ts"],"mappings":";;;;;KAyBY,oBAAoB,eAAe,UAAU,WACrD,qCAAqC;EAEnC;EACA;EACA;EACA;;EAEA;;EAEA;;;;;;;;;KCzBM,0BAA0B;;;;;;;;KC4E1B,+BACV,eAAe,UAAU,SACzB,wBAAwB,UAAU,WAChC,8BAA8B,QAAQ;;;;;;;KAQ9B,kCACV,eAAe,UAAU,SACzB,wBAAwB,UAAU,WAChC,+BAA+B,QAAQ;;;;KAK/B,wBAAwB,kBAClC,uBAAuB,oBAAoB,wBACvC;;;;KAMM,4BACV,gBACA,8BACE,UACF,yBAEA,aAAa,wBAAwB;;;;;UAatB,oBAAoB,QAAQ;WAClC;EACT,gBAAgB,YAAY;EAC5B,mBAAmB;IACjB;MACE;IAAU,SAAS;;EACvB,oBACE;IAAW;KACX;IACE,UAAU;IACV,OAAO;IACP,cAAc;MAEf,QAAQ;;KAGR,2BAA2B,wBAAwB,iBAAiB;;;;KAK7D,kBAAkB;;;;;KAMlB;;;;EAIV;;KAGG,mCAAmC,eAAe,WACrD,eAAe,oBAAoB;EAC7B,cAAc,oBAAoB;;EAClC;;KACI,iBACV,wBAAwB,UAAU,SAClC,eAAe,UAA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J,eAAe,aAAa,YAC5B,UAAU,2BAA2B,SACrC,iBAAiB,2BAA2B,iBAE5C,SAAS,2BACP,QACA,iBACA,SACA,kBAED,QAAQ,0BAA0B,QAAQ;UAI/B;UAuMA;;;;;;;;wBCp3DA,iBACd,MAAM,oBAAoB,WACzB;;;;;;;;;;;wBA2Na,oCACd;;;;;EAMA;IACO,gBAAgB,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBC9HhC,8BACrB,QAAQ,cAAc,kBACrB,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as normalizeUIMessageStreamParts, t as WorkflowChatTransport } from "./workflow-chat-transport-Dj1poviu.js";
|
|
2
|
-
import { asArray, asSchema, convertUint8ArrayToBase64, createIdGenerator, generateId, getErrorMessage, isAbortError, jsonSchema, validateTypes, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
3
|
-
import { DefaultGeneratedFile, InvalidToolApprovalSignatureError, NoOutputGeneratedError, Output, ToolChoiceViolationError, dynamicTool, experimental_filterActiveTools, experimental_streamLanguageModelCall, gateway, isStepCount, tool, wrapLanguageModel } from "ai";
|
|
4
|
-
import { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertLanguageModelContent, convertToLanguageModelPrompt, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, isOutputChunk, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, validateApprovedToolApprovals, verifyToolApprovalSignature } from "ai/internal";
|
|
2
|
+
import { asArray, asSchema, convertUint8ArrayToBase64, createIdGenerator, generateId, getErrorMessage, isAbortError, jsonSchema, safeParseJSON, validateTypes, withUserAgentSuffix } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { DefaultGeneratedFile, InvalidToolApprovalSignatureError, InvalidToolInputError, NoOutputGeneratedError, Output, ToolChoiceViolationError, dynamicTool, experimental_filterActiveTools, experimental_streamLanguageModelCall, gateway, isDeepEqualData, isStepCount, tool, wrapLanguageModel } from "ai";
|
|
4
|
+
import { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertLanguageModelContent, convertToLanguageModelPrompt, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, filterIncludedContext, isOutputChunk, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, validateApprovedToolApprovals, verifyToolApprovalSignature } from "ai/internal";
|
|
5
5
|
import { getWorkflowMetadata } from "workflow";
|
|
6
6
|
import Ajv from "ajv";
|
|
7
7
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
@@ -143,9 +143,9 @@ async function buildModelStepResult(raw, toolCalls, finish, providerExecutedTool
|
|
|
143
143
|
if (!("reasoningIndex" in part)) providerContent.push(part);
|
|
144
144
|
break;
|
|
145
145
|
case "tool-call": {
|
|
146
|
-
const
|
|
146
|
+
const { inputSchemaInput: _inputSchemaInput, ...publicCall } = toolCalls[part.toolCallIndex];
|
|
147
147
|
providerContent.push({
|
|
148
|
-
...
|
|
148
|
+
...publicCall,
|
|
149
149
|
input: "",
|
|
150
150
|
type: "tool-call"
|
|
151
151
|
});
|
|
@@ -410,6 +410,7 @@ function languageModelPromptToModelMessages(prompt) {
|
|
|
410
410
|
*/
|
|
411
411
|
function serializeToolSet(tools, { toolsContext = {}, experimental_sandbox: sandbox } = {}) {
|
|
412
412
|
return Object.fromEntries(Object.entries(tools).map(([name, t]) => {
|
|
413
|
+
const inputSchema = asSchema(t.inputSchema);
|
|
413
414
|
const def = {
|
|
414
415
|
title: t.title,
|
|
415
416
|
metadata: t.metadata,
|
|
@@ -419,11 +420,12 @@ function serializeToolSet(tools, { toolsContext = {}, experimental_sandbox: sand
|
|
|
419
420
|
toolsContext,
|
|
420
421
|
experimental_sandbox: sandbox
|
|
421
422
|
}),
|
|
422
|
-
inputSchema:
|
|
423
|
+
inputSchema: inputSchema.jsonSchema,
|
|
423
424
|
strict: t.strict,
|
|
424
425
|
inputExamples: t.inputExamples,
|
|
425
426
|
providerOptions: t.providerOptions
|
|
426
427
|
};
|
|
428
|
+
if (inputSchema.validate != null) def.hasOwnValidator = true;
|
|
427
429
|
if (t.type === "dynamic") def.type = "dynamic";
|
|
428
430
|
if (t.onInputStart != null) def.hasOnInputStart = true;
|
|
429
431
|
if (t.onInputDelta != null) def.hasOnInputDelta = true;
|
|
@@ -457,9 +459,9 @@ function formatAjvError(error) {
|
|
|
457
459
|
/**
|
|
458
460
|
* Reconstructs tool objects from serializable tool definitions inside a step.
|
|
459
461
|
*
|
|
460
|
-
* Wraps each tool's JSON Schema with `jsonSchema()
|
|
461
|
-
*
|
|
462
|
-
*
|
|
462
|
+
* Wraps each tool's JSON Schema with `jsonSchema()`. Tools without their own
|
|
463
|
+
* validator are validated with Ajv. Tools with their own validator are
|
|
464
|
+
* validated after the workflow step, where the original schema is available.
|
|
463
465
|
*/
|
|
464
466
|
function resolveSerializableTools(tools) {
|
|
465
467
|
const ajvOptions = {
|
|
@@ -482,6 +484,7 @@ function resolveSerializableTools(tools) {
|
|
|
482
484
|
};
|
|
483
485
|
} });
|
|
484
486
|
};
|
|
487
|
+
const createInputSchema = (tool) => tool.hasOwnValidator ? jsonSchema(tool.inputSchema) : createValidatedInputSchema(tool.inputSchema);
|
|
485
488
|
return Object.fromEntries(Object.entries(tools).map(([name, t]) => {
|
|
486
489
|
if (t.type === "provider") {
|
|
487
490
|
const providerTool = {
|
|
@@ -506,7 +509,7 @@ function resolveSerializableTools(tools) {
|
|
|
506
509
|
description: t.description,
|
|
507
510
|
inputExamples: t.inputExamples,
|
|
508
511
|
providerOptions: t.providerOptions,
|
|
509
|
-
inputSchema:
|
|
512
|
+
inputSchema: createInputSchema(t)
|
|
510
513
|
})];
|
|
511
514
|
const functionTool = {
|
|
512
515
|
title: t.title,
|
|
@@ -515,7 +518,7 @@ function resolveSerializableTools(tools) {
|
|
|
515
518
|
strict: t.strict,
|
|
516
519
|
inputExamples: t.inputExamples,
|
|
517
520
|
providerOptions: t.providerOptions,
|
|
518
|
-
inputSchema:
|
|
521
|
+
inputSchema: createInputSchema(t)
|
|
519
522
|
};
|
|
520
523
|
return [name, t.type === "dynamic" ? tool({
|
|
521
524
|
...functionTool,
|
|
@@ -573,7 +576,7 @@ async function runModelCallWithTelemetry({ telemetry, modelInit, prompt, seriali
|
|
|
573
576
|
reasoning: options?.reasoning,
|
|
574
577
|
providerOptions: options?.providerOptions,
|
|
575
578
|
output: void 0,
|
|
576
|
-
runtimeContext: {},
|
|
579
|
+
runtimeContext: telemetry.runtimeContext ?? {},
|
|
577
580
|
toolsContext: {}
|
|
578
581
|
});
|
|
579
582
|
await dispatcher.onStepStart?.({
|
|
@@ -589,7 +592,7 @@ async function runModelCallWithTelemetry({ telemetry, modelInit, prompt, seriali
|
|
|
589
592
|
steps: [],
|
|
590
593
|
providerOptions: options?.providerOptions,
|
|
591
594
|
output: void 0,
|
|
592
|
-
runtimeContext: {},
|
|
595
|
+
runtimeContext: telemetry.runtimeContext ?? {},
|
|
593
596
|
toolsContext: {}
|
|
594
597
|
});
|
|
595
598
|
let result;
|
|
@@ -625,7 +628,7 @@ async function runModelCallWithTelemetry({ telemetry, modelInit, prompt, seriali
|
|
|
625
628
|
callId,
|
|
626
629
|
tools,
|
|
627
630
|
stepNumber: telemetry.stepNumber,
|
|
628
|
-
runtimeContext: {},
|
|
631
|
+
runtimeContext: telemetry.runtimeContext ?? {},
|
|
629
632
|
toolsContext: {}
|
|
630
633
|
});
|
|
631
634
|
await dispatcher.onStepEnd?.(step);
|
|
@@ -733,10 +736,17 @@ async function generateModelCall(prompt, modelInit, serializedTools, options, la
|
|
|
733
736
|
performance: { responseTimeMs }
|
|
734
737
|
});
|
|
735
738
|
abortSignal?.throwIfAborted();
|
|
739
|
+
const repairedToolCallIds = /* @__PURE__ */ new Set();
|
|
740
|
+
const repairToolCall = options.repairToolCall;
|
|
741
|
+
const trackedRepairToolCall = repairToolCall ? async (repairOptions) => {
|
|
742
|
+
const repaired = await repairToolCall(repairOptions);
|
|
743
|
+
if (repaired != null) repairedToolCallIds.add(repairOptions.toolCall.toolCallId);
|
|
744
|
+
return repaired;
|
|
745
|
+
} : void 0;
|
|
736
746
|
const toolCalls = await Promise.all(response.content.filter((part) => part.type === "tool-call").map((toolCall) => parseToolCall({
|
|
737
747
|
toolCall,
|
|
738
748
|
tools,
|
|
739
|
-
repairToolCall:
|
|
749
|
+
repairToolCall: trackedRepairToolCall,
|
|
740
750
|
instructions: modelPrompt.filter((message) => message.role === "system").map((message) => message.content).join("\n") || void 0,
|
|
741
751
|
messages: prompt.filter((message) => message.role !== "system")
|
|
742
752
|
})));
|
|
@@ -808,7 +818,8 @@ async function generateModelCall(prompt, modelInit, serializedTools, options, la
|
|
|
808
818
|
}
|
|
809
819
|
},
|
|
810
820
|
providerExecutedToolResults,
|
|
811
|
-
toolInputLifecycleEvents
|
|
821
|
+
toolInputLifecycleEvents,
|
|
822
|
+
repairedToolCallIds: [...repairedToolCallIds]
|
|
812
823
|
};
|
|
813
824
|
}
|
|
814
825
|
doGenerateStep.maxRetries = 0;
|
|
@@ -832,6 +843,13 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
832
843
|
const abortSignal = timeout == null ? options?.abortSignal : options?.abortSignal == null ? AbortSignal.timeout(timeout) : AbortSignal.any([options.abortSignal, AbortSignal.timeout(timeout)]);
|
|
833
844
|
const model = typeof modelInit === "string" ? gateway.languageModel(modelInit) : modelInit;
|
|
834
845
|
const toolInputLifecycleEvents = [];
|
|
846
|
+
const repairedToolCallIds = /* @__PURE__ */ new Set();
|
|
847
|
+
const repairToolCall = options?.repairToolCall;
|
|
848
|
+
const trackedRepairToolCall = repairToolCall ? async (repairOptions) => {
|
|
849
|
+
const repaired = await repairToolCall(repairOptions);
|
|
850
|
+
if (repaired != null) repairedToolCallIds.add(repairOptions.toolCall.toolCallId);
|
|
851
|
+
return repaired;
|
|
852
|
+
} : void 0;
|
|
835
853
|
const tools = serializedTools ? resolveSerializableTools(serializedTools) : void 0;
|
|
836
854
|
const modelWithTransforms = options?.experimental_transform == null ? model : wrapLanguageModel({
|
|
837
855
|
model,
|
|
@@ -885,7 +903,7 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
885
903
|
frequencyPenalty: options?.frequencyPenalty,
|
|
886
904
|
stopSequences: options?.stopSequences,
|
|
887
905
|
seed: options?.seed,
|
|
888
|
-
repairToolCall:
|
|
906
|
+
repairToolCall: trackedRepairToolCall,
|
|
889
907
|
download: options?.download,
|
|
890
908
|
...languageModelCallTelemetry
|
|
891
909
|
}));
|
|
@@ -1086,7 +1104,7 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
1086
1104
|
toolCallId: part.toolCall.toolCallId,
|
|
1087
1105
|
...part.signature != null ? { signature: part.signature } : {}
|
|
1088
1106
|
});
|
|
1089
|
-
else await writer.write(part);
|
|
1107
|
+
else if (!((part.type === "tool-call" || part.type === "tool-error" && !part.providerExecuted) && serializedTools?.[part.toolName]?.hasOwnValidator)) await writer.write(part);
|
|
1090
1108
|
}
|
|
1091
1109
|
if (part.type === "error" && !hasTerminalError) {
|
|
1092
1110
|
terminalError = part.error;
|
|
@@ -1116,6 +1134,7 @@ async function streamModelStep(conversationPrompt, modelInit, writable, serializ
|
|
|
1116
1134
|
},
|
|
1117
1135
|
providerExecutedToolResults,
|
|
1118
1136
|
toolInputLifecycleEvents,
|
|
1137
|
+
repairedToolCallIds: [...repairedToolCallIds],
|
|
1119
1138
|
...hasTerminalError ? { terminalError } : {}
|
|
1120
1139
|
};
|
|
1121
1140
|
}
|
|
@@ -1343,7 +1362,12 @@ async function* modelCallIterator({ prompt, mode = "stream", include, initialIns
|
|
|
1343
1362
|
functionId: telemetry?.functionId,
|
|
1344
1363
|
recordInputs: telemetry?.recordInputs,
|
|
1345
1364
|
recordOutputs: telemetry?.recordOutputs,
|
|
1346
|
-
stepNumber
|
|
1365
|
+
stepNumber,
|
|
1366
|
+
includeRuntimeContext: telemetry?.includeRuntimeContext,
|
|
1367
|
+
runtimeContext: filterIncludedContext({
|
|
1368
|
+
context: currentRuntimeContext,
|
|
1369
|
+
includeContext: telemetry?.includeRuntimeContext
|
|
1370
|
+
})
|
|
1347
1371
|
} : void 0
|
|
1348
1372
|
};
|
|
1349
1373
|
const modelCallResult = mode === "generate" ? await doGenerateStep(conversationPrompt, currentModel, serializedTools, callOptions) : await doStreamStep(conversationPrompt, currentModel, writable, serializedTools, callOptions);
|
|
@@ -1356,7 +1380,18 @@ async function* modelCallIterator({ prompt, mode = "stream", include, initialIns
|
|
|
1356
1380
|
terminalError = modelCallResult.terminalError;
|
|
1357
1381
|
hasTerminalError = true;
|
|
1358
1382
|
}
|
|
1359
|
-
const { toolCalls, finish, raw, providerExecutedToolResults, toolInputLifecycleEvents } = modelCallResult;
|
|
1383
|
+
const { toolCalls: serializedToolCalls, finish, raw, providerExecutedToolResults, toolInputLifecycleEvents, repairedToolCallIds } = modelCallResult;
|
|
1384
|
+
const toolCalls = await validateToolCallInputs({
|
|
1385
|
+
toolCalls: serializedToolCalls,
|
|
1386
|
+
tools: effectiveTools,
|
|
1387
|
+
serializedTools,
|
|
1388
|
+
repairToolCall,
|
|
1389
|
+
repairedToolCallIds: new Set(repairedToolCallIds),
|
|
1390
|
+
instructions: conversationPrompt.filter((message) => message.role === "system").map((message) => message.content).join("\n") || initialInstructions,
|
|
1391
|
+
messages: stepInputMessages.filter((message) => message.role !== "system"),
|
|
1392
|
+
abortSignal: currentGenerationSettings.abortSignal
|
|
1393
|
+
});
|
|
1394
|
+
if (mode === "stream" && writable != null) await writeDeferredToolCalls(writable, toolCalls.filter((_, index) => serializedTools[serializedToolCalls[index].toolName]?.hasOwnValidator));
|
|
1360
1395
|
await invokeToolInputLifecycleCallbacks({
|
|
1361
1396
|
events: toolInputLifecycleEvents ?? [],
|
|
1362
1397
|
toolCalls,
|
|
@@ -1460,6 +1495,100 @@ async function* modelCallIterator({ prompt, mode = "stream", include, initialIns
|
|
|
1460
1495
|
};
|
|
1461
1496
|
return conversationPrompt;
|
|
1462
1497
|
}
|
|
1498
|
+
async function validateToolCallInputs({ toolCalls, tools, serializedTools, repairToolCall, repairedToolCallIds, instructions, messages, abortSignal }) {
|
|
1499
|
+
return Promise.all(toolCalls.map(async (toolCall) => {
|
|
1500
|
+
if (toolCall.invalid || toolCall.providerExecuted) return toolCall;
|
|
1501
|
+
const tool = tools[toolCall.toolName];
|
|
1502
|
+
if (tool == null) return toolCall;
|
|
1503
|
+
if (asSchema(tool.inputSchema).validate == null) return toolCall;
|
|
1504
|
+
let repairedInput;
|
|
1505
|
+
const parsedToolCall = await parseToolCall({
|
|
1506
|
+
toolCall: {
|
|
1507
|
+
type: "tool-call",
|
|
1508
|
+
toolCallId: toolCall.toolCallId,
|
|
1509
|
+
toolName: toolCall.toolName,
|
|
1510
|
+
input: JSON.stringify(toolCall.input) ?? (toolCall.input == null ? "" : String(toolCall.input)),
|
|
1511
|
+
providerExecuted: toolCall.providerExecuted,
|
|
1512
|
+
providerMetadata: toolCall.providerMetadata
|
|
1513
|
+
},
|
|
1514
|
+
tools,
|
|
1515
|
+
repairToolCall: repairToolCall == null || repairedToolCallIds.has(toolCall.toolCallId) ? void 0 : async (options) => {
|
|
1516
|
+
const repairedToolCall = await repairToolCallInStep({
|
|
1517
|
+
repairToolCall,
|
|
1518
|
+
serializedTools,
|
|
1519
|
+
toolCall: options.toolCall,
|
|
1520
|
+
error: {
|
|
1521
|
+
toolName: options.toolCall.toolName,
|
|
1522
|
+
toolInput: options.toolCall.input,
|
|
1523
|
+
message: getErrorMessage(options.error)
|
|
1524
|
+
},
|
|
1525
|
+
instructions,
|
|
1526
|
+
messages: options.messages
|
|
1527
|
+
});
|
|
1528
|
+
if (repairedToolCall != null) {
|
|
1529
|
+
const parsedRepairedInput = repairedToolCall.input.trim() === "" ? {
|
|
1530
|
+
success: true,
|
|
1531
|
+
value: {}
|
|
1532
|
+
} : await safeParseJSON({ text: repairedToolCall.input });
|
|
1533
|
+
if (parsedRepairedInput.success) repairedInput = { value: parsedRepairedInput.value };
|
|
1534
|
+
}
|
|
1535
|
+
return repairedToolCall;
|
|
1536
|
+
},
|
|
1537
|
+
instructions,
|
|
1538
|
+
messages,
|
|
1539
|
+
abortSignal
|
|
1540
|
+
});
|
|
1541
|
+
const inputSchemaInput = repairedInput ?? { value: toolCall.input };
|
|
1542
|
+
return {
|
|
1543
|
+
...toolCall,
|
|
1544
|
+
...parsedToolCall,
|
|
1545
|
+
...!parsedToolCall.invalid && !isDeepEqualData(inputSchemaInput.value, parsedToolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {}
|
|
1546
|
+
};
|
|
1547
|
+
}));
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Runs `repairToolCall` inside a step. The callback may be a `'use step'`
|
|
1551
|
+
* function, so its arguments must be serializable: the tools and the
|
|
1552
|
+
* `inputSchema` accessor are rebuilt here instead of crossing the boundary
|
|
1553
|
+
* from the workflow body.
|
|
1554
|
+
*/
|
|
1555
|
+
async function repairToolCallInStep({ repairToolCall, serializedTools, toolCall, error, instructions, messages }) {
|
|
1556
|
+
"use step";
|
|
1557
|
+
const tools = resolveSerializableTools(serializedTools);
|
|
1558
|
+
return repairToolCall({
|
|
1559
|
+
toolCall,
|
|
1560
|
+
tools,
|
|
1561
|
+
inputSchema: async ({ toolName }) => asSchema(tools[toolName]?.inputSchema).jsonSchema,
|
|
1562
|
+
instructions,
|
|
1563
|
+
system: instructions,
|
|
1564
|
+
messages,
|
|
1565
|
+
error: new InvalidToolInputError({
|
|
1566
|
+
toolName: error.toolName,
|
|
1567
|
+
toolInput: error.toolInput,
|
|
1568
|
+
cause: new Error(error.message),
|
|
1569
|
+
message: error.message
|
|
1570
|
+
})
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
async function writeDeferredToolCalls(writable, toolCalls) {
|
|
1574
|
+
"use step";
|
|
1575
|
+
const writer = writable.getWriter();
|
|
1576
|
+
try {
|
|
1577
|
+
for (const toolCall of toolCalls) {
|
|
1578
|
+
await writer.write(toolCall);
|
|
1579
|
+
if (toolCall.invalid && !toolCall.providerExecuted) await writer.write({
|
|
1580
|
+
type: "tool-error",
|
|
1581
|
+
toolCallId: toolCall.toolCallId,
|
|
1582
|
+
toolName: toolCall.toolName,
|
|
1583
|
+
input: toolCall.input,
|
|
1584
|
+
error: getErrorMessage(toolCall.error),
|
|
1585
|
+
dynamic: true
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
} finally {
|
|
1589
|
+
writer.releaseLock();
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1463
1592
|
async function invokeToolInputLifecycleCallbacks({ events, toolCalls, tools, messages, abortSignal, toolsContext, experimental_sandbox }) {
|
|
1464
1593
|
const toolNamesByCallId = /* @__PURE__ */ new Map();
|
|
1465
1594
|
const toolCallsById = new Map(toolCalls.map((toolCall) => [toolCall.toolCallId, toolCall]));
|
|
@@ -1499,7 +1628,7 @@ async function invokeToolInputLifecycleCallbacks({ events, toolCalls, tools, mes
|
|
|
1499
1628
|
break;
|
|
1500
1629
|
case "available": {
|
|
1501
1630
|
const toolCall = toolCallsById.get(toolCallId);
|
|
1502
|
-
if (toolCall == null) break;
|
|
1631
|
+
if (toolCall == null || toolCall.invalid) break;
|
|
1503
1632
|
await tool.onInputAvailable?.({
|
|
1504
1633
|
...options,
|
|
1505
1634
|
input: toolCall.input
|
|
@@ -2357,6 +2486,7 @@ var WorkflowAgent = class {
|
|
|
2357
2486
|
addToolResultsToStep(step, executedResults, mode);
|
|
2358
2487
|
const approvalToolCalls = pausedToolCalls.filter((tc) => approvalNeeded[nonProviderToolCalls.indexOf(tc)]);
|
|
2359
2488
|
const approvalRequests = await Promise.all(approvalToolCalls.map(async (tc) => {
|
|
2489
|
+
const { inputSchemaInput, ...toolCallWithoutInputSchemaInput } = tc;
|
|
2360
2490
|
const approvalId = `approval-${tc.toolCallId}`;
|
|
2361
2491
|
const signature = effectiveToolApprovalSecret == null ? void 0 : await signWorkflowToolApproval({
|
|
2362
2492
|
secret: effectiveToolApprovalSecret,
|
|
@@ -2368,14 +2498,15 @@ var WorkflowAgent = class {
|
|
|
2368
2498
|
return {
|
|
2369
2499
|
type: "tool-approval-request",
|
|
2370
2500
|
approvalId,
|
|
2501
|
+
...inputSchemaInput !== void 0 ? { inputSchemaInput } : {},
|
|
2371
2502
|
toolCall: {
|
|
2372
|
-
...
|
|
2503
|
+
...toolCallWithoutInputSchemaInput,
|
|
2373
2504
|
type: "tool-call"
|
|
2374
2505
|
},
|
|
2375
2506
|
...signature != null ? { signature } : {}
|
|
2376
2507
|
};
|
|
2377
2508
|
}));
|
|
2378
|
-
step?.content.push(...approvalRequests);
|
|
2509
|
+
step?.content.push(...approvalRequests.map(({ inputSchemaInput: _inputSchemaInput, ...request }) => request));
|
|
2379
2510
|
const approvalMessages = approvalRequests.map(({ toolCall, ...request }) => ({
|
|
2380
2511
|
...request,
|
|
2381
2512
|
toolCallId: toolCall.toolCallId
|
|
@@ -2644,7 +2775,8 @@ async function writeApprovalRequests(writable, approvalRequests) {
|
|
|
2644
2775
|
type: "tool-approval-request",
|
|
2645
2776
|
approvalId: request.approvalId,
|
|
2646
2777
|
toolCallId: request.toolCallId,
|
|
2647
|
-
...request.signature != null ? { signature: request.signature } : {}
|
|
2778
|
+
...request.signature != null ? { signature: request.signature } : {},
|
|
2779
|
+
...request.inputSchemaInput !== void 0 ? { inputSchemaInput: request.inputSchemaInput } : {}
|
|
2648
2780
|
});
|
|
2649
2781
|
} finally {
|
|
2650
2782
|
writer.releaseLock();
|
|
@@ -3023,6 +3155,7 @@ function toUIMessageChunk(part) {
|
|
|
3023
3155
|
type: "tool-approval-request",
|
|
3024
3156
|
approvalId: part.approvalId,
|
|
3025
3157
|
toolCallId: "toolCallId" in part ? part.toolCallId : part.toolCall.toolCallId,
|
|
3158
|
+
..."inputSchemaInput" in part && part.inputSchemaInput !== void 0 ? { inputSchemaInput: part.inputSchemaInput } : {},
|
|
3026
3159
|
...part.signature != null ? { signature: part.signature } : {}
|
|
3027
3160
|
};
|
|
3028
3161
|
default: {
|