wechat-to-anything 0.6.7 → 0.6.8
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/cli/agent-adapter.mjs +8 -3
- package/cli/bridge.mjs +3 -4
- package/cli/cdn.mjs +2 -2
- package/package.json +1 -1
package/cli/agent-adapter.mjs
CHANGED
|
@@ -14,6 +14,9 @@ import { join } from "node:path";
|
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { randomBytes } from "node:crypto";
|
|
16
16
|
|
|
17
|
+
// Windows 上 npm 全局安装生成 .cmd,execFile/spawn 需要 shell: true 才能找到
|
|
18
|
+
const IS_WIN = process.platform === "win32";
|
|
19
|
+
|
|
17
20
|
/**
|
|
18
21
|
* 统一调用接口 — 根据 URL 自动选择适配器
|
|
19
22
|
*/
|
|
@@ -37,7 +40,7 @@ export async function checkAgent(url) {
|
|
|
37
40
|
const name = url.replace("cli://", "");
|
|
38
41
|
const cmd = { codex: "codex", gemini: "gemini", claude: "claude", openclaw: "openclaw" }[name] || name;
|
|
39
42
|
return new Promise((resolve, reject) => {
|
|
40
|
-
execFile(cmd, ["--version"], { timeout: 5000 }, (err) => {
|
|
43
|
+
execFile(cmd, ["--version"], { timeout: 5000, shell: IS_WIN }, (err) => {
|
|
41
44
|
if (err) reject(new Error(`${cmd} CLI 未安装(npm install -g ${{
|
|
42
45
|
codex: "@openai/codex", gemini: "@google/gemini-cli", claude: "@anthropic-ai/claude-code", openclaw: "openclaw"
|
|
43
46
|
}[name] || cmd})`));
|
|
@@ -161,7 +164,7 @@ function runCodex(prompt, imagePaths = []) {
|
|
|
161
164
|
for (const img of imagePaths) args.push("-i", img);
|
|
162
165
|
args.push("--", prompt);
|
|
163
166
|
|
|
164
|
-
execFile("codex", args, { timeout: 300_000, maxBuffer: 2 * 1024 * 1024, cwd: tmpdir() },
|
|
167
|
+
execFile("codex", args, { timeout: 300_000, maxBuffer: 2 * 1024 * 1024, cwd: tmpdir(), shell: IS_WIN },
|
|
165
168
|
async (err, stdout, stderr) => {
|
|
166
169
|
try {
|
|
167
170
|
const reply = await readFile(outFile, "utf-8").catch(() => "");
|
|
@@ -177,7 +180,7 @@ function runCodex(prompt, imagePaths = []) {
|
|
|
177
180
|
|
|
178
181
|
function runGemini(prompt) {
|
|
179
182
|
return new Promise((resolve, reject) => {
|
|
180
|
-
const child = spawn("gemini", [], { cwd: tmpdir(), stdio: ["pipe", "pipe", "pipe"], timeout: 300_000 });
|
|
183
|
+
const child = spawn("gemini", [], { cwd: tmpdir(), stdio: ["pipe", "pipe", "pipe"], timeout: 300_000, shell: IS_WIN });
|
|
181
184
|
let stdout = "", stderr = "";
|
|
182
185
|
child.stdout.on("data", (d) => (stdout += d));
|
|
183
186
|
child.stderr.on("data", (d) => (stderr += d));
|
|
@@ -197,6 +200,7 @@ function runClaude(prompt) {
|
|
|
197
200
|
const child = spawn("claude", ["--print", prompt], {
|
|
198
201
|
stdio: ["ignore", "pipe", "pipe"],
|
|
199
202
|
timeout: 300_000,
|
|
203
|
+
shell: IS_WIN,
|
|
200
204
|
});
|
|
201
205
|
let stdout = "", stderr = "";
|
|
202
206
|
child.stdout.on("data", (d) => (stdout += d));
|
|
@@ -218,6 +222,7 @@ function runOpenClaw(prompt) {
|
|
|
218
222
|
cwd: tmpdir(),
|
|
219
223
|
stdio: ["ignore", "pipe", "pipe"],
|
|
220
224
|
timeout: 300_000,
|
|
225
|
+
shell: IS_WIN,
|
|
221
226
|
});
|
|
222
227
|
let stdout = "", stderr = "";
|
|
223
228
|
child.stdout.on("data", (d) => (stdout += d));
|
package/cli/bridge.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
loadCredentials, loginWithQR, getUpdates,
|
|
5
5
|
sendMessage, sendImageByUrl, sendVideoByUrl,
|
|
6
6
|
extractText, extractMedia,
|
|
7
|
-
getConfig, sendTyping,
|
|
7
|
+
getConfig, sendTyping, buildHeaders, BASE_URL,
|
|
8
8
|
} from "./weixin.mjs";
|
|
9
9
|
import { downloadAndDecrypt, downloadMediaToFile, uploadToCdn } from "./cdn.mjs";
|
|
10
10
|
import { callAgentAuto, checkAgent } from "./agent-adapter.mjs";
|
|
@@ -130,8 +130,6 @@ export async function start(agents, defaultAgent, { port = 9099 } = {}) {
|
|
|
130
130
|
try {
|
|
131
131
|
const { execFileSync } = await import("node:child_process");
|
|
132
132
|
const { statSync, writeFileSync } = await import("node:fs");
|
|
133
|
-
const { uploadToCdn } = await import("./cdn.mjs");
|
|
134
|
-
const { buildHeaders, BASE_URL: baseUrl } = await import("./weixin.mjs");
|
|
135
133
|
|
|
136
134
|
let audioFile = audioSrc;
|
|
137
135
|
if (audioSrc.startsWith("http://") || audioSrc.startsWith("https://")) {
|
|
@@ -166,7 +164,7 @@ export async function start(agents, defaultAgent, { port = 9099 } = {}) {
|
|
|
166
164
|
},
|
|
167
165
|
base_info: {},
|
|
168
166
|
});
|
|
169
|
-
await fetch(`${
|
|
167
|
+
await fetch(`${BASE_URL}/ilink/bot/sendmessage`, {
|
|
170
168
|
method: "POST", headers: buildHeaders(creds.token, body), body,
|
|
171
169
|
});
|
|
172
170
|
console.log(pc.green(`→ [语音] 已发送 (${durationMs}ms)`));
|
|
@@ -246,6 +244,7 @@ export async function start(agents, defaultAgent, { port = 9099 } = {}) {
|
|
|
246
244
|
if (bodySize > 1_048_576) { // 1MB limit
|
|
247
245
|
res.writeHead(413, { "Content-Type": "application/json" });
|
|
248
246
|
res.end(JSON.stringify({ error: "body too large (max 1MB)" }));
|
|
247
|
+
req.destroy();
|
|
249
248
|
return;
|
|
250
249
|
}
|
|
251
250
|
body += chunk;
|
package/cli/cdn.mjs
CHANGED
|
@@ -80,7 +80,7 @@ export async function downloadMediaToFile(encryptQueryParam, aesKeyBase64, ext =
|
|
|
80
80
|
*/
|
|
81
81
|
export async function uploadImageWithThumb(filePath, toUserId, token) {
|
|
82
82
|
const { buildHeaders, BASE_URL } = await import("./weixin.mjs");
|
|
83
|
-
const { execFileSync } = await import("child_process");
|
|
83
|
+
const { execFileSync } = await import("node:child_process");
|
|
84
84
|
|
|
85
85
|
const plaintext = await readFile(filePath);
|
|
86
86
|
const rawsize = plaintext.length;
|
|
@@ -183,7 +183,7 @@ export async function uploadImageWithThumb(filePath, toUserId, token) {
|
|
|
183
183
|
*/
|
|
184
184
|
export async function uploadVideoWithThumb(filePath, toUserId, token) {
|
|
185
185
|
const { buildHeaders, BASE_URL } = await import("./weixin.mjs");
|
|
186
|
-
const { execFileSync } = await import("child_process");
|
|
186
|
+
const { execFileSync } = await import("node:child_process");
|
|
187
187
|
|
|
188
188
|
const plaintext = await readFile(filePath);
|
|
189
189
|
const rawsize = plaintext.length;
|