File size: 5,032 Bytes
1dbc34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
 * CLI Status Query Hooks
 *
 * React Query hooks for fetching CLI tool status (Claude, GitHub CLI, etc.)
 */

import { useQuery } from '@tanstack/react-query';
import { getElectronAPI } from '@/lib/electron';
import { queryKeys } from '@/lib/query-keys';
import { STALE_TIMES } from '@/lib/query-client';

/**
 * Fetch Claude CLI status
 *
 * @returns Query result with Claude CLI status
 */
export function useClaudeCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.claude(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup) {
        throw new Error('Setup API not available');
      }
      const result = await api.setup.getClaudeStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch Claude status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch GitHub CLI status
 *
 * @returns Query result with GitHub CLI status
 */
export function useGitHubCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.github(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup?.getGhStatus) {
        throw new Error('GitHub CLI status API not available');
      }
      const result = await api.setup.getGhStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch GitHub CLI status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch API keys status
 *
 * @returns Query result with API keys status
 */
export function useApiKeysStatus() {
  return useQuery({
    queryKey: queryKeys.cli.apiKeys(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup) {
        throw new Error('Setup API not available');
      }
      const result = await api.setup.getApiKeys();
      if (!result.success) {
        throw new Error('Failed to fetch API keys');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch platform info
 *
 * @returns Query result with platform info
 */
export function usePlatformInfo() {
  return useQuery({
    queryKey: queryKeys.cli.platform(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup) {
        throw new Error('Setup API not available');
      }
      const result = await api.setup.getPlatform();
      if (!result.success) {
        throw new Error('Failed to fetch platform info');
      }
      return result;
    },
    staleTime: Infinity, // Platform info never changes
  });
}

/**
 * Fetch Cursor CLI status
 *
 * @returns Query result with Cursor CLI status
 */
export function useCursorCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.cursor(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup?.getCursorStatus) {
        throw new Error('Cursor CLI status API not available');
      }
      const result = await api.setup.getCursorStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch Cursor CLI status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch Copilot CLI status
 *
 * @returns Query result with Copilot CLI status
 */
export function useCopilotCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.copilot(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup?.getCopilotStatus) {
        throw new Error('Copilot CLI status API not available');
      }
      const result = await api.setup.getCopilotStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch Copilot CLI status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch Gemini CLI status
 *
 * @returns Query result with Gemini CLI status
 */
export function useGeminiCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.gemini(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup?.getGeminiStatus) {
        throw new Error('Gemini CLI status API not available');
      }
      const result = await api.setup.getGeminiStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch Gemini CLI status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}

/**
 * Fetch OpenCode CLI status
 *
 * @returns Query result with OpenCode CLI status
 */
export function useOpencodeCliStatus() {
  return useQuery({
    queryKey: queryKeys.cli.opencode(),
    queryFn: async () => {
      const api = getElectronAPI();
      if (!api.setup?.getOpencodeStatus) {
        throw new Error('OpenCode CLI status API not available');
      }
      const result = await api.setup.getOpencodeStatus();
      if (!result.success) {
        throw new Error(result.error || 'Failed to fetch OpenCode CLI status');
      }
      return result;
    },
    staleTime: STALE_TIMES.CLI_STATUS,
  });
}