agent-bridge-qwenwork 1.0.40 → 1.0.41

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
@@ -24,7 +24,7 @@
24
24
 
25
25
  当前源码声明 `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
26
 
27
- 任务身份来自唯一可见编辑器的原生 `chatId`、`subChatId`,并经当前账号 scope 查询验证;URL 和“新任务”外观不能证明身份。切换到其他任务需要该任务已加载的唯一原生侧栏入口;入口缺失或不唯一时明确拒绝,不改写 URL 或猜测目标。
27
+ 任务身份来自唯一可见编辑器的原生 `chatId`、`subChatId`;URL 和“新任务”外观不能证明身份。千问明确声明 `version: 2`、`mode: shared` 时,按其原生共享模式读取任务,不要求隔离身份或附加 `expectedScope`;其他启动状态仍经当前账号 scope 查询验证。读取前后都会核对启动模式,模式变化时丢弃结果,不自动降级重试。切换到其他任务需要该任务已加载的唯一原生侧栏入口;入口缺失或不唯一时明确拒绝,不改写 URL 或猜测目标。
28
28
 
29
29
  尚未分配原生 ID 的空白页返回 `qwenwork-pending:` 临时句柄,首轮 `run` 后更新为原生 ID;页面状态变化后失效,`read` 不接受临时句柄。relay 中继及仅有 direct 接口的 CLI 客户端明确不支持四项管理能力,`run` 保留原文字契约,不声称返回本地原生会话 ID。
30
30
 
@@ -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 (this.historyIdentityScope ??= this.readHistoryIdentityScope());
178
- const checked = this.historyResult(await this.trpc("auth.checkLocalIdentityScope", "query", { scope }), "auth.checkLocalIdentityScope");
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 });
@@ -349,6 +348,7 @@ class QwenCdpClient {
349
348
  const socket = this.socket;
350
349
  this.socket = undefined;
351
350
  this.historyIdentityScope = undefined;
351
+ this.historyIdentityMode = undefined;
352
352
  socket?.close();
353
353
  for (const pending of this.pending.values())
354
354
  pending.reject(new Error("CDP 已关闭"));
@@ -873,13 +873,39 @@ class QwenCdpClient {
873
873
  }
874
874
  /** 仅开放已核实的会话历史只读查询,不允许从历史 provider 调用 mutation。 */
875
875
  async queryHistory(path, input) {
876
- const scope = await (this.historyIdentityScope ??= this.readHistoryIdentityScope());
877
- const result = this.historyResult(await this.trpc(path, "query", { ...input, expectedScope: scope }), path);
878
- const checked = this.historyResult(await this.trpc("auth.checkLocalIdentityScope", "query", { scope }), "auth.checkLocalIdentityScope");
879
- if (checked?.valid !== true)
880
- throw new Error("千问历史查询后身份校验失败,未返回任务内容");
876
+ const scope = await this.taskIdentityScope();
877
+ const result = this.historyResult(await this.trpc(path, "query", { ...input, ...(scope ? { expectedScope: scope } : {}) }), path);
878
+ await this.checkTaskIdentityScope(scope);
881
879
  return result;
882
880
  }
881
+ async taskIdentityScope() {
882
+ const mode = await (this.historyIdentityMode ??= this.readHistoryIdentityMode());
883
+ if (await this.readHistoryIdentityMode() !== mode)
884
+ throw new Error("千问原生身份启动模式已变化,未读取任务内容");
885
+ return mode === "isolated" ? (this.historyIdentityScope ??= this.readHistoryIdentityScope()) : undefined;
886
+ }
887
+ async checkTaskIdentityScope(scope) {
888
+ if (await this.readHistoryIdentityMode() !== (scope ? "isolated" : "shared"))
889
+ throw new Error("千问原生身份启动模式已变化,未返回任务内容");
890
+ if (scope) {
891
+ const checked = this.historyResult(await this.trpc("auth.checkLocalIdentityScope", "query", { scope }), "auth.checkLocalIdentityScope");
892
+ if (checked?.valid !== true)
893
+ throw new Error("千问任务身份上下文已变化,未返回任务内容或发送消息");
894
+ }
895
+ }
896
+ /**
897
+ * 新版千问在 shared 模式下明确关闭本地身份隔离,插件不向原生接口附加 expectedScope。
898
+ * 未明确暴露 shared 标记时按隔离模式处理,避免把身份状态误降级为共享模式。
899
+ */
900
+ async readHistoryIdentityMode() {
901
+ const mode = await this.evaluate(`(() => {
902
+ const startup = globalThis.__localIdentityStartup;
903
+ return startup && startup.version === 2 && startup.mode === "shared" ? "shared" : "isolated";
904
+ })()`);
905
+ if (mode !== "shared" && mode !== "isolated")
906
+ throw new Error("千问原生身份启动模式无效,未读取任务内容");
907
+ return mode;
908
+ }
883
909
  async readHistoryIdentityScope() {
884
910
  const status = this.historyResult(await this.trpc("auth.getLocalIdentityStatus", "query", {}), "auth.getLocalIdentityStatus");
885
911
  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.40",
20
+ version: "1.0.41",
21
21
  displayName: "千问办公",
22
22
  entry: "dist/index.js",
23
23
  apiVersion: "1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-qwenwork",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "agent-bridge 的千问办公插件。",
5
5
  "keywords": [
6
6
  "mu-agent-bridge-plugin",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "qwenwork",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",