agent-bridge-qwenwork 1.0.21 → 1.0.22

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.
@@ -261,7 +261,34 @@ class QwenCdpClient {
261
261
  return { text: reply, ...(attachments.length ? { attachments } : {}) };
262
262
  }
263
263
  }
264
- throw new Error("千问办公 UI 超时未返回回复");
264
+ const permission = await this.permissionStatus(sessionUrl);
265
+ throw new Error(permission ?? `QWEN_REPLY_TIMEOUT:千问办公 UI 超时未返回回复(已等待 ${Math.round(timeoutMs / 1000)} 秒);桌面任务未被停止`);
266
+ }
267
+ async permissionStatus(sessionUrl) {
268
+ try {
269
+ if (await this.evaluate("typeof window !== 'undefined' && Boolean(window.electronTRPC)") !== true)
270
+ return;
271
+ const chatId = new URL(sessionUrl).searchParams.get("chat");
272
+ if (!chatId)
273
+ return;
274
+ const response = await this.trpc("agent.getAllStreamingStates", "query", {});
275
+ const states = response.result?.data?.json;
276
+ if (!Array.isArray(states))
277
+ return;
278
+ for (const state of states) {
279
+ if (typeof state?.chatId !== "string" || !chatId.endsWith(state.chatId) || !state.chatId || !Array.isArray(state.pendingInteractions))
280
+ continue;
281
+ for (const interaction of state.pendingInteractions) {
282
+ if (interaction?.kind !== "permission")
283
+ continue;
284
+ const input = interaction.toolInput;
285
+ const details = [interaction.toolName, input?.operation, input?.path].filter(value => typeof value === "string").join(" · ");
286
+ return `QWEN_PERMISSION_REQUIRED:千问办公正在等待权限确认(${details});请在千问桌面中确认或拒绝,当前任务未被停止`;
287
+ }
288
+ }
289
+ }
290
+ catch { /* 旧版客户端不支持该只读接口时,保留原始超时信息。 */ }
291
+ return;
265
292
  }
266
293
  async injectAttachments(items) {
267
294
  const files = items.map(item => {
@@ -458,11 +485,23 @@ class QwenCdpClient {
458
485
  pending.resolve(message);
459
486
  }
460
487
  async ensureVisible() {
461
- await this.evaluate(`(async () => {
488
+ try {
489
+ await this.evaluate(`(async () => {
462
490
  if (document.querySelector('button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]')) throw new Error('千问桌面端正在生成回复');
463
491
  // 隐藏窗口会暂停消息渲染,使桌面端的提交前检查一直等不到确认。
464
492
  if (document.hidden && typeof window.desktopApi?.focusMainWindow === 'function') await window.desktopApi.focusMainWindow();
465
493
  })()`);
494
+ }
495
+ catch (error) {
496
+ let permission;
497
+ try {
498
+ permission = await this.permissionStatus(String(await this.evaluate("location.href")));
499
+ }
500
+ catch { /* 断线时保留原始错误。 */ }
501
+ if (permission)
502
+ throw new Error(permission);
503
+ throw error;
504
+ }
466
505
  }
467
506
  recoverDraft() {
468
507
  return (0, cdp_draft_1.recoverCdpDraft)(this.evaluate.bind(this), exports.inputSelector, 'button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]', this.options.dataDir);
@@ -9,10 +9,9 @@ const cdp_client_1 = require("./cdp-client");
9
9
  const plugin_1 = require("../../plugin");
10
10
  const desktop_launch_1 = require("../desktop-launch");
11
11
  const session_history_1 = require("./session-history");
12
- const CHAT_HEARTBEAT_INTERVAL_MS = 2 * 60 * 60_000;
13
12
  exports.qwenworkManifest = {
14
13
  id: "qwenwork",
15
- version: "1.0.21",
14
+ version: "1.0.22",
16
15
  displayName: "千问办公",
17
16
  entry: "dist/index.js",
18
17
  apiVersion: "1",
@@ -293,39 +292,13 @@ class QwenworkPlugin {
293
292
  this.healthTimer.unref();
294
293
  }
295
294
  async checkHealth() {
296
- if (this.checking || this.busy || this.recovery || this.state === "stopped" || (!this.client?.healthCheck && !this.client?.chatHeartbeat))
295
+ if (this.checking || this.busy || this.recovery || this.state === "stopped" || !this.client)
297
296
  return;
298
- const client = this.client;
299
297
  this.checking = true;
300
298
  await this.enqueue(async () => {
301
299
  try {
302
- if (this.stopped || this.busy)
303
- return;
304
- if (!client.connected()) {
305
- await this.recover();
306
- return;
307
- }
308
- if (client.chatHeartbeat && (!this.lastHeartbeatAttempt || Date.now() - Date.parse(this.lastHeartbeatAttempt) >= CHAT_HEARTBEAT_INTERVAL_MS)) {
309
- this.lastHeartbeatAttempt = new Date().toISOString();
310
- await client.chatHeartbeat();
311
- this.lastHeartbeat = new Date().toISOString();
312
- this.state = "ready";
313
- this.message = "";
314
- }
315
- else {
316
- await client.healthCheck?.();
317
- }
318
- if (this.stopped)
319
- return;
320
- this.failures = 0;
321
- }
322
- catch (error) {
323
- if (this.stopped)
324
- return;
325
- this.state = "degraded";
326
- this.message = error instanceof Error ? error.message : String(error);
327
- this.context?.logger?.error(`千问心跳失败:${this.message}`);
328
- if (++this.failures >= 2 && !client.connected())
300
+ // 健康轮询只看连接状态,不发对话或 CDP 探测,避免打断桌面任务。
301
+ if (!this.stopped && !this.busy && !this.client?.connected())
329
302
  await this.recover();
330
303
  }
331
304
  finally {
@@ -350,8 +323,6 @@ class QwenworkPlugin {
350
323
  else if (this.restart)
351
324
  await this.restart();
352
325
  await client.connect();
353
- if (client.chatHeartbeat)
354
- this.lastHeartbeatAttempt = new Date().toISOString();
355
326
  await this.verifyConnection(client);
356
327
  if (this.stopped) {
357
328
  client.close();
@@ -360,8 +331,6 @@ class QwenworkPlugin {
360
331
  this.state = "ready";
361
332
  this.message = "";
362
333
  this.failures = 0;
363
- if (client.chatHeartbeat)
364
- this.lastHeartbeat = new Date().toISOString();
365
334
  this.restarts += 1;
366
335
  this.context?.logger?.info("千问自动恢复成功", { restarts: this.restarts });
367
336
  })().catch((error) => {
@@ -374,10 +343,8 @@ class QwenworkPlugin {
374
343
  return this.recovery;
375
344
  }
376
345
  async verifyConnection(client) {
377
- if (client.chatHeartbeat)
378
- await client.chatHeartbeat();
379
- else
380
- await client.healthCheck?.();
346
+ if (!client.connected())
347
+ throw new Error("千问 CDP 连接恢复失败");
381
348
  }
382
349
  enqueue(operation) {
383
350
  const run = this.requestQueue.then(operation, operation);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-qwenwork",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "agent-bridge 的千问办公插件。",
5
5
  "keywords": [
6
6
  "mu-agent-bridge-plugin",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "qwenwork",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",