wechat-to-anything 0.5.3 → 0.5.4

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/README.md CHANGED
@@ -141,7 +141,7 @@ def chat(request):
141
141
  return {"choices": [{"message": {"role": "assistant", "content": reply}}]}
142
142
  ```
143
143
 
144
- > 完整语音发送示例见 [examples/voice-test.mjs](examples/voice-test.mjs)
144
+ > 示例:[examples/image-test.mjs](examples/image-test.mjs) · [examples/voice-test.mjs](examples/voice-test.mjs)
145
145
 
146
146
  ## 凭证
147
147
 
package/cli/bridge.mjs CHANGED
@@ -292,8 +292,8 @@ export async function start(agents, defaultAgent) {
292
292
 
293
293
  // 检查回复是否包含 [audio:path/url]
294
294
  const audioMatch = reply.match(/\[audio:(.*?)\]/);
295
- // 检查回复是否包含图片 URL(markdown 格式)
296
- const imageMatch = reply.match(/!\[.*?\]\((https?:\/\/[^\s)]+)\)/);
295
+ // 检查回复是否包含图片(markdown 格式,支持 URL 和 data URI)
296
+ const imageMatch = reply.match(/!\[.*?\]\(((?:https?:\/\/|data:image\/)[^\s)]+)\)/);
297
297
 
298
298
  if (audioMatch) {
299
299
  const audioSrc = audioMatch[1];
package/cli/weixin.mjs CHANGED
@@ -192,10 +192,16 @@ export async function sendMessage(token, to, text, contextToken) {
192
192
  export async function sendImageByUrl(token, to, contextToken, imageUrl) {
193
193
  const { writeFile: wf } = await import("node:fs/promises");
194
194
 
195
- // 下载图片
196
- const resp = await fetch(imageUrl);
197
- if (!resp.ok) throw new Error(`图片下载失败: ${resp.status}`);
198
- const buf = Buffer.from(await resp.arrayBuffer());
195
+ // 获取图片数据
196
+ let buf;
197
+ if (imageUrl.startsWith("data:")) {
198
+ const b64 = imageUrl.split(",")[1];
199
+ buf = Buffer.from(b64, "base64");
200
+ } else {
201
+ const resp = await fetch(imageUrl);
202
+ if (!resp.ok) throw new Error(`图片下载失败: ${resp.status}`);
203
+ buf = Buffer.from(await resp.arrayBuffer());
204
+ }
199
205
  const tmpPath = "/tmp/wxta_image_send.jpg";
200
206
  await wf(tmpPath, buf);
201
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechat-to-anything",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "一条命令,把微信变成任何 AI Agent 的入口",
5
5
  "type": "module",
6
6
  "bin": {