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

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,13 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.0-beta.54
4
+
5
+ ### Patch Changes
6
+
7
+ - 9061dc0: feat: image editing
8
+ - Updated dependencies [9061dc0]
9
+ - @ai-sdk/provider@3.0.0-beta.28
10
+
3
11
  ## 4.0.0-beta.53
4
12
 
5
13
  ### 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
  */
@@ -1265,4 +1335,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1265
1335
  */
1266
1336
  type ToolCallOptions = ToolExecutionOptions;
1267
1337
 
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 };
1338
+ 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
  */
@@ -1265,4 +1335,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1265
1335
  */
1266
1336
  type ToolCallOptions = ToolExecutionOptions;
1267
1337
 
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 };
1338
+ 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 };