agent-bridge-qwenwork 1.0.25 → 1.0.27

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/README.md CHANGED
@@ -14,6 +14,8 @@
14
14
 
15
15
  `/new` 在已确认的空白新任务页可重复执行。远程消息和 `/new` 遇到输入框残留时,先将原文、页面地址和时间追加到插件数据目录的 `draft-recovery.jsonl`,再通过编辑器原生删除操作清理;备份失败、内容发生变化或正在生成回复时不清理。后台心跳只清理桥接自己的检测文本,遇到普通用户草稿则跳过。发送消息会点击桌面端“发送消息”按钮并确认输入框清空,避免仅按 Enter 后消息仍停留在输入框。真实通信失败后保持降级,普通 CDP 检查通过不会把状态改回就绪,须有真实回复或真实对话心跳通过。
16
16
 
17
+ 提交前等待发送按钮就绪;窗口在插入、点击复查或回复轮询期间被最小化时,插件会恢复千问主窗口并继续确认。只有复查确认尚未点击时最多再尝试一次;仅备份并清理原会话内仍与本次请求完全一致的文字,保留用户后来修改的草稿。点击后无法确认提交状态时不会自动重发或清理输入,避免重复执行。
18
+
17
19
  真实心跳会消耗模型额度,并在当前千问聊天会话留下检测消息;它通过与用户请求相同的发送和取回回复路径运行。云端故障、账号额度不足或登录过期仍可能需要修复服务或账号,验证失败期间不会报告健康。
18
20
 
19
21
  文件、图片、视频附件经桌面原生上传入口送入本轮任务;回传只采集本轮助手通过“已展示最终文件”工具声明的产物,不扫描普通正文中的任意路径。图片按内容去重,视频以 `video/*` 文件附件交给 AUN,使用分块读取避免大视频导致 CDP 断连。单条最多 8 个附件,单个不超过 32 MiB、合计不超过 64 MiB;实际可处理的格式及内容理解能力由桌面端和模型决定。验证证据见仓库的 `docs/verification/2026-10-20-qwenwork-media.md`。
@@ -5,7 +5,7 @@ const promises_1 = require("node:fs/promises");
5
5
  const node_os_1 = require("node:os");
6
6
  const node_path_1 = require("node:path");
7
7
  /** 空闲时先备份旧草稿,再通过编辑器原生删除事件清理,避免只修改 DOM。 */
