@searchfe/openclaw-baiduapp 0.1.12-beta.2 → 0.1.12

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.
@@ -2,7 +2,7 @@
2
2
  "id": "openclaw-baiduapp",
3
3
  "name": "Baidu App",
4
4
  "description": "百度App消息渠道插件(支持主动推送)",
5
- "version": "0.1.12-beta.2",
5
+ "version": "0.1.12",
6
6
  "channels": ["openclaw-baiduapp"],
7
7
  "configSchema": {
8
8
  "type": "object",
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@searchfe/openclaw-baiduapp",
3
- "version": "0.1.12-beta.2",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Baidu App channel plugin (百度App消息渠道插件)",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "dist",
9
- "openclaw.plugin.json",
10
- "cli.js",
11
- "src/cli-qrcode.mjs"
9
+ "openclaw.plugin.json"
12
10
  ],
13
11
  "openclaw": {
14
12
  "extensions": [
@@ -73,9 +71,6 @@
73
71
  "defaultChoice": "npm"
74
72
  }
75
73
  },
76
- "bin": {
77
- "openclaw-baiduapp": "cli.js"
78
- },
79
74
  "main": "./dist/index.js",
80
75
  "types": "./dist/index.d.ts",
81
76
  "exports": {
@@ -95,8 +90,7 @@
95
90
  "release:major": "npm run build && npm version major && npm publish"
96
91
  },
97
92
  "dependencies": {
98
- "@baiducloud/sdk": "^1.0.7",
99
- "qrcode-terminal": "^0.12.0"
93
+ "@baiducloud/sdk": "^1.0.7"
100
94
  },
