@ai-sdk/provider-utils 5.0.13 → 5.0.14
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 +7 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +111 -85
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/connect-to-websocket.ts +19 -3
- package/src/index.ts +1 -0
- package/src/serialization-error.ts +23 -0
- package/src/serialize-model-options.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0c464d9: feat(provider-utils): add a typed serialization error
|
|
8
|
+
- c49380c: feat: add experimental streaming speech translation models (`openai.translation('gpt-realtime-translate')` over the OpenAI Realtime translations WebSocket and `google.translation('gemini-3.5-live-translate-preview')` over the Gemini Live API). `connectToWebSocket` in `@ai-sdk/provider-utils` now passes close code and reason to `onClose` (additive, optional parameter).
|
|
9
|
+
|
|
3
10
|
## 5.0.13
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -85,7 +85,14 @@ declare function connectToWebSocket({ url, protocols, headers, webSocket, abortS
|
|
|
85
85
|
/** Constructor throws and message decoding/processing failures. */
|
|
86
86
|
onProcessingError: (error: unknown) => void;
|
|
87
87
|
onSocketError?: () => void;
|
|
88
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Receives the close code and reason when the transport provides them
|
|
90
|
+
* (native `CloseEvent` / `ws` close event).
|
|
91
|
+
*/
|
|
92
|
+
onClose?: (info: {
|
|
93
|
+
code?: number;
|
|
94
|
+
reason?: string;
|
|
95
|
+
}) => void;
|
|
89
96
|
/** Also called (without opening a socket) when the signal is already aborted. */
|
|
90
97
|
onAbort?: (reason: unknown) => void;
|
|
91
98
|
}): WebSocketConnection;
|
|
@@ -793,9 +800,9 @@ declare function downloadBlob(url: string, options?: {
|
|
|
793
800
|
abortSignal?: AbortSignal;
|
|
794
801
|
}): Promise<Blob>;
|
|
795
802
|
|
|
796
|
-
declare const symbol: unique symbol;
|
|
803
|
+
declare const symbol$1: unique symbol;
|
|
797
804
|
declare class DownloadError extends AISDKError {
|
|
798
|
-
private readonly [symbol];
|
|
805
|
+
private readonly [symbol$1];
|
|
799
806
|
readonly url: string;
|
|
800
807
|
readonly statusCode?: number;
|
|
801
808
|
readonly statusText?: string;
|
|
@@ -2216,6 +2223,16 @@ declare function serializeModelOptions<CONFIG extends {
|
|
|
2216
2223
|
config: JSONObject;
|
|
2217
2224
|
};
|
|
2218
2225
|
|
|
2226
|
+
declare const symbol: unique symbol;
|
|
2227
|
+
declare class SerializationError extends AISDKError {
|
|
2228
|
+
private readonly [symbol];
|
|
2229
|
+
constructor({ message, cause, }?: {
|
|
2230
|
+
message?: string;
|
|
2231
|
+
cause?: unknown;
|
|
2232
|
+
});
|
|
2233
|
+
static isInstance(error: unknown): error is SerializationError;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2219
2236
|
declare function secureJsonParse(text: string): any;
|
|
2220
2237
|
|
|
2221
2238
|
/**
|
|
@@ -2621,4 +2638,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2621
2638
|
dynamic?: boolean;
|
|
2622
2639
|
}
|
|
2623
2640
|
|
|
2624
|
-
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 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, 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, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, 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 };
|
|
2641
|
+
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 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, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, 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 };
|
package/dist/index.js
CHANGED
|
@@ -86,8 +86,8 @@ async function waitForWebSocketBufferDrain(socket, {
|
|
|
86
86
|
pollIntervalMs = 20,
|
|
87
87
|
abortSignal
|
|
88
88
|
} = {}) {
|
|
89
|
-
var
|
|
90
|
-
while (socket.readyState === WEBSOCKET_OPEN_STATE && ((
|
|
89
|
+
var _a3;
|
|
90
|
+
while (socket.readyState === WEBSOCKET_OPEN_STATE && ((_a3 = socket.bufferedAmount) != null ? _a3 : 0) > highWaterMark) {
|
|
91
91
|
if ((abortSignal == null ? void 0 : abortSignal.aborted) === true) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
@@ -109,7 +109,7 @@ function connectToWebSocket({
|
|
|
109
109
|
onClose,
|
|
110
110
|
onAbort
|
|
111
111
|
}) {
|
|
112
|
-
var
|
|
112
|
+
var _a3;
|
|
113
113
|
let socket;
|
|
114
114
|
let abortListener;
|
|
115
115
|
const close = (code) => {
|
|
@@ -123,7 +123,7 @@ function connectToWebSocket({
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
126
|
-
onAbort == null ? void 0 : onAbort((
|
|
126
|
+
onAbort == null ? void 0 : onAbort((_a3 = abortSignal.reason) != null ? _a3 : new Error("Aborted"));
|
|
127
127
|
return { socket: void 0, close };
|
|
128
128
|
}
|
|
129
129
|
try {
|
|
@@ -137,8 +137,8 @@ function connectToWebSocket({
|
|
|
137
137
|
}
|
|
138
138
|
if (abortSignal != null && onAbort != null) {
|
|
139
139
|
abortListener = () => {
|
|
140
|
-
var
|
|
141
|
-
return onAbort((
|
|
140
|
+
var _a4;
|
|
141
|
+
return onAbort((_a4 = abortSignal.reason) != null ? _a4 : new Error("Aborted"));
|
|
142
142
|
};
|
|
143
143
|
abortSignal.addEventListener("abort", abortListener, { once: true });
|
|
144
144
|
}
|
|
@@ -157,8 +157,11 @@ function connectToWebSocket({
|
|
|
157
157
|
socket.onerror = () => {
|
|
158
158
|
tail = tail.then(() => onSocketError == null ? void 0 : onSocketError()).catch(onProcessingError);
|
|
159
159
|
};
|
|
160
|
-
socket.onclose = () => {
|
|
161
|
-
|
|
160
|
+
socket.onclose = (event) => {
|
|
161
|
+
const closeEvent = event;
|
|
162
|
+
const code = typeof (closeEvent == null ? void 0 : closeEvent.code) === "number" ? closeEvent.code : void 0;
|
|
163
|
+
const reason = typeof (closeEvent == null ? void 0 : closeEvent.reason) === "string" ? closeEvent.reason : void 0;
|
|
164
|
+
tail = tail.then(() => onClose == null ? void 0 : onClose({ code, reason })).catch(onProcessingError);
|
|
162
165
|
};
|
|
163
166
|
return { socket, close };
|
|
164
167
|
}
|
|
@@ -279,12 +282,12 @@ function createToolNameMapping({
|
|
|
279
282
|
}
|
|
280
283
|
return {
|
|
281
284
|
toProviderToolName: (customToolName) => {
|
|
282
|
-
var
|
|
283
|
-
return (
|
|
285
|
+
var _a3;
|
|
286
|
+
return (_a3 = customToolNameToProviderToolName[customToolName]) != null ? _a3 : customToolName;
|
|
284
287
|
},
|
|
285
288
|
toCustomToolName: (providerToolName) => {
|
|
286
|
-
var
|
|
287
|
-
return (
|
|
289
|
+
var _a3;
|
|
290
|
+
return (_a3 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3 : providerToolName;
|
|
288
291
|
}
|
|
289
292
|
};
|
|
290
293
|
}
|
|
@@ -312,17 +315,17 @@ var DelayedPromise = class {
|
|
|
312
315
|
return this._promise;
|
|
313
316
|
}
|
|
314
317
|
resolve(value) {
|
|
315
|
-
var
|
|
318
|
+
var _a3;
|
|
316
319
|
this.status = { type: "resolved", value };
|
|
317
320
|
if (this._promise) {
|
|
318
|
-
(
|
|
321
|
+
(_a3 = this._resolve) == null ? void 0 : _a3.call(this, value);
|
|
319
322
|
}
|
|
320
323
|
}
|
|
321
324
|
reject(error) {
|
|
322
|
-
var
|
|
325
|
+
var _a3;
|
|
323
326
|
this.status = { type: "rejected", error };
|
|
324
327
|
if (this._promise) {
|
|
325
|
-
(
|
|
328
|
+
(_a3 = this._reject) == null ? void 0 : _a3.call(this, error);
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
331
|
isResolved() {
|
|
@@ -637,9 +640,9 @@ function isFullMediaType(mediaType) {
|
|
|
637
640
|
|
|
638
641
|
// src/cancel-response-body.ts
|
|
639
642
|
async function cancelResponseBody(response) {
|
|
640
|
-
var
|
|
643
|
+
var _a3;
|
|
641
644
|
try {
|
|
642
|
-
await ((
|
|
645
|
+
await ((_a3 = response.body) == null ? void 0 : _a3.cancel());
|
|
643
646
|
} catch (e) {
|
|
644
647
|
}
|
|
645
648
|
}
|
|
@@ -713,8 +716,8 @@ var BLOCKED_REQUEST_HEADERS = [
|
|
|
713
716
|
];
|
|
714
717
|
function sanitizeRequestHeaders(input) {
|
|
715
718
|
const headers = new Headers(input);
|
|
716
|
-
for (const
|
|
717
|
-
headers.delete(
|
|
719
|
+
for (const name3 of BLOCKED_REQUEST_HEADERS) {
|
|
720
|
+
headers.delete(name3);
|
|
718
721
|
}
|
|
719
722
|
return headers;
|
|
720
723
|
}
|
|
@@ -976,7 +979,7 @@ async function readResponseWithSizeLimit({
|
|
|
976
979
|
|
|
977
980
|
// src/download-blob.ts
|
|
978
981
|
async function downloadBlob(url, options) {
|
|
979
|
-
var
|
|
982
|
+
var _a3, _b3;
|
|
980
983
|
try {
|
|
981
984
|
const response = await fetchWithValidatedRedirects({
|
|
982
985
|
url,
|
|
@@ -993,9 +996,9 @@ async function downloadBlob(url, options) {
|
|
|
993
996
|
const data = await readResponseWithSizeLimit({
|
|
994
997
|
response,
|
|
995
998
|
url,
|
|
996
|
-
maxBytes: (
|
|
999
|
+
maxBytes: (_a3 = options == null ? void 0 : options.maxBytes) != null ? _a3 : DEFAULT_MAX_DOWNLOAD_SIZE
|
|
997
1000
|
});
|
|
998
|
-
const contentType = (
|
|
1001
|
+
const contentType = (_b3 = response.headers.get("content-type")) != null ? _b3 : void 0;
|
|
999
1002
|
return new Blob([data], contentType ? { type: contentType } : void 0);
|
|
1000
1003
|
} catch (error) {
|
|
1001
1004
|
if (DownloadError.isInstance(error)) {
|
|
@@ -1129,14 +1132,14 @@ function handleFetchError({
|
|
|
1129
1132
|
|
|
1130
1133
|
// src/get-runtime-environment-user-agent.ts
|
|
1131
1134
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
1132
|
-
var
|
|
1135
|
+
var _a3, _b3, _c;
|
|
1133
1136
|
if (globalThisAny.window) {
|
|
1134
1137
|
return `runtime/browser`;
|
|
1135
1138
|
}
|
|
1136
|
-
if ((
|
|
1139
|
+
if ((_a3 = globalThisAny.navigator) == null ? void 0 : _a3.userAgent) {
|
|
1137
1140
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
1138
1141
|
}
|
|
1139
|
-
if ((_c = (
|
|
1142
|
+
if ((_c = (_b3 = globalThisAny.process) == null ? void 0 : _b3.versions) == null ? void 0 : _c.node) {
|
|
1140
1143
|
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
1141
1144
|
}
|
|
1142
1145
|
if (globalThisAny.EdgeRuntime) {
|
|
@@ -1180,7 +1183,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1180
1183
|
}
|
|
1181
1184
|
|
|
1182
1185
|
// src/version.ts
|
|
1183
|
-
var VERSION = true ? "5.0.
|
|
1186
|
+
var VERSION = true ? "5.0.14" : "0.0.0-test";
|
|
1184
1187
|
|
|
1185
1188
|
// src/get-from-api.ts
|
|
1186
1189
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1288,8 +1291,8 @@ function injectJsonInstructionIntoMessages({
|
|
|
1288
1291
|
schemaPrefix,
|
|
1289
1292
|
schemaSuffix
|
|
1290
1293
|
}) {
|
|
1291
|
-
var
|
|
1292
|
-
const systemMessage = ((
|
|
1294
|
+
var _a3, _b3;
|
|
1295
|
+
const systemMessage = ((_a3 = messages[0]) == null ? void 0 : _a3.role) === "system" ? { ...messages[0] } : { role: "system", content: "" };
|
|
1293
1296
|
systemMessage.content = injectJsonInstruction({
|
|
1294
1297
|
prompt: systemMessage.content,
|
|
1295
1298
|
schema,
|
|
@@ -1298,14 +1301,14 @@ function injectJsonInstructionIntoMessages({
|
|
|
1298
1301
|
});
|
|
1299
1302
|
return [
|
|
1300
1303
|
systemMessage,
|
|
1301
|
-
...((
|
|
1304
|
+
...((_b3 = messages[0]) == null ? void 0 : _b3.role) === "system" ? messages.slice(1) : messages
|
|
1302
1305
|
];
|
|
1303
1306
|
}
|
|
1304
1307
|
|
|
1305
1308
|
// src/is-buffer.ts
|
|
1306
1309
|
function isBuffer(value) {
|
|
1307
|
-
var
|
|
1308
|
-
return (
|
|
1310
|
+
var _a3, _b3;
|
|
1311
|
+
return (_b3 = (_a3 = globalThis.Buffer) == null ? void 0 : _a3.isBuffer(value)) != null ? _b3 : false;
|
|
1309
1312
|
}
|
|
1310
1313
|
|
|
1311
1314
|
// src/is-non-nullable.ts
|
|
@@ -1488,15 +1491,15 @@ function mapReasoningToProviderBudget({
|
|
|
1488
1491
|
|
|
1489
1492
|
// src/media-type-to-extension.ts
|
|
1490
1493
|
function mediaTypeToExtension(mediaType) {
|
|
1491
|
-
var
|
|
1494
|
+
var _a3;
|
|
1492
1495
|
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
1493
|
-
return (
|
|
1496
|
+
return (_a3 = {
|
|
1494
1497
|
mpeg: "mp3",
|
|
1495
1498
|
"x-wav": "wav",
|
|
1496
1499
|
opus: "ogg",
|
|
1497
1500
|
mp4: "m4a",
|
|
1498
1501
|
"x-m4a": "m4a"
|
|
1499
|
-
}[subtype]) != null ?
|
|
1502
|
+
}[subtype]) != null ? _a3 : subtype;
|
|
1500
1503
|
}
|
|
1501
1504
|
|
|
1502
1505
|
// src/parse-json.ts
|
|
@@ -1643,11 +1646,11 @@ function parseAnyDef() {
|
|
|
1643
1646
|
// src/to-json-schema/zod3-to-json-schema/parsers/array.ts
|
|
1644
1647
|
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
1645
1648
|
function parseArrayDef(def, refs) {
|
|
1646
|
-
var
|
|
1649
|
+
var _a3, _b3, _c;
|
|
1647
1650
|
const res = {
|
|
1648
1651
|
type: "array"
|
|
1649
1652
|
};
|
|
1650
|
-
if (((
|
|
1653
|
+
if (((_a3 = def.type) == null ? void 0 : _a3._def) && ((_c = (_b3 = def.type) == null ? void 0 : _b3._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1651
1654
|
res.items = parseDef(def.type._def, {
|
|
1652
1655
|
...refs,
|
|
1653
1656
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -2040,8 +2043,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
2040
2043
|
return result;
|
|
2041
2044
|
}
|
|
2042
2045
|
function addFormat(schema, value, message, refs) {
|
|
2043
|
-
var
|
|
2044
|
-
if (schema.format || ((
|
|
2046
|
+
var _a3;
|
|
2047
|
+
if (schema.format || ((_a3 = schema.anyOf) == null ? void 0 : _a3.some((x) => x.format))) {
|
|
2045
2048
|
if (!schema.anyOf) {
|
|
2046
2049
|
schema.anyOf = [];
|
|
2047
2050
|
}
|
|
@@ -2060,8 +2063,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
2060
2063
|
}
|
|
2061
2064
|
}
|
|
2062
2065
|
function addPattern(schema, regex, message, refs) {
|
|
2063
|
-
var
|
|
2064
|
-
if (schema.pattern || ((
|
|
2066
|
+
var _a3;
|
|
2067
|
+
if (schema.pattern || ((_a3 = schema.allOf) == null ? void 0 : _a3.some((x) => x.pattern))) {
|
|
2065
2068
|
if (!schema.allOf) {
|
|
2066
2069
|
schema.allOf = [];
|
|
2067
2070
|
}
|
|
@@ -2080,7 +2083,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
2080
2083
|
}
|
|
2081
2084
|
}
|
|
2082
2085
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
2083
|
-
var
|
|
2086
|
+
var _a3;
|
|
2084
2087
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
2085
2088
|
return regex.source;
|
|
2086
2089
|
}
|
|
@@ -2110,7 +2113,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
2110
2113
|
pattern += source[i];
|
|
2111
2114
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
2112
2115
|
inCharRange = false;
|
|
2113
|
-
} else if (source[i + 1] === "-" && ((
|
|
2116
|
+
} else if (source[i + 1] === "-" && ((_a3 = source[i + 2]) == null ? void 0 : _a3.match(/[a-z]/))) {
|
|
2114
2117
|
pattern += source[i];
|
|
2115
2118
|
inCharRange = true;
|
|
2116
2119
|
} else {
|
|
@@ -2164,15 +2167,15 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
2164
2167
|
|
|
2165
2168
|
// src/to-json-schema/zod3-to-json-schema/parsers/record.ts
|
|
2166
2169
|
function parseRecordDef(def, refs) {
|
|
2167
|
-
var
|
|
2170
|
+
var _a3, _b3, _c, _d, _e, _f;
|
|
2168
2171
|
const schema = {
|
|
2169
2172
|
type: "object",
|
|
2170
|
-
additionalProperties: (
|
|
2173
|
+
additionalProperties: (_a3 = parseDef(def.valueType._def, {
|
|
2171
2174
|
...refs,
|
|
2172
2175
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2173
|
-
})) != null ?
|
|
2176
|
+
})) != null ? _a3 : refs.allowedAdditionalProperties
|
|
2174
2177
|
};
|
|
2175
|
-
if (((
|
|
2178
|
+
if (((_b3 = def.keyType) == null ? void 0 : _b3._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
2176
2179
|
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
2177
2180
|
return {
|
|
2178
2181
|
...schema,
|
|
@@ -2445,8 +2448,8 @@ function safeIsOptional(schema) {
|
|
|
2445
2448
|
|
|
2446
2449
|
// src/to-json-schema/zod3-to-json-schema/parsers/optional.ts
|
|
2447
2450
|
var parseOptionalDef = (def, refs) => {
|
|
2448
|
-
var
|
|
2449
|
-
if (refs.currentPath.toString() === ((
|
|
2451
|
+
var _a3;
|
|
2452
|
+
if (refs.currentPath.toString() === ((_a3 = refs.propertyPath) == null ? void 0 : _a3.toString())) {
|
|
2450
2453
|
return parseDef(def.innerType._def, refs);
|
|
2451
2454
|
}
|
|
2452
2455
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -2645,10 +2648,10 @@ var getRelativePath = (pathA, pathB) => {
|
|
|
2645
2648
|
|
|
2646
2649
|
// src/to-json-schema/zod3-to-json-schema/parse-def.ts
|
|
2647
2650
|
function parseDef(def, refs, forceResolution = false) {
|
|
2648
|
-
var
|
|
2651
|
+
var _a3;
|
|
2649
2652
|
const seenItem = refs.seen.get(def);
|
|
2650
2653
|
if (refs.override) {
|
|
2651
|
-
const overrideResult = (
|
|
2654
|
+
const overrideResult = (_a3 = refs.override) == null ? void 0 : _a3.call(
|
|
2652
2655
|
refs,
|
|
2653
2656
|
def,
|
|
2654
2657
|
refs,
|
|
@@ -2716,11 +2719,11 @@ var getRefs = (options) => {
|
|
|
2716
2719
|
currentPath,
|
|
2717
2720
|
propertyPath: void 0,
|
|
2718
2721
|
seen: new Map(
|
|
2719
|
-
Object.entries(_options.definitions).map(([
|
|
2722
|
+
Object.entries(_options.definitions).map(([name3, def]) => [
|
|
2720
2723
|
def._def,
|
|
2721
2724
|
{
|
|
2722
2725
|
def: def._def,
|
|
2723
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
2726
|
+
path: [..._options.basePath, _options.definitionPath, name3],
|
|
2724
2727
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2725
2728
|
jsonSchema: void 0
|
|
2726
2729
|
}
|
|
@@ -2731,50 +2734,50 @@ var getRefs = (options) => {
|
|
|
2731
2734
|
|
|
2732
2735
|
// src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts
|
|
2733
2736
|
var zod3ToJsonSchema = (schema, options) => {
|
|
2734
|
-
var
|
|
2737
|
+
var _a3;
|
|
2735
2738
|
const refs = getRefs(options);
|
|
2736
2739
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2737
|
-
(acc, [
|
|
2738
|
-
var
|
|
2740
|
+
(acc, [name4, schema2]) => {
|
|
2741
|
+
var _a4;
|
|
2739
2742
|
return {
|
|
2740
2743
|
...acc,
|
|
2741
|
-
[
|
|
2744
|
+
[name4]: (_a4 = parseDef(
|
|
2742
2745
|
schema2._def,
|
|
2743
2746
|
{
|
|
2744
2747
|
...refs,
|
|
2745
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2748
|
+
currentPath: [...refs.basePath, refs.definitionPath, name4]
|
|
2746
2749
|
},
|
|
2747
2750
|
true
|
|
2748
|
-
)) != null ?
|
|
2751
|
+
)) != null ? _a4 : parseAnyDef()
|
|
2749
2752
|
};
|
|
2750
2753
|
},
|
|
2751
2754
|
{}
|
|
2752
2755
|
) : void 0;
|
|
2753
|
-
const
|
|
2754
|
-
const main = (
|
|
2756
|
+
const name3 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2757
|
+
const main = (_a3 = parseDef(
|
|
2755
2758
|
schema._def,
|
|
2756
|
-
|
|
2759
|
+
name3 === void 0 ? refs : {
|
|
2757
2760
|
...refs,
|
|
2758
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2761
|
+
currentPath: [...refs.basePath, refs.definitionPath, name3]
|
|
2759
2762
|
},
|
|
2760
2763
|
false
|
|
2761
|
-
)) != null ?
|
|
2764
|
+
)) != null ? _a3 : parseAnyDef();
|
|
2762
2765
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2763
2766
|
if (title !== void 0) {
|
|
2764
2767
|
main.title = title;
|
|
2765
2768
|
}
|
|
2766
|
-
const combined =
|
|
2769
|
+
const combined = name3 === void 0 ? definitions ? {
|
|
2767
2770
|
...main,
|
|
2768
2771
|
[refs.definitionPath]: definitions
|
|
2769
2772
|
} : main : {
|
|
2770
2773
|
$ref: [
|
|
2771
2774
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2772
2775
|
refs.definitionPath,
|
|
2773
|
-
|
|
2776
|
+
name3
|
|
2774
2777
|
].join("/"),
|
|
2775
2778
|
[refs.definitionPath]: {
|
|
2776
2779
|
...definitions,
|
|
2777
|
-
[
|
|
2780
|
+
[name3]: main
|
|
2778
2781
|
}
|
|
2779
2782
|
};
|
|
2780
2783
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -2850,8 +2853,8 @@ function hasStandardJsonSchema(schema) {
|
|
|
2850
2853
|
return schema["~standard"].jsonSchema != null;
|
|
2851
2854
|
}
|
|
2852
2855
|
function zod3Schema(zodSchema2, options) {
|
|
2853
|
-
var
|
|
2854
|
-
const useReferences = (
|
|
2856
|
+
var _a3;
|
|
2857
|
+
const useReferences = (_a3 = options == null ? void 0 : options.useReferences) != null ? _a3 : false;
|
|
2855
2858
|
return jsonSchema(
|
|
2856
2859
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2857
2860
|
() => zod3ToJsonSchema(zodSchema2, {
|
|
@@ -2866,8 +2869,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
2866
2869
|
);
|
|
2867
2870
|
}
|
|
2868
2871
|
function zod4Schema(zodSchema2, options) {
|
|
2869
|
-
var
|
|
2870
|
-
const useReferences = (
|
|
2872
|
+
var _a3;
|
|
2873
|
+
const useReferences = (_a3 = options == null ? void 0 : options.useReferences) != null ? _a3 : false;
|
|
2871
2874
|
return jsonSchema(
|
|
2872
2875
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2873
2876
|
() => addAdditionalPropertiesToJsonSchema(
|
|
@@ -3534,6 +3537,26 @@ function isJSONSerializable(value) {
|
|
|
3534
3537
|
return false;
|
|
3535
3538
|
}
|
|
3536
3539
|
|
|
3540
|
+
// src/serialization-error.ts
|
|
3541
|
+
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
|
3542
|
+
var name2 = "AI_SerializationError";
|
|
3543
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
|
3544
|
+
var symbol2 = Symbol.for(marker2);
|
|
3545
|
+
var _a2, _b2;
|
|
3546
|
+
var SerializationError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
3547
|
+
// used in isInstance
|
|
3548
|
+
constructor({
|
|
3549
|
+
message = "Failed to serialize value.",
|
|
3550
|
+
cause
|
|
3551
|
+
} = {}) {
|
|
3552
|
+
super({ name: name2, message, cause });
|
|
3553
|
+
this[_a2] = true;
|
|
3554
|
+
}
|
|
3555
|
+
static isInstance(error) {
|
|
3556
|
+
return AISDKError2.hasMarker(error, marker2);
|
|
3557
|
+
}
|
|
3558
|
+
};
|
|
3559
|
+
|
|
3537
3560
|
// src/serialize-model-options.ts
|
|
3538
3561
|
function serializeModelOptions(options) {
|
|
3539
3562
|
const serializableConfig = {};
|
|
@@ -3555,7 +3578,9 @@ function resolveSync(value) {
|
|
|
3555
3578
|
next = value();
|
|
3556
3579
|
}
|
|
3557
3580
|
if (next instanceof Promise) {
|
|
3558
|
-
throw new
|
|
3581
|
+
throw new SerializationError({
|
|
3582
|
+
message: "Cannot serialize asynchronous model options."
|
|
3583
|
+
});
|
|
3559
3584
|
}
|
|
3560
3585
|
return next;
|
|
3561
3586
|
}
|
|
@@ -3567,10 +3592,10 @@ import {
|
|
|
3567
3592
|
var StreamingToolCallTracker = class {
|
|
3568
3593
|
constructor(controller, options = {}) {
|
|
3569
3594
|
this.toolCalls = [];
|
|
3570
|
-
var
|
|
3595
|
+
var _a3, _b3;
|
|
3571
3596
|
this.controller = controller;
|
|
3572
|
-
this._generateId = (
|
|
3573
|
-
this.typeValidation = (
|
|
3597
|
+
this._generateId = (_a3 = options.generateId) != null ? _a3 : generateId;
|
|
3598
|
+
this.typeValidation = (_b3 = options.typeValidation) != null ? _b3 : "none";
|
|
3574
3599
|
this.extractMetadata = options.extractMetadata;
|
|
3575
3600
|
this.buildToolCallProviderMetadata = options.buildToolCallProviderMetadata;
|
|
3576
3601
|
}
|
|
@@ -3580,8 +3605,8 @@ var StreamingToolCallTracker = class {
|
|
|
3580
3605
|
* events as appropriate.
|
|
3581
3606
|
*/
|
|
3582
3607
|
processDelta(toolCallDelta) {
|
|
3583
|
-
var
|
|
3584
|
-
const index = (
|
|
3608
|
+
var _a3;
|
|
3609
|
+
const index = (_a3 = toolCallDelta.index) != null ? _a3 : this.toolCalls.length;
|
|
3585
3610
|
if (this.toolCalls[index] == null) {
|
|
3586
3611
|
this.processNewToolCall(index, toolCallDelta);
|
|
3587
3612
|
} else {
|
|
@@ -3600,7 +3625,7 @@ var StreamingToolCallTracker = class {
|
|
|
3600
3625
|
}
|
|
3601
3626
|
}
|
|
3602
3627
|
processNewToolCall(index, toolCallDelta) {
|
|
3603
|
-
var
|
|
3628
|
+
var _a3, _b3, _c;
|
|
3604
3629
|
if (this.typeValidation === "required") {
|
|
3605
3630
|
if (toolCallDelta.type !== "function") {
|
|
3606
3631
|
throw new InvalidResponseDataError({
|
|
@@ -3622,7 +3647,7 @@ var StreamingToolCallTracker = class {
|
|
|
3622
3647
|
message: `Expected 'id' to be a string.`
|
|
3623
3648
|
});
|
|
3624
3649
|
}
|
|
3625
|
-
if (((
|
|
3650
|
+
if (((_a3 = toolCallDelta.function) == null ? void 0 : _a3.name) == null) {
|
|
3626
3651
|
throw new InvalidResponseDataError({
|
|
3627
3652
|
data: toolCallDelta,
|
|
3628
3653
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -3633,7 +3658,7 @@ var StreamingToolCallTracker = class {
|
|
|
3633
3658
|
id: toolCallDelta.id,
|
|
3634
3659
|
toolName: toolCallDelta.function.name
|
|
3635
3660
|
});
|
|
3636
|
-
const metadata = (
|
|
3661
|
+
const metadata = (_b3 = this.extractMetadata) == null ? void 0 : _b3.call(this, toolCallDelta);
|
|
3637
3662
|
this.toolCalls[index] = {
|
|
3638
3663
|
id: toolCallDelta.id,
|
|
3639
3664
|
type: "function",
|
|
@@ -3654,12 +3679,12 @@ var StreamingToolCallTracker = class {
|
|
|
3654
3679
|
}
|
|
3655
3680
|
}
|
|
3656
3681
|
processExistingToolCall(index, toolCallDelta) {
|
|
3657
|
-
var
|
|
3682
|
+
var _a3;
|
|
3658
3683
|
const toolCall = this.toolCalls[index];
|
|
3659
3684
|
if (toolCall.hasFinished) {
|
|
3660
3685
|
return;
|
|
3661
3686
|
}
|
|
3662
|
-
if (((
|
|
3687
|
+
if (((_a3 = toolCallDelta.function) == null ? void 0 : _a3.arguments) != null) {
|
|
3663
3688
|
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
3664
3689
|
this.controller.enqueue({
|
|
3665
3690
|
type: "tool-input-delta",
|
|
@@ -3669,18 +3694,18 @@ var StreamingToolCallTracker = class {
|
|
|
3669
3694
|
}
|
|
3670
3695
|
}
|
|
3671
3696
|
finishToolCall(toolCall) {
|
|
3672
|
-
var
|
|
3697
|
+
var _a3, _b3;
|
|
3673
3698
|
this.controller.enqueue({
|
|
3674
3699
|
type: "tool-input-end",
|
|
3675
3700
|
id: toolCall.id
|
|
3676
3701
|
});
|
|
3677
|
-
const providerMetadata = (
|
|
3702
|
+
const providerMetadata = (_a3 = this.buildToolCallProviderMetadata) == null ? void 0 : _a3.call(
|
|
3678
3703
|
this,
|
|
3679
3704
|
toolCall.metadata
|
|
3680
3705
|
);
|
|
3681
3706
|
this.controller.enqueue({
|
|
3682
3707
|
type: "tool-call",
|
|
3683
|
-
toolCallId: (
|
|
3708
|
+
toolCallId: (_b3 = toolCall.id) != null ? _b3 : this._generateId(),
|
|
3684
3709
|
toolName: toolCall.function.name,
|
|
3685
3710
|
input: toolCall.function.arguments,
|
|
3686
3711
|
...providerMetadata ? { providerMetadata } : {}
|
|
@@ -3887,6 +3912,7 @@ export {
|
|
|
3887
3912
|
TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE,
|
|
3888
3913
|
TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE,
|
|
3889
3914
|
EventSourceParserStream2 as EventSourceParserStream,
|
|
3915
|
+
SerializationError,
|
|
3890
3916
|
StreamingToolCallTracker,
|
|
3891
3917
|
VERSION,
|
|
3892
3918
|
WORKFLOW_DESERIALIZE,
|