@agent-wechat/wechat 0.11.8 → 0.11.10
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.
- package/dist/index.js +52 -237
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1082,7 +1082,7 @@ var require_main = __commonJS({
|
|
|
1082
1082
|
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
1083
1083
|
|
|
1084
1084
|
// src/channel.ts
|
|
1085
|
-
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID2 } from "openclaw/plugin-sdk";
|
|
1085
|
+
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID2 } from "openclaw/plugin-sdk/account-id";
|
|
1086
1086
|
|
|
1087
1087
|
// src/types.ts
|
|
1088
1088
|
function normalizeDmPolicy(policy) {
|
|
@@ -1153,16 +1153,16 @@ var WeChatClient = class {
|
|
|
1153
1153
|
return this.base;
|
|
1154
1154
|
}
|
|
1155
1155
|
// ---- internal helpers ----
|
|
1156
|
-
async get(
|
|
1157
|
-
const res = await fetch(`${this.base}${
|
|
1156
|
+
async get(path) {
|
|
1157
|
+
const res = await fetch(`${this.base}${path}`, {
|
|
1158
1158
|
headers: this.headers
|
|
1159
1159
|
});
|
|
1160
1160
|
if (!res.ok)
|
|
1161
1161
|
throw new Error(`${res.status} ${res.statusText}: ${await res.text()}`);
|
|
1162
1162
|
return res.json();
|
|
1163
1163
|
}
|
|
1164
|
-
async post(
|
|
1165
|
-
const res = await fetch(`${this.base}${
|
|
1164
|
+
async post(path, body) {
|
|
1165
|
+
const res = await fetch(`${this.base}${path}`, {
|
|
1166
1166
|
method: "POST",
|
|
1167
1167
|
headers: this.headers,
|
|
1168
1168
|
body: body != null ? JSON.stringify(body) : void 0
|
|
@@ -1171,8 +1171,8 @@ var WeChatClient = class {
|
|
|
1171
1171
|
throw new Error(`${res.status} ${res.statusText}: ${await res.text()}`);
|
|
1172
1172
|
return res.json();
|
|
1173
1173
|
}
|
|
1174
|
-
async del(
|
|
1175
|
-
const res = await fetch(`${this.base}${
|
|
1174
|
+
async del(path) {
|
|
1175
|
+
const res = await fetch(`${this.base}${path}`, {
|
|
1176
1176
|
method: "DELETE",
|
|
1177
1177
|
headers: this.headers
|
|
1178
1178
|
});
|
|
@@ -1774,8 +1774,8 @@ function getErrorMap() {
|
|
|
1774
1774
|
|
|
1775
1775
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
1776
1776
|
var makeIssue = (params) => {
|
|
1777
|
-
const { data, path
|
|
1778
|
-
const fullPath = [...
|
|
1777
|
+
const { data, path, errorMaps, issueData } = params;
|
|
1778
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
1779
1779
|
const fullIssue = {
|
|
1780
1780
|
...issueData,
|
|
1781
1781
|
path: fullPath
|
|
@@ -1891,11 +1891,11 @@ var errorUtil;
|
|
|
1891
1891
|
|
|
1892
1892
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
1893
1893
|
var ParseInputLazyPath = class {
|
|
1894
|
-
constructor(parent, value,
|
|
1894
|
+
constructor(parent, value, path, key) {
|
|
1895
1895
|
this._cachedPath = [];
|
|
1896
1896
|
this.parent = parent;
|
|
1897
1897
|
this.data = value;
|
|
1898
|
-
this._path =
|
|
1898
|
+
this._path = path;
|
|
1899
1899
|
this._key = key;
|
|
1900
1900
|
}
|
|
1901
1901
|
get path() {
|
|
@@ -5510,16 +5510,18 @@ var agentConfigSchema = external_exports.object({
|
|
|
5510
5510
|
});
|
|
5511
5511
|
|
|
5512
5512
|
// src/monitor.ts
|
|
5513
|
-
import {
|
|
5513
|
+
import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline";
|
|
5514
5514
|
|
|
5515
5515
|
// src/access-control.ts
|
|
5516
5516
|
import {
|
|
5517
5517
|
buildChannelKeyCandidates,
|
|
5518
|
+
resolveChannelEntryMatchWithFallback
|
|
5519
|
+
} from "openclaw/plugin-sdk/channel-targets";
|
|
5520
|
+
import {
|
|
5518
5521
|
resolveAllowlistProviderRuntimeGroupPolicy,
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
} from "openclaw/plugin-sdk";
|
|
5522
|
+
resolveDefaultGroupPolicy
|
|
5523
|
+
} from "openclaw/plugin-sdk/config-runtime";
|
|
5524
|
+
import { resolveSenderCommandAuthorization } from "openclaw/plugin-sdk/command-auth";
|
|
5523
5525
|
var INVISIBLE_TEXT_RE = /[\u200b-\u200f\u202a-\u202e\u2060-\u206f]/g;
|
|
5524
5526
|
var WECHAT_MENTION_START_RE = /^[@@]/u;
|
|
5525
5527
|
function unique(values) {
|
|
@@ -6166,7 +6168,7 @@ async function dispatchSegment(segment, client, chatId, chat, liveAccount, polic
|
|
|
6166
6168
|
);
|
|
6167
6169
|
}
|
|
6168
6170
|
});
|
|
6169
|
-
const { onModelSelected, ...prefixOptions } =
|
|
6171
|
+
const { onModelSelected, ...prefixOptions } = createChannelReplyPipeline({
|
|
6170
6172
|
cfg,
|
|
6171
6173
|
agentId: route.agentId,
|
|
6172
6174
|
channel: "wechat",
|
|
@@ -6431,11 +6433,38 @@ async function processUnreadChat(client, chat, lastSeenId, account, cfg, log, sk
|
|
|
6431
6433
|
lastSeenId.set(chatId, maxId);
|
|
6432
6434
|
}
|
|
6433
6435
|
|
|
6434
|
-
// src/
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6436
|
+
// src/status.ts
|
|
6437
|
+
function collectWeChatStatusIssues(accounts) {
|
|
6438
|
+
const issues = [];
|
|
6439
|
+
for (const snapshot of accounts) {
|
|
6440
|
+
if (snapshot.connected === false) {
|
|
6441
|
+
issues.push({
|
|
6442
|
+
channel: "wechat",
|
|
6443
|
+
accountId: snapshot.accountId,
|
|
6444
|
+
kind: "runtime",
|
|
6445
|
+
message: snapshot.lastError ? `Cannot reach agent-wechat server: ${snapshot.lastError}` : "Cannot reach agent-wechat server.",
|
|
6446
|
+
fix: "Ensure the agent-wechat container is running (pnpm cli up)"
|
|
6447
|
+
});
|
|
6448
|
+
} else if (snapshot.authStatus === "app_not_running") {
|
|
6449
|
+
issues.push({
|
|
6450
|
+
channel: "wechat",
|
|
6451
|
+
accountId: snapshot.accountId,
|
|
6452
|
+
kind: "runtime",
|
|
6453
|
+
message: "WeChat application is not running. It should restart automatically.",
|
|
6454
|
+
fix: "If it doesn't restart, try: wx down && wx up"
|
|
6455
|
+
});
|
|
6456
|
+
} else if (snapshot.linked === false) {
|
|
6457
|
+
issues.push({
|
|
6458
|
+
channel: "wechat",
|
|
6459
|
+
accountId: snapshot.accountId,
|
|
6460
|
+
kind: "auth",
|
|
6461
|
+
message: "WeChat session not authenticated.",
|
|
6462
|
+
fix: "Run: openclaw channels login --channel wechat"
|
|
6463
|
+
});
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
6466
|
+
return issues;
|
|
6467
|
+
}
|
|
6439
6468
|
|
|
6440
6469
|
// src/login.ts
|
|
6441
6470
|
var ACTIVE_LOGIN_TTL_MS = 5 * 6e4;
|
|
@@ -6632,218 +6661,6 @@ function handleEvent(login, event) {
|
|
|
6632
6661
|
}
|
|
6633
6662
|
}
|
|
6634
6663
|
|
|
6635
|
-
// src/onboarding.ts
|
|
6636
|
-
var TOKEN_DIR = path.join(os.homedir(), ".config", "agent-wechat");
|
|
6637
|
-
var TOKEN_PATH = path.join(TOKEN_DIR, "token");
|
|
6638
|
-
function readOrGenerateToken() {
|
|
6639
|
-
try {
|
|
6640
|
-
const t = fs.readFileSync(TOKEN_PATH, "utf-8").trim();
|
|
6641
|
-
if (t) return t;
|
|
6642
|
-
} catch {
|
|
6643
|
-
}
|
|
6644
|
-
fs.mkdirSync(TOKEN_DIR, { recursive: true });
|
|
6645
|
-
const token = randomBytes(32).toString("hex");
|
|
6646
|
-
fs.writeFileSync(TOKEN_PATH, token + "\n", { mode: 384 });
|
|
6647
|
-
return token;
|
|
6648
|
-
}
|
|
6649
|
-
var wechatOnboardingAdapter = {
|
|
6650
|
-
channel: "wechat",
|
|
6651
|
-
getStatus: async ({ cfg }) => {
|
|
6652
|
-
const account = resolveWeChatAccount(cfg);
|
|
6653
|
-
if (!account?.serverUrl) {
|
|
6654
|
-
return {
|
|
6655
|
-
channel: "wechat",
|
|
6656
|
-
configured: false,
|
|
6657
|
-
statusLines: ["Not configured. Run: openclaw channels setup wechat"]
|
|
6658
|
-
};
|
|
6659
|
-
}
|
|
6660
|
-
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
6661
|
-
const statusLines = [];
|
|
6662
|
-
try {
|
|
6663
|
-
await client.status();
|
|
6664
|
-
statusLines.push(`Connected to ${account.serverUrl}`);
|
|
6665
|
-
} catch {
|
|
6666
|
-
return {
|
|
6667
|
-
channel: "wechat",
|
|
6668
|
-
configured: true,
|
|
6669
|
-
statusLines: [
|
|
6670
|
-
`Server URL: ${account.serverUrl}`,
|
|
6671
|
-
"Cannot reach server \u2014 is the agent-wechat container running?"
|
|
6672
|
-
]
|
|
6673
|
-
};
|
|
6674
|
-
}
|
|
6675
|
-
try {
|
|
6676
|
-
const auth = await client.authStatus();
|
|
6677
|
-
if (auth.status === "logged_in") {
|
|
6678
|
-
statusLines.push(
|
|
6679
|
-
`Logged in${auth.loggedInUser ? ` as ${auth.loggedInUser}` : ""}`
|
|
6680
|
-
);
|
|
6681
|
-
} else {
|
|
6682
|
-
statusLines.push("Not logged in. Run: openclaw channels login --channel wechat");
|
|
6683
|
-
}
|
|
6684
|
-
} catch {
|
|
6685
|
-
statusLines.push("Could not check auth status");
|
|
6686
|
-
}
|
|
6687
|
-
statusLines.push(`DM policy: ${account.dmPolicy}`);
|
|
6688
|
-
if (account.allowFrom.length > 0) {
|
|
6689
|
-
statusLines.push(`Allowed senders: ${account.allowFrom.join(", ")}`);
|
|
6690
|
-
}
|
|
6691
|
-
statusLines.push(`Group policy: ${account.groupPolicy}`);
|
|
6692
|
-
return { channel: "wechat", configured: true, statusLines };
|
|
6693
|
-
},
|
|
6694
|
-
configure: async ({ prompter, cfg }) => {
|
|
6695
|
-
const wechatCfg = {
|
|
6696
|
-
...cfg?.channels?.wechat ?? {}
|
|
6697
|
-
};
|
|
6698
|
-
const existingUrl = wechatCfg.serverUrl ?? "http://localhost:6174";
|
|
6699
|
-
const serverUrl = await prompter.text({
|
|
6700
|
-
message: "Agent-wechat server URL",
|
|
6701
|
-
initialValue: existingUrl
|
|
6702
|
-
});
|
|
6703
|
-
wechatCfg.serverUrl = serverUrl;
|
|
6704
|
-
const existingToken = wechatCfg.token ?? "";
|
|
6705
|
-
const localDefault = existingToken || readOrGenerateToken();
|
|
6706
|
-
const token = await prompter.text({
|
|
6707
|
-
message: "Auth token (leave empty to use local token)",
|
|
6708
|
-
initialValue: localDefault
|
|
6709
|
-
});
|
|
6710
|
-
wechatCfg.token = token || localDefault;
|
|
6711
|
-
const client = new WeChatClient({ baseUrl: serverUrl, token: token || void 0 });
|
|
6712
|
-
try {
|
|
6713
|
-
await client.status();
|
|
6714
|
-
} catch {
|
|
6715
|
-
wechatCfg.enabled = false;
|
|
6716
|
-
throw new Error(
|
|
6717
|
-
`Cannot reach ${serverUrl}. Ensure the agent-wechat container is running.`
|
|
6718
|
-
);
|
|
6719
|
-
}
|
|
6720
|
-
try {
|
|
6721
|
-
const auth = await client.authStatus();
|
|
6722
|
-
if (auth.status !== "logged_in") {
|
|
6723
|
-
const wantsLink = await prompter.confirm({
|
|
6724
|
-
message: "WeChat not logged in. Link now?",
|
|
6725
|
-
initialValue: true
|
|
6726
|
-
});
|
|
6727
|
-
if (wantsLink) {
|
|
6728
|
-
await prompter.note(
|
|
6729
|
-
"Starting login \u2014 watch for QR code or phone confirmation.",
|
|
6730
|
-
"WeChat Login"
|
|
6731
|
-
);
|
|
6732
|
-
try {
|
|
6733
|
-
await loginTerminal(client, {
|
|
6734
|
-
onEvent: (event) => {
|
|
6735
|
-
switch (event.type) {
|
|
6736
|
-
case "status":
|
|
6737
|
-
prompter.note?.(event.message, "Status");
|
|
6738
|
-
break;
|
|
6739
|
-
case "qr":
|
|
6740
|
-
prompter.note?.("Scan QR code with WeChat", "Login");
|
|
6741
|
-
break;
|
|
6742
|
-
case "phone_confirm":
|
|
6743
|
-
prompter.note?.(
|
|
6744
|
-
event.message || "Please confirm login on your phone",
|
|
6745
|
-
"Confirm"
|
|
6746
|
-
);
|
|
6747
|
-
break;
|
|
6748
|
-
case "login_success":
|
|
6749
|
-
prompter.note?.("Login successful!", "Done");
|
|
6750
|
-
break;
|
|
6751
|
-
case "login_timeout":
|
|
6752
|
-
prompter.note?.("Login timed out. Please try again.", "Timeout");
|
|
6753
|
-
break;
|
|
6754
|
-
case "error":
|
|
6755
|
-
prompter.note?.(`Error: ${event.message}`, "Error");
|
|
6756
|
-
break;
|
|
6757
|
-
}
|
|
6758
|
-
}
|
|
6759
|
-
});
|
|
6760
|
-
} catch (err) {
|
|
6761
|
-
prompter.note?.(
|
|
6762
|
-
`Login failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
6763
|
-
"Error"
|
|
6764
|
-
);
|
|
6765
|
-
}
|
|
6766
|
-
} else {
|
|
6767
|
-
await prompter.note(
|
|
6768
|
-
"Run `openclaw channels login --channel wechat` later to link.",
|
|
6769
|
-
"WeChat"
|
|
6770
|
-
);
|
|
6771
|
-
}
|
|
6772
|
-
}
|
|
6773
|
-
} catch {
|
|
6774
|
-
}
|
|
6775
|
-
const dmPolicy = await prompter.select({
|
|
6776
|
-
message: "DM (direct message) policy",
|
|
6777
|
-
options: [
|
|
6778
|
-
{ label: "Disabled \u2014 ignore all DMs", value: "disabled" },
|
|
6779
|
-
{ label: "Allowlist \u2014 only respond to specific senders", value: "allowlist" },
|
|
6780
|
-
{ label: "Open \u2014 respond to all DMs", value: "open" }
|
|
6781
|
-
]
|
|
6782
|
-
});
|
|
6783
|
-
wechatCfg.dmPolicy = dmPolicy;
|
|
6784
|
-
if (dmPolicy === "allowlist") {
|
|
6785
|
-
const raw = await prompter.text({
|
|
6786
|
-
message: "Allowed WeChat IDs (comma-separated wxid_xxx values)"
|
|
6787
|
-
});
|
|
6788
|
-
wechatCfg.allowFrom = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
6789
|
-
}
|
|
6790
|
-
const groupPolicy = await prompter.select({
|
|
6791
|
-
message: "Group chat policy",
|
|
6792
|
-
options: [
|
|
6793
|
-
{ label: "Disabled \u2014 ignore all group messages", value: "disabled" },
|
|
6794
|
-
{ label: "Allowlist \u2014 only respond in specific groups", value: "allowlist" },
|
|
6795
|
-
{ label: "Open \u2014 respond in all groups (when mentioned)", value: "open" }
|
|
6796
|
-
]
|
|
6797
|
-
});
|
|
6798
|
-
wechatCfg.groupPolicy = groupPolicy;
|
|
6799
|
-
if (groupPolicy === "allowlist") {
|
|
6800
|
-
const raw = await prompter.text({
|
|
6801
|
-
message: "Allowed group sender IDs (comma-separated wxid_xxx values; use * to allow any sender)"
|
|
6802
|
-
});
|
|
6803
|
-
wechatCfg.groupAllowFrom = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
6804
|
-
}
|
|
6805
|
-
wechatCfg.enabled = true;
|
|
6806
|
-
const newCfg = {
|
|
6807
|
-
...cfg,
|
|
6808
|
-
channels: { ...cfg.channels, wechat: wechatCfg }
|
|
6809
|
-
};
|
|
6810
|
-
return { cfg: newCfg };
|
|
6811
|
-
}
|
|
6812
|
-
};
|
|
6813
|
-
|
|
6814
|
-
// src/status.ts
|
|
6815
|
-
function collectWeChatStatusIssues(accounts) {
|
|
6816
|
-
const issues = [];
|
|
6817
|
-
for (const snapshot of accounts) {
|
|
6818
|
-
if (snapshot.connected === false) {
|
|
6819
|
-
issues.push({
|
|
6820
|
-
channel: "wechat",
|
|
6821
|
-
accountId: snapshot.accountId,
|
|
6822
|
-
kind: "runtime",
|
|
6823
|
-
message: snapshot.lastError ? `Cannot reach agent-wechat server: ${snapshot.lastError}` : "Cannot reach agent-wechat server.",
|
|
6824
|
-
fix: "Ensure the agent-wechat container is running (pnpm cli up)"
|
|
6825
|
-
});
|
|
6826
|
-
} else if (snapshot.authStatus === "app_not_running") {
|
|
6827
|
-
issues.push({
|
|
6828
|
-
channel: "wechat",
|
|
6829
|
-
accountId: snapshot.accountId,
|
|
6830
|
-
kind: "runtime",
|
|
6831
|
-
message: "WeChat application is not running. It should restart automatically.",
|
|
6832
|
-
fix: "If it doesn't restart, try: wx down && wx up"
|
|
6833
|
-
});
|
|
6834
|
-
} else if (snapshot.linked === false) {
|
|
6835
|
-
issues.push({
|
|
6836
|
-
channel: "wechat",
|
|
6837
|
-
accountId: snapshot.accountId,
|
|
6838
|
-
kind: "auth",
|
|
6839
|
-
message: "WeChat session not authenticated.",
|
|
6840
|
-
fix: "Run: openclaw channels login --channel wechat"
|
|
6841
|
-
});
|
|
6842
|
-
}
|
|
6843
|
-
}
|
|
6844
|
-
return issues;
|
|
6845
|
-
}
|
|
6846
|
-
|
|
6847
6664
|
// src/agent-tools.ts
|
|
6848
6665
|
function createWeChatLoginTool(account) {
|
|
6849
6666
|
const client = new WeChatClient({
|
|
@@ -7442,9 +7259,7 @@ Error: ${event.message}`);
|
|
|
7442
7259
|
}
|
|
7443
7260
|
};
|
|
7444
7261
|
}
|
|
7445
|
-
}
|
|
7446
|
-
// ---- Onboarding adapter ----
|
|
7447
|
-
onboarding: wechatOnboardingAdapter
|
|
7262
|
+
}
|
|
7448
7263
|
};
|
|
7449
7264
|
|
|
7450
7265
|
// index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-wechat/wechat",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/node": "^22",
|
|
11
11
|
"esbuild": "^0.25.0",
|
|
12
|
-
"openclaw": ">=2026.3.
|
|
12
|
+
"openclaw": ">=2026.3.23 <2027.0.0",
|
|
13
13
|
"typescript": "^5.4.5",
|
|
14
14
|
"@agent-wechat/shared": "0.1.0"
|
|
15
15
|
},
|