ai 7.0.17 → 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.
Files changed (50) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/index.d.ts +38 -3
  3. package/dist/index.js +160 -77
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.js +43 -31
  6. package/dist/internal/index.js.map +1 -1
  7. package/docs/02-foundations/02-providers-and-models.mdx +57 -52
  8. package/docs/02-getting-started/00-choosing-a-provider.mdx +1 -16
  9. package/docs/02-getting-started/01-navigating-the-library.mdx +12 -12
  10. package/docs/02-getting-started/02-nextjs-app-router.mdx +2 -36
  11. package/docs/02-getting-started/03-nextjs-pages-router.mdx +2 -36
  12. package/docs/02-getting-started/04-svelte.mdx +2 -34
  13. package/docs/02-getting-started/05-nuxt.mdx +2 -36
  14. package/docs/02-getting-started/06-nodejs.mdx +1 -18
  15. package/docs/02-getting-started/07-expo.mdx +3 -62
  16. package/docs/02-getting-started/08-tanstack-start.mdx +2 -36
  17. package/docs/02-getting-started/09-coding-agents.mdx +2 -32
  18. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
  19. package/docs/03-ai-sdk-core/30-embeddings.mdx +18 -18
  20. package/docs/03-ai-sdk-core/38-video-generation.mdx +22 -3
  21. package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +1 -28
  22. package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +7 -7
  23. package/docs/03-ai-sdk-harnesses/06-workflow-utilities.mdx +1 -16
  24. package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +1 -28
  25. package/docs/04-ai-sdk-ui/01-overview.mdx +5 -5
  26. package/docs/04-ai-sdk-ui/08-object-generation.mdx +7 -10
  27. package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +3 -2
  28. package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +6 -9
  29. package/docs/07-reference/02-ai-sdk-ui/index.mdx +5 -5
  30. package/package.json +4 -4
  31. package/src/generate-text/collect-tool-approvals.ts +17 -4
  32. package/src/generate-text/execute-tool-call.ts +3 -2
  33. package/src/generate-text/execute-tools-from-stream.ts +2 -1
  34. package/src/generate-text/generate-text.ts +5 -4
  35. package/src/generate-text/index.ts +1 -0
  36. package/src/generate-text/invoke-tool-callbacks-from-stream.ts +6 -4
  37. package/src/generate-text/parse-tool-call.ts +5 -4
  38. package/src/generate-text/resolve-tool-approval.ts +9 -6
  39. package/src/generate-text/stream-language-model-call.ts +2 -1
  40. package/src/generate-text/stream-text.ts +3 -2
  41. package/src/generate-text/to-response-messages.ts +4 -3
  42. package/src/generate-text/tool-approval-signature.ts +4 -40
  43. package/src/generate-text/tool-fingerprint.ts +76 -0
  44. package/src/generate-text/validate-tool-approvals.ts +6 -1
  45. package/src/generate-video/generate-video.ts +96 -21
  46. package/src/ui/convert-to-model-messages.ts +3 -2
  47. package/src/ui/process-ui-message-stream.ts +3 -0
  48. package/src/ui/validate-ui-messages.ts +2 -1
  49. package/src/util/canonical-hash.ts +44 -0
  50. package/src/util/get-own.ts +18 -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 asSchema7,
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.17" : "0.0.0-test";
1092
+ var VERSION = true ? "7.0.19" : "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 == null ? void 0 : tools[toolName];
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 == null ? void 0 : toolsContext[toolName],
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
- const { inputSchema } = tools[toolName];
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 == null ? void 0 : tools[toolCall.toolName];
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 == null ? void 0 : refineToolInput[toolCall.toolName];
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[toolName];
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 == null ? void 0 : tools[toolName];
3958
+ const tool2 = getOwn(tools, toolName);
3951
3959
  const input = toolCall.input;
