()
| 59 | let cancelled = false; |
| 60 | |
| 61 | async function loadInitialState() { |
| 62 | try { |
| 63 | const next = await api<Snapshot>('/api/state'); |
| 64 | let nextConfig = mergeConfig(next.config); |
| 65 | |
| 66 | if (window.clawDesktop?.getBootstrap) { |
| 67 | try { |
| 68 | const desktop = await window.clawDesktop.getBootstrap() as DesktopBootstrap; |
| 69 | setEncryptionAvailable(Boolean(desktop.encryptionAvailable)); |
| 70 | setAppInfo(desktop.appInfo || null); |
| 71 | if (desktop.upstreamApiKey) { |
| 72 | nextConfig = { |
| 73 | ...nextConfig, |
| 74 | upstreamApiKey: desktop.upstreamApiKey, |
| 75 | }; |
| 76 | await api('/api/config', { |
| 77 | method: 'POST', |
| 78 | body: nextConfig, |
| 79 | }); |
| 80 | } |
| 81 | } catch (error) { |
| 82 | console.warn('Failed to hydrate desktop bootstrap', error); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (!cancelled) { |
| 87 | setSnapshot(next); |
| 88 | setConfig(nextConfig); |
| 89 | setInitialHydrated(true); |
| 90 | |
| 91 | api<{ skills: Array<{ name: string; description: string }> }>('/api/skills') |
| 92 | .then(r => { if (!cancelled) setSkills(r.skills || []) }) |
| 93 | .catch(() => {}); |
| 94 | } |
| 95 | } catch (error) { |
| 96 | if (!cancelled) { |
| 97 | setErrorMessage(error instanceof Error ? error.message : String(error)); |
| 98 | setInitialHydrated(true); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void loadInitialState(); |
| 104 |
no test coverage detected