agent-bridge-qwenwork 1.0.26 → 1.0.28
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,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
`/new` 在已确认的空白新任务页可重复执行。远程消息和 `/new` 遇到输入框残留时,先将原文、页面地址和时间追加到插件数据目录的 `draft-recovery.jsonl`,再通过编辑器原生删除操作清理;备份失败、内容发生变化或正在生成回复时不清理。后台心跳只清理桥接自己的检测文本,遇到普通用户草稿则跳过。发送消息会点击桌面端“发送消息”按钮并确认输入框清空,避免仅按 Enter 后消息仍停留在输入框。真实通信失败后保持降级,普通 CDP 检查通过不会把状态改回就绪,须有真实回复或真实对话心跳通过。
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
提交前等待发送按钮就绪;窗口在插入、点击复查或回复轮询期间被最小化时,插件会恢复千问主窗口并继续确认。只有复查确认尚未点击时最多再尝试一次;仅备份并清理原会话内仍与本次请求完全一致的文字,保留用户后来修改的草稿。点击后无法确认提交状态时不会自动重发或清理输入,避免重复执行。
|
|
18
18
|
|
|
19
19
|
真实心跳会消耗模型额度,并在当前千问聊天会话留下检测消息;它通过与用户请求相同的发送和取回回复路径运行。云端故障、账号额度不足或登录过期仍可能需要修复服务或账号,验证失败期间不会报告健康。
|
|
20
20
|
|
|
@@ -45,7 +45,7 @@ async function findWindowsExecutable(fileName, configured, run = execFileAsync)
|
|
|
45
45
|
const registered = await findRegisteredWindowsExecutable(fileName, run);
|
|
46
46
|
if (registered)
|
|
47
47
|
return registered;
|
|
48
|
-
const pattern = /doubao|豆包|qwen|qwwork|千问|deepseek|harness|dsh/i;
|
|
48
|
+
const pattern = /doubao|豆包|qwen|qwwork|千问|deepseek|harness|dsh|zcode/i;
|
|
49
49
|
const roots = [...new Set([
|
|
50
50
|
process.env.DSH_INSTALL_DIR,
|
|
51
51
|
"D:\\Programs\\DeepSeek Harness",
|
|
@@ -65,7 +65,7 @@ async function findWindowsExecutable(fileName, configured, run = execFileAsync)
|
|
|
65
65
|
}
|
|
66
66
|
async function findRegisteredWindowsExecutable(fileName, run) {
|
|
67
67
|
const target = fileName.replace(/'/g, "''");
|
|
68
|
-
const script = `$ErrorActionPreference='SilentlyContinue';$target='${target}'
|
|
68
|
+
const script = `$ErrorActionPreference='SilentlyContinue';[Console]::OutputEncoding=[Text.Encoding]::UTF8;$target='${target}'
|
|
69
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
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
71
|
foreach($key in $keys){$item=Get-Item $key -ErrorAction SilentlyContinue;if($item){Emit-Path $item.GetValue('')}}
|
|
@@ -138,9 +138,16 @@ async function launchManagedAndWait(executable, args, profileDirectory, connect,
|
|
|
138
138
|
if (profileDirectory)
|
|
139
139
|
await (0, promises_1.mkdir)(profileDirectory, { recursive: true });
|
|
140
140
|
const child = launch(executable, profileDirectory ? [...args, `--user-data-dir=${profileDirectory}`] : args);
|
|
141
|
+
// 先等待 spawn,避免异步 error 终止 daemon 或在启动失败后继续轮询。
|
|
142
|
+
const events = child;
|
|
143
|
+
const started = typeof events.once === "function" ? new Promise((resolve, reject) => {
|
|
144
|
+
events.once("error", reject);
|
|
145
|
+
events.once("spawn", resolve);
|
|
146
|
+
}) : Promise.resolve();
|
|
141
147
|
child.unref();
|
|
142
148
|
onProcess(child);
|
|
143
149
|
try {
|
|
150
|
+
await started;
|
|
144
151
|
return await waitFor(connect, timeoutMs, 250);
|
|
145
152
|
}
|
|
146
153
|
catch (error) {
|
|
@@ -265,21 +265,25 @@ class QwenCdpClient {
|
|
|
265
265
|
const input = document.querySelector(${JSON.stringify(exports.inputSelector)});
|
|
266
266
|
const button = document.querySelector('button[aria-label="发送消息"]');
|
|
267
267
|
const generating = document.querySelector('button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]');
|
|
268
|
-
return Boolean(location.href === ${JSON.stringify(submitUrl)} && input && input.innerText.trim() === ${JSON.stringify(text.trim())}
|
|
268
|
+
return Boolean(!document.hidden && location.href === ${JSON.stringify(submitUrl)} && input && input.innerText.trim() === ${JSON.stringify(text.trim())}
|
|
269
269
|
&& button && !button.disabled && button.getAttribute('aria-disabled') !== 'true' && !generating);
|
|
270
270
|
})()`;
|
|
271
271
|
await this.cdp("Input.insertText", { text });
|
|
272
272
|
inserted = true;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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;
|
|
281
284
|
submitAttempted = false;
|
|
282
|
-
|
|
285
|
+
if (attempt === 1)
|
|
286
|
+
throw new Error("千问发送按钮未就绪或输入校验失败,未发送消息");
|
|
283
287
|
}
|
|
284
288
|
await this.waitFor(`(() => { const input = document.querySelector(${JSON.stringify(exports.inputSelector)}); return Boolean(input && !input.innerText.trim()); })()`, "千问未确认消息已提交");
|
|
285
289
|
}
|
|
@@ -309,6 +313,7 @@ class QwenCdpClient {
|
|
|
309
313
|
while (Date.now() < deadline || signal?.aborted) {
|
|
310
314
|
// 上游取消不停止桌面生成;确认结束前保留插件队列。
|
|
311
315
|
await wait(2_000);
|
|
316
|
+
await this.restoreVisible();
|
|
312
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 })))`);
|
|
313
318
|
const messages = JSON.parse(messagesJson || "[]");
|
|
314
319
|
const fresh = freshAssistantMessages(beforeIds, messages);
|
|
@@ -572,9 +577,8 @@ class QwenCdpClient {
|
|
|
572
577
|
try {
|
|
573
578
|
await this.evaluate(`(async () => {
|
|
574
579
|
if (document.querySelector('button[aria-label="停止"],button[aria-label="停止生成"],button[aria-label="Stop generating"]')) throw new Error('千问桌面端正在生成回复');
|
|
575
|
-
// 隐藏窗口会暂停消息渲染,使桌面端的提交前检查一直等不到确认。
|
|
576
|
-
if (document.hidden && typeof window.desktopApi?.focusMainWindow === 'function') await window.desktopApi.focusMainWindow();
|
|
577
580
|
})()`);
|
|
581
|
+
await this.restoreVisible();
|
|
578
582
|
}
|
|
579
583
|
catch (error) {
|
|
580
584
|
let permission;
|
|
@@ -587,6 +591,11 @@ class QwenCdpClient {
|
|
|
587
591
|
throw error;
|
|
588
592
|
}
|
|
589
593
|
}
|
|
594
|
+
async restoreVisible() {
|
|
595
|
+
await this.evaluate(`(async () => {
|
|
596
|
+
if (document.hidden && typeof window.desktopApi?.focusMainWindow === 'function') await window.desktopApi.focusMainWindow();
|
|
597
|
+
})()`);
|
|
598
|
+
}
|
|
590
599
|
recoverDraft(expected) {
|
|
591
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);
|
|
592
601
|
}
|
|
@@ -650,6 +659,7 @@ class QwenCdpClient {
|
|
|
650
659
|
async waitFor(expression, message) {
|
|
651
660
|
const deadline = Date.now() + this.options.timeoutMs;
|
|
652
661
|
while (Date.now() < deadline) {
|
|
662
|
+
await this.restoreVisible();
|
|
653
663
|
if (await this.evaluate(expression))
|
|
654
664
|
return;
|
|
655
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.
|
|
15
|
+
version: "1.0.28",
|
|
16
16
|
displayName: "千问办公",
|
|
17
17
|
entry: "dist/index.js",
|
|
18
18
|
apiVersion: "1",
|
|
@@ -170,8 +170,8 @@ class QwenworkPlugin {
|
|
|
170
170
|
throw error;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
async deactivate(reason) {
|
|
174
|
-
const reloadDesktop = reason === "reload" && Boolean(this.client) && !this.relayTarget;
|
|
173
|
+
async deactivate(reason, options) {
|
|
174
|
+
const reloadDesktop = !options?.preserveDesktop && reason === "reload" && Boolean(this.client) && !this.relayTarget;
|
|
175
175
|
await this.cleanup();
|
|
176
176
|
if (reloadDesktop) {
|
|
177
177
|
if (this.restartDesktopHook)
|
|
@@ -191,8 +191,6 @@ class QwenworkPlugin {
|
|
|
191
191
|
return { status: this.state, ...(this.message ? { message: this.message } : {}), details };
|
|
192
192
|
}
|
|
193
193
|
async handle(request) {
|
|
194
|
-
if (this.recovery)
|
|
195
|
-
await this.recovery;
|
|
196
194
|
if (this.state === "stopped" || (!this.relayTarget && !this.client))
|
|
197
195
|
throw new Error("qwenwork 插件未就绪");
|
|
198
196
|
return this.enqueueTask(() => this.completeRequest(request));
|
|
@@ -207,9 +205,8 @@ class QwenworkPlugin {
|
|
|
207
205
|
throw new Error("千问办公当前忙,无法创建新会话");
|
|
208
206
|
if (!this.client?.createSession)
|
|
209
207
|
throw new Error("千问办公当前传输不支持新建会话");
|
|
210
|
-
if (!this.client.connected())
|
|
211
|
-
throw new Error("千问办公 CDP 未连接");
|
|
212
208
|
return this.enqueueTask(async () => {
|
|
209
|
+
await this.ensureConnected();
|
|
213
210
|
await this.client.createSession(request.name);
|
|
214
211
|
return { text: "千问办公已创建新会话", sessionId };
|
|
215
212
|
});
|
|
@@ -222,8 +219,7 @@ class QwenworkPlugin {
|
|
|
222
219
|
if (!this.client)
|
|
223
220
|
throw new Error("qwenwork 插件未就绪");
|
|
224
221
|
try {
|
|
225
|
-
|
|
226
|
-
throw new Error("千问 CDP 已断开,等待空闲后自动恢复");
|
|
222
|
+
await this.ensureConnected(signal);
|
|
227
223
|
const reply = this.client.complete ? (await this.client.complete(prompt, timeoutMs, signal, undefined, undefined, onMessage)).text : await this.client.direct(prompt, timeoutMs, signal);
|
|
228
224
|
if ((0, cdp_client_1.isQwenApiUnavailableReply)(reply))
|
|
229
225
|
throw new agent_1.AgentOperationError("QWEN_REMOTE_ERROR", "等待千问办公回复", new Error("千问生成接口不可用;桌面未提供具体服务端错误码,CDP 仍连接,未重启或重新提交任务"));
|
|
@@ -233,7 +229,7 @@ class QwenworkPlugin {
|
|
|
233
229
|
return reply;
|
|
234
230
|
}
|
|
235
231
|
catch (error) {
|
|
236
|
-
if (!signal?.aborted) {
|
|
232
|
+
if (!this.stopped && !signal?.aborted) {
|
|
237
233
|
this.message = error instanceof Error ? error.message : String(error);
|
|
238
234
|
this.failures = this.client.connected() ? 0 : 2;
|
|
239
235
|
this.state = "degraded";
|
|
@@ -248,8 +244,10 @@ class QwenworkPlugin {
|
|
|
248
244
|
if (!this.client)
|
|
249
245
|
throw new Error("qwenwork 插件未就绪");
|
|
250
246
|
try {
|
|
251
|
-
if (!this.client.connected())
|
|
252
|
-
throw new Error("千问 CDP
|
|
247
|
+
if (modelRequest && !this.client.connected())
|
|
248
|
+
throw new Error("千问 CDP 已断开,模型请求不会启动或重启桌面");
|
|
249
|
+
if (!modelRequest)
|
|
250
|
+
await this.ensureConnected(request.signal);
|
|
253
251
|
if (request.attachments?.length && (!this.client.attachmentInput || !this.client.complete))
|
|
254
252
|
throw new Error("千问当前客户端不支持附件输入");
|
|
255
253
|
const timeoutMs = request.timeoutMs ?? asNumber(this.context?.config.timeoutMs, 240_000);
|
|
@@ -264,7 +262,7 @@ class QwenworkPlugin {
|
|
|
264
262
|
return response;
|
|
265
263
|
}
|
|
266
264
|
catch (error) {
|
|
267
|
-
if (!request.signal?.aborted && !modelRequest) {
|
|
265
|
+
if (!this.stopped && !request.signal?.aborted && !modelRequest) {
|
|
268
266
|
this.message = error instanceof Error ? error.message : String(error);
|
|
269
267
|
this.failures = this.client.connected() ? 0 : 2;
|
|
270
268
|
this.state = "degraded";
|
|
@@ -383,9 +381,26 @@ class QwenworkPlugin {
|
|
|
383
381
|
});
|
|
384
382
|
}
|
|
385
383
|
async recover() {
|
|
384
|
+
if (this.stopped || this.busy)
|
|
385
|
+
return;
|
|
386
|
+
try {
|
|
387
|
+
await this.reconnect();
|
|
388
|
+
}
|
|
389
|
+
catch { /* 失败已记录,留待下次空闲检查。 */ }
|
|
390
|
+
}
|
|
391
|
+
async ensureConnected(signal) {
|
|
392
|
+
signal?.throwIfAborted();
|
|
393
|
+
if (this.stopped || !this.client)
|
|
394
|
+
throw new Error("qwenwork 插件未就绪");
|
|
395
|
+
await this.reconnect();
|
|
396
|
+
signal?.throwIfAborted();
|
|
397
|
+
if (this.stopped)
|
|
398
|
+
throw new Error("qwenwork 插件未就绪");
|
|
399
|
+
}
|
|
400
|
+
async reconnect() {
|
|
386
401
|
if (this.recovery)
|
|
387
402
|
return this.recovery;
|
|
388
|
-
if (this.stopped
|
|
403
|
+
if (this.stopped)
|
|
389
404
|
return;
|
|
390
405
|
const client = this.client;
|
|
391
406
|
if (!client || client.connected())
|
|
@@ -406,11 +421,12 @@ class QwenworkPlugin {
|
|
|
406
421
|
this.restarts += 1;
|
|
407
422
|
this.context?.logger?.info("千问 CDP 自动重连成功", { restarts: this.restarts });
|
|
408
423
|
})().catch((error) => {
|
|
409
|
-
if (this.stopped)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
424
|
+
if (!this.stopped) {
|
|
425
|
+
this.state = "failed";
|
|
426
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
427
|
+
this.context?.logger?.error(`千问 CDP 重连失败,桌面未重启,下次空闲检查重试:${this.message}`);
|
|
428
|
+
}
|
|
429
|
+
throw error;
|
|
414
430
|
}).finally(() => { this.recovery = undefined; });
|
|
415
431
|
return this.recovery;
|
|
416
432
|
}
|
package/package.json
CHANGED