@ai-sdk/provider-utils 5.0.0-beta.20 → 5.0.0-beta.21
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 +6 -0
- package/dist/index.d.ts +36 -31
- package/dist/index.js +10 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/get-error-message.ts +1 -15
- package/src/types/executable-tool.ts +17 -0
- package/src/types/execute-tool.ts +22 -23
- package/src/types/index.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ImageModelV4File, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV4Prompt, LanguageModelV4FilePart, SharedV4ProviderReference, LanguageModelV4CallOptions, SharedV4Warning, SharedV4ProviderOptions, JSONObject, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
|
+
export { getErrorMessage } from '@ai-sdk/provider';
|
|
2
3
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
3
4
|
export * from '@standard-schema/spec';
|
|
4
5
|
import * as z3 from 'zod/v3';
|
|
@@ -199,8 +200,6 @@ type IdGenerator = () => string;
|
|
|
199
200
|
*/
|
|
200
201
|
declare const generateId: IdGenerator;
|
|
201
202
|
|
|
202
|
-
declare function getErrorMessage(error: unknown | undefined): string;
|
|
203
|
-
|
|
204
203
|
/**
|
|
205
204
|
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
206
205
|
*/
|
|
@@ -1549,35 +1548,15 @@ declare function withUserAgentSuffix(headers: HeadersInit | Record<string, strin
|
|
|
1549
1548
|
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
|
1550
1549
|
|
|
1551
1550
|
/**
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1554
|
-
* This generator yields intermediate ("preliminary") outputs as they're produced, allowing callers
|
|
1555
|
-
* to stream partial tool results before completion. When execution is finished, it yields a final output,
|
|
1556
|
-
* ensuring all consumers receive a conclusive result.
|
|
1557
|
-
*
|
|
1558
|
-
* - If the tool's `execute` function returns an `AsyncIterable`, all intermediate values are yielded
|
|
1559
|
-
* as `{ type: "preliminary", output }` except the last, which is yielded as `{ type: "final", output }`.
|
|
1560
|
-
* - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
|
|
1561
|
-
*
|
|
1562
|
-
* @template INPUT Input type for the tool execution.
|
|
1563
|
-
* @template OUTPUT Output type for the tool execution.
|
|
1564
|
-
* @template CONTEXT Context object extension for execution (extends Context).
|
|
1565
|
-
* @param params.execute The tool execute function.
|
|
1566
|
-
* @param params.input Input value to pass to the execute function.
|
|
1567
|
-
* @param params.options Additional options for tool execution.
|
|
1568
|
-
* @yields An object containing either a preliminary or final output from the tool.
|
|
1551
|
+
* A tool that is guaranteed to expose an execute function.
|
|
1569
1552
|
*/
|
|
1570
|
-
|
|
1571
|
-
execute:
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
} | {
|
|
1578
|
-
type: 'final';
|
|
1579
|
-
output: OUTPUT;
|
|
1580
|
-
}>;
|
|
1553
|
+
type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
|
|
1554
|
+
execute: NonNullable<TOOL['execute']>;
|
|
1555
|
+
};
|
|
1556
|
+
/**
|
|
1557
|
+
* Checks whether a tool exposes an execute function.
|
|
1558
|
+
*/
|
|
1559
|
+
declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
|
|
1581
1560
|
|
|
1582
1561
|
/**
|
|
1583
1562
|
* Infer the context type of a tool.
|
|
@@ -1594,6 +1573,32 @@ type InferToolInput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<infer
|
|
|
1594
1573
|
*/
|
|
1595
1574
|
type InferToolOutput<TOOL extends Tool<any, any, any>> = TOOL extends Tool<any, infer OUTPUT, any> ? OUTPUT : never;
|
|
1596
1575
|
|
|
1576
|
+
/**
|
|
1577
|
+
* Executes a tool function and normalizes its results into a stream of outputs.
|
|
1578
|
+
*
|
|
1579
|
+
* - If the tool's `execute` function returns an `AsyncIterable`, each yielded value is emitted as
|
|
1580
|
+
* `{ type: "preliminary", output }`. After iteration completes, the last yielded value is emitted
|
|
1581
|
+
* again as `{ type: "final", output }`.
|
|
1582
|
+
* - If the tool returns a direct value or Promise, a single `{ type: "final", output }` is yielded.
|
|
1583
|
+
*
|
|
1584
|
+
* @param params.tool The tool whose `execute` function should be invoked.
|
|
1585
|
+
* @param params.input The input value to pass to the tool.
|
|
1586
|
+
* @param params.options Additional options for tool execution.
|
|
1587
|
+
* @yields A preliminary output for each streamed value, followed by a final output, or a single final
|
|
1588
|
+
* output for non-streaming tools.
|
|
1589
|
+
*/
|
|
1590
|
+
declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
|
|
1591
|
+
tool: ExecutableTool<TOOL>;
|
|
1592
|
+
input: InferToolInput<TOOL>;
|
|
1593
|
+
options: ToolExecutionOptions<InferToolContext<TOOL>>;
|
|
1594
|
+
}): AsyncGenerator<{
|
|
1595
|
+
type: 'preliminary';
|
|
1596
|
+
output: InferToolOutput<TOOL>;
|
|
1597
|
+
} | {
|
|
1598
|
+
type: 'final';
|
|
1599
|
+
output: InferToolOutput<TOOL>;
|
|
1600
|
+
}>;
|
|
1601
|
+
|
|
1597
1602
|
/**
|
|
1598
1603
|
* A mapping of tool names to tool definitions.
|
|
1599
1604
|
*/
|
|
@@ -1684,4 +1689,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
1684
1689
|
dynamic?: boolean;
|
|
1685
1690
|
}
|
|
1686
1691
|
|
|
1687
|
-
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, 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 ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId,
|
|
1692
|
+
export { type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type ExecutableTool, type FetchFunction, type FilePart, type FlexibleSchema, 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 ProviderOptions, type ProviderReference, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, 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, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, downloadBlob, dynamicTool, executeTool, extractResponseHeaders, generateId, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isCustomReasoning, isExecutableTool, isNonNullable, isParsableJson, isProviderReference, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, removeUndefinedEntries, resolve, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, stripFileExtension, tool, validateDownloadUrl, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
package/dist/index.js
CHANGED
|
@@ -445,18 +445,7 @@ var createIdGenerator = ({
|
|
|
445
445
|
var generateId = createIdGenerator();
|
|
446
446
|
|
|
447
447
|
// src/get-error-message.ts
|
|
448
|
-
|
|
449
|
-
if (error == null) {
|
|
450
|
-
return "unknown error";
|
|
451
|
-
}
|
|
452
|
-
if (typeof error === "string") {
|
|
453
|
-
return error;
|
|
454
|
-
}
|
|
455
|
-
if (error instanceof Error) {
|
|
456
|
-
return error.toString();
|
|
457
|
-
}
|
|
458
|
-
return JSON.stringify(error);
|
|
459
|
-
}
|
|
448
|
+
import { getErrorMessage } from "@ai-sdk/provider";
|
|
460
449
|
|
|
461
450
|
// src/get-from-api.ts
|
|
462
451
|
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
@@ -577,7 +566,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
577
566
|
}
|
|
578
567
|
|
|
579
568
|
// src/version.ts
|
|
580
|
-
var VERSION = true ? "5.0.0-beta.
|
|
569
|
+
var VERSION = true ? "5.0.0-beta.21" : "0.0.0-test";
|
|
581
570
|
|
|
582
571
|
// src/get-from-api.ts
|
|
583
572
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2794,11 +2783,11 @@ function isAsyncIterable(obj) {
|
|
|
2794
2783
|
|
|
2795
2784
|
// src/types/execute-tool.ts
|
|
2796
2785
|
async function* executeTool({
|
|
2797
|
-
|
|
2786
|
+
tool: tool2,
|
|
2798
2787
|
input,
|
|
2799
2788
|
options
|
|
2800
2789
|
}) {
|
|
2801
|
-
const result = execute(input, options);
|
|
2790
|
+
const result = tool2.execute(input, options);
|
|
2802
2791
|
if (isAsyncIterable(result)) {
|
|
2803
2792
|
let lastOutput;
|
|
2804
2793
|
for await (const output of result) {
|
|
@@ -2811,6 +2800,11 @@ async function* executeTool({
|
|
|
2811
2800
|
}
|
|
2812
2801
|
}
|
|
2813
2802
|
|
|
2803
|
+
// src/types/executable-tool.ts
|
|
2804
|
+
function isExecutableTool(tool2) {
|
|
2805
|
+
return tool2 != null && typeof tool2.execute === "function";
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2814
2808
|
// src/index.ts
|
|
2815
2809
|
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
2816
2810
|
import {
|
|
@@ -2853,6 +2847,7 @@ export {
|
|
|
2853
2847
|
injectJsonInstructionIntoMessages,
|
|
2854
2848
|
isAbortError,
|
|
2855
2849
|
isCustomReasoning,
|
|
2850
|
+
isExecutableTool,
|
|
2856
2851
|
isNonNullable,
|
|
2857
2852
|
isParsableJson,
|
|
2858
2853
|
isProviderReference,
|