wechat-to-anything 0.5.0
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/README.md +144 -0
- package/bin/cli.mjs +120 -0
- package/cli/agent-adapter.mjs +250 -0
- package/cli/bridge.mjs +330 -0
- package/cli/cdn.mjs +144 -0
- package/cli/weixin.mjs +343 -0
- package/docs/wechat-image-receive.png +0 -0
- package/docs/wechat-image-send.png +0 -0
- package/docs/wechat-voice-demo.gif +0 -0
- package/docs/wechat-voice-demo.mp4 +0 -0
- package/examples/claude-code/README.md +19 -0
- package/examples/claude-code/package-lock.json +340 -0
- package/examples/claude-code/package.json +11 -0
- package/examples/claude-code/server.mjs +98 -0
- package/examples/gemini/README.md +32 -0
- package/examples/gemini/server.mjs +98 -0
- package/examples/openai/README.md +35 -0
- package/examples/openai/server.mjs +119 -0
- package/package.json +39 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-code-agent-example",
|
|
3
|
+
"lockfileVersion": 3,
|
|
4
|
+
"requires": true,
|
|
5
|
+
"packages": {
|
|
6
|
+
"": {
|
|
7
|
+
"name": "claude-code-agent-example",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@anthropic-ai/claude-code": "latest"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"node_modules/@anthropic-ai/claude-code": {
|
|
13
|
+
"version": "2.1.81",
|
|
14
|
+
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-2.1.81.tgz",
|
|
15
|
+
"integrity": "sha512-CyQmbrsCccqx7kNgg7/4+L9GcUG6VaTZYtB51zPHy85z1VvbPrnRP+jFP4seyR9L/c3XHSDU1LVHzKKyd1IcGQ==",
|
|
16
|
+
"license": "SEE LICENSE IN README.md",
|
|
17
|
+
"bin": {
|
|
18
|
+
"claude": "cli.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18.0.0"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@img/sharp-darwin-arm64": "^0.34.2",
|
|
25
|
+
"@img/sharp-darwin-x64": "^0.34.2",
|
|
26
|
+
"@img/sharp-linux-arm": "^0.34.2",
|
|
27
|
+
"@img/sharp-linux-arm64": "^0.34.2",
|
|
28
|
+
"@img/sharp-linux-x64": "^0.34.2",
|
|
29
|
+
"@img/sharp-linuxmusl-arm64": "^0.34.2",
|
|
30
|
+
"@img/sharp-linuxmusl-x64": "^0.34.2",
|
|
31
|
+
"@img/sharp-win32-arm64": "^0.34.2",
|
|
32
|
+
"@img/sharp-win32-x64": "^0.34.2"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"node_modules/@img/sharp-darwin-arm64": {
|
|
36
|
+
"version": "0.34.5",
|
|
37
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.5.tgz",
|
|
38
|
+
"integrity": "sha512-imtQ3WMJXbMY4fxb/Ndp6HBTNVtWCUI0WdobyheGf5+ad6xX8VIDO8u2xE4qc/fr08CKG/7dDseFtn6M6g/r3w==",
|
|
39
|
+
"cpu": [
|
|
40
|
+
"arm64"
|
|
41
|
+
],
|
|
42
|
+
"license": "Apache-2.0",
|
|
43
|
+
"optional": true,
|
|
44
|
+
"os": [
|
|
45
|
+
"darwin"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
49
|
+
},
|
|
50
|
+
"funding": {
|
|
51
|
+
"url": "https://opencollective.com/libvips"
|
|
52
|
+
},
|
|
53
|
+
"optionalDependencies": {
|
|
54
|
+
"@img/sharp-libvips-darwin-arm64": "1.2.4"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"node_modules/@img/sharp-darwin-x64": {
|
|
58
|
+
"version": "0.34.5",
|
|
59
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.5.tgz",
|
|
60
|
+
"integrity": "sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==",
|
|
61
|
+
"cpu": [
|
|
62
|
+
"x64"
|
|
63
|
+
],
|
|
64
|
+
"license": "Apache-2.0",
|
|
65
|
+
"optional": true,
|
|
66
|
+
"os": [
|
|
67
|
+
"darwin"
|
|
68
|
+
],
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
71
|
+
},
|
|
72
|
+
"funding": {
|
|
73
|
+
"url": "https://opencollective.com/libvips"
|
|
74
|
+
},
|
|
75
|
+
"optionalDependencies": {
|
|
76
|
+
"@img/sharp-libvips-darwin-x64": "1.2.4"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"node_modules/@img/sharp-libvips-darwin-arm64": {
|
|
80
|
+
"version": "1.2.4",
|
|
81
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.2.4.tgz",
|
|
82
|
+
"integrity": "sha512-zqjjo7RatFfFoP0MkQ51jfuFZBnVE2pRiaydKJ1G/rHZvnsrHAOcQALIi9sA5co5xenQdTugCvtb1cuf78Vf4g==",
|
|
83
|
+
"cpu": [
|
|
84
|
+
"arm64"
|
|
85
|
+
],
|
|
86
|
+
"license": "LGPL-3.0-or-later",
|
|
87
|
+
"optional": true,
|
|
88
|
+
"os": [
|
|
89
|
+
"darwin"
|
|
90
|
+
],
|
|
91
|
+
"funding": {
|
|
92
|
+
"url": "https://opencollective.com/libvips"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"node_modules/@img/sharp-libvips-darwin-x64": {
|
|
96
|
+
"version": "1.2.4",
|
|
97
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.4.tgz",
|
|
98
|
+
"integrity": "sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==",
|
|
99
|
+
"cpu": [
|
|
100
|
+
"x64"
|
|
101
|
+
],
|
|
102
|
+
"license": "LGPL-3.0-or-later",
|
|
103
|
+
"optional": true,
|
|
104
|
+
"os": [
|
|
105
|
+
"darwin"
|
|
106
|
+
],
|
|
107
|
+
"funding": {
|
|
108
|
+
"url": "https://opencollective.com/libvips"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"node_modules/@img/sharp-libvips-linux-arm": {
|
|
112
|
+
"version": "1.2.4",
|
|
113
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.2.4.tgz",
|
|
114
|
+
"integrity": "sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==",
|
|
115
|
+
"cpu": [
|
|
116
|
+
"arm"
|
|
117
|
+
],
|
|
118
|
+
"license": "LGPL-3.0-or-later",
|
|
119
|
+
"optional": true,
|
|
120
|
+
"os": [
|
|
121
|
+
"linux"
|
|
122
|
+
],
|
|
123
|
+
"funding": {
|
|
124
|
+
"url": "https://opencollective.com/libvips"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"node_modules/@img/sharp-libvips-linux-arm64": {
|
|
128
|
+
"version": "1.2.4",
|
|
129
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.2.4.tgz",
|
|
130
|
+
"integrity": "sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==",
|
|
131
|
+
"cpu": [
|
|
132
|
+
"arm64"
|
|
133
|
+
],
|
|
134
|
+
"license": "LGPL-3.0-or-later",
|
|
135
|
+
"optional": true,
|
|
136
|
+
"os": [
|
|
137
|
+
"linux"
|
|
138
|
+
],
|
|
139
|
+
"funding": {
|
|
140
|
+
"url": "https://opencollective.com/libvips"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"node_modules/@img/sharp-libvips-linux-x64": {
|
|
144
|
+
"version": "1.2.4",
|
|
145
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.2.4.tgz",
|
|
146
|
+
"integrity": "sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==",
|
|
147
|
+
"cpu": [
|
|
148
|
+
"x64"
|
|
149
|
+
],
|
|
150
|
+
"license": "LGPL-3.0-or-later",
|
|
151
|
+
"optional": true,
|
|
152
|
+
"os": [
|
|
153
|
+
"linux"
|
|
154
|
+
],
|
|
155
|
+
"funding": {
|
|
156
|
+
"url": "https://opencollective.com/libvips"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"node_modules/@img/sharp-libvips-linuxmusl-arm64": {
|
|
160
|
+
"version": "1.2.4",
|
|
161
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.2.4.tgz",
|
|
162
|
+
"integrity": "sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==",
|
|
163
|
+
"cpu": [
|
|
164
|
+
"arm64"
|
|
165
|
+
],
|
|
166
|
+
"license": "LGPL-3.0-or-later",
|
|
167
|
+
"optional": true,
|
|
168
|
+
"os": [
|
|
169
|
+
"linux"
|
|
170
|
+
],
|
|
171
|
+
"funding": {
|
|
172
|
+
"url": "https://opencollective.com/libvips"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"node_modules/@img/sharp-libvips-linuxmusl-x64": {
|
|
176
|
+
"version": "1.2.4",
|
|
177
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.2.4.tgz",
|
|
178
|
+
"integrity": "sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==",
|
|
179
|
+
"cpu": [
|
|
180
|
+
"x64"
|
|
181
|
+
],
|
|
182
|
+
"license": "LGPL-3.0-or-later",
|
|
183
|
+
"optional": true,
|
|
184
|
+
"os": [
|
|
185
|
+
"linux"
|
|
186
|
+
],
|
|
187
|
+
"funding": {
|
|
188
|
+
"url": "https://opencollective.com/libvips"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"node_modules/@img/sharp-linux-arm": {
|
|
192
|
+
"version": "0.34.5",
|
|
193
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.5.tgz",
|
|
194
|
+
"integrity": "sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==",
|
|
195
|
+
"cpu": [
|
|
196
|
+
"arm"
|
|
197
|
+
],
|
|
198
|
+
"license": "Apache-2.0",
|
|
199
|
+
"optional": true,
|
|
200
|
+
"os": [
|
|
201
|
+
"linux"
|
|
202
|
+
],
|
|
203
|
+
"engines": {
|
|
204
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
205
|
+
},
|
|
206
|
+
"funding": {
|
|
207
|
+
"url": "https://opencollective.com/libvips"
|
|
208
|
+
},
|
|
209
|
+
"optionalDependencies": {
|
|
210
|
+
"@img/sharp-libvips-linux-arm": "1.2.4"
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
"node_modules/@img/sharp-linux-arm64": {
|
|
214
|
+
"version": "0.34.5",
|
|
215
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.5.tgz",
|
|
216
|
+
"integrity": "sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==",
|
|
217
|
+
"cpu": [
|
|
218
|
+
"arm64"
|
|
219
|
+
],
|
|
220
|
+
"license": "Apache-2.0",
|
|
221
|
+
"optional": true,
|
|
222
|
+
"os": [
|
|
223
|
+
"linux"
|
|
224
|
+
],
|
|
225
|
+
"engines": {
|
|
226
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
227
|
+
},
|
|
228
|
+
"funding": {
|
|
229
|
+
"url": "https://opencollective.com/libvips"
|
|
230
|
+
},
|
|
231
|
+
"optionalDependencies": {
|
|
232
|
+
"@img/sharp-libvips-linux-arm64": "1.2.4"
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
"node_modules/@img/sharp-linux-x64": {
|
|
236
|
+
"version": "0.34.5",
|
|
237
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.5.tgz",
|
|
238
|
+
"integrity": "sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==",
|
|
239
|
+
"cpu": [
|
|
240
|
+
"x64"
|
|
241
|
+
],
|
|
242
|
+
"license": "Apache-2.0",
|
|
243
|
+
"optional": true,
|
|
244
|
+
"os": [
|
|
245
|
+
"linux"
|
|
246
|
+
],
|
|
247
|
+
"engines": {
|
|
248
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
249
|
+
},
|
|
250
|
+
"funding": {
|
|
251
|
+
"url": "https://opencollective.com/libvips"
|
|
252
|
+
},
|
|
253
|
+
"optionalDependencies": {
|
|
254
|
+
"@img/sharp-libvips-linux-x64": "1.2.4"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
"node_modules/@img/sharp-linuxmusl-arm64": {
|
|
258
|
+
"version": "0.34.5",
|
|
259
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.5.tgz",
|
|
260
|
+
"integrity": "sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==",
|
|
261
|
+
"cpu": [
|
|
262
|
+
"arm64"
|
|
263
|
+
],
|
|
264
|
+
"license": "Apache-2.0",
|
|
265
|
+
"optional": true,
|
|
266
|
+
"os": [
|
|
267
|
+
"linux"
|
|
268
|
+
],
|
|
269
|
+
"engines": {
|
|
270
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
271
|
+
},
|
|
272
|
+
"funding": {
|
|
273
|
+
"url": "https://opencollective.com/libvips"
|
|
274
|
+
},
|
|
275
|
+
"optionalDependencies": {
|
|
276
|
+
"@img/sharp-libvips-linuxmusl-arm64": "1.2.4"
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
"node_modules/@img/sharp-linuxmusl-x64": {
|
|
280
|
+
"version": "0.34.5",
|
|
281
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.5.tgz",
|
|
282
|
+
"integrity": "sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==",
|
|
283
|
+
"cpu": [
|
|
284
|
+
"x64"
|
|
285
|
+
],
|
|
286
|
+
"license": "Apache-2.0",
|
|
287
|
+
"optional": true,
|
|
288
|
+
"os": [
|
|
289
|
+
"linux"
|
|
290
|
+
],
|
|
291
|
+
"engines": {
|
|
292
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
293
|
+
},
|
|
294
|
+
"funding": {
|
|
295
|
+
"url": "https://opencollective.com/libvips"
|
|
296
|
+
},
|
|
297
|
+
"optionalDependencies": {
|
|
298
|
+
"@img/sharp-libvips-linuxmusl-x64": "1.2.4"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
"node_modules/@img/sharp-win32-arm64": {
|
|
302
|
+
"version": "0.34.5",
|
|
303
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.5.tgz",
|
|
304
|
+
"integrity": "sha512-WQ3AgWCWYSb2yt+IG8mnC6Jdk9Whs7O0gxphblsLvdhSpSTtmu69ZG1Gkb6NuvxsNACwiPV6cNSZNzt0KPsw7g==",
|
|
305
|
+
"cpu": [
|
|
306
|
+
"arm64"
|
|
307
|
+
],
|
|
308
|
+
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
|
309
|
+
"optional": true,
|
|
310
|
+
"os": [
|
|
311
|
+
"win32"
|
|
312
|
+
],
|
|
313
|
+
"engines": {
|
|
314
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
315
|
+
},
|
|
316
|
+
"funding": {
|
|
317
|
+
"url": "https://opencollective.com/libvips"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
"node_modules/@img/sharp-win32-x64": {
|
|
321
|
+
"version": "0.34.5",
|
|
322
|
+
"resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.5.tgz",
|
|
323
|
+
"integrity": "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw==",
|
|
324
|
+
"cpu": [
|
|
325
|
+
"x64"
|
|
326
|
+
],
|
|
327
|
+
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
|
328
|
+
"optional": true,
|
|
329
|
+
"os": [
|
|
330
|
+
"win32"
|
|
331
|
+
],
|
|
332
|
+
"engines": {
|
|
333
|
+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
334
|
+
},
|
|
335
|
+
"funding": {
|
|
336
|
+
"url": "https://opencollective.com/libvips"
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code → OpenAI 兼容 HTTP 服务
|
|
3
|
+
*
|
|
4
|
+
* 通过 `claude --print` 子进程调用 Claude Code,
|
|
5
|
+
* 包装成标准 HTTP 接口供 wechat-to-anything 连接。
|
|
6
|
+
*
|
|
7
|
+
* 前置条件:
|
|
8
|
+
* npm install (安装 @anthropic-ai/claude-code)
|
|
9
|
+
* 设置环境变量 ANTHROPIC_API_KEY
|
|
10
|
+
*
|
|
11
|
+
* 用法:
|
|
12
|
+
* ANTHROPIC_API_KEY=sk-ant-xxx node server.mjs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createServer } from "node:http";
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
import { resolve, dirname } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
|
|
20
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const CLAUDE_BIN = resolve(__dirname, "node_modules/.bin/claude");
|
|
22
|
+
const PORT = process.env.PORT || 3000;
|
|
23
|
+
|
|
24
|
+
const server = createServer(async (req, res) => {
|
|
25
|
+
if (req.method !== "POST" || !req.url.startsWith("/v1/chat/completions")) {
|
|
26
|
+
res.writeHead(404);
|
|
27
|
+
res.end("Not Found");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const body = await readBody(req);
|
|
32
|
+
const { messages } = JSON.parse(body);
|
|
33
|
+
const userMessage =
|
|
34
|
+
messages?.findLast((m) => m.role === "user")?.content || "";
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const result = await runClaude(userMessage);
|
|
38
|
+
|
|
39
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
40
|
+
res.end(
|
|
41
|
+
JSON.stringify({
|
|
42
|
+
choices: [
|
|
43
|
+
{
|
|
44
|
+
message: { role: "assistant", content: result },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
51
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
server.listen(PORT, () => {
|
|
56
|
+
console.log(`🧬 Claude Code Agent 运行在 http://localhost:${PORT}/v1`);
|
|
57
|
+
console.log(
|
|
58
|
+
` 然后运行: npx wechat-to-anything http://localhost:${PORT}/v1`
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 通过 claude --print 子进程执行,stdin 关闭避免等待
|
|
64
|
+
*/
|
|
65
|
+
function runClaude(prompt) {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const child = spawn(CLAUDE_BIN, ["--print", prompt], {
|
|
68
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
69
|
+
timeout: 120_000,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
let stdout = "";
|
|
73
|
+
let stderr = "";
|
|
74
|
+
|
|
75
|
+
child.stdout.on("data", (d) => (stdout += d));
|
|
76
|
+
child.stderr.on("data", (d) => (stderr += d));
|
|
77
|
+
|
|
78
|
+
child.on("close", (code) => {
|
|
79
|
+
if (code !== 0) {
|
|
80
|
+
// Claude 可能把错误写到 stdout 或 stderr,合并捕获
|
|
81
|
+
const errMsg = (stderr + stdout).trim() || `exit code ${code}`;
|
|
82
|
+
reject(new Error(errMsg));
|
|
83
|
+
} else {
|
|
84
|
+
resolve(stdout.trim());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
child.on("error", (err) => reject(err));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function readBody(req) {
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
let data = "";
|
|
95
|
+
req.on("data", (chunk) => (data += chunk));
|
|
96
|
+
req.on("end", () => resolve(data));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Gemini CLI Agent
|
|
2
|
+
|
|
3
|
+
通过 Google Gemini CLI 将 Gemini 模型接入微信。
|
|
4
|
+
|
|
5
|
+
## 前置条件
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @google/gemini-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
首次使用会引导 Google 账号登录(免费额度)。
|
|
12
|
+
|
|
13
|
+
## 启动
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# 1. 启动 Agent
|
|
17
|
+
node server.mjs
|
|
18
|
+
|
|
19
|
+
# 2. 连接微信(另一个终端)
|
|
20
|
+
npx wechat-to-anything http://localhost:3002/v1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 多 Agent 模式
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx wechat-to-anything \
|
|
27
|
+
--agent codex=http://localhost:3001/v1 \
|
|
28
|
+
--agent gemini=http://localhost:3002/v1 \
|
|
29
|
+
--default codex
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
微信里发 `@gemini 你好` 路由到 Gemini。
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini CLI Agent — 通过 gemini CLI 调用
|
|
3
|
+
*
|
|
4
|
+
* 前置:npm install -g @google/gemini-cli
|
|
5
|
+
* 用法:node server.mjs
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createServer } from "node:http";
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { writeFile, unlink, mkdir } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { randomBytes } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
const PORT = 3002;
|
|
16
|
+
const TMP_DIR = join(tmpdir(), "wechat-gemini");
|
|
17
|
+
|
|
18
|
+
function runGemini(prompt) {
|
|
19
|
+
return new Promise(async (resolve, reject) => {
|
|
20
|
+
await mkdir(TMP_DIR, { recursive: true });
|
|
21
|
+
|
|
22
|
+
const child = spawn("gemini", [], {
|
|
23
|
+
cwd: tmpdir(),
|
|
24
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
25
|
+
timeout: 300_000,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let stdout = "";
|
|
29
|
+
let stderr = "";
|
|
30
|
+
|
|
31
|
+
child.stdout.on("data", (d) => (stdout += d));
|
|
32
|
+
child.stderr.on("data", (d) => (stderr += d));
|
|
33
|
+
|
|
34
|
+
// 发送 prompt 到 stdin 然后关闭
|
|
35
|
+
child.stdin.write(prompt);
|
|
36
|
+
child.stdin.end();
|
|
37
|
+
|
|
38
|
+
child.on("close", (code) => {
|
|
39
|
+
const reply = stdout.trim();
|
|
40
|
+
if (reply) {
|
|
41
|
+
resolve(reply);
|
|
42
|
+
} else if (code !== 0) {
|
|
43
|
+
reject(new Error((stderr || `exit code ${code}`).trim().slice(0, 300)));
|
|
44
|
+
} else {
|
|
45
|
+
resolve("(empty response)");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
child.on("error", (err) => {
|
|
50
|
+
reject(new Error(`gemini CLI 未安装或不可用: ${err.message}`));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const server = createServer(async (req, res) => {
|
|
56
|
+
if (req.method === "POST" && req.url.endsWith("/chat/completions")) {
|
|
57
|
+
let body = "";
|
|
58
|
+
for await (const chunk of req) body += chunk;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const { messages } = JSON.parse(body);
|
|
62
|
+
const lastMsg = messages[messages.length - 1];
|
|
63
|
+
let prompt = "";
|
|
64
|
+
|
|
65
|
+
if (typeof lastMsg.content === "string") {
|
|
66
|
+
prompt = lastMsg.content;
|
|
67
|
+
} else if (Array.isArray(lastMsg.content)) {
|
|
68
|
+
for (const part of lastMsg.content) {
|
|
69
|
+
if (part.type === "text") {
|
|
70
|
+
prompt += (prompt ? "\n" : "") + part.text;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!prompt) { res.writeHead(400); res.end('{"error":"empty"}'); return; }
|
|
76
|
+
|
|
77
|
+
console.log(`← ${prompt.slice(0, 80)}`);
|
|
78
|
+
|
|
79
|
+
const reply = await runGemini(prompt);
|
|
80
|
+
console.log(`→ ${reply.slice(0, 80)}`);
|
|
81
|
+
|
|
82
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
83
|
+
res.end(JSON.stringify({ choices: [{ message: { role: "assistant", content: reply } }] }));
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(`❌ ${err.message.slice(0, 200)}`);
|
|
86
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
87
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
91
|
+
res.end('{"status":"ok","agent":"gemini"}');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
server.listen(PORT, () => {
|
|
96
|
+
console.log(`🤖 Gemini Agent 运行在 http://localhost:${PORT}/v1`);
|
|
97
|
+
console.log(` 通过 Gemini CLI 调用`);
|
|
98
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# OpenAI Codex 示例
|
|
2
|
+
|
|
3
|
+
通过 Codex CLI 调用(账号登录,不需要 API key)。支持图片识别。
|
|
4
|
+
|
|
5
|
+
## 前置
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @openai/codex
|
|
9
|
+
codex login
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 用法
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
node server.mjs
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
然后:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx wechat-to-anything http://localhost:3001/v1
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 功能
|
|
25
|
+
|
|
26
|
+
- **文字对话**:微信发文字 → Codex 回复
|
|
27
|
+
- **图片识别**:微信先发图片,再发问题 → Codex 看图回答(gpt-5.4)
|
|
28
|
+
- **账号登录**:通过 `codex login` 登录,使用 Plus 订阅额度
|
|
29
|
+
|
|
30
|
+
## 技术细节
|
|
31
|
+
|
|
32
|
+
- 使用 `codex exec` 非交互模式
|
|
33
|
+
- 图片通过 `-i <file>` 参数传入
|
|
34
|
+
- 回复通过 `-o <file>` 输出(避免 stdout 被进度信息污染)
|
|
35
|
+
- 加速参数:`--skip-git-repo-check --ephemeral`
|