-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathenv.ts
More file actions
55 lines (50 loc) · 1.52 KB
/
Copy pathenv.ts
File metadata and controls
55 lines (50 loc) · 1.52 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
export const DEFAULT_INTELLIGENCE_API_URL =
"https://api.intelligence.copilotkit.ai";
export const DEFAULT_INTELLIGENCE_GATEWAY_WS_URL =
"wss://realtime.intelligence.copilotkit.ai";
export const DEFAULT_INTELLIGENCE_CHANNEL_NAME = "open-tag";
export interface AppEnvironment {
agentUrl: string;
agentAuthHeader?: string;
intelligenceApiKey: string;
intelligenceApiUrl: string;
intelligenceGatewayWsUrl: string;
channelName: string;
port: number;
}
function required(env: NodeJS.ProcessEnv, name: string): string {
const value = env[name];
if (!value) {
throw new Error(`Missing required env var: ${name}`);
}
return value;
}
export function parsePort(
raw: string | undefined,
defaultPort = 3000,
name = "PORT",
): number {
if (raw === undefined) return defaultPort;
const port = Number(raw);
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
throw new Error(`Invalid ${name}: "${raw}"`);
}
return port;
}
export function readEnvironment(
env: NodeJS.ProcessEnv = process.env,
): AppEnvironment {
return {
agentUrl: required(env, "AGENT_URL"),
agentAuthHeader: env.AGENT_AUTH_HEADER,
intelligenceApiKey: required(env, "INTELLIGENCE_API_KEY"),
intelligenceApiUrl:
env.INTELLIGENCE_API_URL ?? DEFAULT_INTELLIGENCE_API_URL,
intelligenceGatewayWsUrl:
env.INTELLIGENCE_GATEWAY_WS_URL ??
DEFAULT_INTELLIGENCE_GATEWAY_WS_URL,
channelName:
env.INTELLIGENCE_CHANNEL_NAME ?? DEFAULT_INTELLIGENCE_CHANNEL_NAME,
port: parsePort(env.PORT),
};
}