ai 3.0.19 → 3.0.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.
Files changed (67) hide show
  1. package/anthropic/dist/index.d.mts +1 -319
  2. package/anthropic/dist/index.d.ts +1 -319
  3. package/anthropic/dist/index.js +44 -216
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +32 -200
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +60 -333
  8. package/dist/index.d.ts +60 -333
  9. package/dist/index.js +152 -441
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +127 -412
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +1 -319
  14. package/google/dist/index.d.ts +1 -319
  15. package/google/dist/index.js +75 -229
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +63 -213
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +1 -319
  20. package/mistral/dist/index.d.ts +1 -319
  21. package/mistral/dist/index.js +32 -205
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +20 -189
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +2 -320
  26. package/openai/dist/index.d.ts +2 -320
  27. package/openai/dist/index.js +69 -280
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +57 -260
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +4 -10
  32. package/react/dist/index.d.mts +8 -4
  33. package/react/dist/index.d.ts +12 -6
  34. package/react/dist/index.js +23 -105
  35. package/react/dist/index.js.map +1 -1
  36. package/react/dist/index.mjs +22 -105
  37. package/react/dist/index.mjs.map +1 -1
  38. package/react/dist/index.server.d.mts +4 -2
  39. package/react/dist/index.server.d.ts +4 -2
  40. package/react/dist/index.server.js.map +1 -1
  41. package/react/dist/index.server.mjs.map +1 -1
  42. package/rsc/dist/rsc-server.mjs +6 -16
  43. package/rsc/dist/rsc-server.mjs.map +1 -1
  44. package/solid/dist/index.d.mts +1 -1
  45. package/solid/dist/index.d.ts +1 -1
  46. package/solid/dist/index.js +19 -104
  47. package/solid/dist/index.js.map +1 -1
  48. package/solid/dist/index.mjs +19 -104
  49. package/solid/dist/index.mjs.map +1 -1
  50. package/svelte/dist/index.d.mts +1 -1
  51. package/svelte/dist/index.d.ts +1 -1
  52. package/svelte/dist/index.js +19 -104
  53. package/svelte/dist/index.js.map +1 -1
  54. package/svelte/dist/index.mjs +19 -104
  55. package/svelte/dist/index.mjs.map +1 -1
  56. package/vue/dist/index.d.mts +1 -1
  57. package/vue/dist/index.d.ts +1 -1
  58. package/vue/dist/index.js +19 -104
  59. package/vue/dist/index.js.map +1 -1
  60. package/vue/dist/index.mjs +19 -104
  61. package/vue/dist/index.mjs.map +1 -1
  62. package/spec/dist/index.d.mts +0 -752
  63. package/spec/dist/index.d.ts +0 -752
  64. package/spec/dist/index.js +0 -873
  65. package/spec/dist/index.js.map +0 -1
  66. package/spec/dist/index.mjs +0 -807
  67. package/spec/dist/index.mjs.map +0 -1
