@ai-sdk/provider-utils
Advanced tools
| export type WebSocketLike = { | ||
| readyState: number; | ||
| send(data: string | Uint8Array | ArrayBuffer): void; | ||
| close(code?: number, reason?: string): void; | ||
| onopen: ((event: unknown) => void) | null; | ||
| onmessage: ((event: { data: unknown }) => void) | null; | ||
| onerror: ((event: unknown) => void) | null; | ||
| onclose: ((event: unknown) => void) | null; | ||
| }; | ||
| export type WebSocketConstructor = new ( | ||
| url: string | URL, | ||
| protocols?: string | string[], | ||
| options?: { | ||
| headers?: Record<string, string | undefined>; | ||
| }, | ||
| ) => WebSocketLike; | ||
| export function getWebSocketConstructor( | ||
| webSocket: WebSocketConstructor | undefined, | ||
| ): WebSocketConstructor { | ||
| const WebSocketConstructor = | ||
| webSocket ?? (globalThis.WebSocket as unknown as WebSocketConstructor); | ||
| if (WebSocketConstructor == null) { | ||
| throw new Error('No WebSocket implementation available.'); | ||
| } | ||
| return WebSocketConstructor; | ||
| } | ||
| /** | ||
| * Converts an http(s) URL to the corresponding ws(s) URL. | ||
| */ | ||
| export function toWebSocketUrl(url: string | URL): URL { | ||
| const wsUrl = new URL(url); | ||
| if (wsUrl.protocol === 'http:') { | ||
| wsUrl.protocol = 'ws:'; | ||
| } else if (wsUrl.protocol === 'https:') { | ||
| wsUrl.protocol = 'wss:'; | ||
| } | ||
| return wsUrl; | ||
| } | ||
| const textDecoder = new TextDecoder(); | ||
| /** | ||
| * Reads WebSocket message data as text, handling string, binary, | ||
| * and Blob payloads. | ||
| */ | ||
| export async function readWebSocketMessageText(data: unknown): Promise<string> { | ||
| if (typeof data === 'string') return data; | ||
| if (data instanceof ArrayBuffer) return textDecoder.decode(data); | ||
| if (ArrayBuffer.isView(data)) { | ||
| return textDecoder.decode(data); | ||
| } | ||
| if (typeof Blob !== 'undefined' && data instanceof Blob) { | ||
| return data.text(); | ||
| } | ||
| return String(data); | ||
| } |
+8
-0
| # @ai-sdk/provider-utils | ||
| ## 5.0.5 | ||
| ### Patch Changes | ||
| - 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT. | ||
| - Updated dependencies [5c5c0f5] | ||
| - @ai-sdk/provider@4.0.2 | ||
| ## 5.0.4 | ||
@@ -4,0 +12,0 @@ |
+2
-2
| { | ||
| "name": "@ai-sdk/provider-utils", | ||
| "version": "5.0.4", | ||
| "version": "5.0.5", | ||
| "type": "module", | ||
@@ -38,3 +38,3 @@ "license": "Apache-2.0", | ||
| "eventsource-parser": "^3.0.8", | ||
| "@ai-sdk/provider": "4.0.1" | ||
| "@ai-sdk/provider": "4.0.2" | ||
| }, | ||
@@ -41,0 +41,0 @@ "devDependencies": { |
+7
-0
@@ -98,2 +98,9 @@ export { asArray } from './as-array'; | ||
| export { VERSION } from './version'; | ||
| export { | ||
| getWebSocketConstructor, | ||
| readWebSocketMessageText, | ||
| toWebSocketUrl, | ||
| type WebSocketConstructor, | ||
| type WebSocketLike, | ||
| } from './websocket'; | ||
| export { withUserAgentSuffix } from './with-user-agent-suffix'; | ||
@@ -100,0 +107,0 @@ export * from './without-trailing-slash'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
763567
0.89%154
0.65%13191
0.9%+ Added
- Removed
Updated