@ray-js/t-agent-plugin-aistream 0.2.0-beta.20 → 0.2.1-beta-1

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.
@@ -1601,17 +1601,17 @@ export type ReceivedSearchKnowledgeSkill = ReceivedTextSkillPacketBody<BuildInSk
1601
1601
  };
1602
1602
  }>;
1603
1603
  export interface ReceivedSmartHomeSkillDevice {
1604
- deviceId: string;
1605
- icon: string;
1604
+ devId: string;
1605
+ devIcon: string;
1606
1606
  dps?: Record<string, string>;
1607
- name: string;
1607
+ devName: string;
1608
1608
  room: string;
1609
1609
  success: boolean;
1610
1610
  }
1611
1611
  export interface ReceivedSmartHomeSkillScene {
1612
1612
  sceneId: string;
1613
- name: string;
1614
- icon: string;
1613
+ sceneName: string;
1614
+ sceneIcon: string;
1615
1615
  type: number;
1616
1616
  valid: boolean;
1617
1617
  displayColor: string;
@@ -90,8 +90,8 @@ export function withBuildIn() {
90
90
  data.sceneInfo.push({
91
91
  type: scene.type,
92
92
  enabled: scene.enable,
93
- icon: scene.icon,
94
- name: scene.name,
93
+ icon: scene.sceneIcon,
94
+ name: scene.sceneName,
95
95
  sceneId: scene.sceneId,
96
96
  intent: 'queryScene',
97
97
  valid: scene.valid,
@@ -103,8 +103,8 @@ export function withBuildIn() {
103
103
  for (const scene of content.general.data.scenes) {
104
104
  data.sceneInfo.push({
105
105
  type: scene.type,
106
- icon: scene.icon,
107
- name: scene.name,
106
+ icon: scene.sceneIcon,
107
+ name: scene.sceneName,
108
108
  sceneId: scene.sceneId,
109
109
  intent: 'controlScene',
110
110
  valid: scene.valid,
@@ -115,9 +115,9 @@ export function withBuildIn() {
115
115
  } else if (content.general.action === ReceivedSmartHomeSkillAction.QUERY_DEVICE) {
116
116
  for (const dev of content.general.data.devices) {
117
117
  data.deviceInfo.push({
118
- icon: dev.icon,
119
- name: dev.name,
120
- deviceId: dev.deviceId,
118
+ icon: dev.devIcon,
119
+ name: dev.devName,
120
+ deviceId: dev.devId,
121
121
  intent: 'queryDevice',
122
122
  room: dev.room,
123
123
  success: dev.success
@@ -126,9 +126,9 @@ export function withBuildIn() {
126
126
  } else if (content.general.action === ReceivedSmartHomeSkillAction.CONTROL_DEVICE) {
127
127
  for (const dev of content.general.data.devices) {
128
128
  data.deviceInfo.push({
129
- icon: dev.icon,
130
- name: dev.name,
131
- deviceId: dev.deviceId,
129
+ icon: dev.devIcon,
130
+ name: dev.devName,
131
+ deviceId: dev.devId,
132
132
  intent: 'controlDevice',
133
133
  success: null
134
134
  });
@@ -418,7 +418,9 @@ export class AIStreamEvent {
418
418
  path: chunk.path,
419
419
  userData: chunk.userData
420
420
  }));
421
- throw error;
421
+ if (error) {
422
+ throw error;
423
+ }
422
424
  }
423
425
  sendEventPayloadEnd({
424
426
  eventId: this.eventId,
@@ -1,4 +1,4 @@
1
- import { AudioBody, ConnectStateBody, EventBody, FileBody, ImageBody, SessionStateBody, TextBody, VideoBody } from '../AIStreamTypes';
1
+ import { AudioBody, ConnectStateBody, EventBody, FileBody, ImageBody, RecordAmplitudesBody, SessionStateBody, TextBody, VideoBody } from '../AIStreamTypes';
2
2
  export type AIStreamDataEntry = {
3
3
  type: 'text';
4
4
  body: TextBody;
@@ -23,6 +23,9 @@ export type AIStreamDataEntry = {
23
23
  } | {
24
24
  type: 'sessionState';
25
25
  body: SessionStateBody;
26
+ } | {
27
+ type: 'amplitudes';
28
+ body: RecordAmplitudesBody;
26
29
  };
27
30
  export interface AIStreamObserverOptions {
28
31
  sessionState?: boolean;
@@ -35,6 +38,7 @@ export interface AIStreamObserverOptions {
35
38
  image?: boolean;
36
39
  dataChannels?: string[];
37
40
  sessionId?: string;
41
+ amplitudes?: boolean;
38
42
  }
39
43
  export declare class AIStreamObserverPool {
40
44
  isStarted: boolean;
@@ -3,9 +3,9 @@ import "core-js/modules/esnext.iterator.constructor.js";
3
3
  import "core-js/modules/esnext.iterator.for-each.js";
4
4
  import "core-js/modules/web.dom-collections.iterator.js";
5
5
  import { ConnectState, EventType, SessionState, StreamFlag } from '../AIStreamTypes';
6
- import { listenAudioReceived, listenConnectStateChanged, listenEventReceived, listenImageReceived, listenSessionStateChanged, listenTextReceived } from './ttt';
6
+ import { listenAudioReceived, listenConnectStateChanged, listenEventReceived, listenImageReceived, listenRecordAmplitudes, listenSessionStateChanged, listenTextReceived } from './ttt';
7
7
  import logger from './logger';
8
- const types = ['connectionState', 'sessionState', 'event', 'text', 'audio', 'video', 'file', 'image'];
8
+ const types = ['connectionState', 'sessionState', 'event', 'text', 'audio', 'video', 'file', 'image', 'amplitudes'];
9
9
  export class AIStreamObserverPool {
10
10
  constructor() {
11
11
  _defineProperty(this, "isStarted", false);
@@ -18,7 +18,8 @@ export class AIStreamObserverPool {
18
18
  audio: new Set(),
19
19
  video: new Set(),
20
20
  file: new Set(),
21
- image: new Set()
21
+ image: new Set(),
22
+ amplitudes: new Set()
22
23
  };
23
24
  }
24
25
  start() {
@@ -26,19 +27,21 @@ export class AIStreamObserverPool {
26
27
  return;
27
28
  }
28
29
  const handle = entry => {
29
- var _entry$body;
30
30
  const observers = this.observerMap[entry.type];
31
31
  let state = '';
32
- if (entry.type === 'connectionState') {
33
- state = "".concat(ConnectState[entry.body.connectState], " ").concat(entry.body.code || '');
34
- } else if (entry.type === 'sessionState') {
35
- state = "".concat(SessionState[entry.body.sessionState], " ").concat(entry.body.code || '');
36
- } else if (entry.type === 'event') {
37
- state = "".concat(EventType[entry.body.eventType]);
38
- } else if ((_entry$body = entry.body) !== null && _entry$body !== void 0 && _entry$body.streamFlag) {
39
- state = "".concat(StreamFlag[entry.body.streamFlag]);
32
+ if (entry.type !== 'amplitudes') {
33
+ var _entry$body;
34
+ if (entry.type === 'connectionState') {
35
+ state = "".concat(ConnectState[entry.body.connectState], " ").concat(entry.body.code || '');
36
+ } else if (entry.type === 'sessionState') {
37
+ state = "".concat(SessionState[entry.body.sessionState], " ").concat(entry.body.code || '');
38
+ } else if (entry.type === 'event') {
39
+ state = "".concat(EventType[entry.body.eventType]);
40
+ } else if ((_entry$body = entry.body) !== null && _entry$body !== void 0 && _entry$body.streamFlag) {
41
+ state = "".concat(StreamFlag[entry.body.streamFlag]);
42
+ }
43
+ logger.debug("Pool received: %c".concat(observers.size ? '⊕' : '×').concat(entry.type, " ").concat(state), 'background: black; color: white', entry);
40
44
  }
41
- logger.debug("Pool received: %c".concat(observers.size ? '⊕' : '×').concat(entry.type, " ").concat(state), 'background: black; color: white', entry);
42
45
  observers.forEach(observer => {
43
46
  if (entry.type === 'text' || entry.type === 'audio' || entry.type === 'video' || entry.type === 'file' || entry.type === 'image') {
44
47
  const {
@@ -78,6 +81,9 @@ export class AIStreamObserverPool {
78
81
  })), listenImageReceived(body => handle({
79
82
  type: 'image',
80
83
  body
84
+ })), listenRecordAmplitudes(body => handle({
85
+ type: 'amplitudes',
86
+ body
81
87
  }))
82
88
  // listenVideoReceived(body => handle({ type: 'video', body })),
83
89
  // listenFileReceived(body => handle({ type: 'file', body })),
@@ -96,7 +102,8 @@ export class AIStreamObserverPool {
96
102
  audio: new Set(),
97
103
  video: new Set(),
98
104
  file: new Set(),
99
- image: new Set()
105
+ image: new Set(),
106
+ amplitudes: new Set()
100
107
  };
101
108
  }
102
109
  connect(observer) {
@@ -9,8 +9,8 @@ import "core-js/modules/esnext.iterator.map.js";
9
9
  import "core-js/modules/web.dom-collections.iterator.js";
10
10
  import { BubbleTileStatus, ChatMessageStatus, createHooks, EmitterEvent } from '@ray-js/t-agent';
11
11
  import { messageAppraise } from './utils/apis';
12
- import { getAccountInfo, getCurrentHomeInfo, runTTTAction, sendBlocksToAIStream } from './utils';
13
- import { BizCode, ConnectClientType } from './AIStreamTypes';
12
+ import { AIStreamObserver, getAccountInfo, getCurrentHomeInfo, runTTTAction, sendBlocksToAIStream } from './utils';
13
+ import { BizCode, ConnectClientType, ConnectState } from './AIStreamTypes';
14
14
  import { ChatHistoryLocalStore } from './ChatHistoryStore';
15
15
  import { DEFAULT_TOKEN_API, DEFAULT_TOKEN_API_VERSION, globalAIStreamClient } from './global';
16
16
  import logger from './utils/logger';
@@ -110,6 +110,20 @@ export function withAIStream() {
110
110
  logger.error('earlyStart failed', error);
111
111
  });
112
112
  }
113
+ const observer = new AIStreamObserver(data => {
114
+ if (data.type === 'amplitudes') {
115
+ ui.emitEvent('amplitudes', data);
116
+ } else if (data.type === 'connectionState') {
117
+ ui.emitEvent('networkChange', {
118
+ online: data.body.connectState === ConnectState.CONNECTED
119
+ });
120
+ }
121
+ }, globalAIStreamClient.pool);
122
+ observer.observe({
123
+ connectionState: true,
124
+ amplitudes: true
125
+ });
126
+ await session.set('AIStream.observer', observer);
113
127
  });
114
128
  const getHistoryStore = () => {
115
129
  const historyStore = session.get('AIStream.historyStore');
@@ -391,6 +405,10 @@ export function withAIStream() {
391
405
  };
392
406
  });
393
407
  onAgentDispose(async () => {
408
+ const observer = session.get('AIStream.observer');
409
+ if (observer) {
410
+ observer.disconnect();
411
+ }
394
412
  const streamSession = session.get('AIStream.streamSession');
395
413
 
396
414
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-plugin-aistream",
3
- "version": "0.2.0-beta.20",
3
+ "version": "0.2.1-beta-1",
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": "517ce9d6aec8ac6a1ade692df773750d0c7738cf"
38
+ "gitHead": "d2a87bb209c5649e75bc765a8174849274cda82e"
39
39
  }