forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.dart
More file actions
99 lines (69 loc) · 3.22 KB
/
Copy pathenv.dart
File metadata and controls
99 lines (69 loc) · 3.22 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
94
95
96
97
98
99
abstract class Env {
static const productionApiBaseUrl = 'https://api.omi.me/';
static const productionAgentProxyWsUrl = 'wss://agent.omi.me/v1/agent/ws';
static late final EnvFields _instance;
static String? _apiBaseUrlOverride;
static String? _agentProxyWsUrlOverride;
static bool isTestFlight = false;
static void init(EnvFields instance) {
_instance = instance;
}
static void overrideApiBaseUrl(String url) {
_apiBaseUrlOverride = url;
}
static void clearApiBaseUrlOverrideForTesting() {
_apiBaseUrlOverride = null;
}
static void overrideAgentProxyWsUrl(String url) {
_agentProxyWsUrlOverride = url;
}
static String? get openAIAPIKey => _instance.openAIAPIKey;
static String? get posthogApiKey => _instance.posthogApiKey;
// static String? get apiBaseUrl => 'https://omi-backend.ngrok.app/';
static String? get apiBaseUrl => _apiBaseUrlOverride ?? _instance.apiBaseUrl;
/// Production-family packages have one pinned backend authority. This runs
/// during startup so a misconfigured signing group fails before networking.
static void validateStartupRouting({required bool productionFamily, String? configuredApiBaseUrl}) {
if (!productionFamily) return;
final normalized = (configuredApiBaseUrl ?? apiBaseUrl ?? '').trim().replaceFirst(RegExp(r'/+$'), '');
if (normalized != productionApiBaseUrl.replaceFirst(RegExp(r'/+$'), '')) {
throw StateError('Production packages require API_BASE_URL=https://api.omi.me/');
}
if (_agentProxyWsUrlFor(normalized) != productionAgentProxyWsUrl) {
throw StateError('Production packages require the production agent WebSocket endpoint.');
}
}
static void requireProductionRouting() => validateStartupRouting(productionFamily: true);
/// WebSocket URL for the agent proxy service.
/// Derives from apiBaseUrl: api.omi.me → agent.omi.me, api.omiapi.com → agent.omiapi.com.
/// Can be overridden via Env.overrideAgentProxyWsUrl() for local testing.
static String get agentProxyWsUrl {
if (_agentProxyWsUrlOverride != null) return _agentProxyWsUrlOverride!;
return _agentProxyWsUrlFor(apiBaseUrl ?? productionApiBaseUrl);
}
static String _agentProxyWsUrlFor(String base) {
final host = Uri.parse(base).host.replaceFirst('api.', 'agent.');
return 'wss://$host/v1/agent/ws';
}
static String? get googleMapsApiKey => _instance.googleMapsApiKey;
static String? get intercomAppId => _instance.intercomAppId;
static String? get intercomIOSApiKey => _instance.intercomIOSApiKey;
static String? get intercomAndroidApiKey => _instance.intercomAndroidApiKey;
static String? get googleClientId => _instance.googleClientId;
static String? get googleClientSecret => _instance.googleClientSecret;
static bool get useWebAuth => _instance.useWebAuth ?? false;
static bool get useAuthCustomToken => _instance.useAuthCustomToken ?? false;
}
abstract class EnvFields {
String? get openAIAPIKey;
String? get posthogApiKey;
String? get apiBaseUrl;
String? get googleMapsApiKey;
String? get intercomAppId;
String? get intercomIOSApiKey;
String? get intercomAndroidApiKey;
String? get googleClientId;
String? get googleClientSecret;
bool? get useWebAuth;
bool? get useAuthCustomToken;
}