@ray-js/t-agent-plugin-aistream 0.2.2-beta-1 → 0.2.2-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.
@@ -41,41 +41,18 @@ export function withBuildIn() {
41
41
 
42
42
  // 关联文档
43
43
 
44
+ // 关联智能家居卡片
44
45
  (() => {
45
46
  onSkillsEnd((skills, responseMessage) => {
46
47
  if (!responseMessage) {
47
48
  return;
48
49
  }
49
- const data = {
50
- documents: []
50
+ const operateData = {
51
+ deviceInfo: [],
52
+ sceneInfo: [],
53
+ changeInfo: []
51
54
  };
52
- for (const skill of skills) {
53
- var _content$custom;
54
- if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
55
- continue;
56
- }
57
- const content = skill;
58
- if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
59
- continue;
60
- }
61
- for (const doc of content.custom.data.documents) {
62
- data.documents.push({
63
- title: doc.title,
64
- url: doc.url
65
- });
66
- }
67
- }
68
- if (data.documents.length) {
69
- responseMessage.bubble.addTile('documents', data);
70
- }
71
- });
72
- })();
73
- (() => {
74
- onSkillsEnd((skills, responseMessage) => {
75
- if (!responseMessage) {
76
- return;
77
- }
78
- const data = {
55
+ const executeData = {
79
56
  deviceInfo: [],
80
57
  sceneInfo: [],
81
58
  changeInfo: []
@@ -87,7 +64,7 @@ export function withBuildIn() {
87
64
  const content = skill;
88
65
  if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_SCENE) {
89
66
  for (const scene of content.general.data.scenes) {
90
- data.sceneInfo.push({
67
+ executeData.sceneInfo.push({
91
68
  type: scene.type,
92
69
  enabled: scene.enable,
93
70
  icon: scene.icon,
@@ -101,7 +78,7 @@ export function withBuildIn() {
101
78
  }
102
79
  } else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_SCENE) {
103
80
  for (const scene of content.general.data.scenes) {
104
- data.sceneInfo.push({
81
+ operateData.sceneInfo.push({
105
82
  type: scene.type,
106
83
  icon: scene.icon,
107
84
  name: scene.name,
@@ -114,7 +91,7 @@ export function withBuildIn() {
114
91
  }
115
92
  } else if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_DEVICE) {
116
93
  for (const dev of content.general.data.devices) {
117
- data.deviceInfo.push({
94
+ executeData.deviceInfo.push({
118
95
  icon: dev.icon,
119
96
  name: dev.name,
120
97
  deviceId: dev.deviceId,
@@ -125,7 +102,7 @@ export function withBuildIn() {
125
102
  }
126
103
  } else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_DEVICE) {
127
104
  for (const dev of content.general.data.devices) {
128
- data.deviceInfo.push({
105
+ operateData.deviceInfo.push({
129
106
  icon: dev.icon,
130
107
  name: dev.name,
131
108
  deviceId: dev.deviceId,
@@ -135,8 +112,41 @@ export function withBuildIn() {
135
112
  }
136
113
  }
137
114
  }
138
- if (data.deviceInfo.length) {
139
- responseMessage.bubble.addTile('operateCard', data);
115
+ if (executeData.deviceInfo.length || executeData.sceneInfo.length || executeData.changeInfo.length) {
116
+ responseMessage.bubble.addTile('executeCard', executeData);
117
+ }
118
+ if (operateData.deviceInfo.length || operateData.sceneInfo.length || operateData.changeInfo.length) {
119
+ responseMessage.bubble.addTile('operateCard', operateData);
120
+ }
121
+ });
122
+ })();
123
+ // 最后是关联文档
124
+ (() => {
125
+ onSkillsEnd((skills, responseMessage) => {
126
+ if (!responseMessage) {
127
+ return;
128
+ }
129
+ const data = {
130
+ documents: []
131
+ };
132
+ for (const skill of skills) {
133
+ var _content$custom;
134
+ if (skill.code !== BuildInSkillCode.SEARCH_KNOWLEDGE) {
135
+ continue;
136
+ }
137
+ const content = skill;
138
+ if (!((_content$custom = content.custom) !== null && _content$custom !== void 0 && (_content$custom = _content$custom.data) !== null && _content$custom !== void 0 && _content$custom.documents)) {
139
+ continue;
140
+ }
141
+ for (const doc of content.custom.data.documents) {
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);
140
150
  }
141
151
  });
142
152
  })();
@@ -1,4 +1,4 @@
1
- import { ChatAgent, ChatMessage, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
1
+ import { ChatAgent, ChatCardObject, ChatMessage, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
2
2
  import { ConnectClientType, ReceivedTextSkillPacketBody } from './AIStreamTypes';
3
3
  import { ChatHistoryLocalStore, StoredMessageObject } from './ChatHistoryStore';
4
4
  export interface AIStreamOptions {
@@ -40,6 +40,9 @@ export interface AIStreamHooks {
40
40
  onSkillsEnd: (skills: ReceivedTextSkillPacketBody[], respMsg: ChatMessage, result: {
41
41
  messages: ChatMessage[];
42
42
  }) => void;
43
+ onCardsReceived: (skills: ReceivedTextSkillPacketBody[], result: {
44
+ cards: ChatCardObject[];
45
+ }) => void;
43
46
  }
44
47
  export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAgent) => {
45
48
  hooks: import("hookable").Hookable<any, string>;
@@ -58,6 +61,7 @@ export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAge
58
61
  clearAllMessages: () => Promise<void>;
59
62
  onSkillCompose: (fn: AIStreamHooks['onSkillCompose']) => () => void;
60
63
  onSkillsEnd: (fn: AIStreamHooks['onSkillsEnd']) => () => void;
64
+ onCardsReceived: (fn: AIStreamHooks['onCardsReceived']) => () => void;
61
65
  feedback: ({ requestId, type }: {
62
66
  requestId: string;
63
67
  type: string;
@@ -331,12 +331,24 @@ export function withAIStream() {
331
331
  await hooks.callHook('onSkillsEnd', skills, message, result);
332
332
  await message.update();
333
333
  }
334
+ let valid = false;
334
335
  if (message.bubble.text) {
336
+ valid = true;
335
337
  await message.persist();
336
338
  } else if (message.bubble.status === BubbleTileStatus.NORMAL) {
337
- await message.remove();
339
+ valid = false;
338
340
  } else {
341
+ valid = true;
342
+ }
343
+ if (valid) {
339
344
  await message.persist();
345
+ const [_, ...rest] = result.messages;
346
+ for (const m of rest) {
347
+ await m.show();
348
+ await m.persist();
349
+ }
350
+ } else {
351
+ await message.remove();
340
352
  }
341
353
  return [userMsg, ...result.messages];
342
354
  };
@@ -452,6 +464,43 @@ export function withAIStream() {
452
464
  }
453
465
  }
454
466
  });
467
+ const onSkillsEnd = fn => {
468
+ return hooks.hook('onSkillsEnd', fn);
469
+ };
470
+ onSkillsEnd(async (skills, respMsg, result) => {
471
+ const cards = [];
472
+ for (const skill of skills) {
473
+ var _skill$custom, _skill$general;
474
+ if ((_skill$custom = skill.custom) !== null && _skill$custom !== void 0 && (_skill$custom = _skill$custom.data) !== null && _skill$custom !== void 0 && _skill$custom.aiCards) {
475
+ for (const card of skill.custom.data.aiCards) {
476
+ cards.push(card);
477
+ }
478
+ }
479
+ if ((_skill$general = skill.general) !== null && _skill$general !== void 0 && (_skill$general = _skill$general.data) !== null && _skill$general !== void 0 && _skill$general.aiCards) {
480
+ for (const card of skill.custom.data.aiCards) {
481
+ cards.push(card);
482
+ }
483
+ }
484
+ }
485
+ const r = {
486
+ cards: cards
487
+ };
488
+ await hooks.callHook('onCardsReceived', skills, r);
489
+ for (const card of cards) {
490
+ const m = createMessage({
491
+ role: respMsg.role,
492
+ status: ChatMessageStatus.FINISH,
493
+ meta: {
494
+ eventId: respMsg.meta.eventId,
495
+ sessionId: respMsg.meta.sessionId
496
+ }
497
+ });
498
+ m.addTile('card', {
499
+ card
500
+ });
501
+ result.messages.push(m);
502
+ }
503
+ });
455
504
  return {
456
505
  hooks,
457
506
  aiStream: {
@@ -472,8 +521,9 @@ export function withAIStream() {
472
521
  onSkillCompose: fn => {
473
522
  return hooks.hook('onSkillCompose', fn);
474
523
  },
475
- onSkillsEnd: fn => {
476
- return hooks.hook('onSkillsEnd', fn);
524
+ onSkillsEnd,
525
+ onCardsReceived: fn => {
526
+ return hooks.hook('onCardsReceived', fn);
477
527
  },
478
528
  feedback
479
529
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.2-beta-1",
3
+ "version": "0.2.2-beta-2",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@types/url-parse": "^1.4.11"
37
37
  },
38
- "gitHead": "0dd513ad93a351ad5c00a1ee8993c7b62f03640f"
38
+ "gitHead": "33a1985d3a14487fe5f354411b0c46c8a8af19c7"
39
39
  }