@ai-sdk/provider-utils 3.0.0-canary.1 → 3.0.0-canary.11

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,105 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.0-canary.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 66962ed: fix(packages): export node10 compatible types
8
+ - Updated dependencies [9301f86]
9
+ - Updated dependencies [a3f768e]
10
+ - @ai-sdk/provider@2.0.0-canary.10
11
+
12
+ ## 3.0.0-canary.10
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [e86be6f]
17
+ - @ai-sdk/provider@2.0.0-canary.9
18
+
19
+ ## 3.0.0-canary.9
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [95857aa]
24
+ - Updated dependencies [7ea4132]
25
+ - @ai-sdk/provider@2.0.0-canary.8
26
+
27
+ ## 3.0.0-canary.8
28
+
29
+ ### Major Changes
30
+
31
+ - 5d142ab: remove deprecated `CoreToolCall` and `CoreToolResult` types
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [b6b43c7]
36
+ - Updated dependencies [8aa9e20]
37
+ - Updated dependencies [3795467]
38
+ - @ai-sdk/provider@2.0.0-canary.7
39
+
40
+ ## 3.0.0-canary.7
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [26735b5]
45
+ - Updated dependencies [443d8ec]
46
+ - Updated dependencies [14c9410]
47
+ - Updated dependencies [d9c98f4]
48
+ - Updated dependencies [c4a2fec]
49
+ - Updated dependencies [0054544]
50
+ - Updated dependencies [9e9c809]
51
+ - Updated dependencies [32831c6]
52
+ - Updated dependencies [d0f9495]
53
+ - Updated dependencies [fd65bc6]
54
+ - Updated dependencies [393138b]
55
+ - Updated dependencies [7182d14]
56
+ - @ai-sdk/provider@2.0.0-canary.6
57
+
58
+ ## 3.0.0-canary.6
59
+
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies [411e483]
63
+ - Updated dependencies [79457bd]
64
+ - Updated dependencies [ad80501]
65
+ - Updated dependencies [1766ede]
66
+ - Updated dependencies [f10304b]
67
+ - @ai-sdk/provider@2.0.0-canary.5
68
+
69
+ ## 3.0.0-canary.5
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [6f6bb89]
74
+ - @ai-sdk/provider@2.0.0-canary.4
75
+
76
+ ## 3.0.0-canary.4
77
+
78
+ ### Patch Changes
79
+
80
+ - Updated dependencies [d1a1aa1]
81
+ - @ai-sdk/provider@2.0.0-canary.3
82
+
83
+ ## 3.0.0-canary.3
84
+
85
+ ### Patch Changes
86
+
87
+ - a166433: feat: add transcription with experimental_transcribe
88
+ - 9f95b35: refactor (provider-utils): copy relevant code from `secure-json-parse` into codebase
89
+ - Updated dependencies [a166433]
90
+ - Updated dependencies [abf9a79]
91
+ - Updated dependencies [0a87932]
92
+ - Updated dependencies [6dc848c]
93
+ - @ai-sdk/provider@2.0.0-canary.2
94
+
95
+ ## 3.0.0-canary.2
96
+
97
+ ### Patch Changes
98
+
99
+ - Updated dependencies [c57e248]
100
+ - Updated dependencies [33f4a6a]
101
+ - @ai-sdk/provider@2.0.0-canary.1
102
+
3
103
  ## 3.0.0-canary.1
4
104
 
5
105
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -110,19 +110,19 @@ declare function zodValidator<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeDef,
110
110
  declare function parseJSON(options: {
111
111
  text: string;
112
112
  schema?: undefined;
113
- }): JSONValue;
113
+ }): Promise<JSONValue>;
114
114
  /**
115
115
  * Parses a JSON string into a strongly-typed object using the provided schema.
116
116
  *
117
117
  * @template T - The type of the object to parse the JSON into.
118
118
  * @param {string} text - The JSON string to parse.
119
119
  * @param {Validator<T>} schema - The schema to use for parsing the JSON.
120
- * @returns {T} - The parsed object.
120
+ * @returns {Promise<T>} - The parsed object.
121
121
  */
