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