@agent-wechat/agent-wechat 1.2.0 → 1.3.0-beta.0

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +66 -17
  3. package/package.json +4 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nick Yu and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1512,6 +1512,7 @@ function recalledNativeMessage(message, recall) {
1512
1512
  body: "[Message recalled]",
1513
1513
  quote: void 0,
1514
1514
  link: void 0,
1515
+ location: void 0,
1515
1516
  media: [],
1516
1517
  senderId: message.senderId || null,
1517
1518
  direction: message.senderId ? message.direction : null,
@@ -1783,7 +1784,8 @@ async function prepareNativeAttachmentInput(params) {
1783
1784
  guard2();
1784
1785
  };
1785
1786
  if (message.type === 49 && message.appMessageType === 57) return prepareNativeQuote(params);
1786
- if (message.type === 49 && [1, 74, 87].includes(message.appMessageType ?? 0)) return { body: message.body?.slice(0, 32768) || "[Shared text unavailable]", pending: false };
1787
+ if (message.type === 48) return { body: message.location && message.body ? message.body.slice(0, 32768) : "[Location unavailable]", pending: false };
1788
+ if (message.type === 49 && [1, 17, 74, 87].includes(message.appMessageType ?? 0)) return { body: message.body?.slice(0, 32768) || "[Shared text unavailable]", pending: false };
1787
1789
  if (message.type === 49 && message.appMessageType === 19) return { body: message.body?.slice(0, 65536) || "[Forwarded chat history unavailable]", pending: false };
1788
1790
  if (message.type === 49 && [3, 4, 5, 51].includes(message.appMessageType ?? 0) && message.link) return prepareNativeLink(params);
1789
1791
  if (message.type === 49 && message.appMessageType != null && message.appMessageType !== 6) return { body: `[Unsupported WeChat app message subtype ${message.appMessageType}]`, pending: false, retryable: false };
@@ -2157,14 +2159,15 @@ function nativeDispatchManifest(params) {
2157
2159
  params.message.serverId,
2158
2160
  params.message.appMessageType,
2159
2161
  params.message.quote,
2160
- params.message.link
2162
+ params.message.link,
2163
+ ...params.message.location ? [params.message.location] : []
2161
2164
  ])),
2162
2165
  role: "trigger"
2163
2166
  })]),
2164
2167
  ...history.length ? { historyInputs: Object.freeze(history.map((message) => Object.freeze({
2165
2168
  id: message.id,
2166
2169
  version: message.version ?? "",
2167
- contentSha256: digest(JSON.stringify([message.id, message.version, message.senderId, message.type, message.body, message.mentions, message.serverId, message.appMessageType, message.quote, message.link])),
2170
+ contentSha256: digest(JSON.stringify([message.id, message.version, message.senderId, message.type, message.body, message.mentions, message.serverId, message.appMessageType, message.quote, message.link, ...message.location ? [message.location] : []])),
2168
2171
  role: "history"
2169
2172
  }))) } : {},
2170
2173
  assets,
@@ -2175,10 +2178,10 @@ function nativeDispatchManifest(params) {
2175
2178
  };
2176
2179
  return Object.freeze({ ...manifest, manifestSha256: digest(JSON.stringify(manifest)) });
2177
2180
  }
2178
- function trackNativePreparedInput(manifest, record) {
2181
+ function trackNativePreparedInput(manifest, record2) {
2179
2182
  prune();
2180
2183
  if (!enabled || pending.size >= 1024) return;
2181
- pending.set(manifest.runId, { manifest, record, expires: Date.now() + 15 * 60 * 1e3 });
2184
+ pending.set(manifest.runId, { manifest, record: record2, expires: Date.now() + 15 * 60 * 1e3 });
2182
2185
  }
2183
2186
  function invalidateNativePreparedInputs(accountId, messageIds) {
2184
2187
  const ids = new Set(messageIds);
@@ -2917,6 +2920,9 @@ async function recheckNativeInputs(client, state, messages) {
2917
2920
  }
2918
2921
  if (!quote || !sameEmbeddedQuote(message.quote, quote)) throw Error("Native embedded quote changed; delivery held for review");
2919
2922
  }
2923
+ if (message.type === 48 && (current.type !== 48 || current.body !== message.body || JSON.stringify(current.location) !== JSON.stringify(message.location))) {
2924
+ throw Error("Native location changed; delivery held for review");
2925
+ }
2920
2926
  if (!state.isCurrent(message)) throw new NativeInputInvalidated();
2921
2927
  }
