| 32 | // --- Public API --- |
| 33 | |
| 34 | export function initApiKeyDialog() { |
| 35 | dialog = document.getElementById("apikey-dialog"); |
| 36 | openBtn = document.getElementById("open-apikey-btn"); |
| 37 | closeBtn = document.getElementById("close-apikey-btn"); |
| 38 | saveBtn = document.getElementById("save-apikey-btn"); |
| 39 | restartBtn = document.getElementById("restart-apikey-btn"); |
| 40 | providerSelect = document.getElementById("apikey-provider-select"); |
| 41 | apiKeyInput = document.getElementById("apikey-input"); |
| 42 | baseUrlInput = document.getElementById("apikey-baseurl-input"); |
| 43 | baseUrlGroup = document.getElementById("apikey-baseurl-group"); |
| 44 | modelIdInput = document.getElementById("apikey-modelid-input"); |
| 45 | modelIdGroup = document.getElementById("apikey-modelid-group"); |
| 46 | protocolSelect = document.getElementById("apikey-protocol-select"); |
| 47 | protocolGroup = document.getElementById("apikey-protocol-group"); |
| 48 | apikeySection = document.getElementById("apikey-apikey-section"); |
| 49 | oauthSection = document.getElementById("apikey-oauth-section"); |
| 50 | oauthLoginBtn = document.getElementById("oauth-login-btn"); |
| 51 | oauthLogoutBtn = document.getElementById("oauth-logout-btn"); |
| 52 | oauthStatusIndicator = document.getElementById("oauth-status-indicator"); |
| 53 | oauthStatusText = document.getElementById("oauth-status-text"); |
| 54 | statusEl = document.getElementById("apikey-status"); |
| 55 | |
| 56 | if (!dialog) return; |
| 57 | |
| 58 | if (openBtn) { |
| 59 | openBtn.addEventListener("click", open); |
| 60 | } |
| 61 | if (closeBtn) { |
| 62 | closeBtn.addEventListener("click", close); |
| 63 | } |
| 64 | if (saveBtn) { |
| 65 | saveBtn.addEventListener("click", handleSave); |
| 66 | } |
| 67 | if (restartBtn) { |
| 68 | restartBtn.addEventListener("click", handleRestart); |
| 69 | } |
| 70 | if (providerSelect) { |
| 71 | providerSelect.addEventListener("change", updateProviderUI); |
| 72 | } |
| 73 | if (oauthLoginBtn) { |
| 74 | oauthLoginBtn.addEventListener("click", handleOAuthLogin); |
| 75 | } |
| 76 | if (oauthLogoutBtn) { |
| 77 | oauthLogoutBtn.addEventListener("click", handleOAuthLogout); |
| 78 | } |
| 79 | if (baseUrlInput) { |
| 80 | baseUrlInput.addEventListener("input", updateModelIdVisibility); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * 根据当前连接状态更新按钮外观 |