@ai-sdk/provider 0.0.14 → 0.0.15

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/dist/index.d.ts CHANGED
@@ -82,13 +82,57 @@ type EmbeddingModelV1<VALUE> = {
82
82
  }>;
83
83
  };
84
84
 
85
- declare class APICallError extends Error {
85
+ declare const symbol$b: unique symbol;
86
+ /**
87
+ * Custom error class for AI SDK related errors.
88
+ * @extends Error
89
+ */
90
+ declare class AISDKError extends Error {
91
+ private readonly [symbol$b];
92
+ /**
93
+ * The underlying cause of the error, if any.
94
+ */
95
+ readonly cause?: unknown;
96
+ /**
97
+ * Creates an AI SDK Error.
98
+ *
99
+ * @param {Object} params - The parameters for creating the error.
100
+ * @param {string} params.name - The name of the error.
101
+ * @param {string} params.message - The error message.
102
+ * @param {unknown} [params.cause] - The underlying cause of the error.
103
+ */
104
+ constructor({ name, message, cause, }: {
105
+ name: string;
106
+ message: string;
107
+ cause?: unknown;
108
+ });
109
+ /**
110
+ * Checks if the given error is an AI SDK Error.
111
+ * @param {unknown} error - The error to check.
112
+ * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
113
+ */
114
+ static isInstance(error: unknown): error is AISDKError;
115
+ protected static hasMarker(error: unknown, marker: string): boolean;
116
+ /**
117
+ * Returns a JSON representation of the error.
118
+ * @returns {Object} An object containing the error's name, message, and cause.
119
+ *
120
+ * @deprecated Do not use this method. It will be removed in the next major version.
121
+ */
122
+ toJSON(): {
123
+ name: string;
124
+ message: string;
125
+ };
126
+ }
127
+
128
+ declare const symbol$a: unique symbol;
129
+ declare class APICallError extends AISDKError {
130
+ private readonly [symbol$a];
86
131
  readonly url: string;
87
132
  readonly requestBodyValues: unknown;
88
133
  readonly statusCode?: number;
89
134
  readonly responseHeaders?: Record<string, string>;
90
135
  readonly responseBody?: string;
91
- readonly cause?: unknown;
92
136
  readonly isRetryable: boolean;
93
137
  readonly data?: unknown;
94
138
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable, // server error
@@ -103,7 +147,14 @@ declare class APICallError extends Error {
103
147
  isRetryable?: boolean;
104
148
  data?: unknown;
105
149
  });
150
+ static isInstance(error: unknown): error is APICallError;
151
+ /**
152
+ * @deprecated Use isInstance instead.
153
+ */
106
154
  static isAPICallError(error: unknown): error is APICallError;
155
+ /**
156
+ * @deprecated Do not use this method. It will be removed in the next major version.
157
+ */
107
158
  toJSON(): {
108
159
  name: string;
109
160
  message: string;
@@ -118,84 +169,41 @@ declare class APICallError extends Error {
118
169
  };
119
170
  }
120
171
 
121
- declare class DownloadError extends Error {
122
- readonly url: string;
123
- readonly statusCode?: number;
124
- readonly statusText?: string;
125
- readonly cause?: unknown;
126
- constructor({ url, statusCode, statusText, cause, message, }: {
127
- url: string;
128
- statusCode?: number;
129
- statusText?: string;
130
- message?: string;
131
- cause?: unknown;
132
- });
133
- static isDownloadError(error: unknown): error is DownloadError;
134
- toJSON(): {
135
- name: string;
136
- message: string;
137
- url: string;
138
- statusCode: number | undefined;
139
- statusText: string | undefined;
140
- cause: unknown;
141
- };
142
- }
143
-
144
- declare class EmptyResponseBodyError extends Error {
172
+ declare const symbol$9: unique symbol;
173
+ declare class EmptyResponseBodyError extends AISDKError {
174
+ private readonly [symbol$9];
145
175
  constructor({ message }?: {
146
176
  message?: string;
147
177
  });
178
+ static isInstance(error: unknown): error is EmptyResponseBodyError;
179
+ /**
180
+ * @deprecated use `isInstance` instead
181
+ */
148
182
  static isEmptyResponseBodyError(error: unknown): error is EmptyResponseBodyError;
149
- toJSON(): {
150
- name: string;
151
- message: string;
152
- stack: string | undefined;
153
- };
154
183
  }
155
184
 
156
- declare class InvalidArgumentError extends Error {
157
- readonly parameter: string;
158
- readonly value: unknown;
159
- constructor({ parameter, value, message, }: {
160
- parameter: string;
161
- value: unknown;
162
- message: string;
163
- });
164
- static isInvalidArgumentError(error: unknown): error is InvalidArgumentError;
165
- toJSON(): {
166
- name: string;
167
- message: string;
168
- stack: string | undefined;
169
- parameter: string;
170
- value: unknown;
171
- };
172
- }
173
-
174
- declare class InvalidDataContentError extends Error {
175
- readonly content: unknown;
176
- readonly cause?: unknown;
177
- constructor({ content, cause, message, }: {
178
- content: unknown;
179
- cause?: unknown;
180
- message?: string;
181
- });
182
- static isInvalidDataContentError(error: unknown): error is InvalidDataContentError;
183
- toJSON(): {
184
- name: string;
185
- message: string;
186
- stack: string | undefined;
187
- cause: unknown;
188
- content: unknown;
189
- };
190
- }
185
+ declare function getErrorMessage(error: unknown | undefined): string;
191
186
 
192
- declare class InvalidPromptError extends Error {
187
+ declare const symbol$8: unique symbol;
188
+ /**
189
+ * A prompt is invalid. This error should be thrown by providers when they cannot
190
+ * process a prompt.
191
+ */
192
+ declare class InvalidPromptError extends AISDKError {
193
+ private readonly [symbol$8];
193
194
  readonly prompt: unknown;
194
195
  constructor({ prompt, message }: {
195
196
  prompt: unknown;
196
197
  message: string;
197
198
  });
199
+ static isInstance(error: unknown): error is InvalidPromptError;
200
+ /**
201
+ * @deprecated use `isInstance` instead
202
+ */
198
203
  static isInvalidPromptError(error: unknown): error is InvalidPromptError;
204
+ /**
205
+ * @deprecated Do not use this method. It will be removed in the next major version.
206
+ */
199
207
  toJSON(): {
200
208
  name: string;
201
209
  message: string;
@@ -204,17 +212,26 @@ declare class InvalidPromptError extends Error {
204
212
  };
205
213
  }
206
214
 
215
+ declare const symbol$7: unique symbol;
207
216
  /**
208
- Server returned a response with invalid data content. This should be thrown by providers when they
209
- cannot parse the response from the API.
217
+ * Server returned a response with invalid data content.
218
+ * This should be thrown by providers when they cannot parse the response from the API.
210
219
  */
211
- declare class InvalidResponseDataError extends Error {
220
+ declare class InvalidResponseDataError extends AISDKError {
221
+ private readonly [symbol$7];
212
222
  readonly data: unknown;
213
223
  constructor({ data, message, }: {
214
224
  data: unknown;
215
225
  message?: string;
216
226
  });
227
+ static isInstance(error: unknown): error is InvalidResponseDataError;
228
+ /**
229
+ * @deprecated use `isInstance` instead
230
+ */
217
231
  static isInvalidResponseDataError(error: unknown): error is InvalidResponseDataError;
232
+ /**
233
+ * @deprecated Do not use this method. It will be removed in the next major version.
234
+ */
218
235
  toJSON(): {
219
236
  name: string;
220
237
  message: string;
@@ -223,35 +240,22 @@ declare class InvalidResponseDataError extends Error {
223
240
  };
224
241
  }
225
242
 
226
- declare class InvalidToolArgumentsError extends Error {
227
- readonly toolName: string;
228
- readonly toolArgs: string;
229
- readonly cause: unknown;
230
- constructor({ toolArgs, toolName, cause, message, }: {
231
- message?: string;
232
- toolArgs: string;
233
- toolName: string;
234
- cause: unknown;
235
- });
236
- static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
237
- toJSON(): {
238
- name: string;
239
- message: string;
240
- cause: unknown;
241
- stack: string | undefined;
242
- toolName: string;
243
- toolArgs: string;
244
- };
245
- }
246
-
247
- declare class JSONParseError extends Error {
243
+ declare const symbol$6: unique symbol;
244
+ declare class JSONParseError extends AISDKError {
245
+ private readonly [symbol$6];
248
246
  readonly text: string;
249
- readonly cause: unknown;
250
247
  constructor({ text, cause }: {
251
248
  text: string;
252
249
  cause: unknown;
253
250
  });
251
+ static isInstance(error: unknown): error is JSONParseError;
252
+ /**
253
+ * @deprecated use `isInstance` instead
254
+ */
254
255
  static isJSONParseError(error: unknown): error is JSONParseError;
256
+ /**
257
+ * @deprecated Do not use this method. It will be removed in the next major version.
258
+ */
255
259
  toJSON(): {
256
260
  name: string;
257
261
  message: string;
@@ -261,37 +265,49 @@ declare class JSONParseError extends Error {
261
265
  };
262
266
  }
263
267
 
264
- declare class LoadAPIKeyError extends Error {
268
+ declare const symbol$5: unique symbol;
269
+ declare class LoadAPIKeyError extends AISDKError {
270
+ private readonly [symbol$5];
265
271
  constructor({ message }: {
266
272
  message: string;
267
273
  });
274
+ static isInstance(error: unknown): error is LoadAPIKeyError;
275
+ /**
276
+ * @deprecated Use isInstance instead.
277
+ */
268
278
  static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError;
269
- toJSON(): {
270
- name: string;
271
- message: string;
272
- };
273
279
  }
274
280
 
275
- declare class LoadSettingError extends Error {
281
+ declare const symbol$4: unique symbol;
282
+ declare class LoadSettingError extends AISDKError {
283
+ private readonly [symbol$4];
276
284
  constructor({ message }: {
277
285
  message: string;
278
286
  });
287
+ static isInstance(error: unknown): error is LoadSettingError;
288
+ /**
289
+ * @deprecated Use isInstance instead.
290
+ */
279
291
  static isLoadSettingError(error: unknown): error is LoadSettingError;
280
- toJSON(): {
281
- name: string;
282
- message: string;
283
- };
284
292
  }
285
293
 
294
+ declare const symbol$3: unique symbol;
286
295
  /**
287
296
  Thrown when the AI provider fails to generate any content.
288
297
  */
289
- declare class NoContentGeneratedError extends Error {
290
- readonly cause: unknown;
298
+ declare class NoContentGeneratedError extends AISDKError {
299
+ private readonly [symbol$3];
291
300
  constructor({ message, }?: {
292
301
  message?: string;
293
302
  });
303
+ static isInstance(error: unknown): error is NoContentGeneratedError;
304
+ /**
305
+ * @deprecated Use isInstance instead.
306
+ */
294
307
  static isNoContentGeneratedError(error: unknown): error is NoContentGeneratedError;
308
+ /**
309
+ * @deprecated Do not use this method. It will be removed in the next major version.
310
+ */
295
311
  toJSON(): {
296
312
  name: string;
297
313
  cause: unknown;
@@ -300,62 +316,9 @@ declare class NoContentGeneratedError extends Error {
300
316
  };
301
317
  }
302
318
 
303
- /**
304
- Thrown when the AI provider fails to generate a parsable object.
305
- */
306
- declare class NoObjectGeneratedError extends Error {
307
- readonly cause: unknown;
308
- constructor({ message }?: {
309
- message?: string;
310
- });
311
- static isNoObjectGeneratedError(error: unknown): error is NoObjectGeneratedError;
312
- toJSON(): {
313
- name: string;
314
- cause: unknown;
315
- message: string;
316
- stack: string | undefined;
317
- };
318
- }
319
-
320
- declare class NoSuchToolError extends Error {
321
- readonly toolName: string;
322
- readonly availableTools: string[] | undefined;
323
- constructor({ toolName, availableTools, message, }: {
324
- toolName: string;
325
- availableTools?: string[] | undefined;
326
- message?: string;
327
- });
328
- static isNoSuchToolError(error: unknown): error is NoSuchToolError;
329
- toJSON(): {
330
- name: string;
331
- message: string;
332
- stack: string | undefined;
333
- toolName: string;
334
- availableTools: string[] | undefined;
335
- };
336
- }
337
-
338
- type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
339
- declare class RetryError extends Error {
340
- readonly reason: RetryErrorReason;
341
- readonly lastError: unknown;
342
- readonly errors: Array<unknown>;
343
- constructor({ message, reason, errors, }: {
344
- message: string;
345
- reason: RetryErrorReason;
346
- errors: Array<unknown>;
347
- });
348
- static isRetryError(error: unknown): error is RetryError;
349
- toJSON(): {
350
- name: string;
351
- message: string;
352
- reason: RetryErrorReason;
353
- lastError: unknown;
354
- errors: unknown[];
355
- };
356
- }
357
-
358
- declare class TooManyEmbeddingValuesForCallError extends Error {
319
+ declare const symbol$2: unique symbol;
320
+ declare class TooManyEmbeddingValuesForCallError extends AISDKError {
321
+ private readonly [symbol$2];
359
322
  readonly provider: string;
360
323
  readonly modelId: string;
361
324
  readonly maxEmbeddingsPerCall: number;
@@ -366,75 +329,41 @@ declare class TooManyEmbeddingValuesForCallError extends Error {
366
329
  maxEmbeddingsPerCall: number;
367
330
  values: Array<unknown>;
368
331
  });
369
- static isInvalidPromptError(error: unknown): error is TooManyEmbeddingValuesForCallError;
370
- toJSON(): {
371
- name: string;
372
- message: string;
373
- stack: string | undefined;
374
- provider: string;
375
- modelId: string;
376
- maxEmbeddingsPerCall: number;
377
- values: unknown[];
378
- };
379
- }
380
-
381
- /**
382
- A tool has a name, a description, and a set of parameters.
383
-
384
- Note: this is **not** the user-facing tool definition. The AI SDK methods will
385
- map the user-facing tool definitions to this format.
386
- */
387
- type LanguageModelV1FunctionTool = {
332
+ static isInstance(error: unknown): error is TooManyEmbeddingValuesForCallError;
388
333
  /**
389
- The type of the tool. Only functions for now, but this gives us room to
390
- add more specific tool types in the future and use a discriminated union.
391
- */
392
- type: 'function';
393
- /**
394
- The name of the tool. Unique within this model call.
395
- */
396
- name: string;
397
- /**
398
- A description of the tool. The language model uses this to understand the
399
- tool's purpose and to provide better completion suggestions.
334
+ * @deprecated use `isInstance` instead
400
335
  */
401
- description?: string;
336
+ static isTooManyEmbeddingValuesForCallError(error: unknown): error is TooManyEmbeddingValuesForCallError;
402
337
  /**
403
- The parameters that the tool expects. The language model uses this to
404
- understand the tool's input requirements and to provide matching suggestions.
338
+ * @deprecated Do not use this method. It will be removed in the next major version.
405
339
  */
406
- parameters: JSONSchema7;
407
- };
408
-
409
- declare class ToolCallParseError extends Error {
410
- readonly cause: unknown;
411
- readonly text: string;
412
- readonly tools: LanguageModelV1FunctionTool[];
413
- constructor({ cause, text, tools, message, }: {
414
- cause: unknown;
415
- text: string;
416
- tools: LanguageModelV1FunctionTool[];
417
- message?: string;
418
- });
419
- static isToolCallParseError(error: unknown): error is ToolCallParseError;
420
340
  toJSON(): {
421
341
  name: string;
422
342
  message: string;
423
343
  stack: string | undefined;
424
- cause: unknown;
425
- text: string;
426
- tools: LanguageModelV1FunctionTool[];
344
+ provider: string;
345
+ modelId: string;
346
+ maxEmbeddingsPerCall: number;
347
+ values: unknown[];
427
348
  };
428
349
  }
429
350
 
430
- declare class TypeValidationError extends Error {
351
+ declare const symbol$1: unique symbol;
352
+ declare class TypeValidationError extends AISDKError {
353
+ private readonly [symbol$1];
431
354
  readonly value: unknown;
432
- readonly cause: unknown;
433
355
  constructor({ value, cause }: {
434
356
  value: unknown;
435
357
  cause: unknown;
436
358
  });
359
+ static isInstance(error: unknown): error is TypeValidationError;
360
+ /**
361
+ * @deprecated use `isInstance` instead
362
+ */
437
363
  static isTypeValidationError(error: unknown): error is TypeValidationError;
364
+ /**
365
+ * @deprecated Do not use this method. It will be removed in the next major version.
366
+ */
438
367
  toJSON(): {
439
368
  name: string;
440
369
  message: string;
@@ -444,12 +373,21 @@ declare class TypeValidationError extends Error {
444
373
  };
445
374
  }
446
375
 
447
- declare class UnsupportedFunctionalityError extends Error {
376
+ declare const symbol: unique symbol;
377
+ declare class UnsupportedFunctionalityError extends AISDKError {
378
+ private readonly [symbol];
448
379
  readonly functionality: string;
449
380
  constructor({ functionality }: {
450
381
  functionality: string;
451
382
  });
383
+ static isInstance(error: unknown): error is UnsupportedFunctionalityError;
384
+ /**
385
+ * @deprecated Use isInstance instead.
386
+ */
452
387
  static isUnsupportedFunctionalityError(error: unknown): error is UnsupportedFunctionalityError;
388
+ /**
389
+ * @deprecated Do not use this method. It will be removed in the next major version.
390
+ */
453
391
  toJSON(): {
454
392
  name: string;
455
393
  message: string;
@@ -458,24 +396,6 @@ declare class UnsupportedFunctionalityError extends Error {
458
396
  };
459
397
  }
460
398
 
461
- declare class UnsupportedJSONSchemaError extends Error {
462
- readonly reason: string;
463
- readonly schema: unknown;
464
- constructor({ schema, reason, message, }: {
465
- schema: unknown;
466
- reason: string;
467
- message?: string;
468
- });
469
- static isUnsupportedJSONSchemaError(error: unknown): error is UnsupportedJSONSchemaError;
470
- toJSON(): {
471
- name: string;
472
- message: string;
473
- stack: string | undefined;
474
- reason: string;
475
- schema: unknown;
476
- };
477
- }
478
-
479
399
  type LanguageModelV1CallSettings = {
480
400
  /**
481
401
  Maximum number of tokens to generate.
@@ -543,6 +463,34 @@ type LanguageModelV1CallSettings = {
543
463
  headers?: Record<string, string | undefined>;
544
464
  };
545
465
 
466
+ /**
467
+ A tool has a name, a description, and a set of parameters.
468
+
469
+ Note: this is **not** the user-facing tool definition. The AI SDK methods will
470
+ map the user-facing tool definitions to this format.
471
+ */
472
+ type LanguageModelV1FunctionTool = {
473
+ /**
474
+ The type of the tool. Only functions for now, but this gives us room to
475
+ add more specific tool types in the future and use a discriminated union.
476
+ */
477
+ type: 'function';
478
+ /**
479
+ The name of the tool. Unique within this model call.
480
+ */
481
+ name: string;
482
+ /**
483
+ A description of the tool. The language model uses this to understand the
484
+ tool's purpose and to provide better completion suggestions.
485
+ */
486
+ description?: string;
487
+ /**
488
+ The parameters that the tool expects. The language model uses this to
489
+ understand the tool's input requirements and to provide matching suggestions.
490
+ */
491
+ parameters: JSONSchema7;
492
+ };
493
+
546
494
  /**
547
495
  A prompt is a list of messages.
548
496
 
@@ -895,4 +843,4 @@ type LanguageModelV1StreamPart = {
895
843
  };
896
844
  type LanguageModelV1ResponseMetadata = {};
897
845
 
898
- export { APICallError, DownloadError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ResponseMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoObjectGeneratedError, NoSuchToolError, RetryError, type RetryErrorReason, TooManyEmbeddingValuesForCallError, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError };
846
+ export { AISDKError, APICallError, type EmbeddingModelV1, type EmbeddingModelV1Embedding, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, type LanguageModelV1, type LanguageModelV1CallOptions, type LanguageModelV1CallWarning, type LanguageModelV1FinishReason, type LanguageModelV1FunctionTool, type LanguageModelV1FunctionToolCall, type LanguageModelV1ImagePart, type LanguageModelV1LogProbs, type LanguageModelV1Message, type LanguageModelV1Prompt, type LanguageModelV1ResponseMetadata, type LanguageModelV1StreamPart, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type LanguageModelV1ToolChoice, type LanguageModelV1ToolResultPart, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage };