Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/anirudh-sohaney_openfin.json
T

1 line
16 KiB
JSON

{"repo": "anirudh-sohaney/openfin", "files": {"src/OpenFin/main/webapp/static/js/config.js": {"c61344ac0b679733ef7c5e4f95073c63c7401609": {"t": 1785746667.2861226, "n": 7395, "h": "18c1fa5358f23b56", "c": "/* ═══════════════════════════════════════════════════════════════════════════\n OpenFin Webapp — Config Page Logic\n Provider selection, API key management, lock/change mechanism\n ═══════════════════════════════════════════════════════════════════════════ */\n\n// Provider base URLs for display\nconst PROVIDER_BASE_URLS = {\n openai: \"https://api.openai.com/v1\",\n anthropic: \"https://api.anthropic.com/v1\",\n gemini: \"https://generativelanguage.googleapis.com/v1beta\",\n openrouter: \"https://openrouter.ai/api/v1\",\n xai: \"https://api.x.ai/v1\",\n deepseek: \"https://api.deepseek.com/v1\",\n groq: \"https://api.groq.com/openai/v1\",\n together: \"https://api.together.xyz/v1\",\n mistral: \"https://api.mistral.ai/v1\",\n};\n\n/**\n * Initialize the config page.\n */\nasync function initConfig() {\n setupThemeToggle();\n await loadConfigValues();\n\n // Provider dropdown change → update base URL display\n const provSelect = document.getElementById('configProvider');\n if (provSelect) {\n provSelect.addEventListener('change', () => updateBaseUrlDisplay());\n }\n\n // Change buttons\n document.getElementById('llmKeyChangeBtn')?.addEventListener('click', () => unlockField('llmkey'));\n document.getElementById('tavilyChangeBtn')?.addEventListener('click', () => unlockField('tavily'));\n}\n\n/**\n * Set up the theme toggle buttons.\n */\nfunction setupThemeToggle() {\n const toggleBtns = document.querySelectorAll('.toggle-btn');\n toggleBtns.forEach(btn => {\n btn.addEventListener('click', () => {\n const theme = btn.dataset.themeVal;\n setTheme(theme);\n });\n });\n}\n\n/**\n * Set the theme (dark/light) and persist to localStorage.\n */\nfunction setTheme(theme) {\n document.documentElement.setAttribute('data-theme', theme);\n localStorage.setItem('openfin-theme', theme);\n\n document.querySelectorAll('.toggle-btn').forEach(btn => {\n btn.classList.toggle('active', btn.getAttribute('data-theme-val') === theme);\n });\n}\n\n/**\n * Update the base URL display when provider changes.\n */\nfunction updateBaseUrlDisplay() {\n const provSelect = document.getElementById('configProvider');\n const baseUrlEl = document.getElementById('llmBaseUrl');\n const provider = provSelect.value;\n\n if (provider && PROVIDER_BASE_URLS[provider]) {\n baseUrlEl.textContent = `Base URL: ${PROVIDER_BASE_URLS[provider]}`;\n } else {\n baseUrlEl.textContent = 'Base URL: —';\n }\n}\n\n/**\n * Unlock a locked field for editing (triggered by Change button).\n */\nfunction unlockField(type) {\n const row = document.getElementById(`${type}-row`);\n if (!row) return;\n\n const input = row.querySelector('input');\n const changeBtn = row.querySelector('.config-change-btn');\n\n if (input) {\n input.disabled = false;\n input.value = '';\n input.focus();\n }\n if (changeBtn) {\n changeBtn.style.display = 'none';\n }\n}\n\n/**\n * Lock a field after saving (hide key, disable input, show Change button).\n */\nfunction lockField(type, maskedValue) {\n const row = document.getElementById(`${type}-row`);\n if (!row) return;\n\n const input = row.querySelector('input');\n const changeBtn = row.querySelector('.config-change-btn');\n\n if (input) {\n input.value = maskedValue || '';\n input.disabled = true;\n }\n if (changeBtn) {\n changeBtn.style.display = '';\n }\n}\n\n/**\n * Load config values from the server and populate form fields.\n * Locks fields that have values already saved.\n */\nasync function loadConfigValues() {\n try {\n const config = await fetchConfig();\n\n // Provider dropdown\n const provSelect = document.getElementById('configProvider');\n if (provSelect && config.provider) {\n provSelect.value = config.provider;\n }\n\n // LLM API Key\n const llmInput = document.getElementById('configLlmKey');\n if (llmInput) {\n if (config.llm_key) {\n // Has saved key — lock it\n lockField('llmkey', config.llm_key);\n } else {\n // No saved key — leave unlocked\n llmInput.disabled = false;\n document.getElementById('llmKeyChangeBtn').style.display = 'none';\n }\n }\n\n // Tavily key\n const tavilyInput = document.getElementById('configTavily');\n if (tavilyInput) {\n if (config.tavily_key) {\n lockField('tavily', config.tavily_key);\n } else {\n tavilyInput.disabled = false;\n document.getElementById('tavilyChangeBtn').style.display = 'none';\n }\n }\n\n // Model\n const modelInput = document.getElementById('configModel');\n if (modelInput) {\n if (config.llm_model) {\n modelInput.value = config.llm_model;\n modelInput.disabled = true;\n } else {\n modelInput.disabled = false;\n }\n }\n\n // Update base URL display\n updateBaseUrlDisplay();\n } catch (err) {\n console.warn('Failed to load config:', err.message);\n }\n}\n\n/**\n * Save config values from the form to the server.\n */\nasync function saveConfigValues() {\n const statusEl = document.getElementById('configStatus');\n statusEl.textContent = 'Saving...';\n statusEl.className = 'config-status';\n\n const config = {};\n\n // Provider\n const provSelect = document.getElementById('configProvider');\n if (provSelect) {\n const val = provSelect.value.trim();\n if (val) {\n config.provider = val;\n }\n }\n\n // LLM API Key — only include if field is unlocked (being changed)\n const llmInput = document.getElementById('configLlmKey');\n if (llmInput && !llmInput.disabled && llmInput.value.trim()) {\n config.llm_key = llmInput.value.trim();\n }\n\n // Tavily key — only include if field is unlocked\n const tavilyInput = document.getElementById('configTavily');\n if (tavilyInput && !tavilyInput.disabled && tavilyInput.value.trim()) {\n config.tavily_key = tavilyInput.value.trim();\n }\n\n // Model — only include if field is unlocked (first time) or always include if changed\n const modelInput = document.getElementById('configModel');\n if (modelInput && !modelInput.disabled && modelInput.value.trim()) {\n config.llm_model = modelInput.value.trim();\n }\n\n // Validate: need at least a provider if providing LLM key\n if (config.llm_key && !config.provider) {\n statusEl.textContent = 'Please select an LLM provider first.';\n statusEl.className = 'config-status error';\n return;\n }\n\n try {\n await saveConfig(config);\n statusEl.textContent = 'Settings saved successfully.';\n statusEl.className = 'config-status success';\n\n // Reload to update lock states and show masked values\n await loadConfigValues();\n\n setTimeout(() => { statusEl.textContent = ''; }, 3000);\n } catch (err) {\n statusEl.textContent = `Failed to save: ${err.message}`;\n statusEl.className = 'config-status error';\n }\n}\n\n/**\n * Initialize the theme on page load from localStorage.\n */\nfunction initTheme() {\n const savedTheme = localStorage.getItem('openfin-theme') || 'dark';\n setTheme(savedTheme);\n}\n"}, "769193c88cfb23429861343455364cd4f566720a": {"t": 1785766707.2514439, "n": 7395, "h": "18c1fa5358f23b56", "c": "/* ═══════════════════════════════════════════════════════════════════════════\n OpenFin Webapp — Config Page Logic\n Provider selection, API key management, lock/change mechanism\n ═══════════════════════════════════════════════════════════════════════════ */\n\n// Provider base URLs for display\nconst PROVIDER_BASE_URLS = {\n openai: \"https://api.openai.com/v1\",\n anthropic: \"https://api.anthropic.com/v1\",\n gemini: \"https://generativelanguage.googleapis.com/v1beta\",\n openrouter: \"https://openrouter.ai/api/v1\",\n xai: \"https://api.x.ai/v1\",\n deepseek: \"https://api.deepseek.com/v1\",\n groq: \"https://api.groq.com/openai/v1\",\n together: \"https://api.together.xyz/v1\",\n mistral: \"https://api.mistral.ai/v1\",\n};\n\n/**\n * Initialize the config page.\n */\nasync function initConfig() {\n setupThemeToggle();\n await loadConfigValues();\n\n // Provider dropdown change → update base URL display\n const provSelect = document.getElementById('configProvider');\n if (provSelect) {\n provSelect.addEventListener('change', () => updateBaseUrlDisplay());\n }\n\n // Change buttons\n document.getElementById('llmKeyChangeBtn')?.addEventListener('click', () => unlockField('llmkey'));\n document.getElementById('tavilyChangeBtn')?.addEventListener('click', () => unlockField('tavily'));\n}\n\n/**\n * Set up the theme toggle buttons.\n */\nfunction setupThemeToggle() {\n const toggleBtns = document.querySelectorAll('.toggle-btn');\n toggleBtns.forEach(btn => {\n btn.addEventListener('click', () => {\n const theme = btn.dataset.themeVal;\n setTheme(theme);\n });\n });\n}\n\n/**\n * Set the theme (dark/light) and persist to localStorage.\n */\nfunction setTheme(theme) {\n document.documentElement.setAttribute('data-theme', theme);\n localStorage.setItem('openfin-theme', theme);\n\n document.querySelectorAll('.toggle-btn').forEach(btn => {\n btn.classList.toggle('active', btn.getAttribute('data-theme-val') === theme);\n });\n}\n\n/**\n * Update the base URL display when provider changes.\n */\nfunction updateBaseUrlDisplay() {\n const provSelect = document.getElementById('configProvider');\n const baseUrlEl = document.getElementById('llmBaseUrl');\n const provider = provSelect.value;\n\n if (provider && PROVIDER_BASE_URLS[provider]) {\n baseUrlEl.textContent = `Base URL: ${PROVIDER_BASE_URLS[provider]}`;\n } else {\n baseUrlEl.textContent = 'Base URL: —';\n }\n}\n\n/**\n * Unlock a locked field for editing (triggered by Change button).\n */\nfunction unlockField(type) {\n const row = document.getElementById(`${type}-row`);\n if (!row) return;\n\n const input = row.querySelector('input');\n const changeBtn = row.querySelector('.config-change-btn');\n\n if (input) {\n input.disabled = false;\n input.value = '';\n input.focus();\n }\n if (changeBtn) {\n changeBtn.style.display = 'none';\n }\n}\n\n/**\n * Lock a field after saving (hide key, disable input, show Change button).\n */\nfunction lockField(type, maskedValue) {\n const row = document.getElementById(`${type}-row`);\n if (!row) return;\n\n const input = row.querySelector('input');\n const changeBtn = row.querySelector('.config-change-btn');\n\n if (input) {\n input.value = maskedValue || '';\n input.disabled = true;\n }\n if (changeBtn) {\n changeBtn.style.display = '';\n }\n}\n\n/**\n * Load config values from the server and populate form fields.\n * Locks fields that have values already saved.\n */\nasync function loadConfigValues() {\n try {\n const config = await fetchConfig();\n\n // Provider dropdown\n const provSelect = document.getElementById('configProvider');\n if (provSelect && config.provider) {\n provSelect.value = config.provider;\n }\n\n // LLM API Key\n const llmInput = document.getElementById('configLlmKey');\n if (llmInput) {\n if (config.llm_key) {\n // Has saved key — lock it\n lockField('llmkey', config.llm_key);\n } else {\n // No saved key — leave unlocked\n llmInput.disabled = false;\n document.getElementById('llmKeyChangeBtn').style.display = 'none';\n }\n }\n\n // Tavily key\n const tavilyInput = document.getElementById('configTavily');\n if (tavilyInput) {\n if (config.tavily_key) {\n lockField('tavily', config.tavily_key);\n } else {\n tavilyInput.disabled = false;\n document.getElementById('tavilyChangeBtn').style.display = 'none';\n }\n }\n\n // Model\n const modelInput = document.getElementById('configModel');\n if (modelInput) {\n if (config.llm_model) {\n modelInput.value = config.llm_model;\n modelInput.disabled = true;\n } else {\n modelInput.disabled = false;\n }\n }\n\n // Update base URL display\n updateBaseUrlDisplay();\n } catch (err) {\n console.warn('Failed to load config:', err.message);\n }\n}\n\n/**\n * Save config values from the form to the server.\n */\nasync function saveConfigValues() {\n const statusEl = document.getElementById('configStatus');\n statusEl.textContent = 'Saving...';\n statusEl.className = 'config-status';\n\n const config = {};\n\n // Provider\n const provSelect = document.getElementById('configProvider');\n if (provSelect) {\n const val = provSelect.value.trim();\n if (val) {\n config.provider = val;\n }\n }\n\n // LLM API Key — only include if field is unlocked (being changed)\n const llmInput = document.getElementById('configLlmKey');\n if (llmInput && !llmInput.disabled && llmInput.value.trim()) {\n config.llm_key = llmInput.value.trim();\n }\n\n // Tavily key — only include if field is unlocked\n const tavilyInput = document.getElementById('configTavily');\n if (tavilyInput && !tavilyInput.disabled && tavilyInput.value.trim()) {\n config.tavily_key = tavilyInput.value.trim();\n }\n\n // Model — only include if field is unlocked (first time) or always include if changed\n const modelInput = document.getElementById('configModel');\n if (modelInput && !modelInput.disabled && modelInput.value.trim()) {\n config.llm_model = modelInput.value.trim();\n }\n\n // Validate: need at least a provider if providing LLM key\n if (config.llm_key && !config.provider) {\n statusEl.textContent = 'Please select an LLM provider first.';\n statusEl.className = 'config-status error';\n return;\n }\n\n try {\n await saveConfig(config);\n statusEl.textContent = 'Settings saved successfully.';\n statusEl.className = 'config-status success';\n\n // Reload to update lock states and show masked values\n await loadConfigValues();\n\n setTimeout(() => { statusEl.textContent = ''; }, 3000);\n } catch (err) {\n statusEl.textContent = `Failed to save: ${err.message}`;\n statusEl.className = 'config-status error';\n }\n}\n\n/**\n * Initialize the theme on page load from localStorage.\n */\nfunction initTheme() {\n const savedTheme = localStorage.getItem('openfin-theme') || 'dark';\n setTheme(savedTheme);\n}\n"}}}}