Repository navigation
Expand file tree
/
Copy pathenv.validation.ts
More file actions
73 lines (68 loc) · 2.05 KB
/
Copy pathenv.validation.ts
File metadata and controls
73 lines (68 loc) · 2.05 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { z } from './lib/zod';
import { normalizeLiteLlmUrl } from './modules/llm/llm.config';
export const envValidationSchema = z
.object({
NODE_ENV: z
.enum(['development', 'production', 'test'])
.default('development'),
SERVER_PORT: z.coerce.number().int().min(1).max(65535).default(3000),
SERVER_BASE_URL: z.url().default('http://localhost:3000'),
MONGODB_URI: z.string().min(1),
BETTER_AUTH_SECRET: z
.string()
.min(1)
.default('example-only-secret-do-not-use-in-production-32'),
BETTER_AUTH_URL: z.url().default('http://localhost:3000'),
GITHUB_CLIENT_ID: z.string().default(''),
GITHUB_CLIENT_SECRET: z.string().default(''),
GOOGLE_CLIENT_ID: z.string().default(''),
GOOGLE_CLIENT_SECRET: z.string().default(''),
LITELLM_BASE_URL: z
.string()
.trim()
.optional()
.refine((value) => {
if (!value) return true;
try {
normalizeLiteLlmUrl(value);
return true;
} catch {
return false;
}
}, 'Invalid LiteLLM API base URL'),
LITELLM_TEAM_KEY: z.string().trim().optional(),
LITELLM_TEAM_ID: z.string().trim().optional(),
LITELLM_JSON_OBJECT_MODELS: z.string().trim().default(''),
LITELLM_DEPLOYMENT_ID: z
.string()
.trim()
.regex(/^[a-zA-Z0-9_-]+$/)
.optional(),
LITELLM_TIMEOUT_MS: z.coerce
.number()
.int()
.min(1)
.max(3_600_000)
.default(300_000),
LOG_LEVEL: z.string().default('debug'),
LOG_DIR: z.string().default('./logs'),
})
.superRefine((env, ctx) => {
const keys = [
'LITELLM_BASE_URL',
'LITELLM_TEAM_KEY',
'LITELLM_TEAM_ID',
'LITELLM_DEPLOYMENT_ID',
] as const;
if (keys.some((key) => Boolean(env[key]))) {
for (const key of keys) {
if (!env[key])
ctx.addIssue({
code: 'custom',
path: [key],
message:
'All LiteLLM connection and identity settings are required when enabling team models',
});
}
}
});