ai 4.1.19 → 4.1.21
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 +15 -0
 - package/dist/index.d.mts +13 -14
 - package/dist/index.d.ts +13 -14
 - package/dist/index.js +135 -15
 - package/dist/index.js.map +1 -1
 - package/dist/index.mjs +135 -15
 - package/dist/index.mjs.map +1 -1
 - package/package.json +3 -3
 - package/rsc/dist/index.d.ts +2 -9
 - package/rsc/dist/rsc-server.d.mts +2 -9
 - package/rsc/dist/rsc-server.mjs +88 -2
 - package/rsc/dist/rsc-server.mjs.map +1 -1
 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "ai",
         
     | 
| 
       3 
     | 
    
         
            -
              "version": "4.1. 
     | 
| 
      
 3 
     | 
    
         
            +
              "version": "4.1.21",
         
     | 
| 
       4 
4 
     | 
    
         
             
              "description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "license": "Apache-2.0",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "sideEffects": false,
         
     | 
| 
         @@ -42,8 +42,8 @@ 
     | 
|
| 
       42 
42 
     | 
    
         
             
              "dependencies": {
         
     | 
| 
       43 
43 
     | 
    
         
             
                "@ai-sdk/provider": "1.0.7",
         
     | 
| 
       44 
44 
     | 
    
         
             
                "@ai-sdk/provider-utils": "2.1.6",
         
     | 
| 
       45 
     | 
    
         
            -
                "@ai-sdk/react": "1.1. 
     | 
| 
       46 
     | 
    
         
            -
                "@ai-sdk/ui-utils": "1.1. 
     | 
| 
      
 45 
     | 
    
         
            +
                "@ai-sdk/react": "1.1.10",
         
     | 
| 
      
 46 
     | 
    
         
            +
                "@ai-sdk/ui-utils": "1.1.10",
         
     | 
| 
       47 
47 
     | 
    
         
             
                "@opentelemetry/api": "1.9.0",
         
     | 
| 
       48 
48 
     | 
    
         
             
                "jsondiffpatch": "0.6.0"
         
     | 
| 
       49 
49 
     | 
    
         
             
              },
         
     | 
    
        package/rsc/dist/index.d.ts
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1 } from '@ai-sdk/provider';
         
     | 
| 
       2 
2 
     | 
    
         
             
            import { ReactNode } from 'react';
         
     | 
| 
       3 
3 
     | 
    
         
             
            import { z } from 'zod';
         
     | 
| 
       4 
     | 
    
         
            -
            import {  
     | 
| 
      
 4 
     | 
    
         
            +
            import { Message } from '@ai-sdk/ui-utils';
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;
         
     | 
| 
       7 
7 
     | 
    
         
             
            type AIActions<T = any, R = any> = Record<string, AIAction<T, R>>;
         
     | 
| 
         @@ -480,13 +480,6 @@ It can be a user message, an assistant message, or a tool message. 
     | 
|
| 
       480 
480 
     | 
    
         
             
             */
         
     | 
| 
       481 
481 
     | 
    
         
             
            type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
         
     | 
| 
       482 
482 
     | 
    
         | 
| 
       483 
     | 
    
         
            -
            type UIMessage = {
         
     | 
| 
       484 
     | 
    
         
            -
                role: 'system' | 'user' | 'assistant' | 'data';
         
     | 
| 
       485 
     | 
    
         
            -
                content: string;
         
     | 
| 
       486 
     | 
    
         
            -
                toolInvocations?: ToolInvocation[];
         
     | 
| 
       487 
     | 
    
         
            -
                experimental_attachments?: Attachment[];
         
     | 
| 
       488 
     | 
    
         
            -
            };
         
     | 
| 
       489 
     | 
    
         
            -
             
     | 
| 
       490 
483 
     | 
    
         
             
            /**
         
     | 
| 
       491 
484 
     | 
    
         
             
            Prompt part of the AI function options.
         
     | 
| 
       492 
485 
     | 
    
         
             
            It contains a system message, a simple text prompt, or a list of messages.
         
     | 
| 
         @@ -503,7 +496,7 @@ type Prompt = { 
     | 
|
| 
       503 
496 
     | 
    
         
             
                /**
         
     | 
| 
       504 
497 
     | 
    
         
             
              A list of messages. You can either use `prompt` or `messages` but not both.
         
     | 
| 
       505 
498 
     | 
    
         
             
                 */
         
     | 
| 
       506 
     | 
    
         
            -
                messages?: Array<CoreMessage> | Array< 
     | 
| 
      
 499 
     | 
    
         
            +
                messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
         
     | 
| 
       507 
500 
     | 
    
         
             
            };
         
     | 
