@ray-js/t-agent-ui-ray 0.2.8-beta.2 → 0.2.8-beta.4
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 +337 -87
- package/README.md +916 -706
- package/dist/PrivateImage/index.js +7 -10
- package/dist/tiles/BubbleTile/index.d.ts +15 -1
- package/dist/tiles/BubbleTile/index.js +60 -68
- package/dist/tiles/BubbleToolTile/audio-play.svg +1 -0
- package/dist/tiles/BubbleToolTile/audio-playing.svg +24 -0
- package/dist/tiles/BubbleToolTile/copy.svg +1 -0
- package/dist/tiles/BubbleToolTile/index.d.ts +10 -0
- package/dist/tiles/BubbleToolTile/index.js +63 -0
- package/dist/tiles/BubbleToolTile/index.less +46 -0
- package/dist/tiles/TimeTile/index.js +17 -16
- package/dist/tiles/map.js +3 -3
- package/dist/utils/getMessageContent.d.ts +11 -0
- package/dist/utils/getMessageContent.js +49 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -1
- package/package.json +2 -3
- package/dist/tiles/WorkflowTile/RollBack/index.d.ts +0 -5
- package/dist/tiles/WorkflowTile/RollBack/index.js +0 -27
- package/dist/tiles/WorkflowTile/RollBack/index.less +0 -20
- package/dist/tiles/WorkflowTile/RollBack/workflow-rollback.png +0 -0
- package/dist/tiles/WorkflowTile/index.d.ts +0 -21
- package/dist/tiles/WorkflowTile/index.js +0 -32
- package/dist/tiles/WorkflowTile/index.less +0 -31
package/README-zh_CN.md
CHANGED
|
@@ -22,12 +22,14 @@ 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.
|
|
25
|
+
"AIStreamKit": "1.3.2"
|
|
26
26
|
},
|
|
27
27
|
"baseversion": "2.21.10"
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
> 使用 MCP 功能时,`AIStreamKit` 需要 `2.2.1` 或以上版本。
|
|
32
|
+
|
|
31
33
|
## package.json 依赖要求
|
|
32
34
|
|
|
33
35
|
```json
|
|
@@ -59,59 +61,70 @@ yarn run miniapp
|
|
|
59
61
|
import React from 'react';
|
|
60
62
|
import { View } from '@ray-js/components';
|
|
61
63
|
import { createChatAgent, withDebug, withUI } from '@ray-js/t-agent';
|
|
62
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
ChatContainer,
|
|
66
|
+
defaultRenderOptions,
|
|
67
|
+
MessageInput,
|
|
68
|
+
MessageList,
|
|
69
|
+
MessageActionBar,
|
|
70
|
+
} from '@ray-js/t-agent-ui-ray';
|
|
63
71
|
import { withAIStream, withBuildIn } from '@ray-js/t-agent-plugin-aistream';
|
|
64
72
|
|
|
65
73
|
const createAgent = () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const agent = createChatAgent(
|
|
75
|
+
withUI(),
|
|
76
|
+
withAIStream({
|
|
77
|
+
earlyStart: true,
|
|
78
|
+
agentId: 'your-agent-id',
|
|
79
|
+
tokenOptions: {
|
|
80
|
+
api: 'm.life.ai.agent.token.get',
|
|
81
|
+
version: '1.0',
|
|
82
|
+
extParams: {
|
|
83
|
+
dialogueMode: 1,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
withDebug(),
|
|
88
|
+
withBuildIn()
|
|
89
|
+
);
|
|
78
90
|
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
92
|
+
if (type === 'start-event') {
|
|
93
|
+
result.userData = {
|
|
94
|
+
sessionAttributes: {
|
|
95
|
+
'custom.param': {
|
|
96
|
+
'custom.app.scene': {
|
|
97
|
+
value: 'chat-page',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
onChatStart(async result => {
|
|
84
|
-
const hello = createMessage({
|
|
85
|
-
role: 'assistant',
|
|
86
|
-
});
|
|
105
|
+
const { onChatStart, createMessage } = agent;
|
|
87
106
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await hello.persist();
|
|
107
|
+
onChatStart(async result => {
|
|
108
|
+
const hello = createMessage({
|
|
109
|
+
role: 'assistant',
|
|
92
110
|
});
|
|
93
111
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
112
|
+
hello.bubble.setText('Hello, world!');
|
|
113
|
+
result.messages.push(hello);
|
|
114
|
+
await hello.persist();
|
|
115
|
+
});
|
|
99
116
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('Agent creation failed:', error);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
117
|
+
return agent;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const renderOptions = {
|
|
121
|
+
...defaultRenderOptions,
|
|
109
122
|
};
|
|
110
123
|
|
|
111
124
|
export default function ChatPage() {
|
|
112
125
|
return (
|
|
113
126
|
<View style={{ height: '100vh' }}>
|
|
114
|
-
<ChatContainer createAgent={createAgent}>
|
|
127
|
+
<ChatContainer createAgent={createAgent} renderOptions={renderOptions}>
|
|
115
128
|
<MessageList />
|
|
116
129
|
<MessageInput />
|
|
117
130
|
<MessageActionBar />
|
|
@@ -790,6 +803,8 @@ const createAgent = () => {
|
|
|
790
803
|
- `options.sendBy` 发送者角色,默认为 'user'
|
|
791
804
|
- `options.responseBy` 响应者角色,默认为 'assistant'
|
|
792
805
|
- `options.userData` 可选的用户数据
|
|
806
|
+
- `agent.plugins.aiStream.removeMessage(message)` 删除一条历史消息
|
|
807
|
+
- `agent.plugins.aiStream.clearAllMessages()` 清空当前会话的所有消息和本地历史
|
|
793
808
|
- `agent.plugins.aiStream.getChatId()` 获取当前会话的 chatId,返回 Promise<string>
|
|
794
809
|
|
|
795
810
|
Hooks:
|
|
@@ -805,7 +820,7 @@ Hooks:
|
|
|
805
820
|
- `status` 消息状态
|
|
806
821
|
- `result.text` 文本内容,可以修改
|
|
807
822
|
- `onSkillCompose` 当收到技能数据时触发,用于处理技能的渲染
|
|
808
|
-
- `skill`
|
|
823
|
+
- `skill` 当前技能数据 (ReceivedTextSkillPacketBody)
|
|
809
824
|
- `respMsg` 响应消息
|
|
810
825
|
- `result.messages` 消息列表
|
|
811
826
|
- `onSkillsEnd` 当所有技能处理完成时触发
|
|
@@ -826,8 +841,90 @@ Hooks:
|
|
|
826
841
|
- `data.blocks` 当 type 为 'start-event' 时,包含本次发送的输入块
|
|
827
842
|
- `result.userData` 返回的用户数据对象,会被合并后发送给 AI 平台
|
|
828
843
|
|
|
844
|
+
### withMCP 插件
|
|
845
|
+
|
|
846
|
+
提供 MCP 服务暴露能力,可以实现让 Agent 调用小程序里面提供的 tool,实现操作蓝牙设备,调用自定义 api,读取本地文件等功能,使用时先需要在智能体节点上开启“设备 MCP”,此外,MCP tool 的名字必须以 `device.` 开头。
|
|
847
|
+
|
|
848
|
+

|
|
849
|
+
|
|
850
|
+
**使用前提**:
|
|
851
|
+
|
|
852
|
+
- 必须在 `withAIStream` 之后使用
|
|
853
|
+
- 使用 MCP 功能时,`AIStreamKit` 需要 `2.2.1` 或以上版本
|
|
854
|
+
- `createServer` 必须同步返回 `McpServer`
|
|
855
|
+
|
|
856
|
+
参数:
|
|
857
|
+
|
|
858
|
+
- `createServer(agent)` 创建 MCP 服务实例
|
|
859
|
+
- `createContext(event, agent)` 可选,为每次 MCP 请求补充上下文
|
|
860
|
+
|
|
829
861
|
**使用示例**:
|
|
830
862
|
|
|
863
|
+
```tsx
|
|
864
|
+
import { createChatAgent, withUI } from '@ray-js/t-agent';
|
|
865
|
+
import { McpServer, withAIStream, withMCP } from '@ray-js/t-agent-plugin-aistream';
|
|
866
|
+
|
|
867
|
+
const createAgent = () => {
|
|
868
|
+
const server = new McpServer({
|
|
869
|
+
name: 'demo-mcp',
|
|
870
|
+
version: '1.0.0',
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
server.registerTool(
|
|
874
|
+
'device.echo',
|
|
875
|
+
{
|
|
876
|
+
description: '回显输入参数',
|
|
877
|
+
inputSchema: {
|
|
878
|
+
type: 'object',
|
|
879
|
+
properties: {
|
|
880
|
+
text: { type: 'string' },
|
|
881
|
+
},
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
async (args, context) => {
|
|
885
|
+
return {
|
|
886
|
+
content: [
|
|
887
|
+
{
|
|
888
|
+
type: 'text',
|
|
889
|
+
text: JSON.stringify({
|
|
890
|
+
text: args.text,
|
|
891
|
+
sessionId: context.sessionId,
|
|
892
|
+
}),
|
|
893
|
+
},
|
|
894
|
+
],
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
return createChatAgent(
|
|
900
|
+
withUI(),
|
|
901
|
+
withAIStream({
|
|
902
|
+
agentId: 'your-agent-id',
|
|
903
|
+
}),
|
|
904
|
+
withMCP({
|
|
905
|
+
createServer: () => server,
|
|
906
|
+
createContext: event => ({
|
|
907
|
+
traceId: event.eventId,
|
|
908
|
+
}),
|
|
909
|
+
})
|
|
910
|
+
);
|
|
911
|
+
};
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
启用后,插件会:
|
|
915
|
+
|
|
916
|
+
- 在创建 session 时注入 `sessionAttributes.deviceMcp`
|
|
917
|
+
- 在收到 `MCP_CMD` 事件时调用对应 tool
|
|
918
|
+
- 将 tool 执行结果按 JSON-RPC 响应格式回传给 AIStream
|
|
919
|
+
|
|
920
|
+
### 自定义变量传入
|
|
921
|
+
|
|
922
|
+
某些情况下,你可能需要自定义变量到 agent 作为流程中的变量,你需要在工作流里配置自定义变量的引用处,然后再在小程序里传入自定义变量:
|
|
923
|
+
|
|
924
|
+

|
|
925
|
+
|
|
926
|
+
**小程序中传入自定义变量**:
|
|
927
|
+
|
|
831
928
|
```tsx
|
|
832
929
|
const agent = createChatAgent(
|
|
833
930
|
withUI(),
|
|
@@ -839,10 +936,14 @@ const agent = createChatAgent(
|
|
|
839
936
|
agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
840
937
|
// 在创建会话时传递用户信息
|
|
841
938
|
if (type === 'create-session') {
|
|
842
|
-
result.
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
939
|
+
result.userData = {
|
|
940
|
+
sessionAttributes: {
|
|
941
|
+
'custom.param': {
|
|
942
|
+
'custom.app.test_me': {
|
|
943
|
+
// 此处为平台上配置接收的参数名
|
|
944
|
+
value: `with value test me ${type} ${Date.now()}`,
|
|
945
|
+
},
|
|
946
|
+
},
|
|
846
947
|
},
|
|
847
948
|
};
|
|
848
949
|
return;
|
|
@@ -850,9 +951,13 @@ agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
|
850
951
|
// 在每次发送消息时传递动态上下文
|
|
851
952
|
if (type === 'start-event') {
|
|
852
953
|
result.userData = {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
954
|
+
sessionAttributes: {
|
|
955
|
+
'custom.param': {
|
|
956
|
+
'custom.app.test_me': {
|
|
957
|
+
// 此处为平台上配置接收的参数名
|
|
958
|
+
value: `with value test me ${type} ${Date.now()}`,
|
|
959
|
+
},
|
|
960
|
+
},
|
|
856
961
|
},
|
|
857
962
|
};
|
|
858
963
|
return;
|
|
@@ -869,6 +974,65 @@ agent.plugins.aiStream.onUserDataRead((type, data, result) => {
|
|
|
869
974
|
- **智能家居**:设备控制、场景管理
|
|
870
975
|
- **知识库搜索**:关联文档展示
|
|
871
976
|
|
|
977
|
+
#### 配置项
|
|
978
|
+
|
|
979
|
+
```tsx
|
|
980
|
+
withBuildIn({
|
|
981
|
+
// 是否默认开启 TTS 自动播放,默认 false
|
|
982
|
+
audioAutoPlay: true,
|
|
983
|
+
});
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
#### TTS 语音播放
|
|
987
|
+
|
|
988
|
+
当 `withAIStream({ enableTts: true })` 开启后,服务端会随消息下发 TTS 音频包。`withBuildIn` 会消费这些音频包并提供完整的播放能力:
|
|
989
|
+
|
|
990
|
+
- **自动播放**:音频流开始(`StreamFlag.START`)时,若 `AIStream.audioAutoPlay` 为 `true`,则自动播放。
|
|
991
|
+
- **气泡播放按钮**:音频流结束后,会在对应气泡里插入一个 `bubbleTool` tile(语音播放 / 复制按钮)。播放参数(`path` / `codecType` / `sampleRate` / `channels` / `bitDepth` / `pts`)会按音频流 id 聚合后写入 tile,点击即可重新播放。
|
|
992
|
+
- **单条互斥**:同一时刻只播放一条,开始新播放或主动停止时会先停掉当前播放。
|
|
993
|
+
- **播放生命周期**:监听底层 `onAudioPlayChanged`,在播放完成 / 异常时自动复位播放状态。
|
|
994
|
+
|
|
995
|
+
**对外暴露的 session 状态**(均通过 `sessionChange` 事件广播,UI 侧可用 `useAgentSessionValue` 订阅并派生组件状态):
|
|
996
|
+
|
|
997
|
+
| key | 类型 | 说明 |
|
|
998
|
+
| --------------------------- | ---------------- | --------------------- |
|
|
999
|
+
| `AIStream.audioAutoPlay` | `boolean` | 是否开启 TTS 自动播放 |
|
|
1000
|
+
| `AIStream.audioPlaying` | `boolean` | 当前是否正在播放 |
|
|
1001
|
+
| `AIStream.playingMessageId` | `string \| null` | 正在播放的消息 id |
|
|
1002
|
+
|
|
1003
|
+
**对外暴露的 UI 事件**:
|
|
1004
|
+
|
|
1005
|
+
| 事件名 | 说明 |
|
|
1006
|
+
| --------------- | ---------------------------------------- |
|
|
1007
|
+
| `audioPlayStop` | 主动停止当前播放(不论是否开启自动播放) |
|
|
1008
|
+
|
|
1009
|
+
示例:在页面顶部做一个三态(播放中 / 自动播放 / 静音)切换按钮:
|
|
1010
|
+
|
|
1011
|
+
```tsx
|
|
1012
|
+
import { useAgentSessionValue, useEmitEvent } from '@ray-js/t-agent-ui-ray';
|
|
1013
|
+
|
|
1014
|
+
function AudioToggle() {
|
|
1015
|
+
const [audioAutoPlay, setAudioAutoPlay] = useAgentSessionValue<boolean>('AIStream.audioAutoPlay');
|
|
1016
|
+
const [audioPlaying] = useAgentSessionValue<boolean>('AIStream.audioPlaying');
|
|
1017
|
+
const emitEvent = useEmitEvent();
|
|
1018
|
+
|
|
1019
|
+
const onClick = () => {
|
|
1020
|
+
if (audioPlaying) {
|
|
1021
|
+
// 播放中:点击立刻停止播放,不论是否静音
|
|
1022
|
+
emitEvent('audioPlayStop', undefined);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
// 否则切换自动播放 / 静音
|
|
1026
|
+
setAudioAutoPlay(prev => !prev);
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
const label = audioPlaying ? '🎵 播放中' : audioAutoPlay ? '🔊 自动播放' : '🔇 静音';
|
|
1030
|
+
return <View onClick={onClick}>{label}</View>;
|
|
1031
|
+
}
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
> 组件内的 `playing` 状态应从 session 派生(如 `audioPlaying && playingMessageId === message.id`),不要在 tile 内部维护本地播放状态,避免被持久化或与全局状态不一致。
|
|
1035
|
+
|
|
872
1036
|
## mock 机制
|
|
873
1037
|
|
|
874
1038
|
为了方便开发,我们提供了一个 mock 机制,可以在开发时不用连接小程序 AI 智能体平台,直接使用 mock 数据进行开发。
|
|
@@ -918,6 +1082,92 @@ mock.hooks.hook('asrDetection', context => {
|
|
|
918
1082
|
});
|
|
919
1083
|
```
|
|
920
1084
|
|
|
1085
|
+
### mock MCP
|
|
1086
|
+
|
|
1087
|
+
推荐做法是在 mock 的 `sendToAIStream` 钩子里,根据输入内容决定要调用哪个 MCP tool,再通过 `context.callMCPTool()` 直接走一遍完整的 MCP 调用链。
|
|
1088
|
+
|
|
1089
|
+
```tsx
|
|
1090
|
+
import { mock } from '@ray-js/t-agent-plugin-aistream';
|
|
1091
|
+
|
|
1092
|
+
const getToolCall = (text: string) => {
|
|
1093
|
+
if (text.includes('报错') || text.includes('失败') || text.includes('异常')) {
|
|
1094
|
+
return {
|
|
1095
|
+
name: 'device.home.energy.summary.fail',
|
|
1096
|
+
arguments: {
|
|
1097
|
+
reason: 'mock-error-case',
|
|
1098
|
+
},
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
if (text.includes('能耗') || text.includes('电量') || text.includes('数据')) {
|
|
1103
|
+
return {
|
|
1104
|
+
name: 'device.home.energy.summary.get',
|
|
1105
|
+
arguments: {
|
|
1106
|
+
period: 'today',
|
|
1107
|
+
},
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
return {
|
|
1112
|
+
name: 'device.app.open',
|
|
1113
|
+
arguments: {
|
|
1114
|
+
category: 'music',
|
|
1115
|
+
},
|
|
1116
|
+
};
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
export const setupMockMCP = () => {
|
|
1120
|
+
mock.hooks.hook('sendToAIStream', async context => {
|
|
1121
|
+
const text = context.data
|
|
1122
|
+
.filter(item => item.type === 'text')
|
|
1123
|
+
.map(item => item.text)
|
|
1124
|
+
.join(' ');
|
|
1125
|
+
|
|
1126
|
+
if (!/mcp|应用|能耗|电量|数据|报错|失败|异常/i.test(text)) {
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
const toolCall = getToolCall(text);
|
|
1131
|
+
|
|
1132
|
+
await context.writeText(`MCP mock 正在调用 ${toolCall.name}...`);
|
|
1133
|
+
|
|
1134
|
+
try {
|
|
1135
|
+
const result = await context.callMCPTool(toolCall.name, toolCall.arguments, {
|
|
1136
|
+
delayMs: 80,
|
|
1137
|
+
});
|
|
1138
|
+
await context.writeText(
|
|
1139
|
+
`工具 ${toolCall.name} 已返回:${
|
|
1140
|
+
typeof result === 'string' ? result : JSON.stringify(result == null ? {} : result)
|
|
1141
|
+
}`
|
|
1142
|
+
);
|
|
1143
|
+
} catch (error) {
|
|
1144
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1145
|
+
await context.writeText(`MCP mock 已收到工具报错:${message}`);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
await context.end();
|
|
1149
|
+
});
|
|
1150
|
+
};
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
使用时在创建 agent 前注册一次即可:
|
|
1154
|
+
|
|
1155
|
+
```tsx
|
|
1156
|
+
const createAgent = () => {
|
|
1157
|
+
setupMockMCP();
|
|
1158
|
+
|
|
1159
|
+
return createChatAgent(
|
|
1160
|
+
withUI(),
|
|
1161
|
+
withAIStream({
|
|
1162
|
+
agentId: 'your-agent-id',
|
|
1163
|
+
}),
|
|
1164
|
+
withMCP({
|
|
1165
|
+
createServer: () => server,
|
|
1166
|
+
})
|
|
1167
|
+
);
|
|
1168
|
+
};
|
|
1169
|
+
```
|
|
1170
|
+
|
|
921
1171
|
## 附带的 utils 工具(现在不稳定,还在开发中)
|
|
922
1172
|
|
|
923
1173
|
### AbortController
|
|
@@ -1112,17 +1362,30 @@ yarn add @ray-js/t-agent-ui-ray
|
|
|
1112
1362
|
## 使用
|
|
1113
1363
|
|
|
1114
1364
|
```tsx
|
|
1115
|
-
import
|
|
1365
|
+
import React from 'react';
|
|
1366
|
+
import { View } from '@ray-js/components';
|
|
1367
|
+
import {
|
|
1368
|
+
ChatContainer,
|
|
1369
|
+
defaultRenderOptions,
|
|
1370
|
+
MessageActionBar,
|
|
1371
|
+
MessageInput,
|
|
1372
|
+
MessageList,
|
|
1373
|
+
} from '@ray-js/t-agent-ui-ray';
|
|
1116
1374
|
// createAgent 实现参见 t-agent 的使用示例
|
|
1117
1375
|
import { createAgent } from './createAgent';
|
|
1118
1376
|
|
|
1377
|
+
const renderOptions = {
|
|
1378
|
+
...defaultRenderOptions,
|
|
1379
|
+
};
|
|
1380
|
+
|
|
1119
1381
|
export default function ChatPage() {
|
|
1120
1382
|
// createAgent 必须返回一个 ChatAgent 应用过 withUI、withAIStream 插件的实例
|
|
1121
1383
|
return (
|
|
1122
1384
|
<View style={{ height: '100vh' }}>
|
|
1123
|
-
<ChatContainer createAgent={createAgent}>
|
|
1385
|
+
<ChatContainer createAgent={createAgent} renderOptions={renderOptions}>
|
|
1124
1386
|
<MessageList />
|
|
1125
1387
|
<MessageInput />
|
|
1388
|
+
<MessageActionBar />
|
|
1126
1389
|
</ChatContainer>
|
|
1127
1390
|
</View>
|
|
1128
1391
|
);
|
|
@@ -1181,7 +1444,16 @@ props:
|
|
|
1181
1444
|
|
|
1182
1445
|
- `className` 输入框的类名
|
|
1183
1446
|
- `placeholder` 输入框的占位符
|
|
1447
|
+
- `placeholderStyle` 输入框 placeholder 的样式
|
|
1184
1448
|
- `renderTop` 用于渲染输入框上方的内容
|
|
1449
|
+
- `style` 输入框容器样式
|
|
1450
|
+
- `attachment` 是否启用附件上传,或传入 `{ image, video, imageCount, videoCount }` 精细控制
|
|
1451
|
+
- `maxTextLength` 文本最大长度,默认 200
|
|
1452
|
+
- `maxAudioMs` 录音最大时长
|
|
1453
|
+
- `onStateChange` 输入框状态变化回调,状态值见 `MessageInputState`
|
|
1454
|
+
- `amplitudeCount` 语音波形振幅采样数量
|
|
1455
|
+
|
|
1456
|
+
`MessageInput` 当前默认导出的是 `MessageInputAIStream`,适用于已接入 `withAIStream` 的场景。
|
|
1185
1457
|
|
|
1186
1458
|
### MessageActionBar(0.2.x 新增)
|
|
1187
1459
|
|
|
@@ -1261,7 +1533,12 @@ const MyTile = ({ notifyHeightChanged }) => {
|
|
|
1261
1533
|
- bubble 气泡
|
|
1262
1534
|
- buttons 按钮组
|
|
1263
1535
|
- card 卡片
|
|
1536
|
+
- divider 分隔线
|
|
1537
|
+
- documents 关联文档
|
|
1538
|
+
- executeCard 执行结果卡片
|
|
1539
|
+
- file 文件
|
|
1264
1540
|
- image 图片
|
|
1541
|
+
- operateCard 操作结果卡片
|
|
1265
1542
|
- recommendations 推荐行动
|
|
1266
1543
|
- text 文本,包含 markdown 支持
|
|
1267
1544
|
- time 时间标识
|
|
@@ -1269,10 +1546,6 @@ const MyTile = ({ notifyHeightChanged }) => {
|
|
|
1269
1546
|
- video 视频
|
|
1270
1547
|
- workflow 工作选项
|
|
1271
1548
|
|
|
1272
|
-
### 内置 card
|
|
1273
|
-
|
|
1274
|
-
- WorkflowReplyCard 工作流回复卡片
|
|
1275
|
-
|
|
1276
1549
|
## React Hooks
|
|
1277
1550
|
|
|
1278
1551
|
### useChatAgent
|
|
@@ -1337,16 +1610,23 @@ const MyTilePart = () => {
|
|
|
1337
1610
|
|
|
1338
1611
|
### useSendAction
|
|
1339
1612
|
|
|
1340
|
-
发送一个 TTTAction
|
|
1613
|
+
发送一个 TTTAction。
|
|
1614
|
+
|
|
1615
|
+
如果当前组件位于 tile 或 card 内部,会优先走 `emitTileEvent`。
|
|
1616
|
+
如果当前组件只是 `ChatContainer` 下的普通子组件,则会退化为触发 UI 事件 `runTTTAction`。
|
|
1341
1617
|
|
|
1342
1618
|
```tsx
|
|
1343
1619
|
import { useSendAction } from '@ray-js/t-agent-ui-ray';
|
|
1344
1620
|
|
|
1345
|
-
const
|
|
1621
|
+
const ActionPanel = () => {
|
|
1346
1622
|
const sendAction = useSendAction();
|
|
1347
1623
|
|
|
1348
1624
|
const handleClick = () => {
|
|
1349
|
-
sendAction({
|
|
1625
|
+
sendAction({
|
|
1626
|
+
type: 'sendMessage',
|
|
1627
|
+
blocks: [{ type: 'text', text: 'hello' }],
|
|
1628
|
+
sendImmediately: true,
|
|
1629
|
+
});
|
|
1350
1630
|
};
|
|
1351
1631
|
|
|
1352
1632
|
return <button onClick={handleClick}>Send Message</button>;
|
|
@@ -1753,33 +2033,3 @@ const renderOptions = {
|
|
|
1753
2033
|
| t-agent.error.stream-exists | 错误提示 | 消息发送异常,请稍后再试 |
|
|
1754
2034
|
| t-agent.error.timeout | 错误提示 | 发送超时 |
|
|
1755
2035
|
| t-agent.error.asr-empty | 错误提示 | 语音识别结果为空 |
|
|
1756
|
-
|
|
1757
|
-
# 更新日志
|
|
1758
|
-
|
|
1759
|
-
## 0.2.x 版本
|
|
1760
|
-
|
|
1761
|
-
### @ray-js/t-agent
|
|
1762
|
-
|
|
1763
|
-
- **Hook 机制增强**:新增 `onMessageFeedback` 和 `onClearHistory` 等生命周期钩子
|
|
1764
|
-
- **消息状态管理**:优化消息状态管理,提供更精确的消息状态控制
|
|
1765
|
-
- **错误处理**:增强错误处理机制,支持更详细的错误信息和错误分类
|
|
1766
|
-
- **性能优化**:优化内存管理和垃圾回收机制
|
|
1767
|
-
|
|
1768
|
-
### @ray-js/t-agent-plugin-aistream
|
|
1769
|
-
|
|
1770
|
-
- **全新插件**:替代废弃的 assistant 插件,提供更强大的功能
|
|
1771
|
-
- **连接优化**:新增 `earlyStart` 参数,支持提前建立连接,减少首次响应时间
|
|
1772
|
-
- **Token 管理**:优化 Token 获取机制,支持自定义 `tokenOptions`
|
|
1773
|
-
- **语音识别**:新增 AsrAgent 语音识别功能,支持实时语音转文字
|
|
1774
|
-
- **Mock 机制**:改进的 mock 机制,支持更灵活的测试场景
|
|
1775
|
-
- **多模态支持**:默认支持文本、图片、语音等多种输入类型
|
|
1776
|
-
|
|
1777
|
-
### @ray-js/t-agent-ui-ray
|
|
1778
|
-
|
|
1779
|
-
- **消息操作栏**:新增 MessageActionBar 组件,支持多选操作和批量删除
|
|
1780
|
-
- **虚拟滚动**:集成 LazyScrollView,提供虚拟滚动和性能优化
|
|
1781
|
-
- **国际化系统**:完整的国际化系统,支持中文简繁体、英文、日文等 8 种语言
|
|
1782
|
-
- **翻译 Hook**:新增 useTranslate Hook,简化多语言使用
|
|
1783
|
-
- **自定义渲染**:扩展 renderOptions,支持更多自定义渲染选项
|
|
1784
|
-
- **交互优化**:优化长按菜单功能,支持复制、删除、多选、点赞等操作
|
|
1785
|
-
- **UI 完善**:新增多语言键值对,覆盖所有 UI 交互场景
|