@ray-js/t-agent-plugin-aistream 0.2.8-beta.4 → 0.2.8-beta.6

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 {};
@@ -16,7 +16,7 @@ export function withBuildIn(options) {
16
16
  session,
17
17
  onTileEvent,
18
18
  onAgentStart,
19
- createMessage
19
+ onInputBlocksPush
20
20
  } = agent;
21
21
  const {
22
22
  onSkillsEnd,
@@ -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(避免被持久化)。
@@ -199,6 +194,11 @@ export function withBuildIn(options) {
199
194
  agent.plugins.ui.onEvent('audioPlayStop', () => {
200
195
  stopCurrent();
201
196
  });
197
+
198
+ // 推送新的输入块(发送新消息)时,立即停止当前语音播放
199
+ onInputBlocksPush(() => {
200
+ stopCurrent();
201
+ });
202
202
  onAttachmentCompose((part, respMsg) => {
203
203
  if (part.attachmentType === 'audio') {
204
204
  const audio = part.attachment;
@@ -278,7 +278,25 @@ export function withBuildIn(options) {
278
278
  await setPlayingMessage(messageId);
279
279
  }
280
280
  });
281
- })();
281
+ };
282
+
283
+ // 各功能默认开启,不传选项保持兼容;显式传 false 才关闭
284
+ // 关联智能家居卡片
285
+ if ((options === null || options === void 0 ? void 0 : options.smartHome) !== false) {
286
+ enableSmartHome();
287
+ }
288
+ // 关联文档
289
+ if ((options === null || options === void 0 ? void 0 : options.documents) !== false) {
290
+ enableDocuments();
291
+ }
292
+ // 图片
293
+ if ((options === null || options === void 0 ? void 0 : options.image) !== false) {
294
+ enableImage();
295
+ }
296
+ // 语音
297
+ if ((options === null || options === void 0 ? void 0 : options.audio) !== false) {
298
+ enableAudio();
299
+ }
282
300
  return {};
283
301
  };
284
302
  }
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.4",
3
+ "version": "0.2.8-beta.6",
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": "556407c77bdeb9f879a8bb9e89184fc62e4c8bd0"
39
+ "gitHead": "c79954a409ec0606a51ea4caab4ba90ee74155a7"
40
40
  }