ai 3.1.17 → 3.1.19

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.mts CHANGED
@@ -728,34 +728,6 @@ onlyBar('bar');
728
728
  */
729
729
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
730
730
 
731
- /**
732
- Typed tool call that is returned by generateText and streamText.
733
- It contains the tool call ID, the tool name, and the tool arguments.
734
- */
735
- interface ToolCall$1<NAME extends string, ARGS> {
736
- /**
737
- ID of the tool call. This ID is used to match the tool call with the tool result.
738
- */
739
- toolCallId: string;
740
- /**
741
- Name of the tool that is being called.
742
- */
743
- toolName: NAME;
744
- /**
745
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
746
- */
747
- args: ARGS;
748
- }
749
- type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
750
- [NAME in keyof TOOLS]: {
751
- type: 'tool-call';
752
- toolCallId: string;
753
- toolName: NAME & string;
754
- args: z.infer<TOOLS[NAME]['parameters']>;
755
- };
756
- }>;
757
- type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
758
-
759
731
  /**
760
732
  Typed tool result that is returned by generateText and streamText.
761
733
  It contains the tool call ID, the tool name, the tool arguments, and the tool result.
@@ -798,6 +770,44 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
798
770
  type ToToolResult<TOOLS extends Record<string, CoreTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
799
771
  type ToToolResultArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolResult<TOOLS>>;
800
772
 
773
+ /**
774
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
775
+ with the AI core functions (e.g. `streamText`).
776
+ */
777
+ declare function convertToCoreMessages(messages: Array<{
778
+ role: 'user' | 'assistant';
779
+ content: string;
780
+ toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
781
+ }>): CoreMessage[];
782
+
783
+ /**
784
+ Typed tool call that is returned by generateText and streamText.
785
+ It contains the tool call ID, the tool name, and the tool arguments.
786
+ */
787
+ interface ToolCall$1<NAME extends string, ARGS> {
788
+ /**
789
+ ID of the tool call. This ID is used to match the tool call with the tool result.
790
+ */
791
+ toolCallId: string;
792
+ /**
793
+ Name of the tool that is being called.
794
+ */
795
+ toolName: NAME;
796
+ /**
797
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
798
+ */
799
+ args: ARGS;
800
+ }
801
+ type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
802
+ [NAME in keyof TOOLS]: {
803
+ type: 'tool-call';
804
+ toolCallId: string;
805
+ toolName: NAME & string;
806
+ args: z.infer<TOOLS[NAME]['parameters']>;
807
+ };
808
+ }>;
809
+ type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
810
+
801
811
  /**
802
812
  Generate a text and call tools for a given prompt using a language model.
803
813
 
@@ -876,6 +886,14 @@ declare class GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
876
886
  */
877
887
  readonly warnings: CallWarning[] | undefined;
878
888
  /**
889
+ The response messages that were generated during the call. It consists of an assistant message,
890
+ potentially containing tool calls.
891
+ When there are tool results, there is an additional tool message with the tool results that are available.
892
+ If there are tools that do not have execute functions, they are not included in the tool results and
893
+ need to be added separately.
894
+ */
895
+ readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
896
+ /**
879
897
  Optional raw response data.
880
898
  */
