ai 3.1.0-canary.0 → 3.1.0-canary.2

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 (61) hide show
  1. package/ai-model-specification/dist/index.d.mts +539 -0
  2. package/ai-model-specification/dist/index.d.ts +539 -0
  3. package/ai-model-specification/dist/index.js +581 -0
  4. package/ai-model-specification/dist/index.js.map +1 -0
  5. package/ai-model-specification/dist/index.mjs +526 -0
  6. package/ai-model-specification/dist/index.mjs.map +1 -0
  7. package/core/dist/index.d.mts +122 -77
  8. package/core/dist/index.d.ts +122 -77
  9. package/core/dist/index.js +266 -174
  10. package/core/dist/index.js.map +1 -1
  11. package/core/dist/index.mjs +266 -173
  12. package/core/dist/index.mjs.map +1 -1
  13. package/dist/index.d.mts +3 -1
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.js +39 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +39 -1
  18. package/dist/index.mjs.map +1 -1
  19. package/package.json +14 -4
  20. package/prompts/dist/index.d.mts +32 -19
  21. package/prompts/dist/index.d.ts +32 -19
  22. package/prompts/dist/index.js +0 -1
  23. package/prompts/dist/index.js.map +1 -1
  24. package/prompts/dist/index.mjs +0 -1
  25. package/prompts/dist/index.mjs.map +1 -1
  26. package/provider/dist/index.d.mts +154 -191
  27. package/provider/dist/index.d.ts +154 -191
  28. package/provider/dist/index.js +800 -26131
  29. package/provider/dist/index.js.map +1 -1
  30. package/provider/dist/index.mjs +770 -7736
  31. package/provider/dist/index.mjs.map +1 -1
  32. package/react/dist/index.js +16 -1
  33. package/react/dist/index.js.map +1 -1
  34. package/react/dist/index.mjs +16 -1
  35. package/react/dist/index.mjs.map +1 -1
  36. package/rsc/dist/index.d.ts +11 -0
  37. package/rsc/dist/rsc-server.d.mts +11 -0
  38. package/rsc/dist/rsc-server.mjs +21 -21
  39. package/rsc/dist/rsc-server.mjs.map +1 -1
  40. package/rsc/dist/rsc-shared.mjs +21 -1
  41. package/rsc/dist/rsc-shared.mjs.map +1 -1
  42. package/provider/dist/chunk-3DTRVHCT.mjs +0 -5046
  43. package/provider/dist/chunk-3DTRVHCT.mjs.map +0 -1
  44. package/provider/dist/chunk-4OUDS3CP.mjs +0 -30
  45. package/provider/dist/chunk-4OUDS3CP.mjs.map +0 -1
  46. package/provider/dist/chunk-5IYCPJBV.mjs +0 -56
  47. package/provider/dist/chunk-5IYCPJBV.mjs.map +0 -1
  48. package/provider/dist/chunk-VB2TCVQ4.mjs +0 -6746
  49. package/provider/dist/chunk-VB2TCVQ4.mjs.map +0 -1
  50. package/provider/dist/chunk-VYIXVZ6L.mjs +0 -317
  51. package/provider/dist/chunk-VYIXVZ6L.mjs.map +0 -1
  52. package/provider/dist/chunk-WTOUHN6A.mjs +0 -2251
  53. package/provider/dist/chunk-WTOUHN6A.mjs.map +0 -1
  54. package/provider/dist/client-22WAAXR7.mjs +0 -10
  55. package/provider/dist/client-22WAAXR7.mjs.map +0 -1
  56. package/provider/dist/fileFromPath-23RINPB2.mjs +0 -115
  57. package/provider/dist/fileFromPath-23RINPB2.mjs.map +0 -1
  58. package/provider/dist/lib-BZMMM4HX.mjs +0 -20
  59. package/provider/dist/lib-BZMMM4HX.mjs.map +0 -1
  60. package/provider/dist/openai-3YL4AWLI.mjs +0 -3451
  61. package/provider/dist/openai-3YL4AWLI.mjs.map +0 -1
