agent-bridge-qwenwork 1.0.27 → 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.
|
@@ -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) {
|
|
@@ -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