@ai-sdk/provider-utils 5.0.0-beta.1 → 5.0.0-beta.10

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/dist/index.mjs CHANGED
@@ -50,30 +50,25 @@ function convertAsyncIteratorToReadableStream(iterator) {
50
50
  // src/create-tool-name-mapping.ts
51
51
  function createToolNameMapping({
52
52
  tools = [],
53
- providerToolNames,
54
- resolveProviderToolName
53
+ providerToolNames
55
54
  }) {
56
- var _a2;
57
55
  const customToolNameToProviderToolName = {};
58
56
  const providerToolNameToCustomToolName = {};
59
57
  for (const tool2 of tools) {
60
- if (tool2.type === "provider") {
61
- const providerToolName = (_a2 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a2 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
62
- if (providerToolName == null) {
63
- continue;
64
- }
58
+ if (tool2.type === "provider" && tool2.id in providerToolNames) {
59
+ const providerToolName = providerToolNames[tool2.id];
65
60
  customToolNameToProviderToolName[tool2.name] = providerToolName;
66
61
  providerToolNameToCustomToolName[providerToolName] = tool2.name;
67
62
  }
68
63
  }
69
64
  return {
70
65
  toProviderToolName: (customToolName) => {
71
- var _a3;
72
- return (_a3 = customToolNameToProviderToolName[customToolName]) != null ? _a3 : customToolName;
66
+ var _a2;
67
+ return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
73
68
  },
74
69
  toCustomToolName: (providerToolName) => {
75
- var _a3;
76
- return (_a3 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3 : providerToolName;
70
+ var _a2;
71
+ return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
77
72
  }
78
73
  };
79
74
  }
@@ -299,10 +294,13 @@ function validateDownloadUrl(url) {
299
294
  message: `Invalid URL: ${url}`
300
295
  });
301
296
  }
297
+ if (parsed.protocol === "data:") {
298
+ return;
299
+ }
302
300
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
303
301
  throw new DownloadError({
304
302
  url,
305
- message: `URL scheme must be http or https, got ${parsed.protocol}`
303
+ message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
306
304
  });
307
305
  }
308
306
  const hostname = parsed.hostname;
@@ -579,7 +577,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
579
577
  }
580
578
 
581
579
  // src/version.ts
582
- var VERSION = true ? "5.0.0-beta.1" : "0.0.0-test";
580
+ var VERSION = true ? "5.0.0-beta.10" : "0.0.0-test";
583
581
 
584
582
  // src/get-from-api.ts
585
583
  var getOriginalFetch = () => globalThis.fetch;
@@ -695,6 +693,11 @@ function isNonNullable(value) {
695
693
  return value != null;
696
694
  }
697
695
 
696
+ // src/is-provider-reference.ts
697
+ function isProviderReference(data) {
698
+ return typeof data === "object" && !(data instanceof Uint8Array) && !(data instanceof URL);
699
+ }
700
+
698
701
  // src/is-url-supported.ts
