ai 5.0.0-canary.16 → 5.0.0-canary.18

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.
@@ -1,20 +1,7 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import { ToolResultContent, ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
3
2
  import { z } from 'zod';
4
- import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
5
-
6
- type ToolResultContent = Array<{
7
- type: 'text';
8
- text: string;
9
- } | {
10
- type: 'image';
11
- data: string;
12
- mediaType?: string;
13
- /**
14
- * @deprecated Use `mediaType` instead.
15
- */
16
- mimeType?: string;
17
- }>;
3
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
4
+ import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2FinishReason, LanguageModelV2Usage, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
18
5
 
19
6
  /**
20
7
  Additional provider-specific options.
@@ -64,10 +51,6 @@ interface ImagePart {
64
51
  */
65
52
  mediaType?: string;
66
53
  /**
67
- @deprecated Use `mediaType` instead.
68
- */
69
- mimeType?: string;
70
- /**
71
54
  Additional provider-specific metadata. They are passed through
72
55
  to the provider from the AI SDK and enable provider-specific
73
56
  functionality that can be fully encapsulated in the provider.
@@ -97,10 +80,6 @@ interface FilePart {
97
80
  */
98
81
  mediaType: string;
99
82
  /**
100
- @deprecated Use `mediaType` instead.
101
- */
102
- mimeType?: string;
103
- /**
104
83
  Additional provider-specific metadata. They are passed through
105
84
  to the provider from the AI SDK and enable provider-specific
106
85
  functionality that can be fully encapsulated in the provider.
@@ -187,7 +166,7 @@ interface ToolResultPart {
187
166
  to increase the resilience against prompt injection attacks,
188
167
  and because not all providers support several system messages.
189
168
  */
190
- type CoreSystemMessage = {
169
+ type SystemModelMessage = {
191
170
  role: 'system';
192
171
  content: string;
193
172
  /**
@@ -200,7 +179,7 @@ type CoreSystemMessage = {
200
179
  /**
201
180
  A user message. It can contain text or a combination of text and images.
202
181
  */
203
- type CoreUserMessage = {
182
+ type UserModelMessage = {
204
183
  role: 'user';
205
184
  content: UserContent;
206
185
  /**
@@ -217,7 +196,7 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
217
196
  /**
218
197
  An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
219
198
  */
220
- type CoreAssistantMessage = {
199
+ type AssistantModelMessage = {
221
200
  role: 'assistant';
222
201
  content: AssistantContent;
223
202
  /**
@@ -235,7 +214,7 @@ type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | Too
235
214
  /**
236
215
  A tool message. It contains the result of one or more tool calls.
237
216
  */
238
- type CoreToolMessage = {
217
+ type ToolModelMessage = {
239
218
  role: 'tool';
240
219
  content: ToolContent;
241
220
  /**
@@ -253,7 +232,7 @@ type ToolContent = Array<ToolResultPart>;
253
232
  A message that can be used in the `messages` field of a prompt.
254
233
  It can be a user message, an assistant message, or a tool message.
255
234
  */
256
- type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
235
+ type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
257
236
 
258
237
  type JSONValue = JSONValue$1;
259
238
 
@@ -293,24 +272,6 @@ type ToolInvocation = ({
293
272
  state: 'result';
294
273
  step?: number;
295
274
  } & ToolResult<string, any, any>);
296
- /**
297
- * An attachment that can be sent along with a message.
298
- */
299
- interface Attachment {
300
- /**
301
- * The name of the attachment, usually the file name.
302
- */
303
- name?: string;
304
- /**
305
- * A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
306
- * By default, it's extracted from the pathname's extension.
307
- */
308
- contentType?: string;
309
- /**
310
- * The URL of the attachment. It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
311
- */
312
- url: string;
313
- }
314
275
  /**
315
276
  * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
316
277
  */
@@ -328,10 +289,6 @@ interface UIMessage {
328
289
  */
329
290
  content: string;
330
291
  /**
331
- Additional attachments to be sent along with the message.
332
- */
333
- experimental_attachments?: Attachment[];
334
- /**
335
292
  The role of the message.
336
293
  */
337
294
  role: 'system' | 'user' | 'assistant';
@@ -342,8 +299,12 @@ interface UIMessage {
342
299
  /**
343
300
  The parts of the message. Use this for rendering the message in the UI.
344
301
 
345
- Assistant messages can have text, reasoning and tool invocation parts.
346
- User messages can have text parts.
302
+ System messages should be avoided (set the system prompt on the server instead).
303
+ They can have text parts.
304
+
305
+ User messages can have text parts and file parts.
306
+
307
+ Assistant messages can have text, reasoning, tool invocation, and file parts.
347
308
  */
348
309
  parts: Array<UIMessagePart>;
349
310
  }
@@ -404,9 +365,14 @@ type FileUIPart = {
404
365
  */
405
366
  mediaType: string;
406
367
  /**
407
- * The base64 encoded data.
368
+ * Optional filename of the file.
369
+ */
370
+ filename?: string;
371
+ /**
372
+ * The URL of the file.
373
+ * It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
408
374
  */
409
- data: string;
375
+ url: string;
410
376
  };
411
377
  /**
412
378
  * A step boundary part of a message.
@@ -415,25 +381,6 @@ type StepStartUIPart = {
415
381
  type: 'step-start';
416
382
  };
417
383
 
418
- /**
419
- Represents the number of tokens used in a prompt and completion.
420
- */
421
- type LanguageModelUsage = {
422
- /**
423
- The number of tokens used in the prompt.
424
- */
425
- promptTokens: number;
426
- /**
427
- The number of tokens used in the completion.
428
- */
429
- completionTokens: number;
430
- /**
431
- The total number of tokens used (promptTokens + completionTokens).
432
- */
433
- totalTokens: number;
434
- };
435
- declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
436
-
437
384
  type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
438
385
  interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
439
386
  code: CODE;
@@ -451,25 +398,19 @@ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, Da
451
398
  argsTextDelta: string;
452
399
  }>, DataStreamPart<"d", "finish_message", {
453
400
  finishReason: LanguageModelV2FinishReason;
454
- usage?: {
455
- promptTokens: number;
456
- completionTokens: number;
457
- };
401
+ usage?: LanguageModelV2Usage;
458
402
  }>, DataStreamPart<"e", "finish_step", {
459
403
  isContinued: boolean;
460
404
  finishReason: LanguageModelV2FinishReason;
461
- usage?: {
462
- promptTokens: number;
463
- completionTokens: number;
464
- };
405
+ usage?: LanguageModelV2Usage;
465
406
  }>, DataStreamPart<"f", "start_step", {
466
407
  messageId: string;
467
408
  }>, DataStreamPart<"g", "reasoning", {
468
409
  text: string;
469
410
  providerMetadata?: Record<string, any> | undefined;
470
411
  }>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"l", "reasoning_part_finish", {}>, DataStreamPart<"k", "file", {
471
- data: string;
472
- mimeType: string;
412
+ url: string;
413
+ mediaType: string;
473
414
  }>];
474
415
  type DataStreamParts = (typeof dataStreamParts)[number];
475
416
  /**
@@ -502,7 +443,7 @@ type DataStreamPartValueType = {
502
443
  */
503
444
  declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
504
445
  /**
505
- Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,
446
+ Prepends a string with a prefix from the `StreamChunkPrefixes`, converts it to JSON,
506
447
  and appends a new line.
507
448
 
508
449
  It ensures type-safety for the part type and value.
@@ -519,7 +460,7 @@ interface ToolExecutionOptions {
519
460
  * Messages that were sent to the language model to initiate the response that contained the tool call.
520
461
  * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
521
462
  */
522
- messages: CoreMessage[];
463
+ messages: ModelMessage[];
523
464
  /**
524
465
  * An optional abort signal that indicates that the overall operation should be aborted.
525
466
  */
@@ -597,7 +538,7 @@ type Prompt = {
597
538
  /**
598
539
  A list of messages. You can either use `prompt` or `messages` but not both.
599
540
  */
600
- messages?: Array<CoreMessage> | Array<Omit<UIMessage, 'id'>>;
541
+ messages?: Array<ModelMessage> | Array<Omit<UIMessage, 'id'>>;
601
542
  };
602
543
 
603
544
  type StandardizedPrompt = {
@@ -608,7 +549,7 @@ type StandardizedPrompt = {
608
549
  /**
609
550
  * Messages.
610
551
  */
611
- messages: CoreMessage[];
552
+ messages: ModelMessage[];
612
553
  };
613
554
  declare function standardizePrompt<TOOLS extends ToolSet>({ prompt, tools, }: {
614
555
  prompt: Prompt;
@@ -846,4 +787,4 @@ declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefi
846
787
  */
847
788
  declare const HANGING_STREAM_WARNING_TIME_MS: number;
848
789
 
849
- export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, StreamData, calculateLanguageModelUsage, convertToLanguageModelPrompt, createCallbacksTransformer, formatDataStreamPart, mergeStreams, prepareCallSettings, prepareResponseHeaders, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
790
+ export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, StreamData, convertToLanguageModelPrompt, createCallbacksTransformer, formatDataStreamPart, mergeStreams, prepareCallSettings, prepareResponseHeaders, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
@@ -1,20 +1,7 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import { ToolResultContent, ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
3
2
  import { z } from 'zod';
4
- import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
5
-
6
- type ToolResultContent = Array<{
7
- type: 'text';
8
- text: string;
9
- } | {
10
- type: 'image';
11
- data: string;
12
- mediaType?: string;
13
- /**
14
- * @deprecated Use `mediaType` instead.
15
- */
16
- mimeType?: string;
17
- }>;
3
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
4
+ import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2FinishReason, LanguageModelV2Usage, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
18
5
 
19
6
  /**
20
7
  Additional provider-specific options.
@@ -64,10 +51,6 @@ interface ImagePart {
64
51
  */
65
52
  mediaType?: string;
66
53
  /**
67
- @deprecated Use `mediaType` instead.
68
- */
69
- mimeType?: string;
70
- /**
71
54
  Additional provider-specific metadata. They are passed through
72
55
  to the provider from the AI SDK and enable provider-specific
73
56
  functionality that can be fully encapsulated in the provider.
@@ -97,10 +80,6 @@ interface FilePart {
97
80
  */
98
81
  mediaType: string;
99
82
  /**
100
- @deprecated Use `mediaType` instead.
101
- */
102
- mimeType?: string;
103
- /**
104
83
  Additional provider-specific metadata. They are passed through
105
84
  to the provider from the AI SDK and enable provider-specific
106
85
  functionality that can be fully encapsulated in the provider.
@@ -187,7 +166,7 @@ interface ToolResultPart {
187
166
  to increase the resilience against prompt injection attacks,
188
167
  and because not all providers support several system messages.
189
168
  */
190
- type CoreSystemMessage = {
169
+ type SystemModelMessage = {
191
170
  role: 'system';
192
171
  content: string;
193
172
  /**
@@ -200,7 +179,7 @@ type CoreSystemMessage = {
200
179
  /**
201
180
  A user message. It can contain text or a combination of text and images.
202
181
  */
203
- type CoreUserMessage = {
182
+ type UserModelMessage = {
204
183
  role: 'user';
205
184
  content: UserContent;
206
185
  /**
@@ -217,7 +196,7 @@ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
217
196
  /**
218
197
  An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
219
198
  */
220
- type CoreAssistantMessage = {
199
+ type AssistantModelMessage = {
221
200
  role: 'assistant';
222
201
  content: AssistantContent;
223
202
  /**
@@ -235,7 +214,7 @@ type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | Too
235
214
  /**
236
215
  A tool message. It contains the result of one or more tool calls.
237
216
  */
238
- type CoreToolMessage = {
217
+ type ToolModelMessage = {
239
218
  role: 'tool';
240
219
  content: ToolContent;
241
220
  /**
@@ -253,7 +232,7 @@ type ToolContent = Array<ToolResultPart>;
253
232
  A message that can be used in the `messages` field of a prompt.
254
233
  It can be a user message, an assistant message, or a tool message.
255
234
  */
256
- type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
235
+ type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
257
236
 
258
237
  type JSONValue = JSONValue$1;
259
238
 
@@ -293,24 +272,6 @@ type ToolInvocation = ({
293
272
  state: 'result';
294
273
  step?: number;
295
274
  } & ToolResult<string, any, any>);
296
- /**
297
- * An attachment that can be sent along with a message.
298
- */
299
- interface Attachment {
300
- /**
301
- * The name of the attachment, usually the file name.
302
- */
303
- name?: string;
304
- /**
305
- * A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
306
- * By default, it's extracted from the pathname's extension.
307
- */
308
- contentType?: string;
309
- /**
310
- * The URL of the attachment. It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
311
- */
312
- url: string;
313
- }
314
275
  /**
315
276
  * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
316
277
  */
@@ -328,10 +289,6 @@ interface UIMessage {
328
289
  */
329
290
  content: string;
330
291
  /**
331
- Additional attachments to be sent along with the message.
332
- */
333
- experimental_attachments?: Attachment[];
334
- /**
335
292
  The role of the message.
336
293
  */
337
294
  role: 'system' | 'user' | 'assistant';
@@ -342,8 +299,12 @@ interface UIMessage {
342
299
  /**
343
300
  The parts of the message. Use this for rendering the message in the UI.
344
301
 
345
- Assistant messages can have text, reasoning and tool invocation parts.
346
- User messages can have text parts.
302
+ System messages should be avoided (set the system prompt on the server instead).
303
+ They can have text parts.
304
+
305
+ User messages can have text parts and file parts.
306
+
307
+ Assistant messages can have text, reasoning, tool invocation, and file parts.
347
308
  */
348
309
  parts: Array<UIMessagePart>;
349
310
  }
@@ -404,9 +365,14 @@ type FileUIPart = {
404
365
  */
405
366
  mediaType: string;
406
367
  /**
407
- * The base64 encoded data.
368
+ * Optional filename of the file.
369
+ */
370
+ filename?: string;
371
+ /**
372
+ * The URL of the file.
373
+ * It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
408
374
  */
409
- data: string;
375
+ url: string;
410
376
  };
411
377
  /**
412
378
  * A step boundary part of a message.
@@ -415,25 +381,6 @@ type StepStartUIPart = {
415
381
  type: 'step-start';
416
382
  };
417
383
 
418
- /**
419
- Represents the number of tokens used in a prompt and completion.
420
- */
421
- type LanguageModelUsage = {
422
- /**
423
- The number of tokens used in the prompt.
424
- */
425
- promptTokens: number;
426
- /**
427
- The number of tokens used in the completion.
428
- */
429
- completionTokens: number;
430
- /**
431
- The total number of tokens used (promptTokens + completionTokens).
432
- */
433
- totalTokens: number;
434
- };
435
- declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
436
-
437
384
  type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
438
385
  interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
439
386
  code: CODE;
@@ -451,25 +398,19 @@ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, Da
451
398
  argsTextDelta: string;
452
399
  }>, DataStreamPart<"d", "finish_message", {
453
400
  finishReason: LanguageModelV2FinishReason;
454
- usage?: {
455
- promptTokens: number;
456
- completionTokens: number;
457
- };
401
+ usage?: LanguageModelV2Usage;
458
402
  }>, DataStreamPart<"e", "finish_step", {
459
403
  isContinued: boolean;
460
404
  finishReason: LanguageModelV2FinishReason;
461
- usage?: {
462
- promptTokens: number;
463
- completionTokens: number;
464
- };
405
+ usage?: LanguageModelV2Usage;
465
406
  }>, DataStreamPart<"f", "start_step", {
466
407
  messageId: string;
467
408
  }>, DataStreamPart<"g", "reasoning", {
468
409
  text: string;
469
410
  providerMetadata?: Record<string, any> | undefined;
470
411
  }>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"l", "reasoning_part_finish", {}>, DataStreamPart<"k", "file", {
471
- data: string;
472
- mimeType: string;
412
+ url: string;
413
+ mediaType: string;
473
414
  }>];
474
415
  type DataStreamParts = (typeof dataStreamParts)[number];
475
416
  /**
@@ -502,7 +443,7 @@ type DataStreamPartValueType = {
502
443
  */
503
444
  declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
504
445
  /**
505
- Prepends a string with a prefix from the `StreamChunkPrefixes`, JSON-ifies it,
446
+ Prepends a string with a prefix from the `StreamChunkPrefixes`, converts it to JSON,
506
447
  and appends a new line.
507
448
 
508
449
  It ensures type-safety for the part type and value.
@@ -519,7 +460,7 @@ interface ToolExecutionOptions {
519
460
  * Messages that were sent to the language model to initiate the response that contained the tool call.
520
461
  * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
521
462
  */
522
- messages: CoreMessage[];
463
+ messages: ModelMessage[];
523
464
  /**
524
465
  * An optional abort signal that indicates that the overall operation should be aborted.
525
466
  */
@@ -597,7 +538,7 @@ type Prompt = {
597
538
  /**
598
539
  A list of messages. You can either use `prompt` or `messages` but not both.
599
540
  */
600
- messages?: Array<CoreMessage> | Array<Omit<UIMessage, 'id'>>;
541
+ messages?: Array<ModelMessage> | Array<Omit<UIMessage, 'id'>>;
601
542
  };
602
543
 
603
544
  type StandardizedPrompt = {
@@ -608,7 +549,7 @@ type StandardizedPrompt = {
608
549
  /**
609
550
  * Messages.
610
551
  */
611
- messages: CoreMessage[];
552
+ messages: ModelMessage[];
612
553
  };
613
554
  declare function standardizePrompt<TOOLS extends ToolSet>({ prompt, tools, }: {
614
555
  prompt: Prompt;
@@ -846,4 +787,4 @@ declare function createCallbacksTransformer(callbacks?: StreamCallbacks | undefi
846
787
  */
847
788
  declare const HANGING_STREAM_WARNING_TIME_MS: number;
848
789
 
849
- export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, StreamData, calculateLanguageModelUsage, convertToLanguageModelPrompt, createCallbacksTransformer, formatDataStreamPart, mergeStreams, prepareCallSettings, prepareResponseHeaders, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };
790
+ export { DataStreamWriter, HANGING_STREAM_WARNING_TIME_MS, StreamCallbacks, StreamData, convertToLanguageModelPrompt, createCallbacksTransformer, formatDataStreamPart, mergeStreams, prepareCallSettings, prepareResponseHeaders, prepareRetries, prepareToolsAndToolChoice, standardizePrompt };