@ai-sdk/provider-utils 5.0.0-beta.0 → 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/CHANGELOG.md +150 -0
- package/dist/index.d.mts +276 -76
- package/dist/index.d.ts +276 -76
- package/dist/index.js +117 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -16
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.js +3 -3
- package/package.json +2 -4
- package/src/convert-image-model-file-to-data-uri.ts +3 -3
- package/src/create-tool-name-mapping.ts +5 -21
- package/src/download-blob.ts +5 -0
- package/src/index.ts +7 -0
- package/src/inject-json-instruction.ts +5 -5
- package/src/is-provider-reference.ts +18 -0
- package/src/map-reasoning-to-provider.ts +105 -0
- package/src/provider-tool-factory.ts +43 -32
- package/src/resolve-provider-reference.ts +27 -0
- package/src/types/assistant-model-message.ts +4 -0
- package/src/types/content-part.ts +90 -4
- package/src/types/context.ts +4 -0
- package/src/types/execute-tool.ts +24 -4
- package/src/types/index.ts +10 -9
- package/src/types/infer-tool-context.ts +7 -0
- package/src/types/infer-tool-input.ts +7 -0
- package/src/types/infer-tool-output.ts +7 -0
- package/src/types/infer-tool-set-context.ts +17 -0
- package/src/types/provider-options.ts +2 -2
- package/src/types/provider-reference.ts +10 -0
- package/src/types/tool-set.ts +22 -0
- package/src/types/tool.ts +57 -35
- package/src/types/union-to-intersection.ts +17 -0
- package/src/validate-download-url.ts +7 -2
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 =
|
|
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
|
|
72
|
-
return (
|
|
66
|
+
var _a2;
|
|
67
|
+
return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
|
|
73
68
|
},
|
|
74
69
|
toCustomToolName: (providerToolName) => {
|
|
75
|
-
var
|
|
76
|
-
return (
|
|
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
|
|
303
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
306
304
|
});
|
|
307
305
|
}
|
|
308
306
|
const hostname = parsed.hostname;
|
|
@@ -392,6 +390,9 @@ async function downloadBlob(url, options) {
|
|
|
392
390
|
const response = await fetch(url, {
|
|
393
391
|
signal: options == null ? void 0 : options.abortSignal
|
|
394
392
|
});
|
|
393
|
+
if (response.redirected) {
|
|
394
|
+
validateDownloadUrl(response.url);
|
|
395
|
+
}
|
|
395
396
|
if (!response.ok) {
|
|
396
397
|
throw new DownloadError({
|
|
397
398
|
url,
|
|
@@ -576,7 +577,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
576
577
|
}
|
|
577
578
|
|
|
578
579
|
// src/version.ts
|
|
579
|
-
var VERSION = true ? "5.0.0-beta.
|
|
580
|
+
var VERSION = true ? "5.0.0-beta.10" : "0.0.0-test";
|
|
580
581
|
|
|
581
582
|
// src/get-from-api.ts
|
|
582
583
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -692,6 +693,11 @@ function isNonNullable(value) {
|
|
|
692
693
|
return value != null;
|
|
693
694
|
}
|
|
694
695
|
|
|
696
|
+
// src/is-provider-reference.ts
|
|
697
|
+
function isProviderReference(data) {
|
|
698
|
+
return typeof data === "object" && !(data instanceof Uint8Array) && !(data instanceof URL);
|
|
699
|
+
}
|
|
700
|
+
|
|
695
701
|
// src/is-url-supported.ts
|
|
696
702
|
function isUrlSupported({
|
|
697
703
|
mediaType,
|
|
@@ -741,6 +747,63 @@ function loadApiKey({
|
|
|
741
747
|
return apiKey;
|
|
742
748
|
}
|
|
743
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
|
+
|
|
744
807
|
// src/load-optional-setting.ts
|
|
745
808
|
function loadOptionalSetting({
|
|
746
809
|
settingValue,
|
|
@@ -906,7 +969,7 @@ function visit(def) {
|
|
|
906
969
|
}
|
|
907
970
|
|
|
908
971
|
// src/to-json-schema/zod3-to-json-schema/options.ts
|
|
909
|
-
var ignoreOverride = Symbol(
|
|
972
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
910
973
|
"Let zodToJsonSchema decide on which parser to use"
|
|
911
974
|
);
|
|
912
975
|
var defaultOptions = {
|
|
@@ -2086,7 +2149,7 @@ var zod3ToJsonSchema = (schema, options) => {
|
|
|
2086
2149
|
};
|
|
2087
2150
|
|
|
2088
2151
|
// src/schema.ts
|
|
2089
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
2152
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2090
2153
|
function lazySchema(createSchema) {
|
|
2091
2154
|
let schema;
|
|
2092
2155
|
return () => {
|
|
@@ -2504,6 +2567,24 @@ function removeUndefinedEntries(record) {
|
|
|
2504
2567
|
);
|
|
2505
2568
|
}
|
|
2506
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
|
+
|
|
2507
2588
|
// src/resolve.ts
|
|
2508
2589
|
async function resolve(value) {
|
|
2509
2590
|
if (typeof value === "function") {
|
|
@@ -2724,14 +2805,18 @@ export {
|
|
|
2724
2805
|
getRuntimeEnvironmentUserAgent,
|
|
2725
2806
|
injectJsonInstructionIntoMessages,
|
|
2726
2807
|
isAbortError,
|
|
2808
|
+
isCustomReasoning,
|
|
2727
2809
|
isNonNullable,
|
|
2728
2810
|
isParsableJson,
|
|
2811
|
+
isProviderReference,
|
|
2729
2812
|
isUrlSupported,
|
|
2730
2813
|
jsonSchema,
|
|
2731
2814
|
lazySchema,
|
|
2732
2815
|
loadApiKey,
|
|
2733
2816
|
loadOptionalSetting,
|
|
2734
2817
|
loadSetting,
|
|
2818
|
+
mapReasoningToProviderBudget,
|
|
2819
|
+
mapReasoningToProviderEffort,
|
|
2735
2820
|
mediaTypeToExtension,
|
|
2736
2821
|
normalizeHeaders,
|
|
2737
2822
|
parseJSON,
|
|
@@ -2743,6 +2828,7 @@ export {
|
|
|
2743
2828
|
readResponseWithSizeLimit,
|
|
2744
2829
|
removeUndefinedEntries,
|
|
2745
2830
|
resolve,
|
|
2831
|
+
resolveProviderReference,
|
|
2746
2832
|
safeParseJSON,
|
|
2747
2833
|
safeValidateTypes,
|
|
2748
2834
|
stripFileExtension,
|