ai 3.4.25 → 3.4.27

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ai
2
2
 
3
+ ## 3.4.27
4
+
5
+ ### Patch Changes
6
+
7
+ - fa772ae: feat (ai/core): automatically convert ui messages to core messages
8
+
9
+ ## 3.4.26
10
+
11
+ ### Patch Changes
12
+
13
+ - 57f39ea: feat (ai/core): support multi-modal tool results in convertToCoreMessages
14
+
3
15
  ## 3.4.25
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema, DeepPartial, ToolInvocation, Attachment, JSONValue as JSONValue$1, CreateMessage, FunctionCall as FunctionCall$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
1
+ import { ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, CreateMessage, FunctionCall as FunctionCall$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
2
  export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, Function, FunctionCall, FunctionCallHandler, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, Tool, ToolCall, ToolCallHandler, ToolChoice, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseStreamPart, processDataProtocolResponse, readDataStream } from '@ai-sdk/ui-utils';
3
3
  import { AttributeValue, Tracer } from '@opentelemetry/api';
4
4
  import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, LanguageModelV1CallOptions, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
@@ -634,6 +634,13 @@ It can be a user message, an assistant message, or a tool message.
634
634
  */
635
635
  type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
636
636
 
637
+ type UIMessage = {
638
+ role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
639
+ content: string;
640
+ toolInvocations?: ToolInvocation[];
641
+ experimental_attachments?: Attachment[];
642
+ };
643
+
637
644
  /**
638
645
  Prompt part of the AI function options.
639
646
  It contains a system message, a simple text prompt, or a list of messages.
@@ -650,7 +657,7 @@ type Prompt = {
650
657
  /**
651
658
  A list of messages. You can either use `prompt` or `messages` but not both.
652
659
  */
653
- messages?: Array<CoreMessage>;
660
+ messages?: Array<CoreMessage> | Array<UIMessage>;
654
661
  };
655
662
 
656
663
  /**
@@ -1321,17 +1328,13 @@ declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARA
1321
1328
  */
1322
1329
  type ExperimentalTool = CoreTool;
1323
1330
 
1324
- type ConvertibleMessage = {
1325
- role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1326
- content: string;
1327
- toolInvocations?: ToolInvocation[];
1328
- experimental_attachments?: Attachment[];
1329
- };
1330
1331
  /**
1331
1332
  Converts an array of messages from useChat into an array of CoreMessages that can be used
1332
1333
  with the AI core functions (e.g. `streamText`).
1333
1334
  */
1334
- declare function convertToCoreMessages(messages: Array<ConvertibleMessage>): CoreMessage[];
1335
+ declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> = never>(messages: Array<UIMessage>, options?: {
1336
+ tools?: TOOLS;
1337
+ }): CoreMessage[];
1335
1338
 
1336
1339
  /**
1337
1340
  Create a union of the given object's values, and optionally specify which keys to get the values from.
@@ -2427,9 +2430,9 @@ declare class InvalidMessageRoleError extends AISDKError {
2427
2430
  declare const symbol$2: unique symbol;
2428
2431
  declare class MessageConversionError extends AISDKError {
2429
2432
  private readonly [symbol$2];
2430
- readonly originalMessage: ConvertibleMessage;
2433
+ readonly originalMessage: UIMessage;
2431
2434
  constructor({ originalMessage, message, }: {
2432
- originalMessage: ConvertibleMessage;
2435
+ originalMessage: UIMessage;
2433
2436
  message: string;
2434
2437
  });
2435
2438
  static isInstance(error: unknown): error is MessageConversionError;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema, DeepPartial, ToolInvocation, Attachment, JSONValue as JSONValue$1, CreateMessage, FunctionCall as FunctionCall$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
1
+ import { ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, CreateMessage, FunctionCall as FunctionCall$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
2
  export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, Function, FunctionCall, FunctionCallHandler, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, Tool, ToolCall, ToolCallHandler, ToolChoice, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseStreamPart, processDataProtocolResponse, readDataStream } from '@ai-sdk/ui-utils';
3
3
  import { AttributeValue, Tracer } from '@opentelemetry/api';
4
4
  import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, LanguageModelV1CallOptions, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
@@ -634,6 +634,13 @@ It can be a user message, an assistant message, or a tool message.
634
634
  */
635
635
  type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
636
636
 
637
+ type UIMessage = {
638
+ role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
639
+ content: string;
640
+ toolInvocations?: ToolInvocation[];
641
+ experimental_attachments?: Attachment[];
642
+ };
643
+
637
644
  /**
638
645
  Prompt part of the AI function options.
639
646
  It contains a system message, a simple text prompt, or a list of messages.
@@ -650,7 +657,7 @@ type Prompt = {
650
657
  /**
651
658
  A list of messages. You can either use `prompt` or `messages` but not both.
652
659
  */
653
- messages?: Array<CoreMessage>;
660
+ messages?: Array<CoreMessage> | Array<UIMessage>;
654
661
  };
655
662
 
656
663
  /**
@@ -1321,17 +1328,13 @@ declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARA
1321
1328
  */
1322
1329
  type ExperimentalTool = CoreTool;
1323
1330
 
1324
- type ConvertibleMessage = {
1325
- role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
1326
- content: string;
1327
- toolInvocations?: ToolInvocation[];
1328
- experimental_attachments?: Attachment[];
1329
- };
1330
1331
  /**
1331
1332
  Converts an array of messages from useChat into an array of CoreMessages that can be used
1332
1333
  with the AI core functions (e.g. `streamText`).
1333
1334
  */
1334
- declare function convertToCoreMessages(messages: Array<ConvertibleMessage>): CoreMessage[];
1335
+ declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> = never>(messages: Array<UIMessage>, options?: {
1336
+ tools?: TOOLS;
1337
+ }): CoreMessage[];
1335
1338
 
1336
1339
  /**
1337
1340
  Create a union of the given object's values, and optionally specify which keys to get the values from.
@@ -2427,9 +2430,9 @@ declare class InvalidMessageRoleError extends AISDKError {
2427
2430
  declare const symbol$2: unique symbol;
2428
2431
  declare class MessageConversionError extends AISDKError {
2429
2432
  private readonly [symbol$2];
2430
- readonly originalMessage: ConvertibleMessage;
2433
+ readonly originalMessage: UIMessage;
2431
2434
  constructor({ originalMessage, message, }: {
2432
- originalMessage: ConvertibleMessage;
2435
+ originalMessage: UIMessage;
2433
2436
  message: string;
2434
2437
  });
2435
2438
  static isInstance(error: unknown): error is MessageConversionError;