@agent-wechat/agent-wechat 1.0.0-beta.16 → 1.0.0-beta.19

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 +47 -7
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -178,6 +178,7 @@ var decimal = (value) => {
178
178
  return value;
179
179
  };
180
180
  var NativeWeChatClient = class {
181
+ mediaBatchSupported = true;
181
182
  baseUrl;
182
183
  token;
183
184
  fetchImpl;
@@ -368,8 +369,8 @@ var NativeWeChatClient = class {
368
369
  groups(accountId, options) {
369
370
  return this.request(`v1/accounts/${id(accountId)}/groups${listQuery(options)}`);
370
371
  }
371
- thread(accountId, threadId2) {
372
- return this.request(`v1/accounts/${id(accountId)}/threads/${id(threadId2)}`);
372
+ thread(accountId, threadId2, signal) {
373
+ return this.request(`v1/accounts/${id(accountId)}/threads/${id(threadId2)}`, { signal });
373
374
  }
374
375
  contact(accountId, username) {
375
376
  return this.request(`v1/accounts/${id(accountId)}/contacts/${id(username)}`);
@@ -447,8 +448,8 @@ var NativeWeChatClient = class {
447
448
  syncGroups(accountId) {
448
449
  return this.request(`v1/accounts/${id(accountId)}/group-sync`, { method: "POST", body: "{}" });
449
450
  }
450
- async messages(accountId, threadId2, options) {
451
- const result = await this.request(`v1/accounts/${id(accountId)}/threads/${id(threadId2)}/messages${listQuery(options)}`);
451
+ async messages(accountId, threadId2, options, signal) {
452
+ const result = await this.request(`v1/accounts/${id(accountId)}/threads/${id(threadId2)}/messages${listQuery(options)}`, { signal });
452
453
  for (const msg of result.items) {
453
454
  if (isNativeTombstone(msg))
454
455
  continue;
@@ -520,8 +521,38 @@ var NativeWeChatClient = class {
520
521
  throw new Error("An idempotency key is required");
521
522
  return this.request(`v1/accounts/${id(accountId)}/sends`, { method: "POST", headers: { "Idempotency-Key": key }, body: JSON.stringify(input) });
522
523
  }
523
- mediaAssets(accountId, messageId) {
524
- return this.request(`v1/accounts/${id(accountId)}/messages/${id(messageId)}/media`);
524
+ mediaAssets(accountId, messageId, signal) {
525
+ return this.request(`v1/accounts/${id(accountId)}/messages/${id(messageId)}/media`, { signal });
526
+ }
527
+ async mediaAssetsBatch(accountId, messageIds, signal) {
528
+ if (!messageIds.length || messageIds.length > 40 || messageIds.some((id2) => !id2 || id2.length > 8192) || new Set(messageIds).size !== messageIds.length)
529
+ throw new Error("Invalid media lookup batch");
530
+ if (this.mediaBatchSupported) {
531
+ try {
532
+ const batch = await this.request(`v1/accounts/${id(accountId)}/media/lookup`, { method: "POST", body: JSON.stringify({ messageIds }), signal });
533
+ const expected = new Set(messageIds);
534
+ if (!Array.isArray(batch.items) || batch.items.length !== expected.size)
535
+ throw new Error("Invalid media lookup response");
536
+ for (const item of batch.items) {
537
+ if (!expected.delete(item.messageId) || !Array.isArray(item.assets) || item.error !== null && typeof item.error !== "string" || item.assets.some((asset) => asset.accountId !== accountId || asset.messageId !== item.messageId))
538
+ throw new Error("Invalid media lookup identity");
539
+ }
540
+ return batch;
541
+ } catch (error) {
542
+ if (!(error instanceof NativeApiError) || ![404, 405].includes(error.status))
543
+ throw error;
544
+ this.mediaBatchSupported = false;
545
+ }
546
+ }
547
+ return { items: await Promise.all(messageIds.map(async (messageId) => {
548
+ try {
549
+ return { messageId, assets: (await this.mediaAssets(accountId, messageId, signal)).items, error: null };
550
+ } catch (error) {
551
+ if (!(error instanceof NativeApiError))
552
+ throw error;
553
+ return { messageId, assets: [], error: error.code };
554
+ }
555
+ })) };
525
556
  }
526
557
  transferMedia(accountId, input) {
527
558
  return this.request(`v1/accounts/${id(accountId)}/messages/${id(input.messageId)}/media-transfers`, { method: "POST", body: JSON.stringify(input) });
@@ -1402,6 +1433,15 @@ function recalledNativeMessage(message, recall) {
1402
1433
  }
1403
1434
 
1404
1435
  // src/native-quote.ts
1436
+ function sameEmbeddedQuote(stored, current) {
1437
+ if (stored.state === "unsupported" && current.state === "embedded")
1438
+ return ["serverId", "type", "appMessageType", "senderId", "direction"].every((field) => (stored[field] ?? null) === (current[field] ?? null));
1439
+ const compared = { ...current };
1440
+ for (const field of ["embeddedLink", "embeddedSticker"]) {
1441
+ if (!Object.hasOwn(stored, field)) delete compared[field];
1442
+ }
1443
+ return JSON.stringify(stored) === JSON.stringify(compared);
1444
+ }
1405
1445
  function renderEmbeddedQuote(message, permitted = true, imageBody) {
1406
1446
  const comment = (message.body ?? "").slice(0, 16384);
1407
1447
  const source = message.quote;
@@ -2707,7 +2747,7 @@ async function recheckNativeInputs(client, state, messages) {
2707
2747
  invalidateNativePreparedInputs(message.accountId, affected);
2708
2748
  throw new NativeInputInvalidated();
2709
2749
  }
2710
- if (!quote || JSON.stringify(quote) !== JSON.stringify(message.quote)) throw Error("Native embedded quote changed; delivery held for review");
2750
+ if (!quote || !sameEmbeddedQuote(message.quote, quote)) throw Error("Native embedded quote changed; delivery held for review");
2711
2751
  }
2712
2752
  if (!state.isCurrent(message)) throw new NativeInputInvalidated();
2713
2753
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-wechat/agent-wechat",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.19",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -11,7 +11,7 @@
11
11
  "esbuild": "^0.25.0",
12
12
  "openclaw": "2026.10.7",
13
13
  "typescript": "^5.4.5",
14
- "@agent-wechat/shared": "1.0.0-beta.4"
14
+ "@agent-wechat/shared": "1.0.0-beta.5"
15
15
  },
16
16
  "openclaw": {
17
17
  "extensions": [