feat: add environment configuration and SQLite migration support
This commit is contained in:
@@ -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",
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user