@agent-wechat/agent-wechat 0.15.0 → 0.15.1

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -23
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -5563,6 +5563,9 @@ function attachmentKindForMessageType(baseType) {
5563
5563
  if (baseType === 49) return "file";
5564
5564
  return void 0;
5565
5565
  }
5566
+ function mediaRequestQuality(baseType) {
5567
+ return baseType === 3 ? "best" : "full";
5568
+ }
5566
5569
  function attachmentKindForResult(result, fallback) {
5567
5570
  if (result.type === "image" || result.type === "emoji") return "image";
5568
5571
  if (result.type === "voice") return "audio";
@@ -5615,8 +5618,11 @@ function renderAttachmentBody(originalBody, attachment, exposeNonVisualPath = tr
5615
5618
  return appendReference(originalBody || "<media:video>", `[Video file: ${attachment.path}]`);
5616
5619
  }
5617
5620
  }
5618
- if (!originalBody) return attachment.kind === "image" ? "<media:image>" : originalBody;
5619
- return originalBody;
5621
+ const body = originalBody || (attachment.kind === "image" ? "<media:image>" : originalBody);
5622
+ if (attachment.kind === "image" && attachment.quality === "thumbnail") {
5623
+ return appendReference(body, "[Image preview only: thumbnail quality]");
5624
+ }
5625
+ return body;
5620
5626
  }
5621
5627
  function applyLiveAttachment(message, originalBody, attachment) {
5622
5628
  const attachable = attachment?.status === "ready" && attachment.path && attachment.kind !== "file";
@@ -5889,6 +5895,41 @@ async function sendWeChatMedia(cfg, to, text, mediaUrl, audioAsVoice = false, id
5889
5895
  return `agent-wechat:${to}:${Date.now()}`;
5890
5896
  }
5891
5897
 
5898
+ // src/media-poll.ts
5899
+ function rejectsBestQuality(error) {
5900
+ return error instanceof Error && /^(400|422)\b/.test(error.message) && /\bbest\b/i.test(error.message);
5901
+ }
5902
+ async function pollMedia(client, chatId, localId, quality, log, maxAttempts = 15, intervalMs = 1e3) {
5903
+ let lastResult = null;
5904
+ let legacyImageServer = false;
5905
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
5906
+ let result;
5907
+ if (legacyImageServer) {
5908
+ const full = await client.getMedia(chatId, localId, "full");
5909
+ if (full.data || full.type === "unsupported") return full;
5910
+ const preview = await client.getMedia(chatId, localId, "thumbnail");
5911
+ result = preview.data ? { ...preview, quality: "thumbnail" } : full;
5912
+ } else {
5913
+ try {
5914
+ result = await client.getMedia(chatId, localId, quality);
5915
+ } catch (error) {
5916
+ if (quality !== "best" || !rejectsBestQuality(error)) throw error;
5917
+ legacyImageServer = true;
5918
+ log?.info?.("[media] Server does not support best image quality; trying full then thumbnail");
5919
+ attempt--;
5920
+ continue;
5921
+ }
5922
+ }
5923
+ lastResult = result;
5924
+ if (result.type === "unsupported" || result.data) return result;
5925
+ if (attempt < maxAttempts) {
5926
+ log?.info?.(`[media] Attempt ${attempt}/${maxAttempts} for ${chatId}:${localId} returned no data, retrying...`);
5927
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
5928
+ }
5929
+ }
5930
+ return lastResult;
5931
+ }
5932
+
5892
5933
  // src/access-control.ts
5893
5934
  import {
5894
5935
  buildChannelKeyCandidates,
@@ -6117,24 +6158,6 @@ function sleep(ms, signal) {
6117
6158
  });
6118
6159
  });
6119
6160
  }
6120
- async function pollMedia(client, chatId, localId, log, maxAttempts = 15, intervalMs = 1e3) {
6121
- let lastResult = null;
6122
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
6123
- const result = await client.getMedia(chatId, localId, "full");
6124
- lastResult = result;
6125
- if (result.type === "unsupported") {
6126
- return result;
6127
- }
6128
- if (result.data) {
6129
- return result;
6130
- }
6131
- if (attempt < maxAttempts) {
6132
- log?.info?.(`[media] Attempt ${attempt}/${maxAttempts} for ${chatId}:${localId} returned no data, retrying...`);
6133
- await new Promise((r) => setTimeout(r, intervalMs));
6134
- }
6135
- }
6136
- return lastResult;
6137
- }
6138
6161
  function enqueueWeChatSystemEvent(text, contextKey) {
6139
6162
  try {
6140
6163
  const core = getWeChatRuntime();
@@ -6151,7 +6174,7 @@ async function retrieveAttachment(client, chatId, msg, liveAccount, log, maxAtte
6151
6174
  if (!expectedKind) return void 0;
6152
6175
  const fallbackFilename = attachmentFallbackFilename(expectedKind, msg.localId, msg.content);
6153
6176
  try {
6154
- const result = await pollMedia(client, chatId, msg.localId, log, maxAttempts);
6177
+ const result = await pollMedia(client, chatId, msg.localId, mediaRequestQuality(baseType), log, maxAttempts);
6155
6178
  if (!result) {
6156
6179
  return { kind: expectedKind, status: "unavailable", filename: fallbackFilename };
6157
6180
  }
@@ -6173,9 +6196,9 @@ async function retrieveAttachment(client, chatId, msg, liveAccount, log, maxAtte
6173
6196
  saveMediaBuffer: getWeChatRuntime().channel.media.saveMediaBuffer
6174
6197
  });
6175
6198
  log?.info?.(
6176
- `[wechat:${liveAccount.accountId}] Saved ${kind} attachment for msg ${msg.localId} (${saved.size} bytes)`
6199
+ `[wechat:${liveAccount.accountId}] Saved ${kind} attachment for msg ${msg.localId} (${saved.size} bytes${result.quality ? `, ${result.quality} quality` : ""})`
6177
6200
  );
6178
- return { kind, status: "ready", filename: saved.filename, mime, path: saved.path };
6201
+ return { kind, status: "ready", filename: saved.filename, mime, path: saved.path, quality: result.quality };
6179
6202
  } catch (error) {
6180
6203
  const status = error instanceof AttachmentTooLargeError ? "too_large" : "error";
6181
6204
  log?.error?.(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-wechat/agent-wechat",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -11,7 +11,7 @@
11
11
  "esbuild": "^0.25.0",
12
12
  "openclaw": "^2026.8.1",
13
13
  "typescript": "^5.4.5",
14
- "@agent-wechat/shared": "0.3.0"
14
+ "@agent-wechat/shared": "0.3.1"
15
15
  },
16
16
  "openclaw": {
17
17
  "extensions": [