@ai-sdk/provider-utils 5.0.29 → 5.0.32
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 +25 -0
- package/dist/index.d.ts +50 -2
- package/dist/index.js +115 -7
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/create-provider-stream-error.ts +53 -0
- package/src/embedding-model-capabilities.ts +9 -0
- package/src/index.ts +7 -0
- package/src/normalize-batch-request-counts.ts +42 -0
- package/src/response-handler.ts +67 -0
- package/src/types/tool-approval-request.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e125ba: Allow manual tool approval statuses to include a reason and preserve it across
|
|
8
|
+
core, model, and UI approval requests. OPA `requires-approval` decisions now
|
|
9
|
+
surface their reason to human approvers. UI request chunks serialize the
|
|
10
|
+
optional `reason`, while UI messages retain it as `approval.requestReason`
|
|
11
|
+
separately from an approver's response `reason`.
|
|
12
|
+
|
|
13
|
+
## 5.0.31
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- a9782e1: fix: align batch result parsing, request counts, and lifecycle behavior across providers
|
|
18
|
+
- 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
|
|
19
|
+
- 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.
|
|
20
|
+
|
|
21
|
+
## 5.0.30
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [591d25b]
|
|
26
|
+
- @ai-sdk/provider@4.0.8
|
|
27
|
+
|
|
3
28
|
## 5.0.29
|
|
4
29
|
|
|
5
30
|
### 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,
|
|
@@ -1329,7 +1359,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1329
1359
|
}
|
|
1330
1360
|
|
|
1331
1361
|
// src/version.ts
|
|
1332
|
-
var VERSION = true ? "5.0.
|
|
1362
|
+
var VERSION = true ? "5.0.32" : "0.0.0-test";
|
|
1333
1363
|
|
|
1334
1364
|
// src/get-from-api.ts
|
|
1335
1365
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1666,6 +1696,27 @@ function mediaTypeToExtension(mediaType) {
|
|
|
1666
1696
|
}[subtype]) != null ? _a3 : subtype;
|
|
1667
1697
|
}
|
|
1668
1698
|
|
|
1699
|
+
// src/normalize-batch-request-counts.ts
|
|
1700
|
+
function normalizeBatchRequestCounts({
|
|
1701
|
+
total,
|
|
1702
|
+
pending,
|
|
1703
|
+
completed,
|
|
1704
|
+
failed
|
|
1705
|
+
}) {
|
|
1706
|
+
if (isNonNegativeSafeInteger(total) && isNonNegativeSafeInteger(pending) && isNonNegativeSafeInteger(completed) && isNonNegativeSafeInteger(failed) && pending + completed + failed === total) {
|
|
1707
|
+
return {
|
|
1708
|
+
total,
|
|
1709
|
+
pending,
|
|
1710
|
+
completed,
|
|
1711
|
+
failed
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
return void 0;
|
|
1715
|
+
}
|
|
1716
|
+
function isNonNegativeSafeInteger(value) {
|
|
1717
|
+
return value != null && Number.isSafeInteger(value) && value >= 0;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1669
1720
|
// src/parse-json.ts
|
|
1670
1721
|
import {
|
|
1671
1722
|
JSONParseError,
|
|
@@ -3630,6 +3681,58 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
3630
3681
|
rawValue: parsedResult.rawValue
|
|
3631
3682
|
};
|
|
3632
3683
|
};
|
|
3684
|
+
var createJsonLinesResponseHandler = (responseSchema) => async ({ response }) => {
|
|
3685
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
3686
|
+
if (response.body == null) {
|
|
3687
|
+
throw new EmptyResponseBodyError({});
|
|
3688
|
+
}
|
|
3689
|
+
return {
|
|
3690
|
+
responseHeaders,
|
|
3691
|
+
value: parseJsonLines({
|
|
3692
|
+
stream: response.body,
|
|
3693
|
+
schema: responseSchema
|
|
3694
|
+
})
|
|
3695
|
+
};
|
|
3696
|
+
};
|
|
3697
|
+
async function* parseJsonLines({
|
|
3698
|
+
stream,
|
|
3699
|
+
schema
|
|
3700
|
+
}) {
|
|
3701
|
+
const reader = stream.getReader();
|
|
3702
|
+
const decoder = new TextDecoder();
|
|
3703
|
+
let buffer = "";
|
|
3704
|
+
let finished = false;
|
|
3705
|
+
try {
|
|
3706
|
+
while (true) {
|
|
3707
|
+
const { done, value } = await reader.read();
|
|
3708
|
+
if (done) {
|
|
3709
|
+
finished = true;
|
|
3710
|
+
buffer += decoder.decode();
|
|
3711
|
+
break;
|
|
3712
|
+
}
|
|
3713
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3714
|
+
let lineEnd = buffer.indexOf("\n");
|
|
3715
|
+
while (lineEnd !== -1) {
|
|
3716
|
+
const line = buffer.slice(0, lineEnd).replace(/\r$/, "");
|
|
3717
|
+
buffer = buffer.slice(lineEnd + 1);
|
|
3718
|
+
if (line.trim().length > 0) {
|
|
3719
|
+
yield await parseJSON({ text: line, schema });
|
|
3720
|
+
}
|
|
3721
|
+
lineEnd = buffer.indexOf("\n");
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
const finalLine = buffer.replace(/\r$/, "");
|
|
3725
|
+
if (finalLine.trim().length > 0) {
|
|
3726
|
+
yield await parseJSON({ text: finalLine, schema });
|
|
3727
|
+
}
|
|
3728
|
+
} finally {
|
|
3729
|
+
if (!finished) {
|
|
3730
|
+
await reader.cancel().catch(() => {
|
|
3731
|
+
});
|
|
3732
|
+
}
|
|
3733
|
+
reader.releaseLock();
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3633
3736
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
3634
3737
|
const responseHeaders = extractResponseHeaders(response);
|
|
3635
3738
|
if (!response.body) {
|
|
@@ -3697,8 +3800,8 @@ function isJSONSerializable(value) {
|
|
|
3697
3800
|
// src/serialization-error.ts
|
|
3698
3801
|
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
|
3699
3802
|
var name2 = "AI_SerializationError";
|
|
3700
|
-
var
|
|
3701
|
-
var symbol2 = Symbol.for(
|
|
3803
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
3804
|
+
var symbol2 = Symbol.for(marker3);
|
|
3702
3805
|
var _a2, _b2;
|
|
3703
3806
|
var SerializationError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
3704
3807
|
// used in isInstance
|
|
@@ -3710,7 +3813,7 @@ var SerializationError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
|
3710
3813
|
this[_a2] = true;
|
|
3711
3814
|
}
|
|
3712
3815
|
static isInstance(error) {
|
|
3713
|
-
return AISDKError2.hasMarker(error,
|
|
3816
|
+
return AISDKError2.hasMarker(error, marker3);
|
|
3714
3817
|
}
|
|
3715
3818
|
};
|
|
3716
3819
|
|
|
@@ -4082,6 +4185,7 @@ export {
|
|
|
4082
4185
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
4083
4186
|
DelayedPromise,
|
|
4084
4187
|
DownloadError,
|
|
4188
|
+
EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
4085
4189
|
TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE,
|
|
4086
4190
|
TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE,
|
|
4087
4191
|
EventSourceParserStream2 as EventSourceParserStream,
|
|
@@ -4106,12 +4210,14 @@ export {
|
|
|
4106
4210
|
createEventSourceResponseHandler,
|
|
4107
4211
|
createIdGenerator,
|
|
4108
4212
|
createJsonErrorResponseHandler,
|
|
4213
|
+
createJsonLinesResponseHandler,
|
|
4109
4214
|
createJsonResponseHandler,
|
|
4110
4215
|
createLanguageModelResponseMetadata,
|
|
4111
4216
|
createNullLanguageModelUsage,
|
|
4112
4217
|
createProviderDefinedToolFactory,
|
|
4113
4218
|
createProviderDefinedToolFactoryWithOutputSchema,
|
|
4114
4219
|
createProviderExecutedToolFactory,
|
|
4220
|
+
createProviderStreamError,
|
|
4115
4221
|
createStatusCodeErrorResponseHandler,
|
|
4116
4222
|
createToolNameMapping,
|
|
4117
4223
|
delay,
|
|
@@ -4144,6 +4250,7 @@ export {
|
|
|
4144
4250
|
isNonNullable,
|
|
4145
4251
|
isParsableJson,
|
|
4146
4252
|
isProviderReference,
|
|
4253
|
+
isProviderStreamError,
|
|
4147
4254
|
isRecord,
|
|
4148
4255
|
isSameOrigin,
|
|
4149
4256
|
isUrlSupported,
|
|
@@ -4155,6 +4262,7 @@ export {
|
|
|
4155
4262
|
mapReasoningToProviderBudget,
|
|
4156
4263
|
mapReasoningToProviderEffort,
|
|
4157
4264
|
mediaTypeToExtension,
|
|
4265
|
+
normalizeBatchRequestCounts,
|
|
4158
4266
|
normalizeHeaders,
|
|
4159
4267
|
parseJSON,
|
|
4160
4268
|
parseJsonEventStream,
|