881
899
  rawResponse?: {
@@ -1143,16 +1161,6 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1143
1161
  */
1144
1162
  declare const experimental_streamText: typeof streamText;
1145
1163
 
1146
- /**
1147
- Converts an array of messages from useChat into an array of CoreMessages that can be used
1148
- with the AI core functions (e.g. `streamText`).
1149
- */
1150
- declare function convertToCoreMessages(messages: Array<{
1151
- role: 'user' | 'assistant';
1152
- content: string;
1153
- toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
1154
- }>): CoreMessage[];
1155
-
1156
1164
  type AssistantStatus = 'in_progress' | 'awaiting_message';
1157
1165
  type UseAssistantOptions = {
1158
1166
  /**
package/dist/index.d.ts CHANGED
@@ -728,34 +728,6 @@ onlyBar('bar');
728
728
  */
729
729
  type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
730
730
 
731
- /**
732
- Typed tool call that is returned by generateText and streamText.
733
- It contains the tool call ID, the tool name, and the tool arguments.
734
- */
735
- interface ToolCall$1<NAME extends string, ARGS> {
736
- /**
737
- ID of the tool call. This ID is used to match the tool call with the tool result.
738
- */
739
- toolCallId: string;
740
- /**
741
- Name of the tool that is being called.
742
- */
743
- toolName: NAME;
744
- /**
745
- Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
746
- */
747
- args: ARGS;
748
- }
749
- type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
750
- [NAME in keyof TOOLS]: {
751
- type: 'tool-call';
752
- toolCallId: string;
753
- toolName: NAME & string;
754
- args: z.infer<TOOLS[NAME]['parameters']>;
755
- };
756
- }>;
757
- type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
758
-
759
731
  /**
760
732
  Typed tool result that is returned by generateText and streamText.
761
733
  It contains the tool call ID, the tool name, the tool arguments, and the tool result.
@@ -798,6 +770,44 @@ type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
798
770
  type ToToolResult<TOOLS extends Record<string, CoreTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
799
771
  type ToToolResultArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolResult<TOOLS>>;
800
772
 
773
+ /**
774
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
775
+ with the AI core functions (e.g. `streamText`).
776
+ */
777
+ declare function convertToCoreMessages(messages: Array<{
778
+ role: 'user' | 'assistant';
779
+ content: string;
780
+ toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
781
+ }>): CoreMessage[];
782
+
783
+ /**
784
+ Typed tool call that is returned by generateText and streamText.
785
+ It contains the tool call ID, the tool name, and the tool arguments.
786
+ */
787
+ interface ToolCall$1<NAME extends string, ARGS> {
788
+ /**
789
+ ID of the tool call. This ID is used to match the tool call with the tool result.
790
+ */
791
+ toolCallId: string;
792
+ /**
793
+ Name of the tool that is being called.
794
+ */
795
+ toolName: NAME;
796
+ /**
797
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
798
+ */
799
+ args: ARGS;
800
+ }
801
+ type ToToolCall<TOOLS extends Record<string, CoreTool>> = ValueOf<{
802
+ [NAME in keyof TOOLS]: {
803
+ type: 'tool-call';
804
+ toolCallId: string;
805
+ toolName: NAME & string;
806
+ args: z.infer<TOOLS[NAME]['parameters']>;
807
+ };
808
+ }>;
809
+ type ToToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToToolCall<TOOLS>>;
810
+
801
811
  /**
802
812
  Generate a text and call tools for a given prompt using a language model.
803
813
 
@@ -876,6 +886,14 @@ declare class GenerateTextResult<TOOLS extends Record<string, CoreTool>> {
876
886
  */
877
887
  readonly warnings: CallWarning[] | undefined;
878
888
  /**
889
+ The response messages that were generated during the call. It consists of an assistant message,
890
+ potentially containing tool calls.
891
+ When there are tool results, there is an additional tool message with the tool results that are available.
892
+ If there are tools that do not have execute functions, they are not included in the tool results and
893
+ need to be added separately.
894
+ */
895
+ readonly responseMessages: Array<CoreAssistantMessage | CoreToolMessage>;
896
+ /**
879
897
  Optional raw response data.
880
898
  */
881
899
  rawResponse?: {
@@ -1143,16 +1161,6 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1143
1161
  */
1144
1162
  declare const experimental_streamText: typeof streamText;
1145
1163
 
1146
- /**
1147
- Converts an array of messages from useChat into an array of CoreMessages that can be used
1148
- with the AI core functions (e.g. `streamText`).
1149
- */
1150
- declare function convertToCoreMessages(messages: Array<{
1151
- role: 'user' | 'assistant';
1152
- content: string;
1153
- toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
1154
- }>): CoreMessage[];
1155
-
1156
1164
  type AssistantStatus = 'in_progress' | 'awaiting_message';
1157
1165
  type UseAssistantOptions = {
1158
1166
  /**
package/dist/index.js CHANGED
@@ -1408,8 +1408,32 @@ var GenerateTextResult = class {
1408
1408
  this.warnings = options.warnings;
1409
1409
  this.rawResponse = options.rawResponse;
1410
1410
  this.logprobs = options.logprobs;
1411
+ this.responseMessages = toResponseMessages(options);
1411
1412
  }
1412
1413
  };
1414
+ function toResponseMessages({
1415
+ text,
1416
+ toolCalls,
1417
+ toolResults
1418
+ }) {
1419
+ const responseMessages = [];
1420
+ responseMessages.push({
1421
+ role: "assistant",
1422
+ content: [{ type: "text", text }, ...toolCalls]
1423
+ });
1424
+ if (toolResults.length > 0) {
1425
+ responseMessages.push({
1426
+ role: "tool",
1427
+ content: toolResults.map((result) => ({
1428
+ type: "tool-result",
1429
+ toolCallId: result.toolCallId,
1430
+ toolName: result.toolName,
1431
+ result: result.result
1432
+ }))
1433
+ });
1434
+ }
1435
+ return responseMessages;
1436
+ }
1413
1437
  var experimental_generateText = generateText;
1414
1438
 
1415
1439
  // core/generate-text/run-tools-transformation.ts
@@ -3346,9 +3370,7 @@ async function parseComplexResponse({
3346
3370
  }
3347
3371
  prefixMap.text.toolInvocations.push(value);
3348
3372
  if (onToolCall) {
3349
- console.log("onToolCall", value);
3350
3373
  const result = await onToolCall({ toolCall: value });
3351
- console.log("onToolCall result", result);
3352
3374
  if (result != null) {
3353
3375
  prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { ...value, result };
3354
3376
  }