2922
2928
  }
@@ -2942,7 +2948,7 @@ async function dispatchNativeMessageInput(params, revision) {
2942
2948
  state.update(message.id, { state: "ignored" }, revision);
2943
2949
  return "ignored";
2944
2950
  }
2945
- if (custody.origin !== "live" || message.direction !== "incoming" || ![1, 3, 34, 43, 47, 49].includes(message.type) || message.type === 1 && !message.body || !message.senderId) {
2951
+ if (custody.origin !== "live" || message.direction !== "incoming" || ![1, 3, 34, 43, 47, 48, 49].includes(message.type) || message.type === 1 && !message.body || message.type === 48 && (!message.location || !message.body) || !message.senderId) {
2946
2952
  state.update(message.id, { state: "ignored" }, revision);
2947
2953
  return "ignored";
2948
2954
  }
@@ -3076,7 +3082,7 @@ async function dispatchNativeMessageInput(params, revision) {
3076
3082
  });
3077
3083
  assertCurrent();
3078
3084
  state.beginDispatch(message.id, dispatchManifest, buffered.map((item) => item.message.id));
3079
- const callback = readPolicy !== "on_inbound" && (message.type === 1 || message.type === 49 && [1, 19, 87].includes(message.appMessageType ?? 0) && !!message.body || message.type === 49 && [3, 4, 5, 51].includes(message.appMessageType ?? 0) && !!message.link || preparedMedia.quote && [1, 49].includes(preparedMedia.quote.type ?? 0) && ["resolved", "embedded"].includes(preparedMedia.quote.state) || preparedMedia.attachment?.status === "ready" && preparedMedia.suppliedAssets?.length) ? state.preparedCallback([message.id], readPolicy) : void 0;
3085
+ const callback = readPolicy !== "on_inbound" && (message.type === 1 || message.type === 48 && !!message.location && !!message.body || message.type === 49 && [1, 17, 19, 87].includes(message.appMessageType ?? 0) && !!message.body || message.type === 49 && [3, 4, 5, 51].includes(message.appMessageType ?? 0) && !!message.link || preparedMedia.quote && [1, 49].includes(preparedMedia.quote.type ?? 0) && ["resolved", "embedded"].includes(preparedMedia.quote.state) || preparedMedia.attachment?.status === "ready" && preparedMedia.suppliedAssets?.length) ? state.preparedCallback([message.id], readPolicy) : void 0;
3080
3086
  if (callback) trackNativePreparedInput(dispatchManifest, callback);
3081
3087
  const beforeSend = () => recheck([message, ...admitted]);
3082
3088
  let failed = false;
@@ -3458,6 +3464,58 @@ function createWeChatDurableFinal(host2 = ensureNativeHost) {
3458
3464
  };
3459
3465
  }
3460
3466
 
