@long_88/openclaw-aicc-channel-cli 0.1.0 → 0.1.2
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 +3 -0
- package/cli.mjs +78 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,9 @@ CLI installer for the `@long_88/openclaw-aicc-channel` plugin.
|
|
|
8
8
|
npx -y @long_88/openclaw-aicc-channel-cli install
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
When the install completes, the CLI also inspects `~/.openclaw/openclaw-weixin/accounts.json`.
|
|
12
|
+
If exactly one Weixin account is available, it prints that `weixinFanoutAccountId` and the matching `weixinFanoutTo` from `~/.openclaw/openclaw-weixin/accounts/<id>.json`, then waits for you to press Enter before the process exits. If multiple accounts are detected, the CLI exits with an error so you can resolve the ambiguity first.
|
|
13
|
+
|
|
11
14
|
Configure a bridge account while installing:
|
|
12
15
|
|
|
13
16
|
```bash
|
package/cli.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { createInterface } from "node:readline/promises";
|
|
4
8
|
|
|
5
9
|
const CLI_SPEC = "@long_88/openclaw-aicc-channel-cli";
|
|
6
10
|
const PLUGIN_SPEC = "@long_88/openclaw-aicc-channel";
|
|
@@ -185,7 +189,77 @@ function runCommand(args) {
|
|
|
185
189
|
return result;
|
|
186
190
|
}
|
|
187
191
|
|
|
188
|
-
function
|
|
192
|
+
function readJsonFile(filePath) {
|
|
193
|
+
return JSON.parse(readFileSync(filePath, "utf8"));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function waitForEnter() {
|
|
197
|
+
const rl = createInterface({
|
|
198
|
+
input: process.stdin,
|
|
199
|
+
output: process.stdout
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
await rl.question("[aicc-channel] Press Enter to continue");
|
|
204
|
+
} finally {
|
|
205
|
+
rl.close();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
process.stdout.write("\n");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function logWeixinAccounts() {
|
|
212
|
+
const weixinDir = join(homedir(), ".openclaw", "openclaw-weixin");
|
|
213
|
+
const accountsPath = join(weixinDir, "accounts.json");
|
|
214
|
+
|
|
215
|
+
if (!existsSync(accountsPath)) {
|
|
216
|
+
log(`weixin accounts file was not found: ${accountsPath}`);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let accountIds;
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
accountIds = readJsonFile(accountsPath);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
log(`failed to read weixin accounts file: ${error.message}`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!Array.isArray(accountIds) || accountIds.length === 0) {
|
|
230
|
+
log(`detected weixin accounts: none (${accountsPath})`);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (accountIds.length > 1) {
|
|
235
|
+
fail(`multiple weixin accounts were detected: ${accountIds.join(", ")}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const accountId = accountIds[0];
|
|
239
|
+
const accountPath = join(weixinDir, "accounts", `${accountId}.json`);
|
|
240
|
+
|
|
241
|
+
log(`weixinFanoutAccountId=${accountId}`);
|
|
242
|
+
|
|
243
|
+
if (!existsSync(accountPath)) {
|
|
244
|
+
log(`account config file was not found: ${accountPath}`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
const accountConfig = readJsonFile(accountPath);
|
|
250
|
+
|
|
251
|
+
if (accountConfig?.userId) {
|
|
252
|
+
log(`weixinFanoutTo=${accountConfig.userId}`);
|
|
253
|
+
}
|
|
254
|
+
} catch (error) {
|
|
255
|
+
log(`failed to read account config ${accountPath}: ${error.message}`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
await waitForEnter();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function install(options) {
|
|
189
263
|
const commands = buildCommands(options);
|
|
190
264
|
|
|
191
265
|
if (options.dryRun) {
|
|
@@ -217,6 +291,8 @@ function install(options) {
|
|
|
217
291
|
fail(`command failed: ${formatCommand(command)}`);
|
|
218
292
|
}
|
|
219
293
|
}
|
|
294
|
+
|
|
295
|
+
await logWeixinAccounts();
|
|
220
296
|
}
|
|
221
297
|
|
|
222
298
|
const command = process.argv[2];
|
|
@@ -230,7 +306,7 @@ switch (command) {
|
|
|
230
306
|
process.exit(0);
|
|
231
307
|
break;
|
|
232
308
|
case "install":
|
|
233
|
-
install(parseArgs(process.argv.slice(3)));
|
|
309
|
+
await install(parseArgs(process.argv.slice(3)));
|
|
234
310
|
break;
|
|
235
311
|
default:
|
|
236
312
|
fail(`unknown command: ${command}`);
|