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.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +32 -0
  3. package/README.md +324 -0
  4. package/README.zh.md +192 -0
  5. package/cordis.patch.yml +23 -0
  6. package/lib/approvals.d.ts +29 -0
  7. package/lib/approvals.d.ts.map +1 -0
  8. package/lib/approvals.js +86 -0
  9. package/lib/approvals.js.map +1 -0
  10. package/lib/bridge.d.ts +281 -0
  11. package/lib/bridge.d.ts.map +1 -0
  12. package/lib/bridge.js +827 -0
  13. package/lib/bridge.js.map +1 -0
  14. package/lib/claude-peer.d.ts +44 -0
  15. package/lib/claude-peer.d.ts.map +1 -0
  16. package/lib/claude-peer.js +515 -0
  17. package/lib/claude-peer.js.map +1 -0
  18. package/lib/cli.d.ts +3 -0
  19. package/lib/cli.d.ts.map +1 -0
  20. package/lib/cli.js +128 -0
  21. package/lib/cli.js.map +1 -0
  22. package/lib/client.js +597 -0
  23. package/lib/config.d.ts +160 -0
  24. package/lib/config.d.ts.map +1 -0
  25. package/lib/config.js +187 -0
  26. package/lib/config.js.map +1 -0
  27. package/lib/emoji.d.ts +26 -0
  28. package/lib/emoji.d.ts.map +1 -0
  29. package/lib/emoji.js +54 -0
  30. package/lib/emoji.js.map +1 -0
  31. package/lib/ilink/api/api.d.ts +134 -0
  32. package/lib/ilink/api/api.d.ts.map +1 -0
  33. package/lib/ilink/api/api.js +507 -0
  34. package/lib/ilink/api/api.js.map +1 -0
  35. package/lib/ilink/api/session-guard.d.ts +16 -0
  36. package/lib/ilink/api/session-guard.d.ts.map +1 -0
  37. package/lib/ilink/api/session-guard.js +49 -0
  38. package/lib/ilink/api/session-guard.js.map +1 -0
  39. package/lib/ilink/api/types.d.ts +251 -0
  40. package/lib/ilink/api/types.d.ts.map +1 -0
  41. package/lib/ilink/api/types.js +37 -0
  42. package/lib/ilink/api/types.js.map +1 -0
  43. package/lib/ilink/auth/accounts.d.ts +67 -0
  44. package/lib/ilink/auth/accounts.d.ts.map +1 -0
  45. package/lib/ilink/auth/accounts.js +190 -0
  46. package/lib/ilink/auth/accounts.js.map +1 -0
  47. package/lib/ilink/auth/login-qr.d.ts +43 -0
  48. package/lib/ilink/auth/login-qr.d.ts.map +1 -0
  49. package/lib/ilink/auth/login-qr.js +333 -0
  50. package/lib/ilink/auth/login-qr.js.map +1 -0
  51. package/lib/ilink/cdn/aes-ecb.d.ts +7 -0
  52. package/lib/ilink/cdn/aes-ecb.d.ts.map +1 -0
  53. package/lib/ilink/cdn/aes-ecb.js +19 -0
  54. package/lib/ilink/cdn/aes-ecb.js.map +1 -0
  55. package/lib/ilink/cdn/cdn-upload.d.ts +18 -0
  56. package/lib/ilink/cdn/cdn-upload.d.ts.map +1 -0
  57. package/lib/ilink/cdn/cdn-upload.js +90 -0
  58. package/lib/ilink/cdn/cdn-upload.js.map +1 -0
  59. package/lib/ilink/cdn/cdn-url.d.ts +14 -0
  60. package/lib/ilink/cdn/cdn-url.d.ts.map +1 -0
  61. package/lib/ilink/cdn/cdn-url.js +14 -0
  62. package/lib/ilink/cdn/cdn-url.js.map +1 -0
  63. package/lib/ilink/cdn/pic-decrypt.d.ts +10 -0
  64. package/lib/ilink/cdn/pic-decrypt.d.ts.map +1 -0
  65. package/lib/ilink/cdn/pic-decrypt.js +89 -0
  66. package/lib/ilink/cdn/pic-decrypt.js.map +1 -0
  67. package/lib/ilink/cdn/upload.d.ts +43 -0
  68. package/lib/ilink/cdn/upload.d.ts.map +1 -0
  69. package/lib/ilink/cdn/upload.js +115 -0
  70. package/lib/ilink/cdn/upload.js.map +1 -0
  71. package/lib/ilink/media/mime.d.ts +7 -0
  72. package/lib/ilink/media/mime.d.ts.map +1 -0
  73. package/lib/ilink/media/mime.js +73 -0
  74. package/lib/ilink/media/mime.js.map +1 -0
  75. package/lib/ilink/messaging/send-media.d.ts +23 -0
  76. package/lib/ilink/messaging/send-media.d.ts.map +1 -0
  77. package/lib/ilink/messaging/send-media.js +71 -0
  78. package/lib/ilink/messaging/send-media.js.map +1 -0
  79. package/lib/ilink/messaging/send.d.ts +55 -0
  80. package/lib/ilink/messaging/send.d.ts.map +1 -0
  81. package/lib/ilink/messaging/send.js +182 -0
  82. package/lib/ilink/messaging/send.js.map +1 -0
  83. package/lib/ilink/storage/state-dir.d.ts +14 -0
  84. package/lib/ilink/storage/state-dir.d.ts.map +1 -0
  85. package/lib/ilink/storage/state-dir.js +22 -0
  86. package/lib/ilink/storage/state-dir.js.map +1 -0
  87. package/lib/ilink/storage/sync-buf.d.ts +21 -0
  88. package/lib/ilink/storage/sync-buf.d.ts.map +1 -0
  89. package/lib/ilink/storage/sync-buf.js +64 -0
  90. package/lib/ilink/storage/sync-buf.js.map +1 -0
  91. package/lib/ilink/util/logger.d.ts +20 -0
  92. package/lib/ilink/util/logger.d.ts.map +1 -0
  93. package/lib/ilink/util/logger.js +73 -0
  94. package/lib/ilink/util/logger.js.map +1 -0
  95. package/lib/ilink/util/random.d.ts +11 -0
  96. package/lib/ilink/util/random.d.ts.map +1 -0
  97. package/lib/ilink/util/random.js +16 -0
  98. package/lib/ilink/util/random.js.map +1 -0
  99. package/lib/ilink/util/redact.d.ts +21 -0
  100. package/lib/ilink/util/redact.d.ts.map +1 -0
  101. package/lib/ilink/util/redact.js +54 -0
  102. package/lib/ilink/util/redact.js.map +1 -0
  103. package/lib/image-compress.d.ts +38 -0
  104. package/lib/image-compress.d.ts.map +1 -0
  105. package/lib/image-compress.js +184 -0
  106. package/lib/image-compress.js.map +1 -0
  107. package/lib/inbound-media.d.ts +17 -0
  108. package/lib/inbound-media.d.ts.map +1 -0
  109. package/lib/inbound-media.js +96 -0
  110. package/lib/inbound-media.js.map +1 -0
  111. package/lib/inbound.d.ts +28 -0
  112. package/lib/inbound.d.ts.map +1 -0
  113. package/lib/inbound.js +265 -0
  114. package/lib/inbound.js.map +1 -0
  115. package/lib/index.d.ts +23 -0
  116. package/lib/index.d.ts.map +1 -0
  117. package/lib/index.js +321 -0
  118. package/lib/index.js.map +1 -0
  119. package/lib/mcp-route.d.ts +33 -0
  120. package/lib/mcp-route.d.ts.map +1 -0
  121. package/lib/mcp-route.js +422 -0
  122. package/lib/mcp-route.js.map +1 -0
  123. package/lib/memory-auto.d.ts +22 -0
  124. package/lib/memory-auto.d.ts.map +1 -0
  125. package/lib/memory-auto.js +144 -0
  126. package/lib/memory-auto.js.map +1 -0
  127. package/lib/memory.d.ts +26 -0
  128. package/lib/memory.d.ts.map +1 -0
  129. package/lib/memory.js +168 -0
  130. package/lib/memory.js.map +1 -0
  131. package/lib/models-route.d.ts +24 -0
  132. package/lib/models-route.d.ts.map +1 -0
  133. package/lib/models-route.js +84 -0
  134. package/lib/models-route.js.map +1 -0
  135. package/lib/monitor.d.ts +13 -0
  136. package/lib/monitor.d.ts.map +1 -0
  137. package/lib/monitor.js +116 -0
  138. package/lib/monitor.js.map +1 -0
  139. package/lib/pending.d.ts +23 -0
  140. package/lib/pending.d.ts.map +1 -0
  141. package/lib/pending.js +38 -0
  142. package/lib/pending.js.map +1 -0
  143. package/lib/prompt.d.ts +36 -0
  144. package/lib/prompt.d.ts.map +1 -0
  145. package/lib/prompt.js +246 -0
  146. package/lib/prompt.js.map +1 -0
  147. package/lib/questions.d.ts +21 -0
  148. package/lib/questions.d.ts.map +1 -0
  149. package/lib/questions.js +116 -0
  150. package/lib/questions.js.map +1 -0
  151. package/lib/quote-history.d.ts +18 -0
  152. package/lib/quote-history.d.ts.map +1 -0
  153. package/lib/quote-history.js +96 -0
  154. package/lib/quote-history.js.map +1 -0
  155. package/lib/state.d.ts +27 -0
  156. package/lib/state.d.ts.map +1 -0
  157. package/lib/state.js +154 -0
  158. package/lib/state.js.map +1 -0
  159. package/lib/subagent-model.d.ts +26 -0
  160. package/lib/subagent-model.d.ts.map +1 -0
  161. package/lib/subagent-model.js +30 -0
  162. package/lib/subagent-model.js.map +1 -0
  163. package/lib/tool.d.ts +14 -0
  164. package/lib/tool.d.ts.map +1 -0
  165. package/lib/tool.js +518 -0
  166. package/lib/tool.js.map +1 -0
  167. package/package.json +94 -0
