@ray-js/t-agent 0.2.5-beta-1 → 0.2.5-beta-2
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 +562 -305
- package/README.md +570 -269
- package/package.json +2 -2
package/README-zh_CN.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# AI 智能体 SDK
|
|
2
2
|
|
|
3
|
+
## 版本说明
|
|
4
|
+
|
|
5
|
+
**⚠️ 重要提示**:从 0.2.x 版本开始,`@ray-js/t-agent-plugin-assistant` 已被废弃,请使用 `@ray-js/t-agent-plugin-aistream` 替代。
|
|
6
|
+
|
|
3
7
|
## 安装(ray 小程序)
|
|
4
8
|
|
|
5
9
|
```shell
|
|
6
|
-
yarn add @ray-js/t-agent @ray-js/t-agent-plugin-
|
|
10
|
+
yarn add @ray-js/t-agent @ray-js/t-agent-plugin-aistream @ray-js/t-agent-ui-ray
|
|
7
11
|
```
|
|
8
12
|
|
|
9
|
-
> 确保 `@ray-js/t-agent` `@ray-js/t-agent-plugin-
|
|
13
|
+
> 确保 `@ray-js/t-agent` `@ray-js/t-agent-plugin-aistream` `@ray-js/t-agent-ui-ray` 版本一致
|
|
10
14
|
|
|
11
15
|
## 小程序 kit 要求
|
|
12
16
|
|
|
@@ -17,7 +21,8 @@ yarn add @ray-js/t-agent @ray-js/t-agent-plugin-assistant @ray-js/t-agent-ui-ray
|
|
|
17
21
|
"BizKit": "4.10.0",
|
|
18
22
|
"DeviceKit": "4.6.1",
|
|
19
23
|
"HomeKit": "3.4.0",
|
|
20
|
-
"MiniKit": "3.12.1"
|
|
24
|
+
"MiniKit": "3.12.1",
|
|
25
|
+
"AIStreamKit": "1.0.0"
|
|
21
26
|
},
|
|
22
27
|
"baseversion": "2.21.10"
|
|
23
28
|
}
|
|
@@ -54,48 +59,54 @@ yarn run miniapp
|
|
|
54
59
|
import React from 'react';
|
|
55
60
|
import { View } from '@ray-js/components';
|
|
56
61
|
import { createChatAgent, withDebug, withUI } from '@ray-js/t-agent';
|
|
57
|
-
import { ChatContainer, MessageInput, MessageList } from '@ray-js/t-agent-ui-ray';
|
|
58
|
-
import {
|
|
62
|
+
import { ChatContainer, MessageInput, MessageList, MessageActionBar } from '@ray-js/t-agent-ui-ray';
|
|
63
|
+
import { withAIStream, withBuildIn } from '@ray-js/t-agent-plugin-aistream';
|
|
59
64
|
|
|
60
65
|
const createAgent = () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
66
|
+
try {
|
|
67
|
+
// 应用插件是有顺序的
|
|
68
|
+
const agent = createChatAgent(
|
|
69
|
+
withUI(), // 第一个插件 withUI 插件提供了一些默认的 UI 行为,必选
|
|
70
|
+
withAIStream({
|
|
71
|
+
// withAIStream 插件对接小程序 AI 智能体平台,在小程序中必选
|
|
72
|
+
enableTts: false, // 是否开启语音合成
|
|
73
|
+
earlyStart: true, // 是否在 onAgentStart 阶段就建立连接
|
|
74
|
+
agentId: '', // 输入你的智能体ID
|
|
75
|
+
}),
|
|
76
|
+
withDebug(), // withDebug 会在 console 里打印日志
|
|
77
|
+
withBuildIn() // withBuildIn 插件提供了一些内置的功能
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// 将生命周期钩子拿出来,方便注册自定义行为
|
|
81
|
+
const { onChatStart, createMessage, onChatResume, onError, onInputBlocksPush, session } = agent;
|
|
82
|
+
|
|
83
|
+
// 初始化聊天时,发送一条消息
|
|
84
|
+
onChatStart(async result => {
|
|
85
|
+
const hello = createMessage({
|
|
86
|
+
role: 'assistant',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
hello.bubble.setText('Hello, world!');
|
|
90
|
+
result.messages.push(hello);
|
|
91
|
+
// 持久化消息,下次进入时会展示
|
|
92
|
+
await hello.persist();
|
|
80
93
|
});
|
|
81
94
|
|
|
82
|
-
|
|
83
|
-
result
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
// 恢复聊天时,发送一条消息
|
|
96
|
+
onChatResume(async result => {
|
|
97
|
+
const welcomeBack = createMessage({
|
|
98
|
+
role: 'assistant',
|
|
99
|
+
});
|
|
87
100
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
role: 'assistant',
|
|
101
|
+
welcomeBack.bubble.setText('Welcome back');
|
|
102
|
+
result.messages.push(welcomeBack);
|
|
103
|
+
await welcomeBack.persist();
|
|
92
104
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
return agent;
|
|
105
|
+
return agent;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Agent creation failed:', error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
99
110
|
};
|
|
100
111
|
|
|
101
112
|
export default function ChatPage() {
|
|
@@ -104,6 +115,7 @@ export default function ChatPage() {
|
|
|
104
115
|
<ChatContainer createAgent={createAgent}>
|
|
105
116
|
<MessageList />
|
|
106
117
|
<MessageInput />
|
|
118
|
+
<MessageActionBar />
|
|
107
119
|
</ChatContainer>
|
|
108
120
|
</View>
|
|
109
121
|
);
|
|
@@ -169,6 +181,14 @@ const createAgent = () => {
|
|
|
169
181
|
};
|
|
170
182
|
```
|
|
171
183
|
|
|
184
|
+
#### Hook 执行顺序
|
|
185
|
+
|
|
186
|
+
Hook 按照以下顺序执行:
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
onAgentStart → onChatStart/onChatResume → onMessageListInit → onInputBlocksPush
|
|
190
|
+
```
|
|
191
|
+
|
|
172
192
|
ChatAgent 主要 Hook 和参数:
|
|
173
193
|
|
|
174
194
|
- `agent.onAgentStart` 初始化 Agent
|
|
@@ -584,6 +604,58 @@ ui 插件的主要事件如下,你还可以自由地注册需要的事件:
|
|
|
584
604
|
- `payload.value: any`: 会话数据 value
|
|
585
605
|
- `payload.oldValue: any`: 会话数据旧值
|
|
586
606
|
|
|
607
|
+
UI 插件增强功能(0.2.x 新增):
|
|
608
|
+
|
|
609
|
+
withUI 插件在 0.2.x 版本中新增了 Hook 机制,可以让开发者自定义消息反馈和历史清理的行为:
|
|
610
|
+
|
|
611
|
+
**消息反馈 Hook**:
|
|
612
|
+
|
|
613
|
+
- `agent.plugins.ui.hook('onMessageFeedback', async context => {})` 注册消息反馈 Hook
|
|
614
|
+
- `context.payload.messageId: string` 消息 ID
|
|
615
|
+
- `context.payload.rate: 'like' | 'unlike'` 反馈类型
|
|
616
|
+
- `context.payload.content?: string` 反馈内容(可选)
|
|
617
|
+
- `context.result: { success: boolean }` 返回结果,需要设置是否成功
|
|
618
|
+
|
|
619
|
+
**清空历史 Hook**:
|
|
620
|
+
|
|
621
|
+
- `agent.plugins.ui.hook('onClearHistory', async context => {})` 注册清空历史 Hook
|
|
622
|
+
- `context.payload: any` 清空历史的参数
|
|
623
|
+
- `context.result: { success: boolean }` 返回结果,需要设置是否成功
|
|
624
|
+
|
|
625
|
+
**调用 Hook**:
|
|
626
|
+
|
|
627
|
+
- `agent.plugins.ui.callHook('onMessageFeedback', payload)` 调用消息反馈 Hook
|
|
628
|
+
- `agent.plugins.ui.callHook('onClearHistory', payload)` 调用清空历史 Hook
|
|
629
|
+
|
|
630
|
+
使用示例:
|
|
631
|
+
|
|
632
|
+
```tsx
|
|
633
|
+
const agent = createChatAgent(withUI(), withAIStream({ agentId: 'your-agent-id' }));
|
|
634
|
+
|
|
635
|
+
// 注册消息反馈处理
|
|
636
|
+
agent.plugins.ui.hook('onMessageFeedback', async context => {
|
|
637
|
+
const { messageId, rate, content } = context.payload;
|
|
638
|
+
try {
|
|
639
|
+
// 调用你的 API 提交反馈
|
|
640
|
+
await submitFeedback({ messageId, rate, content });
|
|
641
|
+
context.result = { success: true };
|
|
642
|
+
} catch (error) {
|
|
643
|
+
context.result = { success: false };
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
// 注册清空历史处理
|
|
648
|
+
agent.plugins.ui.hook('onClearHistory', async context => {
|
|
649
|
+
try {
|
|
650
|
+
// 调用你的 API 清空历史
|
|
651
|
+
await clearChatHistory();
|
|
652
|
+
context.result = { success: true };
|
|
653
|
+
} catch (error) {
|
|
654
|
+
context.result = { success: false };
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
```
|
|
658
|
+
|
|
587
659
|
> 注意,这里的 ChatMessageObject 是一个消息对象,不是 ChatMessage 类型,
|
|
588
660
|
> 它包含了消息的一些属性和方法,这是为了避免在 UI 层修改消息对象,导致 ChatAgent 中的消息对象不一致。
|
|
589
661
|
> 对消息对象的修改应该始终在 ChatAgent 中进行。
|
|
@@ -655,28 +727,28 @@ const obj = safeParseJSON<{ a: number }>('{"a": 1}');
|
|
|
655
727
|
console.log(obj.a); // 1
|
|
656
728
|
```
|
|
657
729
|
|
|
658
|
-
# t-agent-plugin-
|
|
730
|
+
# t-agent-plugin-aistream
|
|
659
731
|
|
|
660
|
-
t-agent-plugin-
|
|
732
|
+
t-agent-plugin-aistream 是一个对接小程序 AI 智能体平台的插件,提供了对接小程序 AI 智能体平台的能力。
|
|
661
733
|
|
|
662
734
|
## 安装
|
|
663
735
|
|
|
664
736
|
```shell
|
|
665
|
-
yarn add @ray-js/t-agent-plugin-
|
|
737
|
+
yarn add @ray-js/t-agent-plugin-aistream
|
|
666
738
|
```
|
|
667
739
|
|
|
668
740
|
## 使用
|
|
669
741
|
|
|
670
742
|
```tsx
|
|
671
743
|
import { createChatAgent, withUI } from '@ray-js/t-agent';
|
|
672
|
-
import {
|
|
744
|
+
import { withAIStream, withBuildIn } from '@ray-js/t-agent-plugin-aistream';
|
|
673
745
|
|
|
674
746
|
const createAgent = () => {
|
|
675
747
|
const agent = createChatAgent(
|
|
676
748
|
withUI(), // 一般都需要应用 withUI 插件
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
749
|
+
withAIStream({
|
|
750
|
+
agentId: 'your-agent-id', // 输入你的智能体ID
|
|
751
|
+
enableTts: false, // 是否开启语音合成,默认为 false
|
|
680
752
|
}),
|
|
681
753
|
withBuildIn()
|
|
682
754
|
);
|
|
@@ -687,110 +759,96 @@ const createAgent = () => {
|
|
|
687
759
|
|
|
688
760
|
## 包含的插件
|
|
689
761
|
|
|
690
|
-
###
|
|
762
|
+
### withAIStream 插件
|
|
691
763
|
|
|
692
764
|
提供了对接小程序 AI 智能体平台的能力
|
|
693
765
|
|
|
694
766
|
参数:
|
|
695
767
|
|
|
696
|
-
- `
|
|
697
|
-
- `
|
|
698
|
-
- `
|
|
699
|
-
- `
|
|
768
|
+
- `agentId` 智能体 ID(必填)
|
|
769
|
+
- `clientType` 客户端类型,默认为 APP (2)
|
|
770
|
+
- `deviceId` 设备 ID,当 clientType 为 DEVICE (1) 时必填
|
|
771
|
+
- `enableTts` 是否开启语音合成,默认为 false
|
|
772
|
+
- `wireInput` 是否将输入块传递给智能体,默认为 true,设置为 false 时,需要你自己编写 onInputBlocksPush Hook 来处理输入块
|
|
773
|
+
- `historySize` 历史消息大小,默认为 1000
|
|
774
|
+
- `indexId` 索引 ID,默认为 'default'
|
|
775
|
+
- `homeId` 家庭 ID,不填默认当前家庭
|
|
776
|
+
- `earlyStart` 是否在 onAgentStart 阶段就建立连接
|
|
777
|
+
- `tokenOptions` 获取 agent token 的参数
|
|
778
|
+
- `api` API 接口名
|
|
779
|
+
- `version` 接口版本
|
|
780
|
+
- `extParams` 额外参数
|
|
781
|
+
- `createChatHistoryStore` 自定义消息存储函数
|
|
700
782
|
|
|
701
783
|
方法:
|
|
702
784
|
|
|
703
|
-
- `agent.plugins.
|
|
704
|
-
- `agent.plugins.
|
|
785
|
+
- `agent.plugins.aiStream.send` 向智能体发送一条消息
|
|
786
|
+
- `agent.plugins.aiStream.chat` 向智能体发送一条消息,并生成提问 ChatMessage 对象和 AI 回答 ChatMessage 对象,流式更新
|
|
705
787
|
|
|
706
788
|
Hooks:
|
|
707
789
|
|
|
708
|
-
- `
|
|
709
|
-
- `
|
|
710
|
-
- `
|
|
711
|
-
|
|
712
|
-
- `
|
|
713
|
-
- `
|
|
714
|
-
- `
|
|
790
|
+
- `onMessageParse` 当读取历史消息,解析消息时触发,可以在这个 Hook 里修改消息
|
|
791
|
+
- `msgItem` 存储的消息对象
|
|
792
|
+
- `result.messages` 解析后的消息列表
|
|
793
|
+
- `onSkillCompose` 当收到技能数据时触发,用于处理技能的渲染
|
|
794
|
+
- `skill` 技能数据数组 (ReceivedTextSkillPacketBody[])
|
|
795
|
+
- `respMsg` 响应消息
|
|
796
|
+
- `result.messages` 消息列表
|
|
797
|
+
- `onSkillsEnd` 当所有技能处理完成时触发
|
|
798
|
+
- `skills` 技能数据列表 (ReceivedTextSkillPacketBody[])
|
|
799
|
+
- `respMsg` 响应消息
|
|
715
800
|
- `result.messages` 消息列表
|
|
716
801
|
- `onTTTAction` tile 使用 `sendAction` 时触发
|
|
717
802
|
- `tile` 触发的 tile
|
|
718
|
-
- `action` TTTAction
|
|
719
|
-
- `onCardsReceived`
|
|
720
|
-
- `
|
|
803
|
+
- `result.action` TTTAction,可以修改要执行的动作
|
|
804
|
+
- `onCardsReceived` 当收到卡片数据时触发
|
|
805
|
+
- `skills` 技能数据列表 (ReceivedTextSkillPacketBody[])
|
|
721
806
|
- `result.cards` 卡片列表
|
|
722
807
|
|
|
723
808
|
### withBuildIn 插件
|
|
724
809
|
|
|
725
|
-
|
|
810
|
+
提供了一些内置的功能,比如智能家居、知识库搜索等。
|
|
726
811
|
|
|
727
|
-
|
|
812
|
+
**支持的技能**:
|
|
728
813
|
|
|
729
|
-
|
|
814
|
+
- **智能家居**:设备控制、场景管理
|
|
815
|
+
- **知识库搜索**:关联文档展示
|
|
730
816
|
|
|
731
817
|
## mock 机制
|
|
732
818
|
|
|
733
819
|
为了方便开发,我们提供了一个 mock 机制,可以在开发时不用连接小程序 AI 智能体平台,直接使用 mock 数据进行开发。
|
|
734
820
|
|
|
735
|
-
### mock
|
|
736
|
-
|
|
737
|
-
```tsx
|
|
738
|
-
import { mock } from '@ray-js/t-agent-plugin-assistant';
|
|
739
|
-
|
|
740
|
-
// mock 获取历史数据接口
|
|
741
|
-
mock.hooks.hook('getAIAssistantGroupHistory', context => {
|
|
742
|
-
context.result = yourMockData;
|
|
743
|
-
});
|
|
744
|
-
```
|
|
745
|
-
|
|
746
|
-
### mock AI 助手响应
|
|
821
|
+
### mock AI Stream 响应
|
|
747
822
|
|
|
748
823
|
```tsx
|
|
749
|
-
import { mock } from '@ray-js/t-agent-plugin-
|
|
824
|
+
import { mock } from '@ray-js/t-agent-plugin-aistream';
|
|
750
825
|
|
|
751
|
-
mock.hooks.hook('
|
|
752
|
-
if (context.options.block?.includes('hello')) {
|
|
826
|
+
mock.hooks.hook('sendToAIStream', context => {
|
|
827
|
+
if (context.options.blocks?.some(block => block.text?.includes('hello'))) {
|
|
753
828
|
context.responseText = 'hello, who are you?';
|
|
754
829
|
}
|
|
755
830
|
|
|
756
|
-
if (context.options.block?.includes('
|
|
757
|
-
context.responseText = '
|
|
758
|
-
context.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
if (context.options.block?.includes('工作流')) {
|
|
775
|
-
context.responseText = '这是工作流';
|
|
776
|
-
context.responseExtensions = {
|
|
777
|
-
workflowAskOptions: {
|
|
778
|
-
options: [
|
|
779
|
-
{
|
|
780
|
-
name: '选项 1',
|
|
781
|
-
value: '选项 1',
|
|
831
|
+
if (context.options.blocks?.some(block => block.text?.includes('智能家居'))) {
|
|
832
|
+
context.responseText = '正在为您控制智能设备...';
|
|
833
|
+
context.responseSkills = [
|
|
834
|
+
{
|
|
835
|
+
code: 'smart_home',
|
|
836
|
+
general: {
|
|
837
|
+
action: 'control_device',
|
|
838
|
+
data: {
|
|
839
|
+
devices: [
|
|
840
|
+
{
|
|
841
|
+
deviceId: 'vdevo174796589841019',
|
|
842
|
+
icon: '',
|
|
843
|
+
dps: { range: '0', toggle: 'ON' },
|
|
844
|
+
name: '毛巾架',
|
|
845
|
+
},
|
|
846
|
+
],
|
|
782
847
|
},
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
value: '选项 2',
|
|
786
|
-
},
|
|
787
|
-
{
|
|
788
|
-
name: '选项 3',
|
|
789
|
-
value: '选项 3',
|
|
790
|
-
},
|
|
791
|
-
],
|
|
848
|
+
},
|
|
849
|
+
custom: {},
|
|
792
850
|
},
|
|
793
|
-
|
|
851
|
+
];
|
|
794
852
|
}
|
|
795
853
|
});
|
|
796
854
|
```
|
|
@@ -798,7 +856,7 @@ mock.hooks.hook('sendToAssistant', context => {
|
|
|
798
856
|
### mock ASR 语音识别
|
|
799
857
|
|
|
800
858
|
```tsx
|
|
801
|
-
import { mock } from '@ray-js/t-agent-plugin-
|
|
859
|
+
import { mock } from '@ray-js/t-agent-plugin-aistream';
|
|
802
860
|
|
|
803
861
|
mock.hooks.hook('asrDetection', context => {
|
|
804
862
|
context.responseText = 'Hello world!, I am a virtual assistant.';
|
|
@@ -821,45 +879,43 @@ mock.hooks.hook('asrDetection', context => {
|
|
|
821
879
|
- `sendMessage` 发送一条消息
|
|
822
880
|
- `buildIn` 内置行动
|
|
823
881
|
|
|
824
|
-
###
|
|
882
|
+
### AsrAgent
|
|
825
883
|
|
|
826
|
-
ASR
|
|
884
|
+
ASR 语音识别代理,用于识别用户的语音输入
|
|
827
885
|
|
|
828
886
|
使用方法:
|
|
829
887
|
|
|
830
888
|
```tsx
|
|
831
|
-
import {
|
|
889
|
+
import { createAsrAgent } from '@ray-js/t-agent-plugin-aistream';
|
|
832
890
|
|
|
833
891
|
async function startAsr() {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
//
|
|
853
|
-
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
if (res.state === AsrDetectResultState.ERROR) {
|
|
857
|
-
onError(new AsrError(res.errorCode));
|
|
858
|
-
}
|
|
892
|
+
const asrAgent = createAsrAgent({
|
|
893
|
+
agentId: 'your-agent-id',
|
|
894
|
+
onMessage: message => {
|
|
895
|
+
if (message.type === 'text') {
|
|
896
|
+
console.log('识别结果:', message.text);
|
|
897
|
+
} else if (message.type === 'file') {
|
|
898
|
+
console.log('音频文件:', message.file);
|
|
899
|
+
}
|
|
900
|
+
},
|
|
901
|
+
onFinish: () => {
|
|
902
|
+
console.log('识别完成');
|
|
903
|
+
},
|
|
904
|
+
onError: error => {
|
|
905
|
+
console.error('识别出错:', error);
|
|
906
|
+
},
|
|
907
|
+
recordingOptions: {
|
|
908
|
+
saveFile: false,
|
|
909
|
+
sampleRate: 16000,
|
|
910
|
+
maxDuration: 60000, // 最长60秒
|
|
911
|
+
},
|
|
859
912
|
});
|
|
860
913
|
|
|
861
914
|
// 开始识别
|
|
862
|
-
await
|
|
915
|
+
await asrAgent.start();
|
|
916
|
+
|
|
917
|
+
// 结束识别
|
|
918
|
+
await asrAgent.stop();
|
|
863
919
|
}
|
|
864
920
|
```
|
|
865
921
|
|
|
@@ -870,7 +926,7 @@ async function startAsr() {
|
|
|
870
926
|
使用方法:
|
|
871
927
|
|
|
872
928
|
```tsx
|
|
873
|
-
import { promisify } from '@ray-js/t-agent-plugin-
|
|
929
|
+
import { promisify } from '@ray-js/t-agent-plugin-aistream';
|
|
874
930
|
|
|
875
931
|
interface RouterParams {
|
|
876
932
|
/** 路由链接 */
|
|
@@ -897,94 +953,63 @@ mock.hooks.hook('router', context => {
|
|
|
897
953
|
await router({ url: '/pages/index/index' });
|
|
898
954
|
```
|
|
899
955
|
|
|
900
|
-
###
|
|
956
|
+
### sendBlocksToAIStream
|
|
901
957
|
|
|
902
|
-
|
|
958
|
+
**注意:此函数仅供内部使用,一般开发者不需要直接调用**
|
|
903
959
|
|
|
904
|
-
|
|
905
|
-
import { sendBlockToAssistant, getAIAssistantRequestId } from '@ray-js/t-agent-ui-ray';
|
|
960
|
+
给 AIStream 发送消息块,这是一个底层函数,通常应该使用 `agent.plugins.aiStream.send` 或 `agent.plugins.aiStream.chat` 方法。
|
|
906
961
|
|
|
907
|
-
|
|
908
|
-
const requestId = await getAIAssistantRequestId();
|
|
909
|
-
const result = sendBlockToAssistant({
|
|
910
|
-
channel: 'your-channel-id',
|
|
911
|
-
sessionId: 'your-session-id',
|
|
912
|
-
requestId,
|
|
913
|
-
blocks: [{ type: 'text', text: 'hello' }],
|
|
914
|
-
});
|
|
962
|
+
#### 适用场景
|
|
915
963
|
|
|
916
|
-
|
|
917
|
-
|
|
964
|
+
- ✅ **适用**:需要直接控制流式响应的处理时
|
|
965
|
+
- ✅ **适用**:实现自定义的消息发送逻辑
|
|
966
|
+
- ❌ **不适用**:一般的对话场景,应使用 `agent.plugins.aiStream.chat`
|
|
967
|
+
- ❌ **不适用**:简单的消息发送,应使用 `agent.plugins.aiStream.send`
|
|
918
968
|
|
|
919
|
-
|
|
920
|
-
const parts = result.parts();
|
|
921
|
-
|
|
922
|
-
for await (const part of parts) {
|
|
923
|
-
console.log('part', part);
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
```
|
|
927
|
-
|
|
928
|
-
### sendSkillToAssistant
|
|
929
|
-
|
|
930
|
-
给 Assistant 发送技能
|
|
969
|
+
#### 函数签名
|
|
931
970
|
|
|
932
971
|
```tsx
|
|
933
|
-
import {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
},
|
|
943
|
-
});
|
|
944
|
-
|
|
945
|
-
// 获取发送后的元数据
|
|
946
|
-
const meta = await result.metaPromise;
|
|
947
|
-
|
|
948
|
-
// 获取流式消息
|
|
949
|
-
const parts = result.parts();
|
|
972
|
+
import { sendBlocksToAIStream } from '@ray-js/t-agent-plugin-aistream';
|
|
973
|
+
|
|
974
|
+
export interface SendBlocksToAIStreamParams {
|
|
975
|
+
blocks: InputBlock[];
|
|
976
|
+
session: AIStreamSession;
|
|
977
|
+
attribute?: AIStreamChatAttribute;
|
|
978
|
+
signal?: AbortSignal;
|
|
979
|
+
enableTts?: boolean;
|
|
980
|
+
}
|
|
950
981
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
982
|
+
export function sendBlocksToAIStream(params: SendBlocksToAIStreamParams): {
|
|
983
|
+
response: StreamResponse;
|
|
984
|
+
metaPromise: Promise<Record<string, any>>;
|
|
954
985
|
};
|
|
955
986
|
```
|
|
956
987
|
|
|
957
|
-
|
|
988
|
+
#### 使用示例
|
|
958
989
|
|
|
959
|
-
|
|
990
|
+
```tsx
|
|
991
|
+
const send = async () => {
|
|
992
|
+
try {
|
|
993
|
+
// 需要先获取 AIStreamSession 对象
|
|
994
|
+
const streamSession = agent.session.get('AIStream.streamSession');
|
|
960
995
|
|
|
961
|
-
|
|
996
|
+
const result = sendBlocksToAIStream({
|
|
997
|
+
blocks: [{ type: 'text', text: 'hello' }],
|
|
998
|
+
session: streamSession,
|
|
999
|
+
signal: new AbortController().signal,
|
|
1000
|
+
});
|
|
962
1001
|
|
|
963
|
-
|
|
964
|
-
|
|
1002
|
+
// 获取发送后的元数据
|
|
1003
|
+
const meta = await result.metaPromise;
|
|
965
1004
|
|
|
966
|
-
//
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (result) {
|
|
972
|
-
// 已经同意过,或者点了同意按钮
|
|
973
|
-
console.log('用户同意了 AI 隐私协议');
|
|
974
|
-
} else {
|
|
975
|
-
ty.exitMiniProgram({});
|
|
976
|
-
console.log('用户拒绝了 AI 隐私协议');
|
|
1005
|
+
// 获取流式消息
|
|
1006
|
+
const parts = result.response.parts();
|
|
1007
|
+
for await (const part of parts) {
|
|
1008
|
+
console.log('part', part);
|
|
977
1009
|
}
|
|
978
|
-
} catch (
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
title: I18n.t('get_sign_error'),
|
|
982
|
-
icon: 'error',
|
|
983
|
-
});
|
|
984
|
-
// 延迟触发,等待用户看清
|
|
985
|
-
setTimeout(() => {
|
|
986
|
-
ty.exitMiniProgram({});
|
|
987
|
-
}, 1000);
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
console.error('Send message failed:', error);
|
|
1012
|
+
// 错误处理逻辑
|
|
988
1013
|
}
|
|
989
1014
|
};
|
|
990
1015
|
```
|
|
@@ -1038,7 +1063,7 @@ import { ChatContainer, MessageList, MessageInput } from '@ray-js/t-agent-ui-ray
|
|
|
1038
1063
|
import { createAgent } from './createAgent';
|
|
1039
1064
|
|
|
1040
1065
|
export default function ChatPage() {
|
|
1041
|
-
// createAgent 必须返回一个 ChatAgent 应用过 withUI、
|
|
1066
|
+
// createAgent 必须返回一个 ChatAgent 应用过 withUI、withAIStream 插件的实例
|
|
1042
1067
|
return (
|
|
1043
1068
|
<View style={{ height: '100vh' }}>
|
|
1044
1069
|
<ChatContainer createAgent={createAgent}>
|
|
@@ -1066,18 +1091,34 @@ props:
|
|
|
1066
1091
|
- `customBlockTypes` 自定义 block 类型,只有在这里注册的 block 类型才会被 `renderCustomBlockAs` 渲染
|
|
1067
1092
|
- `renderCustomBlockAs` 该函数决定如何在 markdown 气泡消息中渲染自定义 block,默认支持 `echarts`
|
|
1068
1093
|
- `renderCardAs` 该函数决定如何在消息中渲染卡片,一般不需要自定义此项
|
|
1094
|
+
- `renderLongPressAs` **(0.2.x 新增)** 该函数决定如何渲染长按菜单,可以自定义长按菜单的样式和行为
|
|
1095
|
+
- `formatErrorMessageAs` **(0.2.x 新增)** 该函数决定如何格式化错误消息,可以根据错误代码返回用户友好的错误信息
|
|
1069
1096
|
- `customCardMap` 自定义卡片映射,无需修改 `renderCardAs` 函数,只需要在这里注册卡片类型和对应的组件
|
|
1070
1097
|
- `getStaticResourceBizType` 获取静态资源 `bizType`,用于获取静态资源
|
|
1071
1098
|
|
|
1072
1099
|
### MessageList
|
|
1073
1100
|
|
|
1074
|
-
|
|
1101
|
+
消息列表,用于展示消息。在 0.2.x 版本中集成了 LazyScrollView 组件,提供了更好的性能优化。
|
|
1075
1102
|
|
|
1076
|
-
|
|
1103
|
+
**Props**:
|
|
1077
1104
|
|
|
1078
1105
|
- `className` 列表的类名
|
|
1079
1106
|
- `roleSide` 消息角色的对齐方式,默认 `{ user: 'end', assistant: 'start' }`
|
|
1080
1107
|
|
|
1108
|
+
**LazyScrollView 集成(0.2.x 新增)**:
|
|
1109
|
+
|
|
1110
|
+
MessageList 内部使用了 LazyScrollView 组件来优化大量消息的渲染性能:
|
|
1111
|
+
|
|
1112
|
+
- **懒加载渲染**:只渲染可见区域内的消息,大幅提升性能
|
|
1113
|
+
- **高度自适应**:自动计算消息高度,支持动态内容
|
|
1114
|
+
- **notifyHeightChanged()**:当消息内容发生变化时,自动通知高度更新
|
|
1115
|
+
|
|
1116
|
+
组件会自动处理以下场景:
|
|
1117
|
+
|
|
1118
|
+
- 保证最下面 10 条消息始终渲染,避免滚动到底部时出现白屏
|
|
1119
|
+
- 消息高度变化时自动更新滚动位置
|
|
1120
|
+
- 支持滚动到底部的动画效果
|
|
1121
|
+
|
|
1081
1122
|
### MessageInput
|
|
1082
1123
|
|
|
1083
1124
|
消息输入框,用于输入消息、上传附件、ASR 语音识别
|
|
@@ -1088,10 +1129,79 @@ props:
|
|
|
1088
1129
|
- `placeholder` 输入框的占位符
|
|
1089
1130
|
- `renderTop` 用于渲染输入框上方的内容
|
|
1090
1131
|
|
|
1132
|
+
### MessageActionBar(0.2.x 新增)
|
|
1133
|
+
|
|
1134
|
+
消息操作栏组件,用于多选消息时显示操作按钮,支持删除选中消息和清空历史记录。
|
|
1135
|
+
|
|
1136
|
+
**Props**:
|
|
1137
|
+
|
|
1138
|
+
无需传入任何 props,组件会自动根据多选状态显示和隐藏
|
|
1139
|
+
|
|
1140
|
+
**功能**:
|
|
1141
|
+
|
|
1142
|
+
- **返回按钮**:退出多选模式
|
|
1143
|
+
- **清空历史按钮**:清空所有历史消息,会调用 `onClearHistory` Hook
|
|
1144
|
+
- **删除选中按钮**:删除当前选中的消息,当没有选中消息时按钮会被禁用
|
|
1145
|
+
|
|
1146
|
+
**工作原理**:
|
|
1147
|
+
|
|
1148
|
+
MessageActionBar 组件会监听会话数据中的 `UIRay.multiSelect.show` 状态来决定是否显示。当用户长按消息选择"多选"时,该组件会自动显示。
|
|
1149
|
+
|
|
1150
|
+
**使用示例**:
|
|
1151
|
+
|
|
1152
|
+
```tsx
|
|
1153
|
+
export default function ChatPage() {
|
|
1154
|
+
return (
|
|
1155
|
+
<View style={{ height: '100vh' }}>
|
|
1156
|
+
<ChatContainer createAgent={createAgent}>
|
|
1157
|
+
<MessageList />
|
|
1158
|
+
<MessageInput />
|
|
1159
|
+
<MessageActionBar />
|
|
1160
|
+
</ChatContainer>
|
|
1161
|
+
</View>
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1091
1166
|
### PrivateImage
|
|
1092
1167
|
|
|
1093
1168
|
私有图片组件,用于展示私有图片,props 同 Image,增加 bizType 参数
|
|
1094
1169
|
|
|
1170
|
+
### LazyScrollView
|
|
1171
|
+
|
|
1172
|
+
懒加载滚动视图组件,用于优化长列表性能,自动管理可见区域的渲染
|
|
1173
|
+
|
|
1174
|
+
主要特性:
|
|
1175
|
+
|
|
1176
|
+
- 虚拟滚动:只渲染可见区域的元素
|
|
1177
|
+
- 高度缓存:自动缓存元素高度,提升滚动性能
|
|
1178
|
+
- 动态加载:根据滚动位置动态显示/隐藏元素
|
|
1179
|
+
- `notifyHeightChanged()` 功能:当元素高度发生变化时,可以调用此方法通知滚动视图更新
|
|
1180
|
+
|
|
1181
|
+
使用说明:
|
|
1182
|
+
|
|
1183
|
+
LazyScrollView 主要在 MessageList 内部使用,开发者一般不需要直接使用。如果需要在消息中动态改变高度,可以通过 `notifyHeightChanged` 参数来通知高度变化:
|
|
1184
|
+
|
|
1185
|
+
```tsx
|
|
1186
|
+
// 在 tile 组件中使用
|
|
1187
|
+
const MyTile = ({ notifyHeightChanged }) => {
|
|
1188
|
+
const [expanded, setExpanded] = useState(false);
|
|
1189
|
+
|
|
1190
|
+
const handleToggle = () => {
|
|
1191
|
+
setExpanded(!expanded);
|
|
1192
|
+
// 通知高度变化
|
|
1193
|
+
notifyHeightChanged();
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
return (
|
|
1197
|
+
<View>
|
|
1198
|
+
<Button onClick={handleToggle}>展开/收起</Button>
|
|
1199
|
+
{expanded && <View>详细内容...</View>}
|
|
1200
|
+
</View>
|
|
1201
|
+
);
|
|
1202
|
+
};
|
|
1203
|
+
```
|
|
1204
|
+
|
|
1095
1205
|
### 内置 tile 组件
|
|
1096
1206
|
|
|
1097
1207
|
- bubble 气泡
|
|
@@ -1189,6 +1299,41 @@ const MyTilePart = () => {
|
|
|
1189
1299
|
};
|
|
1190
1300
|
```
|
|
1191
1301
|
|
|
1302
|
+
### useTranslate
|
|
1303
|
+
|
|
1304
|
+
获取国际化翻译函数,用于翻译界面文本,提供了完整的多语言支持。
|
|
1305
|
+
|
|
1306
|
+
```tsx
|
|
1307
|
+
import { useTranslate } from '@ray-js/t-agent-ui-ray';
|
|
1308
|
+
|
|
1309
|
+
const MyComponent = () => {
|
|
1310
|
+
const t = useTranslate();
|
|
1311
|
+
|
|
1312
|
+
return (
|
|
1313
|
+
<div>
|
|
1314
|
+
{t('t-agent.message.action.copy')} {/* 输出: "复制消息" */}
|
|
1315
|
+
{t('t-agent.message.delete.title')} {/* 输出: "删除消息" */}
|
|
1316
|
+
{t('t-agent.message.clear-history.title')} {/* 输出: "清空历史" */}
|
|
1317
|
+
</div>
|
|
1318
|
+
);
|
|
1319
|
+
};
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
**支持的语言**:
|
|
1323
|
+
|
|
1324
|
+
内置的多语言支持包括:
|
|
1325
|
+
|
|
1326
|
+
- **中文简体** (`zh-Hans`):简体中文
|
|
1327
|
+
- **中文繁体** (`zh-Hant`):繁体中文
|
|
1328
|
+
- **英文** (`en`):英语
|
|
1329
|
+
- **日文** (`ja`):日语
|
|
1330
|
+
- **德文** (`de`):德语
|
|
1331
|
+
- **法文** (`fr`):法语
|
|
1332
|
+
- **西班牙文** (`es`):西班牙语
|
|
1333
|
+
- **意大利文** (`it`):意大利语
|
|
1334
|
+
|
|
1335
|
+
系统会根据用户的系统语言自动选择对应的翻译,如果不支持当前语言则回退到英文。
|
|
1336
|
+
|
|
1192
1337
|
## renderOptions 自定义渲染
|
|
1193
1338
|
|
|
1194
1339
|
### 替换或新增 tile
|
|
@@ -1217,6 +1362,73 @@ const renderOptions = {
|
|
|
1217
1362
|
};
|
|
1218
1363
|
```
|
|
1219
1364
|
|
|
1365
|
+
### 自定义长按菜单(0.2.x 新增)
|
|
1366
|
+
|
|
1367
|
+
如果你需要自定义长按菜单的样式或行为,可以覆写 `renderLongPressAs` 函数,例如:
|
|
1368
|
+
|
|
1369
|
+
```tsx
|
|
1370
|
+
import { defaultRenderOptions, LongPressResult } from '@ray-js/t-agent-ui-ray';
|
|
1371
|
+
import { View, Button } from '@ray-js/ray';
|
|
1372
|
+
|
|
1373
|
+
const renderOptions = {
|
|
1374
|
+
...defaultRenderOptions,
|
|
1375
|
+
renderLongPressAs: (res: LongPressResult) => {
|
|
1376
|
+
if (!res.menuProps.showActionMenu) {
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return (
|
|
1381
|
+
<View className="my-custom-menu">
|
|
1382
|
+
{res.menuProps.menuItems.map(item => (
|
|
1383
|
+
<Button key={item.key} onClick={() => res.menuProps.handleMenuItemClick(item)}>
|
|
1384
|
+
{item.displayLabel}
|
|
1385
|
+
</Button>
|
|
1386
|
+
))}
|
|
1387
|
+
</View>
|
|
1388
|
+
);
|
|
1389
|
+
},
|
|
1390
|
+
};
|
|
1391
|
+
```
|
|
1392
|
+
|
|
1393
|
+
长按菜单功能包括:
|
|
1394
|
+
|
|
1395
|
+
- **复制消息**:复制文本内容到剪贴板
|
|
1396
|
+
- **删除消息**:删除单条消息
|
|
1397
|
+
- **多选**:进入多选模式,配合 MessageActionBar 使用
|
|
1398
|
+
- **喜欢/不喜欢**:对助手消息进行反馈(仅对 assistant 角色消息可用)
|
|
1399
|
+
|
|
1400
|
+
### 自定义错误消息格式化(0.2.x 新增)
|
|
1401
|
+
|
|
1402
|
+
如果你需要自定义错误消息的显示格式,可以覆写 `formatErrorMessageAs` 函数,例如:
|
|
1403
|
+
|
|
1404
|
+
```tsx
|
|
1405
|
+
import { defaultRenderOptions } from '@ray-js/t-agent-ui-ray';
|
|
1406
|
+
|
|
1407
|
+
const renderOptions = {
|
|
1408
|
+
...defaultRenderOptions,
|
|
1409
|
+
formatErrorMessageAs: (message: string, code: string | undefined) => {
|
|
1410
|
+
// 根据错误代码返回自定义的错误消息
|
|
1411
|
+
if (code === 'network-offline') {
|
|
1412
|
+
return '网络连接异常,请检查您的网络设置';
|
|
1413
|
+
}
|
|
1414
|
+
if (code === 'timeout') {
|
|
1415
|
+
return '请求超时,请稍后重试';
|
|
1416
|
+
}
|
|
1417
|
+
// 使用默认的错误消息
|
|
1418
|
+
return message;
|
|
1419
|
+
},
|
|
1420
|
+
};
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
内置支持的错误代码包括:
|
|
1424
|
+
|
|
1425
|
+
- `network-offline`:网络已断开
|
|
1426
|
+
- `timeout`:发送超时
|
|
1427
|
+
- `invalid-params`:无效参数
|
|
1428
|
+
- `session-create-failed`:连接失败
|
|
1429
|
+
- `connection-closed`:连接已关闭
|
|
1430
|
+
- 等等
|
|
1431
|
+
|
|
1220
1432
|
### 自定义卡片
|
|
1221
1433
|
|
|
1222
1434
|
卡片分为三类:内置卡片(buildIn)、自定义卡片(custom)、低代码卡片(lowCode),目前低代码卡片还在开发中,自定义卡片可以通过 `customCardMap` 注册自己的卡片组件。
|
|
@@ -1336,22 +1548,14 @@ Hello, world!
|
|
|
1336
1548
|
console.log('Hello, world!');
|
|
1337
1549
|
```
|
|
1338
1550
|
|
|
1339
|
-
```
|
|
1340
|
-
|
|
1341
1551
|
渲染结果如下:
|
|
1342
1552
|
|
|
1343
|
-
```
|
|
1344
|
-
|
|
1345
1553
|
这是我的自定义 block!
|
|
1346
1554
|
This is My Block
|
|
1347
1555
|
Hello, world!
|
|
1348
1556
|
以下 fence 没有注册过,不会被渲染成自定义 block,仅当做普通的代码块渲染。
|
|
1349
1557
|
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
## | console.log('Hello, world!'); |
|
|
1353
|
-
|
|
1354
|
-
````
|
|
1558
|
+
console.log('Hello, world!');
|
|
1355
1559
|
|
|
1356
1560
|
### getStaticResourceBizType
|
|
1357
1561
|
|
|
@@ -1364,9 +1568,9 @@ const renderOptions = {
|
|
|
1364
1568
|
...defaultRenderOptions,
|
|
1365
1569
|
getStaticResourceBizType: (src: string, scene: string) => 'bizType',
|
|
1366
1570
|
};
|
|
1367
|
-
|
|
1571
|
+
```
|
|
1368
1572
|
|
|
1369
|
-
|
|
1573
|
+
针对不同的场景,你可能需要不同的 `bizType`,你可以根据 `src` 和 `scene` 来返回不同的 `bizType`。
|
|
1370
1574
|
|
|
1371
1575
|
内置的 `scene` 有以下几种:
|
|
1372
1576
|
|
|
@@ -1398,78 +1602,131 @@ const renderOptions = {
|
|
|
1398
1602
|
|
|
1399
1603
|
以下是内置的多语言 key:
|
|
1400
1604
|
|
|
1401
|
-
| key
|
|
1402
|
-
|
|
|
1403
|
-
| t-agent.build-in.button.create_scene_manually
|
|
1404
|
-
| t-agent.build-in.button.enter_home_manage
|
|
1405
|
-
| t-agent.build-in.button.enter_room_manage
|
|
1406
|
-
| t-agent.build-in.button.enter_alarm_message
|
|
1407
|
-
| t-agent.build-in.button.enter_home_message
|
|
1408
|
-
| t-agent.build-in.button.enter_bulletin
|
|
1409
|
-
| t-agent.build-in.button.enter_notification_setting
|
|
1410
|
-
| t-agent.build-in.button.enter_personal_information
|
|
1411
|
-
| t-agent.build-in.button.enter_account_security
|
|
1412
|
-
| t-agent.build-in.button.enter_setting
|
|
1413
|
-
| t-agent.build-in.button.enter_paring
|
|
1414
|
-
| t-agent.build-in.button.enter_share_device
|
|
1415
|
-
| t-agent.build-in.button.enter_faq_feedback
|
|
1416
|
-
| t-agent.build-in.button.questionnaire_take
|
|
1417
|
-
| t-agent.build-in.button.set_home_location
|
|
1418
|
-
| t-agent.input.voice.require-permission
|
|
1419
|
-
| t-agent.input.upload.failed
|
|
1420
|
-
| t-agent.
|
|
1421
|
-
| t-agent.
|
|
1422
|
-
| t-agent.
|
|
1423
|
-
| t-agent.
|
|
1424
|
-
| t-agent.
|
|
1425
|
-
| t-agent.
|
|
1426
|
-
| t-agent.
|
|
1427
|
-
| t-agent.
|
|
1428
|
-
| t-agent.
|
|
1429
|
-
| t-agent.
|
|
1430
|
-
| t-agent.
|
|
1431
|
-
| t-agent.
|
|
1432
|
-
| t-agent.
|
|
1433
|
-
| t-agent.
|
|
1434
|
-
| t-agent.
|
|
1435
|
-
| t-agent.
|
|
1436
|
-
| t-agent.
|
|
1437
|
-
| t-agent.
|
|
1438
|
-
| t-agent.
|
|
1439
|
-
| t-agent.
|
|
1440
|
-
| t-agent.
|
|
1441
|
-
| t-agent.
|
|
1442
|
-
| t-agent.
|
|
1443
|
-
| t-agent.
|
|
1444
|
-
| t-agent.
|
|
1445
|
-
| t-agent.
|
|
1446
|
-
| t-agent.
|
|
1447
|
-
| t-agent.
|
|
1448
|
-
| t-agent.
|
|
1449
|
-
| t-agent.
|
|
1450
|
-
| t-agent.
|
|
1451
|
-
| t-agent.
|
|
1452
|
-
| t-agent.
|
|
1453
|
-
| t-agent.
|
|
1454
|
-
| t-agent.
|
|
1455
|
-
| t-agent.
|
|
1456
|
-
| t-agent.
|
|
1457
|
-
| t-agent.
|
|
1458
|
-
| t-agent.
|
|
1459
|
-
| t-agent.
|
|
1460
|
-
| t-agent.
|
|
1461
|
-
| t-agent.
|
|
1462
|
-
| t-agent.
|
|
1463
|
-
| t-agent.
|
|
1605
|
+
| key | 使用场景 | 含义 |
|
|
1606
|
+
| ---------------------------------------------------------- | --------------------------- | ---------------------------------------- |
|
|
1607
|
+
| t-agent.build-in.button.create_scene_manually | ButtonTile 内置按钮 | 手动创建场景 |
|
|
1608
|
+
| t-agent.build-in.button.enter_home_manage | ButtonTile 内置按钮 | 进入"家庭管理" |
|
|
1609
|
+
| t-agent.build-in.button.enter_room_manage | ButtonTile 内置按钮 | 进入"房间管理" |
|
|
1610
|
+
| t-agent.build-in.button.enter_alarm_message | ButtonTile 内置按钮 | 进入"告警消息列表" |
|
|
1611
|
+
| t-agent.build-in.button.enter_home_message | ButtonTile 内置按钮 | 进入"家庭消息列表" |
|
|
1612
|
+
| t-agent.build-in.button.enter_bulletin | ButtonTile 内置按钮 | 进入"通知消息列表" |
|
|
1613
|
+
| t-agent.build-in.button.enter_notification_setting | ButtonTile 内置按钮 | 进入"消息推送设置" |
|
|
1614
|
+
| t-agent.build-in.button.enter_personal_information | ButtonTile 内置按钮 | 进入"个人资料" |
|
|
1615
|
+
| t-agent.build-in.button.enter_account_security | ButtonTile 内置按钮 | 进入"账号与安全" |
|
|
1616
|
+
| t-agent.build-in.button.enter_setting | ButtonTile 内置按钮 | 进入"通用设置" |
|
|
1617
|
+
| t-agent.build-in.button.enter_paring | ButtonTile 内置按钮 | 进入"设备配网" |
|
|
1618
|
+
| t-agent.build-in.button.enter_share_device | ButtonTile 内置按钮 | 进入"设备分享" |
|
|
1619
|
+
| t-agent.build-in.button.enter_faq_feedback | ButtonTile 内置按钮 | 进入"常见问题与反馈" |
|
|
1620
|
+
| t-agent.build-in.button.questionnaire_take | ButtonTile 内置按钮 | 填写问卷 |
|
|
1621
|
+
| t-agent.build-in.button.set_home_location | ButtonTile 内置按钮 | 设置家庭位置 |
|
|
1622
|
+
| t-agent.input.voice.require-permission | MessageInput 切换语音输入 | 需要授权录音权限 |
|
|
1623
|
+
| t-agent.input.upload.failed | MessageInput 上传文件 | 文件上传失败 |
|
|
1624
|
+
| t-agent.input.asr.oninput.text.top | MessageInput ASR 语音输入 | 我在听,请说话 |
|
|
1625
|
+
| t-agent.input.asr.oninput.text.center | MessageInput ASR 语音输入 | 松开发送,上划取消 |
|
|
1626
|
+
| t-agent.input.asr.ptt | MessageInput ASR 语音输入 | 按住说话 |
|
|
1627
|
+
| t-agent.input.asr.error.too-short | MessageInput ASR 错误 | 说话时间太短 |
|
|
1628
|
+
| t-agent.input.asr.error.empty | MessageInput ASR 错误 | 未能从语音中识别到文字 |
|
|
1629
|
+
| t-agent.input.asr.error.unknown | MessageInput ASR 错误 | 语音识别失败 |
|
|
1630
|
+
| t-agent.input.asr.error.timeout | MessageInput ASR 错误 | 语音识别已达时长限制,将直接发送 |
|
|
1631
|
+
| t-agent.input.upload.source-type.camera | MessageInput 上传文件 | 拍照 |
|
|
1632
|
+
| t-agent.input.upload.source-type.camera.require-permission | MessageInput 上传文件 | 拍照需要摄像头权限,请在设置中开启 |
|
|
1633
|
+
| t-agent.input.upload.source-type.album | MessageInput 上传文件 | 从相册中选择 |
|
|
1634
|
+
| t-agent.input.upload.source-type.album.require-permission | MessageInput 上传文件 | 从相册中选择需要相册权限,请在设置中开启 |
|
|
1635
|
+
| t-agent.input.upload.image.max-reached | MessageInput 上传文件 | 已达到图片上传上限 |
|
|
1636
|
+
| t-agent.input.upload.video.max-reached | MessageInput 上传文件 | 已达到视频上传上限 |
|
|
1637
|
+
| t-agent.file-tile.unknown-filename | FileTile 文件显示 | 文件 |
|
|
1638
|
+
| t-agent.message.feedback.success | BubbleTile 消息评价 | 反馈成功 |
|
|
1639
|
+
| t-agent.message.bubble.aborted | BubbleTile 消息 | 用户中断 |
|
|
1640
|
+
| t-agent.message.action.copy | BubbleTile 长按菜单 | 复制消息 |
|
|
1641
|
+
| t-agent.message.action.delete | BubbleTile 长按菜单 | 删除消息 |
|
|
1642
|
+
| t-agent.message.action.multi-select | BubbleTile 长按菜单 | 多选 |
|
|
1643
|
+
| t-agent.message.action.like | BubbleTile 长按菜单 | 喜欢消息 |
|
|
1644
|
+
| t-agent.message.action.unlike | BubbleTile 长按菜单 | 不喜欢消息 |
|
|
1645
|
+
| t-agent.message.copy.success | BubbleTile 复制成功 | 复制成功 |
|
|
1646
|
+
| t-agent.message.delete.success | BubbleTile 删除成功 | 删除成功 |
|
|
1647
|
+
| t-agent.message.like.success | BubbleTile 反馈 | 点赞成功 |
|
|
1648
|
+
| t-agent.message.unlike.success | BubbleTile 反馈 | 取消点赞成功 |
|
|
1649
|
+
| t-agent.message.delete.title | BubbleTile 删除消息弹窗标题 | 删除消息 |
|
|
1650
|
+
| t-agent.message.delete.content | BubbleTile 删除消息弹窗内容 | 确定要删除这条消息吗? |
|
|
1651
|
+
| t-agent.message.delete.confirm | BubbleTile 删除消息弹窗确认 | 确认 |
|
|
1652
|
+
| t-agent.message.delete.cancel | BubbleTile 删除消息弹窗取消 | 取消 |
|
|
1653
|
+
| t-agent.message.clear-history.title | MessageActionBar 清空历史 | 清空历史 |
|
|
1654
|
+
| t-agent.message.clear-history.content | MessageActionBar 清空历史 | 确定要清空历史吗? |
|
|
1655
|
+
| t-agent.message.clear-history.button | MessageActionBar 清空历史 | 清空历史 |
|
|
1656
|
+
| t-agent.message.multi-select-delete.title | MessageActionBar 多选删除 | 删除选中消息 |
|
|
1657
|
+
| t-agent.message.multi-select-delete.content | MessageActionBar 多选删除 | 确定要删除这些选中的消息吗? |
|
|
1658
|
+
| t-agent.execute-card-tile.execution.success | ExecuteCardTile 执行结果 | 执行成功 |
|
|
1659
|
+
| t-agent.execute-card-tile.execution.failed | ExecuteCardTile 执行结果 | 执行失败 |
|
|
1660
|
+
| t-agent.execute-card-tile.scene.invalid | ExecuteCardTile 场景状态 | 场景失效 |
|
|
1661
|
+
| t-agent.execute-card-tile.delete | ExecuteCardTile 按钮 | 删除 |
|
|
1662
|
+
| t-agent.execute-card-tile.execute | ExecuteCardTile 按钮 | 执行 |
|
|
1663
|
+
| t-agent.execute-card-tile.switch.scene.state | ExecuteCardTile 操作 | 切换场景状态 |
|
|
1664
|
+
| t-agent.operate-card-tile.open.device.failed | OperateCardTile 操作结果 | 打开设备失败 |
|
|
1665
|
+
| t-agent.operate-card-tile.open.scene.failed | OperateCardTile 操作结果 | 打开场景失败 |
|
|
1666
|
+
| t-agent.operate-card-tile.operation.impact | OperateCardTile 标题 | 本次操作影响: |
|
|
1667
|
+
| t-agent.operate-card-tile.hide.details | OperateCardTile 按钮 | 收起详情 |
|
|
1668
|
+
| t-agent.operate-card-tile.view.details | OperateCardTile 按钮 | 查看详情 |
|
|
1669
|
+
| t-agent.operate-card-tile.device.move.desc | OperateCardTile 设备移动 | 设备"{device}"移动到"{room}" |
|
|
1670
|
+
| t-agent.operate-card-tile.device.rename.desc | OperateCardTile 设备重命名 | 设备"{oldName}"改名"{newName}" |
|
|
1671
|
+
| t-agent.operate-card-tile.device.count | OperateCardTile 设备计数 | {count}个设备 |
|
|
1672
|
+
| t-agent.operate-card-tile.scene.count | OperateCardTile 场景计数 | {count}个场景 |
|
|
1673
|
+
| t-agent.operate-card-tile.home.count | OperateCardTile 家庭计数 | {count}个家庭 |
|
|
1674
|
+
| t-agent.operate-card-tile.room.count | OperateCardTile 房间计数 | {count}个房间 |
|
|
1675
|
+
| t-agent.operate-card-tile.group.count | OperateCardTile 群组计数 | {count}个群组 |
|
|
1676
|
+
| t-agent.operate-card-tile.description.format | OperateCardTile 描述格式 | {items}。 |
|
|
1677
|
+
| t-agent.operate-card-tile.description.separator | OperateCardTile 描述分隔符 | , |
|
|
1678
|
+
| t-agent.expand.tab.device | ExpandTile 标签页 | 设备 |
|
|
1679
|
+
| t-agent.expand.tab.scene | ExpandTile 标签页 | 场景 |
|
|
1680
|
+
| t-agent.expand.tab.more | ExpandTile 标签页 | 其他 |
|
|
1681
|
+
| t-agent.expand.execution.success | ExpandTile 执行结果 | 执行成功 |
|
|
1682
|
+
| t-agent.expand.execution.failed | ExpandTile 执行结果 | 执行失败 |
|
|
1683
|
+
| t-agent.expand.device.rename | ExpandTile 设备重命名 | {oldName}改名成{newName} |
|
|
1684
|
+
| t-agent.expand.scene.rename | ExpandTile 场景重命名 | {oldName}改名成{newName} |
|
|
1685
|
+
| t-agent.expand.scene.one-click | ExpandTile 场景类型 | 一键执行 |
|
|
1686
|
+
| t-agent.expand.scene.auto | ExpandTile 场景类型 | 自动执行 |
|
|
1687
|
+
| t-agent.expand.no.details | ExpandTile 详情显示 | 没有可显示的详情内容 |
|
|
1688
|
+
| t-agent.error.unknown-error | 错误提示 | 未知错误 |
|
|
1689
|
+
| t-agent.error.network-offline | 错误提示 | 网络已断开,请检查网络连接 |
|
|
1690
|
+
| t-agent.error.invalid-params | 错误提示 | 无效参数,请重试 |
|
|
1691
|
+
| t-agent.error.session-create-failed | 错误提示 | 连接失败,请重试 |
|
|
1692
|
+
| t-agent.error.connection-closed | 错误提示 | 连接已关闭,请重试 |
|
|
1693
|
+
| t-agent.error.event-exists | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1694
|
+
| t-agent.error.event-disposed | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1695
|
+
| t-agent.error.event-closed | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1696
|
+
| t-agent.error.event-aborted | 错误提示 | 消息已中断 |
|
|
1697
|
+
| t-agent.error.event-write-failed | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1698
|
+
| t-agent.error.event-no-data-code | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1699
|
+
| t-agent.error.stream-exists | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1700
|
+
| t-agent.error.timeout | 错误提示 | 发送超时 |
|
|
1701
|
+
| t-agent.error.asr-empty | 错误提示 | 语音识别结果为空 |
|
|
1464
1702
|
|
|
1465
1703
|
# 更新日志
|
|
1466
1704
|
|
|
1467
|
-
##
|
|
1705
|
+
## 0.2.x 版本
|
|
1706
|
+
|
|
1707
|
+
### @ray-js/t-agent
|
|
1708
|
+
|
|
1709
|
+
- **Hook 机制增强**:新增 `onMessageFeedback` 和 `onClearHistory` 等生命周期钩子
|
|
1710
|
+
- **消息状态管理**:优化消息状态管理,提供更精确的消息状态控制
|
|
1711
|
+
- **错误处理**:增强错误处理机制,支持更详细的错误信息和错误分类
|
|
1712
|
+
- **性能优化**:优化内存管理和垃圾回收机制
|
|
1713
|
+
|
|
1714
|
+
### @ray-js/t-agent-plugin-aistream
|
|
1715
|
+
|
|
1716
|
+
- **全新插件**:替代废弃的 assistant 插件,提供更强大的功能
|
|
1717
|
+
- **语音合成**:支持 TTS 功能,通过 `enableTts` 参数控制
|
|
1718
|
+
- **连接优化**:新增 `earlyStart` 参数,支持提前建立连接,减少首次响应时间
|
|
1719
|
+
- **Token 管理**:优化 Token 获取机制,支持自定义 `tokenOptions`
|
|
1720
|
+
- **语音识别**:新增 AsrAgent 语音识别功能,支持实时语音转文字
|
|
1721
|
+
- **Mock 机制**:改进的 mock 机制,支持更灵活的测试场景
|
|
1722
|
+
- **多模态支持**:默认支持文本、图片、语音等多种输入类型
|
|
1723
|
+
|
|
1724
|
+
### @ray-js/t-agent-ui-ray
|
|
1468
1725
|
|
|
1469
|
-
-
|
|
1470
|
-
-
|
|
1471
|
-
-
|
|
1472
|
-
-
|
|
1473
|
-
-
|
|
1474
|
-
-
|
|
1475
|
-
-
|
|
1726
|
+
- **消息操作栏**:新增 MessageActionBar 组件,支持多选操作和批量删除
|
|
1727
|
+
- **虚拟滚动**:集成 LazyScrollView,提供虚拟滚动和性能优化
|
|
1728
|
+
- **国际化系统**:完整的国际化系统,支持中文简繁体、英文、日文等 8 种语言
|
|
1729
|
+
- **翻译 Hook**:新增 useTranslate Hook,简化多语言使用
|
|
1730
|
+
- **自定义渲染**:扩展 renderOptions,支持更多自定义渲染选项
|
|
1731
|
+
- **交互优化**:优化长按菜单功能,支持复制、删除、多选、点赞等操作
|
|
1732
|
+
- **UI 完善**:新增多语言键值对,覆盖所有 UI 交互场景
|