@ai-sdk/provider-utils 5.0.3 → 5.0.5
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 +14 -0
- package/dist/index.d.ts +28 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +8 -0
- package/src/websocket.ts +61 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
|
|
8
|
+
- Updated dependencies [5c5c0f5]
|
|
9
|
+
- @ai-sdk/provider@4.0.2
|
|
10
|
+
|
|
11
|
+
## 5.0.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- c6f5e62: Prevent prototype pollution when synchronously parsing provider JSON inputs and expose `secureJsonParse` from provider-utils.
|
|
16
|
+
|
|
3
17
|
## 5.0.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2079,6 +2079,8 @@ declare function serializeModelOptions<CONFIG extends {
|
|
|
2079
2079
|
config: JSONObject;
|
|
2080
2080
|
};
|
|
2081
2081
|
|
|
2082
|
+
declare function secureJsonParse(text: string): any;
|
|
2083
|
+
|
|
2082
2084
|
/**
|
|
2083
2085
|
* Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
|
|
2084
2086
|
*/
|
|
@@ -2219,6 +2221,31 @@ declare function safeValidateTypes<OBJECT>({ value, schema, context, }: {
|
|
|
2219
2221
|
|
|
2220
2222
|
declare const VERSION: string;
|
|
2221
2223
|
|
|
2224
|
+
type WebSocketLike = {
|
|
2225
|
+
readyState: number;
|
|
2226
|
+
send(data: string | Uint8Array | ArrayBuffer): void;
|
|
2227
|
+
close(code?: number, reason?: string): void;
|
|
2228
|
+
onopen: ((event: unknown) => void) | null;
|
|
2229
|
+
onmessage: ((event: {
|
|
2230
|
+
data: unknown;
|
|
2231
|
+
}) => void) | null;
|
|
2232
|
+
onerror: ((event: unknown) => void) | null;
|
|
2233
|
+
onclose: ((event: unknown) => void) | null;
|
|
2234
|
+
};
|
|
2235
|
+
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[], options?: {
|
|
2236
|
+
headers?: Record<string, string | undefined>;
|
|
2237
|
+
}) => WebSocketLike;
|
|
2238
|
+
declare function getWebSocketConstructor(webSocket: WebSocketConstructor | undefined): WebSocketConstructor;
|
|
2239
|
+
/**
|
|
2240
|
+
* Converts an http(s) URL to the corresponding ws(s) URL.
|
|
2241
|
+
*/
|
|
2242
|
+
declare function toWebSocketUrl(url: string | URL): URL;
|
|
2243
|
+
/**
|
|
2244
|
+
* Reads WebSocket message data as text, handling string, binary,
|
|
2245
|
+
* and Blob payloads.
|
|
2246
|
+
*/
|
|
2247
|
+
declare function readWebSocketMessageText(data: unknown): Promise<string>;
|
|
2248
|
+
|
|
2222
2249
|
/**
|
|
2223
2250
|
* Appends suffix parts to the `user-agent` header.
|
|
2224
2251
|
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
|
@@ -2384,4 +2411,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2384
2411
|
dynamic?: boolean;
|
|
2385
2412
|
}
|
|
2386
2413
|
|
|
2387
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, 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, asArray, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, 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, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
2414
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, 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 WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, 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, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -971,7 +971,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
971
971
|
}
|
|
972
972
|
|
|
973
973
|
// src/version.ts
|
|
974
|
-
var VERSION = true ? "5.0.
|
|
974
|
+
var VERSION = true ? "5.0.5" : "0.0.0-test";
|
|
975
975
|
|
|
976
976
|
// src/get-from-api.ts
|
|
977
977
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -3487,6 +3487,36 @@ function stripFileExtension(filename) {
|
|
|
3487
3487
|
return firstDotIndex === -1 ? filename : filename.slice(0, firstDotIndex);
|
|
3488
3488
|
}
|
|
3489
3489
|
|
|
3490
|
+
// src/websocket.ts
|
|
3491
|
+
function getWebSocketConstructor(webSocket) {
|
|
3492
|
+
const WebSocketConstructor = webSocket != null ? webSocket : globalThis.WebSocket;
|
|
3493
|
+
if (WebSocketConstructor == null) {
|
|
3494
|
+
throw new Error("No WebSocket implementation available.");
|
|
3495
|
+
}
|
|
3496
|
+
return WebSocketConstructor;
|
|
3497
|
+
}
|
|
3498
|
+
function toWebSocketUrl(url) {
|
|
3499
|
+
const wsUrl = new URL(url);
|
|
3500
|
+
if (wsUrl.protocol === "http:") {
|
|
3501
|
+
wsUrl.protocol = "ws:";
|
|
3502
|
+
} else if (wsUrl.protocol === "https:") {
|
|
3503
|
+
wsUrl.protocol = "wss:";
|
|
3504
|
+
}
|
|
3505
|
+
return wsUrl;
|
|
3506
|
+
}
|
|
3507
|
+
var textDecoder2 = new TextDecoder();
|
|
3508
|
+
async function readWebSocketMessageText(data) {
|
|
3509
|
+
if (typeof data === "string") return data;
|
|
3510
|
+
if (data instanceof ArrayBuffer) return textDecoder2.decode(data);
|
|
3511
|
+
if (ArrayBuffer.isView(data)) {
|
|
3512
|
+
return textDecoder2.decode(data);
|
|
3513
|
+
}
|
|
3514
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
3515
|
+
return data.text();
|
|
3516
|
+
}
|
|
3517
|
+
return String(data);
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3490
3520
|
// src/without-trailing-slash.ts
|
|
3491
3521
|
function withoutTrailingSlash(url) {
|
|
3492
3522
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -3570,6 +3600,7 @@ export {
|
|
|
3570
3600
|
getFromApi,
|
|
3571
3601
|
getRuntimeEnvironmentUserAgent,
|
|
3572
3602
|
getTopLevelMediaType,
|
|
3603
|
+
getWebSocketConstructor,
|
|
3573
3604
|
injectJsonInstructionIntoMessages,
|
|
3574
3605
|
isAbortError,
|
|
3575
3606
|
isBrowserRuntime,
|
|
@@ -3598,6 +3629,7 @@ export {
|
|
|
3598
3629
|
postJsonToApi,
|
|
3599
3630
|
postToApi,
|
|
3600
3631
|
readResponseWithSizeLimit,
|
|
3632
|
+
readWebSocketMessageText,
|
|
3601
3633
|
removeUndefinedEntries,
|
|
3602
3634
|
resolve,
|
|
3603
3635
|
resolveFullMediaType,
|
|
@@ -3605,8 +3637,10 @@ export {
|
|
|
3605
3637
|
retryWithExponentialBackoff,
|
|
3606
3638
|
safeParseJSON,
|
|
3607
3639
|
safeValidateTypes,
|
|
3640
|
+
secureJsonParse,
|
|
3608
3641
|
serializeModelOptions,
|
|
3609
3642
|
stripFileExtension,
|
|
3643
|
+
toWebSocketUrl,
|
|
3610
3644
|
tool,
|
|
3611
3645
|
validateDownloadUrl,
|
|
3612
3646
|
validateTypes,
|