heyeric 1.0.0 → 1.1.0
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/dist/index.js +27 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { execSync } from "child_process";
|
|
4
|
+
import { execSync, spawn } from "child_process";
|
|
5
|
+
import { createInterface } from "readline";
|
|
5
6
|
import { readFileSync } from "fs";
|
|
6
7
|
import { platform } from "os";
|
|
7
8
|
import { basename } from "path";
|
|
@@ -12,11 +13,9 @@ function die(msg) {
|
|
|
12
13
|
}
|
|
13
14
|
var query = process.argv.slice(2).join(" ").trim();
|
|
14
15
|
if (!query) die("Usage: eric <query>");
|
|
15
|
-
var apiUrl = process.env.AI_API_URL;
|
|
16
|
-
var apiKey = process.env.AI_API_KEY;
|
|
16
|
+
var apiUrl = process.env.AI_API_URL || "https://aiapi.ericpark.me/v1/chat/completions";
|
|
17
|
+
var apiKey = process.env.AI_API_KEY || "ericpark";
|
|
17
18
|
var model = process.env.AI_MODEL || "gpt-5.4-mini";
|
|
18
|
-
if (!apiUrl) die("AI_API_URL environment variable is required");
|
|
19
|
-
if (!apiKey) die("AI_API_KEY environment variable is required");
|
|
20
19
|
var cwd = process.cwd();
|
|
21
20
|
var os = platform();
|
|
22
21
|
var shell = basename(process.env.SHELL || "/bin/bash");
|
|
@@ -113,7 +112,29 @@ async function main() {
|
|
|
113
112
|
command = command.replace(/^`+|`+$/g, "");
|
|
114
113
|
command = command.trim();
|
|
115
114
|
if (!command) die("API returned empty command");
|
|
116
|
-
process.
|
|
115
|
+
process.stderr.write(`\x1B[1;32m\u276F\x1B[0m \x1B[1m${command}\x1B[0m
|
|
116
|
+
`);
|
|
117
|
+
process.stderr.write(`\x1B[2mEnter to run \xB7 Type to refine \xB7 Ctrl+C to cancel\x1B[0m
|
|
118
|
+
`);
|
|
119
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
120
|
+
const answer = await new Promise((resolve) => {
|
|
121
|
+
rl.question("\x1B[2m\u203A \x1B[0m", (input) => {
|
|
122
|
+
rl.close();
|
|
123
|
+
resolve(input.trim());
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
if (answer) {
|
|
127
|
+
const child2 = spawn(process.argv[0], [...process.argv.slice(1, 2), answer], {
|
|
128
|
+
stdio: "inherit",
|
|
129
|
+
env: process.env
|
|
130
|
+
});
|
|
131
|
+
child2.on("close", (code) => process.exit(code ?? 0));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const child = spawn(command, { shell: true, stdio: "inherit" });
|
|
135
|
+
child.on("close", (code) => {
|
|
136
|
+
process.exit(code ?? 0);
|
|
137
|
+
});
|
|
117
138
|
}
|
|
118
139
|
main().catch((err) => {
|
|
119
140
|
die(err.message);
|