()
| 26 | export const createCliStatusFallback = (): CLIStatus => buildOptimisticStatus(); |
| 27 | |
| 28 | export async function fetchCliStatusSnapshot(): Promise<CLIStatus> { |
| 29 | const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? ''; |
| 30 | try { |
| 31 | const response = await fetch(`${API_BASE}/api/settings/cli-status`); |
| 32 | if (!response.ok) { |
| 33 | throw new Error(`Failed to fetch CLI status: ${response.status}`); |
| 34 | } |
| 35 | |
| 36 | const payload = (await response.json()) as CLIStatus; |
| 37 | const optimistic = buildOptimisticStatus(); |
| 38 | |
| 39 | for (const option of CLI_OPTIONS) { |
| 40 | const entry = payload[option.id]; |
| 41 | if (!entry) { |
| 42 | continue; |
| 43 | } |
| 44 | optimistic[option.id] = { |
| 45 | ...optimistic[option.id], |
| 46 | ...entry, |
| 47 | checking: false, |
| 48 | available: entry.available ?? entry.installed ?? optimistic[option.id]?.available ?? false, |
| 49 | configured: entry.configured ?? entry.installed ?? optimistic[option.id]?.configured ?? false, |
| 50 | models: entry.models ?? option.models?.map((model) => model.id), |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | return optimistic; |
| 55 | } catch (error) { |
| 56 | console.warn('Failed to fetch CLI status from API:', error); |
| 57 | return buildOptimisticStatus(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | export function useCLI({ projectId }: UseCLIOptions) { |
| 62 | const [cliOptions, setCLIOptions] = useState<CLIOption[]>(() => CLI_OPTIONS.map((option) => ({ ...option }))); |
no test coverage detected