@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.
- package/dist/AIStreamTypes.d.ts +5 -5
- package/dist/buildIn/withBuildIn.js +10 -10
- package/dist/utils/AIStream.js +3 -1
- package/dist/utils/observer.d.ts +5 -1
- package/dist/utils/observer.js +21 -14
- package/dist/withAIStream.js +20 -2
- package/package.json +2 -2
package/dist/AIStreamTypes.d.ts
CHANGED
|
@@ -1601,17 +1601,17 @@ export type ReceivedSearchKnowledgeSkill = ReceivedTextSkillPacketBody<BuildInSk
|
|
|
1601
1601
|
};
|
|
1602
1602
|
}>;
|
|
1603
1603
|
export interface ReceivedSmartHomeSkillDevice {
|
|
1604
|
-
|
|
1605
|
-
|
|
1604
|
+
devId: string;
|
|
1605
|
+
devIcon: string;
|
|
1606
1606
|
dps?: Record<string, string>;
|
|
1607
|
-
|
|
1607
|
+
devName: string;
|
|
1608
1608
|
room: string;
|
|
1609
1609
|
success: boolean;
|
|
1610
1610
|
}
|
|
1611
1611
|
export interface ReceivedSmartHomeSkillScene {
|
|
1612
1612
|
sceneId: string;
|
|
1613
|
-
|
|
1614
|
-
|
|
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.
|
|
94
|
-
name: scene.
|
|
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.
|
|
107
|
-
name: scene.
|
|
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.
|
|
119
|
-
name: dev.
|
|
120
|
-
deviceId: dev.
|
|
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.
|
|
130
|
-
name: dev.
|
|
131
|
-
deviceId: dev.
|
|
129
|
+
icon: dev.devIcon,
|
|
130
|
+
name: dev.devName,
|
|
131
|
+
deviceId: dev.devId,
|
|
132
132
|
intent: 'controlDevice',
|
|
133
133
|
success: null
|
|
134
134
|
});
|
package/dist/utils/AIStream.js
CHANGED
package/dist/utils/observer.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/observer.js
CHANGED
|
@@ -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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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) {
|
package/dist/withAIStream.js
CHANGED
|
@@ -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.
|
|
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": "
|
|
38
|
+
"gitHead": "d2a87bb209c5649e75bc765a8174849274cda82e"
|
|
39
39
|
}
|