nanoai-cli 1.0.8 → 1.0.10
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/nanoai.js +65 -0
- package/package.json +1 -1
package/bin/nanoai.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const { ensureBinary } = require("../scripts/download");
|
|
7
|
+
const { maybeUpdateBinary } = require("../scripts/update");
|
|
8
|
+
|
|
9
|
+
function log(message) {
|
|
10
|
+
console.error(`[nanoagent] ${message}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function forwardSignal(child, signal) {
|
|
14
|
+
if (!child || child.killed) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
child.kill(signal);
|
|
20
|
+
} catch {
|
|
21
|
+
// Ignore races where the process exits before the signal is forwarded.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
let binaryPath = await ensureBinary({ log });
|
|
27
|
+
binaryPath = await maybeUpdateBinary(binaryPath, { log });
|
|
28
|
+
|
|
29
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
windowsHide: false,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
35
|
+
const signalHandlers = new Map();
|
|
36
|
+
|
|
37
|
+
for (const signal of forwardedSignals) {
|
|
38
|
+
const handler = () => forwardSignal(child, signal);
|
|
39
|
+
signalHandlers.set(signal, handler);
|
|
40
|
+
process.on(signal, handler);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
child.on("error", (error) => {
|
|
44
|
+
log(`Failed to start NanoAgent CLI: ${error.message}`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.on("exit", (code, signal) => {
|
|
49
|
+
for (const [event, handler] of signalHandlers) {
|
|
50
|
+
process.removeListener(event, handler);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (signal) {
|
|
54
|
+
process.kill(process.pid, signal);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
process.exit(code ?? 0);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main().catch((error) => {
|
|
63
|
+
log(error && error.message ? error.message : String(error));
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|