@ai-sdk/provider-utils 4.0.0-beta.53 → 4.0.0-beta.55

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
+ ## 4.0.0-beta.55
4
+
5
+ ### Patch Changes
6
+
7
+ - 50b70d6: feat(anthropic): add programmatic tool calling
8
+
9
+ ## 4.0.0-beta.54
10
+
11
+ ### Patch Changes
12
+
13
+ - 9061dc0: feat: image editing
14
+ - Updated dependencies [9061dc0]
15
+ - @ai-sdk/provider@3.0.0-beta.28
16
+
3
17
  ## 4.0.0-beta.53
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -91,6 +91,76 @@ declare function extractResponseHeaders(response: Response): {
91
91
  [k: string]: string;
92
92
  };
93
93
 
94
+ /**
95
+ * Convert an ImageModelV3File to a URL or data URI string.
96
+ *
97
+ * If the file is a URL, it returns the URL as-is.
98
+ * If the file is base64 data, it returns a data URI with the base64 data.
99
+ * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
100
+ */
101
+ declare function convertImageModelFileToDataUri(file: ImageModelV3File): string;
102
+
103
+ /**
104
+ * Converts an input object to FormData for multipart/form-data requests.
105
+ *
106
+ * Handles the following cases:
107
+ * - `null` or `undefined` values are skipped
108
+ * - Arrays with a single element are appended as a single value
109
+ * - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
110
+ * unless `useArrayBrackets` is set to `false`
111
+ * - All other values are appended directly
112
+ *
113
+ * @param input - The input object to convert. Use a generic type for type validation.
114
+ * @param options - Optional configuration object.
115
+ * @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
116
+ * Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
117
+ * @returns A FormData object containing the input values.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * type MyInput = {
122
+ * model: string;
123
+ * prompt: string;
124
+ * images: Blob[];
125
+ * };
126
+ *
127
+ * const formData = convertToFormData<MyInput>({
128
+ * model: 'gpt-image-1',
129
+ * prompt: 'A cat',
130
+ * images: [blob1, blob2],
131
+ * });
132
+ * ```
133
+ */
134
+ declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
135
+ useArrayBrackets?: boolean;
136
+ }): FormData;
137
+
138
+ /**
139
+ * Download a file from a URL and return it as a Blob.
140
+ *
141
+ * @param url - The URL to download from.
142
+ * @returns A Promise that resolves to the downloaded Blob.
143
+ *
144
+ * @throws DownloadError if the download fails.
145
+ */
146
+ declare function downloadBlob(url: string): Promise<Blob>;
147
+
148
+ declare const symbol: unique symbol;
149
+ declare class DownloadError extends AISDKError {
150
+ private readonly [symbol];
151
+ readonly url: string;
152
+ readonly statusCode?: number;
153
+ readonly statusText?: string;
154
+ constructor({ url, statusCode, statusText, cause, message, }: {
155
+ url: string;
156
+ statusCode?: number;
157
+ statusText?: string;
158
+ message?: string;
159
+ cause?: unknown;
160
+ });
161
+ static isInstance(error: unknown): error is DownloadError;
162
+ }
163
+
94
164
  /**
95
165
  * Fetch function type (standardizes the version of fetch used).
96
166
  */
@@ -1042,6 +1112,20 @@ The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
1042
1112
  The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1043
1113
  */
1044
1114
  args: Record<string, unknown>;
1115
+ /**
1116
+ * Whether this provider-executed tool supports deferred results.
1117
+ *
1118
+ * When true, the tool result may not be returned in the same turn as the
1119
+ * tool call (e.g., when using programmatic tool calling where a server tool
1120
+ * triggers a client-executed tool, and the server tool's result is deferred
1121
+ * until the client tool is resolved).
1122
+ *
1123
+ * This flag allows the AI SDK to handle tool results that arrive without
1124
+ * a matching tool call in the current response.
1125
+ *
1126
+ * @default false
1127
+ */
1128
+ supportsDeferredResults?: boolean;
1045
1129
  });
1046
1130
  /**
1047
1131
  * Infer the input type of a tool.
@@ -1114,10 +1198,21 @@ type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (
1114
1198
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1115
1199
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1116
1200
  }) => Tool<INPUT, OUTPUT>;
1117
- declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, }: {
1201
+ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
1118
1202
  id: `${string}.${string}`;
1119
1203
  inputSchema: FlexibleSchema<INPUT>;
1120
1204
  outputSchema: FlexibleSchema<OUTPUT>;
1205
+ /**
1206
+ * Whether this provider-executed tool supports deferred results.
1207
+ *
1208
+ * When true, the tool result may not be returned in the same turn as the
1209
+ * tool call (e.g., when using programmatic tool calling where a server tool
1210
+ * triggers a client-executed tool, and the server tool's result is deferred
1211
+ * until the client tool is resolved).
1212
+ *
1213
+ * @default false
1214
+ */
1215
+ supportsDeferredResults?: boolean;
1121
1216
  }): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
1122
1217
 
1123
1218
  /**
@@ -1265,4 +1360,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1265
1360
  */
1266
1361
  type ToolCallOptions = ToolExecutionOptions;
1267
1362
 
1268
- export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1363
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
1
+ import { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, ImageModelV3File, AISDKError, JSONSchema7, JSONParseError, TypeValidationError, JSONValue, APICallError, LanguageModelV3Prompt, SharedV3ProviderOptions } from '@ai-sdk/provider';
2
2
  import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