699
702
  function isUrlSupported({
700
703
  mediaType,
@@ -744,6 +747,63 @@ function loadApiKey({
744
747
  return apiKey;
745
748
  }
746
749
 
750
+ // src/map-reasoning-to-provider.ts
751
+ function isCustomReasoning(reasoning) {
752
+ return reasoning !== void 0 && reasoning !== "provider-default";
753
+ }
754
+ function mapReasoningToProviderEffort({
755
+ reasoning,
756
+ effortMap,
757
+ warnings
758
+ }) {
759
+ const mapped = effortMap[reasoning];
760
+ if (mapped == null) {
761
+ warnings.push({
762
+ type: "unsupported",
763
+ feature: "reasoning",
764
+ details: `reasoning "${reasoning}" is not supported by this model.`
765
+ });
766
+ return void 0;
767
+ }
768
+ if (mapped !== reasoning) {
769
+ warnings.push({
770
+ type: "compatibility",
771
+ feature: "reasoning",
772
+ details: `reasoning "${reasoning}" is not directly supported by this model. mapped to effort "${mapped}".`
773
+ });
774
+ }
775
+ return mapped;
776
+ }
777
+ var DEFAULT_REASONING_BUDGET_PERCENTAGES = {
778
+ minimal: 0.02,
779
+ low: 0.1,
780
+ medium: 0.3,
781
+ high: 0.6,
782
+ xhigh: 0.9
783
+ };
784
+ function mapReasoningToProviderBudget({
785
+ reasoning,
786
+ maxOutputTokens,
787
+ maxReasoningBudget,
788
+ minReasoningBudget = 1024,
789
+ budgetPercentages = DEFAULT_REASONING_BUDGET_PERCENTAGES,
790
+ warnings
791
+ }) {
792
+ const pct = budgetPercentages[reasoning];
793
+ if (pct == null) {
794
+ warnings.push({
795
+ type: "unsupported",
796
+ feature: "reasoning",
797
+ details: `reasoning "${reasoning}" is not supported by this model.`
798
+ });
799
+ return void 0;
800
+ }
801
+ return Math.min(
802
+ maxReasoningBudget,
803
+ Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
804
+ );
805
+ }
806
+
747
807
  // src/load-optional-setting.ts
748
808
  function loadOptionalSetting({
749
809
  settingValue,
@@ -909,7 +969,7 @@ function visit(def) {
909
969
  }
910
970
 
911
971
  // src/to-json-schema/zod3-to-json-schema/options.ts
912
- var ignoreOverride = Symbol(
972
+ var ignoreOverride = /* @__PURE__ */ Symbol(
913
973
  "Let zodToJsonSchema decide on which parser to use"
914
974
  );
915
975
  var defaultOptions = {
@@ -2089,7 +2149,7 @@ var zod3ToJsonSchema = (schema, options) => {
2089
2149
  };
2090
2150
 
2091
2151
  // src/schema.ts
2092
- var schemaSymbol = Symbol.for("vercel.ai.schema");
2152
+ var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
2093
2153
  function lazySchema(createSchema) {
2094
2154
  let schema;
2095
2155
  return () => {
@@ -2507,6 +2567,24 @@ function removeUndefinedEntries(record) {
2507
2567
  );
2508
2568
  }
2509
2569
 
2570
+ // src/resolve-provider-reference.ts
2571
+ import {
2572
+ NoSuchProviderReferenceError
2573
+ } from "@ai-sdk/provider";
2574
+ function resolveProviderReference({
2575
+ reference,
2576
+ provider
2577
+ }) {
2578
+ const id = reference[provider];
2579
+ if (id != null) {
2580
+ return id;
2581
+ }
2582
+ throw new NoSuchProviderReferenceError({
2583
+ provider,
2584
+ reference
2585
+ });
2586
+ }
2587
+
2510
2588
  // src/resolve.ts
2511
2589
  async function resolve(value) {
2512
2590
  if (typeof value === "function") {
@@ -2727,14 +2805,18 @@ export {
2727
2805
  getRuntimeEnvironmentUserAgent,
2728
2806
  injectJsonInstructionIntoMessages,
2729
2807
  isAbortError,
2808
+ isCustomReasoning,
2730
2809
  isNonNullable,
2731
2810
  isParsableJson,
2811
+ isProviderReference,
2732
2812
  isUrlSupported,
2733
2813
  jsonSchema,
2734
2814
  lazySchema,
2735
2815
  loadApiKey,
2736
2816
  loadOptionalSetting,
2737
2817
  loadSetting,
2818
+ mapReasoningToProviderBudget,
2819
+ mapReasoningToProviderEffort,
2738
2820
  mediaTypeToExtension,
2739
2821
  normalizeHeaders,
2740
2822
  parseJSON,
@@ -2746,6 +2828,7 @@ export {
2746
2828
  readResponseWithSizeLimit,
2747
2829
  removeUndefinedEntries,
2748
2830
  resolve,
2831
+ resolveProviderReference,
2749
2832
  safeParseJSON,
2750
2833
  safeValidateTypes,
2751
2834
  stripFileExtension,