MCPcopy
hub / github.com/opactorai/Claudable / fetchCliStatusSnapshot

Function fetchCliStatusSnapshot

hooks/useCLI.ts:28–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26export const createCliStatusFallback = (): CLIStatus => buildOptimisticStatus();
27
28export 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
61export function useCLI({ projectId }: UseCLIOptions) {
62 const [cliOptions, setCLIOptions] = useState<CLIOption[]>(() => CLI_OPTIONS.map((option) => ({ ...option })));

Callers 4

CreateProjectModalFunction · 0.90
GlobalSettingsFunction · 0.90
HomePageFunction · 0.90
useCLIFunction · 0.85

Calls 1

buildOptimisticStatusFunction · 0.85

Tested by

no test coverage detected