()
| 27 | * Returns null if the API is unavailable or the file doesn't exist. |
| 28 | */ |
| 29 | export async function loadPersistedConfig(): Promise<PersistedConfig | null> { |
| 30 | try { |
| 31 | const res = await fetch(CONFIG_API); |
| 32 | if (res.ok) { |
| 33 | const data: unknown = await res.json(); |
| 34 | if (isLegacyConfig(data)) { |
| 35 | return { llm: data }; |
| 36 | } |
| 37 | if (typeof data === 'object' && data !== null && 'llm' in data) { |
| 38 | return data as PersistedConfig; |
| 39 | } |
| 40 | } |
| 41 | } catch { |
| 42 | // API not available (production / network error) |
| 43 | } |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Save the full config to ~/.openroom/config.json via the dev-server API. |
no test coverage detected