@@ -0,0 +1,539 @@
1
+ import * as zod from 'zod';
2
+ import { ZodSchema } from 'zod';
3
+
4
+ declare class AI_InvalidArgumentError extends Error {
5
+ readonly parameter: string;
6
+ readonly value: unknown;
7
+ constructor({ parameter, value, message, }: {
8
+ parameter: string;
9
+ value: unknown;
10
+ message: string;
11
+ });
12
+ toJSON(): {
13
+ name: string;
14
+ message: string;
15
+ stack: string | undefined;
16
+ parameter: string;
17
+ value: unknown;
18
+ };
19
+ }
20
+
21
+ declare class ApiCallError extends Error {
22
+ readonly url: string;
23
+ readonly requestBodyValues: unknown;
24
+ readonly statusCode?: number;
25
+ readonly responseBody?: string;
26
+ readonly cause?: unknown;
27
+ readonly isRetryable: boolean;
28
+ readonly data?: unknown;
29
+ constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, data, }: {
30
+ message: string;
31
+ url: string;
32
+ requestBodyValues: unknown;
33
+ statusCode?: number;
34
+ responseBody?: string;
35
+ cause?: unknown;
36
+ isRetryable?: boolean;
37
+ data?: unknown;
38
+ });
39
+ toJSON(): {
40
+ name: string;
41
+ message: string;
42
+ url: string;
43
+ requestBodyValues: unknown;
44
+ statusCode: number | undefined;
45
+ responseBody: string | undefined;
46
+ cause: unknown;
47
+ isRetryable: boolean;
48
+ data: unknown;
49
+ };
50
+ }
51
+
52
+ declare class JSONParseError extends Error {
53
+ readonly text: string;
54
+ readonly cause: unknown;
55
+ constructor({ text, cause }: {
56
+ text: string;
57
+ cause: unknown;
58
+ });
59
+ toJSON(): {
60
+ name: string;
61
+ message: string;
62
+ cause: unknown;
63
+ stack: string | undefined;
64
+ valueText: string;
65
+ };
66
+ }
67
+
68
+ declare class LoadAPIKeyError extends Error {
69
+ constructor({ message }: {
70
+ message: string;
71
+ });
72
+ toJSON(): {
73
+ name: string;
74
+ message: string;
75
+ };
76
+ }
77
+
78
+ declare class NoTextGeneratedError extends Error {
79
+ readonly cause: unknown;
80
+ constructor();
81
+ toJSON(): {
82
+ name: string;
83
+ cause: unknown;
84
+ message: string;
85
+ stack: string | undefined;
86
+ };
87
+ }
88
+
89
+ declare class TypeValidationError extends Error {
90
+ readonly value: unknown;
91
+ readonly cause: unknown;
92
+ constructor({ value, cause }: {
93
+ value: unknown;
94
+ cause: unknown;
95
+ });
96
+ toJSON(): {
97
+ name: string;
98
+ message: string;
99
+ cause: unknown;
100
+ stack: string | undefined;
101
+ value: unknown;
102
+ };
103
+ }
104
+
105
+ declare class UnsupportedFunctionalityError extends Error {
106
+ readonly functionality: string;
107
+ readonly provider: string;
108
+ constructor({ provider, functionality, }: {
109
+ provider: string;
110
+ functionality: string;
111
+ });
112
+ toJSON(): {
113
+ name: string;
114
+ message: string;
115
+ stack: string | undefined;
116
+ provider: string;
117
+ functionality: string;
118
+ };
119
+ }
120
+
121
+ type JsonSchema = Record<string, unknown>;
122
+
123
+ type LanguageModelV1CallSettings = {
124
+ /**
125
+ * Maximum number of tokens to generate.
126
+ */
127
+ maxTokens?: number;
128
+ /**
129
+ * Temperature setting. This is a number between 0 (almost no randomness) and
130
+ * 1 (very random).
131
+ *
132
+ * Different LLM providers have different temperature
133
+ * scales, so they'd need to map it (without mapping, the same temperature has
134
+ * different effects on different models). The provider can also chose to map
135
+ * this to topP, potentially even using a custom setting on their model.
136
+ *
137
+ * Note: This is an example of a setting that requires a clear specification of
138
+ * the semantics.
139
+ */
140
+ temperature?: number;
141
+ /**
142
+ * Nucleus sampling. This is a number between 0 and 1.
143
+ *
144
+ * E.g. 0.1 would mean that only tokens with the top 10% probability mass
145
+ * are considered.
146
+ *
147
+ * It is recommended to set either `temperature` or `topP`, but not both.
148
+ */
149
+ topP?: number;
150
+ /**
151
+ * Presence penalty setting. It affects the likelihood of the model to
152
+ * repeat information that is already in the prompt.
153
+ *
154
+ * The presence penalty is a number between -1 (increase repetition)
155
+ * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
156
+ */
157
+ presencePenalty?: number;
158
+ /**
159
+ * Frequency penalty setting. It affects the likelihood of the model
160
+ * to repeatedly use the same words or phrases.
161
+ *
162
+ * The frequency penalty is a number between -1 (increase repetition)
163
+ * and 1 (maximum penalty, decrease repetition). 0 means no penalty.
164
+ */
165
+ frequencyPenalty?: number;
166
+ /**
167
+ * The seed (integer) to use for random sampling. If set and supported
168
+ * by the model, calls will generate deterministic results.
169
+ */
170
+ seed?: number;
171
+ };
172
+
173
+ /**
174
+ * A tool has a name, a description, and a set of parameters.
175
+ *
176
+ * Note: this is **not** the user-facing tool definition. The AI SDK methods will
177
+ * map the user-facing tool definitions to this format.
178
+ */
179
+ type LanguageModelV1FunctionTool = {
180
+ /**
181
+ * The type of the tool. Only functions for now, but this gives us room to
182
+ * add more specific tool types in the future and use a discriminated union.
183
+ */
184
+ type: 'function';
185
+ /**
186
+ * The name of the tool. Unique within this model call.
187
+ */
188
+ name: string;
189
+ description?: string;
190
+ parameters: JsonSchema;
191
+ };
192
+
193
+ /**
194
+ * A prompt is a list of messages.
195
+ *
196
+ * Note: Not all models and prompt formats support multi-modal inputs and
197
+ * tool calls. The validation happens at runtime.
198
+ *
199
+ * Note: This is not a user-facing prompt. The AI SDK methods will map the
200
+ * user-facing prompt types such as chat or instruction prompts to this format.
201
+ */
202
+ type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
203
+ type LanguageModelV1Message = {
204
+ role: 'system';
205
+ content: string;
206
+ } | {
207
+ role: 'user';
208
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
209
+ } | {
210
+ role: 'assistant';
211
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
212
+ } | {
213
+ role: 'tool';
214
+ content: Array<LanguageModelV1ToolResultPart>;
215
+ };
216
+ interface LanguageModelV1TextPart {
217
+ type: 'text';
218
+ /**
219
+ * The text content.
220
+ */
221
+ text: string;
222
+ }
223
+ interface LanguageModelV1ImagePart {
224
+ type: 'image';
225
+ /**
226
+ * Image data as a Uint8Array.
227
+ */
228
+ image: Uint8Array;
229
+ /**
230
+ * Optional mime type of the image.
231
+ */
232
+ mimeType?: string;
233
+ }
234
+ interface LanguageModelV1ToolCallPart {
235
+ type: 'tool-call';
236
+ toolCallId: string;
237
+ toolName: string;
238
+ args: unknown;
239
+ }
240
+ interface LanguageModelV1ToolResultPart {
241
+ type: 'tool-result';
242
+ toolCallId: string;
243
+ toolName: string;
244
+ result: unknown;
245
+ }
246
+
247
+ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
248
+ /**
249
+ * Whether the user provided the input as messages or as
250
+ * a prompt. This can help guide non-chat models in the
251
+ * expansion, bc different expansions can be needed for
252
+ * chat/non-chat use cases.
253
+ */
254
+ inputFormat: 'messages' | 'prompt';
255
+ /**
256
+ * The mode affects the behavior of the language model. It is required to
257
+ * support provider-independent streaming and generation of structured objects.
258
+ * The model can take this information and e.g. configure json mode, the correct
259
+ * low level grammar, etc. It can also be used to optimize the efficiency of the
260
+ * streaming, e.g. tool-delta stream parts are only needed in the
261
+ * object-tool mode.
262
+ */
263
+ mode: {
264
+ type: 'regular';
265
+ tools?: Array<LanguageModelV1FunctionTool>;
266
+ } | {
267
+ type: 'object-json';
268
+ } | {
269
+ type: 'object-grammar';
270
+ schema: JsonSchema;
271
+ } | {
272
+ type: 'object-tool';
273
+ tool: LanguageModelV1FunctionTool;
274
+ };
275
+ /**
276
+ * A language mode prompt is a standardized prompt type.
277
+ *
278
+ * Note: This is **not** the user-facing prompt. The AI SDK methods will map the
279
+ * user-facing prompt types such as chat or instruction prompts to this format.
280
+ * That approach allows us to evolve the user facing prompts without breaking
281
+ * the language model interface.
282
+ */
283
+ prompt: LanguageModelV1Prompt;
284
+ };
285
+
286
+ /**
287
+ * Warning from the model provider for this call. The call will proceed, but e.g.
288
+ * some settings might not be supported, which can lead to suboptimal results.
289
+ */
290
+ type LanguageModelV1CallWarning = {
291
+ type: 'unsupported-setting';
292
+ setting: keyof LanguageModelV1CallSettings;
293
+ } | {
294
+ type: 'other';
295
+ message: string;
296
+ };
297
+
298
+ type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
299
+
300
+ type LanguageModelV1FunctionToolCall = {
301
+ toolCallType: 'function';
302
+ toolCallId: string;
303
+ toolName: string;
304
+ /**
305
+ * Stringified JSON object with the tool call arguments. Must match the
306
+ * parameters schema of the tool.
307
+ */
308
+ args: string;
309
+ };
310
+
311
+ type LanguageModelV1 = {
312
+ /**
313
+ * The language model must specify which language model interface
314
+ * version it implements. This will allow us to evolve the language
315
+ * model interface and retain backwards compatibility. The different
316
+ * implementation versions can be handled as a discriminated union
317
+ * on our side.
318
+ */
319
+ readonly specificationVersion: 'v1';
320
+ /**
321
+ * Name of the provider for logging purposes.
322
+ */
323
+ readonly provider: string;
324
+ /**
325
+ * Provider-specific model ID for logging purposes.
326
+ */
327
+ readonly modelId: string;
328
+ /**
329
+ * Default object generation mode that should be used with this model when
330
+ * no mode is specified. Should be the mode with the best results for this
331
+ * model. `undefined` can be returned if object generation is not supported.
332
+ *
333
+ * This is needed to generate the best objects possible w/o requiring the
334
+ * user to explicitly specify the object generation mode.
335
+ */
336
+ readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
337
+ /**
338
+ * Generates a language model output (non-streaming).
339
+ *
340
+ * Naming: "do" prefix to prevent accidental direct usage of the method
341
+ * by the user.
342
+ */
343
+ doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
344
+ /**
345
+ * Text that the model has generated. Can be undefined if the model
346
+ * has only generated tool calls.
347
+ */
348
+ text?: string;
349
+ /**
350
+ * Tool calls that the model has generated. Can be undefined if the
351
+ * model has only generated text.
352
+ */
353
+ toolCalls?: Array<LanguageModelV1FunctionToolCall>;
354
+ warnings?: LanguageModelV1CallWarning[];
355
+ }>;
356
+ /**
357
+ * Generates a language model output (streaming).
358
+ *
359
+ * Naming: "do" prefix to prevent accidental direct usage of the method
360
+ * by the user.
361
+ *
362
+ * @return A stream of higher-level language model output parts.
363
+ */
364
+ doStream(options: LanguageModelV1CallOptions): PromiseLike<{
365
+ stream: ReadableStream<LanguageModelV1StreamPart>;
366
+ warnings?: LanguageModelV1CallWarning[];
367
+ }>;
368
+ };
369
+ type LanguageModelV1StreamPart = {
370
+ type: 'text-delta';
371
+ textDelta: string;
372
+ } | ({
373
+ type: 'tool-call';
374
+ } & LanguageModelV1FunctionToolCall) | {
375
+ type: 'tool-call-delta';
376
+ toolCallId: string;
377
+ toolName: string;
378
+ argsTextDelta: string;
379
+ } | {
380
+ type: 'finish-metadata';
381
+ finishReason: LanguageModelV1FinishReason;
382
+ usage: {
383
+ promptTokens: number;
384
+ completionTokens: number;
385
+ };
386
+ } | {
387
+ type: 'error';
388
+ error: unknown;
389
+ };
390
+
391
+ declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
392
+ apiKey: string | undefined;
393
+ environmentVariableName: string;
394
+ apiKeyParameterName?: string;
395
+ description: string;
396
+ }): string;
397
+
398
+ /**
399
+ * Parses a JSON string into an unknown object.
400
+ *
401
+ * @param text - The JSON string to parse.
402
+ * @returns {unknown} - The parsed JSON object.
403
+ */
404
+ declare function parseJSON({ text }: {
405
+ text: string;
406
+ }): unknown;
407
+ /**
408
+ * Parses a JSON string into a strongly-typed object using the provided schema.
409
+ *
410
+ * @template T - The type of the object to parse the JSON into.
411
+ * @param {string} text - The JSON string to parse.
412
+ * @param {Schema<T>} schema - The schema to use for parsing the JSON.
413
+ * @returns {T} - The parsed object.
414
+ */
415
+ declare function parseJSON<T>({ text, schema, }: {
416
+ text: string;
417
+ schema: ZodSchema<T>;
418
+ }): T;
419
+ /**
420
+ * Safely parses a JSON string and returns the result as an object of type `unknown`.
421
+ *
422
+ * @param text - The JSON string to parse.
423
+ * @returns {object} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
424
+ */
425
+ declare function safeParseJSON({ text, }: {
426
+ text: string;
427
+ }): {
428
+ success: true;
429
+ value: unknown;
430
+ } | {
431
+ success: false;
432
+ error: JSONParseError | TypeValidationError;
433
+ };
434
+ /**
435
+ * Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
436
+ *
437
+ * @template T - The type of the object to parse the JSON into.
438
+ * @param {string} text - The JSON string to parse.
439
+ * @param {Schema<T>} schema - The schema to use for parsing the JSON.
440
+ * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
441
+ */
442
+ declare function safeParseJSON<T>({ text, schema, }: {
443
+ text: string;
444
+ schema: ZodSchema<T>;
445
+ }): {
446
+ success: true;
447
+ value: T;
448
+ } | {
449
+ success: false;
450
+ error: JSONParseError | TypeValidationError;
451
+ };
452
+ declare function isParseableJson(input: string): boolean;
453
+
454
+ type ParsedChunk<T> = {
455
+ type: 'value';
456
+ value: T;
457
+ } | {
458
+ type: 'error';
459
+ error: unknown;
460
+ };
461
+
462
+ type ResponseHandler<RETURN_TYPE> = (options: {
463
+ url: string;
464
+ requestBodyValues: unknown;
465
+ response: Response;
466
+ }) => PromiseLike<RETURN_TYPE>;
467
+ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
468
+ errorSchema: ZodSchema<T, zod.ZodTypeDef, T>;
469
+ errorToMessage: (error: T) => string;
470
+ isRetryable?: ((response: Response, error?: T | undefined) => boolean) | undefined;
471
+ }) => ResponseHandler<ApiCallError>;
472
+ declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodSchema<T, zod.ZodTypeDef, T>) => ResponseHandler<ReadableStream<ParsedChunk<T>>>;
473
+ declare const createJsonResponseHandler: <T>(responseSchema: ZodSchema<T, zod.ZodTypeDef, T>) => ResponseHandler<T>;
474
+
475
+ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, }: {
476
+ url: string;
477
+ headers?: Record<string, string> | undefined;
478
+ body: unknown;
479
+ failedResponseHandler: ResponseHandler<ApiCallError>;
480
+ successfulResponseHandler: ResponseHandler<T>;
481
+ abortSignal?: AbortSignal | undefined;
482
+ }) => Promise<T>;
483
+ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, }: {
484
+ url: string;
485
+ headers?: Record<string, string> | undefined;
486
+ body: {
487
+ content: string | FormData | Uint8Array;
488
+ values: unknown;
489
+ };
490
+ failedResponseHandler: ResponseHandler<Error>;
491
+ successfulResponseHandler: ResponseHandler<T>;
492
+ abortSignal?: AbortSignal | undefined;
493
+ }) => Promise<T>;
494
+
495
+ declare function scale({ inputMin, inputMax, outputMin, outputMax, value, }: {
496
+ inputMin?: number;
497
+ inputMax?: number;
498
+ outputMin: number;
499
+ outputMax: number;
500
+ value: number | undefined;
501
+ }): number | undefined;
502
+
503
+ declare function convertBase64ToUint8Array(base64String: string): Uint8Array;
504
+ declare function convertUint8ArrayToBase64(array: Uint8Array): string;
505
+
506
+ /**
507
+ * Validates the types of an unknown object using a schema and
508
+ * return a strongly-typed object.
509
+ *
510
+ * @template T - The type of the object to validate.
511
+ * @param {string} options.value - The object to validate.
512
+ * @param {Schema<T>} options.schema - The schema to use for validating the JSON.
513
+ * @returns {T} - The typed object.
514
+ */
515
+ declare function validateTypes<T>({ value, schema, }: {
516
+ value: unknown;
517
+ schema: ZodSchema<T>;
518
+ }): T;
519
+ /**
520
+ * Safely validates the types of an unknown object using a schema and
521
+ * return a strongly-typed object.
522
+ *
523
+ * @template T - The type of the object to validate.
524
+ * @param {string} options.value - The JSON object to validate.
525
+ * @param {Schema<T>} options.schema - The schema to use for validating the JSON.
526
+ * @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
527
+ */
528
+ declare function safeValidateTypes<T>({ value, schema, }: {
529
+ value: unknown;
530
+ schema: ZodSchema<T>;
531
+ }): {
532
+ success: true;
533
+ value: T;
534
+ } | {
535
+ success: false;
536
+ error: TypeValidationError;
537
+ };
538
+
539
+ export { AI_InvalidArgumentError, ApiCallError, JSONParseError, LanguageModelV1, LanguageModelV1CallWarning, LanguageModelV1FunctionTool, LanguageModelV1FunctionToolCall, LanguageModelV1ImagePart, LanguageModelV1Message, LanguageModelV1Prompt, LanguageModelV1StreamPart, LanguageModelV1TextPart, LanguageModelV1ToolCallPart, LanguageModelV1ToolResultPart, LoadAPIKeyError, NoTextGeneratedError, ParsedChunk, ResponseHandler, TypeValidationError, UnsupportedFunctionalityError, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, isParseableJson, loadApiKey, parseJSON, postJsonToApi, postToApi, safeParseJSON, safeValidateTypes, scale, validateTypes };