ai 3.1.0-canary.4 → 3.1.1

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