blun-king-cli 5.1.4 → 5.1.6
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/blun-cli.js +28 -8
- package/package.json +1 -1
package/blun-cli.js
CHANGED
|
@@ -17,7 +17,7 @@ const MEMORY_DIR = path.join(CONFIG_DIR, "memory");
|
|
|
17
17
|
const SKILLS_DIR = path.join(CONFIG_DIR, "skills");
|
|
18
18
|
const HISTORY_FILE = path.join(CONFIG_DIR, "history.json");
|
|
19
19
|
const LOG_FILE = path.join(CONFIG_DIR, "cli.log");
|
|
20
|
-
const PKG_VERSION = (() => { try { return require(path.join(__dirname, "..", "package.json")).version; } catch(
|
|
20
|
+
const PKG_VERSION = (() => { try { return require(path.join(__dirname, "package.json")).version; } catch(e) { try { return require(path.join(__dirname, "..", "package.json")).version; } catch(e2) { return "5.1.6"; } } })();
|
|
21
21
|
|
|
22
22
|
if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
23
23
|
if (!fs.existsSync(MEMORY_DIR)) fs.mkdirSync(MEMORY_DIR, { recursive: true });
|
|
@@ -2679,25 +2679,45 @@ async function main() {
|
|
|
2679
2679
|
printHeader();
|
|
2680
2680
|
checkForUpdates();
|
|
2681
2681
|
|
|
2682
|
-
// API Key check — prompt if missing
|
|
2683
|
-
if (!config.api.key && !process.argv.includes("--api-key")) {
|
|
2682
|
+
// API Key check — prompt if missing (uses raw stdin since readline may not work after setRawMode)
|
|
2683
|
+
if (!config.api.key && !config.auth.api_key && !process.argv.includes("--api-key")) {
|
|
2684
2684
|
console.log("");
|
|
2685
2685
|
console.log(C.yellow + " " + BOX.bot + " No API key configured." + C.reset);
|
|
2686
2686
|
console.log(C.gray + " Enter your BLUN King API key (or press Enter to skip):" + C.reset);
|
|
2687
|
+
process.stdout.write(C.brightBlue + " API Key: " + C.reset);
|
|
2687
2688
|
var apiKeyAnswer = await new Promise(function(resolve) {
|
|
2688
|
-
var
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2689
|
+
var buf = "";
|
|
2690
|
+
process.stdin.setRawMode(true);
|
|
2691
|
+
process.stdin.resume();
|
|
2692
|
+
process.stdin.setEncoding("utf8");
|
|
2693
|
+
function onKeyApi(key) {
|
|
2694
|
+
if (key === "\x03") { process.exit(0); }
|
|
2695
|
+
if (key === "\r" || key === "\n") {
|
|
2696
|
+
process.stdin.removeListener("data", onKeyApi);
|
|
2697
|
+
process.stdin.setRawMode(false);
|
|
2698
|
+
process.stdout.write("\n");
|
|
2699
|
+
resolve(buf.trim());
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
if (key === "\x7f" || key === "\b") {
|
|
2703
|
+
if (buf.length > 0) { buf = buf.slice(0, -1); process.stdout.write("\b \b"); }
|
|
2704
|
+
return;
|
|
2705
|
+
}
|
|
2706
|
+
buf += key;
|
|
2707
|
+
process.stdout.write("*");
|
|
2708
|
+
}
|
|
2709
|
+
process.stdin.on("data", onKeyApi);
|
|
2693
2710
|
});
|
|
2694
2711
|
if (apiKeyAnswer) {
|
|
2695
2712
|
config.api.key = apiKeyAnswer;
|
|
2713
|
+
config.auth.api_key = apiKeyAnswer;
|
|
2696
2714
|
var cfgFile = path.join(CONFIG_DIR, "config.json");
|
|
2697
2715
|
var cfgData = {};
|
|
2698
2716
|
if (fs.existsSync(cfgFile)) { try { cfgData = JSON.parse(fs.readFileSync(cfgFile, "utf8")); } catch(e) {} }
|
|
2699
2717
|
if (!cfgData.api) cfgData.api = {};
|
|
2718
|
+
if (!cfgData.auth) cfgData.auth = {};
|
|
2700
2719
|
cfgData.api.key = apiKeyAnswer;
|
|
2720
|
+
cfgData.auth.api_key = apiKeyAnswer;
|
|
2701
2721
|
fs.writeFileSync(cfgFile, JSON.stringify(cfgData, null, 2));
|
|
2702
2722
|
printSuccess("API key saved.");
|
|
2703
2723
|
}
|