@jterrazz/intelligence 4.2.0 → 5.0.0

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.
package/dist/index.d.cts CHANGED
@@ -4,7 +4,6 @@ import { LanguageModel, LanguageModelMiddleware } from "ai";
4
4
  import { JSONSchema7 } from "json-schema";
5
5
  import { Schema } from "zod";
6
6
  import { z } from "zod/v4";
7
-
8
7
  //#region src/logging/logging.middleware.d.ts
9
8
  interface LoggingMiddlewareOptions {
10
9
  logger: LoggerPort;
@@ -20,7 +19,68 @@ interface LoggingMiddlewareOptions {
20
19
  declare function createLoggingMiddleware(options: LoggingMiddlewareOptions): LanguageModelMiddleware;
21
20
  //#endregion
22
21
  //#region node_modules/@ai-sdk/provider/dist/index.d.ts
23
- type SharedV3Headers = Record<string, string>;
22
+ /**
23
+ * A mapping of provider names to provider-specific file identifiers.
24
+ *
25
+ * Provider references allow files to be identified across different
26
+ * providers without re-uploading, by storing each provider's own
27
+ * identifier for the same logical file.
28
+ *
29
+ * ```ts
30
+ * {
31
+ * "openai": "file-abc123",
32
+ * "anthropic": "file-xyz789"
33
+ * }
34
+ * ```
35
+ *
36
+ * The `type?: never` constraint excludes any object that has a `type`
37
+ * property, so a `SharedV4ProviderReference` cannot be confused with a
38
+ * tagged file-data shape (e.g. `{ type: 'data', data }` or
39
+ * `{ type: 'reference', reference }`) when both appear in the same union.
40
+ */
41
+ type SharedV4ProviderReference = Record<string, string> & {
42
+ type?: never;
43
+ };
44
+ /**
45
+ * File data variant containing raw bytes (`Uint8Array`) or a base64-encoded
46
+ * string.
47
+ */
48
+ interface SharedV4FileDataData {
49
+ type: 'data';
50
+ data: Uint8Array | string;
51
+ }
52
+ /**
53
+ * File data variant containing a URL that points to the file.
54
+ */
55
+ interface SharedV4FileDataUrl {
56
+ type: 'url';
57
+ url: URL;
58
+ }
59
+ /**
60
+ * File data variant containing a provider reference (`{ [provider]: id }`).
61
+ */
62
+ interface SharedV4FileDataReference {
63
+ type: 'reference';
64
+ reference: SharedV4ProviderReference;
65
+ }
66
+ /**
67
+ * File data variant containing inline text content (e.g. an inline text
68
+ * document).
69
+ */
70
+ interface SharedV4FileDataText {
71
+ type: 'text';
72
+ text: string;
73
+ }
74
+ /**
75
+ * File data as a tagged discriminated union:
76
+ *
77
+ * - `{ type: 'data', data }`: raw bytes (`Uint8Array`) or base64-encoded string.
78
+ * - `{ type: 'url', url }`: a URL that points to the file.
79
+ * - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
80
+ * - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
81
+ */
82
+ type SharedV4FileData = SharedV4FileDataData | SharedV4FileDataUrl | SharedV4FileDataReference | SharedV4FileDataText;
83
+ type SharedV4Headers = Record<string, string>;
24
84
  /**
25
85
  * A JSON value can be a string, number, boolean, object, array, or null.
26
86
  * JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
@@ -51,7 +111,7 @@ type JSONArray = JSONValue[];
51
111
  * }
52
112
  * ```
53
113
  */
54
- type SharedV3ProviderMetadata = Record<string, JSONObject>;
114
+ type SharedV4ProviderMetadata = Record<string, JSONObject>;
55
115
  /**
56
116
  * Additional provider-specific options.
57
117
  * Options are additional input to the provider.
@@ -73,14 +133,14 @@ type SharedV3ProviderMetadata = Record<string, JSONObject>;
73
133
  * }
74
134
  * ```
75
135
  */
76
- type SharedV3ProviderOptions = Record<string, JSONObject>;
136
+ type SharedV4ProviderOptions = Record<string, JSONObject>;
77
137
  /**
78
138
  * Warning from the model.
79
139
  *
80
140
  * For example, that certain features are unsupported or compatibility
81
141
  * functionality is used (which might lead to suboptimal results).
82
142
  */
83
- type SharedV3Warning = {
143
+ type SharedV4Warning = {
84
144
  /**
85
145
  * A feature is not supported by the model.
86
146
  */
@@ -106,6 +166,19 @@ type SharedV3Warning = {
106
166
  * Additional details about the warning.
107
167
  */
108
168
  details?: string;
169
+ } | {
170
+ /**
171
+ * A deprecated feature or option is being used.
172
+ */
173
+ type: 'deprecated';
174
+ /**
175
+ * The deprecated setting or feature name.
176
+ */
177
+ setting: string;
178
+ /**
179
+ * A human-readable message explaining what to use instead.
180
+ */
181
+ message: string;
109
182
  } | {
110
183
  /**
111
184
  * Other warning.
@@ -122,7 +195,7 @@ type SharedV3Warning = {
122
195
  * Note: this is **not** the user-facing tool definition. The AI SDK methods will
123
196
  * map the user-facing tool definitions to this format.
124
197
  */
125
- type LanguageModelV3FunctionTool = {
198
+ type LanguageModelV4FunctionTool = {
126
199
  /**
127
200
  * The type of the tool (always 'function').
128
201
  */
@@ -159,12 +232,8 @@ type LanguageModelV3FunctionTool = {
159
232
  /**
160
233
  * The provider-specific options for the tool.
161
234
  */
162
- providerOptions?: SharedV3ProviderOptions;
235
+ providerOptions?: SharedV4ProviderOptions;
163
236
  };
164
- /**
165
- * Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
166
- */
167
- type LanguageModelV3DataContent = Uint8Array | string | URL;
168
237
  /**
169
238
  * A prompt is a list of messages.
170
239
  *
@@ -174,31 +243,31 @@ type LanguageModelV3DataContent = Uint8Array | string | URL;
174
243
  * Note: This is not a user-facing prompt. The AI SDK methods will map the
175
244
  * user-facing prompt types such as chat or instruction prompts to this format.
176
245
  */
177
- type LanguageModelV3Prompt = Array<LanguageModelV3Message>;
178
- type LanguageModelV3Message = ({
246
+ type LanguageModelV4Prompt = Array<LanguageModelV4Message>;
247
+ type LanguageModelV4Message = ({
179
248
  role: 'system';
180
249
  content: string;
181
250
  } | {
182
251
  role: 'user';
183
- content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart>;
252
+ content: Array<LanguageModelV4TextPart | LanguageModelV4FilePart>;
184
253
  } | {
185
254
  role: 'assistant';
186
- content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart | LanguageModelV3ReasoningPart | LanguageModelV3ToolCallPart | LanguageModelV3ToolResultPart>;
255
+ content: Array<LanguageModelV4TextPart | LanguageModelV4FilePart | LanguageModelV4CustomPart | LanguageModelV4ReasoningPart | LanguageModelV4ReasoningFilePart | LanguageModelV4ToolCallPart | LanguageModelV4ToolResultPart>;
187
256
  } | {
188
257
  role: 'tool';
189
- content: Array<LanguageModelV3ToolResultPart | LanguageModelV3ToolApprovalResponsePart>;
258
+ content: Array<LanguageModelV4ToolResultPart | LanguageModelV4ToolApprovalResponsePart>;
190
259
  }) & {
191
260
  /**
192
261
  * Additional provider-specific options. They are passed through
193
262
  * to the provider from the AI SDK and enable provider-specific
194
263
  * functionality that can be fully encapsulated in the provider.
195
264
  */
196
- providerOptions?: SharedV3ProviderOptions;
265
+ providerOptions?: SharedV4ProviderOptions;
197
266
  };
198
267
  /**
199
268
  * Text content part of a prompt. It contains a string of text.
200
269
  */
201
- interface LanguageModelV3TextPart {
270
+ interface LanguageModelV4TextPart {
202
271
  type: 'text';
203
272
  /**
204
273
  * The text content.
@@ -209,12 +278,12 @@ interface LanguageModelV3TextPart {
209
278
  * to the provider from the AI SDK and enable provider-specific
210
279
  * functionality that can be fully encapsulated in the provider.
211
280
  */
212
- providerOptions?: SharedV3ProviderOptions;
281
+ providerOptions?: SharedV4ProviderOptions;
213
282
  }
214
283
  /**
215
284
  * Reasoning content part of a prompt. It contains a string of reasoning text.
216
285
  */
217
- interface LanguageModelV3ReasoningPart {
286
+ interface LanguageModelV4ReasoningPart {
218
287
  type: 'reasoning';
219
288
  /**
220
289
  * The reasoning text.
@@ -225,25 +294,77 @@ interface LanguageModelV3ReasoningPart {
225
294
  * to the provider from the AI SDK and enable provider-specific
226
295
  * functionality that can be fully encapsulated in the provider.
227
296
  */
228
- providerOptions?: SharedV3ProviderOptions;
297
+ providerOptions?: SharedV4ProviderOptions;
298
+ }
299
+ /**
300
+ * Reasoning file content part of a prompt. It contains a file generated as part of reasoning.
301
+ */
302
+ interface LanguageModelV4ReasoningFilePart {
303
+ type: 'reasoning-file';
304
+ /**
305
+ * File data as a tagged discriminated union:
306
+ *
307
+ * - `{ type: 'data', data }`: raw bytes (Uint8Array) or base64-encoded string.
308
+ * - `{ type: 'url', url }`: a URL that points to the file.
309
+ */
310
+ data: SharedV4FileDataData | SharedV4FileDataUrl;
311
+ /**
312
+ * IANA media type of the file.
313
+ *
314
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
315
+ */
316
+ mediaType: string;
317
+ /**
318
+ * Additional provider-specific options. They are passed through
319
+ * to the provider from the AI SDK and enable provider-specific
320
+ * functionality that can be fully encapsulated in the provider.
321
+ */
322
+ providerOptions?: SharedV4ProviderOptions;
323
+ }
324
+ /**
325
+ * Provider-specific content part of a prompt. It contains no standardized
326
+ * payload beyond provider-specific options.
327
+ */
328
+ interface LanguageModelV4CustomPart {
329
+ type: 'custom';
330
+ /**
331
+ * The kind of custom content, in the format `{provider}.{provider-type}`.
332
+ */
333
+ kind: `${string}.${string}`;
334
+ /**
335
+ * Additional provider-specific options. They are passed through
336
+ * to the provider from the AI SDK and enable provider-specific
337
+ * functionality that can be fully encapsulated in the provider.
338
+ */
339
+ providerOptions?: SharedV4ProviderOptions;
229
340
  }
230
341
  /**
231
342
  * File content part of a prompt. It contains a file.
232
343
  */
233
- interface LanguageModelV3FilePart {
344
+ interface LanguageModelV4FilePart {
234
345
  type: 'file';
235
346
  /**
236
347
  * Optional filename of the file.
237
348
  */
238
349
  filename?: string;
239
350
  /**
240
- * File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
351
+ * File data as a tagged discriminated union:
352
+ *
353
+ * - `{ type: 'data', data }`: raw bytes (Uint8Array) or base64-encoded string.
354
+ * - `{ type: 'url', url }`: a URL that points to the file.
355
+ * - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
356
+ * - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
241
357
  */
242
- data: LanguageModelV3DataContent;
358
+ data: SharedV4FileData;
243
359
  /**
244
- * IANA media type of the file.
360
+ * Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
361
+ * the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
245
362
  *
246
- * Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
363
+ * `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
364
+ * top-level segment alone (e.g. `image`). Providers can use the helpers in
365
+ * `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
366
+ * `detectMediaType`) to resolve the field according to their API
367
+ * requirements.
247
368
  *
248
369
  * @see https://www.iana.org/assignments/media-types/media-types.xhtml
249
370
  */
@@ -253,12 +374,12 @@ interface LanguageModelV3FilePart {
253
374
  * to the provider from the AI SDK and enable provider-specific
254
375
  * functionality that can be fully encapsulated in the provider.
255
376
  */
256
- providerOptions?: SharedV3ProviderOptions;
377
+ providerOptions?: SharedV4ProviderOptions;
257
378
  }
258
379
  /**
259
380
  * Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
260
381
  */
261
- interface LanguageModelV3ToolCallPart {
382
+ interface LanguageModelV4ToolCallPart {
262
383
  type: 'tool-call';
263
384
  /**
264
385
  * ID of the tool call. This ID is used to match the tool call with the tool result.
@@ -282,12 +403,12 @@ interface LanguageModelV3ToolCallPart {
282
403
  * to the provider from the AI SDK and enable provider-specific
283
404
  * functionality that can be fully encapsulated in the provider.
284
405
  */
285
- providerOptions?: SharedV3ProviderOptions;
406
+ providerOptions?: SharedV4ProviderOptions;
286
407
  }
287
408
  /**
288
409
  * Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
289
410
  */
290
- interface LanguageModelV3ToolResultPart {
411
+ interface LanguageModelV4ToolResultPart {
291
412
  type: 'tool-result';
292
413
  /**
293
414
  * ID of the tool call that this result is associated with.
@@ -300,19 +421,19 @@ interface LanguageModelV3ToolResultPart {
300
421
  /**
301
422
  * Result of the tool call.
302
423
  */
303
- output: LanguageModelV3ToolResultOutput;
424
+ output: LanguageModelV4ToolResultOutput;
304
425
  /**
305
426
  * Additional provider-specific options. They are passed through
306
427
  * to the provider from the AI SDK and enable provider-specific
307
428
  * functionality that can be fully encapsulated in the provider.
308
429
  */
309
- providerOptions?: SharedV3ProviderOptions;
430
+ providerOptions?: SharedV4ProviderOptions;
310
431
  }
311
432
  /**
312
433
  * Tool approval response content part of a prompt. It contains the user's
313
434
  * decision to approve or deny a provider-executed tool call.
314
435
  */
315
- interface LanguageModelV3ToolApprovalResponsePart {
436
+ interface LanguageModelV4ToolApprovalResponsePart {
316
437
  type: 'tool-approval-response';
317
438
  /**
318
439
  * ID of the approval request that this response refers to.
@@ -331,12 +452,12 @@ interface LanguageModelV3ToolApprovalResponsePart {
331
452
  * to the provider from the AI SDK and enable provider-specific
332
453
  * functionality that can be fully encapsulated in the provider.
333
454
  */
334
- providerOptions?: SharedV3ProviderOptions;
455
+ providerOptions?: SharedV4ProviderOptions;
335
456
  }
336
457
  /**
337
458
  * Result of a tool call.
338
459
  */
339
- type LanguageModelV3ToolResultOutput = {
460
+ type LanguageModelV4ToolResultOutput = {
340
461
  /**
341
462
  * Text tool output that should be directly sent to the API.
342
463
  */
@@ -345,14 +466,14 @@ type LanguageModelV3ToolResultOutput = {
345
466
  /**
346
467
  * Provider-specific options.
347
468
  */
348
- providerOptions?: SharedV3ProviderOptions;
469
+ providerOptions?: SharedV4ProviderOptions;
349
470
  } | {
350
471
  type: 'json';
351
472
  value: JSONValue;
352
473
  /**
353
474
  * Provider-specific options.
354
475
  */
355
- providerOptions?: SharedV3ProviderOptions;
476
+ providerOptions?: SharedV4ProviderOptions;
356
477
  } | {
357
478
  /**
358
479
  * Type when the user has denied the execution of the tool call.
@@ -365,21 +486,21 @@ type LanguageModelV3ToolResultOutput = {
365
486
  /**
366
487
  * Provider-specific options.
367
488
  */
368
- providerOptions?: SharedV3ProviderOptions;
489
+ providerOptions?: SharedV4ProviderOptions;
369
490
  } | {
370
491
  type: 'error-text';
371
492
  value: string;
372
493
  /**
373
494
  * Provider-specific options.
374
495
  */
375
- providerOptions?: SharedV3ProviderOptions;
496
+ providerOptions?: SharedV4ProviderOptions;
376
497
  } | {
377
498
  type: 'error-json';
378
499
  value: JSONValue;
379
500
  /**
380
501
  * Provider-specific options.
381
502
  */
382
- providerOptions?: SharedV3ProviderOptions;
503
+ providerOptions?: SharedV4ProviderOptions;
383
504
  } | {
384
505
  type: 'content';
385
506
  value: Array<{
@@ -391,15 +512,28 @@ type LanguageModelV3ToolResultOutput = {
391
512
  /**
392
513
  * Provider-specific options.
393
514
  */
394
- providerOptions?: SharedV3ProviderOptions;
515
+ providerOptions?: SharedV4ProviderOptions;
395
516
  } | {
396
- type: 'file-data';
517
+ type: 'file';
397
518
  /**
398
- * Base-64 encoded media data.
519
+ * File data as a tagged discriminated union:
520
+ *
521
+ * - `{ type: 'data', data }`: raw bytes (Uint8Array) or base64-encoded string.
522
+ * - `{ type: 'url', url }`: a URL that points to the file.
523
+ * - `{ type: 'reference', reference }`: a provider reference (`{ [provider]: id }`).
524
+ * - `{ type: 'text', text }`: inline text content (e.g. an inline text document).
399
525
  */
400
- data: string;
526
+ data: SharedV4FileData;
401
527
  /**
402
- * IANA media type.
528
+ * Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
529
+ * the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
530
+ *
531
+ * `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
532
+ * top-level segment alone (e.g. `image`). Providers can use the helpers in
533
+ * `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
534
+ * `detectMediaType`) to resolve the field according to their API
535
+ * requirements.
536
+ *
403
537
  * @see https://www.iana.org/assignments/media-types/media-types.xhtml
404
538
  */
405
539
  mediaType: string;
@@ -410,81 +544,7 @@ type LanguageModelV3ToolResultOutput = {
410
544
  /**
411
545
  * Provider-specific options.
412
546
  */
413
- providerOptions?: SharedV3ProviderOptions;
414
- } | {
415
- type: 'file-url';
416
- /**
417
- * URL of the file.
418
- */
419
- url: string;
420
- /**
421
- * Provider-specific options.
422
- */
423
- providerOptions?: SharedV3ProviderOptions;
424
- } | {
425
- type: 'file-id';
426
- /**
427
- * ID of the file.
428
- *
429
- * If you use multiple providers, you need to
430
- * specify the provider specific ids using
431
- * the Record option. The key is the provider
432
- * name, e.g. 'openai' or 'anthropic'.
433
- */
434
- fileId: string | Record<string, string>;
435
- /**
436
- * Provider-specific options.
437
- */
438
- providerOptions?: SharedV3ProviderOptions;
439
- } | {
440
- /**
441
- * Images that are referenced using base64 encoded data.
442
- */
443
- type: 'image-data';
444
- /**
445
- * Base-64 encoded image data.
446
- */
447
- data: string;
448
- /**
449
- * IANA media type.
450
- * @see https://www.iana.org/assignments/media-types/media-types.xhtml
451
- */
452
- mediaType: string;
453
- /**
454
- * Provider-specific options.
455
- */
456
- providerOptions?: SharedV3ProviderOptions;
457
- } | {
458
- /**
459
- * Images that are referenced using a URL.
460
- */
461
- type: 'image-url';
462
- /**
463
- * URL of the image.
464
- */
465
- url: string;
466
- /**
467
- * Provider-specific options.
468
- */
469
- providerOptions?: SharedV3ProviderOptions;
470
- } | {
471
- /**
472
- * Images that are referenced using a provider file id.
473
- */
474
- type: 'image-file-id';
475
- /**
476
- * Image that is referenced using a provider file id.
477
- *
478
- * If you use multiple providers, you need to
479
- * specify the provider specific ids using
480
- * the Record option. The key is the provider
481
- * name, e.g. 'openai' or 'anthropic'.
482
- */
483
- fileId: string | Record<string, string>;
484
- /**
485
- * Provider-specific options.
486
- */
487
- providerOptions?: SharedV3ProviderOptions;
547
+ providerOptions?: SharedV4ProviderOptions;
488
548
  } | {
489
549
  /**
490
550
  * Custom content part. This can be used to implement
@@ -494,7 +554,7 @@ type LanguageModelV3ToolResultOutput = {
494
554
  /**
495
555
  * Provider-specific options.
496
556
  */
497
- providerOptions?: SharedV3ProviderOptions;
557
+ providerOptions?: SharedV4ProviderOptions;
498
558
  }>;
499
559
  };
500
560
  /**
@@ -504,7 +564,7 @@ type LanguageModelV3ToolResultOutput = {
504
564
  * The input and output schemas are defined be the provider, and
505
565
  * some of the tools are also executed on the provider systems.
506
566
  */
507
- type LanguageModelV3ProviderTool = {
567
+ type LanguageModelV4ProviderTool = {
508
568
  /**
509
569
  * The type of the tool (always 'provider').
510
570
  */
@@ -522,7 +582,7 @@ type LanguageModelV3ProviderTool = {
522
582
  */
523
583
  args: Record<string, unknown>;
524
584
  };
525
- type LanguageModelV3ToolChoice = {
585
+ type LanguageModelV4ToolChoice = {
526
586
  type: 'auto';
527
587
  } | {
528
588
  type: 'none';
@@ -532,7 +592,7 @@ type LanguageModelV3ToolChoice = {
532
592
  type: 'tool';
533
593
  toolName: string;
534
594
  };
535
- type LanguageModelV3CallOptions = {
595
+ type LanguageModelV4CallOptions = {
536
596
  /**
537
597
  * A language mode prompt is a standardized prompt type.
538
598
  *
@@ -541,7 +601,7 @@ type LanguageModelV3CallOptions = {
541
601
  * That approach allows us to evolve the user facing prompts without breaking
542
602
  * the language model interface.
543
603
  */
544
- prompt: LanguageModelV3Prompt;
604
+ prompt: LanguageModelV4Prompt;
545
605
  /**
546
606
  * Maximum number of tokens to generate.
547
607
  */
@@ -607,11 +667,11 @@ type LanguageModelV3CallOptions = {
607
667
  /**
608
668
  * The tools that are available for the model.
609
669
  */
610
- tools?: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderTool>;
670
+ tools?: Array<LanguageModelV4FunctionTool | LanguageModelV4ProviderTool>;
611
671
  /**
612
672
  * Specifies how the tool should be selected. Defaults to 'auto'.
613
673
  */
614
- toolChoice?: LanguageModelV3ToolChoice;
674
+ toolChoice?: LanguageModelV4ToolChoice;
615
675
  /**
616
676
  * Include raw chunks in the stream. Only applicable for streaming calls.
617
677
  */
@@ -625,19 +685,41 @@ type LanguageModelV3CallOptions = {
625
685
  * Only applicable for HTTP-based providers.
626
686
  */
627
687
  headers?: Record<string, string | undefined>;
688
+ /**
689
+ * Reasoning effort level for the model. Controls how much reasoning
690
+ * the model performs before generating a response. Defaults to 'provider-default'.
691
+ */
692
+ reasoning?: 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
628
693
  /**
629
694
  * Additional provider-specific options. They are passed through
630
695
  * to the provider from the AI SDK and enable provider-specific
631
696
  * functionality that can be fully encapsulated in the provider.
632
697
  */
633
- providerOptions?: SharedV3ProviderOptions;
698
+ providerOptions?: SharedV4ProviderOptions;
699
+ };
700
+ /**
701
+ * A provider-specific content block that does not map to another standardized
702
+ * content part type.
703
+ */
704
+ type LanguageModelV4CustomContent = {
705
+ type: 'custom';
706
+ /**
707
+ * The kind of custom content, in the format `{provider}.{provider-type}`.
708
+ */
709
+ kind: `${string}.${string}`;
710
+ /**
711
+ * Additional provider-specific options. They are passed through
712
+ * to the provider from the AI SDK and enable provider-specific
713
+ * functionality that can be fully encapsulated in the provider.
714
+ */
715
+ providerMetadata?: SharedV4ProviderMetadata;
634
716
  };
635
717
  /**
636
718
  * A file that has been generated by the model.
637
719
  * Generated files as base64 encoded strings or binary data.
638
720
  * The files should be returned without any unnecessary conversion.
639
721
  */
640
- type LanguageModelV3File = {
722
+ type LanguageModelV4File = {
641
723
  type: 'file';
642
724
  /**
643
725
  * The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
@@ -646,34 +728,67 @@ type LanguageModelV3File = {
646
728
  */
647
729
  mediaType: string;
648
730
  /**
649
- * Generated file data as base64 encoded strings or binary data.
731
+ * Generated file data as a tagged discriminated union:
732
+ *
733
+ * - `{ type: 'data', data }`: raw bytes (Uint8Array) or base64-encoded string.
734
+ * - `{ type: 'url', url }`: a URL that points to the file.
650
735
  *
651
736
  * The file data should be returned without any unnecessary conversion.
652
737
  * If the API returns base64 encoded strings, the file data should be returned
653
738
  * as base64 encoded strings. If the API returns binary data, the file data should
654
739
  * be returned as binary data.
655
740
  */
656
- data: string | Uint8Array;
741
+ data: SharedV4FileDataData | SharedV4FileDataUrl;
657
742
  /**
658
743
  * Optional provider-specific metadata for the file part.
659
744
  */
660
- providerMetadata?: SharedV3ProviderMetadata;
745
+ providerMetadata?: SharedV4ProviderMetadata;
661
746
  };
662
747
  /**
663
748
  * Reasoning that the model has generated.
664
749
  */
665
- type LanguageModelV3Reasoning = {
750
+ type LanguageModelV4Reasoning = {
666
751
  type: 'reasoning';
667
752
  text: string;
668
753
  /**
669
754
  * Optional provider-specific metadata for the reasoning part.
670
755
  */
671
- providerMetadata?: SharedV3ProviderMetadata;
756
+ providerMetadata?: SharedV4ProviderMetadata;
757
+ };
758
+ /**
759
+ * A file that has been generated by the model as part of reasoning.
760
+ * Generated files as base64 encoded strings or binary data.
761
+ * The files should be returned without any unnecessary conversion.
762
+ */
763
+ type LanguageModelV4ReasoningFile = {
764
+ type: 'reasoning-file';
765
+ /**
766
+ * The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
767
+ *
768
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
769
+ */
770
+ mediaType: string;
771
+ /**
772
+ * Generated file data as a tagged discriminated union:
773
+ *
774
+ * - `{ type: 'data', data }`: raw bytes (Uint8Array) or base64-encoded string.
775
+ * - `{ type: 'url', url }`: a URL that points to the file.
776
+ *
777
+ * The file data should be returned without any unnecessary conversion.
778
+ * If the API returns base64 encoded strings, the file data should be returned
779
+ * as base64 encoded strings. If the API returns binary data, the file data should
780
+ * be returned as binary data.
781
+ */
782
+ data: SharedV4FileDataData | SharedV4FileDataUrl;
783
+ /**
784
+ * Optional provider-specific metadata for the reasoning file part.
785
+ */
786
+ providerMetadata?: SharedV4ProviderMetadata;
672
787
  };
673
788
  /**
674
789
  * A source that has been used as input to generate the response.
675
790
  */
676
- type LanguageModelV3Source = {
791
+ type LanguageModelV4Source = {
677
792
  type: 'source';
678
793
  /**
679
794
  * The type of source - URL sources reference web content.
@@ -694,7 +809,7 @@ type LanguageModelV3Source = {
694
809
  /**
695
810
  * Additional provider metadata for the source.
696
811
  */
697
- providerMetadata?: SharedV3ProviderMetadata;
812
+ providerMetadata?: SharedV4ProviderMetadata;
698
813
  } | {
699
814
  type: 'source';
700
815
  /**
@@ -720,18 +835,18 @@ type LanguageModelV3Source = {
720
835
  /**
721
836
  * Additional provider metadata for the source.
722
837
  */
723
- providerMetadata?: SharedV3ProviderMetadata;
838
+ providerMetadata?: SharedV4ProviderMetadata;
724
839
  };
725
840
  /**
726
841
  * Text that the model has generated.
727
842
  */
728
- type LanguageModelV3Text = {
843
+ type LanguageModelV4Text = {
729
844
  type: 'text';
730
845
  /**
731
846
  * The text content.
732
847
  */
733
848
  text: string;
734
- providerMetadata?: SharedV3ProviderMetadata;
849
+ providerMetadata?: SharedV4ProviderMetadata;
735
850
  };
736
851
  /**
737
852
  * Tool approval request emitted by a provider for a provider-executed tool call.
@@ -739,7 +854,7 @@ type LanguageModelV3Text = {
739
854
  * This is used for flows where the provider executes the tool (e.g. MCP tools)
740
855
  * but requires an explicit user approval before continuing.
741
856
  */
742
- type LanguageModelV3ToolApprovalRequest = {
857
+ type LanguageModelV4ToolApprovalRequest = {
743
858
  type: 'tool-approval-request';
744
859
  /**
745
860
  * ID of the approval request. This ID is referenced by the subsequent
@@ -753,12 +868,12 @@ type LanguageModelV3ToolApprovalRequest = {
753
868
  /**
754
869
  * Additional provider-specific metadata for the approval request.
755
870
  */
756
- providerMetadata?: SharedV3ProviderMetadata;
871
+ providerMetadata?: SharedV4ProviderMetadata;
757
872
  };
758
873
  /**
759
874
  * Tool calls that the model has generated.
760
875
  */
761
- type LanguageModelV3ToolCall = {
876
+ type LanguageModelV4ToolCall = {
762
877
  type: 'tool-call';
763
878
  /**
764
879
  * The identifier of the tool call. It must be unique across all tool calls.
@@ -786,12 +901,12 @@ type LanguageModelV3ToolCall = {
786
901
  /**
787
902
  * Additional provider-specific metadata for the tool call.
788
903
  */
789
- providerMetadata?: SharedV3ProviderMetadata;
904
+ providerMetadata?: SharedV4ProviderMetadata;
790
905
  };
791
906
  /**
792
907
  * Result of a tool call that has been executed by the provider.
793
908
  */
794
- type LanguageModelV3ToolResult = {
909
+ type LanguageModelV4ToolResult = {
795
910
  type: 'tool-result';
796
911
  /**
797
912
  * The ID of the tool call that this result is associated with.
@@ -827,9 +942,9 @@ type LanguageModelV3ToolResult = {
827
942
  /**
828
943
  * Additional provider-specific metadata for the tool result.
829
944
  */
830
- providerMetadata?: SharedV3ProviderMetadata;
945
+ providerMetadata?: SharedV4ProviderMetadata;
831
946
  };
832
- type LanguageModelV3Content = LanguageModelV3Text | LanguageModelV3Reasoning | LanguageModelV3File | LanguageModelV3ToolApprovalRequest | LanguageModelV3Source | LanguageModelV3ToolCall | LanguageModelV3ToolResult;
947
+ type LanguageModelV4Content = LanguageModelV4Text | LanguageModelV4Reasoning | LanguageModelV4CustomContent | LanguageModelV4ReasoningFile | LanguageModelV4File | LanguageModelV4ToolApprovalRequest | LanguageModelV4Source | LanguageModelV4ToolCall | LanguageModelV4ToolResult;
833
948
  /**
834
949
  * Reason why a language model finished generating a response.
835
950
  *
@@ -837,7 +952,7 @@ type LanguageModelV3Content = LanguageModelV3Text | LanguageModelV3Reasoning | L
837
952
  * The unified finish reason is used to provide a consistent finish reason across different providers.
838
953
  * The raw finish reason is used to provide the original finish reason from the provider.
839
954
  */
840
- type LanguageModelV3FinishReason = {
955
+ type LanguageModelV4FinishReason = {
841
956
  /**
842
957
  * Unified finish reason. This enables using the same finish reason across different providers.
843
958
  *
@@ -856,7 +971,7 @@ type LanguageModelV3FinishReason = {
856
971
  */
857
972
  raw: string | undefined;
858
973
  };
859
- interface LanguageModelV3ResponseMetadata {
974
+ interface LanguageModelV4ResponseMetadata {
860
975
  /**
861
976
  * ID for the generated response, if the provider sends one.
862
977
  */
@@ -873,7 +988,7 @@ interface LanguageModelV3ResponseMetadata {
873
988
  /**
874
989
  * Usage information for a language model call.
875
990
  */
876
- type LanguageModelV3Usage = {
991
+ type LanguageModelV4Usage = {
877
992
  /**
878
993
  * Information about the input tokens.
879
994
  */
@@ -923,25 +1038,25 @@ type LanguageModelV3Usage = {
923
1038
  /**
924
1039
  * The result of a language model doGenerate call.
925
1040
  */
926
- type LanguageModelV3GenerateResult = {
1041
+ type LanguageModelV4GenerateResult = {
927
1042
  /**
928
1043
  * Ordered content that the model has generated.
929
1044
  */
930
- content: Array<LanguageModelV3Content>;
1045
+ content: Array<LanguageModelV4Content>;
931
1046
  /**
932
1047
  * The finish reason.
933
1048
  */
934
- finishReason: LanguageModelV3FinishReason;
1049
+ finishReason: LanguageModelV4FinishReason;
935
1050
  /**
936
1051
  * The usage information.
937
1052
  */
938
- usage: LanguageModelV3Usage;
1053
+ usage: LanguageModelV4Usage;
939
1054
  /**
940
1055
  * Additional provider-specific metadata. They are passed through
941
1056
  * from the provider to the AI SDK and enable provider-specific
942
1057
  * results that can be fully encapsulated in the provider.
943
1058
  */
944
- providerMetadata?: SharedV3ProviderMetadata;
1059
+ providerMetadata?: SharedV4ProviderMetadata;
945
1060
  /**
946
1061
  * Optional request information for telemetry and debugging purposes.
947
1062
  */
@@ -954,11 +1069,11 @@ type LanguageModelV3GenerateResult = {
954
1069
  /**
955
1070
  * Optional response information for telemetry and debugging purposes.
956
1071
  */
957
- response?: LanguageModelV3ResponseMetadata & {
1072
+ response?: LanguageModelV4ResponseMetadata & {
958
1073
  /**
959
1074
  * Response headers.
960
1075
  */
961
- headers?: SharedV3Headers;
1076
+ headers?: SharedV4Headers;
962
1077
  /**
963
1078
  * Response HTTP body.
964
1079
  */
@@ -967,39 +1082,39 @@ type LanguageModelV3GenerateResult = {
967
1082
  /**
968
1083
  * Warnings for the call, e.g. unsupported settings.
969
1084
  */
970
- warnings: Array<SharedV3Warning>;
1085
+ warnings: Array<SharedV4Warning>;
971
1086
  };
972
- type LanguageModelV3StreamPart = {
1087
+ type LanguageModelV4StreamPart = {
973
1088
  type: 'text-start';
974
- providerMetadata?: SharedV3ProviderMetadata;
1089
+ providerMetadata?: SharedV4ProviderMetadata;
975
1090
  id: string;
976
1091
  } | {
977
1092
  type: 'text-delta';
978
1093
  id: string;
979
- providerMetadata?: SharedV3ProviderMetadata;
1094
+ providerMetadata?: SharedV4ProviderMetadata;
980
1095
  delta: string;
981
1096
  } | {
982
1097
  type: 'text-end';
983
- providerMetadata?: SharedV3ProviderMetadata;
1098
+ providerMetadata?: SharedV4ProviderMetadata;
984
1099
  id: string;
985
1100
  } | {
986
1101
  type: 'reasoning-start';
987
- providerMetadata?: SharedV3ProviderMetadata;
1102
+ providerMetadata?: SharedV4ProviderMetadata;
988
1103
  id: string;
989
1104
  } | {
990
1105
  type: 'reasoning-delta';
991
1106
  id: string;
992
- providerMetadata?: SharedV3ProviderMetadata;
1107
+ providerMetadata?: SharedV4ProviderMetadata;
993
1108
  delta: string;
994
1109
  } | {
995
1110
  type: 'reasoning-end';
996
1111
  id: string;
997
- providerMetadata?: SharedV3ProviderMetadata;
1112
+ providerMetadata?: SharedV4ProviderMetadata;
998
1113
  } | {
999
1114
  type: 'tool-input-start';
1000
1115
  id: string;
1001
1116
  toolName: string;
1002
- providerMetadata?: SharedV3ProviderMetadata;
1117
+ providerMetadata?: SharedV4ProviderMetadata;
1003
1118
  providerExecuted?: boolean;
1004
1119
  dynamic?: boolean;
1005
1120
  title?: string;
@@ -1007,21 +1122,21 @@ type LanguageModelV3StreamPart = {
1007
1122
  type: 'tool-input-delta';
1008
1123
  id: string;
1009
1124
  delta: string;
1010
- providerMetadata?: SharedV3ProviderMetadata;
1125
+ providerMetadata?: SharedV4ProviderMetadata;
1011
1126
  } | {
1012
1127
  type: 'tool-input-end';
1013
1128
  id: string;
1014
- providerMetadata?: SharedV3ProviderMetadata;
1015
- } | LanguageModelV3ToolApprovalRequest | LanguageModelV3ToolCall | LanguageModelV3ToolResult | LanguageModelV3File | LanguageModelV3Source | {
1129
+ providerMetadata?: SharedV4ProviderMetadata;
1130
+ } | LanguageModelV4ToolApprovalRequest | LanguageModelV4ToolCall | LanguageModelV4ToolResult | LanguageModelV4CustomContent | LanguageModelV4File | LanguageModelV4ReasoningFile | LanguageModelV4Source | {
1016
1131
  type: 'stream-start';
1017
- warnings: Array<SharedV3Warning>;
1132
+ warnings: Array<SharedV4Warning>;
1018
1133
  } | ({
1019
1134
  type: 'response-metadata';
1020
- } & LanguageModelV3ResponseMetadata) | {
1135
+ } & LanguageModelV4ResponseMetadata) | {
1021
1136
  type: 'finish';
1022
- usage: LanguageModelV3Usage;
1023
- finishReason: LanguageModelV3FinishReason;
1024
- providerMetadata?: SharedV3ProviderMetadata;
1137
+ usage: LanguageModelV4Usage;
1138
+ finishReason: LanguageModelV4FinishReason;
1139
+ providerMetadata?: SharedV4ProviderMetadata;
1025
1140
  } | {
1026
1141
  type: 'raw';
1027
1142
  rawValue: unknown;
@@ -1032,11 +1147,11 @@ type LanguageModelV3StreamPart = {
1032
1147
  /**
1033
1148
  * The result of a language model doStream call.
1034
1149
  */
1035
- type LanguageModelV3StreamResult = {
1150
+ type LanguageModelV4StreamResult = {
1036
1151
  /**
1037
1152
  * The stream.
1038
1153
  */
1039
- stream: ReadableStream<LanguageModelV3StreamPart>;
1154
+ stream: ReadableStream<LanguageModelV4StreamPart>;
1040
1155
  /**
1041
1156
  * Optional request information for telemetry and debugging purposes.
1042
1157
  */
@@ -1053,17 +1168,17 @@ type LanguageModelV3StreamResult = {
1053
1168
  /**
1054
1169
  * Response headers.
1055
1170
  */
1056
- headers?: SharedV3Headers;
1171
+ headers?: SharedV4Headers;
1057
1172
  };
1058
1173
  };
1059
1174
  /**
1060
- * Specification for a language model that implements the language model interface version 3.
1175
+ * Specification for a language model that implements the language model interface version 4.
1061
1176
  */
1062
- type LanguageModelV3 = {
1177
+ type LanguageModelV4 = {
1063
1178
  /**
1064
1179
  * The language model must specify which language model interface version it implements.
1065
1180
  */
1066
- readonly specificationVersion: 'v3';
1181
+ readonly specificationVersion: 'v4';
1067
1182
  /**
1068
1183
  * Provider ID.
1069
1184
  */
@@ -1087,10 +1202,11 @@ type LanguageModelV3 = {
1087
1202
  supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
1088
1203
  /**
1089
1204
  * Generates a language model output (non-streaming).
1090
- * Naming: "do" prefix to prevent accidental direct usage of the method
1205
+ *
1206
+ * Naming: "do" prefix to prevent accidental direct usage of the method
1091
1207
  * by the user.
1092
1208
  */
1093
- doGenerate(options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3GenerateResult>;
1209
+ doGenerate(options: LanguageModelV4CallOptions): PromiseLike<LanguageModelV4GenerateResult>;
1094
1210
  /**
1095
1211
  * Generates a language model output (streaming).
1096
1212
  *
@@ -1099,13 +1215,8 @@ type LanguageModelV3 = {
1099
1215
  *
1100
1216
  * @return A stream of higher-level language model output parts.
1101
1217
  */
1102
- doStream(options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult>;
1218
+ doStream(options: LanguageModelV4CallOptions): PromiseLike<LanguageModelV4StreamResult>;
1103
1219
  };
1104
- /**
1105
- * Experimental middleware for LanguageModelV3.
1106
- * This type defines the structure for middleware that can be used to modify
1107
- * the behavior of LanguageModelV3 operations.
1108
- */
1109
1220
  //#endregion
1110
1221
  //#region src/ports/observability.port.d.ts
1111
1222
  /**
@@ -1197,7 +1308,7 @@ interface ObservabilityMiddlewareOptions {
1197
1308
  /**
1198
1309
  * Helper to create type-safe observability metadata for providerOptions
1199
1310
  */
1200
- declare function withObservability(meta: ObservabilityMetadata): SharedV3ProviderOptions;
1311
+ declare function withObservability(meta: ObservabilityMetadata): SharedV4ProviderOptions;
1201
1312
  /**
1202
1313
  * Creates middleware that sends generation data to an observability platform.
1203
1314
  */
@@ -1296,11 +1407,11 @@ declare function unwrapOr<T>(result: GenerationResult<T>, defaultValue: T): T;
1296
1407
  //#endregion
1297
1408
  //#region src/generation/generate-structured.d.ts
1298
1409
  interface GenerateStructuredOptions<T> {
1299
- model: LanguageModelV3;
1410
+ model: LanguageModelV4;
1300
1411
  prompt: string;
1301
1412
  system?: string;
1302
1413
  schema: Schema<T>;
1303
- providerOptions?: SharedV3ProviderOptions;
1414
+ providerOptions?: SharedV4ProviderOptions;
1304
1415
  abortSignal?: AbortSignal;
1305
1416
  maxOutputTokens?: number;
1306
1417
  temperature?: number;