@ai-sdk/provider-utils 5.0.4 → 5.0.6

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - ac306ed: Fix `StreamingToolCallTracker` finalizing streaming tool calls on parsable partial JSON. Tool calls now only finalize during stream flush, restoring the behavior of #13137: a parsable argument buffer can still be the prefix of a longer argument string, so finalizing early could act on truncated tool inputs.
8
+
9
+ ## 5.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
14
+ - Updated dependencies [5c5c0f5]
15
+ - @ai-sdk/provider@4.0.2
16
+
3
17
  ## 5.0.4
4
18
 
5
19
  ### 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.4" : "0.0.0-test";
974
+ var VERSION = true ? "5.0.6" : "0.0.0-test";
975
975
 
976
976
  // src/get-from-api.ts
977
977
  var getOriginalFetch = () => globalThis.fetch;
@@ -3438,9 +3438,6 @@ var StreamingToolCallTracker = class {
3438
3438
  delta: toolCall.function.arguments
3439
3439
  });
3440
3440
  }
3441
- if (isParsableJson(toolCall.function.arguments)) {
3442
- this.finishToolCall(toolCall);
3443
- }
3444
3441
  }
3445
3442
  processExistingToolCall(index, toolCallDelta) {
3446
3443
  var _a2;
@@ -3456,9 +3453,6 @@ var StreamingToolCallTracker = class {
3456
3453
  delta: toolCallDelta.function.arguments
3457
3454
  });
3458
3455
  }
3459
- if (isParsableJson(toolCall.function.arguments)) {
3460
- this.finishToolCall(toolCall);
3461
- }
3462
3456
  }
3463
3457
  finishToolCall(toolCall) {
3464
3458
  var _a2, _b2;
@@ -3487,6 +3481,36 @@ function stripFileExtension(filename) {
3487
3481
  return firstDotIndex === -1 ? filename : filename.slice(0, firstDotIndex);
3488
3482
  }
3489
3483
 
3484
+ // src/websocket.ts
3485
+ function getWebSocketConstructor(webSocket) {
3486
+ const WebSocketConstructor = webSocket != null ? webSocket : globalThis.WebSocket;
3487
+ if (WebSocketConstructor == null) {
3488
+ throw new Error("No WebSocket implementation available.");
3489
+ }
3490
+ return WebSocketConstructor;
3491
+ }
3492
+ function toWebSocketUrl(url) {
3493
+ const wsUrl = new URL(url);
3494
+ if (wsUrl.protocol === "http:") {
3495
+ wsUrl.protocol = "ws:";
3496
+ } else if (wsUrl.protocol === "https:") {
3497
+ wsUrl.protocol = "wss:";
3498
+ }
3499
+ return wsUrl;
3500
+ }
3501
+ var textDecoder2 = new TextDecoder();
3502
+ async function readWebSocketMessageText(data) {
3503
+ if (typeof data === "string") return data;
3504
+ if (data instanceof ArrayBuffer) return textDecoder2.decode(data);
3505
+ if (ArrayBuffer.isView(data)) {
3506
+ return textDecoder2.decode(data);
3507
+ }
3508
+ if (typeof Blob !== "undefined" && data instanceof Blob) {
3509
+ return data.text();
3510
+ }
3511
+ return String(data);
3512
+ }
3513
+
3490
3514
  // src/without-trailing-slash.ts
3491
3515
  function withoutTrailingSlash(url) {
3492
3516
  return url == null ? void 0 : url.replace(/\/$/, "");
@@ -3570,6 +3594,7 @@ export {
3570
3594
  getFromApi,
3571
3595
  getRuntimeEnvironmentUserAgent,
3572
3596
  getTopLevelMediaType,
3597
+ getWebSocketConstructor,
3573
3598
  injectJsonInstructionIntoMessages,
3574
3599
  isAbortError,
3575
3600
  isBrowserRuntime,
@@ -3598,6 +3623,7 @@ export {
3598
3623
  postJsonToApi,
3599
3624
  postToApi,
3600
3625
  readResponseWithSizeLimit,
3626
+ readWebSocketMessageText,
3601
3627
  removeUndefinedEntries,
3602
3628
  resolve,
3603
3629
  resolveFullMediaType,
@@ -3608,6 +3634,7 @@ export {
3608
3634
  secureJsonParse,
3609
3635
  serializeModelOptions,
3610
3636
  stripFileExtension,
3637
+ toWebSocketUrl,
3611
3638
  tool,
3612
3639
  validateDownloadUrl,
3613
3640
  validateTypes,