agent-bridge-qwenwork 1.0.40 → 1.0.42
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
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
提交前等待发送按钮就绪;窗口在插入、点击复查或回复轮询期间被最小化时,插件会恢复千问主窗口并继续确认。只有复查确认尚未点击时最多再尝试一次;仅备份并清理原会话内仍与本次请求完全一致的文字,保留用户后来修改的草稿。点击后无法确认提交状态时不会自动重发或清理输入,避免重复执行。
|
|
18
18
|
|
|
19
|
+
首轮发送后,千问可能先替换首页输入框,再挂载用户消息。插件会在限定时间内等待本次原文和原生任务身份就绪,再读取回复;等待期间的用户操作、页面变化或任务身份切换仍会使绑定失效。已点击发送后的绑定错误使用 `QWEN_SESSION_BIND_FAILED`,明确提示不会重复提交,不再标为尚未发送。
|
|
20
|
+
|
|
19
21
|
云端故障、账号额度不足或登录过期仍可能需要修复服务或账号,重连 CDP 本身不能证明上游模型可用。
|
|
20
22
|
|
|
21
23
|
文件、图片、视频附件经桌面原生上传入口送入本轮任务;回传只采集本轮助手通过“已展示最终文件”工具声明的产物,不扫描普通正文中的任意路径。图片按内容去重,视频以 `video/*` 文件附件交给 AUN,使用分块读取避免大视频导致 CDP 断连。单条最多 8 个附件,单个不超过 32 MiB、合计不超过 64 MiB;实际可处理的格式及内容理解能力由桌面端和模型决定。验证证据见仓库的 `docs/verification/2026-10-20-qwenwork-media.md`。
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
|
|
25
27
|
当前源码声明 `agent/task/run`、`agent/task/recent`、`agent/task/read`、`agent/task/switch` 和 `agent/task/new`。原生 CDP 的 `run` 接受 `{"task":"需要执行的自然语言任务"}`,未选择任务时独立新建;`switch` 或 `new` 成功后,同一 Provider 与已认证 Peer 的后续 `run` 续聊并返回 `text`、`sessionId`,重载清除选择。切换前后核对真实活动 ID,目标不存在时不新建替代任务。
|
|
26
28
|
|
|
27
|
-
任务身份来自唯一可见编辑器的原生 `chatId`、`subChatId
|
|
29
|
+
任务身份来自唯一可见编辑器的原生 `chatId`、`subChatId`;URL 和“新任务”外观不能证明身份。千问明确声明 `version: 2`、`mode: shared` 时,按其原生共享模式读取任务,不要求隔离身份或附加 `expectedScope`;其他启动状态仍经当前账号 scope 查询验证。读取前后都会核对启动模式,模式变化时丢弃结果,不自动降级重试。切换到其他任务需要该任务已加载的唯一原生侧栏入口;入口缺失或不唯一时明确拒绝,不改写 URL 或猜测目标。
|
|
28
30
|
|
|
29
31
|
尚未分配原生 ID 的空白页返回 `qwenwork-pending:` 临时句柄,首轮 `run` 后更新为原生 ID;页面状态变化后失效,`read` 不接受临时句柄。relay 中继及仅有 direct 接口的 CLI 客户端明确不支持四项管理能力,`run` 保留原文字契约,不声称返回本地原生会话 ID。
|
|
30
32
|
|
|
@@ -139,6 +139,7 @@ class QwenCdpClient {
|
|
|
139
139
|
sequence = 0;
|
|
140
140
|
pending = new Map();
|
|
141
141
|
historyIdentityScope;
|
|
142
|
+
historyIdentityMode;
|
|
142
143
|
options;
|
|
143
144
|
constructor(options = {}) {
|
|
144
145
|
this.options = {
|
|
@@ -174,10 +175,8 @@ class QwenCdpClient {
|
|
|
174
175
|
if (!state.chatId) {
|
|
175
176
|
if (state.messages)
|
|
176
177
|
throw new Error("千问已有消息但原生任务上下文缺失,不能确认任务身份");
|
|
177
|
-
const scope = await
|
|
178
|
-
|
|
179
|
-
if (checked?.valid !== true)
|
|
180
|
-
throw new Error("千问空白任务身份上下文已变化,未发送消息");
|
|
178
|
+
const scope = await this.taskIdentityScope();
|
|
179
|
+
await this.checkTaskIdentityScope(scope);
|
|
181
180
|
}
|
|
182
181
|
else {
|
|
183
182
|
const chat = await this.queryHistory("chats.get", { id: state.chatId });
|
|
@@ -192,6 +191,7 @@ class QwenCdpClient {
|
|
|
192
191
|
}
|
|
193
192
|
async waitForAssignedTask(previous, reservationToken, submittedText) {
|
|
194
193
|
const deadline = Date.now() + Math.min(this.options.timeoutMs, 10_000);
|
|
194
|
+
let assigned;
|
|
195
195
|
while (Date.now() < deadline) {
|
|
196
196
|
const candidate = await this.evaluate(`(() => {
|
|
197
197
|
const state = ${taskStateExpression};
|
|
@@ -200,21 +200,31 @@ class QwenCdpClient {
|
|
|
200
200
|
const editorReplaced = state.editor !== ${previous.editor};
|
|
201
201
|
const oldEditorVisible = reservedEditor?.getClientRects?.().length > 0 && getComputedStyle(reservedEditor).visibility !== 'hidden'
|
|
202
202
|
&& !reservedEditor.closest('[inert],[hidden],[aria-hidden="true"]');
|
|
203
|
-
const
|
|
204
|
-
.
|
|
205
|
-
|
|
206
|
-
const replacementConfirmed = !oldEditorVisible && submittedMessage;
|
|
203
|
+
const userMessages = [...document.querySelectorAll('[data-message-id][data-conversation-user-text="true"],[data-message-id] [data-role="user"] [data-slot="session-user-text"]')]
|
|
204
|
+
.map(message => message.innerText.trim()).filter(Boolean);
|
|
205
|
+
const submittedMessage = userMessages.includes(${JSON.stringify(submittedText.trim())});
|
|
207
206
|
const currentEditor = [...document.querySelectorAll(${JSON.stringify(exports.inputSelector)})].find(editor => globalThis.__agentBridgeQwenEditors?.editors.get(editor) === state.editor);
|
|
208
207
|
if (state.url !== ${JSON.stringify(previous.url)}
|
|
209
208
|
|| reservation?.token !== ${JSON.stringify(reservationToken)}
|
|
210
|
-
|| (editorReplaced ? !
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
|| (editorReplaced ? oldEditorVisible || (userMessages.length > 0 && !submittedMessage) : reservedEditor !== currentEditor)) {
|
|
210
|
+
const reason = state.url !== ${JSON.stringify(previous.url)} ? '页面地址已变化'
|
|
211
|
+
: reservation?.token !== ${JSON.stringify(reservationToken)} ? '空白绑定已撤销'
|
|
212
|
+
: editorReplaced && oldEditorVisible ? '原编辑器仍可见'
|
|
213
|
+
: editorReplaced ? '用户消息与本次原文不符' : '编辑器绑定不符';
|
|
214
|
+
throw new Error('千问首轮原生任务页面、编辑器或空白绑定已失效(' + reason + '),任务可能已提交,请勿重复发送');
|
|
215
|
+
}
|
|
216
|
+
// 首页编辑器和用户消息分批挂载;消息未出现时继续等待,不能提前判为失败或确认绑定。
|
|
217
|
+
return { state, ready: !editorReplaced || submittedMessage };
|
|
214
218
|
})()`);
|
|
215
|
-
|
|
219
|
+
const state = candidate.state;
|
|
220
|
+
if (assigned && (state.chatId !== assigned.chatId || state.subChatId !== assigned.subChatId)) {
|
|
221
|
+
throw new Error("千问首轮等待绑定期间原生任务身份已切换,任务可能已提交,请勿重复发送");
|
|
222
|
+
}
|
|
223
|
+
if (state.chatId && state.subChatId)
|
|
224
|
+
assigned ??= state;
|
|
225
|
+
if (candidate.ready && state.chatId && state.subChatId) {
|
|
216
226
|
const verified = await this.readTaskState();
|
|
217
|
-
if (verified.chatId !==
|
|
227
|
+
if (verified.chatId !== state.chatId || verified.subChatId !== state.subChatId)
|
|
218
228
|
throw new Error("千问首轮任务身份已切换,任务可能已提交,请勿重复发送");
|
|
219
229
|
return verified;
|
|
220
230
|
}
|
|
@@ -349,6 +359,7 @@ class QwenCdpClient {
|
|
|
349
359
|
const socket = this.socket;
|
|
350
360
|
this.socket = undefined;
|
|
351
361
|
this.historyIdentityScope = undefined;
|
|
362
|
+
this.historyIdentityMode = undefined;
|
|
352
363
|
socket?.close();
|
|
353
364
|
for (const pending of this.pending.values())
|
|
354
365
|
pending.reject(new Error("CDP 已关闭"));
|
|
@@ -466,8 +477,11 @@ class QwenCdpClient {
|
|
|
466
477
|
finally { if (reservation) reservation.submitting = false; }
|
|
467
478
|
return true;
|
|
468
479
|
})()`);
|
|
469
|
-
if (sent === true)
|
|
480
|
+
if (sent === true) {
|
|
481
|
+
stage = "确认千问办公任务绑定(已点击发送,不会重复提交)";
|
|
482
|
+
code = "QWEN_SESSION_BIND_FAILED";
|
|
470
483
|
break;
|
|
484
|
+
}
|
|
471
485
|
submitAttempted = false;
|
|
472
486
|
if (attempt === 1)
|
|
473
487
|
throw new Error("千问发送按钮未就绪或输入校验失败,未发送消息");
|
|
@@ -873,13 +887,39 @@ class QwenCdpClient {
|
|
|
873
887
|
}
|
|
874
888
|
/** 仅开放已核实的会话历史只读查询,不允许从历史 provider 调用 mutation。 */
|
|
875
889
|
async queryHistory(path, input) {
|
|
876
|
-
const scope = await
|
|
877
|
-
const result = this.historyResult(await this.trpc(path, "query", { ...input, expectedScope: scope }), path);
|
|
878
|
-
|
|
879
|
-
if (checked?.valid !== true)
|
|
880
|
-
throw new Error("千问历史查询后身份校验失败,未返回任务内容");
|
|
890
|
+
const scope = await this.taskIdentityScope();
|
|
891
|
+
const result = this.historyResult(await this.trpc(path, "query", { ...input, ...(scope ? { expectedScope: scope } : {}) }), path);
|
|
892
|
+
await this.checkTaskIdentityScope(scope);
|
|
881
893
|
return result;
|
|
882
894
|
}
|
|
895
|
+
async taskIdentityScope() {
|
|
896
|
+
const mode = await (this.historyIdentityMode ??= this.readHistoryIdentityMode());
|
|
897
|
+
if (await this.readHistoryIdentityMode() !== mode)
|
|
898
|
+
throw new Error("千问原生身份启动模式已变化,未读取任务内容");
|
|
899
|
+
return mode === "isolated" ? (this.historyIdentityScope ??= this.readHistoryIdentityScope()) : undefined;
|
|
900
|
+
}
|
|
901
|
+
async checkTaskIdentityScope(scope) {
|
|
902
|
+
if (await this.readHistoryIdentityMode() !== (scope ? "isolated" : "shared"))
|
|
903
|
+
throw new Error("千问原生身份启动模式已变化,未返回任务内容");
|
|
904
|
+
if (scope) {
|
|
905
|
+
const checked = this.historyResult(await this.trpc("auth.checkLocalIdentityScope", "query", { scope }), "auth.checkLocalIdentityScope");
|
|
906
|
+
if (checked?.valid !== true)
|
|
907
|
+
throw new Error("千问任务身份上下文已变化,未返回任务内容或发送消息");
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* 新版千问在 shared 模式下明确关闭本地身份隔离,插件不向原生接口附加 expectedScope。
|
|
912
|
+
* 未明确暴露 shared 标记时按隔离模式处理,避免把身份状态误降级为共享模式。
|
|
913
|
+
*/
|
|
914
|
+
async readHistoryIdentityMode() {
|
|
915
|
+
const mode = await this.evaluate(`(() => {
|
|
916
|
+
const startup = globalThis.__localIdentityStartup;
|
|
917
|
+
return startup && startup.version === 2 && startup.mode === "shared" ? "shared" : "isolated";
|
|
918
|
+
})()`);
|
|
919
|
+
if (mode !== "shared" && mode !== "isolated")
|
|
920
|
+
throw new Error("千问原生身份启动模式无效,未读取任务内容");
|
|
921
|
+
return mode;
|
|
922
|
+
}
|
|
883
923
|
async readHistoryIdentityScope() {
|
|
884
924
|
const status = this.historyResult(await this.trpc("auth.getLocalIdentityStatus", "query", {}), "auth.getLocalIdentityStatus");
|
|
885
925
|
const scope = status?.scope;
|
|
@@ -17,7 +17,7 @@ const session_history_1 = require("./session-history");
|
|
|
17
17
|
const ability_1 = require("./ability");
|
|
18
18
|
exports.qwenworkManifest = {
|
|
19
19
|
id: "qwenwork",
|
|
20
|
-
version: "1.0.
|
|
20
|
+
version: "1.0.42",
|
|
21
21
|
displayName: "千问办公",
|
|
22
22
|
entry: "dist/index.js",
|
|
23
23
|
apiVersion: "1",
|
package/package.json
CHANGED