feat: add environment configuration and SQLite migration support

This commit is contained in:
Zoe
2026-09-19 15:00:32 -05:00
parent 75b3a01aee
commit 118a5387cb
10 changed files with 193 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
export interface Config {
llamaCppOrigin: string;
modelId: string;
databasePath: string;
}
export function readConfig(environment: NodeJS.ProcessEnv = process.env): Config {
const origin = environment.LLAMA_CPP_ORIGIN?.trim();
const modelId = environment.LLAMA_CPP_MODEL_ID?.trim();
if (!origin || !modelId) {
throw new Error("Set LLAMA_CPP_ORIGIN and LLAMA_CPP_MODEL_ID in .env (see .env.example).");
}
const url = new URL(origin);
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password
|| url.pathname !== "/" || url.search || url.hash) {
throw new Error("LLAMA_CPP_ORIGIN must be an HTTP(S) origin without credentials, path, query, or fragment.");
}
return {
llamaCppOrigin: url.origin,
modelId,
databasePath: environment.DATABASE_PATH?.trim() || "./data/token.sqlite",
};
}