Repository navigation
Expand file tree
/
Copy pathenv.ts
More file actions
55 lines (50 loc) · 1.98 KB
/
Copy pathenv.ts
File metadata and controls
55 lines (50 loc) · 1.98 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
/**
* Typed environment access for the knowledge module. Ported in spirit from
* the knowledge service config, but every key is OPTIONAL: missing
* LLM/embedding keys degrade gracefully (stub distillation + keyword-only
* search) instead of throwing. Bun auto-loads backend/.env.
*/
function opt(name: string, fallback: string): string {
return process.env[name] ?? fallback;
}
export const env = {
/** Postgres — the retrieval store (tsvector + pgvector). Inside the sandbox
* gateway process GATEWAY_DATABASE_URL carries the restricted role; it must
* win WITHOUT the gateway env file defining DATABASE_URL, because deploy
* scripts source backend.env and gateway.env into one shell and a gateway
* DATABASE_URL would shadow the privileged one (it broke a release gate). */
databaseUrl:
process.env.GATEWAY_DATABASE_URL ??
opt("DATABASE_URL", "postgres://postgres@localhost:5432/useagent"),
/** Default org when the caller resolves none (headers wired later). */
defaultOrg: opt("KNOWLEDGE_DEFAULT_ORG", "useagent-dev"),
/** Distillation LLM — OpenRouter (OpenAI-compatible). Absent key → stub. */
distill: {
get baseUrl() {
return opt("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1");
},
get apiKey(): string | null {
return process.env.OPENROUTER_API_KEY ?? null;
},
get model() {
return opt("DISTILL_MODEL", "z-ai/glm-5.2");
},
},
/** Embeddings — OpenAI text-embedding-3-large @ 1024 dims. Absent key → no vectors. */
embed: {
get baseUrl() {
return opt("OPENAI_BASE_URL", "https://api.openai.com/v1");
},
get apiKey(): string | null {
return process.env.OPENAI_API_KEY ?? null;
},
get model() {
return opt("EMBED_MODEL", "text-embedding-3-large");
},
get dimensions() {
return Number(opt("EMBED_DIMENSIONS", "1024"));
},
},
} as const;
/** Vector column dimensionality — the store column and embeddings must agree. */
export const EMBED_DIMS = 1024;