@ray-js/t-agent-plugin-aistream 0.2.0-beta-13 → 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.
@@ -72,9 +72,11 @@ export class AIStreamConnection {
72
72
  }
73
73
  };
74
74
  this.promise = (async () => {
75
+ // 检查连接状态
75
76
  {
76
77
  const [error, result] = await tryCatch(() => isConnected(this.options));
77
78
  if (error) {
79
+ this.promise = null;
78
80
  throw new AIStreamConnectionError(error.message, error.code || AIStreamErrorCode.AIStreamError);
79
81
  }
80
82
  if (result.connected) {
@@ -84,10 +86,12 @@ export class AIStreamConnection {
84
86
  return;
85
87
  }
86
88
  }
89
+
90
+ // 未连接的情况,调用 connect
87
91
  {
88
- // 调用 SDK connect
89
92
  const [error, result] = await tryCatch(() => connect(this.options));
90
93
  if (error) {
94
+ this.promise = null;
91
95
  throw new AIStreamConnectionError(error.message, error.code || AIStreamErrorCode.AIStreamError);
92
96
  }
93
97
  this.connectionId = result.connectionId;
@@ -181,38 +185,41 @@ export class AIStreamSession {
181
185
  return Promise.resolve();
182
186
  }
183
187
  this.promise = (async () => {
184
- await this.connection._ensureConnected();
185
- let ownerId = this.options.ownerId;
186
- if (!ownerId) {
187
- if (this.connection.options.clientType === ConnectClientType.APP) {
188
- const {
189
- homeId
190
- } = await getCurrentHomeInfo();
191
- ownerId = homeId;
192
- } else {
193
- ownerId = this.connection.options.deviceId;
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;
194
201
  }
195
- this.options.ownerId = ownerId;
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;
196
222
  }
197
- const options = _objectSpread({
198
- bizTag: BizTag.DEFAULT,
199
- ownerId,
200
- extParams: {}
201
- }, this.options);
202
- const {
203
- agentToken,
204
- bizConfig
205
- } = await queryAgentToken(options);
206
- const res = await createSession({
207
- bizTag: options.bizTag,
208
- agentToken,
209
- bizConfig,
210
- userData: options.userData
211
- });
212
- this.sessionId = res.sessionId;
213
- this.sendDataChannels = res.sendDataChannels;
214
- this.revDataChannels = res.revDataChannels;
215
- this.promise = null;
216
223
  })();
217
224
  return this.promise;
218
225
  }
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-13",
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": "ad4d4b4637a4a5396bcf5adf21adcbf215561436"
38
+ "gitHead": "2fdaf9e5abc36632f003b7060ada22390cda132b"
39
39
  }