@ray-js/t-agent 0.1.0-beta-1 → 0.1.0-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 +45 -18
- package/README.md +36 -10
- package/package.json +2 -2
package/README-zh_CN.md
CHANGED
|
@@ -148,6 +148,7 @@ const createAgent = () => {
|
|
|
148
148
|
- `agent.createMessage(data)` 创建一个与当前 Agent 绑定的消息
|
|
149
149
|
- `agent.emitTileEvent(tileId: string, payload: any)` tile 发送事件
|
|
150
150
|
- `agent.removeMessage(messageId: string)` 删除消息
|
|
151
|
+
- `agent.removeMessageByChannel(channel: string)` 按照渠道删除所有消息
|
|
151
152
|
- `agent.flushStreamToShow(message: ChatMessage, response: StreamResponse, composer: ComposeHandler)` 流式更新消息
|
|
152
153
|
|
|
153
154
|
### Hooks 机制
|
|
@@ -339,6 +340,13 @@ await message.show();
|
|
|
339
340
|
- `message.bubble.setInfo` 方法,设置气泡信息
|
|
340
341
|
- `message.bubble.initWithInputBlocks` 方法,用输入块初始化气泡
|
|
341
342
|
|
|
343
|
+
**气泡消息支持长按操作**,可以进行复制、删除等操作,同时在消息加载和更新过程中会有动画显示。
|
|
344
|
+
|
|
345
|
+
气泡消息支持以下长按操作:
|
|
346
|
+
|
|
347
|
+
- 复制:复制消息文本内容
|
|
348
|
+
- 删除:删除当前消息
|
|
349
|
+
|
|
342
350
|
### 生命周期
|
|
343
351
|
|
|
344
352
|
ChatAgent 在不同的阶段会触发不同的 Hook,开发者可以通过注册 Hook 来实现自定义行为,下面的时序图展示了 ChatAgent 的生命周期。
|
|
@@ -1053,6 +1061,7 @@ props:
|
|
|
1053
1061
|
|
|
1054
1062
|
- `className` 容器的类名
|
|
1055
1063
|
- `createAgent` 创建 `ChatAgent` 的函数,在 `ChatContainer` 挂载后会调用这个函数创建 `ChatAgent` 实例
|
|
1064
|
+
- `agentRef` 用于获取 `ChatAgent` 实例的 ref
|
|
1056
1065
|
- `renderOptions` 渲染选项,用于决定 `MessageList` 中各个元素的渲染方式,具体参照下面的 renderOptions 自定义渲染 部分
|
|
1057
1066
|
- `renderTileAs` 该函数决定如何在消息中渲染 tile
|
|
1058
1067
|
- `customBlockTypes` 自定义 block 类型,只有在这里注册的 block 类型才会被 `renderCustomBlockAs` 渲染
|
|
@@ -1320,25 +1329,30 @@ const renderOptions = {
|
|
|
1320
1329
|
```my-block
|
|
1321
1330
|
Hello, world!
|
|
1322
1331
|
```
|
|
1332
|
+
````
|
|
1323
1333
|
|
|
1324
1334
|
以下 fence 没有注册过,不会被渲染成自定义 block,仅当做普通的代码块渲染。
|
|
1325
1335
|
|
|
1326
1336
|
```javascript
|
|
1327
1337
|
console.log('Hello, world!');
|
|
1328
1338
|
```
|
|
1329
|
-
|
|
1339
|
+
|
|
1340
|
+
```
|
|
1330
1341
|
|
|
1331
1342
|
渲染结果如下:
|
|
1332
1343
|
|
|
1333
1344
|
```
|
|
1345
|
+
|
|
1334
1346
|
这是我的自定义 block!
|
|
1335
1347
|
This is My Block
|
|
1336
1348
|
Hello, world!
|
|
1337
1349
|
以下 fence 没有注册过,不会被渲染成自定义 block,仅当做普通的代码块渲染。
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1350
|
+
|
|
1351
|
+
---
|
|
1352
|
+
|
|
1353
|
+
## | console.log('Hello, world!'); |
|
|
1354
|
+
|
|
1355
|
+
````
|
|
1342
1356
|
|
|
1343
1357
|
### getStaticResourceBizType
|
|
1344
1358
|
|
|
@@ -1351,7 +1365,7 @@ const renderOptions = {
|
|
|
1351
1365
|
...defaultRenderOptions,
|
|
1352
1366
|
getStaticResourceBizType: (src: string, scene: string) => 'bizType',
|
|
1353
1367
|
};
|
|
1354
|
-
|
|
1368
|
+
````
|
|
1355
1369
|
|
|
1356
1370
|
针对不同的场景,你可以需要不同的 `bizType`,你可以根据 `src` 和 `scene` 来返回不同的 `bizType`。
|
|
1357
1371
|
|
|
@@ -1388,21 +1402,34 @@ const renderOptions = {
|
|
|
1388
1402
|
| key | 使用场景 | 含义 |
|
|
1389
1403
|
| -------------------------------------------------- | ------------------------- | -------------------- |
|
|
1390
1404
|
| t-agent.build-in.button.create_scene_manually | ButtonTile 内置按钮 | 手动创建场景 |
|
|
1391
|
-
| t-agent.build-in.button.enter_home_manage | ButtonTile 内置按钮 |
|
|
1392
|
-
| t-agent.build-in.button.enter_room_manage | ButtonTile 内置按钮 |
|
|
1393
|
-
| t-agent.build-in.button.enter_alarm_message | ButtonTile 内置按钮 |
|
|
1394
|
-
| t-agent.build-in.button.enter_home_message | ButtonTile 内置按钮 |
|
|
1395
|
-
| t-agent.build-in.button.enter_bulletin | ButtonTile 内置按钮 |
|
|
1396
|
-
| t-agent.build-in.button.enter_notification_setting | ButtonTile 内置按钮 |
|
|
1397
|
-
| t-agent.build-in.button.enter_personal_information | ButtonTile 内置按钮 |
|
|
1398
|
-
| t-agent.build-in.button.enter_account_security | ButtonTile 内置按钮 |
|
|
1399
|
-
| t-agent.build-in.button.enter_setting | ButtonTile 内置按钮 |
|
|
1400
|
-
| t-agent.build-in.button.enter_paring | ButtonTile 内置按钮 |
|
|
1401
|
-
| t-agent.build-in.button.enter_share_device | ButtonTile 内置按钮 |
|
|
1402
|
-
| t-agent.build-in.button.enter_faq_feedback | ButtonTile 内置按钮 |
|
|
1405
|
+
| t-agent.build-in.button.enter_home_manage | ButtonTile 内置按钮 | 进入"家庭管理" |
|
|
1406
|
+
| t-agent.build-in.button.enter_room_manage | ButtonTile 内置按钮 | 进入"房间管理" |
|
|
1407
|
+
| t-agent.build-in.button.enter_alarm_message | ButtonTile 内置按钮 | 进入"告警消息列表" |
|
|
1408
|
+
| t-agent.build-in.button.enter_home_message | ButtonTile 内置按钮 | 进入"家庭消息列表" |
|
|
1409
|
+
| t-agent.build-in.button.enter_bulletin | ButtonTile 内置按钮 | 进入"通知消息列表" |
|
|
1410
|
+
| t-agent.build-in.button.enter_notification_setting | ButtonTile 内置按钮 | 进入"消息推送设置" |
|
|
1411
|
+
| t-agent.build-in.button.enter_personal_information | ButtonTile 内置按钮 | 进入"个人资料" |
|
|
1412
|
+
| t-agent.build-in.button.enter_account_security | ButtonTile 内置按钮 | 进入"账号与安全" |
|
|
1413
|
+
| t-agent.build-in.button.enter_setting | ButtonTile 内置按钮 | 进入"通用设置" |
|
|
1414
|
+
| t-agent.build-in.button.enter_paring | ButtonTile 内置按钮 | 进入"设备配网" |
|
|
1415
|
+
| t-agent.build-in.button.enter_share_device | ButtonTile 内置按钮 | 进入"设备分享" |
|
|
1416
|
+
| t-agent.build-in.button.enter_faq_feedback | ButtonTile 内置按钮 | 进入"常见问题与反馈" |
|
|
1403
1417
|
| t-agent.build-in.button.questionnaire_take | ButtonTile 内置按钮 | 填写问卷 |
|
|
1404
1418
|
| t-agent.build-in.button.set_home_location | ButtonTile 内置按钮 | 设置家庭位置 |
|
|
1405
1419
|
| t-agent.input.voice.require-permission | MessageInput 切换语音输入 | 需要授权录音权限 |
|
|
1406
1420
|
| t-agent.input.upload.failed | MessageInput 上传文件 | 文件上传失败 |
|
|
1407
1421
|
| t-agent.message.feedback.success | BubbleTile 消息评价 | 反馈成功 |
|
|
1408
1422
|
| t-agent.message.bubble.aborted | BubbleTile 消息 | 用户中断 |
|
|
1423
|
+
| t-agent.message.action.copy | BubbleTile 长按菜单 | 复制消息 |
|
|
1424
|
+
| t-agent.message.action.delete | BubbleTile 长按菜单 | 删除消息 |
|
|
1425
|
+
| t-agent.message.action.deleteByChannel | BubbleTile 长按菜单 | 删除所有渠道消息 |
|
|
1426
|
+
| t-agent.message.like.success | BubbleTile 反馈 | 点赞成功 |
|
|
1427
|
+
| t-agent.message.unlike.success | BubbleTile 反馈 | 取消点赞成功 |
|
|
1428
|
+
|
|
1429
|
+
# 更新日志
|
|
1430
|
+
|
|
1431
|
+
## 最新版本
|
|
1432
|
+
|
|
1433
|
+
- **支持按 channel 清空消息**:通过`agent.removeMessageByChannel`方法可以批量删除特定 channel 的所有消息
|
|
1434
|
+
- **气泡消息加载动画**:消息在加载和更新状态下会显示适当的动画效果,提升用户体验
|
|
1435
|
+
- **气泡消息长按操作**:支持长按消息进行复制和删除等操作,其中助手消息还支持按渠道删除
|
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ export default function ChatPage() {
|
|
|
112
112
|
|
|
113
113
|
# t-agent
|
|
114
114
|
|
|
115
|
-
The t-agent package, crafted in TypeScript, is a dialogue agent SDK for building feature-rich dialogue interactions, supporting plugins to enhance functionality. As a pure SDK, it doesn
|
|
115
|
+
The t-agent package, crafted in TypeScript, is a dialogue agent SDK for building feature-rich dialogue interactions, supporting plugins to enhance functionality. As a pure SDK, it doesn't contain UI components, allowing flexibility to work with any framework.
|
|
116
116
|
|
|
117
117
|
## Basic Concepts
|
|
118
118
|
|
|
@@ -147,6 +147,7 @@ Core Methods:
|
|
|
147
147
|
- `agent.createMessage(data)` Creates a message linked to the agent
|
|
148
148
|
- `agent.emitTileEvent(tileId: string, payload: any)` Emits tile events
|
|
149
149
|
- `agent.removeMessage(messageId: string)` Removes messages
|
|
150
|
+
- `agent.removeMessageByChannel(channel: string)` Removes messages based on channel
|
|
150
151
|
- `agent.flushStreamToShow(message: ChatMessage, response: StreamResponse, composer: ComposeHandler)` Handles stream updates
|
|
151
152
|
|
|
152
153
|
### Hooks Mechanism
|
|
@@ -335,6 +336,13 @@ For bubble messages, additional properties and methods include:
|
|
|
335
336
|
- `message.bubble.setInfo` Configures bubble info
|
|
336
337
|
- `message.bubble.initWithInputBlocks` Initializes bubble with input blocks
|
|
337
338
|
|
|
339
|
+
**Bubble messages support long press operations**, allowing for copy and delete functions, and animations will be displayed during message loading and updating.
|
|
340
|
+
|
|
341
|
+
Bubble messages support the following long press operations:
|
|
342
|
+
|
|
343
|
+
- Copy: Copy the message text content
|
|
344
|
+
- Delete: Delete the current message
|
|
345
|
+
|
|
338
346
|
### Lifecycle
|
|
339
347
|
|
|
340
348
|
ChatAgent phases trigger hooks enabling developers to integrate custom behavior efficiently. Below is the lifecycle depiction:
|
|
@@ -732,7 +740,6 @@ mock.hooks.hook('getAIAssistantGroupHistory', context => {
|
|
|
732
740
|
|
|
733
741
|
### Mock AI Assistant Response
|
|
734
742
|
|
|
735
|
-
````
|
|
736
743
|
```tsx
|
|
737
744
|
import { mock } from '@ray-js/t-agent-plugin-assistant';
|
|
738
745
|
|
|
@@ -781,7 +788,7 @@ mock.hooks.hook('sendToAssistant', context => {
|
|
|
781
788
|
};
|
|
782
789
|
}
|
|
783
790
|
});
|
|
784
|
-
|
|
791
|
+
```
|
|
785
792
|
|
|
786
793
|
### mock ASR Speech Recognition
|
|
787
794
|
|
|
@@ -1001,7 +1008,7 @@ import { useEffect } from 'react';
|
|
|
1001
1008
|
async function getPictureList() {
|
|
1002
1009
|
// Retrieve the user's private picture list from the cloud
|
|
1003
1010
|
const list = await pictureListRequest();
|
|
1004
|
-
// Set into the cache this way, so it won
|
|
1011
|
+
// Set into the cache this way, so it won't need to request next time
|
|
1005
1012
|
for (const item of list) {
|
|
1006
1013
|
setUrlByCloudKey(item.path, item.displayUrl);
|
|
1007
1014
|
}
|
|
@@ -1048,6 +1055,7 @@ props:
|
|
|
1048
1055
|
|
|
1049
1056
|
- `className` Class name of the container
|
|
1050
1057
|
- `createAgent` Function to create `ChatAgent`, which will call this function to create `ChatAgent` instance after `ChatContainer` mount
|
|
1058
|
+
- `agentRef` Reference to the `ChatAgent` instance, used to get the `ChatAgent` instance outside the `ChatContainer`
|
|
1051
1059
|
- `renderOptions` Rendering options, used to decide the rendering method of each element in `MessageList`, refer to the renderOptions custom rendering part below
|
|
1052
1060
|
- `renderTileAs` This function decides how to render tiles in the messages
|
|
1053
1061
|
- `customBlockTypes` Custom block types, only block types registered here will be rendered by `renderCustomBlockAs`
|
|
@@ -1315,25 +1323,30 @@ This is my custom block!
|
|
|
1315
1323
|
```my-block
|
|
1316
1324
|
Hello, world!
|
|
1317
1325
|
```
|
|
1326
|
+
````
|
|
1318
1327
|
|
|
1319
1328
|
The following fence is not registered, and will not be rendered as a custom block, but just as a regular code block.
|
|
1320
1329
|
|
|
1321
1330
|
```javascript
|
|
1322
1331
|
console.log('Hello, world!');
|
|
1323
1332
|
```
|
|
1324
|
-
|
|
1333
|
+
|
|
1334
|
+
```
|
|
1325
1335
|
|
|
1326
1336
|
The rendered result is as follows:
|
|
1327
1337
|
|
|
1328
1338
|
```
|
|
1339
|
+
|
|
1329
1340
|
This is my custom block!
|
|
1330
1341
|
This is My Block
|
|
1331
1342
|
Hello, world!
|
|
1332
1343
|
The following fence is not registered, and will not be rendered as a custom block, but just as a regular code block.
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1344
|
+
|
|
1345
|
+
---
|
|
1346
|
+
|
|
1347
|
+
## | console.log('Hello, world!'); |
|
|
1348
|
+
|
|
1349
|
+
````
|
|
1337
1350
|
|
|
1338
1351
|
### getStaticResourceBizType
|
|
1339
1352
|
|
|
@@ -1346,7 +1359,7 @@ const renderOptions = {
|
|
|
1346
1359
|
...defaultRenderOptions,
|
|
1347
1360
|
getStaticResourceBizType: (src: string, scene: string) => 'bizType',
|
|
1348
1361
|
};
|
|
1349
|
-
|
|
1362
|
+
````
|
|
1350
1363
|
|
|
1351
1364
|
For different scenarios, you may require different `bizType`. You can return different `bizType` based on `src` and `scene`.
|
|
1352
1365
|
|
|
@@ -1401,3 +1414,16 @@ Below are the built-in multilingual keys:
|
|
|
1401
1414
|
| t-agent.input.upload.failed | MessageInput file upload | File upload failed |
|
|
1402
1415
|
| t-agent.message.feedback.success | BubbleTile message feedback | Feedback successful |
|
|
1403
1416
|
| t-agent.message.bubble.aborted | BubbleTile message | User aborted |
|
|
1417
|
+
| t-agent.message.action.copy | BubbleTile long press menu | Copy message |
|
|
1418
|
+
| t-agent.message.action.delete | BubbleTile long press menu | Delete message |
|
|
1419
|
+
| t-agent.message.action.deleteByChannel | BubbleTile long press menu | Delete all channel messages |
|
|
1420
|
+
| t-agent.message.like.success | BubbleTile feedback | Like successful |
|
|
1421
|
+
| t-agent.message.unlike.success | BubbleTile feedback | Unlike successful |
|
|
1422
|
+
|
|
1423
|
+
# Change Log
|
|
1424
|
+
|
|
1425
|
+
## Latest Version
|
|
1426
|
+
|
|
1427
|
+
- **Delete messages by channel**: Use `agent.removeMessageByChannel` method to batch delete all messages of a specific channel
|
|
1428
|
+
- **Bubble message loading animation**: Messages will display appropriate animations during loading and updating states to enhance user experience
|
|
1429
|
+
- **Bubble message long press operations**: Support copying and deleting operations by long-pressing messages, and assistant messages also support deletion by channel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent",
|
|
3
|
-
"version": "0.1.0-beta-
|
|
3
|
+
"version": "0.1.0-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": "
|
|
29
|
+
"gitHead": "afafdb05637f3c9cb46ef3ef518319baa748199e"
|
|
30
30
|
}
|