101
95
  "devDependencies": {
102
96
  "@types/node": "^22.0.0",
package/cli.js DELETED
@@ -1,405 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import {execSync, spawnSync} from 'node:child_process';
4
- import {createRequire} from 'node:module';
5
- import readline from 'node:readline';
6
- import {Writable} from 'node:stream';
7
-
8
- import {printQRCode} from './src/cli-qrcode.mjs';
9
-
10
- const _require = createRequire(import.meta.url);
11
- const CLI_VERSION = _require('./package.json').version;
12
-
13
- const PLUGIN_SPEC = '@searchfe/openclaw-baiduapp';
14
- const CHANNEL_ID = 'openclaw-baiduapp';
15
- const QR_URL = 'https://www.baidu.com';
16
-
17
- function parseArgs(argv) {
18
- const args = argv.slice(2);
19
- let command;
20
- let ak;
21
- let sk;
22
- let agent;
23
- let yes = false;
24
-
25
- for (let index = 0; index < args.length; index++) {
26
- const token = args[index];
27
-
28
- if (token === '--help' || token === '-h') {
29
- if (!command) {
30
- command = token;
31
- }
32
- continue;
33
- }
34
-
35
- if (token === '--yes' || token === '-y') {
36
- yes = true;
37
- continue;
38
- }
39
-
40
- if (token === '--ak') {
41
- ak = args[index + 1];
42
- index += 1;
43
- continue;
44
- }
45
-
46
- if (token.startsWith('--ak=')) {
47
- ak = token.slice('--ak='.length);
48
- continue;
49
- }
50
-
51
- if (token === '--sk') {
52
- sk = args[index + 1];
53
- index += 1;
54
- continue;
55
- }
56
-
57
- if (token.startsWith('--sk=')) {
58
- sk = token.slice('--sk='.length);
59
- continue;
60
- }
61
-
62
- if (token === '--agent') {
63
- agent = args[index + 1];
64
- index += 1;
65
- continue;
66
- }
67
-
68
- if (token.startsWith('--agent=')) {
69
- agent = token.slice('--agent='.length);
70
- continue;
71
- }
72
-
73
- if (!token.startsWith('--') && !command) {
74
- command = token;
75
- }
76
- }
77
-
78
- return {command, ak, sk, agent, yes};
79
- }
80
-
81
- function prompt(question, {hidden = false} = {}) {
82
- if (!process.stdin.isTTY) {
83
- throw new Error('非交互环境:请通过 --ak/--sk 参数传入凭证');
84
- }
85
-
86
- const askOnce = () => new Promise(resolve => {
87
- if (hidden) {
88
- process.stdout.write(question);
89
- const rl = readline.createInterface({
90
- input: process.stdin,
91
- output: new Writable({write(_chunk, _enc, cb) { cb(); }}),
92
- terminal: true,
93
- });
94
- rl.on('SIGINT', () => { rl.close(); process.stdout.write('\n'); process.exit(1); });
95
- rl.question('', answer => {
96
- rl.close();
97
- process.stdout.write('\n');
98
- resolve(String(answer || '').trim());
99
- });
100
- return;
101
- }
102
-
103
- const rl = readline.createInterface({
104
- input: process.stdin,
105
- output: process.stdout,
106
- terminal: true,
107
- });
108
- rl.on('SIGINT', () => { rl.close(); process.exit(1); });
109
- rl.question(question, answer => {
110
- rl.close();
111
- resolve(String(answer || '').trim());
112
- });
113
- });
114
-
115
- return (async () => {
116
- for (let attempt = 0; attempt < 3; attempt++) {
117
- const answer = await askOnce();
118
- if (answer) {
119
- return answer;
120
- }
121
-
122
- if (attempt < 2) {
123
- error('输入不能为空,请重试');
124
- }
125
- }
126
-
127
- throw new Error('输入不能为空,已超过最大重试次数');
128
- })();
129
- }
130
-
131
- function promptOptional(question) {
132
- if (!process.stdin.isTTY) {
133
- return Promise.resolve('');
134
- }
135
- return new Promise(resolve => {
136
- const rl = readline.createInterface({
137
- input: process.stdin,
138
- output: process.stdout,
139
- terminal: true,
140
- });
141
- rl.on('SIGINT', () => {
142
- rl.close();
143
- process.exit(1);
144
- });
145
- rl.question(question, answer => {
146
- rl.close();
147
- resolve(String(answer || '').trim());
148
- });
149
- });
150
- }
151
-
152
- async function checkAndCreateAgent(agentId, {yes = false} = {}) {
153
- let agentsList;
154
- try {
155
- const agentsJson = run('openclaw', ['agents', 'list', '--json']);
156
- agentsList = JSON.parse(agentsJson);
157
- } catch {
158
- // 解析失败时假设 agent 不存在,继续后续流程
159
- agentsList = [];
160
- }
161
-
162
- const exists = Array.isArray(agentsList) && agentsList.some(a => a.id === agentId);
163
- if (exists) {
164
- return;
165
- }
166
-
167
- log(`Agent "${agentId}" 不存在`);
168
- console.log(` 你可以手动执行以下命令新建:`);
169
- console.log(` openclaw agents add ${agentId}`);
170
- console.log();
171
-
172
- let confirm;
173
- if (yes) {
174
- confirm = 'y';
175
- } else {
176
- try {
177
- confirm = await prompt(`是否立即自动新建 agent "${agentId}"?[y/N]: `);
178
- } catch {
179
- confirm = '';
180
- }
181
- }
182
-
183
- if (confirm.toLowerCase() !== 'y') {
184
- error('已取消,请手动新建 agent 后重试');
185
- process.exit(1);
186
- }
187
-
188
- log(`正在新建 agent "${agentId}"...`);
189
- try {
190
- run('openclaw', ['agents', 'add', agentId], {silent: false});
191
- } catch {
192
- error('新建 agent 失败,请手动执行:');
193
- console.log(` openclaw agents add ${agentId}`);
194
- process.exit(1);
195
- }
196
- }
197
-
198
- function run(cmd, args = [], {silent = true} = {}) {
199
- const stdio = silent ? ['pipe', 'pipe', 'pipe'] : 'inherit';
200
- const result = spawnSync(cmd, args, {encoding: 'utf-8', stdio});
201
-
202
- if (result.error) {
203
- const err = new Error(`Command failed: ${cmd}`);
204
- err.stderr = silent ? String(result.stderr || result.error.message || '') : '';
205
- throw err;
206
- }
207
-
208
- if (result.status !== 0) {
209
- const err = new Error(`Command failed with exit code ${result.status}: ${cmd}`);
210
- err.stderr = silent ? String(result.stderr || '') : '';
211
- throw err;
212
- }
213
-
214
- return silent ? String(result.stdout || '').trim() : '';
215
- }
216
-
217
- function which(bin) {
218
- const cmd = process.platform === 'win32' ? `where ${bin}` : `which ${bin}`;
219
-
220
- try {
221
- return execSync(cmd, {
222
- encoding: 'utf-8',
223
- shell: true,
224
- stdio: ['pipe', 'pipe', 'pipe'],
225
- }).trim();
226
- } catch {
227
- return null;
228
- }
229
- }
230
-
231
- function log(msg) {
232
- console.log(`\x1b[36m[openclaw-baiduapp]\x1b[0m ${msg}`);
233
- }
234
-
235
- function error(msg) {
236
- console.error(`\x1b[31m[openclaw-baiduapp]\x1b[0m ${msg}`);
237
- }
238
-
239
- async function install() {
240
- let {ak, sk, agent, yes} = parseArgs(process.argv);
241
-
242
- if ((!ak || !sk) && !process.stdin.isTTY) {
243
- error('非交互环境:请通过 --ak/--sk 参数传入凭证');
244
- process.exit(1);
245
- }
246
-
247
- if (agent !== undefined && !agent.trim()) {
248
- error('--agent 参数不能为空');
249
- process.exit(1);
250
- }
251
- let agentId = agent?.trim();
252
-
253
- if (!which('openclaw')) {
254
- error('未找到 openclaw,请先安装:');
255
- console.log(' npm install -g openclaw');
256
- console.log(' 详见 https://docs.openclaw.ai/install');
257
- process.exit(1);
258
- }
259
- log('已找到本地安装的 openclaw');
260
-
261
- log('正在检查插件版本...');
262
- let installedVersion = null;
263
- try {
264
- const infoJson = run('openclaw', ['config', 'get', `plugins.installs.${CHANNEL_ID}`, '--json']);
265
- const info = JSON.parse(infoJson);
266
- installedVersion = info?.version ?? null;
267
- } catch {
268
- // 未安装或无法读取,后续走安装流程
269
- }
270
-
271
- if (installedVersion === null) {
272
- log(`插件未安装,正在安装 ${PLUGIN_SPEC}@${CLI_VERSION}...`);
273
- try {
274
- run('openclaw', ['plugins', 'install', `${PLUGIN_SPEC}@${CLI_VERSION}`], {silent: false});
275
- } catch (installErr) {
276
- error('插件安装失败,请手动执行:');
277
- console.log(` openclaw plugins install "${PLUGIN_SPEC}@${CLI_VERSION}"`);
278
- process.exit(1);
279
- }
280
- } else if (installedVersion !== CLI_VERSION) {
281
- log(`插件版本不一致(已安装: ${installedVersion},当前 CLI: ${CLI_VERSION}),正在更新...`);
282
- try {
283
- run('openclaw', ['config', 'set', `plugins.installs.${CHANNEL_ID}.spec`, `${PLUGIN_SPEC}@${CLI_VERSION}`]);
284
- run('openclaw', ['config', 'unset', `plugins.installs.${CHANNEL_ID}.integrity`]);
285
- run('openclaw', ['config', 'unset', `plugins.installs.${CHANNEL_ID}.shasum`]);
286
- run('openclaw', ['plugins', 'update', CHANNEL_ID], {silent: false});
287
- run('openclaw', ['gateway', 'restart'], {silent: false});
288
- } catch (updateErr) {
289
- error('插件更新失败,请手动执行:');
290
- console.log(` openclaw config set plugins.installs.${CHANNEL_ID}.spec ${PLUGIN_SPEC}@${CLI_VERSION}`);
291
- console.log(` openclaw config unset plugins.installs.${CHANNEL_ID}.integrity`);
292
- console.log(` openclaw config unset plugins.installs.${CHANNEL_ID}.shasum`);
293
- console.log(` openclaw plugins update ${CHANNEL_ID}`);
294
- console.log(` openclaw gateway restart`);
295
- process.exit(1);
296
- }
297
- } else {
298
- log(`插件版本已是最新(${CLI_VERSION}),跳过更新`);
299
- }
300
-
301
- try {
302
- if (!ak) {
303
- ak = await prompt('请输入 App Key (appKey): ');
304
- }
305
- if (!sk) {
306
- sk = await prompt('请输入 App Secret (appSecret): ', {hidden: true});
307
- }
308
- } catch (promptErr) {
309
- error(promptErr instanceof Error ? promptErr.message : String(promptErr));
310
- process.exit(1);
311
- }
312
-
313
- if (!ak.trim() || !sk.trim()) {
314
- error('appKey 和 appSecret 不能为空');
315
- process.exit(1);
316
- }
317
-
318
- // 插件已确认安装,再询问/校验 agent
319
- if (!agentId && process.stdin.isTTY) {
320
- agentId = await promptOptional('请输入 Agent ID(可选,用于多 agent 配置,直接回车跳过):') || undefined;
321
- }
322
-
323
- if (agentId) {
324
- await checkAndCreateAgent(agentId, {yes});
325
- }
326
-
327
- log('正在写入配置...');
328
- const akPath = agentId
329
- ? `channels.${CHANNEL_ID}.accounts.${agentId}.appKey`
330
- : `channels.${CHANNEL_ID}.appKey`;
331
- const skPath = agentId
332
- ? `channels.${CHANNEL_ID}.accounts.${agentId}.appSecret`
333
- : `channels.${CHANNEL_ID}.appSecret`;
334
- try {
335
- run('openclaw', ['config', 'set', akPath, ak.trim()]);
336
- run('openclaw', ['config', 'set', skPath, sk.trim()]);
337
- } catch {
338
- error('配置写入失败,请手动执行:');
339
- console.log(` openclaw config set ${akPath} <your-app-key>`);
340
- console.log(` openclaw config set ${skPath} <your-app-secret>`);
341
- process.exit(1);
342
- }
343
- if (agentId) {
344
- log(`配置写入成功(agent: ${agentId})`);
345
- } else {
346
- log('配置写入成功');
347
- }
348
-
349
- log('正在重启 OpenClaw Gateway...');
350
- try {
351
- run('openclaw', ['gateway', 'restart'], {silent: false});
352
- } catch {
353
- error('重启失败,可手动执行:');
354
- console.log(' openclaw gateway restart');
355
- }
356
-
357
- console.log();
358
- log('安装完成!扫描下方二维码访问:');
359
- console.log();
360
- printQRCode(QR_URL);
361
- console.log();
362
- console.log(` ${QR_URL}`);
363
- console.log();
364
- }
365
-
366
- function help() {
367
- console.log(`用法: npx @searchfe/openclaw-baiduapp <命令> [选项]
368
-
369
- 命令:
370
- install 安装百度App插件并配置 AK/SK
371
-
372
- 选项:
373
- --ak <appKey> App Key(必填,缺省时交互输入)
374
- --sk <appSecret> App Secret(必填,缺省时交互输入,不回显)
375
- --agent <agentId> Agent ID(可选,指定后写入 accounts.<agentId> 以支持多 agent 配置)
376
- 交互模式下也会提示输入,直接回车跳过(写入根路径)
377
- 指定后自动校验 agent 是否存在,不存在时提示确认新建
378
- --yes, -y 自动确认所有交互提示(如 agent 不存在时自动新建,适合 CI/脚本环境)
379
- --help, -h 显示帮助信息
380
-
381
- 示例:
382
- npx @searchfe/openclaw-baiduapp install --ak your-key --sk your-secret
383
- npx @searchfe/openclaw-baiduapp install --agent my-agent --ak your-key --sk your-secret
384
- npx @searchfe/openclaw-baiduapp install --agent my-agent --ak your-key --sk your-secret --yes
385
- npx @searchfe/openclaw-baiduapp install`);
386
- }
387
-
388
- const {command} = parseArgs(process.argv);
389
-
390
- switch (command) {
391
- case 'install':
392
- await install();
393
- break;
394
- case 'help':
395
- case '--help':
396
- case '-h':
397
- help();
398
- break;
399
- default:
400
- if (command) {
401
- error(`未知命令: ${command}`);
402
- }
403
- help();
404
- process.exit(command ? 1 : 0);
405
- }
@@ -1,5 +0,0 @@
1
- import qrcodeTerminal from 'qrcode-terminal';
2
-
3
- export function printQRCode(url) {
4
- qrcodeTerminal.generate(String(url), {small: true}, qrcode => console.log(qrcode));
5
- }