ai 7.0.112 → 7.0.114
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 +35 -0
- package/README.md +6 -6
- package/dist/index.d.ts +16 -0
- package/dist/index.js +378 -256
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +182 -78
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +3 -0
- package/docs/02-foundations/03-prompts.mdx +1 -1
- package/docs/02-foundations/04-tools.mdx +2 -2
- package/docs/02-foundations/06-provider-options.mdx +11 -11
- package/docs/02-getting-started/00-choosing-a-provider.mdx +4 -4
- package/docs/02-getting-started/02-nextjs-app-router.mdx +3 -3
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +3 -3
- package/docs/02-getting-started/04-svelte.mdx +7 -7
- package/docs/02-getting-started/05-nuxt.mdx +7 -7
- package/docs/02-getting-started/06-nodejs.mdx +3 -3
- package/docs/02-getting-started/07-expo.mdx +3 -3
- package/docs/02-getting-started/08-tanstack-start.mdx +3 -3
- package/docs/02-getting-started/09-coding-agents.mdx +1 -1
- package/docs/03-agents/03-workflows.mdx +2 -2
- package/docs/03-agents/04-loop-control.mdx +1 -1
- package/docs/03-agents/05-configuring-call-options.mdx +4 -2
- package/docs/03-agents/06-memory.mdx +2 -2
- package/docs/03-agents/06-policy-tool-approvals.mdx +2 -2
- package/docs/03-agents/06-tool-approvals.mdx +16 -0
- package/docs/03-agents/07-workflow-agent.mdx +11 -11
- package/docs/03-agents/08-terminal-ui.mdx +2 -2
- package/docs/03-ai-sdk-core/05-generating-text.mdx +2 -2
- package/docs/03-ai-sdk-core/17-mcp-apps.mdx +1 -1
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +1 -1
- package/docs/03-ai-sdk-core/26-reasoning.mdx +13 -12
- package/docs/03-ai-sdk-core/31-reranking.mdx +12 -10
- package/docs/03-ai-sdk-core/32-evaluation.mdx +1 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -2
- package/docs/03-ai-sdk-core/37-speech.mdx +8 -6
- package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/41-skill-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +21 -21
- package/docs/03-ai-sdk-core/60-telemetry.mdx +1 -1
- package/docs/03-ai-sdk-core/65-devtools.mdx +3 -3
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +1 -1
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +3 -3
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +3 -3
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +1 -1
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +5 -5
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +1 -1
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +1 -1
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +5 -3
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -3
- package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +5 -5
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +4 -2
- package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +18 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +3 -3
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +8 -8
- package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +1 -1
- package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +3 -3
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +2 -2
- package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +1 -1
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
- package/package.json +11 -11
- package/src/embed/embed-many.ts +18 -2
- package/src/evaluate/evaluate.ts +1 -10
- package/src/generate-speech/generate-speech.ts +15 -4
- package/src/generate-speech/generated-audio-file.ts +0 -8
- package/src/generate-text/execute-tools-from-stream.ts +0 -2
- package/src/generate-text/generate-text.ts +1 -0
- package/src/generate-text/generated-file.ts +0 -8
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +9 -8
- package/src/generate-text/output.ts +0 -2
- package/src/generate-text/parse-tool-call.ts +38 -25
- package/src/generate-text/restricted-telemetry-dispatcher.ts +6 -58
- package/src/generate-text/stream-text.ts +1 -0
- package/src/generate-text/to-response-messages.ts +7 -0
- package/src/generate-text/tool-call.ts +26 -0
- package/src/generate-text/validate-tool-approvals.ts +39 -3
- package/src/generate-video/generate-video.ts +0 -2
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +9 -1
- package/src/model/get-embedding-model-provider-options-transformer.ts +17 -0
- package/src/prompt/content-part.ts +3 -0
- package/src/prompt/standardize-prompt.ts +2 -0
- package/src/registry/custom-provider.ts +12 -5
- package/src/telemetry/create-telemetry-dispatcher.ts +58 -6
- package/src/telemetry/filter-included-context.ts +57 -2
- package/src/ui/chat.ts +108 -17
- package/src/ui/convert-to-model-messages.ts +8 -0
- package/src/ui/direct-chat-transport.ts +2 -0
- package/src/ui/process-ui-message-stream.ts +6 -0
- package/src/ui/ui-messages.ts +10 -0
- package/src/ui/validate-ui-messages.ts +98 -132
- package/src/ui-message-stream/to-ui-message-chunk.ts +7 -0
- package/src/ui-message-stream/ui-message-chunks.ts +2 -0
- package/src/util/write-to-server-response.ts +0 -2
package/dist/internal/index.d.ts
CHANGED
|
@@ -2911,7 +2911,7 @@ declare function verifyToolApprovalSignature({ secret, signature, approvalId, to
|
|
|
2911
2911
|
* message history before they are executed. Checks HMAC signature (when
|
|
2912
2912
|
* configured), input schema, and approval policy.
|
|
2913
2913
|
*/
|
|
2914
|
-
declare function validateApprovedToolApprovals<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never>({ approvedToolApprovals, tools, toolApproval, messages, toolsContext, runtimeContext, toolApprovalSecret, }: {
|
|
2914
|
+
declare function validateApprovedToolApprovals<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context | unknown | never>({ approvedToolApprovals, tools, toolApproval, messages, toolsContext, runtimeContext, toolApprovalSecret, refineToolInput, }: {
|
|
2915
2915
|
approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2916
2916
|
tools: TOOLS | undefined;
|
|
2917
2917
|
toolApproval: ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT> | undefined;
|
|
@@ -2919,6 +2919,7 @@ declare function validateApprovedToolApprovals<TOOLS extends ToolSet, RUNTIME_CO
|
|
|
2919
2919
|
toolsContext: InferToolSetContext<TOOLS>;
|
|
2920
2920
|
runtimeContext: RUNTIME_CONTEXT;
|
|
2921
2921
|
toolApprovalSecret?: string | Uint8Array;
|
|
2922
|
+
refineToolInput?: ToolInputRefinement<TOOLS>;
|
|
2922
2923
|
}): Promise<{
|
|
2923
2924
|
approvedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
|
2924
2925
|
deniedToolApprovals: Array<CollectedToolApprovals<TOOLS>>;
|
package/dist/internal/index.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
} from "@ai-sdk/provider-utils";
|
|
92
92
|
|
|
93
93
|
// src/version.ts
|
|
94
|
-
var VERSION = true ? "7.0.
|
|
94
|
+
var VERSION = true ? "7.0.114" : "0.0.0-test";
|
|
95
95
|
|
|
96
96
|
// src/util/download/download.ts
|
|
97
97
|
var download = async ({
|
|
@@ -1462,7 +1462,10 @@ var toolApprovalRequestSchema = z.object(
|
|
|
1462
1462
|
type: z.literal("tool-approval-request"),
|
|
1463
1463
|
approvalId: z.string(),
|
|
1464
1464
|
toolCallId: z.string(),
|
|
1465
|
-
reason: z.string().optional()
|
|
1465
|
+
reason: z.string().optional(),
|
|
1466
|
+
isAutomatic: z.boolean().optional(),
|
|
1467
|
+
signature: z.string().optional(),
|
|
1468
|
+
inputSchemaInput: z.unknown().optional()
|
|
1466
1469
|
}
|
|
1467
1470
|
);
|
|
1468
1471
|
var toolApprovalResponseSchema = z.object({
|
|
@@ -2513,6 +2516,50 @@ function mergeCallbacks(...callbacks) {
|
|
|
2513
2516
|
// src/telemetry/create-telemetry-dispatcher.ts
|
|
2514
2517
|
import { asArray as asArray3 } from "@ai-sdk/provider-utils";
|
|
2515
2518
|
|
|
2519
|
+
// src/telemetry/filter-included-context.ts
|
|
2520
|
+
function filterIncludedContext({
|
|
2521
|
+
context,
|
|
2522
|
+
includeContext
|
|
2523
|
+
}) {
|
|
2524
|
+
if (context == null) {
|
|
2525
|
+
return {};
|
|
2526
|
+
}
|
|
2527
|
+
return Object.fromEntries(
|
|
2528
|
+
Object.entries(context).filter(
|
|
2529
|
+
([key]) => (includeContext == null ? void 0 : includeContext[key]) === true
|
|
2530
|
+
)
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2533
|
+
function filterToolsContext({
|
|
2534
|
+
toolsContext,
|
|
2535
|
+
includeToolsContext
|
|
2536
|
+
}) {
|
|
2537
|
+
if (includeToolsContext == null) {
|
|
2538
|
+
return {};
|
|
2539
|
+
}
|
|
2540
|
+
return Object.fromEntries(
|
|
2541
|
+
Object.entries(toolsContext).map(([toolName, toolContext]) => [
|
|
2542
|
+
toolName,
|
|
2543
|
+
filterToolContext({
|
|
2544
|
+
toolName,
|
|
2545
|
+
toolContext,
|
|
2546
|
+
includeToolsContext
|
|
2547
|
+
})
|
|
2548
|
+
])
|
|
2549
|
+
);
|
|
2550
|
+
}
|
|
2551
|
+
function filterToolContext({
|
|
2552
|
+
toolName,
|
|
2553
|
+
toolContext,
|
|
2554
|
+
includeToolsContext
|
|
2555
|
+
}) {
|
|
2556
|
+
const includeToolContext = includeToolsContext == null ? void 0 : includeToolsContext[toolName];
|
|
2557
|
+
return filterIncludedContext({
|
|
2558
|
+
context: toolContext,
|
|
2559
|
+
includeContext: includeToolContext
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2516
2563
|
// src/telemetry/tracing-channel.ts
|
|
2517
2564
|
var AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
|
|
2518
2565
|
|
|
@@ -2663,12 +2710,37 @@ function getGlobalTelemetryIntegrations() {
|
|
|
2663
2710
|
}
|
|
2664
2711
|
|
|
2665
2712
|
// src/telemetry/create-telemetry-dispatcher.ts
|
|
2666
|
-
function augmentEvent(event, telemetry) {
|
|
2667
|
-
|
|
2713
|
+
function augmentEvent(event, telemetry, filterContext = false) {
|
|
2714
|
+
const augmentedEvent = Object.assign(
|
|
2668
2715
|
Object.create(Object.getPrototypeOf(event)),
|
|
2669
2716
|
event,
|
|
2670
|
-
|
|
2717
|
+
{
|
|
2718
|
+
recordInputs: telemetry.recordInputs,
|
|
2719
|
+
recordOutputs: telemetry.recordOutputs,
|
|
2720
|
+
functionId: telemetry.functionId
|
|
2721
|
+
}
|
|
2671
2722
|
);
|
|
2723
|
+
if (filterContext && event != null && typeof event === "object" && "runtimeContext" in event) {
|
|
2724
|
+
augmentedEvent.runtimeContext = filterIncludedContext({
|
|
2725
|
+
context: event.runtimeContext,
|
|
2726
|
+
includeContext: telemetry.includeRuntimeContext
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
if (filterContext && event != null && typeof event === "object") {
|
|
2730
|
+
if ("toolsContext" in event) {
|
|
2731
|
+
augmentedEvent.toolsContext = filterToolsContext({
|
|
2732
|
+
toolsContext: event.toolsContext,
|
|
2733
|
+
includeToolsContext: telemetry.includeToolsContext
|
|
2734
|
+
});
|
|
2735
|
+
} else if ("toolContext" in event && event.toolContext != null && "toolCall" in event && event.toolCall != null && typeof event.toolCall === "object" && "toolName" in event.toolCall) {
|
|
2736
|
+
augmentedEvent.toolContext = filterToolContext({
|
|
2737
|
+
toolName: event.toolCall.toolName,
|
|
2738
|
+
toolContext: event.toolContext,
|
|
2739
|
+
includeToolsContext: telemetry.includeToolsContext
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
return augmentedEvent;
|
|
2672
2744
|
}
|
|
2673
2745
|
function createTelemetryDispatcher({
|
|
2674
2746
|
telemetry
|
|
@@ -2681,7 +2753,9 @@ function createTelemetryDispatcher({
|
|
|
2681
2753
|
const telemetryMetadata = {
|
|
2682
2754
|
recordInputs: telemetry == null ? void 0 : telemetry.recordInputs,
|
|
2683
2755
|
recordOutputs: telemetry == null ? void 0 : telemetry.recordOutputs,
|
|
2684
|
-
functionId: telemetry == null ? void 0 : telemetry.functionId
|
|
2756
|
+
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
2757
|
+
includeRuntimeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext,
|
|
2758
|
+
includeToolsContext: telemetry == null ? void 0 : telemetry.includeToolsContext
|
|
2685
2759
|
};
|
|
2686
2760
|
const mergeTelemetryCallback = (key) => {
|
|
2687
2761
|
const integrationCallbacks = integrations.map((integration) => {
|
|
@@ -2707,14 +2781,14 @@ function createTelemetryDispatcher({
|
|
|
2707
2781
|
runInTracingChannelSpan: async ({ type, event, execute }) => await runWithTracingChannelSpan(
|
|
2708
2782
|
{
|
|
2709
2783
|
type,
|
|
2710
|
-
event: augmentEvent(event, telemetryMetadata)
|
|
2784
|
+
event: augmentEvent(event, telemetryMetadata, true)
|
|
2711
2785
|
},
|
|
2712
2786
|
execute
|
|
2713
2787
|
),
|
|
2714
2788
|
startTracingChannelContext: ({ type, event, completion }) => openTelemetryChannelSpanContext({
|
|
2715
2789
|
message: {
|
|
2716
2790
|
type,
|
|
2717
|
-
event: augmentEvent(event, telemetryMetadata)
|
|
2791
|
+
event: augmentEvent(event, telemetryMetadata, true)
|
|
2718
2792
|
},
|
|
2719
2793
|
completion
|
|
2720
2794
|
}),
|
|
@@ -2789,21 +2863,6 @@ function createTelemetryDispatcher({
|
|
|
2789
2863
|
};
|
|
2790
2864
|
}
|
|
2791
2865
|
|
|
2792
|
-
// src/telemetry/filter-included-context.ts
|
|
2793
|
-
function filterIncludedContext({
|
|
2794
|
-
context,
|
|
2795
|
-
includeContext
|
|
2796
|
-
}) {
|
|
2797
|
-
if (context == null) {
|
|
2798
|
-
return {};
|
|
2799
|
-
}
|
|
2800
|
-
return Object.fromEntries(
|
|
2801
|
-
Object.entries(context).filter(
|
|
2802
|
-
([key]) => (includeContext == null ? void 0 : includeContext[key]) === true
|
|
2803
|
-
)
|
|
2804
|
-
);
|
|
2805
|
-
}
|
|
2806
|
-
|
|
2807
2866
|
// src/generate-text/reasoning.ts
|
|
2808
2867
|
function asReasoningText(reasoningParts) {
|
|
2809
2868
|
const reasoningText = reasoningParts.map((part) => "text" in part ? part.text : "").join("");
|
|
@@ -2940,35 +2999,6 @@ function restrictStepResult({
|
|
|
2940
2999
|
providerMetadata: step.providerMetadata
|
|
2941
3000
|
});
|
|
2942
3001
|
}
|
|
2943
|
-
function filterToolsContext({
|
|
2944
|
-
toolsContext,
|
|
2945
|
-
includeToolsContext
|
|
2946
|
-
}) {
|
|
2947
|
-
if (includeToolsContext == null) {
|
|
2948
|
-
return {};
|
|
2949
|
-
}
|
|
2950
|
-
return Object.fromEntries(
|
|
2951
|
-
Object.entries(toolsContext).map(([toolName, toolContext]) => [
|
|
2952
|
-
toolName,
|
|
2953
|
-
filterToolContext({
|
|
2954
|
-
toolName,
|
|
2955
|
-
toolContext,
|
|
2956
|
-
includeToolsContext
|
|
2957
|
-
})
|
|
2958
|
-
])
|
|
2959
|
-
);
|
|
2960
|
-
}
|
|
2961
|
-
function filterToolContext({
|
|
2962
|
-
toolName,
|
|
2963
|
-
toolContext,
|
|
2964
|
-
includeToolsContext
|
|
2965
|
-
}) {
|
|
2966
|
-
const includeToolContext = includeToolsContext == null ? void 0 : includeToolsContext[toolName];
|
|
2967
|
-
return filterIncludedContext({
|
|
2968
|
-
context: toolContext,
|
|
2969
|
-
includeContext: includeToolContext
|
|
2970
|
-
});
|
|
2971
|
-
}
|
|
2972
3002
|
function createRestrictedTelemetryDispatcher({
|
|
2973
3003
|
telemetry,
|
|
2974
3004
|
includeRuntimeContext,
|
|
@@ -3113,6 +3143,20 @@ function getOwn(obj, key) {
|
|
|
3113
3143
|
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
3114
3144
|
}
|
|
3115
3145
|
|
|
3146
|
+
// src/generate-text/tool-call.ts
|
|
3147
|
+
var inputSchemaInputSymbol = /* @__PURE__ */ Symbol("ai-sdk-tool-call-input-schema-input");
|
|
3148
|
+
function setToolCallInputSchemaInput(toolCall, inputSchemaInput) {
|
|
3149
|
+
Object.defineProperty(toolCall, inputSchemaInputSymbol, {
|
|
3150
|
+
value: inputSchemaInput
|
|
3151
|
+
});
|
|
3152
|
+
return toolCall;
|
|
3153
|
+
}
|
|
3154
|
+
function getToolCallInputSchemaInput(toolCall) {
|
|
3155
|
+
return inputSchemaInputSymbol in toolCall ? {
|
|
3156
|
+
value: toolCall[inputSchemaInputSymbol]
|
|
3157
|
+
} : void 0;
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3116
3160
|
// src/generate-text/parse-tool-call.ts
|
|
3117
3161
|
async function parseToolCall({
|
|
3118
3162
|
toolCall,
|
|
@@ -3235,10 +3279,12 @@ async function refineParsedToolCallInput({
|
|
|
3235
3279
|
if (refine == null) {
|
|
3236
3280
|
return toolCall;
|
|
3237
3281
|
}
|
|
3238
|
-
|
|
3282
|
+
const refinedToolCall = {
|
|
3239
3283
|
...toolCall,
|
|
3240
3284
|
input: await refine(toolCall.input)
|
|
3241
3285
|
};
|
|
3286
|
+
const inputSchemaInput = getToolCallInputSchemaInput(toolCall);
|
|
3287
|
+
return inputSchemaInput == null ? refinedToolCall : setToolCallInputSchemaInput(refinedToolCall, inputSchemaInput.value);
|
|
3242
3288
|
}
|
|
3243
3289
|
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
3244
3290
|
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON({ text: toolCall.input });
|
|
@@ -3283,26 +3329,29 @@ async function doParseToolCall({
|
|
|
3283
3329
|
cause: parseResult.error
|
|
3284
3330
|
});
|
|
3285
3331
|
}
|
|
3286
|
-
return
|
|
3287
|
-
type
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3332
|
+
return setToolCallInputSchemaInput(
|
|
3333
|
+
tool2.type === "dynamic" ? {
|
|
3334
|
+
type: "tool-call",
|
|
3335
|
+
toolCallId: toolCall.toolCallId,
|
|
3336
|
+
toolName: toolCall.toolName,
|
|
3337
|
+
input: parseResult.value,
|
|
3338
|
+
providerExecuted: toolCall.providerExecuted,
|
|
3339
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3340
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
3341
|
+
dynamic: true,
|
|
3342
|
+
title: tool2.title
|
|
3343
|
+
} : {
|
|
3344
|
+
type: "tool-call",
|
|
3345
|
+
toolCallId: toolCall.toolCallId,
|
|
3346
|
+
toolName,
|
|
3347
|
+
input: parseResult.value,
|
|
3348
|
+
providerExecuted: toolCall.providerExecuted,
|
|
3349
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3350
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
3351
|
+
title: tool2.title
|
|
3352
|
+
},
|
|
3353
|
+
parseResult.rawValue
|
|
3354
|
+
);
|
|
3306
3355
|
}
|
|
3307
3356
|
|
|
3308
3357
|
// src/generate-text/validate-tool-context.ts
|
|
@@ -3624,6 +3673,33 @@ import {
|
|
|
3624
3673
|
safeValidateTypes as safeValidateTypes3
|
|
3625
3674
|
} from "@ai-sdk/provider-utils";
|
|
3626
3675
|
|
|
3676
|
+
// src/util/is-deep-equal-data.ts
|
|
3677
|
+
function isDeepEqualData(obj1, obj2) {
|
|
3678
|
+
if (obj1 === obj2) return true;
|
|
3679
|
+
if (obj1 == null || obj2 == null) return false;
|
|
3680
|
+
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
3681
|
+
return obj1 === obj2;
|
|
3682
|
+
if (obj1.constructor !== obj2.constructor) return false;
|
|
3683
|
+
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
3684
|
+
return obj1.getTime() === obj2.getTime();
|
|
3685
|
+
}
|
|
3686
|
+
if (Array.isArray(obj1)) {
|
|
3687
|
+
if (obj1.length !== obj2.length) return false;
|
|
3688
|
+
for (let i = 0; i < obj1.length; i++) {
|
|
3689
|
+
if (!isDeepEqualData(obj1[i], obj2[i])) return false;
|
|
3690
|
+
}
|
|
3691
|
+
return true;
|
|
3692
|
+
}
|
|
3693
|
+
const keys1 = Object.keys(obj1);
|
|
3694
|
+
const keys2 = Object.keys(obj2);
|
|
3695
|
+
if (keys1.length !== keys2.length) return false;
|
|
3696
|
+
for (const key of keys1) {
|
|
3697
|
+
if (!keys2.includes(key)) return false;
|
|
3698
|
+
if (!isDeepEqualData(obj1[key], obj2[key])) return false;
|
|
3699
|
+
}
|
|
3700
|
+
return true;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3627
3703
|
// src/generate-text/resolve-tool-approval.ts
|
|
3628
3704
|
async function resolveToolApproval({
|
|
3629
3705
|
tools,
|
|
@@ -3687,14 +3763,15 @@ async function validateApprovedToolApprovals({
|
|
|
3687
3763
|
messages,
|
|
3688
3764
|
toolsContext,
|
|
3689
3765
|
runtimeContext,
|
|
3690
|
-
toolApprovalSecret
|
|
3766
|
+
toolApprovalSecret,
|
|
3767
|
+
refineToolInput
|
|
3691
3768
|
}) {
|
|
3692
3769
|
var _a12;
|
|
3693
3770
|
const approved = [];
|
|
3694
3771
|
const denied = [];
|
|
3695
3772
|
const invalid = [];
|
|
3696
3773
|
for (const approval of approvedToolApprovals) {
|
|
3697
|
-
const {
|
|
3774
|
+
const { approvalRequest, toolCall } = approval;
|
|
3698
3775
|
const tool2 = getOwn(tools, toolCall.toolName);
|
|
3699
3776
|
if (toolApprovalSecret != null) {
|
|
3700
3777
|
if (approvalRequest.signature == null) {
|
|
@@ -3721,17 +3798,42 @@ async function validateApprovedToolApprovals({
|
|
|
3721
3798
|
}
|
|
3722
3799
|
}
|
|
3723
3800
|
if (isExecutableTool(tool2) && tool2.inputSchema != null) {
|
|
3801
|
+
const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
|
|
3802
|
+
approvalRequest,
|
|
3803
|
+
"inputSchemaInput"
|
|
3804
|
+
);
|
|
3724
3805
|
const validation = await safeValidateTypes3({
|
|
3725
|
-
value: toolCall.input,
|
|
3806
|
+
value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
|
|
3726
3807
|
schema: asSchema3(tool2.inputSchema)
|
|
3727
3808
|
});
|
|
3809
|
+
let validationError;
|
|
3728
3810
|
if (!validation.success) {
|
|
3811
|
+
validationError = validation.error;
|
|
3812
|
+
} else {
|
|
3813
|
+
try {
|
|
3814
|
+
const revalidatedToolCall = await refineParsedToolCallInput({
|
|
3815
|
+
toolCall: {
|
|
3816
|
+
...toolCall,
|
|
3817
|
+
input: validation.value
|
|
3818
|
+
},
|
|
3819
|
+
refineToolInput
|
|
3820
|
+
});
|
|
3821
|
+
if (!isDeepEqualData(revalidatedToolCall.input, toolCall.input)) {
|
|
3822
|
+
validationError = new Error(
|
|
3823
|
+
"Approved tool input does not match the validated schema output."
|
|
3824
|
+
);
|
|
3825
|
+
}
|
|
3826
|
+
} catch (error) {
|
|
3827
|
+
validationError = error;
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
if (validationError != null) {
|
|
3729
3831
|
invalid.push({
|
|
3730
3832
|
...approval,
|
|
3731
3833
|
error: new InvalidToolInputError({
|
|
3732
3834
|
toolName: toolCall.toolName,
|
|
3733
3835
|
toolInput: JSON.stringify(toolCall.input),
|
|
3734
|
-
cause:
|
|
3836
|
+
cause: validationError
|
|
3735
3837
|
})
|
|
3736
3838
|
});
|
|
3737
3839
|
continue;
|
|
@@ -3869,13 +3971,15 @@ async function toResponseMessages({
|
|
|
3869
3971
|
break;
|
|
3870
3972
|
}
|
|
3871
3973
|
case "tool-approval-request":
|
|
3974
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
3872
3975
|
content.push({
|
|
3873
3976
|
type: "tool-approval-request",
|
|
3874
3977
|
approvalId: part.approvalId,
|
|
3875
3978
|
toolCallId: part.toolCall.toolCallId,
|
|
3876
3979
|
...part.reason != null ? { reason: part.reason } : {},
|
|
3877
3980
|
isAutomatic: part.isAutomatic,
|
|
3878
|
-
...part.signature != null ? { signature: part.signature } : {}
|
|
3981
|
+
...part.signature != null ? { signature: part.signature } : {},
|
|
3982
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {}
|
|
3879
3983
|
});
|
|
3880
3984
|
break;
|
|
3881
3985
|
}
|