package/lib/tool.js ADDED
@@ -0,0 +1,518 @@
1
+ /**
2
+ * `send_wechat_file` tool: lets the WeChat agent deliver a local file (image,
3
+ * PDF, document, archive, …) to the user's WeChat conversation.
4
+ *
5
+ * Registered agent-scoped (only the WeChat session sees it) from the bridge's
6
+ * setup hook. Media travels through the vendored iLink CDN upload pipeline
7
+ * (AES-128-ECB encrypted), the same path the official OpenClaw WeChat channel
8
+ * uses.
9
+ */
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+ import { defineTool } from "@deepseek-ai/dsh-tools";
13
+ import { sendWeixinMediaFile } from "./ilink/messaging/send-media.js";
14
+ import { getConfig, sendTyping } from "./ilink/api/api.js";
15
+ import { TypingStatus } from "./ilink/api/types.js";
16
+ import { compressForUpload, makePreviewCopy } from "./image-compress.js";
17
+ import { stripEmoji, stripWechatCodes } from "./emoji.js";
18
+ import { appendMemoryEntry } from "./memory.js";
19
+ import { logger } from "./ilink/util/logger.js";
20
+ /**
21
+ * Register `look_at_image` — hand a local image straight to the model.
22
+ *
23
+ * This replaces `preview_wechat_image`, which only returned a *path*: the model
24
+ * then had to call qwen's `vision_read` on that path, a second round trip that
25
+ * cost roughly 40s per photo. Here the bytes are downscaled and committed
26
+ * through the attachment service — literally the same `bridge.attachImage()`
27
+ * call an inbound WeChat photo takes — and the picture itself comes back as an
28
+ * image block, so the model simply sees it on the next request. No vision
29
+ * model, no extra tool call.
30
+ *
31
+ * The old path-only behaviour survives as a fallback, because the model picker
32
+ * can point this session at a text-only model at any time: on such a route the
33
+ * tool still returns a downscaled copy's path and says to use a vision tool on
34
+ * it. Same tool name, same call site in the prompt, either way.
35
+ *
36
+ * Precedent for returning an image from a tool: `read_image` in
37
+ * @deepseek-ai/dsh-tool-fs. The image rides `output.render`, not the return
38
+ * value — render is what projects the stored value into model content, so it
39
+ * also works when the session is replayed.
40
+ */
41
+ function registerLookAtImageTool(agentCtx, deps) {
42
+ agentCtx.tools.register(defineTool({
43
+ name: "look_at_image",
44
+ description: "Look at a local image yourself. Downscales it and returns the picture itself, so you see it directly in your next step — do NOT call a vision tool afterwards. " +
45
+ "Use this before sending any image you have not already seen this turn, and to inspect any image on disk. " +
46
+ "The original file is never modified. If the current model cannot accept images, this returns a downscaled copy's path instead and says so.",
47
+ parameters: {
48
+ path: {
49
+ type: "string",
50
+ required: true,
51
+ description: "Path of the local image to look at (absolute or relative).",
52
+ },
53
+ },
54
+ output: {
55
+ schema: {
56
+ type: "object",
57
+ additionalProperties: false,
58
+ properties: {
59
+ ok: { type: "boolean", required: true },
60
+ mode: { type: "string", enum: ["image", "path"], required: true },
61
+ path: { type: "string", required: true },
62
+ message: { type: "string", required: true },
63
+ image: {
64
+ type: "object",
65
+ additionalProperties: false,
66
+ properties: {
67
+ attachmentId: { type: "string", required: true },
68
+ mediaType: {
69
+ type: "string",
70
+ enum: ["image/png", "image/jpeg", "image/webp", "image/gif"],
71
+ required: true,
72
+ },
73
+ bytes: { type: "integer", required: true },
74
+ width: { type: "integer", required: true },
75
+ height: { type: "integer", required: true },
76
+ name: { type: "string" },
77
+ // Added by dsh-attachment 0.1.1-rc.2, which normalizes
78
+ // orientation and downscales oversized images and records what
79
+ // it came from. Declared because `additionalProperties: false`
80
+ // would otherwise REJECT the whole tool result the first time a
81
+ // real photo got downscaled.
82
+ originalDimensions: {
83
+ type: "object",
84
+ additionalProperties: false,
85
+ properties: {
86
+ width: { type: "integer", required: true },
87
+ height: { type: "integer", required: true },
88
+ },
89
+ },
90
+ },
91
+ },
92
+ },
93
+ },
94
+ render: (_args, value) => {
95
+ if (value.ok !== true)
96
+ return [{ type: "text", text: `看图失败: ${value.message}` }];
97
+ if (value.mode === "image" && value.image !== undefined) {
98
+ return [
99
+ {
100
+ type: "text",
101
+ text: `<path>${value.path}</path>\n<type>image</type>\n<content>\n${value.image.mediaType} ${value.image.width}x${value.image.height} px, ${value.image.bytes} bytes — 图片本身就在下面,直接看\n</content>`,
102
+ },
103
+ { type: "image", attachment: value.image },
104
+ ];
105
+ }
106
+ return [{
107
+ type: "text",
108
+ text: `缩小副本: ${value.path}\n(${value.message})`,
109
+ }];
110
+ },
111
+ },
112
+ async execute(args) {
113
+ const { path: rawPath } = args;
114
+ const resolved = path.isAbsolute(rawPath)
115
+ ? path.normalize(rawPath)
116
+ : path.resolve(deps.config.cwd ?? process.cwd(), rawPath);
117
+ // Preferred path: the route takes images, so commit the bytes and let
118
+ // the model look for itself.
119
+ const bridge = deps.getBridge();
120
+ if (bridge !== null && await bridge.routeTakesImages()) {
121
+ const ref = await bridge.attachImage(resolved, "look_at_image");
122
+ if (ref !== null) {
123
+ // Pick the declared fields rather than passing the ref through.
124
+ // The store owns this shape and grows it between releases —
125
+ // `originalDimensions` arrived in 0.1.1-rc.2 — and with
126
+ // `additionalProperties: false` an undeclared field fails the whole
127
+ // call. Picking means a future addition is merely ignored.
128
+ const image = {
129
+ attachmentId: ref.attachmentId,
130
+ mediaType: ref.mediaType,
131
+ bytes: ref.bytes,
132
+ width: ref.width,
133
+ height: ref.height,
134
+ ...(ref.name === undefined ? {} : { name: ref.name }),
135
+ ...(ref.originalDimensions === undefined
136
+ ? {}
137
+ : { originalDimensions: ref.originalDimensions }),
138
+ };
139
+ return { ok: true, mode: "image", path: resolved, image, message: "图片已附在结果里" };
140
+ }
141
+ logger.warn(`look_at_image: 附图没成功,退回给路径 ${resolved}`);
142
+ }
143
+ // Fallback: text-only route (or the attach failed). Hand back a small
144
+ // copy plus an explicit instruction, so the turn still completes.
145
+ try {
146
+ const preview = makePreviewCopy(resolved, {
147
+ maxImageEdge: deps.config.maxImageEdge,
148
+ imageQuality: deps.config.imageQuality,
149
+ compressThresholdBytes: deps.config.compressThresholdBytes,
150
+ });
151
+ return {
152
+ ok: true,
153
+ mode: "path",
154
+ path: preview,
155
+ message: "当前模型不能直接看图,请对这个路径调用 vision_read 查看",
156
+ };
157
+ }
158
+ catch (err) {
159
+ return {
160
+ ok: false,
161
+ mode: "path",
162
+ path: resolved,
163
+ message: err instanceof Error ? err.message : String(err),
164
+ };
165
+ }
166
+ },
167
+ }));
168
+ }
169
+ /** Register the tool into one agent's scoped world (call from setup). */
170
+ export function registerSendFileTool(agentCtx, deps) {
171
+ registerLookAtImageTool(agentCtx, deps);
172
+ registerMemoryTool(agentCtx);
173
+ registerSendTextTool(agentCtx, deps);
174
+ registerWechatAskTool(agentCtx, deps);
175
+ agentCtx.tools.register(defineTool({
176
+ name: "send_wechat_file",
177
+ description: "Send a local file (image, PDF, document, spreadsheet, archive, ...) from this computer to the user's WeChat conversation. " +
178
+ "Use this when the user asks you to send them a file or image, or when you produced/edited a file they want delivered. " +
179
+ "This is the ONLY supported way to deliver files over WeChat: never write your own scripts, never read or import plugin source, and never call the WeChat/iLink API directly. " +
180
+ "The file must exist on this computer; the user receives it in the WeChat ClawBot chat. " +
181
+ "BEFORE sending any IMAGE you have not already inspected in this turn, you MUST check it first: call look_at_image on it and confirm from the returned picture that it is the right one and framed sensibly. " +
182
+ "Do not skip this — the user asked for it explicitly, and sending the wrong photo is worse than sending nothing. " +
183
+ "Large images are downscaled automatically before upload (the WeChat CDN rejects full-resolution camera files); pass original: true only when the user explicitly asks for the untouched original. " +
184
+ "Uploading a large non-image file can still take 1-2 minutes — that is normal, do not retry. " +
185
+ "Returns whether the delivery succeeded.",
186
+ parameters: {
187
+ path: {
188
+ type: "string",
189
+ required: true,
190
+ description: "Path of the file to send: absolute, or relative to the working directory.",
191
+ },
192
+ caption: {
193
+ type: "string",
194
+ description: "Optional short text caption delivered together with the file.",
195
+ },
196
+ original: {
197
+ type: "boolean",
198
+ description: "Send the file byte-for-byte with no downscaling. Only for an explicit request for the original — a full-resolution photo will usually be rejected by the WeChat CDN.",
199
+ },
200
+ },
201
+ output: {
202
+ schema: {
203
+ type: "object",
204
+ additionalProperties: false,
205
+ properties: {
206
+ ok: { type: "boolean", required: true },
207
+ message: { type: "string", required: true },
208
+ },
209
+ },
210
+ render: (_args, value) => [
211
+ {
212
+ type: "text",
213
+ text: value.ok
214
+ ? `✅ 文件已发送到微信: ${value.message}`
215
+ : `❌ 发送失败: ${value.message}`,
216
+ },
217
+ ],
218
+ },
219
+ async execute(args) {
220
+ const { path: rawPath, caption, original } = args;
221
+ const bridge = deps.getBridge();
222
+ if (!bridge) {
223
+ return { ok: false, message: "微信桥接未运行(监控未启动)" };
224
+ }
225
+ const account = deps.getAccount();
226
+ if (!account?.configured) {
227
+ return { ok: false, message: "没有已绑定的微信账号" };
228
+ }
229
+ const sender = bridge.activeSender ?? account.userId;
230
+ if (!sender) {
231
+ return { ok: false, message: "无法确定收件人(没有活跃的微信会话)" };
232
+ }
233
+ const resolved = path.isAbsolute(rawPath)
234
+ ? path.normalize(rawPath)
235
+ : path.resolve(deps.config.cwd ?? process.cwd(), rawPath);
236
+ let stat;
237
+ try {
238
+ stat = fs.statSync(resolved);
239
+ }
240
+ catch {
241
+ return { ok: false, message: `文件不存在: ${resolved}` };
242
+ }
243
+ if (!stat.isFile()) {
244
+ return { ok: false, message: `不是普通文件: ${resolved}` };
245
+ }
246
+ logger.info(`send_wechat_file: sending ${resolved} (${stat.size} bytes) to ${sender}`);
247
+ // Originals were sent verbatim here until full-resolution camera files
248
+ // (5568x3712, 5-12MB) started making the C2C CDN answer HTTP 500 —
249
+ // opaque, and each failure burned the whole retry ladder, so one photo
250
+ // hung for ~4 minutes and then failed. Downscale first unless the
251
+ // caller explicitly asked for the untouched file.
252
+ const prep = original === true
253
+ ? { path: resolved, bytes: stat.size, temp: false, note: undefined }
254
+ : compressForUpload(resolved, {
255
+ maxImageEdge: deps.config.maxImageEdge,
256
+ imageQuality: deps.config.imageQuality,
257
+ compressThresholdBytes: deps.config.compressThresholdBytes,
258
+ });
259
+ // Announce the upload only when it is actually going to make the user
260
+ // wait. A downscaled photo is a few hundred KB and lands within a
261
+ // second or two, so a "正在发送…" line arriving just ahead of the image
262
+ // reads as a duplicate of the image itself — the typing indicator below
263
+ // already covers that case. Big files (untouched originals, PDFs,
264
+ // archives, video) can take a minute, and there the notice is the only
265
+ // thing telling the user to wait.
266
+ if (prep.bytes >= deps.config.noticeMinBytes) {
267
+ const sizeMb = (prep.bytes / (1024 * 1024)).toFixed(1);
268
+ const label = prep.note !== undefined
269
+ ? `正在发送 \`${path.basename(resolved)}\`(已压缩 ${prep.note}),可能需要一会儿…`
270
+ : `正在发送 \`${path.basename(resolved)}\`(${sizeMb} MB),大文件可能需要一会儿…`;
271
+ bridge.sendTextTo(sender, label);
272
+ }
273
+ // Show a "typing" indicator while the upload runs (best effort).
274
+ let typingTicket;
275
+ try {
276
+ const cfg = await getConfig({
277
+ baseUrl: account.baseUrl,
278
+ token: account.token,
279
+ ilinkUserId: sender,
280
+ timeoutMs: 10_000,
281
+ });
282
+ typingTicket = cfg.typing_ticket;
283
+ if (typingTicket) {
284
+ await sendTyping({
285
+ baseUrl: account.baseUrl,
286
+ token: account.token,
287
+ body: {
288
+ ilink_user_id: sender,
289
+ typing_ticket: typingTicket,
290
+ status: TypingStatus.TYPING,
291
+ },
292
+ timeoutMs: 10_000,
293
+ });
294
+ }
295
+ }
296
+ catch (err) {
297
+ logger.debug(`send_wechat_file: typing indicator failed (non-fatal): ${String(err)}`);
298
+ }
299
+ try {
300
+ await sendWeixinMediaFile({
301
+ filePath: prep.path,
302
+ to: sender,
303
+ text: deps.config.stripEmoji ? stripEmoji(caption ?? "") : stripWechatCodes(caption ?? ""),
304
+ opts: {
305
+ baseUrl: account.baseUrl,
306
+ token: account.token,
307
+ contextToken: bridge.contextTokenFor(sender),
308
+ timeoutMs: 30_000,
309
+ },
310
+ cdnBaseUrl: account.cdnBaseUrl,
311
+ });
312
+ }
313
+ catch (err) {
314
+ logger.error(`send_wechat_file: failed ${resolved}: ${String(err)}`);
315
+ return {
316
+ ok: false,
317
+ message: `发送失败: ${err instanceof Error ? err.message : String(err)}`,
318
+ };
319
+ }
320
+ finally {
321
+ // Drop the downscaled copy; the original on disk is never touched.
322
+ if (prep.temp) {
323
+ try {
324
+ fs.rmSync(prep.path, { force: true });
325
+ }
326
+ catch (err) {
327
+ logger.debug(`send_wechat_file: temp cleanup failed (non-fatal): ${String(err)}`);
328
+ }
329
+ }
330
+ // Cancel the typing indicator (best effort).
331
+ if (typingTicket) {
332
+ try {
333
+ await sendTyping({
334
+ baseUrl: account.baseUrl,
335
+ token: account.token,
336
+ body: {
337
+ ilink_user_id: sender,
338
+ typing_ticket: typingTicket,
339
+ status: TypingStatus.CANCEL,
340
+ },
341
+ timeoutMs: 10_000,
342
+ });
343
+ }
344
+ catch (err) {
345
+ logger.debug(`send_wechat_file: typing cancel failed (non-fatal): ${String(err)}`);
346
+ }
347
+ }
348
+ }
349
+ return { ok: true, message: resolved };
350
+ },
351
+ }));
352
+ }
353
+ /**
354
+ * Register `remember_user_info`: lets the WeChat agent append durable facts
355
+ * about the user into the long-term memory file (~/.dsh/clawbot/memory.md).
356
+ * The memory text is re-injected into the system prompt on every turn, so the
357
+ * agent grows familiar with the user across sessions (Claude-Desktop-style).
358
+ */
359
+ function registerMemoryTool(agentCtx) {
360
+ agentCtx.tools.register(defineTool({
361
+ name: "remember_user_info",
362
+ description: "Append one durable fact about the user into long-term memory (a Markdown file). " +
363
+ "Use this when the user tells you something worth remembering ACROSS conversations: " +
364
+ "personal background, preferences, habits, recurring needs, plans, or reminders for later. " +
365
+ "Do NOT use it for one-off task details, file paths of the moment, or anything the user already knows you will forget harmlessly. " +
366
+ "Keep the content short and self-contained (one sentence). " +
367
+ "The memory is injected into your system prompt every turn, so remembered facts influence future replies.",
368
+ parameters: {
369
+ content: {
370
+ type: "string",
371
+ required: true,
372
+ description: "The fact to remember, one concise sentence, e.g. '用户喜欢手冲咖啡'.",
373
+ },
374
+ section: {
375
+ type: "string",
376
+ description: "Which memory section to append to: 基本档案 / 偏好与习惯 / 重要事实 / 提醒事项. Defaults to 基本档案.",
377
+ },
378
+ },
379
+ output: {
380
+ schema: {
381
+ type: "object",
382
+ additionalProperties: false,
383
+ properties: {
384
+ ok: { type: "boolean", required: true },
385
+ message: { type: "string", required: true },
386
+ },
387
+ },
388
+ render: (_args, value) => [
389
+ {
390
+ type: "text",
391
+ text: value.ok ? `记忆已更新: ${value.message}` : `记忆更新失败: ${value.message}`,
392
+ },
393
+ ],
394
+ },
395
+ async execute(args) {
396
+ const { content, section } = args;
397
+ const changed = appendMemoryEntry(section ?? "基本档案", content ?? "");
398
+ logger.info(`remember_user_info: section=${section ?? "基本档案"} changed=${changed} content=${content ?? ""}`);
399
+ return {
400
+ ok: changed,
401
+ message: changed ? `已记住: ${content}` : "内容已存在或为空,未重复写入",
402
+ };
403
+ },
404
+ }));
405
+ }
406
+ /**
407
+ * Register `send_wechat_text`: the ONLY way the agent can deliver a text
408
+ * message to the user's WeChat. There is NO automatic forwarding of
409
+ * assistant replies — every message the user should see must be sent by an
410
+ * explicit tool call, so the agent fully controls what reaches WeChat
411
+ * (acknowledgments, progress notes, final summaries, reminders, ...).
412
+ */
413
+ function registerSendTextTool(agentCtx, deps) {
414
+ agentCtx.tools.register(defineTool({
415
+ name: "send_wechat_text",
416
+ description: "Send ONE text message to the user's WeChat conversation. This is the ONLY way to deliver text over WeChat: assistant replies are NOT forwarded automatically, so if you do not call this tool the user never sees your message. " +
417
+ "Use it for acknowledgments, short progress notes, final summaries, and timed-reminder deliveries. " +
418
+ "Send ONE message per call; keep each message as short as possible. " +
419
+ "Never write your own scripts or call the WeChat/iLink API directly.",
420
+ parameters: {
421
+ text: {
422
+ type: "string",
423
+ required: true,
424
+ description: "The exact text to send to WeChat (plain text, no emojis; may use WeChat native emoji codes like [捂脸]).",
425
+ },
426
+ },
427
+ output: {
428
+ schema: {
429
+ type: "object",
430
+ additionalProperties: false,
431
+ properties: {
432
+ ok: { type: "boolean", required: true },
433
+ message: { type: "string", required: true },
434
+ },
435
+ },
436
+ render: (_args, value) => [
437
+ {
438
+ type: "text",
439
+ text: value.ok ? `微信消息已发送: ${value.message}` : `微信消息发送失败: ${value.message}`,
440
+ },
441
+ ],
442
+ },
443
+ async execute(args) {
444
+ const { text } = args;
445
+ const content = (text ?? "").trim();
446
+ if (!content) {
447
+ return { ok: false, message: "消息内容为空" };
448
+ }
449
+ const bridge = deps.getBridge();
450
+ if (!bridge) {
451
+ return { ok: false, message: "微信桥接未运行(监控未启动)" };
452
+ }
453
+ const account = deps.getAccount();
454
+ if (!account?.configured) {
455
+ return { ok: false, message: "没有已绑定的微信账号" };
456
+ }
457
+ const sender = bridge.activeSender ?? account.userId;
458
+ if (!sender) {
459
+ return { ok: false, message: "无法确定收件人(没有活跃的微信会话)" };
460
+ }
461
+ const finalText = deps.config.stripEmoji ? stripEmoji(content) : stripWechatCodes(content);
462
+ bridge.sendTextTo(sender, finalText);
463
+ logger.info(`send_wechat_text: to=${sender} chars=${finalText.length}`);
464
+ return { ok: true, message: content };
465
+ },
466
+ }));
467
+ }
468
+ /**
469
+ * Register a WeChat-scoped override of `ask_user_question`: the global tool
470
+ * routes questions to the webapp GUI provider, but WeChat users are not at
471
+ * the webapp — so on the WeChat agent this tool sends the question through
472
+ * WeChat and waits for the reply (5 min timeout).
473
+ */
474
+ function registerWechatAskTool(agentCtx, deps) {
475
+ agentCtx.tools.register(defineTool({
476
+ name: "ask_user_question",
477
+ description: "Ask the user a question and wait for their answer. The question is delivered to the user's WeChat; returns their reply text (or null on timeout). " +
478
+ "Use when you need a choice/confirmation before continuing.",
479
+ parameters: {
480
+ question: {
481
+ type: "string",
482
+ required: true,
483
+ description: "The question to ask the user, in their language.",
484
+ },
485
+ },
486
+ output: {
487
+ schema: {
488
+ type: "object",
489
+ additionalProperties: false,
490
+ properties: {
491
+ ok: { type: "boolean", required: true },
492
+ answer: { type: "string" },
493
+ message: { type: "string", required: true },
494
+ },
495
+ },
496
+ render: (_args, value) => [
497
+ {
498
+ type: "text",
499
+ text: value.ok ? `用户回答: ${value.answer ?? "(无)"}` : `提问失败: ${value.message}`,
500
+ },
501
+ ],
502
+ },
503
+ async execute(args) {
504
+ const { question } = args;
505
+ const q = (question ?? "").trim();
506
+ if (!q)
507
+ return { ok: false, message: "问题为空" };
508
+ const bridge = deps.getBridge();
509
+ if (!bridge)
510
+ return { ok: false, message: "微信桥接未运行(监控未启动)" };
511
+ const answer = await bridge.askWechat(q);
512
+ return answer !== null
513
+ ? { ok: true, answer, message: "已收到回答" }
514
+ : { ok: false, message: "等待回答超时或中断" };
515
+ },
516
+ }));
517
+ }
518
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAUhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,uBAAuB,CAAC,QAAiB,EAAE,IAAsB;IACxE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CACrB,UAAU,CAAC;QACT,IAAI,EAAE,eAAe;QACrB,WAAW,EACT,iKAAiK;YACjK,2GAA2G;YAC3G,4IAA4I;QAC9I,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,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;oBAC1B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;iBAC5C;aACF;YACD,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;gBACxB;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,EAAE;iBAC7E;aACF;SACF;QACD,KAAK,CAAC,OAAO,CAAC,IAAI;YAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAA6B,CAAC;YACnD,MAAM,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,CAAC;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;YAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;YAC7D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACzC,OAAO,MAAM,KAAK,IAAI;gBACpB,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;gBACxC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "wechat-clawbot",
3
+ "version": "0.9.1",
4
+ "description": "Connect DeepSeek Harness to WeChat via the official WeChat ClawBot (Tencent iLink) bridge — a DSH plugin bundle.",
5
+ "keywords": [
6
+ "deepseek-harness",
7
+ "dsh",
8
+ "plugin",
9
+ "wechat",
10
+ "weixin",
11
+ "clawbot",
12
+ "openclaw"
13
+ ],
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "main": "lib/index.js",
17
+ "types": "lib/types/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./lib/types/index.d.ts",
21
+ "default": "./lib/index.js"
22
+ },
23
+ "./cli": {
24
+ "types": "./lib/types/cli.d.ts",
25
+ "default": "./lib/cli.js"
26
+ },
27
+ "./cordis.patch.yml": "./cordis.patch.yml",
28
+ "./package.json": "./package.json",
29
+ "./client": "./lib/client.js"
30
+ },
31
+ "bin": {
32
+ "clawbot": "lib/cli.js"
33
+ },
34
+ "files": [
35
+ "lib",
36
+ "cordis.patch.yml",
37
+ "README.md",
38
+ "README.zh.md",
39
+ "LICENSE",
40
+ "NOTICE"
41
+ ],
42
+ "engines": {
43
+ "node": ">=22"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json && cp -f src/client.js lib/client.js",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "clean": "rm -rf lib",
49
+ "test:memory": "npm run build && node test/memory-eval-run.mjs"
50
+ },
51
+ "dsh": {
52
+ "bundle": {
53
+ "patch": "./cordis.patch.yml"
54
+ },
55
+ "client": {
56
+ "platform": "web",
57
+ "inject": [
58
+ "slots",
59
+ "settingsScope"
60
+ ]
61
+ }
62
+ },
63
+ "ilink_appid": "bot",
64
+ "dependencies": {
65
+ "qrcode-terminal": "^0.12.0"
66
+ },
67
+ "peerDependencies": {
68
+ "@deepseek-ai/cordis": "^4.0.1",
69
+ "@deepseek-ai/dsh-agent": "^0.1.0-rc.6",
70
+ "@deepseek-ai/dsh-agent-presets": "^0.1.0-rc.6",
71
+ "@deepseek-ai/dsh-attachment": "^0.1.0-rc.5",
72
+ "@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
73
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.6",
74
+ "@deepseek-ai/dsh-settings": "^0.1.0-rc.6",
75
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
76
+ "@deepseek-ai/dsh-user-approval": "^0.1.0-rc.6",
77
+ "@deepseek-ai/dsh-user-questions": "^0.1.0-rc.6",
78
+ "@deepseek-ai/schemastery": "^3.18.0"
79
+ },
80
+ "devDependencies": {
81
+ "@deepseek-ai/cordis": "^4.0.1",
82
+ "@deepseek-ai/dsh-agent": "^0.1.0-rc.6",
83
+ "@deepseek-ai/dsh-agent-presets": "^0.1.0-rc.6",
84
+ "@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
85
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.6",
86
+ "@deepseek-ai/dsh-settings": "^0.1.0-rc.6",
87
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
88
+ "@deepseek-ai/dsh-user-approval": "^0.1.0-rc.6",
89
+ "@deepseek-ai/dsh-user-questions": "^0.1.0-rc.6",
90
+ "@deepseek-ai/schemastery": "^3.18.0",
91
+ "@types/node": "^24.0.0",
92
+ "typescript": "^5.8.0"
93
+ }
94
+ }