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
@@ -1,752 +0,0 @@
1
- import { JSONSchema7 } from 'json-schema';
2
- import * as zod from 'zod';
3
- import { ZodSchema } from 'zod';
4
-
5
- declare class APICallError extends Error {
6
- readonly url: string;
7
- readonly requestBodyValues: unknown;
8
- readonly statusCode?: number;
9
- readonly responseBody?: string;
10
- readonly cause?: unknown;
11
- readonly isRetryable: boolean;
12
- readonly data?: unknown;
13
- constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, // server error
14
- data, }: {
15
- message: string;
16
- url: string;
17
- requestBodyValues: unknown;
18
- statusCode?: number;
19
- responseBody?: string;
20
- cause?: unknown;
21
- isRetryable?: boolean;
22
- data?: unknown;
23
- });
24
- static isAPICallError(error: unknown): error is APICallError;
25
- toJSON(): {
26
- name: string;
27
- message: string;
28
- url: string;
29
- requestBodyValues: unknown;
30
- statusCode: number | undefined;
31
- responseBody: string | undefined;
32
- cause: unknown;
33
- isRetryable: boolean;
34
- data: unknown;
35
- };
36
- }
37
-
38
- declare class InvalidArgumentError extends Error {
39
- readonly parameter: string;
40
- readonly value: unknown;
41
- constructor({ parameter, value, message, }: {
42
- parameter: string;
43
- value: unknown;
44
- message: string;
45
- });
46
- static isInvalidArgumentError(error: unknown): error is InvalidArgumentError;
47
- toJSON(): {
48
- name: string;
49
- message: string;
50
- stack: string | undefined;
51
- parameter: string;
52
- value: unknown;
53
- };
54
- }
55
-
56
- declare class InvalidDataContentError extends Error {
57
- readonly content: unknown;
58
- constructor({ content, message, }: {
59
- content: unknown;
60
- message?: string;
61
- });
62
- static isInvalidDataContentError(error: unknown): error is InvalidDataContentError;
63
- toJSON(): {
64
- name: string;
65
- message: string;
66
- stack: string | undefined;
67
- content: unknown;
68
- };
69
- }
70
-
71
- declare class InvalidPromptError extends Error {
72
- readonly prompt: unknown;
73
- constructor({ prompt, message }: {
74
- prompt: unknown;
75
- message: string;
76
- });
77
- static isInvalidPromptError(error: unknown): error is InvalidPromptError;
78
- toJSON(): {
79
- name: string;
80
- message: string;
81
- stack: string | undefined;
82
- prompt: unknown;
83
- };
84
- }
85
-
86
- /**
87
- * Server returned a response with invalid data content. This should be thrown by providers when they
88
- * cannot parse the response from the API.
89
- */
90
- declare class InvalidResponseDataError extends Error {
91
- readonly data: unknown;
92
- constructor({ data, message, }: {
93
- data: unknown;
94
- message?: string;
95
- });
96
- static isInvalidResponseDataError(error: unknown): error is InvalidResponseDataError;
97
- toJSON(): {
98
- name: string;
99
- message: string;
100
- stack: string | undefined;
101
- data: unknown;
102
- };
103
- }
104
-
105
- declare class InvalidToolArgumentsError extends Error {
106
- readonly toolName: string;
107
- readonly toolArgs: string;
108
- readonly cause: unknown;
109
- constructor({ toolArgs, toolName, cause, message, }: {
110
- message?: string;
111
- toolArgs: string;
112
- toolName: string;
113
- cause: unknown;
114
- });
115
- static isInvalidToolArgumentsError(error: unknown): error is InvalidToolArgumentsError;
116
- toJSON(): {
117
- name: string;
118
- message: string;
119
- cause: unknown;
120
- stack: string | undefined;
121
- toolName: string;
122
- toolArgs: string;
123
- };
124
- }
125
-
126
- declare class JSONParseError extends Error {
127
- readonly text: string;
128
- readonly cause: unknown;
129
- constructor({ text, cause }: {
130
- text: string;
131
- cause: unknown;
132
- });
133
- static isJSONParseError(error: unknown): error is JSONParseError;
134
- toJSON(): {
135
- name: string;
136
- message: string;
137
- cause: unknown;
138
- stack: string | undefined;
139
- valueText: string;
140
- };
141
- }
142
-
143
- declare class LoadAPIKeyError extends Error {
144
- constructor({ message }: {
145
- message: string;
146
- });
147
- static isLoadAPIKeyError(error: unknown): error is LoadAPIKeyError;
148
- toJSON(): {
149
- name: string;
150
- message: string;
151
- };
152
- }
153
-
154
- declare class NoTextGeneratedError extends Error {
155
- readonly cause: unknown;
156
- constructor();
157
- static isNoTextGeneratedError(error: unknown): error is NoTextGeneratedError;
158
- toJSON(): {
159
- name: string;
160
- cause: unknown;
161
- message: string;
162
- stack: string | undefined;
163
- };
164
- }
165
-
166
- declare class NoResponseBodyError extends Error {
167
- constructor({ message }?: {
168
- message?: string;
169
- });
170
- static isNoResponseBodyError(error: unknown): error is NoResponseBodyError;
171
- toJSON(): {
172
- name: string;
173
- message: string;
174
- stack: string | undefined;
175
- };
176
- }
177
-
178
- declare class NoSuchToolError extends Error {
179
- readonly toolName: string;
180
- readonly availableTools: string[] | undefined;
181
- constructor({ toolName, availableTools, message, }: {
182
- toolName: string;
183
- availableTools?: string[] | undefined;
184
- message?: string;
185
- });
186
- static isNoSuchToolError(error: unknown): error is NoSuchToolError;
187
- toJSON(): {
188
- name: string;
189
- message: string;
190
- stack: string | undefined;
191
- toolName: string;
192
- availableTools: string[] | undefined;
193
- };
194
- }
195
-
196
- type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
197
- declare class RetryError extends Error {
198
- readonly reason: RetryErrorReason;
199
- readonly lastError: unknown;
200
- readonly errors: Array<unknown>;
201
- constructor({ message, reason, errors, }: {
202
- message: string;
203
- reason: RetryErrorReason;
204
- errors: Array<unknown>;
205
- });
206
- static isRetryError(error: unknown): error is RetryError;
207
- toJSON(): {
208
- name: string;
209
- message: string;
210
- reason: RetryErrorReason;
211
- lastError: unknown;
212
- errors: unknown[];
213
- };
214
- }
215
-
216
- /**
217
- A tool has a name, a description, and a set of parameters.
218
-
219
- Note: this is **not** the user-facing tool definition. The AI SDK methods will
220
- map the user-facing tool definitions to this format.
221
- */
222
- type LanguageModelV1FunctionTool = {
223
- /**
224
- The type of the tool. Only functions for now, but this gives us room to
225
- add more specific tool types in the future and use a discriminated union.
226
- */
227
- type: 'function';
228
- /**
229
- The name of the tool. Unique within this model call.
230
- */
231
- name: string;
232
- description?: string;
233
- parameters: JSONSchema7;
234
- };
235
-
236
- declare class ToolCallParseError extends Error {
237
- readonly cause: unknown;
238
- readonly text: string;
239
- readonly tools: LanguageModelV1FunctionTool[];
240
- constructor({ cause, text, tools, message, }: {
241
- cause: unknown;
242
- text: string;
243
- tools: LanguageModelV1FunctionTool[];
244
- message?: string;
245
- });
246
- static isToolCallParseError(error: unknown): error is ToolCallParseError;
247
- toJSON(): {
248
- name: string;
249
- message: string;
250
- stack: string | undefined;
251
- cause: unknown;
252
- text: string;
253
- tools: LanguageModelV1FunctionTool[];
254
- };
255
- }
256
-
257
- declare class TypeValidationError extends Error {
258
- readonly value: unknown;
259
- readonly cause: unknown;
260
- constructor({ value, cause }: {
261
- value: unknown;
262
- cause: unknown;
263
- });
264
- static isTypeValidationError(error: unknown): error is TypeValidationError;
265
- toJSON(): {
266
- name: string;
267
- message: string;
268
- cause: unknown;
269
- stack: string | undefined;
270
- value: unknown;
271
- };
272
- }
273
-
274
- declare class UnsupportedFunctionalityError extends Error {
275
- readonly functionality: string;
276
- readonly provider: string;
277
- constructor({ provider, functionality, }: {
278
- provider: string;
279
- functionality: string;
280
- });
281
- static isUnsupportedFunctionalityError(error: unknown): error is UnsupportedFunctionalityError;
282
- toJSON(): {
283
- name: string;
284
- message: string;
285
- stack: string | undefined;
286
- provider: string;
287
- functionality: string;
288
- };
289
- }
290
-
291
- declare class UnsupportedJSONSchemaError extends Error {
292
- readonly provider: string;
293
- readonly reason: string;
294
- readonly schema: unknown;
295
- constructor({ provider, schema, reason, message, }: {
296
- provider: string;
297
- schema: unknown;
298
- reason: string;
299
- message?: string;
300
- });
301
- static isUnsupportedJSONSchemaError(error: unknown): error is UnsupportedJSONSchemaError;
302
- toJSON(): {
303
- name: string;
304
- message: string;
305
- stack: string | undefined;
306
- provider: string;
307
- reason: string;
308
- schema: unknown;
309
- };
310
- }
311
-
312
- type LanguageModelV1CallSettings = {
313
- /**
314
- * Maximum number of tokens to generate.
315
- */
316
- maxTokens?: number;
317
- /**
318
- * Temperature setting. This is a number between 0 (almost no randomness) and
319
- * 1 (very random).
320
- *
321
- * Different LLM providers have different temperature
322
- * scales, so they'd need to map it (without mapping, the same temperature has
323
- * different effects on different models). The provider can also chose to map
324
- * this to topP, potentially even using a custom setting on their model.
325
- *
326
- * Note: This is an example of a setting that requires a clear specification of
327
- * the semantics.
328
- */
329
- temperature?: number;
330
- /**
331
- * Nucleus sampling. This is a number between 0 and 1.
332
- *
333
- * E.g. 0.1 would mean that only tokens with the top 10% probability mass
334
- * are considered.
335
- *
336
- * It is recommended to set either `temperature` or `topP`, but not both.
337
- */
338
- topP?: number;
339
- /**
340
- * Presence penalty setting. It affects the likelihood of the model to
341
- * repeat information that is already in the prompt.
342
- *
343
- * The presence penalty is a number between -1 (increase repetition)
344
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
345
- */
346
- presencePenalty?: number;
347
- /**
348
- * Frequency penalty setting. It affects the likelihood of the model
349
- * to repeatedly use the same words or phrases.
350
- *
351
- * The frequency penalty is a number between -1 (increase repetition)
352
- * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
353
- */
354
- frequencyPenalty?: number;
355
- /**
356
- * The seed (integer) to use for random sampling. If set and supported
357
- * by the model, calls will generate deterministic results.
358
- */
359
- seed?: number;
360
- /**
361
- * Abort signal for cancelling the operation.
362
- */
363
- abortSignal?: AbortSignal;
364
- };
365
-
366
- /**
367
- * A prompt is a list of messages.
368
- *
369
- * Note: Not all models and prompt formats support multi-modal inputs and
370
- * tool calls. The validation happens at runtime.
371
- *
372
- * Note: This is not a user-facing prompt. The AI SDK methods will map the
373
- * user-facing prompt types such as chat or instruction prompts to this format.
374
- */
375
- type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
376
- type LanguageModelV1Message = {
377
- role: 'system';
378
- content: string;
379
- } | {
380
- role: 'user';
381
- content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
382
- } | {
383
- role: 'assistant';
384
- content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
385
- } | {
386
- role: 'tool';
387
- content: Array<LanguageModelV1ToolResultPart>;
388
- };
389
- interface LanguageModelV1TextPart {
390
- type: 'text';
391
- /**
392
- * The text content.
393
- */
394
- text: string;
395
- }
396
- interface LanguageModelV1ImagePart {
397
- type: 'image';
398
- /**
399
- * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
400
- */
401
- image: Uint8Array | URL;
402
- /**
403
- * Optional mime type of the image.
404
- */
405
- mimeType?: string;
406
- }
407
- interface LanguageModelV1ToolCallPart {
408
- type: 'tool-call';
409
- toolCallId: string;
410
- toolName: string;
411
- args: unknown;
412
- }
413
- interface LanguageModelV1ToolResultPart {
414
- type: 'tool-result';
415
- toolCallId: string;
416
- toolName: string;
417
- result: unknown;
418
- }
419
-
420
- type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
421
- /**
422
- * Whether the user provided the input as messages or as
423
- * a prompt. This can help guide non-chat models in the
424
- * expansion, bc different expansions can be needed for
425
- * chat/non-chat use cases.
426
- */
427
- inputFormat: 'messages' | 'prompt';
428
- /**
429
- * The mode affects the behavior of the language model. It is required to
430
- * support provider-independent streaming and generation of structured objects.
431
- * The model can take this information and e.g. configure json mode, the correct
432
- * low level grammar, etc. It can also be used to optimize the efficiency of the
433
- * streaming, e.g. tool-delta stream parts are only needed in the
434
- * object-tool mode.
435
- */
436
- mode: {
437
- type: 'regular';
438
- tools?: Array<LanguageModelV1FunctionTool>;
439
- } | {
440
- type: 'object-json';
441
- } | {
442
- type: 'object-grammar';
443
- schema: JSONSchema7;
444
- } | {
445
- type: 'object-tool';
446
- tool: LanguageModelV1FunctionTool;
447
- };
448
- /**
449
- * A language mode prompt is a standardized prompt type.
450
- *
451
- * Note: This is **not** the user-facing prompt. The AI SDK methods will map the
452
- * user-facing prompt types such as chat or instruction prompts to this format.
453
- * That approach allows us to evolve the user facing prompts without breaking
454
- * the language model interface.
455
- */
456
- prompt: LanguageModelV1Prompt;
457
- };
458
-
459
- /**
460
- * Warning from the model provider for this call. The call will proceed, but e.g.
461
- * some settings might not be supported, which can lead to suboptimal results.
462
- */
463
- type LanguageModelV1CallWarning = {
464
- type: 'unsupported-setting';
465
- setting: keyof LanguageModelV1CallSettings;
466
- } | {
467
- type: 'other';
468
- message: string;
469
- };
470
-
471
- type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
472
-
473
- type LanguageModelV1FunctionToolCall = {
474
- toolCallType: 'function';
475
- toolCallId: string;
476
- toolName: string;
477
- /**
478
- * Stringified JSON object with the tool call arguments. Must match the
479
- * parameters schema of the tool.
480
- */
481
- args: string;
482
- };
483
-
484
- /**
485
- * Experimental: Specification for a language model that implements the language model
486
- * interface version 1.
487
- */
488
- type LanguageModelV1 = {
489
- /**
490
- * The language model must specify which language model interface
491
- * version it implements. This will allow us to evolve the language
492
- * model interface and retain backwards compatibility. The different
493
- * implementation versions can be handled as a discriminated union
494
- * on our side.
495
- */
496
- readonly specificationVersion: 'v1';
497
- /**
498
- * Name of the provider for logging purposes.
499
- */
500
- readonly provider: string;
501
- /**
502
- * Provider-specific model ID for logging purposes.
503
- */
504
- readonly modelId: string;
505
- /**
506
- * Default object generation mode that should be used with this model when
507
- * no mode is specified. Should be the mode with the best results for this
508
- * model. `undefined` can be returned if object generation is not supported.
509
- *
510
- * This is needed to generate the best objects possible w/o requiring the
511
- * user to explicitly specify the object generation mode.
512
- */
513
- readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
514
- /**
515
- * Generates a language model output (non-streaming).
516
- *
517
- * Naming: "do" prefix to prevent accidental direct usage of the method
518
- * by the user.
519
- */
520
- doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
521
- /**
522
- * Text that the model has generated. Can be undefined if the model
523
- * has only generated tool calls.
524
- */
525
- text?: string;
526
- /**
527
- * Tool calls that the model has generated. Can be undefined if the
528
- * model has only generated text.
529
- */
530
- toolCalls?: Array<LanguageModelV1FunctionToolCall>;
531
- /**
532
- * Finish reason.
533
- */
534
- finishReason: LanguageModelV1FinishReason;
535
- /**
536
- * Usage information.
537
- */
538
- usage: {
539
- promptTokens: number;
540
- completionTokens: number;
541
- };
542
- /**
543
- * Raw prompt and setting information for observability provider integration.
544
- */
545
- rawCall: {
546
- /**
547
- * Raw prompt after expansion and conversion to the format that the
548
- * provider uses to send the information to their API.
549
- */
550
- rawPrompt: unknown;
551
- /**
552
- * Raw settings that are used for the API call. Includes provider-specific
553
- * settings.
554
- */
555
- rawSettings: Record<string, unknown>;
556
- };
557
- warnings?: LanguageModelV1CallWarning[];
558
- }>;
559
- /**
560
- * Generates a language model output (streaming).
561
- *
562
- * Naming: "do" prefix to prevent accidental direct usage of the method
563
- * by the user.
564
- *
565
- * @return A stream of higher-level language model output parts.
566
- */
567
- doStream(options: LanguageModelV1CallOptions): PromiseLike<{
568
- stream: ReadableStream<LanguageModelV1StreamPart>;
569
- /**
570
- * Raw prompt and setting information for observability provider integration.
571
- */
572
- rawCall: {
573
- /**
574
- * Raw prompt after expansion and conversion to the format that the
575
- * provider uses to send the information to their API.
576
- */
577
- rawPrompt: unknown;
578
- /**
579
- * Raw settings that are used for the API call. Includes provider-specific
580
- * settings.
581
- */
582
- rawSettings: Record<string, unknown>;
583
- };
584
- warnings?: LanguageModelV1CallWarning[];
585
- }>;
586
- };
587
- type LanguageModelV1StreamPart = {
588
- type: 'text-delta';
589
- textDelta: string;
590
- } | ({
591
- type: 'tool-call';
592
- } & LanguageModelV1FunctionToolCall) | {
593
- type: 'tool-call-delta';
594
- toolCallType: 'function';
595
- toolCallId: string;
596
- toolName: string;
597
- argsTextDelta: string;
598
- } | {
599
- type: 'finish';
600
- finishReason: LanguageModelV1FinishReason;
601
- usage: {
602
- promptTokens: number;
603
- completionTokens: number;
604
- };
605
- } | {
606
- type: 'error';
607
- error: unknown;
608
- };
609
-
610
- /**
611
- * Generates a 7-character random string to use for IDs. Not secure.
612
- */
613
- declare const generateId: (size?: number | undefined) => string;
614
-
615
- declare function getErrorMessage(error: unknown | undefined): string;
616
-
617
- declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
618
- apiKey: string | undefined;
619
- environmentVariableName: string;
620
- apiKeyParameterName?: string;
621
- description: string;
622
- }): string;
623
-
624
- /**
625
- * Parses a JSON string into an unknown object.
626
- *
627
- * @param text - The JSON string to parse.
628
- * @returns {unknown} - The parsed JSON object.
629
- */
630
- declare function parseJSON({ text }: {
631
- text: string;
632
- }): unknown;
633
- /**
634
- * Parses a JSON string into a strongly-typed object using the provided schema.
635
- *
636
- * @template T - The type of the object to parse the JSON into.
637
- * @param {string} text - The JSON string to parse.
638
- * @param {Schema<T>} schema - The schema to use for parsing the JSON.
639
- * @returns {T} - The parsed object.
640
- */
641
- declare function parseJSON<T>({ text, schema, }: {
642
- text: string;
643
- schema: ZodSchema<T>;
644
- }): T;
645
- type ParseResult<T> = {
646
- success: true;
647
- value: T;
648
- } | {
649
- success: false;
650
- error: JSONParseError | TypeValidationError;
651
- };
652
- /**
653
- * Safely parses a JSON string and returns the result as an object of type `unknown`.
654
- *
655
- * @param text - The JSON string to parse.
656
- * @returns {object} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
657
- */
658
- declare function safeParseJSON({ text }: {
659
- text: string;
660
- }): ParseResult<unknown>;
661
- /**
662
- * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
663
- *
664
- * @template T - The type of the object to parse the JSON into.
665
- * @param {string} text - The JSON string to parse.
666
- * @param {Schema<T>} schema - The schema to use for parsing the JSON.
667
- * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
668
- */
669
- declare function safeParseJSON<T>({ text, schema, }: {
670
- text: string;
671
- schema: ZodSchema<T>;
672
- }): ParseResult<T>;
673
- declare function isParseableJson(input: string): boolean;
674
-
675
- type ResponseHandler<RETURN_TYPE> = (options: {
676
- url: string;
677
- requestBodyValues: unknown;
678
- response: Response;
679
- }) => PromiseLike<RETURN_TYPE>;
680
- declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
681
- errorSchema: ZodSchema<T, zod.ZodTypeDef, T>;
682
- errorToMessage: (error: T) => string;
683
- isRetryable?: ((response: Response, error?: T | undefined) => boolean) | undefined;
684
- }) => ResponseHandler<APICallError>;
685
- declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodSchema<T, zod.ZodTypeDef, T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
686
- declare const createJsonResponseHandler: <T>(responseSchema: ZodSchema<T, zod.ZodTypeDef, T>) => ResponseHandler<T>;
687
-
688
- declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, }: {
689
- url: string;
690
- headers?: Record<string, string | undefined> | undefined;
691
- body: unknown;
692
- failedResponseHandler: ResponseHandler<APICallError>;
693
- successfulResponseHandler: ResponseHandler<T>;
694
- abortSignal?: AbortSignal | undefined;
695
- }) => Promise<T>;
696
- declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, }: {
697
- url: string;
698
- headers?: Record<string, string | undefined> | undefined;
699
- body: {
700
- content: string | FormData | Uint8Array;
701
- values: unknown;
702
- };
703
- failedResponseHandler: ResponseHandler<Error>;
704
- successfulResponseHandler: ResponseHandler<T>;
705
- abortSignal?: AbortSignal | undefined;
706
- }) => Promise<T>;
707
-
708
- declare function scale({ inputMin, inputMax, outputMin, outputMax, value, }: {
709
- inputMin?: number;
710
- inputMax?: number;
711
- outputMin: number;
712
- outputMax: number;
713
- value: number | undefined;
714
- }): number | undefined;
715
-
716
- declare function convertBase64ToUint8Array(base64String: string): Uint8Array;
717
- declare function convertUint8ArrayToBase64(array: Uint8Array): string;
718
-
719
- /**
720
- * Validates the types of an unknown object using a schema and
721
- * return a strongly-typed object.
722
- *
723
- * @template T - The type of the object to validate.
724
- * @param {string} options.value - The object to validate.
725
- * @param {Schema<T>} options.schema - The schema to use for validating the JSON.
726
- * @returns {T} - The typed object.
727
- */
728
- declare function validateTypes<T>({ value, schema, }: {
729
- value: unknown;
730
- schema: ZodSchema<T>;
731
- }): T;
732
- /**
733
- * Safely validates the types of an unknown object using a schema and
734
- * return a strongly-typed object.
735
- *
736
- * @template T - The type of the object to validate.
737
- * @param {string} options.value - The JSON object to validate.
738
- * @param {Schema<T>} options.schema - The schema to use for validating the JSON.
739
- * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
740
- */
741
- declare function safeValidateTypes<T>({ value, schema, }: {
742
- value: unknown;
743
- schema: ZodSchema<T>;
744
- }): {
745
- success: true;
746
- value: T;
747
- } | {
748
- success: false;
749
- error: TypeValidationError;
750
- };
751
-
752
- export { APICallError, InvalidArgumentError, InvalidDataContentError, InvalidPromptError, InvalidResponseDataError, InvalidToolArgumentsError, JSONParseError, LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1CallWarning, LanguageModelV1FinishReason, LanguageModelV1FunctionTool, LanguageModelV1FunctionToolCall, LanguageModelV1ImagePart, LanguageModelV1Message, LanguageModelV1Prompt, LanguageModelV1StreamPart, LanguageModelV1TextPart, LanguageModelV1ToolCallPart, LanguageModelV1ToolResultPart, LoadAPIKeyError, NoResponseBodyError, NoSuchToolError, NoTextGeneratedError, ParseResult, ResponseHandler, RetryError, RetryErrorReason, ToolCallParseError, TypeValidationError, UnsupportedFunctionalityError, UnsupportedJSONSchemaError, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, generateId, getErrorMessage, isParseableJson, loadApiKey, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, scale, validateTypes };