@kevisual/cnb 0.0.63 → 0.0.65

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/agent/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { app } from './index.ts';
2
2
  import { parse } from '@kevisual/router/src/commander.ts';
3
3
 
4
- await parse({ app: app, description: 'CNB控制台命令行工具', parse: true })
4
+ await parse({ app: app, description: 'CNB控制台命令行工具', parse: true, exitOnEnd: true })
5
5
 
6
6
  console.log('命令行工具已启动,输入 help 查看可用命令', 'end');
package/agent/live.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { createKeepAlive } from '../src/workspace/keep-live.ts';
2
+ import { readFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { Command, program } from 'commander';
5
+
6
+ program.addCommand(new Command('live')
7
+ .description('启动 CNB Keep Alive 服务')
8
+ .option('-j, --json <string>', 'JSON数据')
9
+ .option('-c, --config <string>', '配置文件路径 (优先级高于 JSON 参数), 默认keep.json')
10
+ .action(async (opts) => {
11
+ let config: { wss: string; cookie: string; url?: string };
12
+ let configPath = opts.config || 'keep.json'
13
+ if (configPath.startsWith('/')) {
14
+ configPath = path.resolve(configPath)
15
+ } else {
16
+ configPath = path.join(process.cwd(), configPath)
17
+ }
18
+
19
+ try {
20
+ let jsonString = opts.json;
21
+
22
+ if (!jsonString) {
23
+ jsonString = readFileSync(configPath, 'utf-8').trim();
24
+ }
25
+
26
+ config = JSON.parse(jsonString);
27
+ } catch (error) {
28
+ console.error('JSON 解析错误: 请检查输入的 JSON 格式是否正确');
29
+ process.exit(1);
30
+ }
31
+ if (!config.wss || !config.cookie) {
32
+ console.error('配置错误: 必须包含 wss 和 cookie 字段');
33
+ process.exit(1);
34
+ }
35
+
36
+ createKeepAlive({
37
+ wsUrl: config.wss,
38
+ cookie: config.cookie,
39
+ onDisconnect: (code) => {
40
+ console.log(`与 CNB 服务器断开连接,代码: ${code}`);
41
+ },
42
+ debug: true
43
+ });
44
+ }));
45
+
46
+ program.parse(process.argv);
package/bin/live.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ import '../dist/cli-live.js';
@@ -0,0 +1,2 @@
1
+
2
+ export { };