agent-bridge-qwenwork 1.0.13 → 1.0.14

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,27 @@ 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 encoded = await this.evaluate(`(() => {
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 button of (message.querySelectorAll?.('button') ?? [])) if (button.innerText.includes('已展示最终文件')) button.click();
236
+ for (const image of (message.querySelectorAll?.('img[src^="data:image/"]') ?? [])) files.push({ address: image.getAttribute('src'), filename: image.getAttribute('alt') || '' });
237
+ for (const link of (message.querySelectorAll?.('a[href]') ?? [])) files.push({ address: link.getAttribute('href'), filename: link.innerText || '' });
238
+ }
239
+ return JSON.stringify(files);
240
+ })()`);
241
+ const files = [...new Map(JSON.parse(encoded || "[]")
242
+ .map((item) => [item.address, item]).filter(([address]) => typeof address === "string")).values()];
243
+ const dataImages = files.map((item) => ({ ...item, image: decodeQwenDataImage(item.address) })).filter((item) => Boolean(item.image));
244
+ const addresses = files.map((item) => normalizeQwenImageUrl(item.address)).filter((value) => Boolean(value)).slice(0, Math.max(0, attachments_1.MAX_ATTACHMENTS - dataImages.length));
245
+ 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 }));
246
+ if (!addresses.length) {
247
+ (0, attachments_1.validateAttachments)(attachments);
248
+ return attachments;
249
+ }
250
+ const downloaded = await this.evaluate(`(async () => {
226
251
  const urls = ${JSON.stringify(addresses)}; const result = []; let total = 0;
227
252
  for (const url of urls) {
228
253
  const response = await fetch(url); if (!response.ok || !response.body) continue;
@@ -235,8 +260,7 @@ class QwenCdpClient {
235
260
  }
236
261
  return result;
237
262
  })()`);
238
- const attachments = [];
239
- for (const item of encoded) {
263
+ for (const item of downloaded) {
240
264
  const data = new Uint8Array(Buffer.from(item.data, "base64"));
241
265
  const contentType = (0, attachments_1.detectImageContentType)(data);
242
266
  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.14",
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.14",
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.14",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",