MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / handleSave

Function handleSave

web/js/api-key-dialog.js:204–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202}
203
204async function handleSave() {
205 const key = apiKeyInput.value.trim();
206 const provider = providerSelect.value;
207 const baseUrl = baseUrlInput.value.trim();
208 const modelId = modelIdInput ? modelIdInput.value.trim() : "";
209 const apiProtocol = protocolSelect ? protocolSelect.value : "";
210
211 // If OAuth is selected, we don't handle it here but it shouldn't happen as save button is hidden
212 const meta = state.config?.supportedProviders?.[provider];
213 if (meta?.authType === "oauth") return;
214
215 const updates = { provider };
216 if (baseUrl !== state.config.baseUrl) {
217 updates.baseUrl = baseUrl;
218 }
219 if (modelId !== (state.config.modelId || "")) {
220 updates.modelId = modelId;
221 }
222 const hasCustomUrl = baseUrl.length > 0;
223 if (hasCustomUrl && apiProtocol !== (state.config.apiProtocol || "openai-completions")) {
224 updates.apiProtocol = apiProtocol;
225 } else if (!hasCustomUrl && state.config.apiProtocol) {
226 updates.apiProtocol = "";
227 }
228
229 if (key && key !== "***************************************************" && key !== state.config.apiKey) {
230 updates.key = key;
231 }
232
233 try {
234 saveBtn.disabled = true;
235 const res = await saveConfigData(updates);
236
237 state.config.provider = res.provider;
238 state.config.baseUrl = res.baseUrl || "";
239 state.config.modelId = res.modelId || "";
240 state.config.apiProtocol = res.apiProtocol || "";
241 if (updates.key) {
242 state.config.hasApiKey = true;
243 state.config.apiKey = updates.key;
244 }
245
246 populateForm();
247 state.restartRequired = !!res.requiresRestart;
248 updateApiKeyButton();
249 refreshWebSocketConnectionPreference();
250
251 if (res.requiresRestart) {
252 setStatus("Settings saved. Restart service to apply changes.", "warning");
253 updateRestartButton(true);
254 } else {
255 setStatus("Settings saved successfully", "success");
256 setTimeout(() => close(), 1200);
257 }
258 } catch (err) {
259 setStatus("Save failed: " + err.message, "error");
260 } finally {
261 saveBtn.disabled = false;

Callers

nothing calls this directly

Calls 7

saveConfigDataFunction · 0.90
updateApiKeyButtonFunction · 0.85
populateFormFunction · 0.70
setStatusFunction · 0.70
updateRestartButtonFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected