refactor: change config to yaml in root
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
SUPERMEMORY_API_KEY=
|
|
||||||
|
|
||||||
BRAINBOX_ROOT_PATH=./brainbox-data
|
|
||||||
|
|
||||||
OPENROUTER_API_KEY=
|
|
||||||
6
bun.lock
6
bun.lock
@@ -8,9 +8,9 @@
|
|||||||
"@openrouter/sdk": "^0.12.79",
|
"@openrouter/sdk": "^0.12.79",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
"commander": "^15.0.0",
|
"commander": "^15.0.0",
|
||||||
"dotenv": "^17.4.2",
|
|
||||||
"prettier": "^3.8.3",
|
"prettier": "^3.8.3",
|
||||||
"supermemory": "^4.24.12",
|
"supermemory": "^4.24.12",
|
||||||
|
"yaml": "^2.9.0",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^25.9.1",
|
"@types/node": "^25.9.1",
|
||||||
@@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
"commander": ["commander@15.0.0", "", {}, "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg=="],
|
"commander": ["commander@15.0.0", "", {}, "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg=="],
|
||||||
|
|
||||||
"dotenv": ["dotenv@17.4.2", "", {}, "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw=="],
|
|
||||||
|
|
||||||
"prettier": ["prettier@3.8.3", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw=="],
|
"prettier": ["prettier@3.8.3", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw=="],
|
||||||
|
|
||||||
"supermemory": ["supermemory@4.24.12", "", { "bin": { "supermemory": "bin/cli" } }, "sha512-xAFextuqk4JuoW33jJaFGqT1oMppN2IgfWUrV18Fv3qAAZ6M1SR1tb+7EBq8vrEQIx4iY2MQh5p+qnfL6lI8Yw=="],
|
"supermemory": ["supermemory@4.24.12", "", { "bin": { "supermemory": "bin/cli" } }, "sha512-xAFextuqk4JuoW33jJaFGqT1oMppN2IgfWUrV18Fv3qAAZ6M1SR1tb+7EBq8vrEQIx4iY2MQh5p+qnfL6lI8Yw=="],
|
||||||
@@ -39,6 +37,8 @@
|
|||||||
|
|
||||||
"undici-types": ["undici-types@7.24.6", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="],
|
"undici-types": ["undici-types@7.24.6", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="],
|
||||||
|
|
||||||
|
"yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="],
|
||||||
|
|
||||||
"zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="],
|
"zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
"@openrouter/sdk": "^0.12.79",
|
"@openrouter/sdk": "^0.12.79",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
"commander": "^15.0.0",
|
"commander": "^15.0.0",
|
||||||
"dotenv": "^17.4.2",
|
|
||||||
"prettier": "^3.8.3",
|
"prettier": "^3.8.3",
|
||||||
"supermemory": "^4.24.12"
|
"supermemory": "^4.24.12",
|
||||||
|
"yaml": "^2.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import "dotenv/config";
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
||||||
import { join } from "path";
|
import { homedir } from "os";
|
||||||
|
import { dirname, join, resolve } from "path";
|
||||||
|
import { parse as parseYaml } from "yaml";
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
openrouterApiKey: string;
|
openrouterApiKey: string;
|
||||||
@@ -7,19 +9,43 @@ export interface Config {
|
|||||||
brainboxRoot: string;
|
brainboxRoot: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const openrouterApiKey = process.env["OPENROUTER_API_KEY"];
|
const brainboxRoot = process.env["BRAINBOX_ROOT_PATH"]
|
||||||
if (!openrouterApiKey) throw new Error("OPENROUTER_API_KEY is missing");
|
? resolve(process.cwd(), process.env["BRAINBOX_ROOT_PATH"])
|
||||||
|
: join(homedir(), ".brainbox");
|
||||||
|
|
||||||
const supermemoryApiKey = process.env["SUPERMEMORY_API_KEY"];
|
interface BrainboxYaml {
|
||||||
if (!supermemoryApiKey) throw new Error("SUPERMEMORY_API_KEY is missing");
|
openrouter?: { apiKey?: string };
|
||||||
|
supermemory?: { apiKey?: string };
|
||||||
|
}
|
||||||
|
|
||||||
const brainboxRoot = join(
|
const yamlPath = join(brainboxRoot, "brainbox.yaml");
|
||||||
process.cwd(),
|
let parsed: BrainboxYaml = {};
|
||||||
process.env["BRAINBOX_ROOT_PATH"] ?? "brainbox-data",
|
try {
|
||||||
);
|
parsed = parseYaml(readFileSync(yamlPath, "utf8")) ?? {};
|
||||||
|
} catch (err) {
|
||||||
|
if ((err as NodeJS.ErrnoException).code === "ENOENT") {
|
||||||
|
mkdirSync(dirname(yamlPath), { recursive: true });
|
||||||
|
writeFileSync(
|
||||||
|
yamlPath,
|
||||||
|
"# Fill in your API keys, then run brainbox again.\n" +
|
||||||
|
"openrouter:\n" +
|
||||||
|
" apiKey: \n" +
|
||||||
|
"supermemory:\n" +
|
||||||
|
" apiKey: \n",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const openrouterApiKey = parsed.openrouter?.apiKey;
|
||||||
|
if (!openrouterApiKey) throw new Error(`openrouter.apiKey is missing in ${yamlPath}`);
|
||||||
|
|
||||||
|
const supermemoryApiKey = parsed.supermemory?.apiKey;
|
||||||
|
if (!supermemoryApiKey) throw new Error(`supermemory.apiKey is missing in ${yamlPath}`);
|
||||||
|
|
||||||
export const config: Config = {
|
export const config: Config = {
|
||||||
openrouterApiKey,
|
openrouterApiKey,
|
||||||
supermemoryApiKey,
|
supermemoryApiKey,
|
||||||
brainboxRoot,
|
brainboxRoot,
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user