8
- async function recoverCdpDraft(evaluate, editorSelector, stopSelector, dataDir = (0, node_path_1.join)((0, node_os_1.tmpdir)(), "agent-bridge-draft-recovery")) {
8
+ async function recoverCdpDraft(evaluate, editorSelector, stopSelector, dataDir = (0, node_path_1.join)((0, node_os_1.tmpdir)(), "agent-bridge-draft-recovery"), expected) {
9
9
  const state = await evaluate(`(() => ({
10
10
  text: document.querySelector(${JSON.stringify(editorSelector)})?.innerText ?? null,
11
11
  generating: Boolean(document.querySelector(${JSON.stringify(stopSelector)})),
@@ -15,13 +15,16 @@ async function recoverCdpDraft(evaluate, editorSelector, stopSelector, dataDir =
15
15
  throw new Error("桌面端正在生成回复,不能清理输入或切换会话");
16
16
  if (state.text === null)
17
17
  throw new Error("桌面端输入框未就绪");
18
+ if (expected && (state.text !== expected.text || state.url !== expected.url))
19
+ return;
18
20
  if (!state.text?.trim())
19
21
  return;
20
22
  await (0, promises_1.mkdir)(dataDir, { recursive: true, mode: 0o700 });
21
23
  await (0, promises_1.appendFile)((0, node_path_1.join)(dataDir, "draft-recovery.jsonl"), JSON.stringify({ time: new Date().toISOString(), url: state.url, text: state.text }) + "\n", { encoding: "utf8", mode: 0o600 });
22
24
  const cleared = await evaluate(`(() => {
23
25
  const editor = document.querySelector(${JSON.stringify(editorSelector)});
24
- const unchanged = () => editor && editor.innerText === ${JSON.stringify(state.text)}
26
+ const unchanged = () => editor && document.querySelector(${JSON.stringify(editorSelector)}) === editor
27
+ && editor.innerText === ${JSON.stringify(state.text)} && (document.URL ?? '') === ${JSON.stringify(state.url)}
25
28
  && !document.querySelector(${JSON.stringify(stopSelector)});
26
29
  if (!unchanged()) return false;
27
30
  editor.focus();
@@ -16,8 +16,8 @@ const node_path_1 = require("node:path");
16
16
  const node_util_1 = require("node:util");
17
17
  const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
18
18
  const versionDirectory = /^(?:app[-_ ]?)?v?\d+(?:[.-]\d+)+$/i;
19
- /** 在 Windows 常见安装目录中查找桌面程序,避免依赖单一盘符。 */
20
- async function findWindowsExecutable(fileName, configured) {
19
+ /** 先从 Windows 注册信息和开始菜单解析,失败时再查常见安装目录。 */
20
+ async function findWindowsExecutable(fileName, configured, run = execFileAsync) {
21
21
  if (configured?.trim()) {
22
22
  const configuredPath = (0, node_path_1.resolve)(configured);
23
23
  if (fileName.toLowerCase() === "doubao.exe") {
@@ -42,12 +42,16 @@ async function findWindowsExecutable(fileName, configured) {
42
42
  }
43
43
  if (process.platform !== "win32")
44
44
  return undefined;
45
+ const registered = await findRegisteredWindowsExecutable(fileName, run);
46
+ if (registered)
47
+ return registered;
45
48
  const pattern = /doubao|豆包|qwen|qwwork|千问|deepseek|harness|dsh/i;
46
49
  const roots = [...new Set([
47
50
  process.env.DSH_INSTALL_DIR,
48
51
  "D:\\Programs\\DeepSeek Harness",
49
52
  "D:\\DSH",
50
53
  process.env.LOCALAPPDATA && (0, node_path_1.join)(process.env.LOCALAPPDATA, "Programs"),
54
+ process.env.LOCALAPPDATA,
51
55
  process.env.ProgramFiles,
52
56
  process.env["ProgramFiles(x86)"],
53
57
  ...Array.from({ length: 24 }, (_, index) => `${String.fromCharCode(67 + index)}:\\`),
@@ -59,6 +63,36 @@ async function findWindowsExecutable(fileName, configured) {
59
63
  }
60
64
  return undefined;
61
65
  }
66
+ async function findRegisteredWindowsExecutable(fileName, run) {
67
+ const target = fileName.replace(/'/g, "''");
68
+ const script = `$ErrorActionPreference='SilentlyContinue';$target='${target}'
69
+ function Emit-Path($value){if(-not $value){return};$value=[Environment]::ExpandEnvironmentVariables(([string]$value).Trim());if($value.StartsWith('"')){$end=$value.IndexOf('"',1);if($end -gt 1){$value=$value.Substring(1,$end-1)}}elseif($value -match '^(\S+?\.exe)(?:\s|$)'){$value=$Matches[1]};if($value -match '(?i)\.exe$'){[Console]::WriteLine($value)}}
70
+ $keys=@("HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\$target","HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\$target","HKLM:\\Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\$target","HKCU:\\Software\\Classes\\Applications\\$target\\shell\\open\\command","HKLM:\\Software\\Classes\\Applications\\$target\\shell\\open\\command")
71
+ foreach($key in $keys){$item=Get-Item $key -ErrorAction SilentlyContinue;if($item){Emit-Path $item.GetValue('')}}
72
+ $dirs=@();if($env:APPDATA){$dirs+=[IO.Path]::Combine($env:APPDATA,'Microsoft\\Windows\\Start Menu\\Programs')};if($env:ProgramData){$dirs+=[IO.Path]::Combine($env:ProgramData,'Microsoft\\Windows\\Start Menu\\Programs')};$shell=New-Object -ComObject WScript.Shell
73
+ foreach($dir in $dirs){Get-ChildItem $dir -Filter '*.lnk' -File -Recurse -ErrorAction SilentlyContinue|ForEach-Object{$link=$shell.CreateShortcut($_.FullName);if($link.TargetPath -and [IO.Path]::GetFileName($link.TargetPath) -ieq $target){Emit-Path $link.TargetPath}}}`;
74
+ try {
75
+ const { stdout } = await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")], { timeout: 10_000, windowsHide: true });
76
+ for (const candidate of stdout.split(/\r?\n/).map(value => value.trim()).filter(Boolean)) {
77
+ const found = await resolveRegisteredCandidate(fileName, candidate);
78
+ if (found)
79
+ return found;
80
+ }
81
+ }
82
+ catch { /* 注册表或开始菜单不可读时继续使用目录兜底 */ }
83
+ return undefined;
84
+ }
85
+ async function resolveRegisteredCandidate(fileName, candidate) {
86
+ const candidatePath = (0, node_path_1.resolve)(candidate.replace(/^"|"$/g, ""));
87
+ if (fileName.toLowerCase() === "doubao.exe" && (0, node_path_1.basename)((0, node_path_1.dirname)(candidatePath)).toLowerCase() === "application") {
88
+ const client = (0, node_path_1.join)((0, node_path_1.dirname)(candidatePath), "app", fileName);
89
+ if ((0, node_fs_1.existsSync)(client))
90
+ return client;
91
+ }
92
+ if ((0, node_fs_1.existsSync)(candidatePath) && (0, node_path_1.basename)(candidatePath).toLowerCase() === fileName.toLowerCase())
93
+ return candidatePath;
94
+ return findExecutableInTree((0, node_path_1.dirname)(candidatePath), fileName, /^/, 3);
95
+ }
62
96
  async function findExecutableInTree(directory, fileName, pattern, depth) {
63
97
  return search(directory, fileName, pattern, depth, pattern.test(directory));
64
98
  }
@@ -256,15 +256,45 @@ class QwenCdpClient {
256
256
  const addedIds = attachments?.length ? await this.injectAttachments(attachments) : [];
257
257
  stage = "向千问办公提交任务(尚未确认发送)";
258
258
  code = "QWEN_SUBMIT_FAILED";
259
+ let submitUrl = "";
260
+ let inserted = false;
261
+ let submitAttempted = false;
259
262
  try {
263
+ submitUrl = String(await this.evaluate("location.href"));
264
+ const readyToSubmit = `(() => {
265
+ const input = document.querySelector(${JSON.stringify(exports.inputSelector)});
266
+ const button = document.querySelector('button[aria-label="发送消息"]');
267
+ const generating = document.querySelector('button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]');
268
+ return Boolean(!document.hidden && location.href === ${JSON.stringify(submitUrl)} && input && input.innerText.trim() === ${JSON.stringify(text.trim())}
269
+ && button && !button.disabled && button.getAttribute('aria-disabled') !== 'true' && !generating);
270
+ })()`;
260
271
  await this.cdp("Input.insertText", { text });
261
- const sent = await this.evaluate(`(() => { const input = document.querySelector(${JSON.stringify(exports.inputSelector)}); const button = document.querySelector('button[aria-label="发送消息"]'); if (!input || input.innerText.trim() !== ${JSON.stringify(text.trim())} || !button || button.disabled || button.getAttribute('aria-disabled') === 'true') return false; button.click(); return true; })()`);
262
- if (sent !== true)
263
- throw new Error("千问发送按钮未就绪或输入校验失败,未发送消息");
272
+ inserted = true;
273
+ // 只有复查确认尚未点击时才再试一次,不能重发提交结果未知的任务。
274
+ for (let attempt = 0; attempt < 2; attempt++) {
275
+ await this.waitFor(readyToSubmit, "千问发送按钮未就绪或输入校验失败,未发送消息");
276
+ submitAttempted = true;
277
+ const sent = await this.evaluate(`(() => {
278
+ if (!${readyToSubmit}) return false;
279
+ document.querySelector('button[aria-label="发送消息"]').click();
280
+ return true;
281
+ })()`);
282
+ if (sent === true)
283
+ break;
284
+ submitAttempted = false;
285
+ if (attempt === 1)
286
+ throw new Error("千问发送按钮未就绪或输入校验失败,未发送消息");
287
+ }
264
288
  await this.waitFor(`(() => { const input = document.querySelector(${JSON.stringify(exports.inputSelector)}); return Boolean(input && !input.innerText.trim()); })()`, "千问未确认消息已提交");
265
289
  }
266
290
  catch (error) {
267
291
  // CDP 断开时清理也可能失败,保留最初的发送错误。
292
+ if (inserted && !submitAttempted) {
293
+ try {
294
+ await this.recoverDraft({ text, url: submitUrl });
295
+ }
296
+ catch { /* 清理失败不能覆盖原错。 */ }
297
+ }
268
298
  try {
269
299
  await this.cleanupAttachments(addedIds);
270
300
  }
@@ -283,6 +313,7 @@ class QwenCdpClient {
283
313
  while (Date.now() < deadline || signal?.aborted) {
284
314
  // 上游取消不停止桌面生成;确认结束前保留插件队列。
285
315
  await wait(2_000);
316
+ await this.restoreVisible();
286
317
  const messagesJson = await this.evaluate(`JSON.stringify([...document.querySelectorAll(${JSON.stringify(exports.assistantMessageSelector)})].map(element => ({ id: element.getAttribute('data-message-id'), text: element.innerText })))`);
287
318
  const messages = JSON.parse(messagesJson || "[]");
288
319
  const fresh = freshAssistantMessages(beforeIds, messages);
@@ -546,9 +577,8 @@ class QwenCdpClient {
546
577
  try {
547
578
  await this.evaluate(`(async () => {
548
579
  if (document.querySelector('button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]')) throw new Error('千问桌面端正在生成回复');
549
- // 隐藏窗口会暂停消息渲染,使桌面端的提交前检查一直等不到确认。
550
- if (document.hidden && typeof window.desktopApi?.focusMainWindow === 'function') await window.desktopApi.focusMainWindow();
551
580
  })()`);
581
+ await this.restoreVisible();
552
582
  }
553
583
  catch (error) {
554
584
  let permission;
@@ -561,8 +591,13 @@ class QwenCdpClient {
561
591
  throw error;
562
592
  }
563
593
  }
564
- recoverDraft() {
565
- 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);
594
+ async restoreVisible() {
595
+ await this.evaluate(`(async () => {
596
+ if (document.hidden && typeof window.desktopApi?.focusMainWindow === 'function') await window.desktopApi.focusMainWindow();
597
+ })()`);
598
+ }
599
+ recoverDraft(expected) {
600
+ 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, expected);
566
601
  }
567
602
  async cdp(method, params = {}, timeoutMs = this.options.timeoutMs) {
568
603
  if (!this.socket)
@@ -624,6 +659,7 @@ class QwenCdpClient {
624
659
  async waitFor(expression, message) {
625
660
  const deadline = Date.now() + this.options.timeoutMs;
626
661
  while (Date.now() < deadline) {
662
+ await this.restoreVisible();
627
663
  if (await this.evaluate(expression))
628
664
  return;
629
665
  await wait(200);
@@ -12,7 +12,7 @@ const desktop_launch_1 = require("../desktop-launch");
12
12
  const session_history_1 = require("./session-history");
13
13
  exports.qwenworkManifest = {
14
14
  id: "qwenwork",
15
- version: "1.0.25",
15
+ version: "1.0.27",
16
16
  displayName: "千问办公",
17
17
  entry: "dist/index.js",
18
18
  apiVersion: "1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-qwenwork",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
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.25",
3
+ "version": "1.0.27",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",