@ray-js/t-agent-plugin-aistream 0.2.8-beta.4 → 0.2.8-beta.5
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.
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { ChatAgent } from '@ray-js/t-agent';
|
|
2
2
|
interface WithBuildInOptions {
|
|
3
|
+
/** 是否开启 TTS 自动播放,默认 false */
|
|
3
4
|
audioAutoPlay?: boolean;
|
|
5
|
+
/** 是否开启智能家居技能(设备控制、场景管理),默认 true */
|
|
6
|
+
smartHome?: boolean;
|
|
7
|
+
/** 是否开启知识库关联文档展示,默认 true */
|
|
8
|
+
documents?: boolean;
|
|
9
|
+
/** 是否开启图片附件展示,默认 true */
|
|
10
|
+
image?: boolean;
|
|
11
|
+
/** 是否开启 TTS 语音播放能力,默认 true */
|
|
12
|
+
audio?: boolean;
|
|
4
13
|
}
|
|
5
14
|
export declare function withBuildIn(options?: WithBuildInOptions): (_agent: ChatAgent) => {};
|
|
6
15
|
export {};
|
|
@@ -33,9 +33,38 @@ export function withBuildIn(options) {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// 关联文档
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const enableDocuments = () => {
|
|
37
|
+
onSkillsEnd((skills, responseMessage) => {
|
|
38
|
+
if (!responseMessage) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const data = {
|
|
42
|
+
documents: []
|
|
43
|
+
};
|
|
44
|
+
for (let i = 0; i < skills.length; i++) {
|
|
45
|
+
var _content$custom;
|
|
46
|
+
const skill = skills[i];
|
|
47
|
+
if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const content = skill;
|
|
51
|
+
if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
for (let i1 = 0; i1 < content.custom.data.documents.length; i1++) {
|
|
55
|
+
const doc = content.custom.data.documents[i1];
|
|
56
|
+
data.documents.push({
|
|
57
|
+
title: doc.title,
|
|
58
|
+
url: doc.url
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (data.documents.length) {
|
|
63
|
+
responseMessage.bubble.addTile('documents', data);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const enableSmartHome = () => {
|
|
39
68
|
onSkillsEnd((skills, responseMessage) => {
|
|
40
69
|
if (!responseMessage) {
|
|
41
70
|
return;
|
|
@@ -117,41 +146,8 @@ export function withBuildIn(options) {
|
|
|
117
146
|
responseMessage.bubble.addTile('operateCard', operateData);
|
|
118
147
|
}
|
|
119
148
|
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
(() => {
|
|
123
|
-
onSkillsEnd((skills, responseMessage) => {
|
|
124
|
-
if (!responseMessage) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const data = {
|
|
128
|
-
documents: []
|
|
129
|
-
};
|
|
130
|
-
for (let i = 0; i < skills.length; i++) {
|
|
131
|
-
var _content$custom;
|
|
132
|
-
const skill = skills[i];
|
|
133
|
-
if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const content = skill;
|
|
137
|
-
if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
for (let i1 = 0; i1 < content.custom.data.documents.length; i1++) {
|
|
141
|
-
const doc = content.custom.data.documents[i1];
|
|
142
|
-
data.documents.push({
|
|
143
|
-
title: doc.title,
|
|
144
|
-
url: doc.url
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (data.documents.length) {
|
|
149
|
-
responseMessage.bubble.addTile('documents', data);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
})();
|
|
153
|
-
// 图片
|
|
154
|
-
(() => {
|
|
149
|
+
};
|
|
150
|
+
const enableImage = () => {
|
|
155
151
|
onAttachmentsEnd((parts, respMsg) => {
|
|
156
152
|
const streamSession = session.get('AIStream.streamSession');
|
|
157
153
|
const prefix = streamSession.baseCacheDir;
|
|
@@ -166,9 +162,8 @@ export function withBuildIn(options) {
|
|
|
166
162
|
}
|
|
167
163
|
});
|
|
168
164
|
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
(() => {
|
|
165
|
+
};
|
|
166
|
+
const enableAudio = () => {
|
|
172
167
|
// 当前正在播放的消息 id 保存在 session 中,保证同一时刻只播一条;
|
|
173
168
|
// 组件里的 playing 状态从 session 的 audioPlaying / playingMessageId 派生。
|
|
174
169
|
// playing 是纯运行时状态,不落到 tile.data(避免被持久化)。
|
|
@@ -278,7 +273,25 @@ export function withBuildIn(options) {
|
|
|
278
273
|
await setPlayingMessage(messageId);
|
|
279
274
|
}
|
|
280
275
|
});
|
|
281
|
-
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// 各功能默认开启,不传选项保持兼容;显式传 false 才关闭
|
|
279
|
+
// 关联智能家居卡片
|
|
280
|
+
if ((options === null || options === void 0 ? void 0 : options.smartHome) !== false) {
|
|
281
|
+
enableSmartHome();
|
|
282
|
+
}
|
|
283
|
+
// 关联文档
|
|
284
|
+
if ((options === null || options === void 0 ? void 0 : options.documents) !== false) {
|
|
285
|
+
enableDocuments();
|
|
286
|
+
}
|
|
287
|
+
// 图片
|
|
288
|
+
if ((options === null || options === void 0 ? void 0 : options.image) !== false) {
|
|
289
|
+
enableImage();
|
|
290
|
+
}
|
|
291
|
+
// 语音
|
|
292
|
+
if ((options === null || options === void 0 ? void 0 : options.audio) !== false) {
|
|
293
|
+
enableAudio();
|
|
294
|
+
}
|
|
282
295
|
return {};
|
|
283
296
|
};
|
|
284
297
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-plugin-aistream",
|
|
3
|
-
"version": "0.2.8-beta.
|
|
3
|
+
"version": "0.2.8-beta.5",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/url-parse": "^1.4.11"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "433a3716af02d01c19f670855e62000fcae37d34"
|
|
40
40
|
}
|