ai 7.0.113 → 7.0.116

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 (83) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +6 -6
  3. package/dist/index.js +1010 -1289
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.js +231 -257
  6. package/dist/internal/index.js.map +1 -1
  7. package/docs/02-foundations/02-providers-and-models.mdx +3 -0
  8. package/docs/02-foundations/03-prompts.mdx +1 -1
  9. package/docs/02-foundations/04-tools.mdx +2 -2
  10. package/docs/02-foundations/06-provider-options.mdx +11 -11
  11. package/docs/02-getting-started/00-choosing-a-provider.mdx +4 -4
  12. package/docs/02-getting-started/02-nextjs-app-router.mdx +3 -3
  13. package/docs/02-getting-started/03-nextjs-pages-router.mdx +3 -3
  14. package/docs/02-getting-started/04-svelte.mdx +7 -7
  15. package/docs/02-getting-started/05-nuxt.mdx +7 -7
  16. package/docs/02-getting-started/06-nodejs.mdx +3 -3
  17. package/docs/02-getting-started/07-expo.mdx +3 -3
  18. package/docs/02-getting-started/08-tanstack-start.mdx +3 -3
  19. package/docs/02-getting-started/09-coding-agents.mdx +1 -1
  20. package/docs/03-agents/03-workflows.mdx +2 -2
  21. package/docs/03-agents/04-loop-control.mdx +1 -1
  22. package/docs/03-agents/05-configuring-call-options.mdx +4 -2
  23. package/docs/03-agents/06-memory.mdx +2 -2
  24. package/docs/03-agents/06-policy-tool-approvals.mdx +2 -2
  25. package/docs/03-agents/07-workflow-agent.mdx +11 -11
  26. package/docs/03-agents/08-terminal-ui.mdx +14 -10
  27. package/docs/03-ai-sdk-core/05-generating-text.mdx +2 -2
  28. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +6 -1
  29. package/docs/03-ai-sdk-core/17-mcp-apps.mdx +1 -1
  30. package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +1 -1
  31. package/docs/03-ai-sdk-core/26-reasoning.mdx +13 -12
  32. package/docs/03-ai-sdk-core/31-reranking.mdx +12 -10
  33. package/docs/03-ai-sdk-core/32-evaluation.mdx +1 -1
  34. package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -2
  35. package/docs/03-ai-sdk-core/37-speech.mdx +6 -6
  36. package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
  37. package/docs/03-ai-sdk-core/41-skill-uploads.mdx +1 -1
  38. package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
  39. package/docs/03-ai-sdk-core/45-provider-management.mdx +21 -21
  40. package/docs/03-ai-sdk-core/60-telemetry.mdx +1 -1
  41. package/docs/03-ai-sdk-core/65-devtools.mdx +3 -3
  42. package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +1 -1
  43. package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +97 -107
  44. package/docs/03-ai-sdk-harnesses/03-tools.mdx +1 -22
  45. package/docs/03-ai-sdk-harnesses/04-skills.mdx +0 -4
  46. package/docs/03-ai-sdk-harnesses/06-workflow-utilities.mdx +43 -9
  47. package/docs/03-ai-sdk-harnesses/07-ui.mdx +33 -30
  48. package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +8 -6
  49. package/docs/04-ai-sdk-ui/02-chatbot.mdx +3 -3
  50. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +3 -3
  51. package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +1 -1
  52. package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +5 -5
  53. package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +1 -1
  54. package/docs/05-ai-sdk-rsc/06-loading-state.mdx +1 -1
  55. package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +3 -3
  56. package/docs/06-advanced/11-secure-url-fetching.mdx +39 -0
  57. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +5 -3
  58. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -3
  59. package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +5 -5
  60. package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +1 -1
  61. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
  62. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +4 -2
  63. package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +1 -1
  64. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +1 -1
  65. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +4 -4
  66. package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +1 -1
  67. package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +1 -1
  68. package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +3 -3
  69. package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -1
  70. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +8 -8
  71. package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +13 -9
  72. package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +3 -3
  73. package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +2 -2
  74. package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +1 -1
  75. package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
  76. package/package.json +12 -12
  77. package/src/evaluate/evaluate.ts +1 -10
  78. package/src/generate-text/restricted-telemetry-dispatcher.ts +6 -58
  79. package/src/prompt/file-part-data.ts +9 -3
  80. package/src/prompt/standardize-prompt.ts +2 -0
  81. package/src/telemetry/create-telemetry-dispatcher.ts +58 -6
  82. package/src/telemetry/filter-included-context.ts +57 -2
  83. package/src/util/download/download.ts +2 -2