3952
- const userDefinedToolApprovalStatus = toolApproval == null ? void 0 : toolApproval[toolName];
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 == null ? void 0 : toolsContext[toolName],
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 == null ? void 0 : toolsContext[toolName],
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 == null ? void 0 : tools[part.toolName],
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 == null ? void 0 : tools[part.toolName],
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 == null ? void 0 : tools[part.toolName],
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
- convertBase64ToUint8Array as convertBase64ToUint8Array2,
4788
- convertUint8ArrayToBase64 as convertUint8ArrayToBase642
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" ? encoder.encode(secret) : secret;
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 encoder.encode(
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 hashInput(input);
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 hashInput(input);
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 == null ? void 0 : tools[toolCall.toolName];
4908
+ const tool2 = getOwn(tools, toolCall.toolName);
4899
4909
  if (toolApprovalSecret != null) {
4900
4910
  if (approvalRequest.signature == null) {
4901
4911
  throw new InvalidToolApprovalSignatureError({
@@ -5160,7 +5170,7 @@ async function generateText({
5160
5170
  const modelOutput = await createToolModelOutput({
5161
5171
  toolCallId: output2.toolCallId,
5162
5172
  input: output2.input,
5163
- tool: tools == null ? void 0 : tools[output2.toolName],
5173
+ tool: getOwn(tools, output2.toolName),
5164
5174
  output: output2.type === "tool-result" ? output2.output : output2.error,
5165
5175
  errorMode: output2.type === "tool-error" ? "text" : "none"
5166
5176
  });
@@ -5413,7 +5423,7 @@ async function generateText({
5413
5423
  if (toolCall.invalid) {
5414
5424
  continue;
5415
5425
  }
5416
- const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
5426
+ const tool2 = getOwn(tools, toolCall.toolName);
5417
5427
  if (tool2 == null) {
5418
5428
  continue;
5419
5429
  }
@@ -5574,7 +5584,7 @@ async function generateText({
5574
5584
  for (const toolCall of stepToolCalls) {
5575
5585
  if (!toolCall.providerExecuted)
5576
5586
  continue;
5577
- const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
5587
+ const tool2 = getOwn(tools, toolCall.toolName);
5578
5588
  if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
5579
5589
  const hasResultInResponse = currentModelResponse.content.some(
5580
5590
  (part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
@@ -5923,7 +5933,7 @@ function asContent({
5923
5933
  (toolCall2) => toolCall2.toolCallId === part.toolCallId
5924
5934
  );
5925
5935
  if (toolCall == null) {
5926
- const tool2 = tools == null ? void 0 : tools[part.toolName];
5936
+ const tool2 = getOwn(tools, part.toolName);
5927
5937
  const supportsDeferredResults = (tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults;
5928
5938
  if (!supportsDeferredResults) {
5929
5939
  throw new Error(`Tool call ${part.toolCallId} not found.`);
@@ -6916,7 +6926,8 @@ function processUIMessageStream({
6916
6926
  id: chunk.approvalId,
6917
6927
  approved: chunk.approved,
6918
6928
  ...chunk.reason != null ? { reason: chunk.reason } : {},
6919
- ...approval.isAutomatic === true ? { isAutomatic: true } : {}
6929
+ ...approval.isAutomatic === true ? { isAutomatic: true } : {},
6930
+ ...approval.signature != null ? { signature: approval.signature } : {}
6920
6931
  };
6921
6932
  if (chunk.providerExecuted != null) {
6922
6933
  toolInvocation.providerExecuted = chunk.providerExecuted;
@@ -7703,7 +7714,7 @@ function executeToolsFromStream({
7703
7714
  if (chunk.invalid) {
7704
7715
  return;
7705
7716
  }
7706
- const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7717
+ const tool2 = getOwn(tools, chunk.toolName);
7707
7718
  if (tool2 == null) {
7708
7719
  return;
7709
7720
  }
@@ -7836,7 +7847,7 @@ function invokeToolCallbacksFromStream({
7836
7847
  }) {
7837
7848
  if (tools == null)
7838
7849
  return stream;
7839
- const ongoingToolCallToolNames = {};
7850
+ const ongoingToolCallToolNames = createIdMap();
7840
7851
  return stream.pipeThrough(
7841
7852
  new TransformStream({
7842
7853
  async transform(chunk, controller) {
@@ -7844,7 +7855,7 @@ function invokeToolCallbacksFromStream({
7844
7855
  switch (chunk.type) {
7845
7856
  case "tool-input-start": {
7846
7857
  ongoingToolCallToolNames[chunk.id] = chunk.toolName;
7847
- const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7858
+ const tool2 = getOwn(tools, chunk.toolName);
7848
7859
  if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
7849
7860
  await tool2.onInputStart({
7850
7861
  toolCallId: chunk.id,
@@ -7857,7 +7868,7 @@ function invokeToolCallbacksFromStream({
7857
7868
  }
7858
7869
  case "tool-input-delta": {
7859
7870
  const toolName = ongoingToolCallToolNames[chunk.id];
7860
- const tool2 = tools == null ? void 0 : tools[toolName];
7871
+ const tool2 = getOwn(tools, toolName);
7861
7872
  if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
7862
7873
  await tool2.onInputDelta({
7863
7874
  inputTextDelta: chunk.delta,
@@ -7871,7 +7882,7 @@ function invokeToolCallbacksFromStream({
7871
7882
  }
7872
7883
  case "tool-call": {
7873
7884
  const toolName = ongoingToolCallToolNames[chunk.toolCallId];
7874
- const tool2 = tools == null ? void 0 : tools[toolName];
7885
+ const tool2 = getOwn(tools, toolName);
7875
7886
  delete ongoingToolCallToolNames[chunk.toolCallId];
7876
7887
  if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
7877
7888
  await tool2.onInputAvailable({
@@ -8281,7 +8292,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8281
8292
  break;
8282
8293
  }
8283
8294
  case "tool-input-start": {
8284
- const tool2 = tools == null ? void 0 : tools[chunk.toolName];
8295
+ const tool2 = getOwn(tools, chunk.toolName);
8285
8296
  controller.enqueue({
8286
8297
  ...chunk,
8287
8298
  dynamic: (_a22 = chunk.dynamic) != null ? _a22 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
@@ -9131,7 +9142,7 @@ var DefaultStreamTextResult = class {
9131
9142
  output: await createToolModelOutput({
9132
9143
  toolCallId: output2.toolCallId,
9133
9144
  input: output2.input,
9134
- tool: tools == null ? void 0 : tools[output2.toolName],
9145
+ tool: getOwn(tools, output2.toolName),
9135
9146
  output: output2.type === "tool-result" ? output2.output : output2.error,
9136
9147
  errorMode: output2.type === "tool-error" ? "text" : "none"
9137
9148
  })
@@ -9548,7 +9559,7 @@ var DefaultStreamTextResult = class {
9548
9559
  for (const toolCall of stepToolCalls) {
9549
9560
  if (toolCall.providerExecuted !== true)
9550
9561
  continue;
9551
- const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
9562
+ const tool2 = getOwn(tools, toolCall.toolName);
9552
9563
  if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
9553
9564
  const hasResultInStep = stepToolOutputs.some(
9554
9565
  (output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
@@ -10351,7 +10362,7 @@ async function convertToModelMessages(messages, options) {
10351
10362
  if (message.parts != null) {
10352
10363
  let block = [];
10353
10364
  async function processBlock() {
10354
- var _a22, _b, _c, _d, _e, _f, _g, _h, _i;
10365
+ var _a22, _b, _c, _d, _e, _f, _g;
10355
10366
  if (block.length === 0) {
10356
10367
  return;
10357
10368
  }
@@ -10423,7 +10434,7 @@ async function convertToModelMessages(messages, options) {
10423
10434
  toolCallId: part.toolCallId,
10424
10435
  input: part.input,
10425
10436
  output: part.state === "output-error" ? part.errorText : part.output,
10426
- tool: (_c = options == null ? void 0 : options.tools) == null ? void 0 : _c[toolName],
10437
+ tool: getOwn(options == null ? void 0 : options.tools, toolName),
10427
10438
  errorMode: part.state === "output-error" ? "json" : "none"
10428
10439
  }),
10429
10440
  ...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
@@ -10431,7 +10442,7 @@ async function convertToModelMessages(messages, options) {
10431
10442
  }
10432
10443
  }
10433
10444
  } else if (isDataUIPart(part)) {
10434
- const dataPart = (_d = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _d.call(
10445
+ const dataPart = (_c = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _c.call(
10435
10446
  options,
10436
10447
  part
10437
10448
  );
@@ -10459,7 +10470,7 @@ async function convertToModelMessages(messages, options) {
10459
10470
  {
10460
10471
  const content2 = [];
10461
10472
  for (const toolPart of toolParts) {
10462
- if (((_e = toolPart.approval) == null ? void 0 : _e.approved) != null) {
10473
+ if (((_d = toolPart.approval) == null ? void 0 : _d.approved) != null) {
10463
10474
  content2.push({
10464
10475
  type: "tool-approval-response",
10465
10476
  approvalId: toolPart.approval.id,
@@ -10468,7 +10479,7 @@ async function convertToModelMessages(messages, options) {
10468
10479
  providerExecuted: toolPart.providerExecuted
10469
10480
  });
10470
10481
  }
10471
- if (toolPart.state === "approval-responded" && ((_f = toolPart.approval) == null ? void 0 : _f.approved) === false) {
10482
+ if (toolPart.state === "approval-responded" && ((_e = toolPart.approval) == null ? void 0 : _e.approved) === false) {
10472
10483
  content2.push({
10473
10484
  type: "tool-result",
10474
10485
  toolCallId: toolPart.toolCallId,
@@ -10491,7 +10502,7 @@ async function convertToModelMessages(messages, options) {
10491
10502
  toolName: getToolName(toolPart),
10492
10503
  output: {
10493
10504
  type: "error-text",
10494
- value: (_h = (_g = toolPart.approval) == null ? void 0 : _g.reason) != null ? _h : "Tool call execution denied."
10505
+ value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool call execution denied."
10495
10506
  },
10496
10507
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
10497
10508
  });
@@ -10508,7 +10519,7 @@ async function convertToModelMessages(messages, options) {
10508
10519
  toolCallId: toolPart.toolCallId,
10509
10520
  input: toolPart.input,
10510
10521
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
10511
- tool: (_i = options == null ? void 0 : options.tools) == null ? void 0 : _i[toolName],
10522
+ tool: getOwn(options == null ? void 0 : options.tools, toolName),
10512
10523
  errorMode: toolPart.state === "output-error" ? "text" : "none"
10513
10524
  }),
10514
10525
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
@@ -10943,7 +10954,7 @@ async function safeValidateUIMessages({
10943
10954
  if (tools && part.type.startsWith("tool-")) {
10944
10955
  const toolPart = part;
10945
10956
  const toolName = toolPart.type.slice(5);
10946
- const tool2 = tools[toolName];
10957
+ const tool2 = getOwn(tools, toolName);
10947
10958
  if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied")) {
10948
10959
  continue;
10949
10960
  }
@@ -13397,6 +13408,50 @@ function smoothStream({
13397
13408
  };
13398
13409
  }
13399
13410
 
13411
+ // src/generate-text/tool-fingerprint.ts
13412
+ import { asSchema as asSchema6 } from "@ai-sdk/provider-utils";
13413
+ function tagDescription(description) {
13414
+ if (typeof description === "string") {
13415
+ return { type: "string", value: description };
13416
+ }
13417
+ if (description == null) {
13418
+ return { type: "none" };
13419
+ }
13420
+ return { type: "function" };
13421
+ }
13422
+ async function fingerprintTools(tools) {
13423
+ const entries = await Promise.all(
13424
+ Object.keys(tools).map(async (name22) => {
13425
+ const tool2 = tools[name22];
13426
+ const digest = await hashCanonical({
13427
+ description: tagDescription(tool2.description),
13428
+ inputSchema: await asSchema6(tool2.inputSchema).jsonSchema,
13429
+ title: tool2.title
13430
+ });
13431
+ return [name22, digest];
13432
+ })
13433
+ );
13434
+ return Object.fromEntries(entries);
13435
+ }
13436
+ function detectToolDrift(current, baseline) {
13437
+ const added = [];
13438
+ const removed = [];
13439
+ const changed = [];
13440
+ for (const name22 of Object.keys(current)) {
13441
+ if (!Object.hasOwn(baseline, name22)) {
13442
+ added.push(name22);
13443
+ } else if (current[name22] !== baseline[name22]) {
13444
+ changed.push(name22);
13445
+ }
13446
+ }
13447
+ for (const name22 of Object.keys(baseline)) {
13448
+ if (!Object.hasOwn(current, name22)) {
13449
+ removed.push(name22);
13450
+ }
13451
+ }
13452
+ return { added, removed, changed };
13453
+ }
13454
+
13400
13455
  // src/generate-video/generate-video.ts
13401
13456
  import {
13402
13457
  convertBase64ToUint8Array as convertBase64ToUint8Array5,
@@ -13434,13 +13489,14 @@ async function experimental_generateVideo({
13434
13489
  abortSignal
13435
13490
  });
13436
13491
  const { prompt, image } = normalizePrompt2(promptArg);
13437
- const normalizedFrameImages = frameImages == null ? void 0 : frameImages.map((frame) => ({
13438
- image: normalizeImageData(frame.image),
13439
- frameType: frame.frameType
13440
- }));
13441
- const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.map(
13442
- (reference) => normalizeImageData(reference)
13443
- );
13492
+ const normalizedFrameImages = frameImages == null ? void 0 : frameImages.flatMap((frame) => {
13493
+ const normalizedImage = normalizeImageData(frame.image);
13494
+ return normalizedImage != null ? [{ image: normalizedImage, frameType: frame.frameType }] : [];
13495
+ });
13496
+ const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.flatMap((reference) => {
13497
+ const normalized = normalizeReferenceData(reference);
13498
+ return normalized != null ? [normalized] : [];
13499
+ });
13444
13500
  const effectiveInputReferences = normalizedFrameImages != null && normalizedFrameImages.length > 0 ? void 0 : normalizedInputReferences;
13445
13501
  const warnings = [];
13446
13502
  if (normalizedFrameImages != null && normalizedFrameImages.length > 0 && normalizedInputReferences != null && normalizedInputReferences.length > 0) {
@@ -13594,8 +13650,11 @@ function normalizePrompt2(promptArg) {
13594
13650
  image: promptArg.image != null ? normalizeImageData(promptArg.image) : void 0
13595
13651
  };
13596
13652
  }
13597
- function normalizeImageData(dataContent) {
13598
- var _a22, _b;
13653
+ function detectFileMediaType(data, restrictToImages) {
13654
+ const detected = restrictToImages ? detectMediaType4({ data, topLevelType: "image" }) : detectMediaType4({ data });
13655
+ return detected != null ? detected : "image/png";
13656
+ }
13657
+ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
13599
13658
  if (typeof dataContent === "string") {
13600
13659
  if (dataContent.startsWith("http://") || dataContent.startsWith("https://")) {
13601
13660
  return {
@@ -13605,24 +13664,46 @@ function normalizeImageData(dataContent) {
13605
13664
  }
13606
13665
  if (dataContent.startsWith("data:")) {
13607
13666
  const { mediaType, base64Content } = splitDataUrl(dataContent);
13667
+ const data = convertBase64ToUint8Array5(base64Content != null ? base64Content : "");
13608
13668
  return {
13609
13669
  type: "file",
13610
- mediaType: mediaType != null ? mediaType : "image/png",
13611
- data: convertBase64ToUint8Array5(base64Content != null ? base64Content : "")
13670
+ mediaType: mediaType != null ? mediaType : detectFileMediaType(data, restrictToImages),
13671
+ data
13612
13672
  };
13613
13673
  }
13614
- const bytes2 = convertBase64ToUint8Array5(dataContent);
13674
+ const bytes = convertBase64ToUint8Array5(dataContent);
13675
+ return {
13676
+ type: "file",
13677
+ mediaType: detectFileMediaType(bytes, restrictToImages),
13678
+ data: bytes
13679
+ };
13680
+ }
13681
+ if (dataContent instanceof Uint8Array || dataContent instanceof ArrayBuffer) {
13682
+ const bytes = dataContent instanceof Uint8Array ? dataContent : new Uint8Array(dataContent);
13615
13683
  return {
13616
13684
  type: "file",
13617
- mediaType: (_a22 = detectMediaType4({ data: bytes2, topLevelType: "image" })) != null ? _a22 : "image/png",
13618
- data: bytes2
13685
+ mediaType: detectFileMediaType(bytes, restrictToImages),
13686
+ data: bytes
13619
13687
  };
13620
13688
  }
13621
- const bytes = convertDataContentToUint8Array(dataContent);
13689
+ return void 0;
13690
+ }
13691
+ function normalizeReferenceData(reference) {
13692
+ const isObjectForm = typeof reference === "object" && reference != null && !(reference instanceof Uint8Array) && !(reference instanceof ArrayBuffer) && "data" in reference;
13693
+ if (!isObjectForm) {
13694
+ return normalizeImageData(reference, {
13695
+ restrictToImages: false
13696
+ });
13697
+ }
13698
+ const normalized = normalizeImageData(reference.data, {
13699
+ restrictToImages: false
13700
+ });
13701
+ if (normalized == null) {
13702
+ return normalized;
13703
+ }
13622
13704
  return {
13623
- type: "file",
13624
- mediaType: (_b = detectMediaType4({ data: bytes, topLevelType: "image" })) != null ? _b : "image/png",
13625
- data: bytes
13705
+ ...normalized,
13706
+ ...reference.mediaType != null ? { mediaType: reference.mediaType } : {}
13626
13707
  };
13627
13708
  }
13628
13709
  async function invokeModelMaxVideosPerCall(model) {
@@ -14307,7 +14388,7 @@ function resampleAudio(input, inputRate, outputRate) {
14307
14388
 
14308
14389
  // src/realtime/get-realtime-tool-definitions.ts
14309
14390
  import {
14310
- asSchema as asSchema6
14391
+ asSchema as asSchema7
14311
14392
  } from "@ai-sdk/provider-utils";
14312
14393
  async function getRealtimeToolDefinitions({
14313
14394
  tools,
@@ -14329,7 +14410,7 @@ async function getRealtimeToolDefinitions({
14329
14410
  type: "function",
14330
14411
  name: name22,
14331
14412
  description,
14332
- parameters: await asSchema6(tool2.inputSchema).jsonSchema
14413
+ parameters: await asSchema7(tool2.inputSchema).jsonSchema
14333
14414
  });
14334
14415
  break;
14335
14416
  }
@@ -16985,7 +17066,7 @@ export {
16985
17066
  UnsupportedFunctionalityError,
16986
17067
  UnsupportedModelVersionError,
16987
17068
  addToolInputExamplesMiddleware,
16988
- asSchema7 as asSchema,
17069
+ asSchema8 as asSchema,
16989
17070
  assistantModelMessageSchema,
16990
17071
  callCompletionApi,
16991
17072
  consumeStream,
@@ -17005,6 +17086,7 @@ export {
17005
17086
  customProvider,
17006
17087
  defaultEmbeddingSettingsMiddleware,
17007
17088
  defaultSettingsMiddleware,
17089
+ detectToolDrift,
17008
17090
  dynamicTool,
17009
17091
  embed,
17010
17092
  embedMany,
@@ -17021,6 +17103,7 @@ export {
17021
17103
  experimental_transcribe,
17022
17104
  extractJsonMiddleware,
17023
17105
  extractReasoningMiddleware,
17106
+ fingerprintTools,
17024
17107
  gateway2 as gateway,
17025
17108
  generateId,
17026
17109
  generateImage,