| 
       508 
501 
     | 
    
         | 
| 
       509 
502 
     | 
    
         
             
            type Streamable = ReactNode | Promise<ReactNode>;
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1 } from '@ai-sdk/provider';
         
     | 
| 
       2 
2 
     | 
    
         
             
            import { ReactNode } from 'react';
         
     | 
| 
       3 
3 
     | 
    
         
             
            import { z } from 'zod';
         
     | 
| 
       4 
     | 
    
         
            -
            import {  
     | 
| 
      
 4 
     | 
    
         
            +
            import { Message } from '@ai-sdk/ui-utils';
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            type AIAction<T = any, R = any> = (...args: T[]) => Promise<R>;
         
     | 
| 
       7 
7 
     | 
    
         
             
            type AIActions<T = any, R = any> = Record<string, AIAction<T, R>>;
         
     | 
| 
         @@ -478,13 +478,6 @@ It can be a user message, an assistant message, or a tool message. 
     | 
|
| 
       478 
478 
     | 
    
         
             
             */
         
     | 
| 
       479 
479 
     | 
    
         
             
            type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
         
     | 
| 
       480 
480 
     | 
    
         | 
| 
       481 
     | 
    
         
            -
            type UIMessage = {
         
     | 
| 
       482 
     | 
    
         
            -
                role: 'system' | 'user' | 'assistant' | 'data';
         
     | 
| 
       483 
     | 
    
         
            -
                content: string;
         
     | 
| 
       484 
     | 
    
         
            -
                toolInvocations?: ToolInvocation[];
         
     | 
| 
       485 
     | 
    
         
            -
                experimental_attachments?: Attachment[];
         
     | 
| 
       486 
     | 
    
         
            -
            };
         
     | 
| 
       487 
     | 
    
         
            -
             
     | 
| 
       488 
481 
     | 
    
         
             
            /**
         
     | 
| 
       489 
482 
     | 
    
         
             
            Prompt part of the AI function options.
         
     | 
| 
       490 
483 
     | 
    
         
             
            It contains a system message, a simple text prompt, or a list of messages.
         
     | 
| 
         @@ -501,7 +494,7 @@ type Prompt = { 
     | 
|
| 
       501 
494 
     | 
    
         
             
                /**
         
     | 
| 
       502 
495 
     | 
    
         
             
              A list of messages. You can either use `prompt` or `messages` but not both.
         
     | 
| 
       503 
496 
     | 
    
         
             
                 */
         
     | 
| 
       504 
     | 
    
         
            -
                messages?: Array<CoreMessage> | Array< 
     | 
| 
      
 497 
     | 
    
         
            +
                messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
         
     | 
| 
       505 
498 
     | 
    
         
             
            };
         
     | 
| 
       506 
499 
     | 
    
         | 
| 
       507 
500 
     | 
    
         
             
            type Streamable = ReactNode | Promise<ReactNode>;
         
     | 
    
        package/rsc/dist/rsc-server.mjs
    CHANGED
    
    | 
         @@ -976,13 +976,13 @@ _a6 = symbol6; 
     | 
|
| 
       976 
976 
     | 
    
         | 
| 
       977 
977 
     | 
    
         
             
            // core/prompt/convert-to-core-messages.ts
         
     | 
| 
       978 