122
122
  declare function parseJSON<T>(options: {
123
123
  text: string;
124
124
  schema: ZodSchema<T> | Validator<T>;
125
- }): T;
125
+ }): Promise<T>;
126
126
  type ParseResult<T> = {
127
127
  success: true;
128
128
  value: T;
@@ -135,12 +135,12 @@ type ParseResult<T> = {
135
135
  * Safely parses a JSON string and returns the result as an object of type `unknown`.
136
136
  *
137
137
  * @param text - The JSON string to parse.
138
- * @returns {object} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
138
+ * @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
139
139
  */
140
140
  declare function safeParseJSON(options: {
141
141
  text: string;
142
142
  schema?: undefined;
143
- }): ParseResult<JSONValue>;
143
+ }): Promise<ParseResult<JSONValue>>;
144
144
  /**
145
145
  * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
146
146
  *
@@ -152,7 +152,7 @@ declare function safeParseJSON(options: {
152
152
  declare function safeParseJSON<T>(options: {
153
153
  text: string;
154
154
  schema: ZodSchema<T> | Validator<T>;
155
- }): ParseResult<T>;
155
+ }): Promise<ParseResult<T>>;
156
156
  declare function isParsableJson(input: string): boolean;
157
157
 
158
158
  type ResponseHandler<RETURN_TYPE> = (options: {
@@ -190,6 +190,23 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
190
190
 
191
191
  declare function isAbortError(error: unknown): error is Error;
192
192
 
193
+ /**
194
+ * Checks if the given URL is supported natively by the model.
195
+ *
196
+ * @param mediaType - The media type of the URL. Case-sensitive.
197
+ * @param url - The URL to check.
198
+ * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
199
+ * and values are arrays of RegExp patterns for URLs.
200
+ *
201
+ * @returns `true` if the URL matches a pattern under the specific media type
202
+ * or the wildcard '*', `false` otherwise.
203
+ */
204
+ declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
205
+ mediaType: string;
206
+ url: string;
207
+ supportedUrls: Record<string, RegExp[]>;
208
+ }): boolean;
209
+
193
210
  declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
194
211
  apiKey: string | undefined;
195
212
  environmentVariableName: string;
@@ -229,7 +246,7 @@ declare function parseProviderOptions<T>({ provider, providerOptions, schema, }:
229
246
  provider: string;
230
247
  providerOptions: Record<string, unknown> | undefined;
231
248
  schema: z.ZodSchema<T>;
232
- }): T | undefined;
249
+ }): Promise<T | undefined>;
233
250
 
234
251
  declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
235
252
  url: string;
@@ -244,6 +261,19 @@ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, su
244
261
  rawValue?: unknown;
245
262
  responseHeaders?: Record<string, string>;
246
263
  }>;
264
+ declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
265
+ url: string;
266
+ headers?: Record<string, string | undefined>;
267
+ formData: FormData;
268
+ failedResponseHandler: ResponseHandler<APICallError>;
269
+ successfulResponseHandler: ResponseHandler<T>;
270
+ abortSignal?: AbortSignal;
271
+ fetch?: FetchFunction;
272
+ }) => Promise<{
273
+ value: T;
274
+ rawValue?: unknown;
275
+ responseHeaders?: Record<string, string>;
276
+ }>;
247
277
  declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
248
278
  url: string;
249
279
  headers?: Record<string, string | undefined>;
@@ -275,8 +305,9 @@ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
275
305
  */
276
306
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
277
307
 
278
- declare function convertBase64ToUint8Array(base64String: string): Uint8Array;
308
+ declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
279
309
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
310
+ declare function convertToBase64(value: string | Uint8Array): string;
280
311
 
281
312
  /**
282
313
  * Validates the types of an unknown object using a schema and
@@ -285,12 +316,12 @@ declare function convertUint8ArrayToBase64(array: Uint8Array): string;
285
316
  * @template T - The type of the object to validate.
286
317
  * @param {string} options.value - The object to validate.
287
318
  * @param {Validator<T>} options.schema - The schema to use for validating the JSON.
288
- * @returns {T} - The typed object.
319
+ * @returns {Promise<T>} - The typed object.
289
320
  */
