agent-bridge-qwenwork 1.0.13 → 1.0.15

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.
@@ -7,6 +7,7 @@ exports.isQwenHeartbeatReplyComplete = isQwenHeartbeatReplyComplete;
7
7
  exports.isQwenApiUnavailableReply = isQwenApiUnavailableReply;
8
8
  exports.isQwenBridgeHealthPrompt = isQwenBridgeHealthPrompt;
9
9
  exports.normalizeQwenImageUrl = normalizeQwenImageUrl;
10
+ exports.decodeQwenDataImage = decodeQwenDataImage;
10
11
  const node_crypto_1 = require("node:crypto");
11
12
  const cdp_draft_1 = require("../cdp-draft");
12
13
  const attachments_1 = require("../../attachments");
@@ -52,6 +53,14 @@ function normalizeQwenImageUrl(address) {
52
53
  return undefined;
53
54
  return url.href;
54
55
  }
56
+ function decodeQwenDataImage(address) {
57
+ const match = /^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/=]+)$/i.exec(address);
58
+ if (!match)
59
+ return undefined;
60
+ const data = new Uint8Array(Buffer.from(match[2], "base64"));
61
+ const contentType = (0, attachments_1.detectImageContentType)(data);
62
+ return contentType && contentType === match[1].toLowerCase() ? { data, contentType } : undefined;
63
+ }
55
64
  function wait(ms, signal) {
56
65
  if (signal?.aborted)
57
66
  return Promise.reject(new Error("请求已取消"));
@@ -218,11 +227,45 @@ class QwenCdpClient {
218
227
  throw new Error("千问办公 UI 超时未返回回复");
219
228
  }
220
229
  async readImages(beforeIds) {
221
- const links = await this.evaluate(`JSON.stringify([...document.querySelectorAll(${JSON.stringify(exports.assistantMessageSelector)})].filter(element => ${JSON.stringify([...beforeIds])}.indexOf(element.getAttribute('data-message-id')) < 0).flatMap(element => [...(element.querySelectorAll?.('a[href]') ?? [])].map(a => a.getAttribute('href')).filter(Boolean)))`);
222
- const addresses = [...new Set(JSON.parse(links || "[]"))].map(normalizeQwenImageUrl).filter((value) => Boolean(value)).slice(0, attachments_1.MAX_ATTACHMENTS);
223
- if (!addresses.length)
224
- return [];
225
- const encoded = await this.evaluate(`(async () => {
230
+ const collectImages = `(() => {
231
+ const before = new Set(${JSON.stringify([...beforeIds])}); const files = [];
232
+ for (const part of document.querySelectorAll(${JSON.stringify(exports.assistantMessageSelector)})) {
233
+ if (before.has(part.getAttribute('data-message-id'))) continue;
234
+ const message = part.closest?.('[data-assistant-message-id]') || part;
235
+ for (const image of (message.querySelectorAll?.('img[src^="data:image/"]') ?? [])) files.push({ address: image.getAttribute('src'), filename: image.getAttribute('alt') || '' });
236
+ for (const link of (message.querySelectorAll?.('a[href^="file://"]') ?? [])) files.push({ address: link.getAttribute('href'), filename: link.innerText || '' });
237
+ }
238
+ return JSON.stringify(files);
239
+ })()`;
240
+ // 工具区域由 React 异步展开,点击和读取必须分开执行。
241
+ await this.evaluate(`(() => {
242
+ const before = new Set(${JSON.stringify([...beforeIds])});
243
+ for (const part of document.querySelectorAll(${JSON.stringify(exports.assistantMessageSelector)})) {
244
+ if (before.has(part.getAttribute('data-message-id'))) continue;
245
+ const message = part.closest?.('[data-assistant-message-id]') || part;
246
+ for (const button of (message.querySelectorAll?.('button') ?? [])) {
247
+ if (button.innerText.includes('已展示最终文件') && button.getAttribute('aria-expanded') !== 'true') button.click();
248
+ }
249
+ }
250
+ return true;
251
+ })()`);
252
+ let encoded = "[]";
253
+ for (let attempt = 0; attempt < 12; attempt++) {
254
+ encoded = String(await this.evaluate(collectImages) ?? "[]");
255
+ if (encoded !== "[]")
256
+ break;
257
+ await wait(250);
258
+ }
259
+ const files = [...new Map(JSON.parse(encoded || "[]")
260
+ .map((item) => [item.address, item]).filter(([address]) => typeof address === "string")).values()];
261
+ const dataImages = files.map((item) => ({ ...item, image: decodeQwenDataImage(item.address) })).filter((item) => Boolean(item.image));
262
+ const addresses = files.map((item) => normalizeQwenImageUrl(item.address)).filter((value) => Boolean(value)).slice(0, Math.max(0, attachments_1.MAX_ATTACHMENTS - dataImages.length));
263
+ const attachments = dataImages.map((item) => ({ kind: "image", data: item.image.data, filename: (0, attachments_1.attachmentFilename)(item.filename || `qwen-${(0, node_crypto_1.randomUUID)()}.jpg`), contentType: item.image.contentType }));
264
+ if (!addresses.length) {
265
+ (0, attachments_1.validateAttachments)(attachments);
266
+ return attachments;
267
+ }
268
+ const downloaded = await this.evaluate(`(async () => {
226
269
  const urls = ${JSON.stringify(addresses)}; const result = []; let total = 0;
227
270
  for (const url of urls) {
228
271
  const response = await fetch(url); if (!response.ok || !response.body) continue;
@@ -235,8 +278,7 @@ class QwenCdpClient {
235
278
  }
236
279
  return result;
237
280
  })()`);
238
- const attachments = [];
239
- for (const item of encoded) {
281
+ for (const item of downloaded) {
240
282
  const data = new Uint8Array(Buffer.from(item.data, "base64"));
241
283
  const contentType = (0, attachments_1.detectImageContentType)(data);
242
284
  if (!contentType)
@@ -11,7 +11,7 @@ const desktop_launch_1 = require("../desktop-launch");
11
11
  const CHAT_HEARTBEAT_INTERVAL_MS = 2 * 60 * 60_000;
12
12
  exports.qwenworkManifest = {
13
13
  id: "qwenwork",
14
- version: "1.0.13",
14
+ version: "1.0.15",
15
15
  displayName: "千问办公",
16
16
  entry: "dist/index.js",
17
17
  apiVersion: "1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-qwenwork",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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.13",
3
+ "version": "1.0.15",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",