wechat-clawbot 0.9.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.
- package/LICENSE +21 -0
- package/NOTICE +32 -0
- package/README.md +324 -0
- package/README.zh.md +192 -0
- package/cordis.patch.yml +23 -0
- package/lib/approvals.d.ts +29 -0
- package/lib/approvals.d.ts.map +1 -0
- package/lib/approvals.js +86 -0
- package/lib/approvals.js.map +1 -0
- package/lib/bridge.d.ts +281 -0
- package/lib/bridge.d.ts.map +1 -0
- package/lib/bridge.js +827 -0
- package/lib/bridge.js.map +1 -0
- package/lib/claude-peer.d.ts +44 -0
- package/lib/claude-peer.d.ts.map +1 -0
- package/lib/claude-peer.js +515 -0
- package/lib/claude-peer.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +128 -0
- package/lib/cli.js.map +1 -0
- package/lib/client.js +597 -0
- package/lib/config.d.ts +160 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +187 -0
- package/lib/config.js.map +1 -0
- package/lib/emoji.d.ts +26 -0
- package/lib/emoji.d.ts.map +1 -0
- package/lib/emoji.js +54 -0
- package/lib/emoji.js.map +1 -0
- package/lib/ilink/api/api.d.ts +134 -0
- package/lib/ilink/api/api.d.ts.map +1 -0
- package/lib/ilink/api/api.js +507 -0
- package/lib/ilink/api/api.js.map +1 -0
- package/lib/ilink/api/session-guard.d.ts +16 -0
- package/lib/ilink/api/session-guard.d.ts.map +1 -0
- package/lib/ilink/api/session-guard.js +49 -0
- package/lib/ilink/api/session-guard.js.map +1 -0
- package/lib/ilink/api/types.d.ts +251 -0
- package/lib/ilink/api/types.d.ts.map +1 -0
- package/lib/ilink/api/types.js +37 -0
- package/lib/ilink/api/types.js.map +1 -0
- package/lib/ilink/auth/accounts.d.ts +67 -0
- package/lib/ilink/auth/accounts.d.ts.map +1 -0
- package/lib/ilink/auth/accounts.js +190 -0
- package/lib/ilink/auth/accounts.js.map +1 -0
- package/lib/ilink/auth/login-qr.d.ts +43 -0
- package/lib/ilink/auth/login-qr.d.ts.map +1 -0
- package/lib/ilink/auth/login-qr.js +333 -0
- package/lib/ilink/auth/login-qr.js.map +1 -0
- package/lib/ilink/cdn/aes-ecb.d.ts +7 -0
- package/lib/ilink/cdn/aes-ecb.d.ts.map +1 -0
- package/lib/ilink/cdn/aes-ecb.js +19 -0
- package/lib/ilink/cdn/aes-ecb.js.map +1 -0
- package/lib/ilink/cdn/cdn-upload.d.ts +18 -0
- package/lib/ilink/cdn/cdn-upload.d.ts.map +1 -0
- package/lib/ilink/cdn/cdn-upload.js +90 -0
- package/lib/ilink/cdn/cdn-upload.js.map +1 -0
- package/lib/ilink/cdn/cdn-url.d.ts +14 -0
- package/lib/ilink/cdn/cdn-url.d.ts.map +1 -0
- package/lib/ilink/cdn/cdn-url.js +14 -0
- package/lib/ilink/cdn/cdn-url.js.map +1 -0
- package/lib/ilink/cdn/pic-decrypt.d.ts +10 -0
- package/lib/ilink/cdn/pic-decrypt.d.ts.map +1 -0
- package/lib/ilink/cdn/pic-decrypt.js +89 -0
- package/lib/ilink/cdn/pic-decrypt.js.map +1 -0
- package/lib/ilink/cdn/upload.d.ts +43 -0
- package/lib/ilink/cdn/upload.d.ts.map +1 -0
- package/lib/ilink/cdn/upload.js +115 -0
- package/lib/ilink/cdn/upload.js.map +1 -0
- package/lib/ilink/media/mime.d.ts +7 -0
- package/lib/ilink/media/mime.d.ts.map +1 -0
- package/lib/ilink/media/mime.js +73 -0
- package/lib/ilink/media/mime.js.map +1 -0
- package/lib/ilink/messaging/send-media.d.ts +23 -0
- package/lib/ilink/messaging/send-media.d.ts.map +1 -0
- package/lib/ilink/messaging/send-media.js +71 -0
- package/lib/ilink/messaging/send-media.js.map +1 -0
- package/lib/ilink/messaging/send.d.ts +55 -0
- package/lib/ilink/messaging/send.d.ts.map +1 -0
- package/lib/ilink/messaging/send.js +182 -0
- package/lib/ilink/messaging/send.js.map +1 -0
- package/lib/ilink/storage/state-dir.d.ts +14 -0
- package/lib/ilink/storage/state-dir.d.ts.map +1 -0
- package/lib/ilink/storage/state-dir.js +22 -0
- package/lib/ilink/storage/state-dir.js.map +1 -0
- package/lib/ilink/storage/sync-buf.d.ts +21 -0
- package/lib/ilink/storage/sync-buf.d.ts.map +1 -0
- package/lib/ilink/storage/sync-buf.js +64 -0
- package/lib/ilink/storage/sync-buf.js.map +1 -0
- package/lib/ilink/util/logger.d.ts +20 -0
- package/lib/ilink/util/logger.d.ts.map +1 -0
- package/lib/ilink/util/logger.js +73 -0
- package/lib/ilink/util/logger.js.map +1 -0
- package/lib/ilink/util/random.d.ts +11 -0
- package/lib/ilink/util/random.d.ts.map +1 -0
- package/lib/ilink/util/random.js +16 -0
- package/lib/ilink/util/random.js.map +1 -0
- package/lib/ilink/util/redact.d.ts +21 -0
- package/lib/ilink/util/redact.d.ts.map +1 -0
- package/lib/ilink/util/redact.js +54 -0
- package/lib/ilink/util/redact.js.map +1 -0
- package/lib/image-compress.d.ts +38 -0
- package/lib/image-compress.d.ts.map +1 -0
- package/lib/image-compress.js +184 -0
- package/lib/image-compress.js.map +1 -0
- package/lib/inbound-media.d.ts +17 -0
- package/lib/inbound-media.d.ts.map +1 -0
- package/lib/inbound-media.js +96 -0
- package/lib/inbound-media.js.map +1 -0
- package/lib/inbound.d.ts +28 -0
- package/lib/inbound.d.ts.map +1 -0
- package/lib/inbound.js +265 -0
- package/lib/inbound.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +321 -0
- package/lib/index.js.map +1 -0
- package/lib/mcp-route.d.ts +33 -0
- package/lib/mcp-route.d.ts.map +1 -0
- package/lib/mcp-route.js +422 -0
- package/lib/mcp-route.js.map +1 -0
- package/lib/memory-auto.d.ts +22 -0
- package/lib/memory-auto.d.ts.map +1 -0
- package/lib/memory-auto.js +144 -0
- package/lib/memory-auto.js.map +1 -0
- package/lib/memory.d.ts +26 -0
- package/lib/memory.d.ts.map +1 -0
- package/lib/memory.js +168 -0
- package/lib/memory.js.map +1 -0
- package/lib/models-route.d.ts +24 -0
- package/lib/models-route.d.ts.map +1 -0
- package/lib/models-route.js +84 -0
- package/lib/models-route.js.map +1 -0
- package/lib/monitor.d.ts +13 -0
- package/lib/monitor.d.ts.map +1 -0
- package/lib/monitor.js +116 -0
- package/lib/monitor.js.map +1 -0
- package/lib/pending.d.ts +23 -0
- package/lib/pending.d.ts.map +1 -0
- package/lib/pending.js +38 -0
- package/lib/pending.js.map +1 -0
- package/lib/prompt.d.ts +36 -0
- package/lib/prompt.d.ts.map +1 -0
- package/lib/prompt.js +246 -0
- package/lib/prompt.js.map +1 -0
- package/lib/questions.d.ts +21 -0
- package/lib/questions.d.ts.map +1 -0
- package/lib/questions.js +116 -0
- package/lib/questions.js.map +1 -0
- package/lib/quote-history.d.ts +18 -0
- package/lib/quote-history.d.ts.map +1 -0
- package/lib/quote-history.js +96 -0
- package/lib/quote-history.js.map +1 -0
- package/lib/state.d.ts +27 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +154 -0
- package/lib/state.js.map +1 -0
- package/lib/subagent-model.d.ts +26 -0
- package/lib/subagent-model.d.ts.map +1 -0
- package/lib/subagent-model.js +30 -0
- package/lib/subagent-model.js.map +1 -0
- package/lib/tool.d.ts +14 -0
- package/lib/tool.d.ts.map +1 -0
- package/lib/tool.js +518 -0
- package/lib/tool.js.map +1 -0
- package/package.json +94 -0
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawBot plugin configuration.
|
|
3
|
+
*
|
|
4
|
+
* Values come from the `clawbot` row in the profile's composed cordis tree
|
|
5
|
+
* (see `cordis.patch.yml` and the profile's own patch layer). Every field has
|
|
6
|
+
* a safe default, so the row can be as small as `{ autoStart: true }`.
|
|
7
|
+
*/
|
|
8
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
9
|
+
import type { LogLevel } from "./ilink/util/logger.js";
|
|
10
|
+
export interface ClawbotConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Start the WeChat monitor automatically when a bound account exists.
|
|
13
|
+
* Set to `false` to only run after the user logs in manually via the
|
|
14
|
+
* `clawbot` CLI while the profile is running.
|
|
15
|
+
*/
|
|
16
|
+
autoStart: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Sender allowlist (WeChat user ids). When empty, only the user who scanned
|
|
19
|
+
* the QR code at login (`account.userId`) may send messages; every other
|
|
20
|
+
* sender is ignored.
|
|
21
|
+
*/
|
|
22
|
+
allowFrom: string[];
|
|
23
|
+
/**
|
|
24
|
+
* The single fixed DSH session id all WeChat messages are routed to.
|
|
25
|
+
* Persisted history is resumed under this id across restarts.
|
|
26
|
+
*/
|
|
27
|
+
sessionId: string;
|
|
28
|
+
/** Working directory for a freshly created session (defaults to `process.cwd()`). */
|
|
29
|
+
cwd?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Register a `userQuestions` provider that forwards `ask_user_question` /
|
|
32
|
+
* plan-review prompts to WeChat. Only one provider may exist per context —
|
|
33
|
+
* if the Web UI already registered one (browser attached), registration is
|
|
34
|
+
* skipped with a warning. Defaults to `false`.
|
|
35
|
+
*/
|
|
36
|
+
forwardQuestions: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* How long (ms) an approval question waits for a WeChat answer before
|
|
39
|
+
* failing closed. `0` (default) waits indefinitely.
|
|
40
|
+
*/
|
|
41
|
+
approvalTimeoutMs: number;
|
|
42
|
+
/** `bot_agent` string reported to the iLink server. */
|
|
43
|
+
botAgent: string;
|
|
44
|
+
/** Long-edge pixel cap for compressed outbound images. */
|
|
45
|
+
maxImageEdge: number;
|
|
46
|
+
/** Primary JPEG quality for compressed outbound images. */
|
|
47
|
+
imageQuality: number;
|
|
48
|
+
/** Only compress outbound images larger than this many bytes. */
|
|
49
|
+
compressThresholdBytes: number;
|
|
50
|
+
/** Deterministically strip Unicode emojis from all outbound WeChat text. */
|
|
51
|
+
stripEmoji: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the `/plugins/clawbot/mcp/*` bridge answers requests — the surface
|
|
54
|
+
* dsh-mcp-bridge (and therefore Claude Code) calls. Off makes every route
|
|
55
|
+
* return 403 while leaving them registered, so this is a live kill switch
|
|
56
|
+
* rather than something needing a restart.
|
|
57
|
+
*/
|
|
58
|
+
mcpBridge: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Only announce an outbound file before uploading it when it is at least
|
|
61
|
+
* this many bytes. Below it the upload finishes fast enough that the typing
|
|
62
|
+
* indicator is the only heads-up needed. `0` announces every file.
|
|
63
|
+
*/
|
|
64
|
+
noticeMinBytes: number;
|
|
65
|
+
/**
|
|
66
|
+
* Attach images directly to the model's message when the route accepts them.
|
|
67
|
+
* Turning this off forces the old behaviour — the model gets a path and has
|
|
68
|
+
* to read it with a vision tool — which is the only way to compare the two
|
|
69
|
+
* without editing code.
|
|
70
|
+
*/
|
|
71
|
+
attachImages: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Pin the WeChat session to one model, independent of the deployment default.
|
|
74
|
+
*
|
|
75
|
+
* Empty means "follow the deployment default" — which is what this plugin has
|
|
76
|
+
* always done, and why picking a model in the web UI silently moved the bot
|
|
77
|
+
* too: that picker writes through to the global `agent-default-model`, and
|
|
78
|
+
* this session installs whatever it finds there.
|
|
79
|
+
*/
|
|
80
|
+
provider?: string;
|
|
81
|
+
model?: string;
|
|
82
|
+
reasoningEffort?: string;
|
|
83
|
+
/** iLink API base URL (override only for testing/mirrors). */
|
|
84
|
+
apiBaseUrl: string;
|
|
85
|
+
/** Log level for the vendored protocol layer. */
|
|
86
|
+
logLevel: LogLevel;
|
|
87
|
+
}
|
|
88
|
+
export declare const DEFAULT_CONFIG: ClawbotConfig;
|
|
89
|
+
/** Merge a raw (possibly partial) row config over the defaults. */
|
|
90
|
+
export declare function normalizeConfig(raw?: Partial<ClawbotConfig> | Record<string, unknown>): ClawbotConfig;
|
|
91
|
+
/**
|
|
92
|
+
* The plugin's configuration schema, and with it its form in DSH's settings UI:
|
|
93
|
+
* a plugin without a schema has no fields for that page to draw.
|
|
94
|
+
*
|
|
95
|
+
* EVERY field must appear here. `Schema.object()` drops what it does not
|
|
96
|
+
* declare, so an omitted field would be silently deleted from the composed
|
|
97
|
+
* cordis row the first time the settings page writes this section back.
|
|
98
|
+
*
|
|
99
|
+
* Field order is form order, so the values worth touching sit at the top and
|
|
100
|
+
* the identity/endpoint plumbing sits at the bottom. Descriptions carry the one
|
|
101
|
+
* thing a form cannot infer: whether a change lands immediately or restarts the
|
|
102
|
+
* WeChat monitor (see HOT_FIELDS below).
|
|
103
|
+
*/
|
|
104
|
+
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
105
|
+
provider: Schema<string, string>;
|
|
106
|
+
model: Schema<string, string>;
|
|
107
|
+
reasoningEffort: Schema<string, string>;
|
|
108
|
+
allowFrom: Schema<string[], string[]>;
|
|
109
|
+
attachImages: Schema<boolean, boolean>;
|
|
110
|
+
stripEmoji: Schema<boolean, boolean>;
|
|
111
|
+
mcpBridge: Schema<boolean, boolean>;
|
|
112
|
+
maxImageEdge: Schema<number, number>;
|
|
113
|
+
imageQuality: Schema<number, number>;
|
|
114
|
+
compressThresholdBytes: Schema<number, number>;
|
|
115
|
+
noticeMinBytes: Schema<number, number>;
|
|
116
|
+
approvalTimeoutMs: Schema<number, number>;
|
|
117
|
+
logLevel: Schema<"debug" | "info" | "warn" | "error", "debug" | "info" | "warn" | "error">;
|
|
118
|
+
autoStart: Schema<boolean, boolean>;
|
|
119
|
+
sessionId: Schema<string, string>;
|
|
120
|
+
forwardQuestions: Schema<boolean, boolean>;
|
|
121
|
+
botAgent: Schema<string, string>;
|
|
122
|
+
apiBaseUrl: Schema<string, string>;
|
|
123
|
+
cwd: Schema<string, string>;
|
|
124
|
+
}>, Schemastery.ObjectT<{
|
|
125
|
+
provider: Schema<string, string>;
|
|
126
|
+
model: Schema<string, string>;
|
|
127
|
+
reasoningEffort: Schema<string, string>;
|
|
128
|
+
allowFrom: Schema<string[], string[]>;
|
|
129
|
+
attachImages: Schema<boolean, boolean>;
|
|
130
|
+
stripEmoji: Schema<boolean, boolean>;
|
|
131
|
+
mcpBridge: Schema<boolean, boolean>;
|
|
132
|
+
maxImageEdge: Schema<number, number>;
|
|
133
|
+
imageQuality: Schema<number, number>;
|
|
134
|
+
compressThresholdBytes: Schema<number, number>;
|
|
135
|
+
noticeMinBytes: Schema<number, number>;
|
|
136
|
+
approvalTimeoutMs: Schema<number, number>;
|
|
137
|
+
logLevel: Schema<"debug" | "info" | "warn" | "error", "debug" | "info" | "warn" | "error">;
|
|
138
|
+
autoStart: Schema<boolean, boolean>;
|
|
139
|
+
sessionId: Schema<string, string>;
|
|
140
|
+
forwardQuestions: Schema<boolean, boolean>;
|
|
141
|
+
botAgent: Schema<string, string>;
|
|
142
|
+
apiBaseUrl: Schema<string, string>;
|
|
143
|
+
cwd: Schema<string, string>;
|
|
144
|
+
}>>;
|
|
145
|
+
/**
|
|
146
|
+
* Fields a running plugin can adopt in place, without tearing anything down.
|
|
147
|
+
*
|
|
148
|
+
* The test for membership is not "is it small" but "is it read at the moment it
|
|
149
|
+
* is used". Everything here is looked up per message, per photo, or per
|
|
150
|
+
* approval, so overwriting the live config object is enough — `logLevel` is the
|
|
151
|
+
* one member needing a side effect (see the update hook in index.ts), and it
|
|
152
|
+
* earns its place because flipping to debug while chasing something is exactly
|
|
153
|
+
* when you least want to drop the WeChat connection.
|
|
154
|
+
*
|
|
155
|
+
* Anything absent is COLD by default: the update hook lets cordis validate and
|
|
156
|
+
* restart the fiber, which reconnects the monitor in a second or two. New
|
|
157
|
+
* fields therefore default to the safe behaviour rather than the fast one.
|
|
158
|
+
*/
|
|
159
|
+
export declare const HOT_FIELDS: Set<keyof ClawbotConfig>;
|
|
160
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","s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AAa,CA4DrG;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DjB,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,0BAiBrB,CAAC"}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawBot plugin configuration.
|
|
3
|
+
*
|
|
4
|
+
* Values come from the `clawbot` row in the profile's composed cordis tree
|
|
5
|
+
* (see `cordis.patch.yml` and the profile's own patch layer). Every field has
|
|
6
|
+
* a safe default, so the row can be as small as `{ autoStart: true }`.
|
|
7
|
+
*/
|
|
8
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
9
|
+
export const DEFAULT_CONFIG = {
|
|
10
|
+
autoStart: true,
|
|
11
|
+
allowFrom: [],
|
|
12
|
+
sessionId: "wechat-main",
|
|
13
|
+
cwd: undefined,
|
|
14
|
+
forwardQuestions: false,
|
|
15
|
+
approvalTimeoutMs: 0,
|
|
16
|
+
botAgent: "DSH-ClawBot/0.1.0 (wechat-clawbot)",
|
|
17
|
+
apiBaseUrl: "https://ilinkai.weixin.qq.com",
|
|
18
|
+
logLevel: "info",
|
|
19
|
+
maxImageEdge: 2048,
|
|
20
|
+
stripEmoji: true,
|
|
21
|
+
mcpBridge: true,
|
|
22
|
+
imageQuality: 80,
|
|
23
|
+
compressThresholdBytes: 1024 * 1024,
|
|
24
|
+
noticeMinBytes: 2 * 1024 * 1024,
|
|
25
|
+
attachImages: true,
|
|
26
|
+
};
|
|
27
|
+
function asStringArray(value) {
|
|
28
|
+
if (!Array.isArray(value))
|
|
29
|
+
return [];
|
|
30
|
+
return value.filter((v) => typeof v === "string" && v.length > 0);
|
|
31
|
+
}
|
|
32
|
+
/** Merge a raw (possibly partial) row config over the defaults. */
|
|
33
|
+
export function normalizeConfig(raw) {
|
|
34
|
+
const r = (raw ?? {});
|
|
35
|
+
return {
|
|
36
|
+
autoStart: typeof r.autoStart === "boolean" ? r.autoStart : DEFAULT_CONFIG.autoStart,
|
|
37
|
+
allowFrom: asStringArray(r.allowFrom),
|
|
38
|
+
sessionId: typeof r.sessionId === "string" && r.sessionId.trim()
|
|
39
|
+
? r.sessionId.trim()
|
|
40
|
+
: DEFAULT_CONFIG.sessionId,
|
|
41
|
+
cwd: typeof r.cwd === "string" && r.cwd.trim() ? r.cwd : undefined,
|
|
42
|
+
forwardQuestions: typeof r.forwardQuestions === "boolean"
|
|
43
|
+
? r.forwardQuestions
|
|
44
|
+
: DEFAULT_CONFIG.forwardQuestions,
|
|
45
|
+
approvalTimeoutMs: typeof r.approvalTimeoutMs === "number" && Number.isFinite(r.approvalTimeoutMs)
|
|
46
|
+
? Math.max(0, r.approvalTimeoutMs)
|
|
47
|
+
: DEFAULT_CONFIG.approvalTimeoutMs,
|
|
48
|
+
botAgent: typeof r.botAgent === "string" && r.botAgent.trim()
|
|
49
|
+
? r.botAgent.trim()
|
|
50
|
+
: DEFAULT_CONFIG.botAgent,
|
|
51
|
+
apiBaseUrl: typeof r.apiBaseUrl === "string" && r.apiBaseUrl.trim()
|
|
52
|
+
? r.apiBaseUrl.trim()
|
|
53
|
+
: DEFAULT_CONFIG.apiBaseUrl,
|
|
54
|
+
logLevel: typeof r.logLevel === "string" &&
|
|
55
|
+
["debug", "info", "warn", "error"].includes(r.logLevel)
|
|
56
|
+
? r.logLevel
|
|
57
|
+
: DEFAULT_CONFIG.logLevel,
|
|
58
|
+
maxImageEdge: typeof r.maxImageEdge === "number" && Number.isFinite(r.maxImageEdge)
|
|
59
|
+
? Math.max(64, Math.min(8192, r.maxImageEdge))
|
|
60
|
+
: DEFAULT_CONFIG.maxImageEdge,
|
|
61
|
+
imageQuality: typeof r.imageQuality === "number" && Number.isFinite(r.imageQuality)
|
|
62
|
+
? Math.max(10, Math.min(100, r.imageQuality))
|
|
63
|
+
: DEFAULT_CONFIG.imageQuality,
|
|
64
|
+
compressThresholdBytes: typeof r.compressThresholdBytes === "number" && Number.isFinite(r.compressThresholdBytes)
|
|
65
|
+
? Math.max(0, r.compressThresholdBytes)
|
|
66
|
+
: DEFAULT_CONFIG.compressThresholdBytes,
|
|
67
|
+
stripEmoji: typeof r.stripEmoji === "boolean" ? r.stripEmoji : DEFAULT_CONFIG.stripEmoji,
|
|
68
|
+
mcpBridge: typeof r.mcpBridge === "boolean" ? r.mcpBridge : DEFAULT_CONFIG.mcpBridge,
|
|
69
|
+
noticeMinBytes: typeof r.noticeMinBytes === "number" && Number.isFinite(r.noticeMinBytes)
|
|
70
|
+
? Math.max(0, r.noticeMinBytes)
|
|
71
|
+
: DEFAULT_CONFIG.noticeMinBytes,
|
|
72
|
+
attachImages: typeof r.attachImages === "boolean" ? r.attachImages : DEFAULT_CONFIG.attachImages,
|
|
73
|
+
provider: typeof r.provider === "string" && r.provider.trim() ? r.provider.trim() : undefined,
|
|
74
|
+
model: typeof r.model === "string" && r.model.trim() ? r.model.trim() : undefined,
|
|
75
|
+
reasoningEffort: typeof r.reasoningEffort === "string" && r.reasoningEffort.trim()
|
|
76
|
+
? r.reasoningEffort.trim()
|
|
77
|
+
: undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The plugin's configuration schema, and with it its form in DSH's settings UI:
|
|
82
|
+
* a plugin without a schema has no fields for that page to draw.
|
|
83
|
+
*
|
|
84
|
+
* EVERY field must appear here. `Schema.object()` drops what it does not
|
|
85
|
+
* declare, so an omitted field would be silently deleted from the composed
|
|
86
|
+
* cordis row the first time the settings page writes this section back.
|
|
87
|
+
*
|
|
88
|
+
* Field order is form order, so the values worth touching sit at the top and
|
|
89
|
+
* the identity/endpoint plumbing sits at the bottom. Descriptions carry the one
|
|
90
|
+
* thing a form cannot infer: whether a change lands immediately or restarts the
|
|
91
|
+
* WeChat monitor (see HOT_FIELDS below).
|
|
92
|
+
*/
|
|
93
|
+
export const Config = Schema.object({
|
|
94
|
+
provider: Schema.string()
|
|
95
|
+
.description("固定这个 bot 用的 provider(如 harvard)。留空 = 跟随全局默认模型"),
|
|
96
|
+
model: Schema.string()
|
|
97
|
+
.description("固定模型 id(如 gpt-5.6-luna)。留空 = 跟随全局默认 —— 也就是说你在网页里换模型时,bot 会跟着换"),
|
|
98
|
+
reasoningEffort: Schema.string()
|
|
99
|
+
.description("思考等级(部分网关带工具时只接受 off;DeepSeek 可用 high 等)。留空 = 用该模型的默认"),
|
|
100
|
+
allowFrom: Schema.array(Schema.string())
|
|
101
|
+
.default([])
|
|
102
|
+
.description("允许给 bot 发消息的微信用户 id。留空 = 只有扫码登录的本人能用"),
|
|
103
|
+
attachImages: Schema.boolean()
|
|
104
|
+
.default(true)
|
|
105
|
+
.description("模型支持时,把图片直接附给它看(快)。关掉则退回让它用视觉工具读路径(慢,约多 40 秒),仅用于对比排查"),
|
|
106
|
+
stripEmoji: Schema.boolean()
|
|
107
|
+
.default(true)
|
|
108
|
+
.description("发出去的文字里去掉 Unicode emoji(改用微信原生表情代码)"),
|
|
109
|
+
mcpBridge: Schema.boolean()
|
|
110
|
+
.default(true)
|
|
111
|
+
.description("开放 Claude 桥(/plugins/clawbot/mcp/*):让 Claude Code 列出/读取/驱动 DSH 会话,并通过 bot 给你发微信。只监听本机,而且每个请求都要 token"),
|
|
112
|
+
maxImageEdge: Schema.number()
|
|
113
|
+
.default(2048)
|
|
114
|
+
.min(64)
|
|
115
|
+
.max(8192)
|
|
116
|
+
.description("发出/附上的图片长边像素上限。相机原图几千万像素,必须缩"),
|
|
117
|
+
imageQuality: Schema.number()
|
|
118
|
+
.default(80)
|
|
119
|
+
.min(10)
|
|
120
|
+
.max(100)
|
|
121
|
+
.description("压缩图片时的 JPEG 质量"),
|
|
122
|
+
compressThresholdBytes: Schema.number()
|
|
123
|
+
.default(1024 * 1024)
|
|
124
|
+
.min(0)
|
|
125
|
+
.description("超过这个字节数才压缩图片,以下的原样发"),
|
|
126
|
+
noticeMinBytes: Schema.number()
|
|
127
|
+
.default(2 * 1024 * 1024)
|
|
128
|
+
.min(0)
|
|
129
|
+
.description("发文件超过这个字节数才先发一条「正在发送」预告。0 = 每个文件都预告"),
|
|
130
|
+
approvalTimeoutMs: Schema.number()
|
|
131
|
+
.default(0)
|
|
132
|
+
.min(0)
|
|
133
|
+
.description("审批类问题等待微信回答的超时(毫秒)。0 = 一直等"),
|
|
134
|
+
logLevel: Schema.union(["debug", "info", "warn", "error"])
|
|
135
|
+
.default("info")
|
|
136
|
+
.description("协议层日志级别"),
|
|
137
|
+
autoStart: Schema.boolean()
|
|
138
|
+
.default(true)
|
|
139
|
+
.description("【改动会重启微信监听】DSH 启动时自动开始监听微信"),
|
|
140
|
+
sessionId: Schema.string()
|
|
141
|
+
.default("wechat-main")
|
|
142
|
+
.description("【改动会重启微信监听】微信消息统一进入的会话 id。改这个等于换一个记忆完全独立的 bot"),
|
|
143
|
+
forwardQuestions: Schema.boolean()
|
|
144
|
+
.default(false)
|
|
145
|
+
.description("【改动会重启微信监听】把 ask_user_question / 计划确认转发到微信"),
|
|
146
|
+
botAgent: Schema.string()
|
|
147
|
+
.default("DSH-ClawBot/0.1.0 (wechat-clawbot)")
|
|
148
|
+
.description("【改动会重启微信监听】上报给 iLink 服务器的 bot_agent 标识"),
|
|
149
|
+
apiBaseUrl: Schema.string()
|
|
150
|
+
.default("https://ilinkai.weixin.qq.com")
|
|
151
|
+
.description("【改动会重启微信监听】iLink 接口地址,只在测试/镜像时改"),
|
|
152
|
+
cwd: Schema.string()
|
|
153
|
+
.description("【改动会重启微信监听】新建会话时的工作目录。留空 = DSH 的启动目录"),
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* Fields a running plugin can adopt in place, without tearing anything down.
|
|
157
|
+
*
|
|
158
|
+
* The test for membership is not "is it small" but "is it read at the moment it
|
|
159
|
+
* is used". Everything here is looked up per message, per photo, or per
|
|
160
|
+
* approval, so overwriting the live config object is enough — `logLevel` is the
|
|
161
|
+
* one member needing a side effect (see the update hook in index.ts), and it
|
|
162
|
+
* earns its place because flipping to debug while chasing something is exactly
|
|
163
|
+
* when you least want to drop the WeChat connection.
|
|
164
|
+
*
|
|
165
|
+
* Anything absent is COLD by default: the update hook lets cordis validate and
|
|
166
|
+
* restart the fiber, which reconnects the monitor in a second or two. New
|
|
167
|
+
* fields therefore default to the safe behaviour rather than the fast one.
|
|
168
|
+
*/
|
|
169
|
+
export const HOT_FIELDS = new Set([
|
|
170
|
+
// The selection ref handed to installModelSelection is mutable by design —
|
|
171
|
+
// prompt assembly snapshots it per step — so switching model needs no
|
|
172
|
+
// reinstall and no restart, just a new value in the ref.
|
|
173
|
+
"provider",
|
|
174
|
+
"model",
|
|
175
|
+
"reasoningEffort",
|
|
176
|
+
"allowFrom",
|
|
177
|
+
"attachImages",
|
|
178
|
+
"stripEmoji",
|
|
179
|
+
"mcpBridge",
|
|
180
|
+
"maxImageEdge",
|
|
181
|
+
"imageQuality",
|
|
182
|
+
"compressThresholdBytes",
|
|
183
|
+
"noticeMinBytes",
|
|
184
|
+
"approvalTimeoutMs",
|
|
185
|
+
"logLevel",
|
|
186
|
+
]);
|
|
187
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAoG9C,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,aAAa;IACxB,GAAG,EAAE,SAAS;IACd,gBAAgB,EAAE,KAAK;IACvB,iBAAiB,EAAE,CAAC;IACpB,QAAQ,EAAE,oCAAoC;IAC9C,UAAU,EAAE,+BAA+B;IAC3C,QAAQ,EAAE,MAAM;IAChB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,IAAI;IACf,YAAY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CAAC;SACxC,WAAW,CAAC,iCAAiC,CAAC;IACjD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE;SACjB,WAAW,CAAC,sCAAsC,CAAC;CACvD,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAsB;IACrD,2EAA2E;IAC3E,sEAAsE;IACtE,yDAAyD;IACzD,UAAU;IACV,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,cAAc;IACd,YAAY;IACZ,WAAW;IACX,cAAc;IACd,cAAc;IACd,wBAAwB;IACxB,gBAAgB;IAChB,mBAAmB;IACnB,UAAU;CACX,CAAC,CAAC"}
|
package/lib/emoji.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clean up outbound WeChat text. The model is unreliable at following "no
|
|
3
|
+
* emoji" instructions, so the plugin enforces the policy deterministically
|
|
4
|
+
* rather than trusting the prompt.
|
|
5
|
+
*
|
|
6
|
+
* Two different things, with two different rules:
|
|
7
|
+
*
|
|
8
|
+
* - **Unicode emoji** (😊 ✅ 🎉) are a matter of taste, so they follow the
|
|
9
|
+
* `stripEmoji` setting. The prompt's rule C.3 flips with the same setting,
|
|
10
|
+
* so the model is not told to produce something that gets stripped on the
|
|
11
|
+
* way out.
|
|
12
|
+
*
|
|
13
|
+
* - **WeChat's own bracket codes** (`[捂脸]`, `[好的]`) are removed
|
|
14
|
+
* unconditionally. They are WeChat's internal notation, and sending them
|
|
15
|
+
* through this bridge does NOT turn them into a picture on the recipient's
|
|
16
|
+
* client — he just sees the literal brackets. They are never right, so
|
|
17
|
+
* there is no setting for them.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Remove WeChat's bracket emoji codes. Applied to every outbound message,
|
|
21
|
+
* whatever the emoji setting says, because they render as literal text.
|
|
22
|
+
*/
|
|
23
|
+
export declare function stripWechatCodes(text: string): string;
|
|
24
|
+
/** Remove Unicode emoji characters (and the bracket codes along the way). */
|
|
25
|
+
export declare function stripEmoji(text: string): string;
|
|
26
|
+
//# sourceMappingURL=emoji.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji.d.ts","sourceRoot":"","sources":["../src/emoji.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA8BH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/lib/emoji.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clean up outbound WeChat text. The model is unreliable at following "no
|
|
3
|
+
* emoji" instructions, so the plugin enforces the policy deterministically
|
|
4
|
+
* rather than trusting the prompt.
|
|
5
|
+
*
|
|
6
|
+
* Two different things, with two different rules:
|
|
7
|
+
*
|
|
8
|
+
* - **Unicode emoji** (😊 ✅ 🎉) are a matter of taste, so they follow the
|
|
9
|
+
* `stripEmoji` setting. The prompt's rule C.3 flips with the same setting,
|
|
10
|
+
* so the model is not told to produce something that gets stripped on the
|
|
11
|
+
* way out.
|
|
12
|
+
*
|
|
13
|
+
* - **WeChat's own bracket codes** (`[捂脸]`, `[好的]`) are removed
|
|
14
|
+
* unconditionally. They are WeChat's internal notation, and sending them
|
|
15
|
+
* through this bridge does NOT turn them into a picture on the recipient's
|
|
16
|
+
* client — he just sees the literal brackets. They are never right, so
|
|
17
|
+
* there is no setting for them.
|
|
18
|
+
*/
|
|
19
|
+
// Common emoji / symbol ranges (and variation selectors). CJK and CJK
|
|
20
|
+
// punctuation are outside these ranges, so Chinese text is never damaged.
|
|
21
|
+
const EMOJI_RE = /[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}\u{2B00}-\u{2BFF}\u{2190}-\u{21FF}\u{2E80}-\u{2EFF}\u{FE0F}\u{200D}\u{2B50}\u{2764}\u{2763}\u{2705}\u{274C}\u{274E}\u{2728}\u{00A9}\u{00AE}\u{203C}\u{2049}\u{2122}\u{2139}]/gu;
|
|
22
|
+
/**
|
|
23
|
+
* WeChat native emoji codes: a bracketed run of 1–4 Han characters, which is
|
|
24
|
+
* what every code in that set looks like (`[捂脸]`, `[偷笑]`, `[再见]`).
|
|
25
|
+
*
|
|
26
|
+
* Deliberately narrow rather than a blanket `\[.*?\]`. The inbound markers this
|
|
27
|
+
* bridge itself uses are longer or carry punctuation (`[定时任务触发]`,
|
|
28
|
+
* `[图片: /path]`, `[引用: …]`), so none of them match. The trailing lookahead
|
|
29
|
+
* spares a markdown link: `[点这里](https://…)` used to lose its label and
|
|
30
|
+
* leave a bare `(url)` dangling — caught by testing exactly that string.
|
|
31
|
+
*
|
|
32
|
+
* A genuine short Han bracket in prose — `[参考]`, say — would still be caught,
|
|
33
|
+
* which is a fair trade for never shipping a broken emoji code.
|
|
34
|
+
*/
|
|
35
|
+
const WECHAT_CODE_RE = /\[\p{Script=Han}{1,4}\](?!\()/gu;
|
|
36
|
+
/** Collapse the whitespace a removal leaves behind. */
|
|
37
|
+
function tidy(text) {
|
|
38
|
+
return text
|
|
39
|
+
.replace(/[ \t]+/g, " ")
|
|
40
|
+
.replace(/ *\n */g, "\n")
|
|
41
|
+
.trim();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Remove WeChat's bracket emoji codes. Applied to every outbound message,
|
|
45
|
+
* whatever the emoji setting says, because they render as literal text.
|
|
46
|
+
*/
|
|
47
|
+
export function stripWechatCodes(text) {
|
|
48
|
+
return tidy(text.replace(WECHAT_CODE_RE, ""));
|
|
49
|
+
}
|
|
50
|
+
/** Remove Unicode emoji characters (and the bracket codes along the way). */
|
|
51
|
+
export function stripEmoji(text) {
|
|
52
|
+
return tidy(text.replace(EMOJI_RE, "").replace(WECHAT_CODE_RE, ""));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=emoji.js.map
|
package/lib/emoji.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji.js","sourceRoot":"","sources":["../src/emoji.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,sEAAsE;AACtE,0EAA0E;AAC1E,MAAM,QAAQ,GACZ,qNAAqN,CAAC;AAExN;;;;;;;;;;;;GAYG;AACH,MAAM,cAAc,GAAG,iCAAiC,CAAC;AAEzD,uDAAuD;AACvD,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,IAAI;SACR,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;SACxB,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { BaseInfo, GetUploadUrlReq, GetUploadUrlResp, GetUpdatesReq, GetUpdatesResp, NotifyStopResp, NotifyStartResp, SendMessageReq, SendMessageResp, SendTypingReq, GetConfigResp } from "./types.js";
|
|
2
|
+
export type WeixinApiOptions = {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
/** Long-poll timeout for getUpdates (server may hold the request up to this). */
|
|
7
|
+
longPollTimeoutMs?: number;
|
|
8
|
+
};
|
|
9
|
+
interface PackageJson {
|
|
10
|
+
name?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
ilink_appid?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Walk up from `startDir` searching for the plugin's own `package.json`.
|
|
16
|
+
*
|
|
17
|
+
* Resilient to differing layouts between dev (TS source under `src/`) and
|
|
18
|
+
* publish (compiled output under `dist/src/`) by not assuming a fixed depth.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readPackageJsonFromDir(startDir: string): PackageJson;
|
|
21
|
+
/**
|
|
22
|
+
* Sanitize a user-supplied `botAgent` config value into a wire-safe string.
|
|
23
|
+
*
|
|
24
|
+
* Grammar (UA-style):
|
|
25
|
+
* bot_agent = product *( SP product )
|
|
26
|
+
* product = name "/" version [ SP "(" comment ")" ]
|
|
27
|
+
* name = 1*32( ALPHA / DIGIT / "_" / "." / "-" )
|
|
28
|
+
* version = 1*32( ALPHA / DIGIT / "_" / "." / "+" / "-" )
|
|
29
|
+
* comment = 1*64( printable ASCII minus "(" ")" )
|
|
30
|
+
*
|
|
31
|
+
* Tokens that fail to parse are dropped silently (no partial tokens kept).
|
|
32
|
+
* Returns `DEFAULT_BOT_AGENT` when the input is empty / all tokens dropped /
|
|
33
|
+
* the result exceeds the length cap after truncation.
|
|
34
|
+
*/
|
|
35
|
+
export declare function sanitizeBotAgent(raw: string | undefined): string;
|
|
36
|
+
/** Build the `base_info` payload included in every API request. */
|
|
37
|
+
export declare function buildBaseInfo(): BaseInfo;
|
|
38
|
+
/**
|
|
39
|
+
* Classify a fetch-level error into a category for logging / diagnostics.
|
|
40
|
+
* This does NOT cover HTTP-level errors (4xx/5xx) — those are thrown separately.
|
|
41
|
+
*/
|
|
42
|
+
export declare function classifyFetchError(err: unknown): {
|
|
43
|
+
type: "dns" | "tcp" | "tls" | "timeout" | "unknown";
|
|
44
|
+
description: string;
|
|
45
|
+
code?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* GET fetch wrapper: send a GET request to a Weixin API endpoint.
|
|
49
|
+
* When `timeoutMs` is set, the request is aborted after that many milliseconds.
|
|
50
|
+
* Query parameters should already be encoded in `endpoint`.
|
|
51
|
+
* Returns the raw response text on success; throws on HTTP error or (if used) timeout abort.
|
|
52
|
+
*/
|
|
53
|
+
export declare function apiGetFetch(params: {
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
endpoint: string;
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
label: string;
|
|
58
|
+
}): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Common fetch wrapper: POST JSON to a Weixin API endpoint.
|
|
61
|
+
* When `timeoutMs` is provided, the request is aborted after that many milliseconds.
|
|
62
|
+
* When omitted, no client-side timeout is applied (relies on OS/TCP stack).
|
|
63
|
+
* Returns the raw response text on success; throws on HTTP error or timeout.
|
|
64
|
+
*
|
|
65
|
+
* When `abortSignal` is provided, an external abort (e.g. gateway channel stop)
|
|
66
|
+
* cancels the in-flight request immediately instead of waiting for `timeoutMs`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function apiPostFetch(params: {
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
endpoint: string;
|
|
71
|
+
body: string;
|
|
72
|
+
token?: string;
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
label: string;
|
|
75
|
+
abortSignal?: AbortSignal;
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Long-poll getUpdates. Server should hold the request until new messages or timeout.
|
|
79
|
+
*
|
|
80
|
+
* On client-side timeout (no server response within timeoutMs), returns an empty response
|
|
81
|
+
* with ret=0 so the caller can simply retry. This is normal for long-poll.
|
|
82
|
+
*/
|
|
83
|
+
export declare function getUpdates(params: GetUpdatesReq & {
|
|
84
|
+
baseUrl: string;
|
|
85
|
+
token?: string;
|
|
86
|
+
timeoutMs?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Optional external abort signal from the gateway. When stopping the channel,
|
|
89
|
+
* this aborts the in-flight long-poll immediately so hot reload can restart.
|
|
90
|
+
*/
|
|
91
|
+
abortSignal?: AbortSignal;
|
|
92
|
+
}): Promise<GetUpdatesResp>;
|
|
93
|
+
/** Get a pre-signed CDN upload URL for a file. */
|
|
94
|
+
export declare function getUploadUrl(params: GetUploadUrlReq & WeixinApiOptions): Promise<GetUploadUrlResp>;
|
|
95
|
+
/**
|
|
96
|
+
* Build an actionable error string for a non-zero `sendMessage` `ret`.
|
|
97
|
+
*
|
|
98
|
+
* The server frequently reports a business-level failure with an empty
|
|
99
|
+
* `errmsg` (commonly `ret=-2`), which is hard to diagnose. The most common
|
|
100
|
+
* cause on agent-initiated outbound delivery is an expired or missing
|
|
101
|
+
* `context_token`: it is only refreshed by a recent inbound message from the
|
|
102
|
+
* recipient, so a bot that sends after a long idle period (cron reminders,
|
|
103
|
+
* scheduled digests) fails until the user messages it again. Surface that
|
|
104
|
+
* likely cause instead of an opaque empty message.
|
|
105
|
+
*
|
|
106
|
+
* Ported from NewFuture/openclaw-weixin v3.0.1 (commit da9efec).
|
|
107
|
+
*/
|
|
108
|
+
export declare function describeSendMessageFailure(resp: SendMessageResp, body: SendMessageReq): string;
|
|
109
|
+
export declare function sendMessage(params: WeixinApiOptions & {
|
|
110
|
+
body: SendMessageReq;
|
|
111
|
+
}): Promise<{
|
|
112
|
+
messageId?: number;
|
|
113
|
+
}>;
|
|
114
|
+
/** Fetch bot config (includes typing_ticket) for a given user. */
|
|
115
|
+
export declare function getConfig(params: WeixinApiOptions & {
|
|
116
|
+
ilinkUserId: string;
|
|
117
|
+
contextToken?: string;
|
|
118
|
+
}): Promise<GetConfigResp>;
|
|
119
|
+
/** Send a typing indicator to a user. */
|
|
120
|
+
export declare function sendTyping(params: WeixinApiOptions & {
|
|
121
|
+
body: SendTypingReq;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Notify Weixin that this channel client is stopping (gateway shutdown / channel stop).
|
|
125
|
+
* Uses a standalone timeout (not the gateway abort signal) so the request can finish
|
|
126
|
+
* after OpenClaw has already aborted the long-poll.
|
|
127
|
+
*/
|
|
128
|
+
export declare function notifyStop(params: WeixinApiOptions): Promise<NotifyStopResp>;
|
|
129
|
+
/**
|
|
130
|
+
* Notify Weixin that this channel client is starting (gateway startup / channel start).
|
|
131
|
+
*/
|
|
132
|
+
export declare function notifyStart(params: WeixinApiOptions): Promise<NotifyStartResp>;
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ilink/api/api.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,EACb,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAMF,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAaD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAsBpE;AAqCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAoEhE;AAED,mEAAmE;AACnE,wBAAgB,aAAa,IAAI,QAAQ,CAKxC;AAgDD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG;IAChD,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,SA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