290
321
  declare function validateTypes<T>({ value, schema: inputSchema, }: {
291
322
  value: unknown;
292
323
  schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
293
- }): T;
324
+ }): Promise<T>;
294
325
  /**
295
326
  * Safely validates the types of an unknown object using a schema and
296
327
  * return a strongly-typed object.
@@ -303,13 +334,13 @@ declare function validateTypes<T>({ value, schema: inputSchema, }: {
303
334
  declare function safeValidateTypes<T>({ value, schema, }: {
304
335
  value: unknown;
305
336
  schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
306
- }): {
337
+ }): Promise<{
307
338
  success: true;
308
339
  value: T;
309
340
  } | {
310
341
  success: false;
311
342
  error: TypeValidationError;
312
- };
343
+ }>;
313
344
 
314
345
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
315
346
 
@@ -331,10 +362,6 @@ interface ToolCall<NAME extends string, ARGS> {
331
362
  */
332
363
  args: ARGS;
333
364
  }
334
- /**
335
- * @deprecated Use `ToolCall` instead.
336
- */
337
- type CoreToolCall<NAME extends string, ARGS> = ToolCall<NAME, ARGS>;
338
365
 
339
366
  /**
340
367
  Typed tool result that is returned by `generateText` and `streamText`.
@@ -358,9 +385,5 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
358
385
  */
359
386
  result: RESULT;
360
387
  }
361
- /**
362
- * @deprecated Use `ToolResult` instead.
363
- */
364
- type CoreToolResult<NAME extends string, ARGS, RESULT> = ToolResult<NAME, ARGS, RESULT>;
365
388
 
366
- export { type CoreToolCall, type CoreToolResult, type EventSourceChunk, type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceParserStream, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, delay, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, parseProviderOptions, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
389
+ export { type EventSourceChunk, type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceParserStream, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, delay, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isUrlSupported, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
package/dist/index.d.ts CHANGED
@@ -110,19 +110,19 @@ declare function zodValidator<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeDef,
110
110
  declare function parseJSON(options: {
111
111
  text: string;
112
112
  schema?: undefined;
113
- }): JSONValue;
113
+ }): Promise<JSONValue>;
114
114
  /**
115
115
  * Parses a JSON string into a strongly-typed object using the provided schema.
116
116
  *
117
117
  * @template T - The type of the object to parse the JSON into.
118
118
  * @param {string} text - The JSON string to parse.
119
119
  * @param {Validator<T>} schema - The schema to use for parsing the JSON.
120
- * @returns {T} - The parsed object.
120
+ * @returns {Promise<T>} - The parsed object.
121
121
  */
122
122
  declare function parseJSON<T>(options: {
123
123
  text: string;
124
124
  schema: ZodSchema<T> | Validator<T>;
125
- }): T;
125
+ }): Promise<T>;
126
126
  type ParseResult<T> = {
127
127
  success: true;
128
128
  value: T;
@@ -135,12 +135,12 @@ type ParseResult<T> = {
135
135
  * Safely parses a JSON string and returns the result as an object of type `unknown`.
136
136
  *
137
137
  * @param text - The JSON string to parse.
138
- * @returns {object} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
138
+ * @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
139
139
  */
140
140
  declare function safeParseJSON(options: {
141
141
  text: string;
142
142
  schema?: undefined;
143
- }): ParseResult<JSONValue>;
143
+ }): Promise<ParseResult<JSONValue>>;
144
144
  /**
145
145
  * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
146
146
  *
@@ -152,7 +152,7 @@ declare function safeParseJSON(options: {
152
152
  declare function safeParseJSON<T>(options: {
153
153
  text: string;
154
154
  schema: ZodSchema<T> | Validator<T>;
155
- }): ParseResult<T>;
155
+ }): Promise<ParseResult<T>>;
156
156
  declare function isParsableJson(input: string): boolean;
157
157
 
158
158
  type ResponseHandler<RETURN_TYPE> = (options: {
@@ -190,6 +190,23 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
190
190
 
191
191
  declare function isAbortError(error: unknown): error is Error;
192
192
 
193
+ /**
194
+ * Checks if the given URL is supported natively by the model.
195
+ *
196
+ * @param mediaType - The media type of the URL. Case-sensitive.
197
+ * @param url - The URL to check.
198
+ * @param supportedUrls - A record where keys are case-sensitive media types (or '*')
199
+ * and values are arrays of RegExp patterns for URLs.
200
+ *
201
+ * @returns `true` if the URL matches a pattern under the specific media type
202
+ * or the wildcard '*', `false` otherwise.
203
+ */
204
+ declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
205
+ mediaType: string;
206
+ url: string;
207
+ supportedUrls: Record<string, RegExp[]>;
208
+ }): boolean;
209
+
193
210
  declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
