ai 7.0.112 → 7.0.113
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 +26 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +315 -213
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +105 -28
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/06-tool-approvals.mdx +16 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +2 -0
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +18 -0
- package/package.json +11 -11
- package/src/embed/embed-many.ts +18 -2
- 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/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/registry/custom-provider.ts +12 -5
- 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.113" : "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({
|
|
@@ -3113,6 +3116,20 @@ function getOwn(obj, key) {
|
|
|
3113
3116
|
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
3114
3117
|
}
|
|
3115
3118
|
|
|
3119
|
+
// src/generate-text/tool-call.ts
|
|
3120
|
+
var inputSchemaInputSymbol = /* @__PURE__ */ Symbol("ai-sdk-tool-call-input-schema-input");
|
|
3121
|
+
function setToolCallInputSchemaInput(toolCall, inputSchemaInput) {
|
|
3122
|
+
Object.defineProperty(toolCall, inputSchemaInputSymbol, {
|
|
3123
|
+
value: inputSchemaInput
|
|
3124
|
+
});
|
|
3125
|
+
return toolCall;
|
|
3126
|
+
}
|
|
3127
|
+
function getToolCallInputSchemaInput(toolCall) {
|
|
3128
|
+
return inputSchemaInputSymbol in toolCall ? {
|
|
3129
|
+
value: toolCall[inputSchemaInputSymbol]
|
|
3130
|
+
} : void 0;
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3116
3133
|
// src/generate-text/parse-tool-call.ts
|
|
3117
3134
|
async function parseToolCall({
|
|
3118
3135
|
toolCall,
|
|
@@ -3235,10 +3252,12 @@ async function refineParsedToolCallInput({
|
|
|
3235
3252
|
if (refine == null) {
|
|
3236
3253
|
return toolCall;
|
|
3237
3254
|
}
|
|
3238
|
-
|
|
3255
|
+
const refinedToolCall = {
|
|
3239
3256
|
...toolCall,
|
|
3240
3257
|
input: await refine(toolCall.input)
|
|
3241
3258
|
};
|
|
3259
|
+
const inputSchemaInput = getToolCallInputSchemaInput(toolCall);
|
|
3260
|
+
return inputSchemaInput == null ? refinedToolCall : setToolCallInputSchemaInput(refinedToolCall, inputSchemaInput.value);
|
|
3242
3261
|
}
|
|
3243
3262
|
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
3244
3263
|
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON({ text: toolCall.input });
|
|
@@ -3283,26 +3302,29 @@ async function doParseToolCall({
|
|
|
3283
3302
|
cause: parseResult.error
|
|
3284
3303
|
});
|
|
3285
3304
|
}
|
|
3286
|
-
return
|
|
3287
|
-
type
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3305
|
+
return setToolCallInputSchemaInput(
|
|
3306
|
+
tool2.type === "dynamic" ? {
|
|
3307
|
+
type: "tool-call",
|
|
3308
|
+
toolCallId: toolCall.toolCallId,
|
|
3309
|
+
toolName: toolCall.toolName,
|
|
3310
|
+
input: parseResult.value,
|
|
3311
|
+
providerExecuted: toolCall.providerExecuted,
|
|
3312
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3313
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
3314
|
+
dynamic: true,
|
|
3315
|
+
title: tool2.title
|
|
3316
|
+
} : {
|
|
3317
|
+
type: "tool-call",
|
|
3318
|
+
toolCallId: toolCall.toolCallId,
|
|
3319
|
+
toolName,
|
|
3320
|
+
input: parseResult.value,
|
|
3321
|
+
providerExecuted: toolCall.providerExecuted,
|
|
3322
|
+
providerMetadata: toolCall.providerMetadata,
|
|
3323
|
+
...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
|
|
3324
|
+
title: tool2.title
|
|
3325
|
+
},
|
|
3326
|
+
parseResult.rawValue
|
|
3327
|
+
);
|
|
3306
3328
|
}
|
|
3307
3329
|
|
|
3308
3330
|
// src/generate-text/validate-tool-context.ts
|
|
@@ -3624,6 +3646,33 @@ import {
|
|
|
3624
3646
|
safeValidateTypes as safeValidateTypes3
|
|
3625
3647
|
} from "@ai-sdk/provider-utils";
|
|
3626
3648
|
|
|
3649
|
+
// src/util/is-deep-equal-data.ts
|
|
3650
|
+
function isDeepEqualData(obj1, obj2) {
|
|
3651
|
+
if (obj1 === obj2) return true;
|
|
3652
|
+
if (obj1 == null || obj2 == null) return false;
|
|
3653
|
+
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
3654
|
+
return obj1 === obj2;
|
|
3655
|
+
if (obj1.constructor !== obj2.constructor) return false;
|
|
3656
|
+
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
3657
|
+
return obj1.getTime() === obj2.getTime();
|
|
3658
|
+
}
|
|
3659
|
+
if (Array.isArray(obj1)) {
|
|
3660
|
+
if (obj1.length !== obj2.length) return false;
|
|
3661
|
+
for (let i = 0; i < obj1.length; i++) {
|
|
3662
|
+
if (!isDeepEqualData(obj1[i], obj2[i])) return false;
|
|
3663
|
+
}
|
|
3664
|
+
return true;
|
|
3665
|
+
}
|
|
3666
|
+
const keys1 = Object.keys(obj1);
|
|
3667
|
+
const keys2 = Object.keys(obj2);
|
|
3668
|
+
if (keys1.length !== keys2.length) return false;
|
|
3669
|
+
for (const key of keys1) {
|
|
3670
|
+
if (!keys2.includes(key)) return false;
|
|
3671
|
+
if (!isDeepEqualData(obj1[key], obj2[key])) return false;
|
|
3672
|
+
}
|
|
3673
|
+
return true;
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3627
3676
|
// src/generate-text/resolve-tool-approval.ts
|
|
3628
3677
|
async function resolveToolApproval({
|
|
3629
3678
|
tools,
|
|
@@ -3687,14 +3736,15 @@ async function validateApprovedToolApprovals({
|
|
|
3687
3736
|
messages,
|
|
3688
3737
|
toolsContext,
|
|
3689
3738
|
runtimeContext,
|
|
3690
|
-
toolApprovalSecret
|
|
3739
|
+
toolApprovalSecret,
|
|
3740
|
+
refineToolInput
|
|
3691
3741
|
}) {
|
|
3692
3742
|
var _a12;
|
|
3693
3743
|
const approved = [];
|
|
3694
3744
|
const denied = [];
|
|
3695
3745
|
const invalid = [];
|
|
3696
3746
|
for (const approval of approvedToolApprovals) {
|
|
3697
|
-
const {
|
|
3747
|
+
const { approvalRequest, toolCall } = approval;
|
|
3698
3748
|
const tool2 = getOwn(tools, toolCall.toolName);
|
|
3699
3749
|
if (toolApprovalSecret != null) {
|
|
3700
3750
|
if (approvalRequest.signature == null) {
|
|
@@ -3721,17 +3771,42 @@ async function validateApprovedToolApprovals({
|
|
|
3721
3771
|
}
|
|
3722
3772
|
}
|
|
3723
3773
|
if (isExecutableTool(tool2) && tool2.inputSchema != null) {
|
|
3774
|
+
const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
|
|
3775
|
+
approvalRequest,
|
|
3776
|
+
"inputSchemaInput"
|
|
3777
|
+
);
|
|
3724
3778
|
const validation = await safeValidateTypes3({
|
|
3725
|
-
value: toolCall.input,
|
|
3779
|
+
value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
|
|
3726
3780
|
schema: asSchema3(tool2.inputSchema)
|
|
3727
3781
|
});
|
|
3782
|
+
let validationError;
|
|
3728
3783
|
if (!validation.success) {
|
|
3784
|
+
validationError = validation.error;
|
|
3785
|
+
} else {
|
|
3786
|
+
try {
|
|
3787
|
+
const revalidatedToolCall = await refineParsedToolCallInput({
|
|
3788
|
+
toolCall: {
|
|
3789
|
+
...toolCall,
|
|
3790
|
+
input: validation.value
|
|
3791
|
+
},
|
|
3792
|
+
refineToolInput
|
|
3793
|
+
});
|
|
3794
|
+
if (!isDeepEqualData(revalidatedToolCall.input, toolCall.input)) {
|
|
3795
|
+
validationError = new Error(
|
|
3796
|
+
"Approved tool input does not match the validated schema output."
|
|
3797
|
+
);
|
|
3798
|
+
}
|
|
3799
|
+
} catch (error) {
|
|
3800
|
+
validationError = error;
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
if (validationError != null) {
|
|
3729
3804
|
invalid.push({
|
|
3730
3805
|
...approval,
|
|
3731
3806
|
error: new InvalidToolInputError({
|
|
3732
3807
|
toolName: toolCall.toolName,
|
|
3733
3808
|
toolInput: JSON.stringify(toolCall.input),
|
|
3734
|
-
cause:
|
|
3809
|
+
cause: validationError
|
|
3735
3810
|
})
|
|
3736
3811
|
});
|
|
3737
3812
|
continue;
|
|
@@ -3869,13 +3944,15 @@ async function toResponseMessages({
|
|
|
3869
3944
|
break;
|
|
3870
3945
|
}
|
|
3871
3946
|
case "tool-approval-request":
|
|
3947
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
3872
3948
|
content.push({
|
|
3873
3949
|
type: "tool-approval-request",
|
|
3874
3950
|
approvalId: part.approvalId,
|
|
3875
3951
|
toolCallId: part.toolCall.toolCallId,
|
|
3876
3952
|
...part.reason != null ? { reason: part.reason } : {},
|
|
3877
3953
|
isAutomatic: part.isAutomatic,
|
|
3878
|
-
...part.signature != null ? { signature: part.signature } : {}
|
|
3954
|
+
...part.signature != null ? { signature: part.signature } : {},
|
|
3955
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {}
|
|
3879
3956
|
});
|
|
3880
3957
|
break;
|
|
3881
3958
|
}
|