chore: preserve initial reconstruction prototype
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const envSchema = z.object({
|
||||
OLLAMA_BASE_URL: z.string().url(),
|
||||
OLLAMA_MODEL: z.string().min(1),
|
||||
});
|
||||
|
||||
export function getConfig() {
|
||||
const parsed = envSchema.safeParse({
|
||||
OLLAMA_BASE_URL: process.env.OLLAMA_BASE_URL,
|
||||
OLLAMA_MODEL: process.env.OLLAMA_MODEL,
|
||||
});
|
||||
|
||||
if (!parsed.success) {
|
||||
return { ok: false, error: parsed.error.flatten().fieldErrors };
|
||||
}
|
||||
|
||||
return { ok: true, config: parsed.data };
|
||||
}
|
||||
|
||||
export function assertConfig() {
|
||||
const result = getConfig();
|
||||
if (!result.ok) {
|
||||
throw new Error(
|
||||
"Invalid configuration:\n" +
|
||||
Object.entries(result.error).map(([k, v]) => ` ${k}: ${v}`).join("\n")
|
||||
);
|
||||
}
|
||||
return result.config;
|
||||
}
|
||||
Reference in New Issue
Block a user