-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
37 lines (33 loc) · 955 Bytes
/
config.ts
File metadata and controls
37 lines (33 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { readFileSync } from "fs";
import { z } from "zod";
const configSchema = z.object({
adapter: z.string(),
credentials: z.record(z.string()),
student_id: z.string(),
sync_cron: z.string().default("*/30 * * * *"),
llm: z.object({
base_url: z.string().default("http://localhost:1234/v1"),
model: z.string().default("qwen2.5-32b"),
api_key: z.string().default("not-needed"),
}),
alerts: z
.object({
telegram_token: z.string(),
chat_id: z.string(),
})
.optional(),
thresholds: z
.object({
warn_below: z.number().default(3.5),
alert_below: z.number().default(3),
})
.default({}),
});
export type Config = z.infer<typeof configSchema>;
let _config: Config | null = null;
export function loadConfig(path = "./config.json"): Config {
if (_config) return _config;
const raw = JSON.parse(readFileSync(path, "utf-8"));
_config = configSchema.parse(raw);
return _config;
}