@bolloon/bolloon-agent 0.1.8 → 0.1.9
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/bin/bolloon-cli.cjs +8 -1
- package/bin/bolloon.cjs +157 -0
- package/package.json +2 -2
package/bin/bolloon-cli.cjs
CHANGED
|
@@ -114,10 +114,17 @@ async function startCLI(additionalArgs) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
async function main() {
|
|
117
|
+
// Get version from package.json
|
|
118
|
+
const binPath = require.main.filename;
|
|
119
|
+
const binDir = path.dirname(binPath);
|
|
120
|
+
const packageDir = path.dirname(binDir);
|
|
121
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf-8"));
|
|
122
|
+
const version = packageJson.version;
|
|
123
|
+
|
|
117
124
|
const { mode, args } = parseArgs();
|
|
118
125
|
switch (mode) {
|
|
119
126
|
case "version":
|
|
120
|
-
console.log("Bolloon Agent
|
|
127
|
+
console.log("Bolloon Agent v" + version);
|
|
121
128
|
break;
|
|
122
129
|
case "help":
|
|
123
130
|
printBanner();
|
package/bin/bolloon.cjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
|
|
6
|
+
const RESET = "\x1b[0m";
|
|
7
|
+
const BOLD = "\x1b[1m";
|
|
8
|
+
const CYAN = "\x1b[36m";
|
|
9
|
+
const GREEN = "\x1b[32m";
|
|
10
|
+
const MAGENTA = "\x1b[35m";
|
|
11
|
+
|
|
12
|
+
function log(msg, color) {
|
|
13
|
+
console.log((color || RESET) + msg + RESET);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function printBanner() {
|
|
17
|
+
console.log("\n" + CYAN + BOLD + [
|
|
18
|
+
" ╔═══════════════════════════════════════════╗",
|
|
19
|
+
" ║ 🤖 Bolloon Agent ║",
|
|
20
|
+
" ║ P2P AI Document Processor ║",
|
|
21
|
+
" ╚═══════════════════════════════════════════╝"
|
|
22
|
+
].join("\n") + RESET + "\n");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getMainEntry() {
|
|
26
|
+
const distDir = path.dirname(require.main.filename);
|
|
27
|
+
const distIndex = path.join(distDir, "index.js");
|
|
28
|
+
if (fs.existsSync(distIndex)) {
|
|
29
|
+
return distIndex;
|
|
30
|
+
}
|
|
31
|
+
return path.join(process.cwd(), "src", "index.ts");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseArgs() {
|
|
35
|
+
const args = process.argv.slice(2);
|
|
36
|
+
if (args.length === 0) {
|
|
37
|
+
return { mode: "gui", args: [] };
|
|
38
|
+
}
|
|
39
|
+
const first = args[0];
|
|
40
|
+
switch (first) {
|
|
41
|
+
case "-v":
|
|
42
|
+
case "--version":
|
|
43
|
+
return { mode: "version", args: [] };
|
|
44
|
+
case "-h":
|
|
45
|
+
case "--help":
|
|
46
|
+
return { mode: "help", args: [] };
|
|
47
|
+
case "-g":
|
|
48
|
+
case "--gui":
|
|
49
|
+
return { mode: "gui", args: args.slice(1) };
|
|
50
|
+
case "-w":
|
|
51
|
+
case "--web":
|
|
52
|
+
return { mode: "web", args: args.slice(1) };
|
|
53
|
+
case "-c":
|
|
54
|
+
case "--cli":
|
|
55
|
+
return { mode: "cli", args: args.slice(1) };
|
|
56
|
+
default:
|
|
57
|
+
return { mode: "passthrough", args };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function startElectron(additionalArgs) {
|
|
62
|
+
try {
|
|
63
|
+
const electron = require("electron");
|
|
64
|
+
const distDir = path.dirname(require.main.filename);
|
|
65
|
+
let mainPath = path.join(distDir, "electron.js");
|
|
66
|
+
if (!fs.existsSync(mainPath)) {
|
|
67
|
+
mainPath = path.join(process.cwd(), "src", "electron.ts");
|
|
68
|
+
}
|
|
69
|
+
log("启动 Electron...", CYAN);
|
|
70
|
+
const child = spawn(electron, [mainPath, ...additionalArgs], {
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
env: { ...process.env, NODE_ENV: "development" }
|
|
73
|
+
});
|
|
74
|
+
child.on("error", (err) => {
|
|
75
|
+
log("Electron 启动失败: " + err.message, MAGENTA);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
78
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
79
|
+
} catch (err) {
|
|
80
|
+
log("Electron 不可用,切换到 Web 模式...", CYAN);
|
|
81
|
+
await startWebServer(additionalArgs);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function startWebServer(additionalArgs) {
|
|
86
|
+
const mainPath = getMainEntry();
|
|
87
|
+
const webArgs = ["--web", ...additionalArgs];
|
|
88
|
+
log("启动 Web 服务...", CYAN);
|
|
89
|
+
const child = spawn(process.execPath, [mainPath, ...webArgs], { stdio: "inherit" });
|
|
90
|
+
child.on("error", (err) => {
|
|
91
|
+
log("Web 服务启动失败: " + err.message, MAGENTA);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
});
|
|
94
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function startCLI(additionalArgs) {
|
|
98
|
+
const mainPath = getMainEntry();
|
|
99
|
+
log("启动命令行界面...", CYAN);
|
|
100
|
+
const child = spawn(process.execPath, [mainPath, ...additionalArgs], { stdio: "inherit" });
|
|
101
|
+
child.on("error", (err) => {
|
|
102
|
+
log("CLI 启动失败: " + err.message, MAGENTA);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
});
|
|
105
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function main() {
|
|
109
|
+
const { mode, args } = parseArgs();
|
|
110
|
+
switch (mode) {
|
|
111
|
+
case "version":
|
|
112
|
+
console.log("Bolloon Agent v0.1.1");
|
|
113
|
+
break;
|
|
114
|
+
case "help":
|
|
115
|
+
printBanner();
|
|
116
|
+
console.log(BOLD + "用法:" + RESET + " bolloon [选项] [命令] [参数]");
|
|
117
|
+
console.log(BOLD + "选项:" + RESET + " --gui, -g 启动图形界面");
|
|
118
|
+
console.log(" --web, -w 启动 Web UI");
|
|
119
|
+
console.log(" --cli, -c 启动命令行界面");
|
|
120
|
+
console.log(" --version, -v 显示版本");
|
|
121
|
+
console.log(" --help, -h 显示帮助");
|
|
122
|
+
console.log(BOLD + "示例:" + RESET + " bolloon # 启动图形界面");
|
|
123
|
+
console.log(" bolloon --web # 启动 Web UI");
|
|
124
|
+
console.log(" bolloon --read file # 读取文档");
|
|
125
|
+
break;
|
|
126
|
+
case "gui":
|
|
127
|
+
printBanner();
|
|
128
|
+
await startElectron(args);
|
|
129
|
+
break;
|
|
130
|
+
case "web":
|
|
131
|
+
printBanner();
|
|
132
|
+
await startWebServer(args);
|
|
133
|
+
break;
|
|
134
|
+
case "cli":
|
|
135
|
+
await startCLI(args);
|
|
136
|
+
break;
|
|
137
|
+
case "passthrough":
|
|
138
|
+
const mainPath = getMainEntry();
|
|
139
|
+
const child = spawn(process.execPath, [mainPath, ...args], { stdio: "inherit" });
|
|
140
|
+
child.on("error", (err) => {
|
|
141
|
+
log("执行失败: " + err.message, MAGENTA);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
});
|
|
144
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
log("未知模式: " + mode, MAGENTA);
|
|
148
|
+
printBanner();
|
|
149
|
+
console.log("输入 --help 查看帮助");
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main().catch((err) => {
|
|
155
|
+
console.error("Fatal error:", err);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolloon/bolloon-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "P2P AI Document Agent - 全局安装后执行 `bolloon` 启动产品",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"src/constraint-runtime"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@bolloon/bolloon-agent": "^0.1.
|
|
35
|
+
"@bolloon/bolloon-agent": "^0.1.8",
|
|
36
36
|
"@bolloon/constraint-runtime": "0.1.0",
|
|
37
37
|
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
38
38
|
"@chainsafe/libp2p-yamux": "^8.0.1",
|