-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathconfig.ts
More file actions
93 lines (83 loc) · 1.62 KB
/
config.ts
File metadata and controls
93 lines (83 loc) · 1.62 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
export interface DemoConfig {
ai: {
enabled: boolean;
};
bootId: string;
database: {
enabled: boolean;
};
queries: {
enabled: boolean;
};
seededAt?: string;
streams?: {
url: string;
};
}
const TRUE_ENV_VALUES = new Set(["1", "true", "yes", "on"]);
const FALSE_ENV_VALUES = new Set(["0", "false", "no", "off"]);
function parseOptionalBooleanEnv(
value: string | undefined,
): boolean | undefined {
const normalized = value?.trim().toLowerCase();
if (!normalized) {
return undefined;
}
if (TRUE_ENV_VALUES.has(normalized)) {
return true;
}
if (FALSE_ENV_VALUES.has(normalized)) {
return false;
}
return undefined;
}
export function resolveDemoAiEnabled(args: {
anthropicApiKey: string;
envValue?: string;
}): boolean {
if (args.anthropicApiKey.trim().length === 0) {
return false;
}
return parseOptionalBooleanEnv(args.envValue) ?? true;
}
export function buildDemoConfig(args: {
aiEnabled: boolean;
bootId: string;
databaseEnabled: boolean;
queryInsightsEnabled?: boolean;
seededAt?: string | null;
streamsUrl?: string;
}): DemoConfig {
const {
aiEnabled,
bootId,
databaseEnabled,
queryInsightsEnabled = databaseEnabled,
seededAt,
streamsUrl,
} = args;
return {
ai: {
enabled: aiEnabled,
},
bootId,
database: {
enabled: databaseEnabled,
},
queries: {
enabled: queryInsightsEnabled,
},
...(seededAt
? {
seededAt,
}
: {}),
...(streamsUrl
? {
streams: {
url: streamsUrl,
},
}
: {}),
};
}