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

Function saveGlobalSettings

components/settings/GlobalSettings.tsx:207–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205 }, [isOpen, loadAllTokens, loadGlobalSettings, checkCLIStatus]);
206
207 const saveGlobalSettings = async () => {
208 setIsLoading(true);
209 setSaveMessage(null);
210
211 try {
212 const payload = JSON.parse(JSON.stringify(globalSettings));
213 if (payload?.cli_settings) {
214 for (const [cli, config] of Object.entries(payload.cli_settings)) {
215 if (config && typeof config === 'object' && 'model' in config) {
216 (config as any).model = normalizeModelId(cli, (config as any).model as string);
217 }
218 }
219 }
220
221 const response = await fetch(`${API_BASE}/api/settings/global`, {
222 method: 'PUT',
223 headers: { 'Content-Type': 'application/json' },
224 body: JSON.stringify(payload)
225 });
226
227 if (!response.ok) {
228 throw new Error('Failed to save settings');
229 }
230
231 setSaveMessage({
232 type: 'success',
233 text: 'Settings saved successfully!'
234 });
235 // make sure context stays in sync
236 try {
237 await refreshGlobalSettings();
238 } catch {}
239
240 // Clear message after 3 seconds
241 setTimeout(() => setSaveMessage(null), 3000);
242
243 } catch (error) {
244 console.error('Failed to save global settings:', error);
245 setSaveMessage({
246 type: 'error',
247 text: 'Failed to save settings. Please try again.'
248 });
249
250 // Clear error message after 5 seconds
251 setTimeout(() => setSaveMessage(null), 5000);
252 } finally {
253 setIsLoading(false);
254 }
255 };
256
257
258 const setDefaultCLI = (cliId: string) => {

Callers

nothing calls this directly

Calls 1

normalizeModelIdFunction · 0.90

Tested by

no test coverage detected