@@ -10,17 +10,16 @@ function asAsyncIterableStream(stream) {
10
10
  const reader = this.getReader();
11
11
  let finished = false;
12
12
  async function cleanup(cancelStream) {
13
- var _a12;
14
13
  if (finished) return;
15
14
  finished = true;
16
15
  try {
17
16
  if (cancelStream) {
18
- await ((_a12 = reader.cancel) == null ? void 0 : _a12.call(reader));
17
+ await reader.cancel?.();
19
18
  }
20
19
  } finally {
21
20
  try {
22
21
  reader.releaseLock();
23
- } catch (e) {
22
+ } catch {
24
23
  }
25
24
  }
26
25
  }
@@ -85,13 +84,13 @@ import {
85
84
  DownloadError,
86
85
  readResponseWithSizeLimit,
87
86
  DEFAULT_MAX_DOWNLOAD_SIZE,
88
- fetchWithValidatedRedirects,
87
+ fetchUntrustedUrl,
89
88
  withUserAgentSuffix,
90
89
  getRuntimeEnvironmentUserAgent
91
90
  } from "@ai-sdk/provider-utils";
92
91
 
93
92
  // src/version.ts
94
- var VERSION = true ? "7.0.113" : "0.0.0-test";
93
+ var VERSION = true ? "7.0.116" : "0.0.0-test";
95
94
 
96
95
  // src/util/download/download.ts
97
96
  var download = async ({
@@ -99,7 +98,6 @@ var download = async ({
99
98
  maxBytes,
100
99
  abortSignal
101
100
  }) => {
102
- var _a12;
103
101
  const urlText = url.toString();
104
102
  try {
105
103
  const headers = withUserAgentSuffix(
@@ -107,7 +105,7 @@ var download = async ({
107
105
  `ai-sdk/${VERSION}`,
108
106
  getRuntimeEnvironmentUserAgent()
109
107
  );
110
- const response = await fetchWithValidatedRedirects({
108
+ const response = await fetchUntrustedUrl({
111
109
  url: urlText,
112
110
  headers,
113
111
  abortSignal
@@ -123,11 +121,11 @@ var download = async ({
123
121
  const data = await readResponseWithSizeLimit({
124
122
  response,
125
123
  url: urlText,
126
- maxBytes: maxBytes != null ? maxBytes : DEFAULT_MAX_DOWNLOAD_SIZE
124
+ maxBytes: maxBytes ?? DEFAULT_MAX_DOWNLOAD_SIZE
127
125
  });
128
126
  return {
129
127
  data,
130
- mediaType: (_a12 = response.headers.get("content-type")) != null ? _a12 : void 0
128
+ mediaType: response.headers.get("content-type") ?? void 0
131
129
  };
132
130
  } catch (error) {
133
131
  if (DownloadError.isInstance(error)) {
@@ -214,7 +212,7 @@ function splitDataUrl(dataUrl) {
214
212
  mediaType: header.split(";")[0].split(":")[1],
215
213
  base64Content
216
214
  };
217
- } catch (e) {
215
+ } catch {
218
216
  return {
219
217
  mediaType: void 0,
220
218
  base64Content: void 0
@@ -228,7 +226,7 @@ function isTaggedFileData(value) {
228
226
  const type = value.type;
229
227
  return type === "data" || type === "url" || type === "reference" || type === "text";
230
228
  }
231
- function convertUrlToFilePartData(url) {
229
+ function convertUrlToFilePartData(url, originalUrl) {
232
230
  if (url.protocol === "data:") {
233
231
  const { mediaType, base64Content } = splitDataUrl(url.toString());
234
232
  if (mediaType == null || base64Content == null) {
@@ -239,7 +237,10 @@ function convertUrlToFilePartData(url) {
239
237
  }
240
238
  return { data: { type: "data", data: base64Content }, mediaType };
241
239
  }
242
- return { data: { type: "url", url }, mediaType: void 0 };
240
+ return {
241
+ data: { type: "url", url, ...originalUrl != null ? { originalUrl } : {} },
242
+ mediaType: void 0
243
+ };
243
244
  }
244
245
  function convertUrlStringToFilePartData(content) {
245
246
  const result = convertUrlToFilePartData(new URL(content));
@@ -281,7 +282,7 @@ function convertToLanguageModelV4FilePart(content) {
281
282
  }
282
283
  return convertInlineDataToFilePartData(content.data);
283
284
  case "url":
284
- return convertUrlToFilePartData(content.url);
285
+ return convertUrlToFilePartData(content.url, content.originalUrl);
285
286
  case "reference":
286
287
  return {
287
288
  data: { type: "reference", reference: content.reference },
@@ -300,7 +301,7 @@ function convertToLanguageModelV4FilePart(content) {
300
301
  if (typeof content === "string") {
301
302
  try {
302
303
  return convertUrlStringToFilePartData(content);
303
- } catch (e) {
304
+ } catch {
304
305
  return convertInlineDataToFilePartData(content);
305
306
  }
306
307
  }
@@ -445,7 +446,7 @@ async function convertToLanguageModelPrompt({
445
446
  }) {
446
447
  const downloadedAssets = await downloadAssets(
447
448
  prompt.messages,
448
- download2 != null ? download2 : createDefaultDownloadFunction(void 0, abortSignal),
449
+ download2 ?? createDefaultDownloadFunction(void 0, abortSignal),
449
450
  supportedUrls
450
451
  );
451
452
  const approvalIdToToolCallId = /* @__PURE__ */ new Map();
@@ -491,7 +492,7 @@ async function convertToLanguageModelPrompt({
491
492
  continue;
492
493
  }
493
494
  const lastCombinedMessage = combinedMessages.at(-1);
494
- if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
495
+ if (lastCombinedMessage?.role === "tool") {
495
496
  const lastContentPart = lastCombinedMessage.content.at(-1);
496
497
  if (lastContentPart != null && lastCombinedMessage.providerOptions != null) {
497
498
  lastContentPart.providerOptions = mergeObjects(
@@ -628,7 +629,7 @@ function convertToLanguageModelMessage({
628
629
  type: "file",
629
630
  data,
630
631
  filename: part.filename,
631
- mediaType: mediaType != null ? mediaType : part.mediaType,
632
+ mediaType: mediaType ?? part.mediaType,
632
633
  providerOptions
633
634
  };
634
635
  }
@@ -651,7 +652,7 @@ function convertToLanguageModelMessage({
651
652
  return {
652
653
  type: "reasoning-file",
653
654
  data,
654
- mediaType: mediaType != null ? mediaType : part.mediaType,
655
+ mediaType: mediaType ?? part.mediaType,
655
656
  providerOptions
656
657
  };
657
658
  }
@@ -741,14 +742,13 @@ function convertToLanguageModelMessage({
741
742
  }
742
743
  }
743
744
  function convertImagePartToFilePart(part) {
744
- var _a12;
745
745
  if (part.type !== "image") {
746
746
  return part;
747
747
  }
748
748
  return {
749
749
  type: "file",
750
750
  data: part.image,
751
- mediaType: (_a12 = part.mediaType) != null ? _a12 : "image",
751
+ mediaType: part.mediaType ?? "image",
752
752
  providerOptions: part.providerOptions
753
753
  };
754
754
  }
@@ -825,7 +825,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
825
825
  };
826
826
  }
827
827
  const { data: normalizedData, mediaType: dataUrlMediaType } = convertToLanguageModelV4FilePart(part.data);
828
- let mediaType = dataUrlMediaType != null ? dataUrlMediaType : part.mediaType;
828
+ let mediaType = dataUrlMediaType ?? part.mediaType;
829
829
  let data = normalizedData;
830
830
  if (data.type === "url") {
831
831
  const downloadedFile = downloadedAssets[data.url.toString()];
@@ -870,7 +870,6 @@ function mapToolResultOutput({
870
870
  return {
871
871
  type: "content",
872
872
  value: output.value.map((item) => {
873
- var _a12;
874
873
  switch (item.type) {
875
874
  case "file": {
876
875
  const convertedPart = convertPartToLanguageModelPart(
@@ -899,7 +898,7 @@ function mapToolResultOutput({
899
898
  };
900
899
  }
901
900
  case "file-url": {
902
- const mediaType = (_a12 = item.mediaType) != null ? _a12 : getMediaTypeFromUrl(item.url);
901
+ const mediaType = item.mediaType ?? getMediaTypeFromUrl(item.url);
903
902
  const url = new URL(item.url);
904
903
  let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
905
904
  if (!item.mediaType) {
@@ -1065,14 +1064,13 @@ var URL_EXTENSION_TO_MEDIA_TYPE = {
1065
1064
  ogg: "audio/ogg"
1066
1065
  };
1067
1066
  function getMediaTypeFromUrl(url, fallbackMediaType = "application/octet-stream") {
1068
- var _a12;
1069
1067
  try {
1070
1068
  const pathname = new URL(url).pathname;
1071
- const fileExtension = (_a12 = pathname.split(".").pop()) == null ? void 0 : _a12.toLowerCase();
1069
+ const fileExtension = pathname.split(".").pop()?.toLowerCase();
1072
1070
  if (fileExtension && Object.hasOwn(URL_EXTENSION_TO_MEDIA_TYPE, fileExtension)) {
1073
1071
  return URL_EXTENSION_TO_MEDIA_TYPE[fileExtension];
1074
1072
  }
1075
- } catch (e) {
1073
+ } catch {
1076
1074
  }
1077
1075
  return fallbackMediaType;
1078
1076
  }
@@ -1091,7 +1089,7 @@ async function createToolModelOutput({
1091
1089
  } else if (errorMode === "json") {
1092
1090
  return { type: "error-json", value: toJSONValue(output) };
1093
1091
  }
1094
- if (tool2 == null ? void 0 : tool2.toModelOutput) {
1092
+ if (tool2?.toModelOutput) {
1095
1093
  return await tool2.toModelOutput({ toolCallId, input, output });
1096
1094
  }
1097
1095
  return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
@@ -1804,7 +1802,7 @@ function prepareRetries({
1804
1802
  });
1805
1803
  }
1806
1804
  }
1807
- const maxRetriesResult = maxRetries != null ? maxRetries : defaultMaxRetries;
1805
+ const maxRetriesResult = maxRetries ?? defaultMaxRetries;
1808
1806
  return {
1809
1807
  maxRetries: maxRetriesResult,
1810
1808
  retry: retryWithExponentialBackoffRespectingRetryHeaders({
@@ -1854,39 +1852,38 @@ function createNullLanguageModelUsage() {
1854
1852
  };
1855
1853
  }
1856
1854
  function addLanguageModelUsage(usage1, usage2) {
1857
- var _a12, _b12, _c, _d, _e, _f, _g, _h, _i, _j;
1858
1855
  return {
1859
1856
  inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
1860
1857
  inputTokenDetails: {
1861
1858
  noCacheTokens: addTokenCounts(
1862
- (_a12 = usage1.inputTokenDetails) == null ? void 0 : _a12.noCacheTokens,
1863
- (_b12 = usage2.inputTokenDetails) == null ? void 0 : _b12.noCacheTokens
1859
+ usage1.inputTokenDetails?.noCacheTokens,
1860
+ usage2.inputTokenDetails?.noCacheTokens
1864
1861
  ),
1865
1862
  cacheReadTokens: addTokenCounts(
1866
- (_c = usage1.inputTokenDetails) == null ? void 0 : _c.cacheReadTokens,
1867
- (_d = usage2.inputTokenDetails) == null ? void 0 : _d.cacheReadTokens
1863
+ usage1.inputTokenDetails?.cacheReadTokens,
1864
+ usage2.inputTokenDetails?.cacheReadTokens
1868
1865
  ),
1869
1866
  cacheWriteTokens: addTokenCounts(
1870
- (_e = usage1.inputTokenDetails) == null ? void 0 : _e.cacheWriteTokens,
1871
- (_f = usage2.inputTokenDetails) == null ? void 0 : _f.cacheWriteTokens
1867
+ usage1.inputTokenDetails?.cacheWriteTokens,
1868
+ usage2.inputTokenDetails?.cacheWriteTokens
1872
1869
  )
1873
1870
  },
1874
1871
  outputTokens: addTokenCounts(usage1.outputTokens, usage2.outputTokens),
1875
1872
  outputTokenDetails: {
1876
1873
  textTokens: addTokenCounts(
1877
- (_g = usage1.outputTokenDetails) == null ? void 0 : _g.textTokens,
1878
- (_h = usage2.outputTokenDetails) == null ? void 0 : _h.textTokens
1874
+ usage1.outputTokenDetails?.textTokens,
1875
+ usage2.outputTokenDetails?.textTokens
1879
1876
  ),
1880
1877
  reasoningTokens: addTokenCounts(
1881
- (_i = usage1.outputTokenDetails) == null ? void 0 : _i.reasoningTokens,
1882
- (_j = usage2.outputTokenDetails) == null ? void 0 : _j.reasoningTokens
1878
+ usage1.outputTokenDetails?.reasoningTokens,
1879
+ usage2.outputTokenDetails?.reasoningTokens
1883
1880
  )
1884
1881
  },
1885
1882
  totalTokens: addTokenCounts(usage1.totalTokens, usage2.totalTokens)
1886
1883
  };
1887
1884
  }
1888
1885
  function addTokenCounts(tokenCount1, tokenCount2) {
1889
- return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
1886
+ return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 ?? 0) + (tokenCount2 ?? 0);
1890
1887
  }
1891
1888
 
1892
1889
  // src/model/resolve-model.ts
@@ -2488,8 +2485,7 @@ function resolveLanguageModel(model) {
2488
2485
  return asLanguageModelV4(model);
2489
2486
  }
2490
2487
  function getGlobalProvider() {
2491
- var _a12;
2492
- const provider = (_a12 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a12 : gateway;
2488
+ const provider = globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway;
2493
2489
  return asProviderV4(provider);
2494
2490
  }
2495
2491
 
@@ -2507,7 +2503,7 @@ function mergeCallbacks(...callbacks) {
2507
2503
  return async (event) => {
2508
2504
  await Promise.allSettled(
2509
2505
  callbacks.map(async (callback) => {
2510
- await (callback == null ? void 0 : callback(event));
2506
+ await callback?.(event);
2511
2507
  })
2512
2508
  );
2513
2509
  };
@@ -2516,13 +2512,56 @@ function mergeCallbacks(...callbacks) {
2516
2512
  // src/telemetry/create-telemetry-dispatcher.ts
2517
2513
  import { asArray as asArray3 } from "@ai-sdk/provider-utils";
2518
2514
 
2515
+ // src/telemetry/filter-included-context.ts
2516
+ function filterIncludedContext({
2517
+ context,
2518
+ includeContext
2519
+ }) {
2520
+ if (context == null) {
2521
+ return {};
2522
+ }
2523
+ return Object.fromEntries(
2524
+ Object.entries(context).filter(
2525
+ ([key]) => includeContext?.[key] === true
2526
+ )
2527
+ );
2528
+ }
2529
+ function filterToolsContext({
2530
+ toolsContext,
2531
+ includeToolsContext
2532
+ }) {
2533
+ if (includeToolsContext == null) {
2534
+ return {};
2535
+ }
2536
+ return Object.fromEntries(
2537
+ Object.entries(toolsContext).map(([toolName, toolContext]) => [
2538
+ toolName,
2539
+ filterToolContext({
2540
+ toolName,
2541
+ toolContext,
2542
+ includeToolsContext
2543
+ })
2544
+ ])
2545
+ );
2546
+ }
2547
+ function filterToolContext({
2548
+ toolName,
2549
+ toolContext,
2550
+ includeToolsContext
2551
+ }) {
2552
+ const includeToolContext = includeToolsContext?.[toolName];
2553
+ return filterIncludedContext({
2554
+ context: toolContext,
2555
+ includeContext: includeToolContext
2556
+ });
2557
+ }
2558
+
2519
2559
  // src/telemetry/tracing-channel.ts
2520
2560
  var AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
2521
2561
 
2522
2562
  // src/util/is-node-runtime.ts
2523
2563
  function isNodeRuntime() {
2524
- var _a12;
2525
- return typeof process !== "undefined" && ((_a12 = process.release) == null ? void 0 : _a12.name) === "node";
2564
+ return typeof process !== "undefined" && process.release?.name === "node";
2526
2565
  }
2527
2566
 
2528
2567
  // src/telemetry/tracing-channel-publisher.ts
@@ -2539,19 +2578,16 @@ async function loadDiagnosticsChannel() {
2539
2578
  return diagnosticsChannelPromise;
2540
2579
  }
2541
2580
  function loadBuiltinModule(id) {
2542
- var _a12;
2543
2581
  const processWithBuiltins = globalThis.process;
2544
2582
  try {
2545
- return (_a12 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a12.call(processWithBuiltins, id);
2546
- } catch (e) {
2583
+ return processWithBuiltins?.getBuiltinModule?.(id);
2584
+ } catch {
2547
2585
  return void 0;
2548
2586
  }
2549
2587
  }
2550
2588
  async function runWithTracingChannelSpan(message, execute) {
2551
- var _a12;
2552
2589
  const diagnosticsChannel = await loadDiagnosticsChannel();
2553
- const tracingChannel = (_a12 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a12.call(
2554
- diagnosticsChannel,
2590
+ const tracingChannel = diagnosticsChannel?.tracingChannel?.(
2555
2591
  AI_SDK_TELEMETRY_TRACING_CHANNEL
2556
2592
  );
2557
2593
  if (tracingChannel == null || tracingChannel.hasSubscribers === false) {
@@ -2584,7 +2620,7 @@ async function runWithTracingChannelSpan(message, execute) {
2584
2620
  };
2585
2621
  try {
2586
2622
  return await tracingChannel.tracePromise(tracedExecute, message);
2587
- } catch (e) {
2623
+ } catch {
2588
2624
  if (hasExecutionError) {
2589
2625
  throw executionError;
2590
2626
  }
@@ -2601,7 +2637,6 @@ function openTelemetryChannelSpanContext({
2601
2637
  message,
2602
2638
  completion
2603
2639
  }) {
2604
- var _a12;
2605
2640
  if (!isNodeRuntime()) {
2606
2641
  return void 0;
2607
2642
  }
@@ -2609,8 +2644,7 @@ function openTelemetryChannelSpanContext({
2609
2644
  "node:diagnostics_channel"
2610
2645
  );
2611
2646
  const asyncHooks = loadBuiltinModule("node:async_hooks");
2612
- const tracingChannel = (_a12 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a12.call(
2613
- diagnosticsChannel,
2647
+ const tracingChannel = diagnosticsChannel?.tracingChannel?.(
2614
2648
  AI_SDK_TELEMETRY_TRACING_CHANNEL
2615
2649
  );
2616
2650
  if (tracingChannel == null || tracingChannel.hasSubscribers === false || asyncHooks == null) {
@@ -2624,7 +2658,7 @@ function openTelemetryChannelSpanContext({
2624
2658
  const safePublish = (publish) => {
2625
2659
  try {
2626
2660
  publish();
2627
- } catch (e) {
2661
+ } catch {
2628
2662
  }
2629
2663
  };
2630
2664
  const publishAsyncEnd = ({
@@ -2661,36 +2695,59 @@ function openTelemetryChannelSpanContext({
2661
2695
 
2662
2696
  // src/telemetry/telemetry-registry.ts
2663
2697
  function getGlobalTelemetryIntegrations() {
2664
- var _a12;
2665
- return (_a12 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a12 : [];
2698
+ return globalThis.AI_SDK_TELEMETRY_INTEGRATIONS ?? [];
2666
2699
  }
2667
2700
 
2668
2701
  // src/telemetry/create-telemetry-dispatcher.ts
2669
- function augmentEvent(event, telemetry) {
2670
- return Object.assign(
2702
+ function augmentEvent(event, telemetry, filterContext = false) {
2703
+ const augmentedEvent = Object.assign(
2671
2704
  Object.create(Object.getPrototypeOf(event)),
2672
2705
  event,
2673
- telemetry
2706
+ {
2707
+ recordInputs: telemetry.recordInputs,
2708
+ recordOutputs: telemetry.recordOutputs,
2709
+ functionId: telemetry.functionId
2710
+ }
2674
2711
  );
2712
+ if (filterContext && event != null && typeof event === "object" && "runtimeContext" in event) {
2713
+ augmentedEvent.runtimeContext = filterIncludedContext({
2714
+ context: event.runtimeContext,
2715
+ includeContext: telemetry.includeRuntimeContext
2716
+ });
2717
+ }
2718
+ if (filterContext && event != null && typeof event === "object") {
2719
+ if ("toolsContext" in event) {
2720
+ augmentedEvent.toolsContext = filterToolsContext({
2721
+ toolsContext: event.toolsContext,
2722
+ includeToolsContext: telemetry.includeToolsContext
2723
+ });
2724
+ } else if ("toolContext" in event && event.toolContext != null && "toolCall" in event && event.toolCall != null && typeof event.toolCall === "object" && "toolName" in event.toolCall) {
2725
+ augmentedEvent.toolContext = filterToolContext({
2726
+ toolName: event.toolCall.toolName,
2727
+ toolContext: event.toolContext,
2728
+ includeToolsContext: telemetry.includeToolsContext
2729
+ });
2730
+ }
2731
+ }
2732
+ return augmentedEvent;
2675
2733
  }
2676
2734
  function createTelemetryDispatcher({
2677
2735
  telemetry
2678
2736
  }) {
2679
- if ((telemetry == null ? void 0 : telemetry.isEnabled) === false) {
2737
+ if (telemetry?.isEnabled === false) {
2680
2738
  return {};
2681
2739
  }
2682
- const localIntegrations = telemetry == null ? void 0 : telemetry.integrations;
2740
+ const localIntegrations = telemetry?.integrations;
2683
2741
  const integrations = localIntegrations != null ? asArray3(localIntegrations) : getGlobalTelemetryIntegrations();
2684
2742
  const telemetryMetadata = {
2685
- recordInputs: telemetry == null ? void 0 : telemetry.recordInputs,
2686
- recordOutputs: telemetry == null ? void 0 : telemetry.recordOutputs,
2687
- functionId: telemetry == null ? void 0 : telemetry.functionId
2743
+ recordInputs: telemetry?.recordInputs,
2744
+ recordOutputs: telemetry?.recordOutputs,
2745
+ functionId: telemetry?.functionId,
2746
+ includeRuntimeContext: telemetry?.includeRuntimeContext,
2747
+ includeToolsContext: telemetry?.includeToolsContext
2688
2748
  };
2689
2749
  const mergeTelemetryCallback = (key) => {
2690
- const integrationCallbacks = integrations.map((integration) => {
2691
- var _a12;
2692
- return (_a12 = integration[key]) == null ? void 0 : _a12.bind(integration);
2693
- }).filter(Boolean).map(
2750
+ const integrationCallbacks = integrations.map((integration) => integration[key]?.bind(integration)).filter(Boolean).map(
2694
2751
  (callback) => ((event) => callback(augmentEvent(event, telemetryMetadata)))
2695
2752
  );
2696
2753
  const mergedIntegrationCallback = mergeCallbacks(...integrationCallbacks);
@@ -2698,26 +2755,20 @@ function createTelemetryDispatcher({
2698
2755
  await mergedIntegrationCallback(event);
2699
2756
  };
2700
2757
  };
2701
- const executeLanguageModelCallWrappers = integrations.map((integration) => {
2702
- var _a12;
2703
- return (_a12 = integration.executeLanguageModelCall) == null ? void 0 : _a12.bind(integration);
2704
- }).filter(Boolean);
2705
- const executeToolWrappers = integrations.map((integration) => {
2706
- var _a12;
2707
- return (_a12 = integration.executeTool) == null ? void 0 : _a12.bind(integration);
2708
- }).filter(Boolean);
2758
+ const executeLanguageModelCallWrappers = integrations.map((integration) => integration.executeLanguageModelCall?.bind(integration)).filter(Boolean);
2759
+ const executeToolWrappers = integrations.map((integration) => integration.executeTool?.bind(integration)).filter(Boolean);
2709
2760
  return {
2710
2761
  runInTracingChannelSpan: async ({ type, event, execute }) => await runWithTracingChannelSpan(
2711
2762
  {
2712
2763
  type,
2713
- event: augmentEvent(event, telemetryMetadata)
2764
+ event: augmentEvent(event, telemetryMetadata, true)
2714
2765
  },
2715
2766
  execute
2716
2767
  ),
2717
2768
  startTracingChannelContext: ({ type, event, completion }) => openTelemetryChannelSpanContext({
2718
2769
  message: {
2719
2770
  type,
2720
- event: augmentEvent(event, telemetryMetadata)
2771
+ event: augmentEvent(event, telemetryMetadata, true)
2721
2772
  },
2722
2773
  completion
2723
2774
  }),
@@ -2792,21 +2843,6 @@ function createTelemetryDispatcher({
2792
2843
  };
2793
2844
  }
2794
2845
 
2795
- // src/telemetry/filter-included-context.ts
2796
- function filterIncludedContext({
2797
- context,
2798
- includeContext
2799
- }) {
2800
- if (context == null) {
2801
- return {};
2802
- }
2803
- return Object.fromEntries(
2804
- Object.entries(context).filter(
2805
- ([key]) => (includeContext == null ? void 0 : includeContext[key]) === true
2806
- )
2807
- );
2808
- }
2809
-
2810
2846
  // src/generate-text/reasoning.ts
2811
2847
  function asReasoningText(reasoningParts) {
2812
2848
  const reasoningText = reasoningParts.map((part) => "text" in part ? part.text : "").join("");
@@ -2943,35 +2979,6 @@ function restrictStepResult({
2943
2979
  providerMetadata: step.providerMetadata
2944
2980
  });
2945
2981
  }
2946
- function filterToolsContext({
2947
- toolsContext,
2948
- includeToolsContext
2949
- }) {
2950
- if (includeToolsContext == null) {
2951
- return {};
2952
- }
2953
- return Object.fromEntries(
2954
- Object.entries(toolsContext).map(([toolName, toolContext]) => [
2955
- toolName,
2956
- filterToolContext({
2957
- toolName,
2958
- toolContext,
2959
- includeToolsContext
2960
- })
2961
- ])
2962
- );
2963
- }
2964
- function filterToolContext({
2965
- toolName,
2966
- toolContext,
2967
- includeToolsContext
2968
- }) {
2969
- const includeToolContext = includeToolsContext == null ? void 0 : includeToolsContext[toolName];
2970
- return filterIncludedContext({
2971
- context: toolContext,
2972
- includeContext: includeToolContext
2973
- });
2974
- }
2975
2982
  function createRestrictedTelemetryDispatcher({
2976
2983
  telemetry,
2977
2984
  includeRuntimeContext,
@@ -2980,127 +2987,100 @@ function createRestrictedTelemetryDispatcher({
2980
2987
  const telemetryDispatcher = createTelemetryDispatcher({ telemetry });
2981
2988
  return {
2982
2989
  ...telemetryDispatcher,
2983
- onStart: (event) => {
2984
- var _a12;
2985
- return (_a12 = telemetryDispatcher.onStart) == null ? void 0 : _a12.call(telemetryDispatcher, {
2986
- ...event,
2987
- runtimeContext: filterIncludedContext({
2988
- context: event.runtimeContext,
2989
- includeContext: includeRuntimeContext
2990
- }),
2991
- toolsContext: filterToolsContext({
2992
- toolsContext: event.toolsContext,
2990
+ onStart: (event) => telemetryDispatcher.onStart?.({
2991
+ ...event,
2992
+ runtimeContext: filterIncludedContext({
2993
+ context: event.runtimeContext,
2994
+ includeContext: includeRuntimeContext
2995
+ }),
2996
+ toolsContext: filterToolsContext({
2997
+ toolsContext: event.toolsContext,
2998
+ includeToolsContext
2999
+ })
3000
+ }),
3001
+ onStepStart: (event) => telemetryDispatcher.onStepStart?.({
3002
+ ...event,
3003
+ runtimeContext: filterIncludedContext({
3004
+ context: event.runtimeContext,
3005
+ includeContext: includeRuntimeContext
3006
+ }),
3007
+ steps: event.steps.map(
3008
+ (step) => restrictStepResult({
3009
+ step,
3010
+ includeRuntimeContext,
2993
3011
  includeToolsContext
2994
3012
  })
2995
- });
2996
- },
2997
- onStepStart: (event) => {
2998
- var _a12;
2999
- return (_a12 = telemetryDispatcher.onStepStart) == null ? void 0 : _a12.call(telemetryDispatcher, {
3000
- ...event,
3001
- runtimeContext: filterIncludedContext({
3002
- context: event.runtimeContext,
3003
- includeContext: includeRuntimeContext
3004
- }),
3005
- steps: event.steps.map(
3006
- (step) => restrictStepResult({
3007
- step,
3008
- includeRuntimeContext,
3013
+ ),
3014
+ toolsContext: filterToolsContext({
3015
+ toolsContext: event.toolsContext,
3016
+ includeToolsContext
3017
+ })
3018
+ }),
3019
+ onStepEnd: (event) => telemetryDispatcher.onStepEnd?.(
3020
+ restrictStepResult({
3021
+ step: event,
3022
+ includeRuntimeContext,
3023
+ includeToolsContext
3024
+ })
3025
+ ),
3026
+ onStepFinish: (event) => telemetryDispatcher.onStepEnd?.(
3027
+ restrictStepResult({
3028
+ step: event,
3029
+ includeRuntimeContext,
3030
+ includeToolsContext
3031
+ })
3032
+ ),
3033
+ onEnd: (event) => telemetryDispatcher.onEnd?.(
3034
+ ((restrictedSteps) => {
3035
+ return {
3036
+ ...event,
3037
+ runtimeContext: filterIncludedContext({
3038
+ context: event.runtimeContext,
3039
+ includeContext: includeRuntimeContext
3040
+ }),
3041
+ steps: restrictedSteps,
3042
+ finalStep: restrictedSteps.at(-1),
3043
+ toolsContext: filterToolsContext({
3044
+ toolsContext: event.toolsContext,
3009
3045
  includeToolsContext
3010
3046
  })
3011
- ),
3012
- toolsContext: filterToolsContext({
3013
- toolsContext: event.toolsContext,
3014
- includeToolsContext
3015
- })
3016
- });
3017
- },
3018
- onStepEnd: (event) => {
3019
- var _a12;
3020
- return (_a12 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a12.call(
3021
- telemetryDispatcher,
3022
- restrictStepResult({
3023
- step: event,
3024
- includeRuntimeContext,
3025
- includeToolsContext
3026
- })
3027
- );
3028
- },
3029
- onStepFinish: (event) => {
3030
- var _a12;
3031
- return (_a12 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a12.call(
3032
- telemetryDispatcher,
3033
- restrictStepResult({
3034
- step: event,
3035
- includeRuntimeContext,
3036
- includeToolsContext
3037
- })
3038
- );
3039
- },
3040
- onEnd: (event) => {
3041
- var _a12;
3042
- return (_a12 = telemetryDispatcher.onEnd) == null ? void 0 : _a12.call(
3043
- telemetryDispatcher,
3044
- ((restrictedSteps) => {
3045
- return {
3046
- ...event,
3047
- runtimeContext: filterIncludedContext({
3048
- context: event.runtimeContext,
3049
- includeContext: includeRuntimeContext
3050
- }),
3051
- steps: restrictedSteps,
3052
- finalStep: restrictedSteps.at(-1),
3053
- toolsContext: filterToolsContext({
3054
- toolsContext: event.toolsContext,
3055
- includeToolsContext
3056
- })
3057
- };
3058
- })(
3059
- event.steps.map(
3060
- (step) => restrictStepResult({
3061
- step,
3062
- includeRuntimeContext,
3063
- includeToolsContext
3064
- })
3065
- )
3066
- )
3067
- );
3068
- },
3069
- onAbort: (event) => {
3070
- var _a12;
3071
- return (_a12 = telemetryDispatcher.onAbort) == null ? void 0 : _a12.call(telemetryDispatcher, {
3072
- ...event,
3073
- steps: event.steps.map(
3047
+ };
3048
+ })(
3049
+ event.steps.map(
3074
3050
  (step) => restrictStepResult({
3075
3051
  step,
3076
3052
  includeRuntimeContext,
3077
3053
  includeToolsContext
3078
3054
  })
3079
3055
  )
3080
- });
3081
- },
3082
- onToolExecutionStart: (event) => {
3083
- var _a12;
3084
- return (_a12 = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _a12.call(telemetryDispatcher, {
3085
- ...event,
3086
- toolContext: filterToolContext({
3087
- toolName: event.toolCall.toolName,
3088
- toolContext: event.toolContext,
3089
- includeToolsContext
3090
- })
3091
- });
3092
- },
3093
- onToolExecutionEnd: (event) => {
3094
- var _a12;
3095
- return (_a12 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _a12.call(telemetryDispatcher, {
3096
- ...event,
3097
- toolContext: filterToolContext({
3098
- toolName: event.toolCall.toolName,
3099
- toolContext: event.toolContext,
3056
+ )
3057
+ ),
3058
+ onAbort: (event) => telemetryDispatcher.onAbort?.({
3059
+ ...event,
3060
+ steps: event.steps.map(
3061
+ (step) => restrictStepResult({
3062
+ step,
3063
+ includeRuntimeContext,
3100
3064
  includeToolsContext
3101
3065
  })
3102
- });
3103
- }
3066
+ )
3067
+ }),
3068
+ onToolExecutionStart: (event) => telemetryDispatcher.onToolExecutionStart?.({
3069
+ ...event,
3070
+ toolContext: filterToolContext({
3071
+ toolName: event.toolCall.toolName,
3072
+ toolContext: event.toolContext,
3073
+ includeToolsContext
3074
+ })
3075
+ }),
3076
+ onToolExecutionEnd: (event) => telemetryDispatcher.onToolExecutionEnd?.({
3077
+ ...event,
3078
+ toolContext: filterToolContext({
3079
+ toolName: event.toolCall.toolName,
3080
+ toolContext: event.toolContext,
3081
+ includeToolsContext
3082
+ })
3083
+ })
3104
3084
  };
3105
3085
  }
3106
3086
 
@@ -3161,14 +3141,13 @@ async function parseToolCall({
3161
3141
  }
3162
3142
  let repairedToolCall = null;
3163
3143
  try {
3164
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
3144
+ abortSignal?.throwIfAborted();
3165
3145
  repairedToolCall = await waitForPromiseWithAbortSignal({
3166
3146
  promise: repairToolCall({
3167
3147
  toolCall,
3168
3148
  tools,
3169
3149
  inputSchema: async ({ toolName }) => {
3170
- var _a12;
3171
- const inputSchema = (_a12 = getOwn(tools, toolName)) == null ? void 0 : _a12.inputSchema;
3150
+ const inputSchema = getOwn(tools, toolName)?.inputSchema;
3172
3151
  return await asSchema2(inputSchema).jsonSchema;
3173
3152
  },
3174
3153
  instructions,
@@ -3180,7 +3159,7 @@ async function parseToolCall({
3180
3159
  abortSignal
3181
3160
  });
3182
3161
  } catch (repairError) {
3183
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
3162
+ abortSignal?.throwIfAborted();
3184
3163
  throw new ToolCallRepairError({
3185
3164
  cause: repairError,
3186
3165
  originalError: error
@@ -3193,11 +3172,11 @@ async function parseToolCall({
3193
3172
  toolCall: await doParseToolCall({ toolCall: repairedToolCall, tools }),
3194
3173
  refineToolInput
3195
3174
  });
3196
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
3175
+ abortSignal?.throwIfAborted();
3197
3176
  return parsedRepairedToolCall;
3198
3177
  }
3199
3178
  } catch (error) {
3200
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
3179
+ abortSignal?.throwIfAborted();
3201
3180
  const parsedInput = await safeParseJSON({ text: toolCall.input });
3202
3181
  const input = parsedInput.success ? parsedInput.value : toolCall.input;
3203
3182
  const tool2 = getOwn(tools, toolCall.toolName);
@@ -3209,10 +3188,10 @@ async function parseToolCall({
3209
3188
  dynamic: true,
3210
3189
  invalid: true,
3211
3190
  error,
3212
- title: tool2 == null ? void 0 : tool2.title,
3191
+ title: tool2?.title,
3213
3192
  providerExecuted: toolCall.providerExecuted,
3214
3193
  providerMetadata: toolCall.providerMetadata,
3215
- ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
3194
+ ...tool2?.metadata != null ? { toolMetadata: tool2.metadata } : {}
3216
3195
  };
3217
3196
  }
3218
3197
  }
@@ -3370,25 +3349,22 @@ function createToolSearchState({
3370
3349
  tools,
3371
3350
  toolCallers
3372
3351
  }) {
3373
- const searchTools = Object.entries(tools != null ? tools : {}).filter(
3352
+ const searchTools = Object.entries(tools ?? {}).filter(
3374
3353
  ([, tool2]) => tool2.deferLoading || isToolSearch(tool2)
3375
3354
  );
3376
3355
  if (searchTools.length === 0) {
3377
3356
  return (activeTools) => activeTools;
3378
3357
  }
3379
3358
  const discovered = /* @__PURE__ */ new Set();
3380
- const getCallers = (name12) => {
3381
- var _a12;
3382
- return (_a12 = getOwn(toolCallers, name12)) != null ? _a12 : [DIRECT_TOOL_CALL];
3383
- };
3359
+ const getCallers = (name12) => getOwn(toolCallers, name12) ?? [DIRECT_TOOL_CALL];
3384
3360
  for (const [name12, tool2] of searchTools) {
3385
3361
  const callers = getCallers(name12);
3386
3362
  if (callers.some((name13) => {
3387
3363
  if (name13 === DIRECT_TOOL_CALL) {
3388
3364
  return false;
3389
3365
  }
3390
- const caller = experimental_getToolCaller2(tools == null ? void 0 : tools[name13]);
3391
- return (caller == null ? void 0 : caller.type) !== "local" || caller.prepareModelMessage == null;
3366
+ const caller = experimental_getToolCaller2(tools?.[name13]);
3367
+ return caller?.type !== "local" || caller.prepareModelMessage == null;
3392
3368
  }) || isToolSearch(tool2) && tool2.deferLoading) {
3393
3369
  throw new InvalidArgumentError({
3394
3370
  parameter: "tools",
@@ -3427,7 +3403,7 @@ function createToolSearchState({
3427
3403
  experimental_sandbox
3428
3404
  });
3429
3405
  const nameTerms = tokenize(name12);
3430
- const descriptionTerms = tokenize(description != null ? description : "");
3406
+ const descriptionTerms = tokenize(description ?? "");
3431
3407
  const score = terms.reduce(
3432
3408
  (score2, term) => score2 + (nameTerms.includes(term) ? 2 : 0) + (descriptionTerms.includes(term) ? 1 : 0),
3433
3409
  0
@@ -3451,8 +3427,7 @@ function createToolSearchState({
3451
3427
  };
3452
3428
  }
3453
3429
  function tokenize(text) {
3454
- var _a12;
3455
- return (_a12 = text.replace(/([a-z\d])([A-Z])/g, "$1 $2").toLowerCase().match(/[\p{L}\p{N}]+/gu)) != null ? _a12 : [];
3430
+ return text.replace(/([a-z\d])([A-Z])/g, "$1 $2").toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
3456
3431
  }
3457
3432
 
3458
3433
  // src/generate-text/collect-tool-approvals.ts
@@ -3460,7 +3435,7 @@ function collectToolApprovals({
3460
3435
  messages
3461
3436
  }) {
3462
3437
  const lastMessage = messages.at(-1);
3463
- if ((lastMessage == null ? void 0 : lastMessage.role) != "tool") {
3438
+ if (lastMessage?.role != "tool") {
3464
3439
  return {
3465
3440
  approvedToolApprovals: [],
3466
3441
  deniedToolApprovals: []
@@ -3704,13 +3679,13 @@ async function resolveToolApproval({
3704
3679
  toolContext: await validateToolContext({
3705
3680
  toolName,
3706
3681
  context: getOwn(toolsContext, toolName),
3707
- contextSchema: tool2 == null ? void 0 : tool2.contextSchema
3682
+ contextSchema: tool2?.contextSchema
3708
3683
  }),
3709
3684
  runtimeContext
3710
3685
  }) : userDefinedToolApprovalStatus;
3711
3686
  return normalizeToolApprovalStatus(approvalStatus);
3712
3687
  }
3713
- if ((tool2 == null ? void 0 : tool2.needsApproval) == null) {
3688
+ if (tool2?.needsApproval == null) {
3714
3689
  return { type: "not-applicable" };
3715
3690
  }
3716
3691
  const needsApproval = typeof tool2.needsApproval === "function" ? await tool2.needsApproval(input, {
@@ -3719,7 +3694,7 @@ async function resolveToolApproval({
3719
3694
  context: await validateToolContext({
3720
3695
  toolName,
3721
3696
  context: getOwn(toolsContext, toolName),
3722
- contextSchema: tool2 == null ? void 0 : tool2.contextSchema
3697
+ contextSchema: tool2?.contextSchema
3723
3698
  })
3724
3699
  }) : tool2.needsApproval;
3725
3700
  return needsApproval ? { type: "user-approval" } : { type: "not-applicable" };
@@ -3739,7 +3714,6 @@ async function validateApprovedToolApprovals({
3739
3714
  toolApprovalSecret,
3740
3715
  refineToolInput
3741
3716
  }) {
3742
- var _a12;
3743
3717
  const approved = [];
3744
3718
  const denied = [];
3745
3719
  const invalid = [];
@@ -3826,7 +3800,7 @@ async function validateApprovedToolApprovals({
3826
3800
  approvalResponse: {
3827
3801
  ...approval.approvalResponse,
3828
3802
  approved: false,
3829
- reason: (_a12 = approvalStatus.reason) != null ? _a12 : approval.approvalResponse.reason
3803
+ reason: approvalStatus.reason ?? approval.approvalResponse.reason
3830
3804
  }
3831
3805
  });
3832
3806
  } else {