@ai-sdk/provider-utils 3.0.43 → 3.0.45
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 +15 -0
- package/dist/index.d.mts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +100 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.45
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 49c554d: Validate response-supplied Black Forest Labs polling and image URLs, including redirects, to block requests to private destinations outside the configured provider origin. Preserve self-hosted endpoints and withhold credentials from foreign origins and cross-origin redirects.
|
|
8
|
+
- b753c03: Reject HTTPS-to-HTTP redirects in validated downloads before requesting the insecure target, including when it matches a configured trusted origin.
|
|
9
|
+
|
|
10
|
+
## 3.0.44
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 0a069bd: fix(provider-utils): support cross-realm Uint8Array and ArrayBuffer in binary type guards and base64 conversion
|
|
15
|
+
- 0a069bd: fix(provider-utils): decode base64 into a preallocated Uint8Array to avoid ~25x transient memory and long event-loop blocking on large files
|
|
16
|
+
- 0a069bd: Add `stringifyWithBigIntAndCycles` for provider tool serialization that converts BigInt values to decimal strings and replaces ancestor cycles while preserving shared references and `toJSON` behavior.
|
|
17
|
+
|
|
3
18
|
## 3.0.43
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -113,6 +113,12 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
113
113
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
114
114
|
* SSRF guard.
|
|
115
115
|
*
|
|
116
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
117
|
+
* the target.
|
|
118
|
+
*
|
|
119
|
+
* All caller headers except User-Agent are dropped on cross-origin redirects.
|
|
120
|
+
* Callers must decide which credentials may be sent to the initial URL.
|
|
121
|
+
*
|
|
116
122
|
* A `redirect: 'manual'` request yields an unreadable opaque response in the
|
|
117
123
|
* browser (and in other spec-compliant fetch implementations), so the redirect
|
|
118
124
|
* target cannot be validated here. In a real browser this is safe to follow
|
|
@@ -347,13 +353,44 @@ declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T
|
|
|
347
353
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
348
354
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
349
355
|
|
|
350
|
-
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
356
|
+
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin, }: {
|
|
351
357
|
url: string;
|
|
352
358
|
headers?: Record<string, string | undefined>;
|
|
353
359
|
failedResponseHandler: ResponseHandler<Error>;
|
|
354
360
|
successfulResponseHandler: ResponseHandler<T>;
|
|
355
361
|
abortSignal?: AbortSignal;
|
|
356
362
|
fetch?: FetchFunction;
|
|
363
|
+
/**
|
|
364
|
+
* Set `true` when `url` is untrusted (e.g. taken from a provider response
|
|
365
|
+
* body): it is routed through {@link fetchWithValidatedRedirects}, which
|
|
366
|
+
* rejects private/loopback/link-local targets and re-validates redirect
|
|
367
|
+
* hops; blocked URLs throw `DownloadError`. Set `false` only for URLs built
|
|
368
|
+
* from a developer-configured endpoint.
|
|
369
|
+
*
|
|
370
|
+
* Optional for backwards compatibility with existing callers; omitting it
|
|
371
|
+
* behaves like `false` (no validation).
|
|
372
|
+
*/
|
|
373
|
+
validateUrl?: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* When set, `headers` are sent only if `url` is same-origin with this origin
|
|
376
|
+
* (the user-agent suffix is always kept). Pass the provider's configured
|
|
377
|
+
* base URL alongside `validateUrl: true` so credentials never ride a request
|
|
378
|
+
* to a response-supplied host on a different origin (e.g. a CDN). Redirects
|
|
379
|
+
* that later cross origin drop all caller headers regardless (see
|
|
380
|
+
* {@link fetchWithValidatedRedirects}).
|
|
381
|
+
*/
|
|
382
|
+
credentialedOrigin?: string;
|
|
383
|
+
/**
|
|
384
|
+
* A developer-configured origin (e.g. the provider's `baseURL`) that is
|
|
385
|
+
* exempt from URL validation when `validateUrl` is `true`. A response URL
|
|
386
|
+
* (or redirect hop) that is same-origin with it is fetched without target
|
|
387
|
+
* validation — it points at exactly the host a config-derived
|
|
388
|
+
* `validateUrl: false` request would fetch anyway, so blocking it would
|
|
389
|
+
* only break legitimate self-hosted / localhost deployments whose response
|
|
390
|
+
* URLs point back at the configured host. Hops on any other origin are
|
|
391
|
+
* still validated. Must never be derived from response data.
|
|
392
|
+
*/
|
|
393
|
+
trustedOrigin?: string;
|
|
357
394
|
}) => Promise<{
|
|
358
395
|
value: T;
|
|
359
396
|
rawValue?: unknown;
|
|
@@ -1058,6 +1095,8 @@ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = St
|
|
|
1058
1095
|
|
|
1059
1096
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1060
1097
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1098
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1099
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1061
1100
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1062
1101
|
|
|
1063
1102
|
/**
|
|
@@ -1204,4 +1243,13 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1204
1243
|
dynamic?: boolean;
|
|
1205
1244
|
}
|
|
1206
1245
|
|
|
1207
|
-
|
|
1246
|
+
/**
|
|
1247
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1248
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1249
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1250
|
+
*/
|
|
1251
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1252
|
+
|
|
1253
|
+
declare function secureJsonParse(text: string): any;
|
|
1254
|
+
|
|
1255
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, secureJsonParse, standardSchemaValidator, stringifyWithBigIntAndCycles, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,12 @@ declare function fetchWithValidatedEndpoint({ url, init, fetch: customFetch, tru
|
|
|
113
113
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
114
114
|
* SSRF guard.
|
|
115
115
|
*
|
|
116
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
117
|
+
* the target.
|
|
118
|
+
*
|
|
119
|
+
* All caller headers except User-Agent are dropped on cross-origin redirects.
|
|
120
|
+
* Callers must decide which credentials may be sent to the initial URL.
|
|
121
|
+
*
|
|
116
122
|
* A `redirect: 'manual'` request yields an unreadable opaque response in the
|
|
117
123
|
* browser (and in other spec-compliant fetch implementations), so the redirect
|
|
118
124
|
* target cannot be validated here. In a real browser this is safe to follow
|
|
@@ -347,13 +353,44 @@ declare const createJsonResponseHandler: <T>(responseSchema: FlexibleValidator<T
|
|
|
347
353
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
348
354
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
349
355
|
|
|
350
|
-
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
|
356
|
+
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin, }: {
|
|
351
357
|
url: string;
|
|
352
358
|
headers?: Record<string, string | undefined>;
|
|
353
359
|
failedResponseHandler: ResponseHandler<Error>;
|
|
354
360
|
successfulResponseHandler: ResponseHandler<T>;
|
|
355
361
|
abortSignal?: AbortSignal;
|
|
356
362
|
fetch?: FetchFunction;
|
|
363
|
+
/**
|
|
364
|
+
* Set `true` when `url` is untrusted (e.g. taken from a provider response
|
|
365
|
+
* body): it is routed through {@link fetchWithValidatedRedirects}, which
|
|
366
|
+
* rejects private/loopback/link-local targets and re-validates redirect
|
|
367
|
+
* hops; blocked URLs throw `DownloadError`. Set `false` only for URLs built
|
|
368
|
+
* from a developer-configured endpoint.
|
|
369
|
+
*
|
|
370
|
+
* Optional for backwards compatibility with existing callers; omitting it
|
|
371
|
+
* behaves like `false` (no validation).
|
|
372
|
+
*/
|
|
373
|
+
validateUrl?: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* When set, `headers` are sent only if `url` is same-origin with this origin
|
|
376
|
+
* (the user-agent suffix is always kept). Pass the provider's configured
|
|
377
|
+
* base URL alongside `validateUrl: true` so credentials never ride a request
|
|
378
|
+
* to a response-supplied host on a different origin (e.g. a CDN). Redirects
|
|
379
|
+
* that later cross origin drop all caller headers regardless (see
|
|
380
|
+
* {@link fetchWithValidatedRedirects}).
|
|
381
|
+
*/
|
|
382
|
+
credentialedOrigin?: string;
|
|
383
|
+
/**
|
|
384
|
+
* A developer-configured origin (e.g. the provider's `baseURL`) that is
|
|
385
|
+
* exempt from URL validation when `validateUrl` is `true`. A response URL
|
|
386
|
+
* (or redirect hop) that is same-origin with it is fetched without target
|
|
387
|
+
* validation — it points at exactly the host a config-derived
|
|
388
|
+
* `validateUrl: false` request would fetch anyway, so blocking it would
|
|
389
|
+
* only break legitimate self-hosted / localhost deployments whose response
|
|
390
|
+
* URLs point back at the configured host. Hops on any other origin are
|
|
391
|
+
* still validated. Must never be derived from response data.
|
|
392
|
+
*/
|
|
393
|
+
trustedOrigin?: string;
|
|
357
394
|
}) => Promise<{
|
|
358
395
|
value: T;
|
|
359
396
|
rawValue?: unknown;
|
|
@@ -1058,6 +1095,8 @@ declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = St
|
|
|
1058
1095
|
|
|
1059
1096
|
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
|
1060
1097
|
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
|
1098
|
+
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
1099
|
+
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
1061
1100
|
declare function convertToBase64(value: string | Uint8Array): string;
|
|
1062
1101
|
|
|
1063
1102
|
/**
|
|
@@ -1204,4 +1243,13 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1204
1243
|
dynamic?: boolean;
|
|
1205
1244
|
}
|
|
1206
1245
|
|
|
1207
|
-
|
|
1246
|
+
/**
|
|
1247
|
+
* Serializes a value as JSON, representing BigInt values as decimal strings and
|
|
1248
|
+
* ancestor cycles as "[Circular]". Reused objects, toJSON methods, and other JSON
|
|
1249
|
+
* serialization behavior are preserved. Getters and toJSON methods may throw.
|
|
1250
|
+
*/
|
|
1251
|
+
declare function stringifyWithBigIntAndCycles(value: unknown): string;
|
|
1252
|
+
|
|
1253
|
+
declare function secureJsonParse(text: string): any;
|
|
1254
|
+
|
|
1255
|
+
export { type AssistantContent, type AssistantModelMessage, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, encodePathSegment, executeTool, extractResponseHeaders, fetchWithValidatedEndpoint, fetchWithValidatedRedirects, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isArrayBuffer, isBrowserRuntime, isParsableJson, isSameOrigin, isUint8Array, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, secureJsonParse, standardSchemaValidator, stringifyWithBigIntAndCycles, tool, validateDownloadUrl, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -68,9 +68,11 @@ __export(index_exports, {
|
|
|
68
68
|
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
69
69
|
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
70
70
|
isAbortError: () => isAbortError,
|
|
71
|
+
isArrayBuffer: () => isArrayBuffer,
|
|
71
72
|
isBrowserRuntime: () => isBrowserRuntime,
|
|
72
73
|
isParsableJson: () => isParsableJson,
|
|
73
74
|
isSameOrigin: () => isSameOrigin,
|
|
75
|
+
isUint8Array: () => isUint8Array,
|
|
74
76
|
isUrlSupported: () => isUrlSupported,
|
|
75
77
|
isValidator: () => isValidator,
|
|
76
78
|
jsonSchema: () => jsonSchema,
|
|
@@ -92,7 +94,9 @@ __export(index_exports, {
|
|
|
92
94
|
resolve: () => resolve,
|
|
93
95
|
safeParseJSON: () => safeParseJSON,
|
|
94
96
|
safeValidateTypes: () => safeValidateTypes,
|
|
97
|
+
secureJsonParse: () => secureJsonParse,
|
|
95
98
|
standardSchemaValidator: () => standardSchemaValidator,
|
|
99
|
+
stringifyWithBigIntAndCycles: () => stringifyWithBigIntAndCycles,
|
|
96
100
|
tool: () => tool,
|
|
97
101
|
validateDownloadUrl: () => validateDownloadUrl,
|
|
98
102
|
validateTypes: () => validateTypes,
|
|
@@ -561,10 +565,12 @@ async function fetchWithValidatedRedirects({
|
|
|
561
565
|
trustedOrigin
|
|
562
566
|
}) {
|
|
563
567
|
var _a2;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
+
let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
|
|
569
|
+
const perHopInit = (redirect) => ({
|
|
570
|
+
signal: abortSignal,
|
|
571
|
+
redirect,
|
|
572
|
+
...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
|
|
573
|
+
});
|
|
568
574
|
let currentUrl = url;
|
|
569
575
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
570
576
|
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
|
|
@@ -572,10 +578,7 @@ async function fetchWithValidatedRedirects({
|
|
|
572
578
|
validateDownloadUrl(currentUrl);
|
|
573
579
|
}
|
|
574
580
|
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
575
|
-
const response = await fetch(currentUrl,
|
|
576
|
-
...baseInit,
|
|
577
|
-
redirect: "manual"
|
|
578
|
-
});
|
|
581
|
+
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
579
582
|
if (response.type === "opaqueredirect") {
|
|
580
583
|
if (!isBrowserRuntime()) {
|
|
581
584
|
throw new DownloadError({
|
|
@@ -583,12 +586,25 @@ async function fetchWithValidatedRedirects({
|
|
|
583
586
|
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
584
587
|
});
|
|
585
588
|
}
|
|
586
|
-
return await fetch(currentUrl,
|
|
589
|
+
return await fetch(currentUrl, perHopInit("follow"));
|
|
587
590
|
}
|
|
588
591
|
const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
|
|
589
592
|
if (response.status >= 300 && response.status < 400 && location) {
|
|
590
|
-
|
|
591
|
-
|
|
593
|
+
void cancelResponseBody(response);
|
|
594
|
+
const nextUrl = new URL(location, currentUrl).toString();
|
|
595
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") {
|
|
596
|
+
throw new DownloadError({
|
|
597
|
+
url,
|
|
598
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
602
|
+
const userAgent = currentHeaders.get("user-agent");
|
|
603
|
+
currentHeaders = new Headers(
|
|
604
|
+
userAgent == null ? void 0 : { "user-agent": userAgent }
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
currentUrl = nextUrl;
|
|
592
608
|
continue;
|
|
593
609
|
}
|
|
594
610
|
return response;
|
|
@@ -845,7 +861,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
845
861
|
}
|
|
846
862
|
|
|
847
863
|
// src/version.ts
|
|
848
|
-
var VERSION = true ? "3.0.
|
|
864
|
+
var VERSION = true ? "3.0.45" : "0.0.0-test";
|
|
849
865
|
|
|
850
866
|
// src/get-from-api.ts
|
|
851
867
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -855,16 +871,28 @@ var getFromApi = async ({
|
|
|
855
871
|
successfulResponseHandler,
|
|
856
872
|
failedResponseHandler,
|
|
857
873
|
abortSignal,
|
|
858
|
-
fetch
|
|
874
|
+
fetch,
|
|
875
|
+
validateUrl,
|
|
876
|
+
credentialedOrigin,
|
|
877
|
+
trustedOrigin
|
|
859
878
|
}) => {
|
|
860
879
|
try {
|
|
861
|
-
const
|
|
880
|
+
const requestFetch = fetch != null ? fetch : getOriginalFetch();
|
|
881
|
+
const outgoingHeaders = credentialedOrigin !== void 0 && !isSameOrigin(url, credentialedOrigin) ? {} : headers;
|
|
882
|
+
const requestHeaders = withUserAgentSuffix(
|
|
883
|
+
outgoingHeaders,
|
|
884
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
885
|
+
getRuntimeEnvironmentUserAgent()
|
|
886
|
+
);
|
|
887
|
+
const response = validateUrl ? await fetchWithValidatedRedirects({
|
|
888
|
+
url,
|
|
889
|
+
headers: requestHeaders,
|
|
890
|
+
abortSignal,
|
|
891
|
+
fetch,
|
|
892
|
+
trustedOrigin
|
|
893
|
+
}) : await requestFetch(url, {
|
|
862
894
|
method: "GET",
|
|
863
|
-
headers:
|
|
864
|
-
headers,
|
|
865
|
-
`ai-sdk/provider-utils/${VERSION}`,
|
|
866
|
-
getRuntimeEnvironmentUserAgent()
|
|
867
|
-
),
|
|
895
|
+
headers: requestHeaders,
|
|
868
896
|
signal: abortSignal
|
|
869
897
|
});
|
|
870
898
|
const responseHeaders = extractResponseHeaders(response);
|
|
@@ -3384,7 +3412,11 @@ var { btoa, atob } = globalThis;
|
|
|
3384
3412
|
function convertBase64ToUint8Array(base64String) {
|
|
3385
3413
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
3386
3414
|
const latin1string = atob(base64Url);
|
|
3387
|
-
|
|
3415
|
+
const bytes = new Uint8Array(latin1string.length);
|
|
3416
|
+
for (let i = 0; i < latin1string.length; i++) {
|
|
3417
|
+
bytes[i] = latin1string.charCodeAt(i);
|
|
3418
|
+
}
|
|
3419
|
+
return bytes;
|
|
3388
3420
|
}
|
|
3389
3421
|
function convertUint8ArrayToBase64(array) {
|
|
3390
3422
|
var _a2;
|
|
@@ -3402,8 +3434,30 @@ function convertUint8ArrayToBase64(array) {
|
|
|
3402
3434
|
}
|
|
3403
3435
|
return btoa(chunks.join(""));
|
|
3404
3436
|
}
|
|
3437
|
+
var typedArrayTag = Object.getOwnPropertyDescriptor(
|
|
3438
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
3439
|
+
Symbol.toStringTag
|
|
3440
|
+
).get;
|
|
3441
|
+
var arrayBufferByteLength = Object.getOwnPropertyDescriptor(
|
|
3442
|
+
ArrayBuffer.prototype,
|
|
3443
|
+
"byteLength"
|
|
3444
|
+
).get;
|
|
3445
|
+
function isUint8Array(value) {
|
|
3446
|
+
return ArrayBuffer.isView(value) && typedArrayTag.call(value) === "Uint8Array";
|
|
3447
|
+
}
|
|
3448
|
+
function isArrayBuffer(value) {
|
|
3449
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) {
|
|
3450
|
+
return false;
|
|
3451
|
+
}
|
|
3452
|
+
try {
|
|
3453
|
+
arrayBufferByteLength.call(value);
|
|
3454
|
+
return true;
|
|
3455
|
+
} catch (e) {
|
|
3456
|
+
return false;
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3405
3459
|
function convertToBase64(value) {
|
|
3406
|
-
return value
|
|
3460
|
+
return isUint8Array(value) ? convertUint8ArrayToBase64(value) : value;
|
|
3407
3461
|
}
|
|
3408
3462
|
|
|
3409
3463
|
// src/without-trailing-slash.ts
|
|
@@ -3438,6 +3492,27 @@ async function* executeTool({
|
|
|
3438
3492
|
// src/index.ts
|
|
3439
3493
|
__reExport(index_exports, require("@standard-schema/spec"), module.exports);
|
|
3440
3494
|
var import_stream2 = require("eventsource-parser/stream");
|
|
3495
|
+
|
|
3496
|
+
// src/stringify-with-bigint-and-cycles.ts
|
|
3497
|
+
function stringifyWithBigIntAndCycles(value) {
|
|
3498
|
+
const ancestors = [];
|
|
3499
|
+
return JSON.stringify(value, function(_key, value2) {
|
|
3500
|
+
if (typeof value2 === "bigint") {
|
|
3501
|
+
return value2.toString();
|
|
3502
|
+
}
|
|
3503
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
3504
|
+
return value2;
|
|
3505
|
+
}
|
|
3506
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
3507
|
+
ancestors.pop();
|
|
3508
|
+
}
|
|
3509
|
+
if (ancestors.includes(value2)) {
|
|
3510
|
+
return "[Circular]";
|
|
3511
|
+
}
|
|
3512
|
+
ancestors.push(value2);
|
|
3513
|
+
return value2;
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3441
3516
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3442
3517
|
0 && (module.exports = {
|
|
3443
3518
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
@@ -3477,9 +3552,11 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3477
3552
|
getRuntimeEnvironmentUserAgent,
|
|
3478
3553
|
injectJsonInstructionIntoMessages,
|
|
3479
3554
|
isAbortError,
|
|
3555
|
+
isArrayBuffer,
|
|
3480
3556
|
isBrowserRuntime,
|
|
3481
3557
|
isParsableJson,
|
|
3482
3558
|
isSameOrigin,
|
|
3559
|
+
isUint8Array,
|
|
3483
3560
|
isUrlSupported,
|
|
3484
3561
|
isValidator,
|
|
3485
3562
|
jsonSchema,
|
|
@@ -3501,7 +3578,9 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
3501
3578
|
resolve,
|
|
3502
3579
|
safeParseJSON,
|
|
3503
3580
|
safeValidateTypes,
|
|
3581
|
+
secureJsonParse,
|
|
3504
3582
|
standardSchemaValidator,
|
|
3583
|
+
stringifyWithBigIntAndCycles,
|
|
3505
3584
|
tool,
|
|
3506
3585
|
validateDownloadUrl,
|
|
3507
3586
|
validateTypes,
|