194
211
  apiKey: string | undefined;
195
212
  environmentVariableName: string;
@@ -229,7 +246,7 @@ declare function parseProviderOptions<T>({ provider, providerOptions, schema, }:
229
246
  provider: string;
230
247
  providerOptions: Record<string, unknown> | undefined;
231
248
  schema: z.ZodSchema<T>;
232
- }): T | undefined;
249
+ }): Promise<T | undefined>;
233
250
 
234
251
  declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
235
252
  url: string;
@@ -244,6 +261,19 @@ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, su
244
261
  rawValue?: unknown;
245
262
  responseHeaders?: Record<string, string>;
246
263
  }>;
264
+ declare const postFormDataToApi: <T>({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
265
+ url: string;
266
+ headers?: Record<string, string | undefined>;
267
+ formData: FormData;
268
+ failedResponseHandler: ResponseHandler<APICallError>;
269
+ successfulResponseHandler: ResponseHandler<T>;
270
+ abortSignal?: AbortSignal;
271
+ fetch?: FetchFunction;
272
+ }) => Promise<{
273
+ value: T;
274
+ rawValue?: unknown;
275
+ responseHeaders?: Record<string, string>;
276
+ }>;
247
277
  declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
248
278
  url: string;
249
279
  headers?: Record<string, string | undefined>;
@@ -275,8 +305,9 @@ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
275
305
  */
276
306
  declare function resolve<T>(value: Resolvable<T>): Promise<T>;
277
307
 
278
- declare function convertBase64ToUint8Array(base64String: string): Uint8Array;
308
+ declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
279
309
  declare function convertUint8ArrayToBase64(array: Uint8Array): string;
310
+ declare function convertToBase64(value: string | Uint8Array): string;
280
311
 
281
312
  /**
282
313
  * Validates the types of an unknown object using a schema and
@@ -285,12 +316,12 @@ declare function convertUint8ArrayToBase64(array: Uint8Array): string;
285
316
  * @template T - The type of the object to validate.
286
317
  * @param {string} options.value - The object to validate.
287
318
  * @param {Validator<T>} options.schema - The schema to use for validating the JSON.
288
- * @returns {T} - The typed object.
319
+ * @returns {Promise<T>} - The typed object.
289
320
  */
290
321
  declare function validateTypes<T>({ value, schema: inputSchema, }: {
291
322
  value: unknown;
292
323
  schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
293
- }): T;
324
+ }): Promise<T>;
294
325
  /**
295
326
  * Safely validates the types of an unknown object using a schema and
296
327
  * return a strongly-typed object.
@@ -303,13 +334,13 @@ declare function validateTypes<T>({ value, schema: inputSchema, }: {
303
334
  declare function safeValidateTypes<T>({ value, schema, }: {
304
335
  value: unknown;
305
336
  schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
306
- }): {
337
+ }): Promise<{
307
338
  success: true;
308
339
  value: T;
309
340
  } | {
310
341
  success: false;
311
342
  error: TypeValidationError;
312
- };
343
+ }>;
313
344
 
314
345
  declare function withoutTrailingSlash(url: string | undefined): string | undefined;
315
346
 
@@ -331,10 +362,6 @@ interface ToolCall<NAME extends string, ARGS> {
331
362
  */
332
363
  args: ARGS;
333
364
  }
334
- /**
335
- * @deprecated Use `ToolCall` instead.
336
- */
337
- type CoreToolCall<NAME extends string, ARGS> = ToolCall<NAME, ARGS>;
338
365
 
339
366
  /**
340
367
  Typed tool result that is returned by `generateText` and `streamText`.
@@ -358,9 +385,5 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
358
385
  */
359
386
  result: RESULT;
360
387
  }
361
- /**
362
- * @deprecated Use `ToolResult` instead.
363
- */
364
- type CoreToolResult<NAME extends string, ARGS, RESULT> = ToolResult<NAME, ARGS, RESULT>;
365
388
 
366
- export { type CoreToolCall, type CoreToolResult, type EventSourceChunk, type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceParserStream, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, delay, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, parseProviderOptions, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
389
+ export { type EventSourceChunk, type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceParserStream, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, delay, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isUrlSupported, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };