ai 3.0.13 → 3.0.14

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