@ai-sdk/provider-utils 5.0.4 → 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 +8 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -0
- package/src/websocket.ts +61 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 5.0.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2221,6 +2221,31 @@ declare function safeValidateTypes<OBJECT>({ value, schema, context, }: {
|
|
|
2221
2221
|
|
|
2222
2222
|
declare const VERSION: string;
|
|
2223
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
|
+
|
|
2224
2249
|
/**
|
|
2225
2250
|
* Appends suffix parts to the `user-agent` header.
|
|
2226
2251
|
* If a `user-agent` header already exists, the suffix parts are appended to it.
|
|
@@ -2386,4 +2411,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2386
2411
|
dynamic?: boolean;
|
|
2387
2412
|
}
|
|
2388
2413
|
|
|
2389
|
-
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, secureJsonParse, 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,
|
|
@@ -3608,6 +3640,7 @@ export {
|
|
|
3608
3640
|
secureJsonParse,
|
|
3609
3641
|
serializeModelOptions,
|
|
3610
3642
|
stripFileExtension,
|
|
3643
|
+
toWebSocketUrl,
|
|
3611
3644
|
tool,
|
|
3612
3645
|
validateDownloadUrl,
|
|
3613
3646
|
validateTypes,
|