ai 3.0.20 → 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 (53) hide show
  1. package/anthropic/dist/index.d.mts +1 -353
  2. package/anthropic/dist/index.d.ts +1 -353
  3. package/anthropic/dist/index.js +30 -188
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +18 -172
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +7 -353
  8. package/dist/index.d.ts +7 -353
  9. package/dist/index.js +98 -324
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +75 -296
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +1 -353
  14. package/google/dist/index.d.ts +1 -353
  15. package/google/dist/index.js +31 -189
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +19 -173
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +1 -353
  20. package/mistral/dist/index.d.ts +1 -353
  21. package/mistral/dist/index.js +29 -187
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +17 -171
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +2 -354
  26. package/openai/dist/index.d.ts +2 -354
  27. package/openai/dist/index.js +64 -255
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +52 -235
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +4 -10
  32. package/react/dist/index.d.mts +1 -1
  33. package/react/dist/index.d.ts +1 -1
  34. package/react/dist/index.js.map +1 -1
  35. package/react/dist/index.mjs.map +1 -1
  36. package/solid/dist/index.d.mts +1 -1
  37. package/solid/dist/index.d.ts +1 -1
  38. package/solid/dist/index.js.map +1 -1
  39. package/solid/dist/index.mjs.map +1 -1
  40. package/svelte/dist/index.d.mts +1 -1
  41. package/svelte/dist/index.d.ts +1 -1
  42. package/svelte/dist/index.js.map +1 -1
  43. package/svelte/dist/index.mjs.map +1 -1
  44. package/vue/dist/index.d.mts +1 -1
  45. package/vue/dist/index.d.ts +1 -1
  46. package/vue/dist/index.js.map +1 -1
  47. package/vue/dist/index.mjs.map +1 -1
  48. package/spec/dist/index.d.mts +0 -780
  49. package/spec/dist/index.d.ts +0 -780
  50. package/spec/dist/index.js +0 -863
  51. package/spec/dist/index.js.map +0 -1
  52. package/spec/dist/index.mjs +0 -797
  53. package/spec/dist/index.mjs.map +0 -1
