@ai-sdk/provider-utils 5.0.15 → 5.0.16
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 +20 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/is-record.ts +6 -0
- package/src/transcription-stream-envelope.ts +11 -14
- package/src/types/index.ts +6 -0
- package/src/types/tool-caller.ts +36 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1191,6 +1191,11 @@ declare function isNonNullable<T>(value: T | undefined | null): value is NonNull
|
|
|
1191
1191
|
*/
|
|
1192
1192
|
declare function isProviderReference(data: unknown): data is SharedV4ProviderReference;
|
|
1193
1193
|
|
|
1194
|
+
/**
|
|
1195
|
+
* Checks whether a value is a non-null, non-array object.
|
|
1196
|
+
*/
|
|
1197
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
1198
|
+
|
|
1194
1199
|
/**
|
|
1195
1200
|
* Checks if the given URL is supported natively by the model.
|
|
1196
1201
|
*
|
|
@@ -2604,6 +2609,20 @@ interface ToolCall<NAME extends string, INPUT> {
|
|
|
2604
2609
|
dynamic?: boolean;
|
|
2605
2610
|
}
|
|
2606
2611
|
|
|
2612
|
+
declare const toolCallerSymbol: unique symbol;
|
|
2613
|
+
type ToolCallerDefinition = {
|
|
2614
|
+
type: 'local';
|
|
2615
|
+
bind: (tools: ToolSet) => Tool;
|
|
2616
|
+
} | {
|
|
2617
|
+
type: 'provider';
|
|
2618
|
+
prepareProviderOptions: (providerOptions: ProviderOptions | undefined) => ProviderOptions;
|
|
2619
|
+
};
|
|
2620
|
+
type ToolCallerTool<TOOL extends Tool = Tool> = TOOL & {
|
|
2621
|
+
readonly [toolCallerSymbol]: ToolCallerDefinition;
|
|
2622
|
+
};
|
|
2623
|
+
declare function toolCaller<TOOL extends Tool>(tool: TOOL, definition: ToolCallerDefinition): ToolCallerTool<TOOL>;
|
|
2624
|
+
declare function getToolCaller(tool: Tool | undefined): ToolCallerDefinition | undefined;
|
|
2625
|
+
|
|
2607
2626
|
/**
|
|
2608
2627
|
* Typed tool result that is returned by `generateText` and `streamText`.
|
|
2609
2628
|
* It contains the tool call ID, the tool name, the tool arguments, and the tool result.
|
|
@@ -2635,4 +2654,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2635
2654
|
dynamic?: boolean;
|
|
2636
2655
|
}
|
|
2637
2656
|
|
|
2638
|
-
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 };
|
|
2657
|
+
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 ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, 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, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isRecord, 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
|
@@ -1294,7 +1294,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1294
1294
|
}
|
|
1295
1295
|
|
|
1296
1296
|
// src/version.ts
|
|
1297
|
-
var VERSION = true ? "5.0.
|
|
1297
|
+
var VERSION = true ? "5.0.16" : "0.0.0-test";
|
|
1298
1298
|
|
|
1299
1299
|
// src/get-from-api.ts
|
|
1300
1300
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1433,6 +1433,11 @@ function isProviderReference(data) {
|
|
|
1433
1433
|
return typeof data === "object" && data !== null && !(data instanceof Uint8Array) && !(data instanceof URL) && !(data instanceof ArrayBuffer) && !isBuffer(data) && !("type" in data);
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
|
+
// src/is-record.ts
|
|
1437
|
+
function isRecord(value) {
|
|
1438
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1436
1441
|
// src/is-url-supported.ts
|
|
1437
1442
|
function isUrlSupported({
|
|
1438
1443
|
mediaType,
|
|
@@ -3918,15 +3923,15 @@ function parseTranscriptionStreamPart(text) {
|
|
|
3918
3923
|
case "stream-start":
|
|
3919
3924
|
return Array.isArray(part.warnings) && part.warnings.every(isWarning) ? part : void 0;
|
|
3920
3925
|
case "transcript-delta":
|
|
3921
|
-
return isString(part.delta) && isOptional(part.id, isString) && isOptional(part.providerMetadata,
|
|
3926
|
+
return isString(part.delta) && isOptional(part.id, isString) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
3922
3927
|
case "transcript-partial":
|
|
3923
|
-
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata,
|
|
3928
|
+
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
3924
3929
|
case "transcript-final":
|
|
3925
|
-
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.endSecond, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata,
|
|
3930
|
+
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.endSecond, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
3926
3931
|
case "finish":
|
|
3927
|
-
return isString(part.text) && Array.isArray(part.segments) && part.segments.every(isSegment) && isOptional(part.language, isString) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.providerMetadata,
|
|
3932
|
+
return isString(part.text) && Array.isArray(part.segments) && part.segments.every(isSegment) && isOptional(part.language, isString) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
3928
3933
|
case "response-metadata": {
|
|
3929
|
-
if (!(isOptional(part.modelId, isString) && isOptional(part.headers,
|
|
3934
|
+
if (!(isOptional(part.modelId, isString) && isOptional(part.headers, isRecord))) {
|
|
3930
3935
|
return void 0;
|
|
3931
3936
|
}
|
|
3932
3937
|
const timestamp = part.timestamp;
|
|
@@ -3956,14 +3961,11 @@ function isNumber(value) {
|
|
|
3956
3961
|
function isOptional(value, check) {
|
|
3957
3962
|
return value === void 0 || check(value);
|
|
3958
3963
|
}
|
|
3959
|
-
function isPlainObject(value) {
|
|
3960
|
-
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
3961
|
-
}
|
|
3962
3964
|
function isWarning(value) {
|
|
3963
|
-
return
|
|
3965
|
+
return isRecord(value) && isString(value.type);
|
|
3964
3966
|
}
|
|
3965
3967
|
function isSegment(value) {
|
|
3966
|
-
return
|
|
3968
|
+
return isRecord(value) && isString(value.text) && isNumber(value.startSecond) && isNumber(value.endSecond);
|
|
3967
3969
|
}
|
|
3968
3970
|
|
|
3969
3971
|
// src/validate-base-url.ts
|
|
@@ -4012,6 +4014,17 @@ async function* executeTool({
|
|
|
4012
4014
|
}
|
|
4013
4015
|
}
|
|
4014
4016
|
|
|
4017
|
+
// src/types/tool-caller.ts
|
|
4018
|
+
var toolCallerSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.experimental.toolCaller");
|
|
4019
|
+
function toolCaller(tool2, definition) {
|
|
4020
|
+
return Object.defineProperty({ ...tool2 }, toolCallerSymbol, {
|
|
4021
|
+
value: definition
|
|
4022
|
+
});
|
|
4023
|
+
}
|
|
4024
|
+
function getToolCaller(tool2) {
|
|
4025
|
+
return tool2 == null ? void 0 : tool2[toolCallerSymbol];
|
|
4026
|
+
}
|
|
4027
|
+
|
|
4015
4028
|
// src/index.ts
|
|
4016
4029
|
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
4017
4030
|
import {
|
|
@@ -4056,9 +4069,11 @@ export {
|
|
|
4056
4069
|
downloadBlob,
|
|
4057
4070
|
dynamicTool,
|
|
4058
4071
|
executeTool,
|
|
4072
|
+
getToolCaller as experimental_getToolCaller,
|
|
4059
4073
|
parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame,
|
|
4060
4074
|
parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart,
|
|
4061
4075
|
serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart,
|
|
4076
|
+
toolCaller as experimental_toolCaller,
|
|
4062
4077
|
extractLines,
|
|
4063
4078
|
extractResponseHeaders,
|
|
4064
4079
|
fetchWithValidatedRedirects,
|
|
@@ -4079,6 +4094,7 @@ export {
|
|
|
4079
4094
|
isNonNullable,
|
|
4080
4095
|
isParsableJson,
|
|
4081
4096
|
isProviderReference,
|
|
4097
|
+
isRecord,
|
|
4082
4098
|
isSameOrigin,
|
|
4083
4099
|
isUrlSupported,
|
|
4084
4100
|
jsonSchema,
|