@ray-js/t-agent-plugin-aistream 0.2.0-beta-12 → 0.2.0-beta-14
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/utils/AIStream.js +40 -32
- package/dist/withAIStream.js +1 -1
- package/package.json +2 -2
package/dist/utils/AIStream.js
CHANGED
|
@@ -34,7 +34,8 @@ export class AIStreamConnection {
|
|
|
34
34
|
_defineProperty(this, "promise", null);
|
|
35
35
|
_defineProperty(this, "observer", null);
|
|
36
36
|
_defineProperty(this, "onStateChanged", entry => {
|
|
37
|
-
|
|
37
|
+
// 一个小程序只能启动一个 connection,所以这里不判断 id
|
|
38
|
+
if (entry.type === 'connectionState') {
|
|
38
39
|
this.state = entry.body.connectState;
|
|
39
40
|
this.activeSessions.forEach(session => {
|
|
40
41
|
if (session.sessionId) {
|
|
@@ -71,9 +72,11 @@ export class AIStreamConnection {
|
|
|
71
72
|
}
|
|
72
73
|
};
|
|
73
74
|
this.promise = (async () => {
|
|
75
|
+
// 检查连接状态
|
|
74
76
|
{
|
|
75
77
|
const [error, result] = await tryCatch(() => isConnected(this.options));
|
|
76
78
|
if (error) {
|
|
79
|
+
this.promise = null;
|
|
77
80
|
throw new AIStreamConnectionError(error.message, error.code || AIStreamErrorCode.AIStreamError);
|
|
78
81
|
}
|
|
79
82
|
if (result.connected) {
|
|
@@ -83,10 +86,12 @@ export class AIStreamConnection {
|
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
89
|
+
|
|
90
|
+
// 未连接的情况,调用 connect
|
|
86
91
|
{
|
|
87
|
-
// 调用 SDK connect
|
|
88
92
|
const [error, result] = await tryCatch(() => connect(this.options));
|
|
89
93
|
if (error) {
|
|
94
|
+
this.promise = null;
|
|
90
95
|
throw new AIStreamConnectionError(error.message, error.code || AIStreamErrorCode.AIStreamError);
|
|
91
96
|
}
|
|
92
97
|
this.connectionId = result.connectionId;
|
|
@@ -180,38 +185,41 @@ export class AIStreamSession {
|
|
|
180
185
|
return Promise.resolve();
|
|
181
186
|
}
|
|
182
187
|
this.promise = (async () => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
try {
|
|
189
|
+
await this.connection._ensureConnected();
|
|
190
|
+
let ownerId = this.options.ownerId;
|
|
191
|
+
if (!ownerId) {
|
|
192
|
+
if (this.connection.options.clientType === ConnectClientType.APP) {
|
|
193
|
+
const {
|
|
194
|
+
homeId
|
|
195
|
+
} = await getCurrentHomeInfo();
|
|
196
|
+
ownerId = homeId;
|
|
197
|
+
} else {
|
|
198
|
+
ownerId = this.connection.options.deviceId;
|
|
199
|
+
}
|
|
200
|
+
this.options.ownerId = ownerId;
|
|
193
201
|
}
|
|
194
|
-
|
|
202
|
+
const options = _objectSpread({
|
|
203
|
+
bizTag: BizTag.DEFAULT,
|
|
204
|
+
ownerId,
|
|
205
|
+
extParams: {}
|
|
206
|
+
}, this.options);
|
|
207
|
+
const {
|
|
208
|
+
agentToken,
|
|
209
|
+
bizConfig
|
|
210
|
+
} = await queryAgentToken(options);
|
|
211
|
+
const res = await createSession({
|
|
212
|
+
bizTag: options.bizTag,
|
|
213
|
+
agentToken,
|
|
214
|
+
bizConfig,
|
|
215
|
+
userData: options.userData
|
|
216
|
+
});
|
|
217
|
+
this.sessionId = res.sessionId;
|
|
218
|
+
this.sendDataChannels = res.sendDataChannels;
|
|
219
|
+
this.revDataChannels = res.revDataChannels;
|
|
220
|
+
} finally {
|
|
221
|
+
this.promise = null;
|
|
195
222
|
}
|
|
196
|
-
const options = _objectSpread({
|
|
197
|
-
bizTag: BizTag.DEFAULT,
|
|
198
|
-
ownerId,
|
|
199
|
-
extParams: {}
|
|
200
|
-
}, this.options);
|
|
201
|
-
const {
|
|
202
|
-
agentToken,
|
|
203
|
-
bizConfig
|
|
204
|
-
} = await queryAgentToken(options);
|
|
205
|
-
const res = await createSession({
|
|
206
|
-
bizTag: options.bizTag,
|
|
207
|
-
agentToken,
|
|
208
|
-
bizConfig,
|
|
209
|
-
userData: options.userData
|
|
210
|
-
});
|
|
211
|
-
this.sessionId = res.sessionId;
|
|
212
|
-
this.sendDataChannels = res.sendDataChannels;
|
|
213
|
-
this.revDataChannels = res.revDataChannels;
|
|
214
|
-
this.promise = null;
|
|
215
223
|
})();
|
|
216
224
|
return this.promise;
|
|
217
225
|
}
|
package/dist/withAIStream.js
CHANGED
|
@@ -288,7 +288,7 @@ export function withAIStream() {
|
|
|
288
288
|
});
|
|
289
289
|
const onError = async () => {
|
|
290
290
|
end = true;
|
|
291
|
-
if (userMsg.isShow) {
|
|
291
|
+
if (userMsg.isShow && userMsg.status !== ChatMessageStatus.FINISH) {
|
|
292
292
|
await userMsg.remove();
|
|
293
293
|
}
|
|
294
294
|
audioEmitter.removeEventListener('error', onError);
|
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-
|
|
3
|
+
"version": "0.2.0-beta-14",
|
|
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": "2fdaf9e5abc36632f003b7060ada22390cda132b"
|
|
39
39
|
}
|