ai 7.0.18 → 7.0.19
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 +21 -0
- package/dist/index.d.ts +38 -3
- package/dist/index.js +160 -77
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +43 -31
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +57 -52
- package/docs/02-getting-started/00-choosing-a-provider.mdx +1 -16
- package/docs/02-getting-started/01-navigating-the-library.mdx +12 -12
- package/docs/02-getting-started/02-nextjs-app-router.mdx +2 -36
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +2 -36
- package/docs/02-getting-started/04-svelte.mdx +2 -34
- package/docs/02-getting-started/05-nuxt.mdx +2 -36
- package/docs/02-getting-started/06-nodejs.mdx +1 -18
- package/docs/02-getting-started/07-expo.mdx +3 -62
- package/docs/02-getting-started/08-tanstack-start.mdx +2 -36
- package/docs/02-getting-started/09-coding-agents.mdx +2 -32
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/30-embeddings.mdx +18 -18
- package/docs/03-ai-sdk-core/38-video-generation.mdx +22 -3
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +1 -28
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +7 -7
- package/docs/03-ai-sdk-harnesses/06-workflow-utilities.mdx +1 -16
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +1 -28
- package/docs/04-ai-sdk-ui/01-overview.mdx +5 -5
- package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +3 -2
- package/docs/07-reference/02-ai-sdk-ui/index.mdx +5 -5
- package/package.json +4 -4
- package/src/generate-text/collect-tool-approvals.ts +17 -4
- package/src/generate-text/execute-tool-call.ts +3 -2
- package/src/generate-text/execute-tools-from-stream.ts +2 -1
- package/src/generate-text/generate-text.ts +5 -4
- package/src/generate-text/index.ts +1 -0
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +6 -4
- package/src/generate-text/parse-tool-call.ts +5 -4
- package/src/generate-text/resolve-tool-approval.ts +9 -6
- package/src/generate-text/stream-language-model-call.ts +2 -1
- package/src/generate-text/stream-text.ts +3 -2
- package/src/generate-text/to-response-messages.ts +4 -3
- package/src/generate-text/tool-approval-signature.ts +4 -40
- package/src/generate-text/tool-fingerprint.ts +76 -0
- package/src/generate-text/validate-tool-approvals.ts +6 -1
- package/src/generate-video/generate-video.ts +96 -21
- package/src/ui/convert-to-model-messages.ts +3 -2
- package/src/ui/process-ui-message-stream.ts +3 -0
- package/src/ui/validate-ui-messages.ts +2 -1
- package/src/util/canonical-hash.ts +44 -0
- package/src/util/get-own.ts +18 -0
package/dist/internal/index.js
CHANGED
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
} from "@ai-sdk/provider-utils";
|
|
86
86
|
|
|
87
87
|
// src/version.ts
|
|
88
|
-
var VERSION = true ? "7.0.
|
|
88
|
+
var VERSION = true ? "7.0.19" : "0.0.0-test";
|
|
89
89
|
|
|
90
90
|
// src/util/download/download.ts
|
|
91
91
|
var download = async ({
|
|
@@ -2869,6 +2869,13 @@ import {
|
|
|
2869
2869
|
safeParseJSON,
|
|
2870
2870
|
safeValidateTypes as safeValidateTypes2
|
|
2871
2871
|
} from "@ai-sdk/provider-utils";
|
|
2872
|
+
|
|
2873
|
+
// src/util/get-own.ts
|
|
2874
|
+
function getOwn(obj, key) {
|
|
2875
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
// src/generate-text/parse-tool-call.ts
|
|
2872
2879
|
async function parseToolCall({
|
|
2873
2880
|
toolCall,
|
|
2874
2881
|
tools,
|
|
@@ -2902,7 +2909,8 @@ async function parseToolCall({
|
|
|
2902
2909
|
toolCall,
|
|
2903
2910
|
tools,
|
|
2904
2911
|
inputSchema: async ({ toolName }) => {
|
|
2905
|
-
|
|
2912
|
+
var _a12;
|
|
2913
|
+
const inputSchema = (_a12 = getOwn(tools, toolName)) == null ? void 0 : _a12.inputSchema;
|
|
2906
2914
|
return await asSchema2(inputSchema).jsonSchema;
|
|
2907
2915
|
},
|
|
2908
2916
|
instructions,
|
|
@@ -2927,7 +2935,7 @@ async function parseToolCall({
|
|
|
2927
2935
|
} catch (error) {
|
|
2928
2936
|
const parsedInput = await safeParseJSON({ text: toolCall.input });
|
|
2929
2937
|
const input = parsedInput.success ? parsedInput.value : toolCall.input;
|
|
2930
|
-
const tool = tools
|
|
2938
|
+
const tool = getOwn(tools, toolCall.toolName);
|
|
2931
2939
|
return {
|
|
2932
2940
|
type: "tool-call",
|
|
2933
2941
|
toolCallId: toolCall.toolCallId,
|
|
@@ -2947,7 +2955,7 @@ async function refineParsedToolCallInput({
|
|
|
2947
2955
|
toolCall,
|
|
2948
2956
|
refineToolInput
|
|
2949
2957
|
}) {
|
|
2950
|
-
const refine = refineToolInput
|
|
2958
|
+
const refine = getOwn(refineToolInput, toolCall.toolName);
|
|
2951
2959
|
if (refine == null) {
|
|
2952
2960
|
return toolCall;
|
|
2953
2961
|
}
|
|
@@ -2980,7 +2988,7 @@ async function doParseToolCall({
|
|
|
2980
2988
|
tools
|
|
2981
2989
|
}) {
|
|
2982
2990
|
const toolName = toolCall.toolName;
|
|
2983
|
-
const tool = tools
|
|
2991
|
+
const tool = getOwn(tools, toolName);
|
|
2984
2992
|
if (tool == null) {
|
|
2985
2993
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
2986
2994
|
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
@@ -3032,7 +3040,7 @@ function collectToolApprovals({
|
|
|
3032
3040
|
deniedToolApprovals: []
|
|
3033
3041
|
};
|
|
3034
3042
|
}
|
|
3035
|
-
const toolCallsByToolCallId =
|
|
3043
|
+
const toolCallsByToolCallId = /* @__PURE__ */ Object.create(null);
|
|
3036
3044
|
for (const message of messages) {
|
|
3037
3045
|
if (message.role === "assistant" && typeof message.content !== "string") {
|
|
3038
3046
|
const content = message.content;
|
|
@@ -3043,7 +3051,7 @@ function collectToolApprovals({
|
|
|
3043
3051
|
}
|
|
3044
3052
|
}
|
|
3045
3053
|
}
|
|
3046
|
-
const toolApprovalRequestsByApprovalId =
|
|
3054
|
+
const toolApprovalRequestsByApprovalId = /* @__PURE__ */ Object.create(null);
|
|
3047
3055
|
for (const message of messages) {
|
|
3048
3056
|
if (message.role === "assistant" && typeof message.content !== "string") {
|
|
3049
3057
|
const content = message.content;
|
|
@@ -3054,7 +3062,9 @@ function collectToolApprovals({
|
|
|
3054
3062
|
}
|
|
3055
3063
|
}
|
|
3056
3064
|
}
|
|
3057
|
-
const toolResults =
|
|
3065
|
+
const toolResults = /* @__PURE__ */ Object.create(
|
|
3066
|
+
null
|
|
3067
|
+
);
|
|
3058
3068
|
for (const part of lastMessage.content) {
|
|
3059
3069
|
if (part.type === "tool-result") {
|
|
3060
3070
|
toolResults[part.toolCallId] = part;
|
|
@@ -3144,16 +3154,16 @@ async function resolveToolApproval({
|
|
|
3144
3154
|
);
|
|
3145
3155
|
}
|
|
3146
3156
|
const toolName = toolCall.toolName;
|
|
3147
|
-
const tool = tools
|
|
3157
|
+
const tool = getOwn(tools, toolName);
|
|
3148
3158
|
const input = toolCall.input;
|
|
3149
|
-
const userDefinedToolApprovalStatus = toolApproval
|
|
3159
|
+
const userDefinedToolApprovalStatus = getOwn(toolApproval, toolName);
|
|
3150
3160
|
if (userDefinedToolApprovalStatus != null) {
|
|
3151
3161
|
const approvalStatus = typeof userDefinedToolApprovalStatus === "function" ? await userDefinedToolApprovalStatus(input, {
|
|
3152
3162
|
toolCallId: toolCall.toolCallId,
|
|
3153
3163
|
messages,
|
|
3154
3164
|
toolContext: await validateToolContext({
|
|
3155
3165
|
toolName,
|
|
3156
|
-
context: toolsContext
|
|
3166
|
+
context: getOwn(toolsContext, toolName),
|
|
3157
3167
|
contextSchema: tool == null ? void 0 : tool.contextSchema
|
|
3158
3168
|
}),
|
|
3159
3169
|
runtimeContext
|
|
@@ -3168,7 +3178,7 @@ async function resolveToolApproval({
|
|
|
3168
3178
|
messages,
|
|
3169
3179
|
context: await validateToolContext({
|
|
3170
3180
|
toolName,
|
|
3171
|
-
context: toolsContext
|
|
3181
|
+
context: getOwn(toolsContext, toolName),
|
|
3172
3182
|
contextSchema: tool == null ? void 0 : tool.contextSchema
|
|
3173
3183
|
})
|
|
3174
3184
|
}) : tool.needsApproval;
|
|
@@ -3179,10 +3189,10 @@ function normalizeToolApprovalStatus(status) {
|
|
|
3179
3189
|
}
|
|
3180
3190
|
|
|
3181
3191
|
// src/generate-text/tool-approval-signature.ts
|
|
3182
|
-
import {
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
} from "@ai-sdk/provider-utils";
|
|
3192
|
+
import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
|
|
3193
|
+
|
|
3194
|
+
// src/util/canonical-hash.ts
|
|
3195
|
+
import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
|
|
3186
3196
|
var encoder = new TextEncoder();
|
|
3187
3197
|
function canonicalJSON(value) {
|
|
3188
3198
|
if (value === null || value === void 0) {
|
|
@@ -3203,11 +3213,21 @@ function canonicalJSON(value) {
|
|
|
3203
3213
|
function toBase64url(bytes) {
|
|
3204
3214
|
return convertUint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
3205
3215
|
}
|
|
3216
|
+
async function hashCanonical(value) {
|
|
3217
|
+
const digest = await crypto.subtle.digest(
|
|
3218
|
+
"SHA-256",
|
|
3219
|
+
encoder.encode(canonicalJSON(value))
|
|
3220
|
+
);
|
|
3221
|
+
return toBase64url(new Uint8Array(digest));
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
// src/generate-text/tool-approval-signature.ts
|
|
3225
|
+
var encoder2 = new TextEncoder();
|
|
3206
3226
|
function fromBase64url(str) {
|
|
3207
3227
|
return convertBase64ToUint8Array(str);
|
|
3208
3228
|
}
|
|
3209
3229
|
async function importKey(secret) {
|
|
3210
|
-
const keyData = typeof secret === "string" ?
|
|
3230
|
+
const keyData = typeof secret === "string" ? encoder2.encode(secret) : secret;
|
|
3211
3231
|
return crypto.subtle.importKey(
|
|
3212
3232
|
"raw",
|
|
3213
3233
|
keyData,
|
|
@@ -3216,16 +3236,8 @@ async function importKey(secret) {
|
|
|
3216
3236
|
["sign", "verify"]
|
|
3217
3237
|
);
|
|
3218
3238
|
}
|
|
3219
|
-
async function hashInput(input) {
|
|
3220
|
-
const canonical = canonicalJSON(input);
|
|
3221
|
-
const digest = await crypto.subtle.digest(
|
|
3222
|
-
"SHA-256",
|
|
3223
|
-
encoder.encode(canonical)
|
|
3224
|
-
);
|
|
3225
|
-
return toBase64url(new Uint8Array(digest));
|
|
3226
|
-
}
|
|
3227
3239
|
function buildPayload(approvalId, toolCallId, toolName, inputDigest) {
|
|
3228
|
-
return
|
|
3240
|
+
return encoder2.encode(
|
|
3229
3241
|
`${approvalId}
|
|
3230
3242
|
${toolCallId}
|
|
3231
3243
|
${toolName}
|
|
@@ -3241,7 +3253,7 @@ async function verifyToolApprovalSignature({
|
|
|
3241
3253
|
input
|
|
3242
3254
|
}) {
|
|
3243
3255
|
const key = await importKey(secret);
|
|
3244
|
-
const inputDigest = await
|
|
3256
|
+
const inputDigest = await hashCanonical(input);
|
|
3245
3257
|
const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
|
|
3246
3258
|
const sigBytes = fromBase64url(signature);
|
|
3247
3259
|
return crypto.subtle.verify("HMAC", key, sigBytes, payload);
|
|
@@ -3262,7 +3274,7 @@ async function validateApprovedToolApprovals({
|
|
|
3262
3274
|
const denied = [];
|
|
3263
3275
|
for (const approval of approvedToolApprovals) {
|
|
3264
3276
|
const { toolCall, approvalRequest } = approval;
|
|
3265
|
-
const tool = tools
|
|
3277
|
+
const tool = getOwn(tools, toolCall.toolName);
|
|
3266
3278
|
if (toolApprovalSecret != null) {
|
|
3267
3279
|
if (approvalRequest.signature == null) {
|
|
3268
3280
|
throw new InvalidToolApprovalSignatureError({
|
|
@@ -3397,7 +3409,7 @@ async function toResponseMessages({
|
|
|
3397
3409
|
const output = await createToolModelOutput({
|
|
3398
3410
|
toolCallId: part.toolCallId,
|
|
3399
3411
|
input: part.input,
|
|
3400
|
-
tool: tools
|
|
3412
|
+
tool: getOwn(tools, part.toolName),
|
|
3401
3413
|
output: part.output,
|
|
3402
3414
|
errorMode: "none"
|
|
3403
3415
|
});
|
|
@@ -3414,7 +3426,7 @@ async function toResponseMessages({
|
|
|
3414
3426
|
const output = await createToolModelOutput({
|
|
3415
3427
|
toolCallId: part.toolCallId,
|
|
3416
3428
|
input: part.input,
|
|
3417
|
-
tool: tools
|
|
3429
|
+
tool: getOwn(tools, part.toolName),
|
|
3418
3430
|
output: part.error,
|
|
3419
3431
|
errorMode: "json"
|
|
3420
3432
|
});
|
|
@@ -3476,7 +3488,7 @@ async function toResponseMessages({
|
|
|
3476
3488
|
const output = await createToolModelOutput({
|
|
3477
3489
|
toolCallId: part.toolCallId,
|
|
3478
3490
|
input: part.input,
|
|
3479
|
-
tool: tools
|
|
3491
|
+
tool: getOwn(tools, part.toolName),
|
|
3480
3492
|
output: part.type === "tool-result" ? part.output : part.error,
|
|
3481
3493
|
errorMode: part.type === "tool-error" ? "text" : "none"
|
|
3482
3494
|
});
|