978 
     | 
    
         
             
            function convertToCoreMessages(messages, options) {
         
     | 
| 
       979 
     | 
    
         
            -
              var _a9;
         
     | 
| 
      
 979 
     | 
    
         
            +
              var _a9, _b;
         
     | 
| 
       980 
980 
     | 
    
         
             
              const tools = (_a9 = options == null ? void 0 : options.tools) != null ? _a9 : {};
         
     | 
| 
       981 
981 
     | 
    
         
             
              const coreMessages = [];
         
     | 
| 
       982 
982 
     | 
    
         
             
              for (let i = 0; i < messages.length; i++) {
         
     | 
| 
       983 
983 
     | 
    
         
             
                const message = messages[i];
         
     | 
| 
       984 
984 
     | 
    
         
             
                const isLastMessage = i === messages.length - 1;
         
     | 
| 
       985 
     | 
    
         
            -
                const { role, content,  
     | 
| 
      
 985 
     | 
    
         
            +
                const { role, content, experimental_attachments } = message;
         
     | 
| 
       986 
986 
     | 
    
         
             
                switch (role) {
         
     | 
| 
       987 
987 
     | 
    
         
             
                  case "system": {
         
     | 
| 
       988 
988 
     | 
    
         
             
                    coreMessages.push({
         
     | 
| 
         @@ -1002,6 +1002,92 @@ function convertToCoreMessages(messages, options) { 
     | 
|
| 
       1002 
1002 
     | 
    
         
             
                    break;
         
     | 
| 
       1003 
1003 
     | 
    
         
             
                  }
         
     | 
| 
       1004 
1004 
     | 
    
         
             
                  case "assistant": {
         
     | 
| 
      
 1005 
     | 
    
         
            +
                    if (message.parts != null) {
         
     | 
| 
      
 1006 
     | 
    
         
            +
                      let processBlock2 = function() {
         
     | 
| 
      
 1007 
     | 
    
         
            +
                        coreMessages.push({
         
     | 
| 
      
 1008 
     | 
    
         
            +
                          role: "assistant",
         
     | 
| 
      
 1009 
     | 
    
         
            +
                          content: block.map((part) => {
         
     | 
| 
      
 1010 
     | 
    
         
            +
                            switch (part.type) {
         
     | 
| 
      
 1011 
     | 
    
         
            +
                              case "text":
         
     | 
| 
      
 1012 
     | 
    
         
            +
                                return {
         
     | 
| 
      
 1013 
     | 
    
         
            +
                                  type: "text",
         
     | 
| 
      
 1014 
     | 
    
         
            +
                                  text: part.text
         
     | 
| 
      
 1015 
     | 
    
         
            +
                                };
         
     | 
| 
      
 1016 
     | 
    
         
            +
                              default:
         
     | 
| 
      
 1017 
     | 
    
         
            +
                                return {
         
     | 
| 
      
 1018 
     | 
    
         
            +
                                  type: "tool-call",
         
     | 
| 
      
 1019 
     | 
    
         
            +
                                  toolCallId: part.toolInvocation.toolCallId,
         
     | 
| 
      
 1020 
     | 
    
         
            +
                                  toolName: part.toolInvocation.toolName,
         
     | 
| 
      
 1021 
     | 
    
         
            +
                                  args: part.toolInvocation.args
         
     | 
| 
      
 1022 
     | 
    
         
            +
                                };
         
     | 
| 
      
 1023 
     | 
    
         
            +
                            }
         
     | 
| 
      
 1024 
     | 
    
         
            +
                          })
         
     | 
| 
      
 1025 
     | 
    
         
            +
                        });
         
     | 
| 
      
 1026 
     | 
    
         
            +
                        const stepInvocations = block.filter(
         
     | 
| 
      
 1027 
     | 
    
         
            +
                          (part) => part.type === "tool-invocation"
         
     | 
| 
      
 1028 
     | 
    
         
            +
                        ).map((part) => part.toolInvocation);
         
     | 
| 
      
 1029 
     | 
    
         
            +
                        if (stepInvocations.length > 0) {
         
     | 
| 
      
 1030 
     | 
    
         
            +
                          coreMessages.push({
         
     | 
| 
      
 1031 
     | 
    
         
            +
                            role: "tool",
         
     | 
| 
      
 1032 
     | 
    
         
            +
                            content: stepInvocations.map(
         
     | 
| 
      
 1033 
     | 
    
         
            +
                              (toolInvocation) => {
         
     | 
| 
      
 1034 
     | 
    
         
            +
                                if (!("result" in toolInvocation)) {
         
     | 
| 
      
 1035 
     | 
    
         
            +
                                  throw new MessageConversionError({
         
     | 
| 
      
 1036 
     | 
    
         
            +
                                    originalMessage: message,
         
     | 
| 
      
 1037 
     | 
    
         
            +
                                    message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
         
     | 
| 
      
 1038 
     | 
    
         
            +
                                  });
         
     | 
| 
      
 1039 
     | 
    
         
            +
                                }
         
     | 
| 
      
 1040 
     | 
    
         
            +
                                const { toolCallId, toolName, result } = toolInvocation;
         
     | 
| 
      
 1041 
     | 
    
         
            +
                                const tool = tools[toolName];
         
     | 
| 
      
 1042 
     | 
    
         
            +
                                return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
         
     | 
| 
      
 1043 
     | 
    
         
            +
                                  type: "tool-result",
         
     | 
| 
      
 1044 
     | 
    
         
            +
                                  toolCallId,
         
     | 
| 
      
 1045 
     | 
    
         
            +
                                  toolName,
         
     | 
| 
      
 1046 
     | 
    
         
            +
                                  result: tool.experimental_toToolResultContent(result),
         
     | 
| 
      
 1047 
     | 
    
         
            +
                                  experimental_content: tool.experimental_toToolResultContent(result)
         
     | 
| 
      
 1048 
     | 
    
         
            +
                                } : {
         
     | 
| 
      
 1049 
     | 
    
         
            +
                                  type: "tool-result",
         
     | 
| 
      
 1050 
     | 
    
         
            +
                                  toolCallId,
         
     | 
| 
      
 1051 
     | 
    
         
            +
                                  toolName,
         
     | 
| 
      
 1052 
     | 
    
         
            +
                                  result
         
     | 
| 
      
 1053 
     | 
    
         
            +
                                };
         
     | 
| 
      
 1054 
     | 
    
         
            +
                              }
         
     | 
| 
      
 1055 
     | 
    
         
            +
                            )
         
     | 
| 
      
 1056 
     | 
    
         
            +
                          });
         
     | 
| 
      
 1057 
     | 
    
         
            +
                        }
         
     | 
| 
      
 1058 
     | 
    
         
            +
                        block = [];
         
     | 
| 
      
 1059 
     | 
    
         
            +
                        blockHasToolInvocations = false;
         
     | 
| 
      
 1060 
     | 
    
         
            +
                        currentStep++;
         
     | 
| 
      
 1061 
     | 
    
         
            +
                      };
         
     | 
| 
      
 1062 
     | 
    
         
            +
                      var processBlock = processBlock2;
         
     | 
| 
      
 1063 
     | 
    
         
            +
                      let currentStep = 0;
         
     | 
| 
      
 1064 
     | 
    
         
            +
                      let blockHasToolInvocations = false;
         
     | 
| 
      
 1065 
     | 
    
         
            +
                      let block = [];
         
     | 
| 
      
 1066 
     | 
    
         
            +
                      for (const part of message.parts) {
         
     | 
| 
      
 1067 
     | 
    
         
            +
                        switch (part.type) {
         
     | 
| 
      
 1068 
     | 
    
         
            +
                          case "reasoning":
         
     | 
| 
      
 1069 
     | 
    
         
            +
                            break;
         
     | 
| 
      
 1070 
     | 
    
         
            +
                          case "text": {
         
     | 
| 
      
 1071 
     | 
    
         
            +
                            if (blockHasToolInvocations) {
         
     | 
| 
      
 1072 
     | 
    
         
            +
                              processBlock2();
         
     | 
| 
      
 1073 
     | 
    
         
            +
                            }
         
     | 
| 
      
 1074 
     | 
    
         
            +
                            block.push(part);
         
     | 
| 
      
 1075 
     | 
    
         
            +
                            break;
         
     | 
| 
      
 1076 
     | 
    
         
            +
                          }
         
     | 
| 
      
 1077 
     | 
    
         
            +
                          case "tool-invocation": {
         
     | 
| 
      
 1078 
     | 
    
         
            +
                            if (((_b = part.toolInvocation.step) != null ? _b : 0) !== currentStep) {
         
     | 
| 
      
 1079 
     | 
    
         
            +
                              processBlock2();
         
     | 
| 
      
 1080 
     | 
    
         
            +
                            }
         
     | 
| 
      
 1081 
     | 
    
         
            +
                            block.push(part);
         
     | 
| 
      
 1082 
     | 
    
         
            +
                            blockHasToolInvocations = true;
         
     | 
| 
      
 1083 
     | 
    
         
            +
                            break;
         
     | 
| 
      
 1084 
     | 
    
         
            +
                          }
         
     | 
| 
      
 1085 
     | 
    
         
            +
                        }
         
     | 
| 
      
 1086 
     | 
    
         
            +
                      }
         
     | 
| 
      
 1087 
     | 
    
         
            +
                      processBlock2();
         
     | 
| 
      
 1088 
     | 
    
         
            +
                      break;
         
     | 
| 
      
 1089 
     | 
    
         
            +
                    }
         
     | 
| 
      
 1090 
     | 
    
         
            +
                    const toolInvocations = message.toolInvocations;
         
     | 
| 
       1005 
1091 
     | 
    
         
             
                    if (toolInvocations == null || toolInvocations.length === 0) {
         
     | 
| 
       1006 
1092 
     | 
    
         
             
                      coreMessages.push({ role: "assistant", content });
         
     | 
| 
       1007 
1093 
     | 
    
         
             
                      break;
         
     |