agent-bridge-qwenwork 1.0.7 → 1.0.8
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
|
@@ -10,4 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
请求超时或明确返回“API不可用”时只结束本次请求,已经发送的任务不自动重发,避免重复执行。健康接口 `/api/plugins/qwenwork/health` 的 `lastHeartbeat` 表示最近真实对话验证通过时间,同时返回 `restarts` 和 `recovering`;日志可搜索“千问真实对话心跳通过”“千问心跳失败”“千问自动恢复成功”。自动恢复只在 CDP 断开且当前无任务时结束千问进程及其子进程;daemon 应在已登录的 Windows 用户桌面会话运行。
|
|
12
12
|
|
|
13
|
+
`/new` 在已确认的空白新任务页可重复执行;有未发送草稿时会拒绝操作并保留内容。发送消息会点击桌面端“发送消息”按钮并确认输入框清空,避免仅按 Enter 后消息仍停留在输入框。真实通信失败后保持降级,普通 CDP 检查通过不会把状态改回就绪,须有真实回复或真实对话心跳通过。
|
|
14
|
+
|
|
13
15
|
真实心跳会消耗模型额度,并在当前千问聊天会话留下检测消息;它通过与用户请求相同的发送和取回回复路径运行。云端故障、账号额度不足或登录过期仍可能需要修复服务或账号,验证失败期间不会报告健康。
|
|
@@ -64,12 +64,16 @@ class QwenCdpClient {
|
|
|
64
64
|
verifyQwenHeartbeatReply(token, reply);
|
|
65
65
|
}
|
|
66
66
|
async createSession(_name) {
|
|
67
|
-
const snapshot = `(() => ({ url: location.href, messages: document.querySelectorAll(
|
|
67
|
+
const snapshot = `(() => ({ url: location.href, messages: document.querySelectorAll('[data-message-id]').length, input: document.querySelector(${JSON.stringify(exports.inputSelector)})?.innerText ?? null, blank: Boolean(document.querySelector('.new-task-model-selector')) }))()`;
|
|
68
68
|
const before = await this.evaluate(snapshot);
|
|
69
|
+
if (before.input?.trim())
|
|
70
|
+
throw new Error("千问输入框含有未发送内容,不能新建会话");
|
|
71
|
+
if (before.input !== null && before.messages === 0 && before.blank)
|
|
72
|
+
return;
|
|
69
73
|
const clicked = await this.evaluate(`(() => { const button = document.querySelector('button[aria-label="新任务"]'); if (!button || button.disabled || button.getAttribute('aria-disabled') === 'true') return false; button.click(); return true; })()`);
|
|
70
74
|
if (clicked !== true)
|
|
71
75
|
throw new Error("千问新任务入口未找到或不可用");
|
|
72
|
-
await this.waitFor(`(() => { const state = ${snapshot}; return state.input && state.messages === 0 && state.url !== ${JSON.stringify(before.url)}; })()`, "千问新会话状态校验失败");
|
|
76
|
+
await this.waitFor(`(() => { const state = ${snapshot}; return state.input !== null && state.input.trim() === '' && state.messages === 0 && state.url !== ${JSON.stringify(before.url)}; })()`, "千问新会话状态校验失败");
|
|
73
77
|
}
|
|
74
78
|
async connect() {
|
|
75
79
|
if (this.connected())
|
|
@@ -132,6 +136,9 @@ class QwenCdpClient {
|
|
|
132
136
|
});
|
|
133
137
|
}
|
|
134
138
|
async direct(text, timeoutMs = 240_000, signal, expectedReply) {
|
|
139
|
+
const ready = await this.evaluate(`(() => { const input = document.querySelector(${JSON.stringify(exports.inputSelector)}); return Boolean(input && !input.innerText.trim() && !document.querySelector('button[aria-label="停止生成"],button[aria-label="Stop generating"]')); })()`);
|
|
140
|
+
if (!ready)
|
|
141
|
+
throw new Error("千问输入框含有未发送内容或正在生成回复,未发送新消息");
|
|
135
142
|
const snapshot = await this.evaluate(`JSON.stringify([...document.querySelectorAll(${JSON.stringify(exports.assistantMessageSelector)})].map(element => ({ id: element.getAttribute('data-message-id'), text: element.innerText })))`);
|
|
136
143
|
const before = JSON.parse(snapshot || "[]");
|
|
137
144
|
const beforeIds = new Set(before.map((message) => message.id).filter((id) => Boolean(id)));
|
|
@@ -144,12 +151,10 @@ class QwenCdpClient {
|
|
|
144
151
|
if (!focused)
|
|
145
152
|
throw new Error("千问输入框未找到");
|
|
146
153
|
await this.cdp("Input.insertText", { text });
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
}
|
|
154
|
+
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; })()`);
|
|
155
|
+
if (sent !== true)
|
|
156
|
+
throw new Error("千问发送按钮未就绪或输入校验失败,未发送消息");
|
|
157
|
+
await this.waitFor(`(() => { const input = document.querySelector(${JSON.stringify(exports.inputSelector)}); return Boolean(input && !input.innerText.trim()); })()`, "千问未确认消息已提交");
|
|
153
158
|
let previousReply = "";
|
|
154
159
|
let stablePolls = 0;
|
|
155
160
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -212,7 +212,7 @@ class QwenworkPlugin {
|
|
|
212
212
|
if (!signal?.aborted) {
|
|
213
213
|
this.message = error instanceof Error ? error.message : String(error);
|
|
214
214
|
this.failures = this.client.connected() ? 0 : 2;
|
|
215
|
-
this.state =
|
|
215
|
+
this.state = "degraded";
|
|
216
216
|
}
|
|
217
217
|
throw error;
|
|
218
218
|
}
|
|
@@ -268,6 +268,8 @@ class QwenworkPlugin {
|
|
|
268
268
|
this.lastHeartbeatAttempt = new Date().toISOString();
|
|
269
269
|
await client.chatHeartbeat();
|
|
270
270
|
this.lastHeartbeat = new Date().toISOString();
|
|
271
|
+
this.state = "ready";
|
|
272
|
+
this.message = "";
|
|
271
273
|
}
|
|
272
274
|
else {
|
|
273
275
|
await client.healthCheck?.();
|
|
@@ -275,8 +277,6 @@ class QwenworkPlugin {
|
|
|
275
277
|
if (this.stopped)
|
|
276
278
|
return;
|
|
277
279
|
this.failures = 0;
|
|
278
|
-
this.state = "ready";
|
|
279
|
-
this.message = "";
|
|
280
280
|
}
|
|
281
281
|
catch (error) {
|
|
282
282
|
if (this.stopped)
|
package/package.json
CHANGED