@ai-sdk/provider-utils 5.0.0-beta.1 → 5.0.0-beta.11
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 +115 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -17
- 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/get-error-message.ts +1 -1
- 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.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
DEFAULT_MAX_DOWNLOAD_SIZE: () => DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
34
34
|
DelayedPromise: () => DelayedPromise,
|
|
35
35
|
DownloadError: () => DownloadError,
|
|
@@ -63,14 +63,18 @@ __export(src_exports, {
|
|
|
63
63
|
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
64
64
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
65
65
|
isAbortError: () => isAbortError,
|
|
66
|
+
isCustomReasoning: () => isCustomReasoning,
|
|
66
67
|
isNonNullable: () => isNonNullable,
|
|
67
68
|
isParsableJson: () => isParsableJson,
|
|
69
|
+
isProviderReference: () => isProviderReference,
|
|
68
70
|
isUrlSupported: () => isUrlSupported,
|
|
69
71
|
jsonSchema: () => jsonSchema,
|
|
70
72
|
lazySchema: () => lazySchema,
|
|
71
73
|
loadApiKey: () => loadApiKey,
|
|
72
74
|
loadOptionalSetting: () => loadOptionalSetting,
|
|
73
75
|
loadSetting: () => loadSetting,
|
|
76
|
+
mapReasoningToProviderBudget: () => mapReasoningToProviderBudget,
|
|
77
|
+
mapReasoningToProviderEffort: () => mapReasoningToProviderEffort,
|
|
74
78
|
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
75
79
|
normalizeHeaders: () => normalizeHeaders,
|
|
76
80
|
parseJSON: () => parseJSON,
|
|
@@ -82,6 +86,7 @@ __export(src_exports, {
|
|
|
82
86
|
readResponseWithSizeLimit: () => readResponseWithSizeLimit,
|
|
83
87
|
removeUndefinedEntries: () => removeUndefinedEntries,
|
|
84
88
|
resolve: () => resolve,
|
|
89
|
+
resolveProviderReference: () => resolveProviderReference,
|
|
85
90
|
safeParseJSON: () => safeParseJSON,
|
|
86
91
|
safeValidateTypes: () => safeValidateTypes,
|
|
87
92
|
stripFileExtension: () => stripFileExtension,
|
|
@@ -92,7 +97,7 @@ __export(src_exports, {
|
|
|
92
97
|
withoutTrailingSlash: () => withoutTrailingSlash,
|
|
93
98
|
zodSchema: () => zodSchema
|
|
94
99
|
});
|
|
95
|
-
module.exports = __toCommonJS(
|
|
100
|
+
module.exports = __toCommonJS(index_exports);
|
|
96
101
|
|
|
97
102
|
// src/combine-headers.ts
|
|
98
103
|
function combineHeaders(...headers) {
|
|
@@ -146,30 +151,25 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
146
151
|
// src/create-tool-name-mapping.ts
|
|
147
152
|
function createToolNameMapping({
|
|
148
153
|
tools = [],
|
|
149
|
-
providerToolNames
|
|
150
|
-
resolveProviderToolName
|
|
154
|
+
providerToolNames
|
|
151
155
|
}) {
|
|
152
|
-
var _a2;
|
|
153
156
|
const customToolNameToProviderToolName = {};
|
|
154
157
|
const providerToolNameToCustomToolName = {};
|
|
155
158
|
for (const tool2 of tools) {
|
|
156
|
-
if (tool2.type === "provider") {
|
|
157
|
-
const providerToolName =
|
|
158
|
-
if (providerToolName == null) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
159
|
+
if (tool2.type === "provider" && tool2.id in providerToolNames) {
|
|
160
|
+
const providerToolName = providerToolNames[tool2.id];
|
|
161
161
|
customToolNameToProviderToolName[tool2.name] = providerToolName;
|
|
162
162
|
providerToolNameToCustomToolName[providerToolName] = tool2.name;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
return {
|
|
166
166
|
toProviderToolName: (customToolName) => {
|
|
167
|
-
var
|
|
168
|
-
return (
|
|
167
|
+
var _a2;
|
|
168
|
+
return (_a2 = customToolNameToProviderToolName[customToolName]) != null ? _a2 : customToolName;
|
|
169
169
|
},
|
|
170
170
|
toCustomToolName: (providerToolName) => {
|
|
171
|
-
var
|
|
172
|
-
return (
|
|
171
|
+
var _a2;
|
|
172
|
+
return (_a2 = providerToolNameToCustomToolName[providerToolName]) != null ? _a2 : providerToolName;
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
175
|
}
|
|
@@ -395,10 +395,13 @@ function validateDownloadUrl(url) {
|
|
|
395
395
|
message: `Invalid URL: ${url}`
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
|
+
if (parsed.protocol === "data:") {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
398
401
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
399
402
|
throw new DownloadError({
|
|
400
403
|
url,
|
|
401
|
-
message: `URL scheme must be http or
|
|
404
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
402
405
|
});
|
|
403
406
|
}
|
|
404
407
|
const hostname = parsed.hostname;
|
|
@@ -551,7 +554,7 @@ function getErrorMessage(error) {
|
|
|
551
554
|
return error;
|
|
552
555
|
}
|
|
553
556
|
if (error instanceof Error) {
|
|
554
|
-
return error.
|
|
557
|
+
return error.toString();
|
|
555
558
|
}
|
|
556
559
|
return JSON.stringify(error);
|
|
557
560
|
}
|
|
@@ -675,7 +678,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
675
678
|
}
|
|
676
679
|
|
|
677
680
|
// src/version.ts
|
|
678
|
-
var VERSION = true ? "5.0.0-beta.
|
|
681
|
+
var VERSION = true ? "5.0.0-beta.11" : "0.0.0-test";
|
|
679
682
|
|
|
680
683
|
// src/get-from-api.ts
|
|
681
684
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -791,6 +794,11 @@ function isNonNullable(value) {
|
|
|
791
794
|
return value != null;
|
|
792
795
|
}
|
|
793
796
|
|
|
797
|
+
// src/is-provider-reference.ts
|
|
798
|
+
function isProviderReference(data) {
|
|
799
|
+
return typeof data === "object" && !(data instanceof Uint8Array) && !(data instanceof URL);
|
|
800
|
+
}
|
|
801
|
+
|
|
794
802
|
// src/is-url-supported.ts
|
|
795
803
|
function isUrlSupported({
|
|
796
804
|
mediaType,
|
|
@@ -840,6 +848,63 @@ function loadApiKey({
|
|
|
840
848
|
return apiKey;
|
|
841
849
|
}
|
|
842
850
|
|
|
851
|
+
// src/map-reasoning-to-provider.ts
|
|
852
|
+
function isCustomReasoning(reasoning) {
|
|
853
|
+
return reasoning !== void 0 && reasoning !== "provider-default";
|
|
854
|
+
}
|
|
855
|
+
function mapReasoningToProviderEffort({
|
|
856
|
+
reasoning,
|
|
857
|
+
effortMap,
|
|
858
|
+
warnings
|
|
859
|
+
}) {
|
|
860
|
+
const mapped = effortMap[reasoning];
|
|
861
|
+
if (mapped == null) {
|
|
862
|
+
warnings.push({
|
|
863
|
+
type: "unsupported",
|
|
864
|
+
feature: "reasoning",
|
|
865
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
866
|
+
});
|
|
867
|
+
return void 0;
|
|
868
|
+
}
|
|
869
|
+
if (mapped !== reasoning) {
|
|
870
|
+
warnings.push({
|
|
871
|
+
type: "compatibility",
|
|
872
|
+
feature: "reasoning",
|
|
873
|
+
details: `reasoning "${reasoning}" is not directly supported by this model. mapped to effort "${mapped}".`
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
return mapped;
|
|
877
|
+
}
|
|
878
|
+
var DEFAULT_REASONING_BUDGET_PERCENTAGES = {
|
|
879
|
+
minimal: 0.02,
|
|
880
|
+
low: 0.1,
|
|
881
|
+
medium: 0.3,
|
|
882
|
+
high: 0.6,
|
|
883
|
+
xhigh: 0.9
|
|
884
|
+
};
|
|
885
|
+
function mapReasoningToProviderBudget({
|
|
886
|
+
reasoning,
|
|
887
|
+
maxOutputTokens,
|
|
888
|
+
maxReasoningBudget,
|
|
889
|
+
minReasoningBudget = 1024,
|
|
890
|
+
budgetPercentages = DEFAULT_REASONING_BUDGET_PERCENTAGES,
|
|
891
|
+
warnings
|
|
892
|
+
}) {
|
|
893
|
+
const pct = budgetPercentages[reasoning];
|
|
894
|
+
if (pct == null) {
|
|
895
|
+
warnings.push({
|
|
896
|
+
type: "unsupported",
|
|
897
|
+
feature: "reasoning",
|
|
898
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
899
|
+
});
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
return Math.min(
|
|
903
|
+
maxReasoningBudget,
|
|
904
|
+
Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
|
|
843
908
|
// src/load-optional-setting.ts
|
|
844
909
|
function loadOptionalSetting({
|
|
845
910
|
settingValue,
|
|
@@ -1002,7 +1067,7 @@ function visit(def) {
|
|
|
1002
1067
|
}
|
|
1003
1068
|
|
|
1004
1069
|
// src/to-json-schema/zod3-to-json-schema/options.ts
|
|
1005
|
-
var ignoreOverride = Symbol(
|
|
1070
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
1006
1071
|
"Let zodToJsonSchema decide on which parser to use"
|
|
1007
1072
|
);
|
|
1008
1073
|
var defaultOptions = {
|
|
@@ -2180,7 +2245,7 @@ var zod3ToJsonSchema = (schema, options) => {
|
|
|
2180
2245
|
};
|
|
2181
2246
|
|
|
2182
2247
|
// src/schema.ts
|
|
2183
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
2248
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2184
2249
|
function lazySchema(createSchema) {
|
|
2185
2250
|
let schema;
|
|
2186
2251
|
return () => {
|
|
@@ -2596,6 +2661,22 @@ function removeUndefinedEntries(record) {
|
|
|
2596
2661
|
);
|
|
2597
2662
|
}
|
|
2598
2663
|
|
|
2664
|
+
// src/resolve-provider-reference.ts
|
|
2665
|
+
var import_provider12 = require("@ai-sdk/provider");
|
|
2666
|
+
function resolveProviderReference({
|
|
2667
|
+
reference,
|
|
2668
|
+
provider
|
|
2669
|
+
}) {
|
|
2670
|
+
const id = reference[provider];
|
|
2671
|
+
if (id != null) {
|
|
2672
|
+
return id;
|
|
2673
|
+
}
|
|
2674
|
+
throw new import_provider12.NoSuchProviderReferenceError({
|
|
2675
|
+
provider,
|
|
2676
|
+
reference
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2599
2680
|
// src/resolve.ts
|
|
2600
2681
|
async function resolve(value) {
|
|
2601
2682
|
if (typeof value === "function") {
|
|
@@ -2605,7 +2686,7 @@ async function resolve(value) {
|
|
|
2605
2686
|
}
|
|
2606
2687
|
|
|
2607
2688
|
// src/response-handler.ts
|
|
2608
|
-
var
|
|
2689
|
+
var import_provider13 = require("@ai-sdk/provider");
|
|
2609
2690
|
var createJsonErrorResponseHandler = ({
|
|
2610
2691
|
errorSchema,
|
|
2611
2692
|
errorToMessage,
|
|
@@ -2616,7 +2697,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2616
2697
|
if (responseBody.trim() === "") {
|
|
2617
2698
|
return {
|
|
2618
2699
|
responseHeaders,
|
|
2619
|
-
value: new
|
|
2700
|
+
value: new import_provider13.APICallError({
|
|
2620
2701
|
message: response.statusText,
|
|
2621
2702
|
url,
|
|
2622
2703
|
requestBodyValues,
|
|
@@ -2634,7 +2715,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2634
2715
|
});
|
|
2635
2716
|
return {
|
|
2636
2717
|
responseHeaders,
|
|
2637
|
-
value: new
|
|
2718
|
+
value: new import_provider13.APICallError({
|
|
2638
2719
|
message: errorToMessage(parsedError),
|
|
2639
2720
|
url,
|
|
2640
2721
|
requestBodyValues,
|
|
@@ -2648,7 +2729,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2648
2729
|
} catch (parseError) {
|
|
2649
2730
|
return {
|
|
2650
2731
|
responseHeaders,
|
|
2651
|
-
value: new
|
|
2732
|
+
value: new import_provider13.APICallError({
|
|
2652
2733
|
message: response.statusText,
|
|
2653
2734
|
url,
|
|
2654
2735
|
requestBodyValues,
|
|
@@ -2663,7 +2744,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2663
2744
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
2664
2745
|
const responseHeaders = extractResponseHeaders(response);
|
|
2665
2746
|
if (response.body == null) {
|
|
2666
|
-
throw new
|
|
2747
|
+
throw new import_provider13.EmptyResponseBodyError({});
|
|
2667
2748
|
}
|
|
2668
2749
|
return {
|
|
2669
2750
|
responseHeaders,
|
|
@@ -2681,7 +2762,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2681
2762
|
});
|
|
2682
2763
|
const responseHeaders = extractResponseHeaders(response);
|
|
2683
2764
|
if (!parsedResult.success) {
|
|
2684
|
-
throw new
|
|
2765
|
+
throw new import_provider13.APICallError({
|
|
2685
2766
|
message: "Invalid JSON response",
|
|
2686
2767
|
cause: parsedResult.error,
|
|
2687
2768
|
statusCode: response.status,
|
|
@@ -2700,7 +2781,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2700
2781
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
2701
2782
|
const responseHeaders = extractResponseHeaders(response);
|
|
2702
2783
|
if (!response.body) {
|
|
2703
|
-
throw new
|
|
2784
|
+
throw new import_provider13.APICallError({
|
|
2704
2785
|
message: "Response body is empty",
|
|
2705
2786
|
url,
|
|
2706
2787
|
requestBodyValues,
|
|
@@ -2716,7 +2797,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
2716
2797
|
value: new Uint8Array(buffer)
|
|
2717
2798
|
};
|
|
2718
2799
|
} catch (error) {
|
|
2719
|
-
throw new
|
|
2800
|
+
throw new import_provider13.APICallError({
|
|
2720
2801
|
message: "Failed to read response as array buffer",
|
|
2721
2802
|
url,
|
|
2722
2803
|
requestBodyValues,
|
|
@@ -2732,7 +2813,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
2732
2813
|
const responseBody = await response.text();
|
|
2733
2814
|
return {
|
|
2734
2815
|
responseHeaders,
|
|
2735
|
-
value: new
|
|
2816
|
+
value: new import_provider13.APICallError({
|
|
2736
2817
|
message: response.statusText,
|
|
2737
2818
|
url,
|
|
2738
2819
|
requestBodyValues,
|
|
@@ -2815,14 +2896,18 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2815
2896
|
getRuntimeEnvironmentUserAgent,
|
|
2816
2897
|
injectJsonInstructionIntoMessages,
|
|
2817
2898
|
isAbortError,
|
|
2899
|
+
isCustomReasoning,
|
|
2818
2900
|
isNonNullable,
|
|
2819
2901
|
isParsableJson,
|
|
2902
|
+
isProviderReference,
|
|
2820
2903
|
isUrlSupported,
|
|
2821
2904
|
jsonSchema,
|
|
2822
2905
|
lazySchema,
|
|
2823
2906
|
loadApiKey,
|
|
2824
2907
|
loadOptionalSetting,
|
|
2825
2908
|
loadSetting,
|
|
2909
|
+
mapReasoningToProviderBudget,
|
|
2910
|
+
mapReasoningToProviderEffort,
|
|
2826
2911
|
mediaTypeToExtension,
|
|
2827
2912
|
normalizeHeaders,
|
|
2828
2913
|
parseJSON,
|
|
@@ -2834,6 +2919,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2834
2919
|
readResponseWithSizeLimit,
|
|
2835
2920
|
removeUndefinedEntries,
|
|
2836
2921
|
resolve,
|
|
2922
|
+
resolveProviderReference,
|
|
2837
2923
|
safeParseJSON,
|
|
2838
2924
|
safeValidateTypes,
|
|
2839
2925
|
stripFileExtension,
|