@@ -1,863 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // spec/index.ts
31
- var spec_exports = {};
32
- __export(spec_exports, {
33
- APICallError: () => APICallError,
34
- InvalidArgumentError: () => InvalidArgumentError,
35
- InvalidDataContentError: () => InvalidDataContentError,
36
- InvalidPromptError: () => InvalidPromptError,
37
- InvalidResponseDataError: () => InvalidResponseDataError,
38
- InvalidToolArgumentsError: () => InvalidToolArgumentsError,
39
- JSONParseError: () => JSONParseError,
40
- LoadAPIKeyError: () => LoadAPIKeyError,
41
- NoResponseBodyError: () => NoResponseBodyError,
42
- NoSuchToolError: () => NoSuchToolError,
43
- NoTextGeneratedError: () => NoTextGeneratedError,
44
- RetryError: () => RetryError,
45
- ToolCallParseError: () => ToolCallParseError,
46
- TypeValidationError: () => TypeValidationError,
47
- UnsupportedFunctionalityError: () => UnsupportedFunctionalityError,
48
- UnsupportedJSONSchemaError: () => UnsupportedJSONSchemaError,
49
- convertBase64ToUint8Array: () => convertBase64ToUint8Array,
50
- convertUint8ArrayToBase64: () => convertUint8ArrayToBase64,
51
- createEventSourceResponseHandler: () => createEventSourceResponseHandler,
52
- createJsonErrorResponseHandler: () => createJsonErrorResponseHandler,
53
- createJsonResponseHandler: () => createJsonResponseHandler,
54
- generateId: () => generateId,
55
- getErrorMessage: () => getErrorMessage,
56
- isParseableJson: () => isParseableJson,
57
- loadApiKey: () => loadApiKey,
58
- parseJSON: () => parseJSON,
59
- postJsonToApi: () => postJsonToApi,
60
- postToApi: () => postToApi,
61
- safeParseJSON: () => safeParseJSON,
62
- safeValidateTypes: () => safeValidateTypes,
63
- scale: () => scale,
64
- validateTypes: () => validateTypes
65
- });
66
- module.exports = __toCommonJS(spec_exports);
67
-
68
- // spec/errors/api-call-error.ts
69
- var APICallError = class extends Error {
70
- constructor({
71
- message,
72
- url,
73
- requestBodyValues,
74
- statusCode,
75
- responseBody,
76
- cause,
77
- isRetryable = statusCode != null && (statusCode === 408 || // request timeout
78
- statusCode === 409 || // conflict
79
- statusCode === 429 || // too many requests
80
- statusCode >= 500),
81
- // server error
82
- data
83
- }) {
84
- super(message);
85
- this.name = "AI_APICallError";
86
- this.url = url;
87
- this.requestBodyValues = requestBodyValues;
88
- this.statusCode = statusCode;
89
- this.responseBody = responseBody;
90
- this.cause = cause;
91
- this.isRetryable = isRetryable;
92
- this.data = data;
93
- }
94
- static isAPICallError(error) {
95
- 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");
96
- }
97
- toJSON() {
98
- return {
99
- name: this.name,
100
- message: this.message,
101
- url: this.url,
102
- requestBodyValues: this.requestBodyValues,
103
- statusCode: this.statusCode,
104
- responseBody: this.responseBody,
105
- cause: this.cause,
106
- isRetryable: this.isRetryable,
107
- data: this.data
108
- };
109
- }
110
- };
111
-
112
- // spec/errors/invalid-argument-error.ts
113
- var InvalidArgumentError = class extends Error {
114
- constructor({
115
- parameter,
116
- value,
117
- message
118
- }) {
119
- super(`Invalid argument for parameter ${parameter}: ${message}`);
120
- this.name = "AI_InvalidArgumentError";
121
- this.parameter = parameter;
122
- this.value = value;
123
- }
124
- static isInvalidArgumentError(error) {
125
- return error instanceof Error && error.name === "AI_InvalidArgumentError" && typeof error.parameter === "string" && typeof error.value === "string";
126
- }
127
- toJSON() {
128
- return {
129
- name: this.name,
130
- message: this.message,
131
- stack: this.stack,
132
- parameter: this.parameter,
133
- value: this.value
134
- };
135
- }
136
- };
137
-
138
- // spec/errors/invalid-data-content-error.ts
139
- var InvalidDataContentError = class extends Error {
140
- constructor({
141
- content,
142
- message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
143
- }) {
144
- super(message);
145
- this.name = "AI_InvalidDataContentError";
146
- this.content = content;
147
- }
148
- static isInvalidDataContentError(error) {
149
- return error instanceof Error && error.name === "AI_InvalidDataContentError" && error.content != null;
150
- }
151
- toJSON() {
152
- return {
153
- name: this.name,
154
- message: this.message,
155
- stack: this.stack,
156
- content: this.content
157
- };
158
- }
159
- };
160
-
161
- // spec/errors/invalid-prompt-error.ts
162
- var InvalidPromptError = class extends Error {
163
- constructor({ prompt: prompt2, message }) {
164
- super(`Invalid prompt: ${message}`);
165
- this.name = "AI_InvalidPromptError";
166
- this.prompt = prompt2;
167
- }
168
- static isInvalidPromptError(error) {
169
- return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
170
- }
171
- toJSON() {
172
- return {
173
- name: this.name,
174
- message: this.message,
175
- stack: this.stack,
176
- prompt: this.prompt
177
- };
178
- }
179
- };
180
-
181
- // spec/errors/invalid-response-data-error.ts
182
- var InvalidResponseDataError = class extends Error {
183
- constructor({
184
- data,
185
- message = `Invalid response data: ${JSON.stringify(data)}.`
186
- }) {
187
- super(message);
188
- this.name = "AI_InvalidResponseDataError";
189
- this.data = data;
190
- }
191
- static isInvalidResponseDataError(error) {
192
- return error instanceof Error && error.name === "AI_InvalidResponseDataError" && error.data != null;
193
- }
194
- toJSON() {
195
- return {
196
- name: this.name,
197
- message: this.message,
198
- stack: this.stack,
199
- data: this.data
200
- };
201
- }
202
- };
203
-
204
- // spec/util/generate-id.ts
205
- var import_non_secure = require("nanoid/non-secure");
206
- var generateId = (0, import_non_secure.customAlphabet)(
207
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
208
- 7
209
- );
210
-
211
- // spec/util/get-error-message.ts
212
- function getErrorMessage(error) {
213
- if (error == null) {
214
- return "unknown error";
215
- }
216
- if (typeof error === "string") {
217
- return error;
218
- }
219
- if (error instanceof Error) {
220
- return error.message;
221
- }
222
- return JSON.stringify(error);
223
- }
224
-
225
- // spec/errors/load-api-key-error.ts
226
- var LoadAPIKeyError = class extends Error {
227
- constructor({ message }) {
228
- super(message);
229
- this.name = "AI_LoadAPIKeyError";
230
- }
231
- static isLoadAPIKeyError(error) {
232
- return error instanceof Error && error.name === "AI_LoadAPIKeyError";
233
- }
234
- toJSON() {
235
- return {
236
- name: this.name,
237
- message: this.message
238
- };
239
- }
240
- };
241
-
242
- // spec/util/load-api-key.ts
243
- function loadApiKey({
244
- apiKey,
245
- environmentVariableName,
246
- apiKeyParameterName = "apiKey",
247
- description
248
- }) {
249
- if (typeof apiKey === "string") {
250
- return apiKey;
251
- }
252
- if (apiKey != null) {
253
- throw new LoadAPIKeyError({
254
- message: `${description} API key must be a string.`
255
- });
256
- }
257
- if (typeof process === "undefined") {
258
- throw new LoadAPIKeyError({
259
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
260
- });
261
- }
262
- apiKey = process.env[environmentVariableName];
263
- if (apiKey == null) {
264
- throw new LoadAPIKeyError({
265
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
266
- });
267
- }
268
- if (typeof apiKey !== "string") {
269
- throw new LoadAPIKeyError({
270
- message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
271
- });
272
- }
273
- return apiKey;
274
- }
275
-
276
- // spec/util/parse-json.ts
277
- var import_secure_json_parse = __toESM(require("secure-json-parse"));
278
-
279
- // spec/errors/json-parse-error.ts
280
- var JSONParseError = class extends Error {
281
- constructor({ text, cause }) {
282
- super(
283
- `JSON parsing failed: Text: ${text}.
284
- Error message: ${getErrorMessage(cause)}`
285
- );
286
- this.name = "AI_JSONParseError";
287
- this.cause = cause;
288
- this.text = text;
289
- }
290
- static isJSONParseError(error) {
291
- return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
292
- }
293
- toJSON() {
294
- return {
295
- name: this.name,
296
- message: this.message,
297
- cause: this.cause,
298
- stack: this.stack,
299
- valueText: this.text
300
- };
301
- }
302
- };
303
-
304
- // spec/errors/type-validation-error.ts
305
- var TypeValidationError = class extends Error {
306
- constructor({ value, cause }) {
307
- super(
308
- `Type validation failed: Value: ${JSON.stringify(value)}.
309
- Error message: ${getErrorMessage(cause)}`
310
- );
311
- this.name = "AI_TypeValidationError";
312
- this.cause = cause;
313
- this.value = value;
314
- }
315
- static isTypeValidationError(error) {
316
- return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
317
- }
318
- toJSON() {
319
- return {
320
- name: this.name,
321
- message: this.message,
322
- cause: this.cause,
323
- stack: this.stack,
324
- value: this.value
325
- };
326
- }
327
- };
328
-
329
- // spec/util/validate-types.ts
330
- function validateTypes({
331
- value,
332
- schema
333
- }) {
334
- try {
335
- return schema.parse(value);
336
- } catch (error) {
337
- throw new TypeValidationError({ value, cause: error });
338
- }
339
- }
340
- function safeValidateTypes({
341
- value,
342
- schema
343
- }) {
344
- try {
345
- const validationResult = schema.safeParse(value);
346
- if (validationResult.success) {
347
- return {
348
- success: true,
349
- value: validationResult.data
350
- };
351
- }
352
- return {
353
- success: false,
354
- error: new TypeValidationError({
355
- value,
356
- cause: validationResult.error
357
- })
358
- };
359
- } catch (error) {
360
- return {
361
- success: false,
362
- error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
363
- };
364
- }
365
- }
366
-
367
- // spec/util/parse-json.ts
368
- function parseJSON({
369
- text,
370
- schema
371
- }) {
372
- try {
373
- const value = import_secure_json_parse.default.parse(text);
374
- if (schema == null) {
375
- return value;
376
- }
377
- return validateTypes({ value, schema });
378
- } catch (error) {
379
- if (JSONParseError.isJSONParseError(error) || TypeValidationError.isTypeValidationError(error)) {
380
- throw error;
381
- }
382
- throw new JSONParseError({ text, cause: error });
383
- }
384
- }
385
- function safeParseJSON({
386
- text,
387
- schema
388
- }) {
389
- try {
390
- const value = import_secure_json_parse.default.parse(text);
391
- if (schema == null) {
392
- return {
393
- success: true,
394
- value
395
- };
396
- }
397
- return safeValidateTypes({ value, schema });
398
- } catch (error) {
399
- return {
400
- success: false,
401
- error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
402
- };
403
- }
404
- }
405
- function isParseableJson(input) {
406
- try {
407
- import_secure_json_parse.default.parse(input);
408
- return true;
409
- } catch (e) {
410
- return false;
411
- }
412
- }
413
-
414
- // spec/util/post-to-api.ts
415
- var postJsonToApi = async ({
416
- url,
417
- headers,
418
- body,
419
- failedResponseHandler,
420
- successfulResponseHandler,
421
- abortSignal
422
- }) => postToApi({
423
- url,
424
- headers: {
425
- ...headers,
426
- "Content-Type": "application/json"
427
- },
428
- body: {
429
- content: JSON.stringify(body),
430
- values: body
431
- },
432
- failedResponseHandler,
433
- successfulResponseHandler,
434
- abortSignal
435
- });
436
- var postToApi = async ({
437
- url,
438
- headers = {},
439
- body,
440
- successfulResponseHandler,
441
- failedResponseHandler,
442
- abortSignal
443
- }) => {
444
- try {
445
- const definedHeaders = Object.fromEntries(
446
- Object.entries(headers).filter(([_key, value]) => value != null)
447
- );
448
- const response = await fetch(url, {
449
- method: "POST",
450
- headers: definedHeaders,
451
- body: body.content,
452
- signal: abortSignal
453
- });
454
- if (!response.ok) {
455
- try {
456
- throw await failedResponseHandler({
457
- response,
458
- url,
459
- requestBodyValues: body.values
460
- });
461
- } catch (error) {
462
- if (error instanceof Error) {
463
- if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
464
- throw error;
465
- }
466
- }
467
- throw new APICallError({
468
- message: "Failed to process error response",
469
- cause: error,
470
- statusCode: response.status,
471
- url,
472
- requestBodyValues: body.values
473
- });
474
- }
475
- }
476
- try {
477
- return await successfulResponseHandler({
478
- response,
479
- url,
480
- requestBodyValues: body.values
481
- });
482
- } catch (error) {
483
- if (error instanceof Error) {
484
- if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
485
- throw error;
486
- }
487
- }
488
- throw new APICallError({
489
- message: "Failed to process successful response",
490
- cause: error,
491
- statusCode: response.status,
492
- url,
493
- requestBodyValues: body.values
494
- });
495
- }
496
- } catch (error) {
497
- if (error instanceof Error) {
498
- if (error.name === "AbortError") {
499
- throw error;
500
- }
501
- }
502
- if (error instanceof TypeError && error.message === "fetch failed") {
503
- const cause = error.cause;
504
- if (cause != null) {
505
- throw new APICallError({
506
- message: `Cannot connect to API: ${cause.message}`,
507
- cause,
508
- url,
509
- requestBodyValues: body.values,
510
- isRetryable: true
511
- // retry when network error
512
- });
513
- }
514
- }
515
- throw error;
516
- }
517
- };
518
-
519
- // spec/util/response-handler.ts
520
- var import_stream = require("eventsource-parser/stream");
521
-
522
- // spec/errors/no-response-body-error.ts
523
- var NoResponseBodyError = class extends Error {
524
- constructor({ message = "No response body" } = {}) {
525
- super(message);
526
- this.name = "AI_NoResponseBodyError";
527
- }
528
- static isNoResponseBodyError(error) {
529
- return error instanceof Error && error.name === "AI_NoResponseBodyError";
530
- }
531
- toJSON() {
532
- return {
533
- name: this.name,
534
- message: this.message,
535
- stack: this.stack
536
- };
537
- }
538
- };
539
-
540
- // spec/util/response-handler.ts
541
- var createJsonErrorResponseHandler = ({
542
- errorSchema,
543
- errorToMessage,
544
- isRetryable
545
- }) => async ({ response, url, requestBodyValues }) => {
546
- const responseBody = await response.text();
547
- if (responseBody.trim() === "") {
548
- return new APICallError({
549
- message: response.statusText,
550
- url,
551
- requestBodyValues,
552
- statusCode: response.status,
553
- responseBody,
554
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
555
- });
556
- }
557
- try {
558
- const parsedError = parseJSON({
559
- text: responseBody,
560
- schema: errorSchema
561
- });
562
- return new APICallError({
563
- message: errorToMessage(parsedError),
564
- url,
565
- requestBodyValues,
566
- statusCode: response.status,
567
- responseBody,
568
- data: parsedError,
569
- isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
570
- });
571
- } catch (parseError) {
572
- return new APICallError({
573
- message: response.statusText,
574
- url,
575
- requestBodyValues,
576
- statusCode: response.status,
577
- responseBody,
578
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
579
- });
580
- }
581
- };
582
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
583
- if (response.body == null) {
584
- throw new NoResponseBodyError();
585
- }
586
- return response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream()).pipeThrough(
587
- new TransformStream({
588
- transform({ data }, controller) {
589
- if (data === "[DONE]") {
590
- return;
591
- }
592
- controller.enqueue(
593
- safeParseJSON({
594
- text: data,
595
- schema: chunkSchema
596
- })
597
- );
598
- }
599
- })
600
- );
601
- };
602
- var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
603
- const responseBody = await response.text();
604
- const parsedResult = safeParseJSON({
605
- text: responseBody,
606
- schema: responseSchema
607
- });
608
- if (!parsedResult.success) {
609
- throw new APICallError({
610
- message: "Invalid JSON response",
611
- cause: parsedResult.error,
612
- statusCode: response.status,
613
- responseBody,
614
- url,
615
- requestBodyValues
616
- });
617
- }
618
- return parsedResult.value;
619
- };
620
-
621
- // spec/util/scale.ts
622
- function scale({
623
- inputMin = 0,
624
- inputMax = 1,
625
- outputMin,
626
- outputMax,
627
- value
628
- }) {
629
- if (value === void 0) {
630
- return void 0;
631
- }
632
- const inputRange = inputMax - inputMin;
633
- const outputRange = outputMax - outputMin;
634
- return (value - inputMin) * outputRange / inputRange + outputMin;
635
- }
636
-
637
- // spec/util/uint8-utils.ts
638
- function convertBase64ToUint8Array(base64String) {
639
- const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
640
- const latin1string = globalThis.atob(base64Url);
641
- return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
642
- }
643
- function convertUint8ArrayToBase64(array) {
644
- let latin1string = "";
645
- for (let i = 0; i < array.length; i++) {
646
- latin1string += String.fromCodePoint(array[i]);
647
- }
648
- return globalThis.btoa(latin1string);
649
- }
650
-
651
- // spec/errors/invalid-tool-arguments-error.ts
652
- var InvalidToolArgumentsError = class extends Error {
653
- constructor({
654
- toolArgs,
655
- toolName,
656
- cause,
657
- message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
658
- cause
659
- )}`
660
- }) {
661
- super(message);
662
- this.name = "AI_InvalidToolArgumentsError";
663
- this.toolArgs = toolArgs;
664
- this.toolName = toolName;
665
- this.cause = cause;
666
- }
667
- static isInvalidToolArgumentsError(error) {
668
- return error instanceof Error && error.name === "AI_InvalidToolArgumentsError" && typeof error.toolName === "string" && typeof error.toolArgs === "string";
669
- }
670
- toJSON() {
671
- return {
672
- name: this.name,
673
- message: this.message,
674
- cause: this.cause,
675
- stack: this.stack,
676
- toolName: this.toolName,
677
- toolArgs: this.toolArgs
678
- };
679
- }
680
- };
681
-
682
- // spec/errors/no-object-generated-error.ts
683
- var NoTextGeneratedError = class extends Error {
684
- constructor() {
685
- super(`No text generated.`);
686
- this.name = "AI_NoTextGeneratedError";
687
- }
688
- static isNoTextGeneratedError(error) {
689
- return error instanceof Error && error.name === "AI_NoTextGeneratedError";
690
- }
691
- toJSON() {
692
- return {
693
- name: this.name,
694
- cause: this.cause,
695
- message: this.message,
696
- stack: this.stack
697
- };
698
- }
699
- };
700
-
701
- // spec/errors/no-such-tool-error.ts
702
- var NoSuchToolError = class extends Error {
703
- constructor({
704
- toolName,
705
- availableTools = void 0,
706
- message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
707
- }) {
708
- super(message);
709
- this.name = "AI_NoSuchToolError";
710
- this.toolName = toolName;
711
- this.availableTools = availableTools;
712
- }
713
- static isNoSuchToolError(error) {
714
- return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
715
- }
716
- toJSON() {
717
- return {
718
- name: this.name,
719
- message: this.message,
720
- stack: this.stack,
721
- toolName: this.toolName,
722
- availableTools: this.availableTools
723
- };
724
- }
725
- };
726
-
727
- // spec/errors/retry-error.ts
728
- var RetryError = class extends Error {
729
- constructor({
730
- message,
731
- reason,
732
- errors
733
- }) {
734
- super(message);
735
- this.name = "AI_RetryError";
736
- this.reason = reason;
737
- this.errors = errors;
738
- this.lastError = errors[errors.length - 1];
739
- }
740
- static isRetryError(error) {
741
- return error instanceof Error && error.name === "AI_RetryError" && typeof error.reason === "string" && Array.isArray(error.errors);
742
- }
743
- toJSON() {
744
- return {
745
- name: this.name,
746
- message: this.message,
747
- reason: this.reason,
748
- lastError: this.lastError,
749
- errors: this.errors
750
- };
751
- }
752
- };
753
-
754
- // spec/errors/tool-call-parse-error.ts
755
- var ToolCallParseError = class extends Error {
756
- constructor({
757
- cause,
758
- text,
759
- tools,
760
- message = `Failed to parse tool calls: ${getErrorMessage(cause)}`
761
- }) {
762
- super(message);
763
- this.name = "AI_ToolCallParseError";
764
- this.cause = cause;
765
- this.text = text;
766
- this.tools = tools;
767
- }
768
- static isToolCallParseError(error) {
769
- return error instanceof Error && error.name === "AI_ToolCallParseError" && "cause" in error && error.cause != void 0 && "text" in error && error.text != void 0 && typeof error.text === "string" && "tools" in error && error.tools != void 0;
770
- }
771
- toJSON() {
772
- return {
773
- name: this.name,
774
- message: this.message,
775
- stack: this.stack,
776
- cause: this.cause,
777
- text: this.text,
778
- tools: this.tools
779
- };
780
- }
781
- };
782
-
783
- // spec/errors/unsupported-functionality-error.ts
784
- var UnsupportedFunctionalityError = class extends Error {
785
- constructor({ functionality }) {
786
- super(`'${functionality}' functionality not supported.`);
787
- this.name = "AI_UnsupportedFunctionalityError";
788
- this.functionality = functionality;
789
- }
790
- static isUnsupportedFunctionalityError(error) {
791
- return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.functionality === "string";
792
- }
793
- toJSON() {
794
- return {
795
- name: this.name,
796
- message: this.message,
797
- stack: this.stack,
798
- functionality: this.functionality
799
- };
800
- }
801
- };
802
-
803
- // spec/errors/unsupported-json-schema-error.ts
804
- var UnsupportedJSONSchemaError = class extends Error {
805
- constructor({
806
- schema,
807
- reason,
808
- message = `Unsupported JSON schema: ${reason}`
809
- }) {
810
- super(message);
811
- this.name = "AI_UnsupportedJSONSchemaError";
812
- this.reason = reason;
813
- this.schema = schema;
814
- }
815
- static isUnsupportedJSONSchemaError(error) {
816
- return error instanceof Error && error.name === "AI_UnsupportedJSONSchemaError" && "reason" in error && error.reason != void 0 && "schema" in error && error.schema !== void 0;
817
- }
818
- toJSON() {
819
- return {
820
- name: this.name,
821
- message: this.message,
822
- stack: this.stack,
823
- reason: this.reason,
824
- schema: this.schema
825
- };
826
- }
827
- };
828
- // Annotate the CommonJS export names for ESM import in node:
829
- 0 && (module.exports = {
830
- APICallError,
831
- InvalidArgumentError,
832
- InvalidDataContentError,
833
- InvalidPromptError,
834
- InvalidResponseDataError,
835
- InvalidToolArgumentsError,
836
- JSONParseError,
837
- LoadAPIKeyError,
838
- NoResponseBodyError,
839
- NoSuchToolError,
840
- NoTextGeneratedError,
841
- RetryError,
842
- ToolCallParseError,
843
- TypeValidationError,
844
- UnsupportedFunctionalityError,
845
- UnsupportedJSONSchemaError,
846
- convertBase64ToUint8Array,
847
- convertUint8ArrayToBase64,
848
- createEventSourceResponseHandler,
849
- createJsonErrorResponseHandler,
850
- createJsonResponseHandler,
851
- generateId,
852
- getErrorMessage,
853
- isParseableJson,
854
- loadApiKey,
855
- parseJSON,
856
- postJsonToApi,
857
- postToApi,
858
- safeParseJSON,
859
- safeValidateTypes,
860
- scale,
861
- validateTypes
862
- });
863
- //# sourceMappingURL=index.js.map