agent-bridge-qwenwork 1.0.6 → 1.0.7
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 +2 -2
- package/dist/src-ts/plugins/qwenwork/index.js +48 -42
- package/package.json +1 -1
- package/plugin.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
`executablePath` 配置保存在独立状态目录,插件升级和重启会继续使用。千问桌面升级后,若路径指向带版本号的目录,插件会从同一安装位置查找最高版本的可执行文件;即使旧版本仍保留,也会启动新版。非版本目录中的固定路径仍优先使用;路径失效时再扫描常见安装目录。重载千问插件后,运行日志会显示实际启动的 `executablePath`。
|
|
8
8
|
|
|
9
|
-
后台每 30
|
|
9
|
+
后台每 30 秒检查主页面与 CDP 连接,空闲时每 2 小时最多发送一条带随机校验码的真实测试消息。首次启动及 CDP 恢复后必须完成真实对话,只有千问原样返回本次校验码才判定可用。任务或 `/new` 执行期间不发送检测消息、不执行恢复。普通 API/UI 错误或健康通信失败但 CDP 仍连接时只标记降级;只有 CDP 已断开才允许自动重启千问并重连。AUN、飞书和 HTTP 共用请求队列,恢复不修改 AID 或 owner 配置。`autoStart: false` 禁止自动启动和重启。
|
|
10
10
|
|
|
11
|
-
请求超时或明确返回“API
|
|
11
|
+
请求超时或明确返回“API不可用”时只结束本次请求,已经发送的任务不自动重发,避免重复执行。健康接口 `/api/plugins/qwenwork/health` 的 `lastHeartbeat` 表示最近真实对话验证通过时间,同时返回 `restarts` 和 `recovering`;日志可搜索“千问真实对话心跳通过”“千问心跳失败”“千问自动恢复成功”。自动恢复只在 CDP 断开且当前无任务时结束千问进程及其子进程;daemon 应在已登录的 Windows 用户桌面会话运行。
|
|
12
12
|
|
|
13
13
|
真实心跳会消耗模型额度,并在当前千问聊天会话留下检测消息;它通过与用户请求相同的发送和取回回复路径运行。云端故障、账号额度不足或登录过期仍可能需要修复服务或账号,验证失败期间不会报告健康。
|
|
@@ -8,6 +8,7 @@ const openai_adapter_1 = require("./openai-adapter");
|
|
|
8
8
|
const cdp_client_1 = require("./cdp-client");
|
|
9
9
|
const plugin_1 = require("../../plugin");
|
|
10
10
|
const desktop_launch_1 = require("../desktop-launch");
|
|
11
|
+
const CHAT_HEARTBEAT_INTERVAL_MS = 2 * 60 * 60_000;
|
|
11
12
|
exports.qwenworkManifest = {
|
|
12
13
|
id: "qwenwork",
|
|
13
14
|
version: "1.0.4",
|
|
@@ -47,9 +48,11 @@ class QwenworkPlugin {
|
|
|
47
48
|
context;
|
|
48
49
|
checking = false;
|
|
49
50
|
failures = 0;
|
|
51
|
+
lastHeartbeatAttempt;
|
|
50
52
|
lastHeartbeat;
|
|
51
53
|
restarts = 0;
|
|
52
54
|
busy = false;
|
|
55
|
+
taskCount = 0;
|
|
53
56
|
stopped = true;
|
|
54
57
|
constructor(options = {}) {
|
|
55
58
|
this.injectedClient = options.client;
|
|
@@ -63,6 +66,8 @@ class QwenworkPlugin {
|
|
|
63
66
|
return;
|
|
64
67
|
this.state = "starting";
|
|
65
68
|
this.stopped = false;
|
|
69
|
+
this.lastHeartbeatAttempt = undefined;
|
|
70
|
+
this.lastHeartbeat = undefined;
|
|
66
71
|
this.context = context;
|
|
67
72
|
try {
|
|
68
73
|
const config = context.config;
|
|
@@ -96,7 +101,6 @@ class QwenworkPlugin {
|
|
|
96
101
|
await (0, desktop_launch_1.launchAndWait)(executable, [`--remote-debugging-port=${this.activeCdpPort}`], async () => {
|
|
97
102
|
try {
|
|
98
103
|
await client.connect();
|
|
99
|
-
await client.healthCheck?.();
|
|
100
104
|
}
|
|
101
105
|
catch (error) {
|
|
102
106
|
client.close();
|
|
@@ -122,7 +126,7 @@ class QwenworkPlugin {
|
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
|
-
this.adapter = new openai_adapter_1.OpenAIAdapter((prompt, signal) => this.
|
|
129
|
+
this.adapter = new openai_adapter_1.OpenAIAdapter((prompt, signal) => this.enqueueTask(() => this.complete(prompt, asNumber(config.timeoutMs, 240_000), signal)), {
|
|
126
130
|
onLog: (message) => context.logger?.info(message),
|
|
127
131
|
onExchange: (direction, text, peer, agentAid) => context.logger?.info("千问通信", { direction, text, peer, agentAid }),
|
|
128
132
|
});
|
|
@@ -135,7 +139,7 @@ class QwenworkPlugin {
|
|
|
135
139
|
if (this.configuredHttpPort > 0)
|
|
136
140
|
await this.adapter.listen(this.configuredHttpPort);
|
|
137
141
|
}
|
|
138
|
-
this.state =
|
|
142
|
+
this.state = "ready";
|
|
139
143
|
this.message = "";
|
|
140
144
|
this.startHealthWatch();
|
|
141
145
|
void this.checkHealth();
|
|
@@ -166,7 +170,7 @@ class QwenworkPlugin {
|
|
|
166
170
|
await this.recovery;
|
|
167
171
|
if (this.state === "stopped" || (!this.relayTarget && !this.client))
|
|
168
172
|
throw new Error("qwenwork 插件未就绪");
|
|
169
|
-
const text = await this.
|
|
173
|
+
const text = await this.enqueueTask(() => this.complete(request.task, request.timeoutMs ?? 240_000));
|
|
170
174
|
return { text };
|
|
171
175
|
}
|
|
172
176
|
async controlSession(request) {
|
|
@@ -181,7 +185,7 @@ class QwenworkPlugin {
|
|
|
181
185
|
throw new Error("千问办公当前传输不支持新建会话");
|
|
182
186
|
if (!this.client.connected())
|
|
183
187
|
throw new Error("千问办公 CDP 未连接");
|
|
184
|
-
return this.
|
|
188
|
+
return this.enqueueTask(async () => {
|
|
185
189
|
await this.client.createSession(request.name);
|
|
186
190
|
return { text: "千问办公已创建新会话", sessionId };
|
|
187
191
|
});
|
|
@@ -193,17 +197,12 @@ class QwenworkPlugin {
|
|
|
193
197
|
}
|
|
194
198
|
if (!this.client)
|
|
195
199
|
throw new Error("qwenwork 插件未就绪");
|
|
196
|
-
if (this.recovery)
|
|
197
|
-
await this.recovery;
|
|
198
|
-
this.busy = true;
|
|
199
200
|
try {
|
|
200
|
-
if (this.
|
|
201
|
-
|
|
202
|
-
if (this.state !== "ready")
|
|
203
|
-
throw new Error(this.message || "千问正在恢复");
|
|
201
|
+
if (!this.client.connected())
|
|
202
|
+
throw new Error("千问 CDP 已断开,等待空闲后自动恢复");
|
|
204
203
|
const reply = await this.client.direct(prompt, timeoutMs, signal);
|
|
205
204
|
if ((0, cdp_client_1.isQwenApiUnavailableReply)(reply))
|
|
206
|
-
throw new Error("
|
|
205
|
+
throw new Error("千问生成接口不可用");
|
|
207
206
|
this.failures = 0;
|
|
208
207
|
this.state = "ready";
|
|
209
208
|
this.message = "";
|
|
@@ -211,16 +210,12 @@ class QwenworkPlugin {
|
|
|
211
210
|
}
|
|
212
211
|
catch (error) {
|
|
213
212
|
if (!signal?.aborted) {
|
|
214
|
-
this.failures = 2;
|
|
215
213
|
this.message = error instanceof Error ? error.message : String(error);
|
|
216
|
-
this.
|
|
217
|
-
|
|
214
|
+
this.failures = this.client.connected() ? 0 : 2;
|
|
215
|
+
this.state = this.client.connected() ? "ready" : "degraded";
|
|
218
216
|
}
|
|
219
217
|
throw error;
|
|
220
218
|
}
|
|
221
|
-
finally {
|
|
222
|
-
this.busy = false;
|
|
223
|
-
}
|
|
224
219
|
}
|
|
225
220
|
registerRoutes(http) {
|
|
226
221
|
if (!this.adapter)
|
|
@@ -251,40 +246,37 @@ class QwenworkPlugin {
|
|
|
251
246
|
this.pluginStatus = undefined;
|
|
252
247
|
}
|
|
253
248
|
startHealthWatch() {
|
|
254
|
-
if (this.relayTarget || !this.client?.healthCheck || this.healthTimer)
|
|
249
|
+
if (this.relayTarget || (!this.client?.healthCheck && !this.client?.chatHeartbeat) || this.healthTimer)
|
|
255
250
|
return;
|
|
256
251
|
this.healthTimer = setInterval(() => { void this.checkHealth(); }, this.healthIntervalMs);
|
|
257
252
|
this.healthTimer.unref();
|
|
258
253
|
}
|
|
259
254
|
async checkHealth() {
|
|
260
|
-
if (this.checking || this.busy || this.recovery || this.state === "stopped" || !this.client?.healthCheck)
|
|
255
|
+
if (this.checking || this.busy || this.recovery || this.state === "stopped" || (!this.client?.healthCheck && !this.client?.chatHeartbeat))
|
|
261
256
|
return;
|
|
262
257
|
const client = this.client;
|
|
263
258
|
this.checking = true;
|
|
264
259
|
await this.enqueue(async () => {
|
|
265
260
|
try {
|
|
266
|
-
if (this.stopped)
|
|
261
|
+
if (this.stopped || this.busy)
|
|
267
262
|
return;
|
|
268
|
-
if (
|
|
263
|
+
if (!client.connected()) {
|
|
269
264
|
await this.recover();
|
|
270
265
|
return;
|
|
271
266
|
}
|
|
272
|
-
if (client.chatHeartbeat && this.
|
|
273
|
-
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if (client.chatHeartbeat)
|
|
267
|
+
if (client.chatHeartbeat && (!this.lastHeartbeatAttempt || Date.now() - Date.parse(this.lastHeartbeatAttempt) >= CHAT_HEARTBEAT_INTERVAL_MS)) {
|
|
268
|
+
this.lastHeartbeatAttempt = new Date().toISOString();
|
|
277
269
|
await client.chatHeartbeat();
|
|
278
|
-
|
|
270
|
+
this.lastHeartbeat = new Date().toISOString();
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
279
273
|
await client.healthCheck?.();
|
|
274
|
+
}
|
|
280
275
|
if (this.stopped)
|
|
281
276
|
return;
|
|
282
|
-
this.lastHeartbeat = new Date().toISOString();
|
|
283
277
|
this.failures = 0;
|
|
284
278
|
this.state = "ready";
|
|
285
279
|
this.message = "";
|
|
286
|
-
if (client.chatHeartbeat)
|
|
287
|
-
this.context?.logger?.info("千问真实对话心跳通过", { verifiedAt: this.lastHeartbeat });
|
|
288
280
|
}
|
|
289
281
|
catch (error) {
|
|
290
282
|
if (this.stopped)
|
|
@@ -292,7 +284,7 @@ class QwenworkPlugin {
|
|
|
292
284
|
this.state = "degraded";
|
|
293
285
|
this.message = error instanceof Error ? error.message : String(error);
|
|
294
286
|
this.context?.logger?.error(`千问心跳失败:${this.message}`);
|
|
295
|
-
if (++this.failures >= 2)
|
|
287
|
+
if (++this.failures >= 2 && !client.connected())
|
|
296
288
|
await this.recover();
|
|
297
289
|
}
|
|
298
290
|
finally {
|
|
@@ -303,24 +295,23 @@ class QwenworkPlugin {
|
|
|
303
295
|
async recover() {
|
|
304
296
|
if (this.recovery)
|
|
305
297
|
return this.recovery;
|
|
306
|
-
if (this.stopped)
|
|
298
|
+
if (this.stopped || this.busy)
|
|
299
|
+
return;
|
|
300
|
+
const client = this.client;
|
|
301
|
+
if (!client || client.connected())
|
|
307
302
|
return;
|
|
308
303
|
this.recovery = (async () => {
|
|
309
304
|
this.state = "starting";
|
|
310
305
|
this.context?.logger?.info("千问自动恢复开始", { reason: this.message });
|
|
311
|
-
|
|
306
|
+
client.close();
|
|
312
307
|
if (this.restartDesktop)
|
|
313
308
|
await this.restartDesktop();
|
|
314
309
|
else if (this.restart)
|
|
315
310
|
await this.restart();
|
|
316
|
-
const client = this.client;
|
|
317
|
-
if (!client)
|
|
318
|
-
throw new Error("千问客户端未初始化");
|
|
319
311
|
await client.connect();
|
|
320
312
|
if (client.chatHeartbeat)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
await client.healthCheck?.();
|
|
313
|
+
this.lastHeartbeatAttempt = new Date().toISOString();
|
|
314
|
+
await this.verifyConnection(client);
|
|
324
315
|
if (this.stopped) {
|
|
325
316
|
client.close();
|
|
326
317
|
return;
|
|
@@ -328,8 +319,9 @@ class QwenworkPlugin {
|
|
|
328
319
|
this.state = "ready";
|
|
329
320
|
this.message = "";
|
|
330
321
|
this.failures = 0;
|
|
322
|
+
if (client.chatHeartbeat)
|
|
323
|
+
this.lastHeartbeat = new Date().toISOString();
|
|
331
324
|
this.restarts += 1;
|
|
332
|
-
this.lastHeartbeat = new Date().toISOString();
|
|
333
325
|
this.context?.logger?.info("千问自动恢复成功", { restarts: this.restarts });
|
|
334
326
|
})().catch((error) => {
|
|
335
327
|
if (this.stopped)
|
|
@@ -340,11 +332,25 @@ class QwenworkPlugin {
|
|
|
340
332
|
}).finally(() => { this.recovery = undefined; });
|
|
341
333
|
return this.recovery;
|
|
342
334
|
}
|
|
335
|
+
async verifyConnection(client) {
|
|
336
|
+
if (client.chatHeartbeat)
|
|
337
|
+
await client.chatHeartbeat();
|
|
338
|
+
else
|
|
339
|
+
await client.healthCheck?.();
|
|
340
|
+
}
|
|
343
341
|
enqueue(operation) {
|
|
344
342
|
const run = this.requestQueue.then(operation, operation);
|
|
345
343
|
this.requestQueue = run.then(() => undefined, () => undefined);
|
|
346
344
|
return run;
|
|
347
345
|
}
|
|
346
|
+
enqueueTask(operation) {
|
|
347
|
+
this.taskCount += 1;
|
|
348
|
+
this.busy = true;
|
|
349
|
+
return this.enqueue(operation).finally(() => {
|
|
350
|
+
this.taskCount -= 1;
|
|
351
|
+
this.busy = this.taskCount > 0;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
348
354
|
}
|
|
349
355
|
exports.QwenworkPlugin = QwenworkPlugin;
|
|
350
356
|
function createQwenworkPlugin(options = {}) {
|
package/package.json
CHANGED