3
3
  export * from '@standard-schema/spec';
4
4
  import * as z3 from 'zod/v3';
@@ -91,6 +91,76 @@ declare function extractResponseHeaders(response: Response): {
91
91
  [k: string]: string;
92
92
  };
93
93
 
94
+ /**
95
+ * Convert an ImageModelV3File to a URL or data URI string.
96
+ *
97
+ * If the file is a URL, it returns the URL as-is.
98
+ * If the file is base64 data, it returns a data URI with the base64 data.
99
+ * If the file is a Uint8Array, it converts it to base64 and returns a data URI.
100
+ */
101
+ declare function convertImageModelFileToDataUri(file: ImageModelV3File): string;
102
+
103
+ /**
104
+ * Converts an input object to FormData for multipart/form-data requests.
105
+ *
106
+ * Handles the following cases:
107
+ * - `null` or `undefined` values are skipped
108
+ * - Arrays with a single element are appended as a single value
109
+ * - Arrays with multiple elements are appended with `[]` suffix (e.g., `image[]`)
110
+ * unless `useArrayBrackets` is set to `false`
111
+ * - All other values are appended directly
112
+ *
113
+ * @param input - The input object to convert. Use a generic type for type validation.
114
+ * @param options - Optional configuration object.
115
+ * @param options.useArrayBrackets - Whether to add `[]` suffix for multi-element arrays.
116
+ * Defaults to `true`. Set to `false` for APIs that expect repeated keys without brackets.
117
+ * @returns A FormData object containing the input values.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * type MyInput = {
122
+ * model: string;
123
+ * prompt: string;
124
+ * images: Blob[];
125
+ * };
126
+ *
127
+ * const formData = convertToFormData<MyInput>({
128
+ * model: 'gpt-image-1',
129
+ * prompt: 'A cat',
130
+ * images: [blob1, blob2],
131
+ * });
132
+ * ```
133
+ */
134
+ declare function convertToFormData<T extends Record<string, unknown>>(input: T, options?: {
135
+ useArrayBrackets?: boolean;
136
+ }): FormData;
137
+
138
+ /**
139
+ * Download a file from a URL and return it as a Blob.
140
+ *
141
+ * @param url - The URL to download from.
142
+ * @returns A Promise that resolves to the downloaded Blob.
143
+ *
144
+ * @throws DownloadError if the download fails.
145
+ */
146
+ declare function downloadBlob(url: string): Promise<Blob>;
147
+
148
+ declare const symbol: unique symbol;
149
+ declare class DownloadError extends AISDKError {
150
+ private readonly [symbol];
151
+ readonly url: string;
152
+ readonly statusCode?: number;
153
+ readonly statusText?: string;
154
+ constructor({ url, statusCode, statusText, cause, message, }: {
155
+ url: string;
156
+ statusCode?: number;
157
+ statusText?: string;
158
+ message?: string;
159
+ cause?: unknown;
160
+ });
161
+ static isInstance(error: unknown): error is DownloadError;
162
+ }
163
+
94
164
  /**
95
165
  * Fetch function type (standardizes the version of fetch used).
96
166
  */
@@ -1042,6 +1112,20 @@ The ID of the tool. Must follow the format `<provider-name>.<unique-tool-name>`.
1042
1112
  The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1043
1113
  */
1044
1114
  args: Record<string, unknown>;
1115
+ /**
1116
+ * Whether this provider-executed tool supports deferred results.
1117
+ *
1118
+ * When true, the tool result may not be returned in the same turn as the
1119
+ * tool call (e.g., when using programmatic tool calling where a server tool
1120
+ * triggers a client-executed tool, and the server tool's result is deferred
1121
+ * until the client tool is resolved).
1122
+ *
1123
+ * This flag allows the AI SDK to handle tool results that arrive without
1124
+ * a matching tool call in the current response.
1125
+ *
1126
+ * @default false
1127
+ */
1128
+ supportsDeferredResults?: boolean;
1045
1129
  });
1046
1130
  /**
1047
1131
  * Infer the input type of a tool.
@@ -1114,10 +1198,21 @@ type ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (
1114
1198
  onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta'];
1115
1199
  onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable'];
1116
1200
  }) => Tool<INPUT, OUTPUT>;
1117
- declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, }: {
1201
+ declare function createProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object>({ id, inputSchema, outputSchema, supportsDeferredResults, }: {
1118
1202
  id: `${string}.${string}`;
1119
1203
  inputSchema: FlexibleSchema<INPUT>;
1120
1204
  outputSchema: FlexibleSchema<OUTPUT>;
1205
+ /**
1206
+ * Whether this provider-executed tool supports deferred results.
1207
+ *
1208
+ * When true, the tool result may not be returned in the same turn as the
1209
+ * tool call (e.g., when using programmatic tool calling where a server tool
1210
+ * triggers a client-executed tool, and the server tool's result is deferred
1211
+ * until the client tool is resolved).
1212
+ *
1213
+ * @default false
1214
+ */
1215
+ supportsDeferredResults?: boolean;
1121
1216
  }): ProviderToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS>;
1122
1217
 
1123
1218
  /**
@@ -1265,4 +1360,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1265
1360
  */
1266
1361
  type ToolCallOptions = ToolExecutionOptions;
1267
1362
 
1268
- export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderToolFactory, createProviderToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1363
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, DownloadError, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderOptions, type ProviderToolFactory, type ProviderToolFactoryWithOutputSchema, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, 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, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };