@ray-js/t-agent 0.2.7-beta.1 → 0.2.7-beta.3

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/README-zh_CN.md CHANGED
@@ -22,12 +22,21 @@ yarn add @ray-js/t-agent @ray-js/t-agent-plugin-aistream @ray-js/t-agent-ui-ray
22
22
  "DeviceKit": "4.6.1",
23
23
  "HomeKit": "3.4.0",
24
24
  "MiniKit": "3.12.1",
25
- "AIStreamKit": "1.0.0"
25
+ "AIStreamKit": "1.3.2"
26
26
  },
27
27
  "baseversion": "2.21.10"
28
28
  }
29
29
  ```
30
30
 
31
+ ### 小程序 kit 与功能对应表
32
+
33
+ 部分功能对 App 的 kit 有依赖要求,需要配置 AIStreamKit 最低才能使用这些功能
34
+
35
+ | 功能 | AIStreamKit 最低版本 | 相关 API |
36
+ | ---------- | -------------------- | ------------------------------------- |
37
+ | 对话分组 | 1.3.2 | agent.plugins.aiStream.getChatId |
38
+ | 自定义参数 | 2.1.0 | agent.plugins.aiStream.onUserDataRead |
39
+
31
40
  ## package.json 依赖要求
32
41
 
33
42
  ```json
@@ -771,6 +780,7 @@ const createAgent = () => {
771
780
  - `indexId` 索引 ID,默认为 'default'
772
781
  - `homeId` 家庭 ID,不填默认当前家庭
773
782
  - `earlyStart` 是否在 onAgentStart 阶段就建立连接
783
+ - `eventIdPrefix` eventId 前缀,用于方便云端调试和日志追踪
774
784
  - `tokenOptions` 获取 agent token 的参数
775
785
  - `api` API 接口名
776
786
  - `version` 接口版本
@@ -779,14 +789,30 @@ const createAgent = () => {
779
789
 
780
790
  方法:
781
791
 
782
- - `agent.plugins.aiStream.send` 向智能体发送一条消息
783
- - `agent.plugins.aiStream.chat` 向智能体发送一条消息,并生成提问 ChatMessage 对象和 AI 回答 ChatMessage 对象,流式更新
792
+ - `agent.plugins.aiStream.send(blocks, signal, userData)` 向智能体发送一条消息
793
+ - `blocks` 输入块数组
794
+ - `signal` 可选的 AbortSignal,用于中断请求
795
+ - `userData` 可选的用户数据,会附带在发送的消息中
796
+ - `agent.plugins.aiStream.chat(blocks, signal, options)` 向智能体发送一条消息,并生成提问 ChatMessage 对象和 AI 回答 ChatMessage 对象,流式更新
797
+ - `blocks` 输入块数组
798
+ - `signal` 可选的 AbortSignal
799
+ - `options.sendBy` 发送者角色,默认为 'user'
800
+ - `options.responseBy` 响应者角色,默认为 'assistant'
801
+ - `options.userData` 可选的用户数据
802
+ - `agent.plugins.aiStream.getChatId()` 获取当前会话的 chatId,返回 Promise<string>
784
803
 
785
804
  Hooks:
786
805
 
787
806
  - `onMessageParse` 当读取历史消息,解析消息时触发,可以在这个 Hook 里修改消息
788
807
  - `msgItem` 存储的消息对象
789
808
  - `result.messages` 解析后的消息列表
809
+ - `onChatMessageSent` 当用户消息和响应消息创建后触发
810
+ - `userMessage` 用户发送的消息
811
+ - `respMessage` AI 的响应消息
812
+ - `onTextCompose` 当收到文本数据时触发,用于处理文本的渲染
813
+ - `respMsg` 响应消息
814
+ - `status` 消息状态
815
+ - `result.text` 文本内容,可以修改
790
816
  - `onSkillCompose` 当收到技能数据时触发,用于处理技能的渲染
791
817
  - `skill` 技能数据数组 (ReceivedTextSkillPacketBody[])
792
818
  - `respMsg` 响应消息
@@ -801,6 +827,47 @@ Hooks:
801
827
  - `onCardsReceived` 当收到卡片数据时触发
802
828
  - `skills` 技能数据列表 (ReceivedTextSkillPacketBody[])
803
829
  - `result.cards` 卡片列表
830
+ - `onUserDataRead` **(0.2.x 新增)** 当需要读取用户自定义数据时触发,用于向 AI 平台传递额外的上下文信息
831
+ - `type` 触发类型,可以是 'create-session' 或 'start-event'
832
+ - `'create-session'` 创建会话时触发,只触发一次
833
+ - `'start-event'` 每次发送消息时触发
834
+ - `data` 上下文数据
835
+ - `data.blocks` 当 type 为 'start-event' 时,包含本次发送的输入块
836
+ - `result.userData` 返回的用户数据对象,会被合并后发送给 AI 平台
837
+
838
+ **使用示例**:
839
+
840
+ ```tsx
841
+ const agent = createChatAgent(
842
+ withUI(),
843
+ withAIStream({
844
+ agentId: 'your-agent-id',
845
+ })
846
+ );
847
+
848
+ agent.plugins.aiStream.onUserDataRead((type, data, result) => {
849
+ // 在创建会话时传递用户信息
850
+ if (type === 'create-session') {
851
+ result.sessionAttributes = {
852
+ 'custom.param': {
853
+ userName: { value: 'John' },
854
+ userLevel: { value: 'Plus' },
855
+ },
856
+ };
857
+ return;
858
+ }
859
+ // 在每次发送消息时传递动态上下文
860
+ if (type === 'start-event') {
861
+ result.userData = {
862
+ 'custom.param': {
863
+ timestamp: { value: Date.now() },
864
+ pid: { value: '123456' },
865
+ },
866
+ };
867
+ return;
868
+ }
869
+ });
870
+ ```
804
871
 
805
872
  ### withBuildIn 插件
806
873
 
package/README.md CHANGED
@@ -22,7 +22,7 @@ yarn add @ray-js/t-agent @ray-js/t-agent-plugin-aistream @ray-js/t-agent-ui-ray
22
22
  "DeviceKit": "4.6.1",
23
23
  "HomeKit": "3.4.0",
24
24
  "MiniKit": "3.12.1",
25
- "AIStreamKit": "1.0.0"
25
+ "AIStreamKit": "1.3.2"
26
26
  },
27
27
  "baseversion": "2.21.10"
28
28
  }
@@ -766,6 +766,7 @@ Parameters:
766
766
  - `indexId` Index ID, defaults to 'default'
767
767
  - `homeId` Home ID, defaults to current home if not provided
768
768
  - `earlyStart` Whether to establish connection during onAgentStart phase
769
+ - `eventIdPrefix` Event ID prefix for cloud debugging and log tracing
769
770
  - `tokenOptions` Parameters for getting agent token
770
771
  - `api` API interface name
771
772
  - `version` Interface version
@@ -774,14 +775,30 @@ Parameters:
774
775
 
775
776
  Methods:
776
777
 
777
- - `agent.plugins.aiStream.send`: Send a message to the agent
778
- - `agent.plugins.aiStream.chat`: Send a message to the agent while generating a ChatMessage object for the question and the AI's answer, updating in a streaming manner
778
+ - `agent.plugins.aiStream.send(blocks, signal, userData)` Send a message to the agent
779
+ - `blocks` Input block array
780
+ - `signal` Optional AbortSignal for interrupting requests
781
+ - `userData` Optional user data to be included with the message
782
+ - `agent.plugins.aiStream.chat(blocks, signal, options)` Send a message to the agent while generating a ChatMessage object for the question and the AI's answer, updating in a streaming manner
783
+ - `blocks` Input block array
784
+ - `signal` Optional AbortSignal
785
+ - `options.sendBy` Sender role, defaults to 'user'
786
+ - `options.responseBy` Responder role, defaults to 'assistant'
787
+ - `options.userData` Optional user data
788
+ - `agent.plugins.aiStream.getChatId()` Get the current session's chatId, returns Promise<string>
779
789
 
780
790
  Hooks:
781
791
 
782
792
  - `onMessageParse` Triggered when reading history messages and parsing them, allowing for message modification in this Hook
783
793
  - `msgItem` Stored message object
784
794
  - `result.messages` Parsed message list
795
+ - `onChatMessageSent` Triggered after user message and response message are created
796
+ - `userMessage` User's sent message
797
+ - `respMessage` AI's response message
798
+ - `onTextCompose` Triggered when receiving text data, used for handling text rendering
799
+ - `respMsg` Response message
800
+ - `status` Message status
801
+ - `result.text` Text content, can be modified
785
802
  - `onSkillCompose` Triggered when receiving skill data, used for handling skill rendering
786
803
  - `skill` Skill data array (ReceivedTextSkillPacketBody[])
787
804
  - `respMsg` Response message
@@ -796,6 +813,47 @@ Hooks:
796
813
  - `onCardsReceived` Triggered when receiving card data
797
814
  - `skills` Skill data list (ReceivedTextSkillPacketBody[])
798
815
  - `result.cards` Card list
816
+ - `onUserDataRead` **(0.2.x New)** Triggered when user custom data needs to be read, used to pass additional context information to the AI platform
817
+ - `type` Trigger type, can be 'create-session' or 'start-event'
818
+ - `'create-session'` Triggered when creating a session, only once
819
+ - `'start-event'` Triggered each time a message is sent
820
+ - `data` Context data
821
+ - `data.blocks` When type is 'start-event', contains the input blocks for this send
822
+ - `result.userData` Returned user data object, will be merged and sent to the AI platform
823
+
824
+ **Usage Example**:
825
+
826
+ ```tsx
827
+ const agent = createChatAgent(
828
+ withUI(),
829
+ withAIStream({
830
+ agentId: 'your-agent-id',
831
+ })
832
+ );
833
+
834
+ agent.plugins.aiStream.onUserDataRead((type, data, result) => {
835
+ // Pass user information when creating a session
836
+ if (type === 'create-session') {
837
+ result.sessionAttributes = {
838
+ 'custom.param': {
839
+ userName: { value: 'John' },
840
+ userLevel: { value: 'Plus' },
841
+ },
842
+ };
843
+ return;
844
+ }
845
+ // Pass dynamic context each time a message is sent
846
+ if (type === 'start-event') {
847
+ result.userData = {
848
+ 'custom.param': {
849
+ timestamp: { value: Date.now() },
850
+ pid: { value: '123456' },
851
+ },
852
+ };
853
+ return;
854
+ }
855
+ });
856
+ ```
799
857
 
800
858
  ### withBuildIn Plugin
801
859
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent",
3
- "version": "0.2.7-beta.1",
3
+ "version": "0.2.7-beta.3",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -26,5 +26,5 @@
26
26
  "build": "ray build --type=component --output dist",
27
27
  "clean": "rimraf ./dist"
28
28
  },
29
- "gitHead": "d7754f9879a7ec837eb343ac759a08734cc789d3"
29
+ "gitHead": "44d1d2ecb71857a1337c20137fe39d25384fdcdb"
30
30
  }