3467
+ // src/native-target.ts
3468
+ function normalizeWeChatTarget(raw) {
3469
+ return raw.trim().replace(/^(agent-)?wechat:/i, "").trim() || void 0;
3470
+ }
3471
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
3472
+ var display = (value, id2) => typeof value === "string" && value ? value : id2;
3473
+ async function configuredClient(cfg, accountId) {
3474
+ const account = resolveWeChatAccount(cfg, accountId ?? void 0);
3475
+ if (!account?.native) throw new Error("No native WeChat daemon configured");
3476
+ const { client } = await ensureNativeHost(account.native);
3477
+ return { client, accountId: account.native.accountId };
3478
+ }
3479
+ function createWeChatMessagingAdapter(resolveClient = configuredClient) {
3480
+ return {
3481
+ normalizeTarget: normalizeWeChatTarget,
3482
+ inferTargetChatType: ({ to }) => normalizeWeChatTarget(to)?.endsWith("@chatroom") ? "group" : "direct",
3483
+ targetResolver: {
3484
+ // Treat targets as native IDs and validate them here, including malformed
3485
+ // provider prefixes, before the host can substitute a display-name match.
3486
+ looksLikeId: () => true,
3487
+ hint: "WeChat contact ID or group ID (not a nickname or alias)",
3488
+ resolveTarget: async ({ cfg, accountId, input, preferredKind }) => {
3489
+ const id2 = normalizeWeChatTarget(input);
3490
+ if (!id2 || id2 === "." || id2 === ".." || id2.length > 4096 || /[\u0000-\u001f\u007f]/.test(id2)) {
3491
+ throw new Error("Invalid WeChat target ID");
3492
+ }
3493
+ const kind2 = id2.endsWith("@chatroom") ? "group" : "user";
3494
+ if (preferredKind === "user" && kind2 !== "user" || preferredKind && preferredKind !== "user" && kind2 !== "group") {
3495
+ throw new Error("WeChat target kind does not match the requested destination");
3496
+ }
3497
+ if (kind2 === "group" || id2.startsWith("wxid_")) return { to: id2, kind: kind2, source: "normalized" };
3498
+ const native = await resolveClient(cfg, accountId);
3499
+ let contact;
3500
+ try {
3501
+ contact = await native.client.contact(native.accountId, id2);
3502
+ } catch (error) {
3503
+ if (!(error instanceof NativeApiError) || error.status !== 404) throw error;
3504
+ const thread3 = await native.client.thread(native.accountId, id2);
3505
+ if (!record(thread3) || thread3.deleted === true || thread3.id !== id2 || thread3.peerId !== id2 || thread3.accountId !== native.accountId || thread3.kind !== "direct") {
3506
+ throw new Error("Native WeChat conversation identity mismatch");
3507
+ }
3508
+ return { to: id2, kind: "user", display: display(thread3.displayName, id2), source: "directory" };
3509
+ }
3510
+ if (!record(contact) || contact.deleted === true || contact.id !== id2 || contact.username !== id2 || contact.accountId !== void 0 && contact.accountId !== native.accountId) {
3511
+ throw new Error("Native WeChat contact identity mismatch");
3512
+ }
3513
+ return { to: id2, kind: "user", display: display(contact.displayName, id2), source: "directory" };
3514
+ }
3515
+ }
3516
+ };
3517
+ }
3518
+
3461
3519
  // src/channel.ts
3462
3520
  var mediaHandlers = createWeChatMediaHandlers();
3463
3521
  var wechatMessageAdapter = createChannelMessageAdapterFromOutbound({
@@ -3597,16 +3655,7 @@ var wechatPlugin = {
3597
3655
  })
3598
3656
  },
3599
3657
  // ---- Messaging adapter ----
3600
- messaging: {
3601
- normalizeTarget: (raw) => raw.replace(/^(agent-)?wechat:/i, "").trim() || void 0,
3602
- targetResolver: {
3603
- looksLikeId: (raw) => {
3604
- const stripped = raw.replace(/^(agent-)?wechat:/i, "").trim();
3605
- return stripped.includes("@chatroom") || stripped.startsWith("wxid_");
3606
- },
3607
- hint: "WeChat ID (wxid_xxx or xxx@chatroom)"
3608
- }
3609
- },
3658
+ messaging: createWeChatMessagingAdapter(),
3610
3659
  // ---- Outbound adapter for OpenClaw hosts using the outbound hook ----
3611
3660
  outbound: {
3612
3661
  deliveryMode: "direct",
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@agent-wechat/agent-wechat",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-beta.0",
4
+ "license": "MIT",
4
5
  "type": "module",
5
6
  "files": [
6
7
  "dist",
7
- "openclaw.plugin.json"
8
+ "openclaw.plugin.json",
9
+ "LICENSE"
8
10
  ],
9
11
  "devDependencies": {
10
12
  "@types/node": "^22",