ai 7.0.18 → 7.0.20
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 +28 -0
- package/dist/index.d.ts +58 -5
- package/dist/index.js +168 -79
- 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-agents/07-workflow-agent.mdx +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +3 -12
- 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/01-generate-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +3 -2
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/index.mdx +5 -5
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +2 -2
- package/package.json +4 -4
- package/src/agent/tool-loop-agent-settings.ts +7 -0
- 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 +14 -5
- 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 +12 -3
- 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/src/util/write-to-server-response.ts +9 -0
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
import { createGateway, gateway as gateway2 } from "@ai-sdk/gateway";
|
|
9
9
|
import {
|
|
10
|
-
asSchema as
|
|
10
|
+
asSchema as asSchema8,
|
|
11
11
|
createIdGenerator as createIdGenerator9,
|
|
12
12
|
dynamicTool,
|
|
13
13
|
generateId,
|
|
@@ -1089,7 +1089,7 @@ import {
|
|
|
1089
1089
|
} from "@ai-sdk/provider-utils";
|
|
1090
1090
|
|
|
1091
1091
|
// src/version.ts
|
|
1092
|
-
var VERSION = true ? "7.0.
|
|
1092
|
+
var VERSION = true ? "7.0.20" : "0.0.0-test";
|
|
1093
1093
|
|
|
1094
1094
|
// src/util/download/download.ts
|
|
1095
1095
|
var download = async ({
|
|
@@ -2572,6 +2572,11 @@ function addImageModelUsage(usage1, usage2) {
|
|
|
2572
2572
|
};
|
|
2573
2573
|
}
|
|
2574
2574
|
|
|
2575
|
+
// src/util/get-own.ts
|
|
2576
|
+
function getOwn(obj, key) {
|
|
2577
|
+
return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2575
2580
|
// src/util/merge-abort-signals.ts
|
|
2576
2581
|
import { filterNullable } from "@ai-sdk/provider-utils";
|
|
2577
2582
|
function mergeAbortSignals(...signals) {
|
|
@@ -2760,7 +2765,7 @@ function collectToolApprovals({
|
|
|
2760
2765
|
deniedToolApprovals: []
|
|
2761
2766
|
};
|
|
2762
2767
|
}
|
|
2763
|
-
const toolCallsByToolCallId =
|
|
2768
|
+
const toolCallsByToolCallId = /* @__PURE__ */ Object.create(null);
|
|
2764
2769
|
for (const message of messages) {
|
|
2765
2770
|
if (message.role === "assistant" && typeof message.content !== "string") {
|
|
2766
2771
|
const content = message.content;
|
|
@@ -2771,7 +2776,7 @@ function collectToolApprovals({
|
|
|
2771
2776
|
}
|
|
2772
2777
|
}
|
|
2773
2778
|
}
|
|
2774
|
-
const toolApprovalRequestsByApprovalId =
|
|
2779
|
+
const toolApprovalRequestsByApprovalId = /* @__PURE__ */ Object.create(null);
|
|
2775
2780
|
for (const message of messages) {
|
|
2776
2781
|
if (message.role === "assistant" && typeof message.content !== "string") {
|
|
2777
2782
|
const content = message.content;
|
|
@@ -2782,7 +2787,9 @@ function collectToolApprovals({
|
|
|
2782
2787
|
}
|
|
2783
2788
|
}
|
|
2784
2789
|
}
|
|
2785
|
-
const toolResults =
|
|
2790
|
+
const toolResults = /* @__PURE__ */ Object.create(
|
|
2791
|
+
null
|
|
2792
|
+
);
|
|
2786
2793
|
for (const part of lastMessage.content) {
|
|
2787
2794
|
if (part.type === "tool-result") {
|
|
2788
2795
|
toolResults[part.toolCallId] = part;
|
|
@@ -2867,13 +2874,13 @@ async function executeToolCall({
|
|
|
2867
2874
|
runInTracingChannelSpan = async ({ execute }) => await execute()
|
|
2868
2875
|
}) {
|
|
2869
2876
|
const { toolName, toolCallId, input } = toolCall;
|
|
2870
|
-
const tool2 = tools
|
|
2877
|
+
const tool2 = getOwn(tools, toolName);
|
|
2871
2878
|
if (!isExecutableTool(tool2)) {
|
|
2872
2879
|
return void 0;
|
|
2873
2880
|
}
|
|
2874
2881
|
const context = await validateToolContext({
|
|
2875
2882
|
toolName,
|
|
2876
|
-
context: toolsContext
|
|
2883
|
+
context: getOwn(toolsContext, toolName),
|
|
2877
2884
|
contextSchema: tool2.contextSchema
|
|
2878
2885
|
});
|
|
2879
2886
|
const toolExecutionContext = {
|
|
@@ -3761,7 +3768,8 @@ async function parseToolCall({
|
|
|
3761
3768
|
toolCall,
|
|
3762
3769
|
tools,
|
|
3763
3770
|
inputSchema: async ({ toolName }) => {
|
|
3764
|
-
|
|
3771
|
+
var _a22;
|
|
3772
|
+
const inputSchema = (_a22 = getOwn(tools, toolName)) == null ? void 0 : _a22.inputSchema;
|
|
3765
3773
|
return await asSchema3(inputSchema).jsonSchema;
|
|
3766
3774
|
},
|
|
3767
3775
|
instructions,
|
|
@@ -3786,7 +3794,7 @@ async function parseToolCall({
|
|
|
3786
3794
|
} catch (error) {
|
|
3787
3795
|
const parsedInput = await safeParseJSON3({ text: toolCall.input });
|
|
3788
3796
|
const input = parsedInput.success ? parsedInput.value : toolCall.input;
|
|
3789
|
-
const tool2 = tools
|
|
3797
|
+
const tool2 = getOwn(tools, toolCall.toolName);
|
|
3790
3798
|
return {
|
|
3791
3799
|
type: "tool-call",
|
|
3792
3800
|
toolCallId: toolCall.toolCallId,
|
|
@@ -3806,7 +3814,7 @@ async function refineParsedToolCallInput({
|
|
|
3806
3814
|
toolCall,
|
|
3807
3815
|
refineToolInput
|
|
3808
3816
|
}) {
|
|
3809
|
-
const refine = refineToolInput
|
|
3817
|
+
const refine = getOwn(refineToolInput, toolCall.toolName);
|
|
3810
3818
|
if (refine == null) {
|
|
3811
3819
|
return toolCall;
|
|
3812
3820
|
}
|
|
@@ -3839,7 +3847,7 @@ async function doParseToolCall({
|
|
|
3839
3847
|
tools
|
|
3840
3848
|
}) {
|
|
3841
3849
|
const toolName = toolCall.toolName;
|
|
3842
|
-
const tool2 = tools
|
|
3850
|
+
const tool2 = getOwn(tools, toolName);
|
|
3843
3851
|
if (tool2 == null) {
|
|
3844
3852
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
3845
3853
|
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
@@ -3947,16 +3955,16 @@ async function resolveToolApproval({
|
|
|
3947
3955
|
);
|
|
3948
3956
|
}
|
|
3949
3957
|
const toolName = toolCall.toolName;
|
|
3950
|
-
const tool2 = tools
|
|
3958
|
+
const tool2 = getOwn(tools, toolName);
|
|
3951
3959
|
const input = toolCall.input;
|
|
3952
|
-
const userDefinedToolApprovalStatus = toolApproval
|
|
3960
|
+
const userDefinedToolApprovalStatus = getOwn(toolApproval, toolName);
|
|
3953
3961
|
if (userDefinedToolApprovalStatus != null) {
|
|
3954
3962
|
const approvalStatus = typeof userDefinedToolApprovalStatus === "function" ? await userDefinedToolApprovalStatus(input, {
|
|
3955
3963
|
toolCallId: toolCall.toolCallId,
|
|
3956
3964
|
messages,
|
|
3957
3965
|
toolContext: await validateToolContext({
|
|
3958
3966
|
toolName,
|
|
3959
|
-
context: toolsContext
|
|
3967
|
+
context: getOwn(toolsContext, toolName),
|
|
3960
3968
|
contextSchema: tool2 == null ? void 0 : tool2.contextSchema
|
|
3961
3969
|
}),
|
|
3962
3970
|
runtimeContext
|
|
@@ -3971,7 +3979,7 @@ async function resolveToolApproval({
|
|
|
3971
3979
|
messages,
|
|
3972
3980
|
context: await validateToolContext({
|
|
3973
3981
|
toolName,
|
|
3974
|
-
context: toolsContext
|
|
3982
|
+
context: getOwn(toolsContext, toolName),
|
|
3975
3983
|
contextSchema: tool2 == null ? void 0 : tool2.contextSchema
|
|
3976
3984
|
})
|
|
3977
3985
|
}) : tool2.needsApproval;
|
|
@@ -4656,7 +4664,7 @@ async function toResponseMessages({
|
|
|
4656
4664
|
const output = await createToolModelOutput({
|
|
4657
4665
|
toolCallId: part.toolCallId,
|
|
4658
4666
|
input: part.input,
|
|
4659
|
-
tool: tools
|
|
4667
|
+
tool: getOwn(tools, part.toolName),
|
|
4660
4668
|
output: part.output,
|
|
4661
4669
|
errorMode: "none"
|
|
4662
4670
|
});
|
|
@@ -4673,7 +4681,7 @@ async function toResponseMessages({
|
|
|
4673
4681
|
const output = await createToolModelOutput({
|
|
4674
4682
|
toolCallId: part.toolCallId,
|
|
4675
4683
|
input: part.input,
|
|
4676
|
-
tool: tools
|
|
4684
|
+
tool: getOwn(tools, part.toolName),
|
|
4677
4685
|
output: part.error,
|
|
4678
4686
|
errorMode: "json"
|
|
4679
4687
|
});
|
|
@@ -4735,7 +4743,7 @@ async function toResponseMessages({
|
|
|
4735
4743
|
const output = await createToolModelOutput({
|
|
4736
4744
|
toolCallId: part.toolCallId,
|
|
4737
4745
|
input: part.input,
|
|
4738
|
-
tool: tools
|
|
4746
|
+
tool: getOwn(tools, part.toolName),
|
|
4739
4747
|
output: part.type === "tool-result" ? part.output : part.error,
|
|
4740
4748
|
errorMode: part.type === "tool-error" ? "text" : "none"
|
|
4741
4749
|
});
|
|
@@ -4783,10 +4791,10 @@ function sortToolResultContentByToolCallOrder({
|
|
|
4783
4791
|
}
|
|
4784
4792
|
|
|
4785
4793
|
// src/generate-text/tool-approval-signature.ts
|
|
4786
|
-
import {
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
} from "@ai-sdk/provider-utils";
|
|
4794
|
+
import { convertBase64ToUint8Array as convertBase64ToUint8Array2 } from "@ai-sdk/provider-utils";
|
|
4795
|
+
|
|
4796
|
+
// src/util/canonical-hash.ts
|
|
4797
|
+
import { convertUint8ArrayToBase64 as convertUint8ArrayToBase642 } from "@ai-sdk/provider-utils";
|
|
4790
4798
|
var encoder = new TextEncoder();
|
|
4791
4799
|
function canonicalJSON(value) {
|
|
4792
4800
|
if (value === null || value === void 0) {
|
|
@@ -4807,11 +4815,21 @@ function canonicalJSON(value) {
|
|
|
4807
4815
|
function toBase64url(bytes) {
|
|
4808
4816
|
return convertUint8ArrayToBase642(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
4809
4817
|
}
|
|
4818
|
+
async function hashCanonical(value) {
|
|
4819
|
+
const digest = await crypto.subtle.digest(
|
|
4820
|
+
"SHA-256",
|
|
4821
|
+
encoder.encode(canonicalJSON(value))
|
|
4822
|
+
);
|
|
4823
|
+
return toBase64url(new Uint8Array(digest));
|
|
4824
|
+
}
|
|
4825
|
+
|
|
4826
|
+
// src/generate-text/tool-approval-signature.ts
|
|
4827
|
+
var encoder2 = new TextEncoder();
|
|
4810
4828
|
function fromBase64url(str) {
|
|
4811
4829
|
return convertBase64ToUint8Array2(str);
|
|
4812
4830
|
}
|
|
4813
4831
|
async function importKey(secret) {
|
|
4814
|
-
const keyData = typeof secret === "string" ?
|
|
4832
|
+
const keyData = typeof secret === "string" ? encoder2.encode(secret) : secret;
|
|
4815
4833
|
return crypto.subtle.importKey(
|
|
4816
4834
|
"raw",
|
|
4817
4835
|
keyData,
|
|
@@ -4820,16 +4838,8 @@ async function importKey(secret) {
|
|
|
4820
4838
|
["sign", "verify"]
|
|
4821
4839
|
);
|
|
4822
4840
|
}
|
|
4823
|
-
async function hashInput(input) {
|
|
4824
|
-
const canonical = canonicalJSON(input);
|
|
4825
|
-
const digest = await crypto.subtle.digest(
|
|
4826
|
-
"SHA-256",
|
|
4827
|
-
encoder.encode(canonical)
|
|
4828
|
-
);
|
|
4829
|
-
return toBase64url(new Uint8Array(digest));
|
|
4830
|
-
}
|
|
4831
4841
|
function buildPayload(approvalId, toolCallId, toolName, inputDigest) {
|
|
4832
|
-
return
|
|
4842
|
+
return encoder2.encode(
|
|
4833
4843
|
`${approvalId}
|
|
4834
4844
|
${toolCallId}
|
|
4835
4845
|
${toolName}
|
|
@@ -4844,7 +4854,7 @@ async function signToolApproval({
|
|
|
4844
4854
|
input
|
|
4845
4855
|
}) {
|
|
4846
4856
|
const key = await importKey(secret);
|
|
4847
|
-
const inputDigest = await
|
|
4857
|
+
const inputDigest = await hashCanonical(input);
|
|
4848
4858
|
const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
|
|
4849
4859
|
const sig = await crypto.subtle.sign("HMAC", key, payload);
|
|
4850
4860
|
return toBase64url(new Uint8Array(sig));
|
|
@@ -4858,7 +4868,7 @@ async function verifyToolApprovalSignature({
|
|
|
4858
4868
|
input
|
|
4859
4869
|
}) {
|
|
4860
4870
|
const key = await importKey(secret);
|
|
4861
|
-
const inputDigest = await
|
|
4871
|
+
const inputDigest = await hashCanonical(input);
|
|
4862
4872
|
const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
|
|
4863
4873
|
const sigBytes = fromBase64url(signature);
|
|
4864
4874
|
return crypto.subtle.verify("HMAC", key, sigBytes, payload);
|
|
@@ -4895,7 +4905,7 @@ async function validateApprovedToolApprovals({
|
|
|
4895
4905
|
const denied = [];
|
|
4896
4906
|
for (const approval of approvedToolApprovals) {
|
|
4897
4907
|
const { toolCall, approvalRequest } = approval;
|
|
4898
|
-
const tool2 = tools
|
|
4908
|
+
const tool2 = getOwn(tools, toolCall.toolName);
|
|
4899
4909
|
if (toolApprovalSecret != null) {
|
|
4900
4910
|
if (approvalRequest.signature == null) {
|
|
4901
4911
|
throw new InvalidToolApprovalSignatureError({
|
|
@@ -4990,7 +5000,8 @@ async function generateText({
|
|
|
4990
5000
|
activeTools,
|
|
4991
5001
|
toolOrder,
|
|
4992
5002
|
prepareStep,
|
|
4993
|
-
experimental_repairToolCall
|
|
5003
|
+
experimental_repairToolCall,
|
|
5004
|
+
repairToolCall = experimental_repairToolCall,
|
|
4994
5005
|
experimental_refineToolInput: refineToolInput,
|
|
4995
5006
|
experimental_download: download2,
|
|
4996
5007
|
runtimeContext = {},
|
|
@@ -5160,7 +5171,7 @@ async function generateText({
|
|
|
5160
5171
|
const modelOutput = await createToolModelOutput({
|
|
5161
5172
|
toolCallId: output2.toolCallId,
|
|
5162
5173
|
input: output2.input,
|
|
5163
|
-
tool: tools
|
|
5174
|
+
tool: getOwn(tools, output2.toolName),
|
|
5164
5175
|
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
5165
5176
|
errorMode: output2.type === "tool-error" ? "text" : "none"
|
|
5166
5177
|
});
|
|
@@ -5413,7 +5424,7 @@ async function generateText({
|
|
|
5413
5424
|
if (toolCall.invalid) {
|
|
5414
5425
|
continue;
|
|
5415
5426
|
}
|
|
5416
|
-
const tool2 = tools
|
|
5427
|
+
const tool2 = getOwn(tools, toolCall.toolName);
|
|
5417
5428
|
if (tool2 == null) {
|
|
5418
5429
|
continue;
|
|
5419
5430
|
}
|
|
@@ -5574,7 +5585,7 @@ async function generateText({
|
|
|
5574
5585
|
for (const toolCall of stepToolCalls) {
|
|
5575
5586
|
if (!toolCall.providerExecuted)
|
|
5576
5587
|
continue;
|
|
5577
|
-
const tool2 = tools
|
|
5588
|
+
const tool2 = getOwn(tools, toolCall.toolName);
|
|
5578
5589
|
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
5579
5590
|
const hasResultInResponse = currentModelResponse.content.some(
|
|
5580
5591
|
(part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
|
|
@@ -5923,7 +5934,7 @@ function asContent({
|
|
|
5923
5934
|
(toolCall2) => toolCall2.toolCallId === part.toolCallId
|
|
5924
5935
|
);
|
|
5925
5936
|
if (toolCall == null) {
|
|
5926
|
-
const tool2 = tools
|
|
5937
|
+
const tool2 = getOwn(tools, part.toolName);
|
|
5927
5938
|
const supportsDeferredResults = (tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults;
|
|
5928
5939
|
if (!supportsDeferredResults) {
|
|
5929
5940
|
throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
@@ -6079,6 +6090,10 @@ function writeToServerResponse({
|
|
|
6079
6090
|
if (done)
|
|
6080
6091
|
break;
|
|
6081
6092
|
const canContinue = response.write(value);
|
|
6093
|
+
const flush = response.flush;
|
|
6094
|
+
if (typeof flush === "function") {
|
|
6095
|
+
flush.call(response);
|
|
6096
|
+
}
|
|
6082
6097
|
if (!canContinue) {
|
|
6083
6098
|
await new Promise((resolve3) => {
|
|
6084
6099
|
response.once("drain", resolve3);
|
|
@@ -6916,7 +6931,8 @@ function processUIMessageStream({
|
|
|
6916
6931
|
id: chunk.approvalId,
|
|
6917
6932
|
approved: chunk.approved,
|
|
6918
6933
|
...chunk.reason != null ? { reason: chunk.reason } : {},
|
|
6919
|
-
...approval.isAutomatic === true ? { isAutomatic: true } : {}
|
|
6934
|
+
...approval.isAutomatic === true ? { isAutomatic: true } : {},
|
|
6935
|
+
...approval.signature != null ? { signature: approval.signature } : {}
|
|
6920
6936
|
};
|
|
6921
6937
|
if (chunk.providerExecuted != null) {
|
|
6922
6938
|
toolInvocation.providerExecuted = chunk.providerExecuted;
|
|
@@ -7703,7 +7719,7 @@ function executeToolsFromStream({
|
|
|
7703
7719
|
if (chunk.invalid) {
|
|
7704
7720
|
return;
|
|
7705
7721
|
}
|
|
7706
|
-
const tool2 = tools
|
|
7722
|
+
const tool2 = getOwn(tools, chunk.toolName);
|
|
7707
7723
|
if (tool2 == null) {
|
|
7708
7724
|
return;
|
|
7709
7725
|
}
|
|
@@ -7836,7 +7852,7 @@ function invokeToolCallbacksFromStream({
|
|
|
7836
7852
|
}) {
|
|
7837
7853
|
if (tools == null)
|
|
7838
7854
|
return stream;
|
|
7839
|
-
const ongoingToolCallToolNames =
|
|
7855
|
+
const ongoingToolCallToolNames = createIdMap();
|
|
7840
7856
|
return stream.pipeThrough(
|
|
7841
7857
|
new TransformStream({
|
|
7842
7858
|
async transform(chunk, controller) {
|
|
@@ -7844,7 +7860,7 @@ function invokeToolCallbacksFromStream({
|
|
|
7844
7860
|
switch (chunk.type) {
|
|
7845
7861
|
case "tool-input-start": {
|
|
7846
7862
|
ongoingToolCallToolNames[chunk.id] = chunk.toolName;
|
|
7847
|
-
const tool2 = tools
|
|
7863
|
+
const tool2 = getOwn(tools, chunk.toolName);
|
|
7848
7864
|
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
|
7849
7865
|
await tool2.onInputStart({
|
|
7850
7866
|
toolCallId: chunk.id,
|
|
@@ -7857,7 +7873,7 @@ function invokeToolCallbacksFromStream({
|
|
|
7857
7873
|
}
|
|
7858
7874
|
case "tool-input-delta": {
|
|
7859
7875
|
const toolName = ongoingToolCallToolNames[chunk.id];
|
|
7860
|
-
const tool2 = tools
|
|
7876
|
+
const tool2 = getOwn(tools, toolName);
|
|
7861
7877
|
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
|
7862
7878
|
await tool2.onInputDelta({
|
|
7863
7879
|
inputTextDelta: chunk.delta,
|
|
@@ -7871,7 +7887,7 @@ function invokeToolCallbacksFromStream({
|
|
|
7871
7887
|
}
|
|
7872
7888
|
case "tool-call": {
|
|
7873
7889
|
const toolName = ongoingToolCallToolNames[chunk.toolCallId];
|
|
7874
|
-
const tool2 = tools
|
|
7890
|
+
const tool2 = getOwn(tools, toolName);
|
|
7875
7891
|
delete ongoingToolCallToolNames[chunk.toolCallId];
|
|
7876
7892
|
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
|
7877
7893
|
await tool2.onInputAvailable({
|
|
@@ -8281,7 +8297,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
|
|
|
8281
8297
|
break;
|
|
8282
8298
|
}
|
|
8283
8299
|
case "tool-input-start": {
|
|
8284
|
-
const tool2 = tools
|
|
8300
|
+
const tool2 = getOwn(tools, chunk.toolName);
|
|
8285
8301
|
controller.enqueue({
|
|
8286
8302
|
...chunk,
|
|
8287
8303
|
dynamic: (_a22 = chunk.dynamic) != null ? _a22 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
|
|
@@ -8420,7 +8436,8 @@ function streamText({
|
|
|
8420
8436
|
providerOptions,
|
|
8421
8437
|
activeTools,
|
|
8422
8438
|
toolOrder,
|
|
8423
|
-
experimental_repairToolCall
|
|
8439
|
+
experimental_repairToolCall,
|
|
8440
|
+
repairToolCall = experimental_repairToolCall,
|
|
8424
8441
|
experimental_refineToolInput: refineToolInput,
|
|
8425
8442
|
experimental_transform: transform,
|
|
8426
8443
|
experimental_download: download2,
|
|
@@ -9131,7 +9148,7 @@ var DefaultStreamTextResult = class {
|
|
|
9131
9148
|
output: await createToolModelOutput({
|
|
9132
9149
|
toolCallId: output2.toolCallId,
|
|
9133
9150
|
input: output2.input,
|
|
9134
|
-
tool: tools
|
|
9151
|
+
tool: getOwn(tools, output2.toolName),
|
|
9135
9152
|
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
9136
9153
|
errorMode: output2.type === "tool-error" ? "text" : "none"
|
|
9137
9154
|
})
|
|
@@ -9548,7 +9565,7 @@ var DefaultStreamTextResult = class {
|
|
|
9548
9565
|
for (const toolCall of stepToolCalls) {
|
|
9549
9566
|
if (toolCall.providerExecuted !== true)
|
|
9550
9567
|
continue;
|
|
9551
|
-
const tool2 = tools
|
|
9568
|
+
const tool2 = getOwn(tools, toolCall.toolName);
|
|
9552
9569
|
if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
|
|
9553
9570
|
const hasResultInStep = stepToolOutputs.some(
|
|
9554
9571
|
(output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
|
|
@@ -10351,7 +10368,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10351
10368
|
if (message.parts != null) {
|
|
10352
10369
|
let block = [];
|
|
10353
10370
|
async function processBlock() {
|
|
10354
|
-
var _a22, _b, _c, _d, _e, _f, _g
|
|
10371
|
+
var _a22, _b, _c, _d, _e, _f, _g;
|
|
10355
10372
|
if (block.length === 0) {
|
|
10356
10373
|
return;
|
|
10357
10374
|
}
|
|
@@ -10423,7 +10440,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10423
10440
|
toolCallId: part.toolCallId,
|
|
10424
10441
|
input: part.input,
|
|
10425
10442
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
10426
|
-
tool: (
|
|
10443
|
+
tool: getOwn(options == null ? void 0 : options.tools, toolName),
|
|
10427
10444
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
10428
10445
|
}),
|
|
10429
10446
|
...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
|
|
@@ -10431,7 +10448,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10431
10448
|
}
|
|
10432
10449
|
}
|
|
10433
10450
|
} else if (isDataUIPart(part)) {
|
|
10434
|
-
const dataPart = (
|
|
10451
|
+
const dataPart = (_c = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _c.call(
|
|
10435
10452
|
options,
|
|
10436
10453
|
part
|
|
10437
10454
|
);
|
|
@@ -10459,7 +10476,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10459
10476
|
{
|
|
10460
10477
|
const content2 = [];
|
|
10461
10478
|
for (const toolPart of toolParts) {
|
|
10462
|
-
if (((
|
|
10479
|
+
if (((_d = toolPart.approval) == null ? void 0 : _d.approved) != null) {
|
|
10463
10480
|
content2.push({
|
|
10464
10481
|
type: "tool-approval-response",
|
|
10465
10482
|
approvalId: toolPart.approval.id,
|
|
@@ -10468,7 +10485,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10468
10485
|
providerExecuted: toolPart.providerExecuted
|
|
10469
10486
|
});
|
|
10470
10487
|
}
|
|
10471
|
-
if (toolPart.state === "approval-responded" && ((
|
|
10488
|
+
if (toolPart.state === "approval-responded" && ((_e = toolPart.approval) == null ? void 0 : _e.approved) === false) {
|
|
10472
10489
|
content2.push({
|
|
10473
10490
|
type: "tool-result",
|
|
10474
10491
|
toolCallId: toolPart.toolCallId,
|
|
@@ -10491,7 +10508,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10491
10508
|
toolName: getToolName(toolPart),
|
|
10492
10509
|
output: {
|
|
10493
10510
|
type: "error-text",
|
|
10494
|
-
value: (
|
|
10511
|
+
value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool call execution denied."
|
|
10495
10512
|
},
|
|
10496
10513
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
10497
10514
|
});
|
|
@@ -10508,7 +10525,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
10508
10525
|
toolCallId: toolPart.toolCallId,
|
|
10509
10526
|
input: toolPart.input,
|
|
10510
10527
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
10511
|
-
tool: (
|
|
10528
|
+
tool: getOwn(options == null ? void 0 : options.tools, toolName),
|
|
10512
10529
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
10513
10530
|
}),
|
|
10514
10531
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -10943,7 +10960,7 @@ async function safeValidateUIMessages({
|
|
|
10943
10960
|
if (tools && part.type.startsWith("tool-")) {
|
|
10944
10961
|
const toolPart = part;
|
|
10945
10962
|
const toolName = toolPart.type.slice(5);
|
|
10946
|
-
const tool2 = tools
|
|
10963
|
+
const tool2 = getOwn(tools, toolName);
|
|
10947
10964
|
if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied")) {
|
|
10948
10965
|
continue;
|
|
10949
10966
|
}
|
|
@@ -13397,6 +13414,50 @@ function smoothStream({
|
|
|
13397
13414
|
};
|
|
13398
13415
|
}
|
|
13399
13416
|
|
|
13417
|
+
// src/generate-text/tool-fingerprint.ts
|
|
13418
|
+
import { asSchema as asSchema6 } from "@ai-sdk/provider-utils";
|
|
13419
|
+
function tagDescription(description) {
|
|
13420
|
+
if (typeof description === "string") {
|
|
13421
|
+
return { type: "string", value: description };
|
|
13422
|
+
}
|
|
13423
|
+
if (description == null) {
|
|
13424
|
+
return { type: "none" };
|
|
13425
|
+
}
|
|
13426
|
+
return { type: "function" };
|
|
13427
|
+
}
|
|
13428
|
+
async function fingerprintTools(tools) {
|
|
13429
|
+
const entries = await Promise.all(
|
|
13430
|
+
Object.keys(tools).map(async (name22) => {
|
|
13431
|
+
const tool2 = tools[name22];
|
|
13432
|
+
const digest = await hashCanonical({
|
|
13433
|
+
description: tagDescription(tool2.description),
|
|
13434
|
+
inputSchema: await asSchema6(tool2.inputSchema).jsonSchema,
|
|
13435
|
+
title: tool2.title
|
|
13436
|
+
});
|
|
13437
|
+
return [name22, digest];
|
|
13438
|
+
})
|
|
13439
|
+
);
|
|
13440
|
+
return Object.fromEntries(entries);
|
|
13441
|
+
}
|
|
13442
|
+
function detectToolDrift(current, baseline) {
|
|
13443
|
+
const added = [];
|
|
13444
|
+
const removed = [];
|
|
13445
|
+
const changed = [];
|
|
13446
|
+
for (const name22 of Object.keys(current)) {
|
|
13447
|
+
if (!Object.hasOwn(baseline, name22)) {
|
|
13448
|
+
added.push(name22);
|
|
13449
|
+
} else if (current[name22] !== baseline[name22]) {
|
|
13450
|
+
changed.push(name22);
|
|
13451
|
+
}
|
|
13452
|
+
}
|
|
13453
|
+
for (const name22 of Object.keys(baseline)) {
|
|
13454
|
+
if (!Object.hasOwn(current, name22)) {
|
|
13455
|
+
removed.push(name22);
|
|
13456
|
+
}
|
|
13457
|
+
}
|
|
13458
|
+
return { added, removed, changed };
|
|
13459
|
+
}
|
|
13460
|
+
|
|
13400
13461
|
// src/generate-video/generate-video.ts
|
|
13401
13462
|
import {
|
|
13402
13463
|
convertBase64ToUint8Array as convertBase64ToUint8Array5,
|
|
@@ -13434,13 +13495,14 @@ async function experimental_generateVideo({
|
|
|
13434
13495
|
abortSignal
|
|
13435
13496
|
});
|
|
13436
13497
|
const { prompt, image } = normalizePrompt2(promptArg);
|
|
13437
|
-
const normalizedFrameImages = frameImages == null ? void 0 : frameImages.
|
|
13438
|
-
|
|
13439
|
-
frameType: frame.frameType
|
|
13440
|
-
})
|
|
13441
|
-
const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.
|
|
13442
|
-
|
|
13443
|
-
|
|
13498
|
+
const normalizedFrameImages = frameImages == null ? void 0 : frameImages.flatMap((frame) => {
|
|
13499
|
+
const normalizedImage = normalizeImageData(frame.image);
|
|
13500
|
+
return normalizedImage != null ? [{ image: normalizedImage, frameType: frame.frameType }] : [];
|
|
13501
|
+
});
|
|
13502
|
+
const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.flatMap((reference) => {
|
|
13503
|
+
const normalized = normalizeReferenceData(reference);
|
|
13504
|
+
return normalized != null ? [normalized] : [];
|
|
13505
|
+
});
|
|
13444
13506
|
const effectiveInputReferences = normalizedFrameImages != null && normalizedFrameImages.length > 0 ? void 0 : normalizedInputReferences;
|
|
13445
13507
|
const warnings = [];
|
|
13446
13508
|
if (normalizedFrameImages != null && normalizedFrameImages.length > 0 && normalizedInputReferences != null && normalizedInputReferences.length > 0) {
|
|
@@ -13594,8 +13656,11 @@ function normalizePrompt2(promptArg) {
|
|
|
13594
13656
|
image: promptArg.image != null ? normalizeImageData(promptArg.image) : void 0
|
|
13595
13657
|
};
|
|
13596
13658
|
}
|
|
13597
|
-
function
|
|
13598
|
-
|
|
13659
|
+
function detectFileMediaType(data, restrictToImages) {
|
|
13660
|
+
const detected = restrictToImages ? detectMediaType4({ data, topLevelType: "image" }) : detectMediaType4({ data });
|
|
13661
|
+
return detected != null ? detected : "image/png";
|
|
13662
|
+
}
|
|
13663
|
+
function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
|
|
13599
13664
|
if (typeof dataContent === "string") {
|
|
13600
13665
|
if (dataContent.startsWith("http://") || dataContent.startsWith("https://")) {
|
|
13601
13666
|
return {
|
|
@@ -13605,24 +13670,46 @@ function normalizeImageData(dataContent) {
|
|
|
13605
13670
|
}
|
|
13606
13671
|
if (dataContent.startsWith("data:")) {
|
|
13607
13672
|
const { mediaType, base64Content } = splitDataUrl(dataContent);
|
|
13673
|
+
const data = convertBase64ToUint8Array5(base64Content != null ? base64Content : "");
|
|
13608
13674
|
return {
|
|
13609
13675
|
type: "file",
|
|
13610
|
-
mediaType: mediaType != null ? mediaType :
|
|
13611
|
-
data
|
|
13676
|
+
mediaType: mediaType != null ? mediaType : detectFileMediaType(data, restrictToImages),
|
|
13677
|
+
data
|
|
13612
13678
|
};
|
|
13613
13679
|
}
|
|
13614
|
-
const
|
|
13680
|
+
const bytes = convertBase64ToUint8Array5(dataContent);
|
|
13681
|
+
return {
|
|
13682
|
+
type: "file",
|
|
13683
|
+
mediaType: detectFileMediaType(bytes, restrictToImages),
|
|
13684
|
+
data: bytes
|
|
13685
|
+
};
|
|
13686
|
+
}
|
|
13687
|
+
if (dataContent instanceof Uint8Array || dataContent instanceof ArrayBuffer) {
|
|
13688
|
+
const bytes = dataContent instanceof Uint8Array ? dataContent : new Uint8Array(dataContent);
|
|
13615
13689
|
return {
|
|
13616
13690
|
type: "file",
|
|
13617
|
-
mediaType: (
|
|
13618
|
-
data:
|
|
13691
|
+
mediaType: detectFileMediaType(bytes, restrictToImages),
|
|
13692
|
+
data: bytes
|
|
13619
13693
|
};
|
|
13620
13694
|
}
|
|
13621
|
-
|
|
13695
|
+
return void 0;
|
|
13696
|
+
}
|
|
13697
|
+
function normalizeReferenceData(reference) {
|
|
13698
|
+
const isObjectForm = typeof reference === "object" && reference != null && !(reference instanceof Uint8Array) && !(reference instanceof ArrayBuffer) && "data" in reference;
|
|
13699
|
+
if (!isObjectForm) {
|
|
13700
|
+
return normalizeImageData(reference, {
|
|
13701
|
+
restrictToImages: false
|
|
13702
|
+
});
|
|
13703
|
+
}
|
|
13704
|
+
const normalized = normalizeImageData(reference.data, {
|
|
13705
|
+
restrictToImages: false
|
|
13706
|
+
});
|
|
13707
|
+
if (normalized == null) {
|
|
13708
|
+
return normalized;
|
|
13709
|
+
}
|
|
13622
13710
|
return {
|
|
13623
|
-
|
|
13624
|
-
mediaType
|
|
13625
|
-
data: bytes
|
|
13711
|
+
...normalized,
|
|
13712
|
+
...reference.mediaType != null ? { mediaType: reference.mediaType } : {}
|
|
13626
13713
|
};
|
|
13627
13714
|
}
|
|
13628
13715
|
async function invokeModelMaxVideosPerCall(model) {
|
|
@@ -14307,7 +14394,7 @@ function resampleAudio(input, inputRate, outputRate) {
|
|
|
14307
14394
|
|
|
14308
14395
|
// src/realtime/get-realtime-tool-definitions.ts
|
|
14309
14396
|
import {
|
|
14310
|
-
asSchema as
|
|
14397
|
+
asSchema as asSchema7
|
|
14311
14398
|
} from "@ai-sdk/provider-utils";
|
|
14312
14399
|
async function getRealtimeToolDefinitions({
|
|
14313
14400
|
tools,
|
|
@@ -14329,7 +14416,7 @@ async function getRealtimeToolDefinitions({
|
|
|
14329
14416
|
type: "function",
|
|
14330
14417
|
name: name22,
|
|
14331
14418
|
description,
|
|
14332
|
-
parameters: await
|
|
14419
|
+
parameters: await asSchema7(tool2.inputSchema).jsonSchema
|
|
14333
14420
|
});
|
|
14334
14421
|
break;
|
|
14335
14422
|
}
|
|
@@ -16985,7 +17072,7 @@ export {
|
|
|
16985
17072
|
UnsupportedFunctionalityError,
|
|
16986
17073
|
UnsupportedModelVersionError,
|
|
16987
17074
|
addToolInputExamplesMiddleware,
|
|
16988
|
-
|
|
17075
|
+
asSchema8 as asSchema,
|
|
16989
17076
|
assistantModelMessageSchema,
|
|
16990
17077
|
callCompletionApi,
|
|
16991
17078
|
consumeStream,
|
|
@@ -17005,6 +17092,7 @@ export {
|
|
|
17005
17092
|
customProvider,
|
|
17006
17093
|
defaultEmbeddingSettingsMiddleware,
|
|
17007
17094
|
defaultSettingsMiddleware,
|
|
17095
|
+
detectToolDrift,
|
|
17008
17096
|
dynamicTool,
|
|
17009
17097
|
embed,
|
|
17010
17098
|
embedMany,
|
|
@@ -17021,6 +17109,7 @@ export {
|
|
|
17021
17109
|
experimental_transcribe,
|
|
17022
17110
|
extractJsonMiddleware,
|
|
17023
17111
|
extractReasoningMiddleware,
|
|
17112
|
+
fingerprintTools,
|
|
17024
17113
|
gateway2 as gateway,
|
|
17025
17114
|
generateId,
|
|
17026
17115
|
generateImage,
|