@ai-sdk/provider-utils 5.0.30 → 5.0.33
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 +24 -0
- package/dist/index.d.ts +50 -2
- package/dist/index.js +213 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/create-provider-stream-error.ts +53 -0
- package/src/embedding-model-capabilities.ts +9 -0
- package/src/handle-fetch-error.ts +44 -12
- package/src/index.ts +7 -0
- package/src/normalize-batch-request-counts.ts +42 -0
- package/src/response-handler.ts +145 -2
- package/src/types/tool-approval-request.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 90192f1: Mark transient network errors that occur while reading successful response bodies as retryable.
|
|
8
|
+
|
|
9
|
+
## 5.0.32
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3e125ba: Allow manual tool approval statuses to include a reason and preserve it across
|
|
14
|
+
core, model, and UI approval requests. OPA `requires-approval` decisions now
|
|
15
|
+
surface their reason to human approvers. UI request chunks serialize the
|
|
16
|
+
optional `reason`, while UI messages retain it as `approval.requestReason`
|
|
17
|
+
separately from an approver's response `reason`.
|
|
18
|
+
|
|
19
|
+
## 5.0.31
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- a9782e1: fix: align batch result parsing, request counts, and lifecycle behavior across providers
|
|
24
|
+
- 35841f5: feat: normalize mid-stream provider error events across supported providers into public StreamProviderError instances and preserve provider-owned type, code, status, retry, and raw payload metadata
|
|
25
|
+
- d2f3353: Split OpenAI and Azure OpenAI embedding requests by a conservative UTF-8 byte budget derived from their aggregate token limit, in addition to input count limits.
|
|
26
|
+
|
|
3
27
|
## 5.0.30
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4ResponseMetadata, LanguageModelV4Usage, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, JSONObject, LanguageModelV4FilePart, LanguageModelV4StreamPart, SharedV4ProviderMetadata, Experimental_TranscriptionModelV4StreamPart, TypeValidationContext } from '@ai-sdk/provider';
|
|
1
|
+
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4ResponseMetadata, LanguageModelV4Usage, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, APICallError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, Experimental_BatchV4Status, JSONObject, LanguageModelV4FilePart, LanguageModelV4StreamPart, SharedV4ProviderMetadata, Experimental_TranscriptionModelV4StreamPart, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
export { getErrorMessage } from '@ai-sdk/provider';
|
|
3
3
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
export * from '@standard-schema/spec';
|
|
@@ -730,6 +730,28 @@ declare function createToolNameMapping({ tools, providerToolNames, }: {
|
|
|
730
730
|
providerToolNames: Record<`${string}.${string}`, string>;
|
|
731
731
|
}): ToolNameMapping;
|
|
732
732
|
|
|
733
|
+
type ProviderStreamError = {
|
|
734
|
+
readonly message: string;
|
|
735
|
+
readonly type?: string;
|
|
736
|
+
readonly code?: string | number;
|
|
737
|
+
readonly statusCode?: number;
|
|
738
|
+
readonly isRetryable?: boolean;
|
|
739
|
+
readonly data: unknown;
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* Adds provider-owned status and retry metadata to a stream error payload
|
|
743
|
+
* without requiring provider packages to depend on AI SDK Core.
|
|
744
|
+
*/
|
|
745
|
+
declare function createProviderStreamError({ message, type, code, statusCode, isRetryable, data, }: {
|
|
746
|
+
message: string;
|
|
747
|
+
type?: string;
|
|
748
|
+
code?: string | number;
|
|
749
|
+
statusCode?: number;
|
|
750
|
+
isRetryable?: boolean;
|
|
751
|
+
data: unknown;
|
|
752
|
+
}): ProviderStreamError;
|
|
753
|
+
declare function isProviderStreamError(error: unknown): error is ProviderStreamError;
|
|
754
|
+
|
|
733
755
|
/**
|
|
734
756
|
* Creates a Promise that resolves after a specified delay
|
|
735
757
|
* @param delayInMs - The delay duration in milliseconds. If null or undefined, resolves immediately.
|
|
@@ -831,6 +853,14 @@ declare class DownloadError extends AISDKError {
|
|
|
831
853
|
static isInstance(error: unknown): error is DownloadError;
|
|
832
854
|
}
|
|
833
855
|
|
|
856
|
+
/**
|
|
857
|
+
* Symbol for exposing the UTF-8 input byte budget of an embedding model.
|
|
858
|
+
*
|
|
859
|
+
* This capability is experimental and intentionally lives outside the versioned
|
|
860
|
+
* embedding model specification.
|
|
861
|
+
*/
|
|
862
|
+
declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
863
|
+
|
|
834
864
|
/**
|
|
835
865
|
* Fetch function type (standardizes the version of fetch used).
|
|
836
866
|
*/
|
|
@@ -1091,6 +1121,7 @@ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage,
|
|
|
1091
1121
|
}) => ResponseHandler<APICallError>;
|
|
1092
1122
|
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
1093
1123
|
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
1124
|
+
declare const createJsonLinesResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<AsyncGenerator<T>>;
|
|
1094
1125
|
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
1095
1126
|
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
1096
1127
|
|
|
@@ -1325,6 +1356,19 @@ declare function mediaTypeToExtension(mediaType: string): string;
|
|
|
1325
1356
|
*/
|
|
1326
1357
|
declare function normalizeHeaders(headers: HeadersInit | Record<string, string | undefined> | Array<[string, string | undefined]> | undefined): Record<string, string>;
|
|
1327
1358
|
|
|
1359
|
+
/**
|
|
1360
|
+
* Normalizes complete batch request counts.
|
|
1361
|
+
*
|
|
1362
|
+
* Returns `undefined` when any count is missing, is not a non-negative safe
|
|
1363
|
+
* integer, or when the item counts do not add up to the total.
|
|
1364
|
+
*/
|
|
1365
|
+
declare function normalizeBatchRequestCounts({ total, pending, completed, failed, }: {
|
|
1366
|
+
total: number | null | undefined;
|
|
1367
|
+
pending: number | null | undefined;
|
|
1368
|
+
completed: number | null | undefined;
|
|
1369
|
+
failed: number | null | undefined;
|
|
1370
|
+
}): Experimental_BatchV4Status['requestCounts'] | undefined;
|
|
1371
|
+
|
|
1328
1372
|
/**
|
|
1329
1373
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
1330
1374
|
*/
|
|
@@ -1413,6 +1457,10 @@ type ToolApprovalRequest = {
|
|
|
1413
1457
|
* ID of the tool call that the approval request is for.
|
|
1414
1458
|
*/
|
|
1415
1459
|
toolCallId: string;
|
|
1460
|
+
/**
|
|
1461
|
+
* Reason why the tool call requires approval.
|
|
1462
|
+
*/
|
|
1463
|
+
reason?: string;
|
|
1416
1464
|
/**
|
|
1417
1465
|
* Flag indicating whether the tool was automatically approved or denied.
|
|
1418
1466
|
*
|
|
@@ -2671,4 +2719,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2671
2719
|
dynamic?: boolean;
|
|
2672
2720
|
}
|
|
2673
2721
|
|
|
2674
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, SerializationError, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
2722
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, SerializationError, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isProviderStreamError, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -323,6 +323,31 @@ function createToolNameMapping({
|
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
// src/create-provider-stream-error.ts
|
|
327
|
+
var marker = /* @__PURE__ */ Symbol.for("vercel.ai.providerStreamError");
|
|
328
|
+
function createProviderStreamError({
|
|
329
|
+
message,
|
|
330
|
+
type,
|
|
331
|
+
code,
|
|
332
|
+
statusCode,
|
|
333
|
+
isRetryable,
|
|
334
|
+
data
|
|
335
|
+
}) {
|
|
336
|
+
const error = {
|
|
337
|
+
message,
|
|
338
|
+
type,
|
|
339
|
+
code,
|
|
340
|
+
statusCode,
|
|
341
|
+
isRetryable,
|
|
342
|
+
data
|
|
343
|
+
};
|
|
344
|
+
Object.defineProperty(error, marker, { value: true });
|
|
345
|
+
return error;
|
|
346
|
+
}
|
|
347
|
+
function isProviderStreamError(error) {
|
|
348
|
+
return typeof error === "object" && error != null && error[marker] === true;
|
|
349
|
+
}
|
|
350
|
+
|
|
326
351
|
// src/delayed-promise.ts
|
|
327
352
|
var DelayedPromise = class {
|
|
328
353
|
constructor() {
|
|
@@ -681,8 +706,8 @@ async function cancelResponseBody(response) {
|
|
|
681
706
|
// src/download-error.ts
|
|
682
707
|
import { AISDKError } from "@ai-sdk/provider";
|
|
683
708
|
var name = "AI_DownloadError";
|
|
684
|
-
var
|
|
685
|
-
var symbol = Symbol.for(
|
|
709
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
710
|
+
var symbol = Symbol.for(marker2);
|
|
686
711
|
var _a, _b;
|
|
687
712
|
var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
688
713
|
constructor({
|
|
@@ -699,7 +724,7 @@ var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
|
699
724
|
this.statusText = statusText;
|
|
700
725
|
}
|
|
701
726
|
static isInstance(error) {
|
|
702
|
-
return AISDKError.hasMarker(error,
|
|
727
|
+
return AISDKError.hasMarker(error, marker2);
|
|
703
728
|
}
|
|
704
729
|
};
|
|
705
730
|
|
|
@@ -1154,6 +1179,11 @@ async function downloadBlob(url, options) {
|
|
|
1154
1179
|
}
|
|
1155
1180
|
}
|
|
1156
1181
|
|
|
1182
|
+
// src/embedding-model-capabilities.ts
|
|
1183
|
+
var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL = /* @__PURE__ */ Symbol.for(
|
|
1184
|
+
"vercel.ai.embeddingModel.maxInputBytesPerCall"
|
|
1185
|
+
);
|
|
1186
|
+
|
|
1157
1187
|
// src/extract-lines.ts
|
|
1158
1188
|
function extractLines({
|
|
1159
1189
|
text,
|
|
@@ -1224,24 +1254,31 @@ function isAbortError(error) {
|
|
|
1224
1254
|
|
|
1225
1255
|
// src/handle-fetch-error.ts
|
|
1226
1256
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
1227
|
-
var
|
|
1257
|
+
var RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
1228
1258
|
"ConnectionRefused",
|
|
1229
1259
|
"ConnectionClosed",
|
|
1230
1260
|
"FailedToOpenSocket",
|
|
1231
1261
|
"ECONNRESET",
|
|
1232
1262
|
"ECONNREFUSED",
|
|
1233
1263
|
"ETIMEDOUT",
|
|
1234
|
-
"EPIPE"
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1264
|
+
"EPIPE",
|
|
1265
|
+
"UND_ERR_SOCKET",
|
|
1266
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
1267
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
1268
|
+
"UND_ERR_CONNECT_TIMEOUT"
|
|
1269
|
+
]);
|
|
1270
|
+
function findNetworkError(error) {
|
|
1271
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1272
|
+
let current = error;
|
|
1273
|
+
while (current instanceof Error && !visited.has(current)) {
|
|
1274
|
+
visited.add(current);
|
|
1275
|
+
const errorWithCode = current;
|
|
1276
|
+
if (typeof errorWithCode.code === "string" && RETRYABLE_NETWORK_ERROR_CODES.has(errorWithCode.code)) {
|
|
1277
|
+
return errorWithCode;
|
|
1278
|
+
}
|
|
1279
|
+
current = current.cause;
|
|
1243
1280
|
}
|
|
1244
|
-
return
|
|
1281
|
+
return void 0;
|
|
1245
1282
|
}
|
|
1246
1283
|
function handleFetchError({
|
|
1247
1284
|
error,
|
|
@@ -1264,9 +1301,23 @@ function handleFetchError({
|
|
|
1264
1301
|
});
|
|
1265
1302
|
}
|
|
1266
1303
|
}
|
|
1267
|
-
|
|
1304
|
+
const networkError = findNetworkError(error);
|
|
1305
|
+
if (networkError != null) {
|
|
1306
|
+
if (APICallError.isInstance(error)) {
|
|
1307
|
+
return new APICallError({
|
|
1308
|
+
message: error.message,
|
|
1309
|
+
cause: error.cause,
|
|
1310
|
+
url: error.url,
|
|
1311
|
+
requestBodyValues: error.requestBodyValues,
|
|
1312
|
+
statusCode: error.statusCode,
|
|
1313
|
+
responseHeaders: error.responseHeaders,
|
|
1314
|
+
responseBody: error.responseBody,
|
|
1315
|
+
data: error.data,
|
|
1316
|
+
isRetryable: true
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1268
1319
|
return new APICallError({
|
|
1269
|
-
message: `Cannot connect to API: ${error.message}`,
|
|
1320
|
+
message: `Cannot connect to API: ${error instanceof Error ? error.message : networkError.message}`,
|
|
1270
1321
|
cause: error,
|
|
1271
1322
|
url,
|
|
1272
1323
|
requestBodyValues,
|
|
@@ -1329,7 +1380,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1329
1380
|
}
|
|
1330
1381
|
|
|
1331
1382
|
// src/version.ts
|
|
1332
|
-
var VERSION = true ? "5.0.
|
|
1383
|
+
var VERSION = true ? "5.0.33" : "0.0.0-test";
|
|
1333
1384
|
|
|
1334
1385
|
// src/get-from-api.ts
|
|
1335
1386
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1666,6 +1717,27 @@ function mediaTypeToExtension(mediaType) {
|
|
|
1666
1717
|
}[subtype]) != null ? _a3 : subtype;
|
|
1667
1718
|
}
|
|
1668
1719
|
|
|
1720
|
+
// src/normalize-batch-request-counts.ts
|
|
1721
|
+
function normalizeBatchRequestCounts({
|
|
1722
|
+
total,
|
|
1723
|
+
pending,
|
|
1724
|
+
completed,
|
|
1725
|
+
failed
|
|
1726
|
+
}) {
|
|
1727
|
+
if (isNonNegativeSafeInteger(total) && isNonNegativeSafeInteger(pending) && isNonNegativeSafeInteger(completed) && isNonNegativeSafeInteger(failed) && pending + completed + failed === total) {
|
|
1728
|
+
return {
|
|
1729
|
+
total,
|
|
1730
|
+
pending,
|
|
1731
|
+
completed,
|
|
1732
|
+
failed
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
return void 0;
|
|
1736
|
+
}
|
|
1737
|
+
function isNonNegativeSafeInteger(value) {
|
|
1738
|
+
return value != null && Number.isSafeInteger(value) && value >= 0;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1669
1741
|
// src/parse-json.ts
|
|
1670
1742
|
import {
|
|
1671
1743
|
JSONParseError,
|
|
@@ -3528,6 +3600,62 @@ async function retryWithExponentialBackoffInternal(f, {
|
|
|
3528
3600
|
// src/response-handler.ts
|
|
3529
3601
|
import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
3530
3602
|
var textDecoder2 = new TextDecoder();
|
|
3603
|
+
function wrapResponseBodyStream({
|
|
3604
|
+
stream,
|
|
3605
|
+
url,
|
|
3606
|
+
requestBodyValues,
|
|
3607
|
+
statusCode,
|
|
3608
|
+
responseHeaders
|
|
3609
|
+
}) {
|
|
3610
|
+
const reader = stream.getReader();
|
|
3611
|
+
let readerReleased = false;
|
|
3612
|
+
const releaseReader = () => {
|
|
3613
|
+
if (!readerReleased) {
|
|
3614
|
+
reader.releaseLock();
|
|
3615
|
+
readerReleased = true;
|
|
3616
|
+
}
|
|
3617
|
+
};
|
|
3618
|
+
return new ReadableStream({
|
|
3619
|
+
async pull(controller) {
|
|
3620
|
+
try {
|
|
3621
|
+
const { done, value } = await reader.read();
|
|
3622
|
+
if (done) {
|
|
3623
|
+
releaseReader();
|
|
3624
|
+
controller.close();
|
|
3625
|
+
} else {
|
|
3626
|
+
controller.enqueue(value);
|
|
3627
|
+
}
|
|
3628
|
+
} catch (error) {
|
|
3629
|
+
releaseReader();
|
|
3630
|
+
if (isAbortError(error)) {
|
|
3631
|
+
controller.error(error);
|
|
3632
|
+
return;
|
|
3633
|
+
}
|
|
3634
|
+
controller.error(
|
|
3635
|
+
handleFetchError({
|
|
3636
|
+
error: new APICallError4({
|
|
3637
|
+
message: "Failed to process successful response",
|
|
3638
|
+
cause: error,
|
|
3639
|
+
statusCode,
|
|
3640
|
+
url,
|
|
3641
|
+
responseHeaders,
|
|
3642
|
+
requestBodyValues
|
|
3643
|
+
}),
|
|
3644
|
+
url,
|
|
3645
|
+
requestBodyValues
|
|
3646
|
+
})
|
|
3647
|
+
);
|
|
3648
|
+
}
|
|
3649
|
+
},
|
|
3650
|
+
async cancel(reason) {
|
|
3651
|
+
try {
|
|
3652
|
+
await reader.cancel(reason);
|
|
3653
|
+
} finally {
|
|
3654
|
+
releaseReader();
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
});
|
|
3658
|
+
}
|
|
3531
3659
|
async function readResponseBodyAsText({
|
|
3532
3660
|
response,
|
|
3533
3661
|
url
|
|
@@ -3593,7 +3721,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
3593
3721
|
};
|
|
3594
3722
|
}
|
|
3595
3723
|
};
|
|
3596
|
-
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
3724
|
+
var createEventSourceResponseHandler = (chunkSchema) => async ({ response, url, requestBodyValues }) => {
|
|
3597
3725
|
const responseHeaders = extractResponseHeaders(response);
|
|
3598
3726
|
if (response.body == null) {
|
|
3599
3727
|
throw new EmptyResponseBodyError({});
|
|
@@ -3601,7 +3729,13 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
|
|
|
3601
3729
|
return {
|
|
3602
3730
|
responseHeaders,
|
|
3603
3731
|
value: parseJsonEventStream({
|
|
3604
|
-
stream:
|
|
3732
|
+
stream: wrapResponseBodyStream({
|
|
3733
|
+
stream: response.body,
|
|
3734
|
+
url,
|
|
3735
|
+
requestBodyValues,
|
|
3736
|
+
statusCode: response.status,
|
|
3737
|
+
responseHeaders
|
|
3738
|
+
}),
|
|
3605
3739
|
schema: chunkSchema
|
|
3606
3740
|
})
|
|
3607
3741
|
};
|
|
@@ -3630,6 +3764,58 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
3630
3764
|
rawValue: parsedResult.rawValue
|
|
3631
3765
|
};
|
|
3632
3766
|
};
|
|
3767
|
+
var createJsonLinesResponseHandler = (responseSchema) => async ({ response }) => {
|
|
3768
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
3769
|
+
if (response.body == null) {
|
|
3770
|
+
throw new EmptyResponseBodyError({});
|
|
3771
|
+
}
|
|
3772
|
+
return {
|
|
3773
|
+
responseHeaders,
|
|
3774
|
+
value: parseJsonLines({
|
|
3775
|
+
stream: response.body,
|
|
3776
|
+
schema: responseSchema
|
|
3777
|
+
})
|
|
3778
|
+
};
|
|
3779
|
+
};
|
|
3780
|
+
async function* parseJsonLines({
|
|
3781
|
+
stream,
|
|
3782
|
+
schema
|
|
3783
|
+
}) {
|
|
3784
|
+
const reader = stream.getReader();
|
|
3785
|
+
const decoder = new TextDecoder();
|
|
3786
|
+
let buffer = "";
|
|
3787
|
+
let finished = false;
|
|
3788
|
+
try {
|
|
3789
|
+
while (true) {
|
|
3790
|
+
const { done, value } = await reader.read();
|
|
3791
|
+
if (done) {
|
|
3792
|
+
finished = true;
|
|
3793
|
+
buffer += decoder.decode();
|
|
3794
|
+
break;
|
|
3795
|
+
}
|
|
3796
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3797
|
+
let lineEnd = buffer.indexOf("\n");
|
|
3798
|
+
while (lineEnd !== -1) {
|
|
3799
|
+
const line = buffer.slice(0, lineEnd).replace(/\r$/, "");
|
|
3800
|
+
buffer = buffer.slice(lineEnd + 1);
|
|
3801
|
+
if (line.trim().length > 0) {
|
|
3802
|
+
yield await parseJSON({ text: line, schema });
|
|
3803
|
+
}
|
|
3804
|
+
lineEnd = buffer.indexOf("\n");
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
const finalLine = buffer.replace(/\r$/, "");
|
|
3808
|
+
if (finalLine.trim().length > 0) {
|
|
3809
|
+
yield await parseJSON({ text: finalLine, schema });
|
|
3810
|
+
}
|
|
3811
|
+
} finally {
|
|
3812
|
+
if (!finished) {
|
|
3813
|
+
await reader.cancel().catch(() => {
|
|
3814
|
+
});
|
|
3815
|
+
}
|
|
3816
|
+
reader.releaseLock();
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3633
3819
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
3634
3820
|
const responseHeaders = extractResponseHeaders(response);
|
|
3635
3821
|
if (!response.body) {
|
|
@@ -3697,8 +3883,8 @@ function isJSONSerializable(value) {
|
|
|
3697
3883
|
// src/serialization-error.ts
|
|
3698
3884
|
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
|
3699
3885
|
var name2 = "AI_SerializationError";
|
|
3700
|
-
var
|
|
3701
|
-
var symbol2 = Symbol.for(
|
|
3886
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
3887
|
+
var symbol2 = Symbol.for(marker3);
|
|
3702
3888
|
var _a2, _b2;
|
|
3703
3889
|
var SerializationError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
3704
3890
|
// used in isInstance
|
|
@@ -3710,7 +3896,7 @@ var SerializationError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
|
3710
3896
|
this[_a2] = true;
|
|
3711
3897
|
}
|
|
3712
3898
|
static isInstance(error) {
|
|
3713
|
-
return AISDKError2.hasMarker(error,
|
|
3899
|
+
return AISDKError2.hasMarker(error, marker3);
|
|
3714
3900
|
}
|
|
3715
3901
|
};
|
|
3716
3902
|
|
|
@@ -4082,6 +4268,7 @@ export {
|
|
|
4082
4268
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
4083
4269
|
DelayedPromise,
|
|
4084
4270
|
DownloadError,
|
|
4271
|
+
EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
4085
4272
|
TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE,
|
|
4086
4273
|
TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE,
|
|
4087
4274
|
EventSourceParserStream2 as EventSourceParserStream,
|
|
@@ -4106,12 +4293,14 @@ export {
|
|
|
4106
4293
|
createEventSourceResponseHandler,
|
|
4107
4294
|
createIdGenerator,
|
|
4108
4295
|
createJsonErrorResponseHandler,
|
|
4296
|
+
createJsonLinesResponseHandler,
|
|
4109
4297
|
createJsonResponseHandler,
|
|
4110
4298
|
createLanguageModelResponseMetadata,
|
|
4111
4299
|
createNullLanguageModelUsage,
|
|
4112
4300
|
createProviderDefinedToolFactory,
|
|
4113
4301
|
createProviderDefinedToolFactoryWithOutputSchema,
|
|
4114
4302
|
createProviderExecutedToolFactory,
|
|
4303
|
+
createProviderStreamError,
|
|
4115
4304
|
createStatusCodeErrorResponseHandler,
|
|
4116
4305
|
createToolNameMapping,
|
|
4117
4306
|
delay,
|
|
@@ -4144,6 +4333,7 @@ export {
|
|
|
4144
4333
|
isNonNullable,
|
|
4145
4334
|
isParsableJson,
|
|
4146
4335
|
isProviderReference,
|
|
4336
|
+
isProviderStreamError,
|
|
4147
4337
|
isRecord,
|
|
4148
4338
|
isSameOrigin,
|
|
4149
4339
|
isUrlSupported,
|
|
@@ -4155,6 +4345,7 @@ export {
|
|
|
4155
4345
|
mapReasoningToProviderBudget,
|
|
4156
4346
|
mapReasoningToProviderEffort,
|
|
4157
4347
|
mediaTypeToExtension,
|
|
4348
|
+
normalizeBatchRequestCounts,
|
|
4158
4349
|
normalizeHeaders,
|
|
4159
4350
|
parseJSON,
|
|
4160
4351
|
parseJsonEventStream,
|