@@ -35,82 +35,8 @@ __export(anthropic_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(anthropic_exports);
37
37
 
38
- // spec/errors/api-call-error.ts
39
- var APICallError = class extends Error {
40
- constructor({
41
- message,
42
- url,
43
- requestBodyValues,
44
- statusCode,
45
- responseBody,
46
- cause,
47
- isRetryable = statusCode != null && (statusCode === 408 || // request timeout
48
- statusCode === 409 || // conflict
49
- statusCode === 429 || // too many requests
50
- statusCode >= 500),
51
- // server error
52
- data
53
- }) {
54
- super(message);
55
- this.name = "AI_APICallError";
56
- this.url = url;
57
- this.requestBodyValues = requestBodyValues;
58
- this.statusCode = statusCode;
59
- this.responseBody = responseBody;
60
- this.cause = cause;
61
- this.isRetryable = isRetryable;
62
- this.data = data;
63
- }
64
- static isAPICallError(error) {
65
- return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
66
- }
67
- toJSON() {
68
- return {
69
- name: this.name,
70
- message: this.message,
71
- url: this.url,
72
- requestBodyValues: this.requestBodyValues,
73
- statusCode: this.statusCode,
74
- responseBody: this.responseBody,
75
- cause: this.cause,
76
- isRetryable: this.isRetryable,
77
- data: this.data
78
- };
79
- }
80
- };
81
-
82
- // spec/util/get-error-message.ts
83
- function getErrorMessage(error) {
84
- if (error == null) {
85
- return "unknown error";
86
- }
87
- if (typeof error === "string") {
88
- return error;
89
- }
90
- if (error instanceof Error) {
91
- return error.message;
92
- }
93
- return JSON.stringify(error);
94
- }
95
-
96
- // spec/errors/load-api-key-error.ts
97
- var LoadAPIKeyError = class extends Error {
98
- constructor({ message }) {
99
- super(message);
100
- this.name = "AI_LoadAPIKeyError";
101
- }
102
- static isLoadAPIKeyError(error) {
103
- return error instanceof Error && error.name === "AI_LoadAPIKeyError";
104
- }
105
- toJSON() {
106
- return {
107
- name: this.name,
108
- message: this.message
109
- };
110
- }
111
- };
112
-
113
38
  // spec/util/load-api-key.ts
39
+ var import_provider = require("@ai-sdk/provider");
114
40
  function loadApiKey({
115
41
  apiKey,
116
42
  environmentVariableName,
@@ -121,23 +47,23 @@ function loadApiKey({
121
47
  return apiKey;
122
48
  }
123
49
  if (apiKey != null) {
124
- throw new LoadAPIKeyError({
50
+ throw new import_provider.LoadAPIKeyError({
125
51
  message: `${description} API key must be a string.`
126
52
  });
127
53
  }
128
54
  if (typeof process === "undefined") {
129
- throw new LoadAPIKeyError({
55
+ throw new import_provider.LoadAPIKeyError({
130
56
  message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
131
57
  });
132
58
  }
133
59
  apiKey = process.env[environmentVariableName];
134
60
  if (apiKey == null) {
135
- throw new LoadAPIKeyError({
61
+ throw new import_provider.LoadAPIKeyError({
136
62
  message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
137
63
  });
138
64
  }
139
65
  if (typeof apiKey !== "string") {
140
- throw new LoadAPIKeyError({
66
+ throw new import_provider.LoadAPIKeyError({
141
67
  message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
142
68
  });
143
69
  }
@@ -145,59 +71,11 @@ function loadApiKey({
145
71
  }
146
72
 
147
73
  // spec/util/parse-json.ts
74
+ var import_provider3 = require("@ai-sdk/provider");
148
75
  var import_secure_json_parse = __toESM(require("secure-json-parse"));
149
76
 
150
- // spec/errors/json-parse-error.ts
151
- var JSONParseError = class extends Error {
152
- constructor({ text, cause }) {
153
- super(
154
- `JSON parsing failed: Text: ${text}.
155
- Error message: ${getErrorMessage(cause)}`
156
- );
157
- this.name = "AI_JSONParseError";
158
- this.cause = cause;
159
- this.text = text;
160
- }
161
- static isJSONParseError(error) {
162
- return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
163
- }
164
- toJSON() {
165
- return {
166
- name: this.name,
167
- message: this.message,
168
- cause: this.cause,
169
- stack: this.stack,
170
- valueText: this.text
171
- };
172
- }
173
- };
174
-
175
- // spec/errors/type-validation-error.ts
176
- var TypeValidationError = class extends Error {
177
- constructor({ value, cause }) {
178
- super(
179
- `Type validation failed: Value: ${JSON.stringify(value)}.
180
- Error message: ${getErrorMessage(cause)}`
181
- );
182
- this.name = "AI_TypeValidationError";
183
- this.cause = cause;
184
- this.value = value;
185
- }
186
- static isTypeValidationError(error) {
187
- return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
188
- }
189
- toJSON() {
190
- return {
191
- name: this.name,
192
- message: this.message,
193
- cause: this.cause,
194
- stack: this.stack,
195
- value: this.value
196
- };
197
- }
198
- };
199
-
200
77
  // spec/util/validate-types.ts
78
+ var import_provider2 = require("@ai-sdk/provider");
201
79
  function validateTypes({
202
80
  value,
203
81
  schema
@@ -205,7 +83,7 @@ function validateTypes({
205
83
  try {
206
84
  return schema.parse(value);
207
85
  } catch (error) {
208
- throw new TypeValidationError({ value, cause: error });
86
+ throw new import_provider2.TypeValidationError({ value, cause: error });
209
87
  }
210
88
  }
211
89
  function safeValidateTypes({
@@ -222,7 +100,7 @@ function safeValidateTypes({
222
100
  }
223
101
  return {
224
102
  success: false,
225
- error: new TypeValidationError({
103
+ error: new import_provider2.TypeValidationError({
226
104
  value,
227
105
  cause: validationResult.error
228
106
  })
@@ -230,7 +108,7 @@ function safeValidateTypes({
230
108
  } catch (error) {
231
109
  return {
232
110
  success: false,
233
- error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
111
+ error: import_provider2.TypeValidationError.isTypeValidationError(error) ? error : new import_provider2.TypeValidationError({ value, cause: error })
234
112
  };
235
113
  }
236
114
  }
@@ -247,10 +125,10 @@ function parseJSON({
247
125
  }
248
126
  return validateTypes({ value, schema });
249
127
  } catch (error) {
250
- if (JSONParseError.isJSONParseError(error) || TypeValidationError.isTypeValidationError(error)) {
128
+ if (import_provider3.JSONParseError.isJSONParseError(error) || import_provider3.TypeValidationError.isTypeValidationError(error)) {
251
129
  throw error;
252
130
  }
253
- throw new JSONParseError({ text, cause: error });
131
+ throw new import_provider3.JSONParseError({ text, cause: error });
254
132
  }
255
133
  }
256
134
  function safeParseJSON({
@@ -269,12 +147,13 @@ function safeParseJSON({
269
147
  } catch (error) {
270
148
  return {
271
149
  success: false,
272
- error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
150
+ error: import_provider3.JSONParseError.isJSONParseError(error) ? error : new import_provider3.JSONParseError({ text, cause: error })
273
151
  };
274
152
  }
275
153
  }
276
154
 
277
155
  // spec/util/post-to-api.ts
156
+ var import_provider4 = require("@ai-sdk/provider");
278
157
  var postJsonToApi = async ({
279
158
  url,
280
159
  headers,
@@ -323,11 +202,11 @@ var postToApi = async ({
323
202
  });
324
203
  } catch (error) {
325
204
  if (error instanceof Error) {
326
- if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
205
+ if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
327
206
  throw error;
328
207
  }
329
208
  }
330
- throw new APICallError({
209
+ throw new import_provider4.APICallError({
331
210
  message: "Failed to process error response",
332
211
  cause: error,
333
212
  statusCode: response.status,
@@ -344,11 +223,11 @@ var postToApi = async ({
344
223
  });
345
224
  } catch (error) {
346
225
  if (error instanceof Error) {
347
- if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
226
+ if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
348
227
  throw error;
349
228
  }
350
229
  }
351
- throw new APICallError({
230
+ throw new import_provider4.APICallError({
352
231
  message: "Failed to process successful response",
353
232
  cause: error,
354
233
  statusCode: response.status,
@@ -365,7 +244,7 @@ var postToApi = async ({
365
244
  if (error instanceof TypeError && error.message === "fetch failed") {
366
245
  const cause = error.cause;
367
246
  if (cause != null) {
368
- throw new APICallError({
247
+ throw new import_provider4.APICallError({
369
248
  message: `Cannot connect to API: ${cause.message}`,
370
249
  cause,
371
250
  url,
@@ -380,27 +259,8 @@ var postToApi = async ({
380
259
  };
381
260
 
382
261
  // spec/util/response-handler.ts
262
+ var import_provider5 = require("@ai-sdk/provider");
383
263
  var import_stream = require("eventsource-parser/stream");
384
-
385
- // spec/errors/no-response-body-error.ts
386
- var NoResponseBodyError = class extends Error {
387
- constructor({ message = "No response body" } = {}) {
388
- super(message);
389
- this.name = "AI_NoResponseBodyError";
390
- }
391
- static isNoResponseBodyError(error) {
392
- return error instanceof Error && error.name === "AI_NoResponseBodyError";
393
- }
394
- toJSON() {
395
- return {
396
- name: this.name,
397
- message: this.message,
398
- stack: this.stack
399
- };
400
- }
401
- };
402
-
403
- // spec/util/response-handler.ts
404
264
  var createJsonErrorResponseHandler = ({
405
265
  errorSchema,
406
266
  errorToMessage,
@@ -408,7 +268,7 @@ var createJsonErrorResponseHandler = ({
408
268
  }) => async ({ response, url, requestBodyValues }) => {
409
269
  const responseBody = await response.text();
410
270
  if (responseBody.trim() === "") {
411
- return new APICallError({
271
+ return new import_provider5.APICallError({
412
272
  message: response.statusText,
413
273
  url,
414
274
  requestBodyValues,
@@ -422,7 +282,7 @@ var createJsonErrorResponseHandler = ({
422
282
  text: responseBody,
423
283
  schema: errorSchema
424
284
  });
425
- return new APICallError({
285
+ return new import_provider5.APICallError({
426
286
  message: errorToMessage(parsedError),
427
287
  url,
428
288
  requestBodyValues,
@@ -432,7 +292,7 @@ var createJsonErrorResponseHandler = ({
432
292
  isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
433
293
  });
434
294
  } catch (parseError) {
435
- return new APICallError({
295
+ return new import_provider5.APICallError({
436
296
  message: response.statusText,
437
297
  url,
438
298
  requestBodyValues,
@@ -444,7 +304,7 @@ var createJsonErrorResponseHandler = ({
444
304
  };
445
305
  var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
446
306
  if (response.body == null) {
447
- throw new NoResponseBodyError();
307
+ throw new import_provider5.NoResponseBodyError();
448
308
  }
449
309
  return response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream()).pipeThrough(
450
310
  new TransformStream({
@@ -469,7 +329,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
469
329
  schema: responseSchema
470
330
  });
471
331
  if (!parsedResult.success) {
472
- throw new APICallError({
332
+ throw new import_provider5.APICallError({
473
333
  message: "Invalid JSON response",
474
334
  cause: parsedResult.error,
475
335
  statusCode: response.status,
@@ -490,34 +350,8 @@ function convertUint8ArrayToBase64(array) {
490
350
  return globalThis.btoa(latin1string);
491
351
  }
492
352
 
493
- // spec/errors/unsupported-functionality-error.ts
494
- var UnsupportedFunctionalityError = class extends Error {
495
- constructor({
496
- provider,
497
- functionality
498
- }) {
499
- super(
500
- `'${functionality}' functionality not supported by the '${provider}' provider.`
501
- );
502
- this.name = "AI_UnsupportedFunctionalityError";
503
- this.provider = provider;
504
- this.functionality = functionality;
505
- }
506
- static isUnsupportedFunctionalityError(error) {
507
- return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.provider === "string" && typeof error.functionality === "string";
508
- }
509
- toJSON() {
510
- return {
511
- name: this.name,
512
- message: this.message,
513
- stack: this.stack,
514
- provider: this.provider,
515
- functionality: this.functionality
516
- };
517
- }
518
- };
519
-
520
353
  // anthropic/anthropic-messages-language-model.ts
354
+ var import_provider7 = require("@ai-sdk/provider");
521
355
  var import_zod2 = require("zod");
522
356
 
523
357
  // anthropic/anthropic-error.ts
@@ -535,10 +369,8 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
535
369
  });
536
370
 
537
371
  // anthropic/convert-to-anthropic-messages-prompt.ts
538
- function convertToAnthropicMessagesPrompt({
539
- prompt,
540
- provider
541
- }) {
372
+ var import_provider6 = require("@ai-sdk/provider");
373
+ function convertToAnthropicMessagesPrompt(prompt) {
542
374
  let system;
543
375
  const messages = [];
544
376
  for (const { role, content } of prompt) {
@@ -558,8 +390,7 @@ function convertToAnthropicMessagesPrompt({
558
390
  }
559
391
  case "image": {
560
392
  if (part.image instanceof URL) {
561
- throw new UnsupportedFunctionalityError({
562
- provider,
393
+ throw new import_provider6.UnsupportedFunctionalityError({
563
394
  functionality: "URL image parts"
564
395
  });
565
396
  } else {
@@ -605,7 +436,8 @@ function convertToAnthropicMessagesPrompt({
605
436
  content: content.map((part) => ({
606
437
  type: "tool_result",
607
438
  tool_use_id: part.toolCallId,
608
- content: JSON.stringify(part.result)
439
+ content: JSON.stringify(part.result),
440
+ is_error: part.isError
609
441
  }))
610
442
  });
611
443
  break;
@@ -680,10 +512,7 @@ var AnthropicMessagesLanguageModel = class {
680
512
  setting: "seed"
681
513
  });
682
514
  }
683
- const messagesPrompt = convertToAnthropicMessagesPrompt({
684
- provider: this.provider,
685
- prompt
686
- });
515
+ const messagesPrompt = convertToAnthropicMessagesPrompt(prompt);
687
516
  const baseArgs = {
688
517
  // model id:
689
518
  model: this.modelId,
@@ -715,30 +544,29 @@ var AnthropicMessagesLanguageModel = class {
715
544
  };
716
545
  }
717
546
  case "object-json": {
718
- throw new UnsupportedFunctionalityError({
719
- functionality: "json-mode object generation",
720
- provider: this.provider
547
+ throw new import_provider7.UnsupportedFunctionalityError({
548
+ functionality: "json-mode object generation"
721
549
  });
722
550
  }
723
551
  case "object-tool": {
552
+ const { name, description, parameters } = mode.tool;
553
+ baseArgs.messages[baseArgs.messages.length - 1].content.push({
554
+ type: "text",
555
+ text: `
556
+
557
+ Use the '${name}' tool.`
558
+ });
724
559
  return {
725
560
  args: {
726
561
  ...baseArgs,
727
- tools: [
728
- {
729
- name: mode.tool.name,
730
- description: mode.tool.description,
731
- input_schema: mode.tool.parameters
732
- }
733
- ]
562
+ tools: [{ name, description, input_schema: parameters }]
734
563
  },
735
564
  warnings
736
565
  };
737
566
  }
738
567
  case "object-grammar": {
739
- throw new UnsupportedFunctionalityError({
740
- functionality: "grammar-mode object generation",
741
- provider: this.provider
568
+ throw new import_provider7.UnsupportedFunctionalityError({
569
+ functionality: "grammar-mode object generation"
742
570
  });
743
571
  }
744
572
  default: {