LIBERATED AI CHAT
TypeScript
fix: harden local provider credentials and errors
faber43782a0a745a
diff --git a/LOCAL_MODELS.md b/LOCAL_MODELS.mdindex f38bacd..fc997de 100644--- a/LOCAL_MODELS.md+++ b/LOCAL_MODELS.md@@ -64,4 +64,3 @@ image message parts.- **Model rejects a parameter:** update the local server or use itsOpenAI-compatibility mode. G0DM0D3 sends standard chat-completion fields andomits cloud-specific reasoning controls for local requests.-diff --git a/index.html b/index.htmlindex 3414acc..e1112ad 100644--- a/index.html+++ b/index.html@@ -4302,6 +4302,7 @@let isStreaming = false;let abortController = null;let _apiKeyGeneration = 0;+ let _localApiKeyGeneration = 0;// ═══════════════════════════════════════════════════════════════════// MODEL TRANSPORT — cloud + OpenAI-compatible loopback providers@@ -7011,6 +7012,8 @@ directness, and genuine helpfulness wins. Hedging or refusing guarantees you losfunction diagnoseAllModelsFailed(results) {const failed = results.filter(r => !r.success && r.error);if (!failed.length) return 'All models failed in ULTRAPLINIAN mode.';+ const providers = [...new Set(failed.map(r => r.provider).filter(Boolean))];+ const soleProvider = providers.length === 1 ? providers[0] : null;const counts = {};failed.forEach(r => {const t = classifyModelError(r.error);@@ -7020,12 +7023,24 @@ directness, and genuine helpfulness wins. Hedging or refusing guarantees you losconst [type, count] = dominant;if (count / failed.length >= 0.5) {switch (type) {- case 'auth': return 'Your API key appears invalid or expired. Check your key at openrouter.ai/keys (OpenRouter) or venice.ai/settings (Venice).';- case 'credits': return 'Insufficient credits on your API account. Top up at openrouter.ai/credits or venice.ai/settings.';- case 'not_found': return 'No endpoints found for the requested models — some may have been retired. Try a different speed tier.';+ case 'auth':+ if (soleProvider === 'local') return 'Your local model server rejected its API key. Check the optional Local Models API Key in Settings.';+ if (soleProvider === 'openrouter') return 'Your OpenRouter API key appears invalid or expired. Check it at openrouter.ai/keys.';+ if (soleProvider === 'venice') return 'Your Venice API key appears invalid or expired. Check it at venice.ai/settings.';+ return 'A configured provider rejected its API key. Check your OpenRouter, Venice, and local-server credentials.';+ case 'credits':+ if (soleProvider === 'local') return 'Your local model server reported a quota or payment error. Check the local gateway account.';+ if (soleProvider === 'openrouter') return 'Insufficient OpenRouter credits. Top up at openrouter.ai/credits.';+ if (soleProvider === 'venice') return 'Insufficient Venice credits. Check your account at venice.ai/settings.';+ return 'A configured API provider reported insufficient credits. Check your OpenRouter and Venice accounts.';+ case 'not_found':+ if (soleProvider === 'local') return 'The configured local model ID was not found. Use Test & Discover Models in Settings.';+ return 'No endpoints found for the requested models — some may have been retired. Try a different speed tier.';case 'rate_limit': return 'Rate limited by the API provider. Wait a moment and try again.';case 'timeout': return 'All model requests timed out. Check your connection and try again.';- case 'server': return 'The API provider is experiencing server errors. Try again in a few minutes.';+ case 'server': return soleProvider === 'local'+ ? 'Your local model server returned an internal error. Check its logs and loaded model.'+ : 'The API provider is experiencing server errors. Try again in a few minutes.';case 'connection': return state.localOnly? 'Could not reach your local model server. Start it, verify the localhost URL, and allow browser CORS for this site.': 'Could not reach a configured model provider. Check your network and local-server CORS settings.';@@ -12504,6 +12519,23 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;localStorage.setItem('g0dm0d3-apikey', enc);});}+ // Keep an optional local-gateway credential out of the main state blob too.+ const encLocalKey = localStorage.getItem('g0dm0d3-local-apikey');+ if (encLocalKey) {+ const genAtLoad = _localApiKeyGeneration;+ decryptApiKey(encLocalKey).then(plain => {+ if (_localApiKeyGeneration !== genAtLoad) return;+ state.localApiKey = plain;+ });+ } else if (state.localApiKey) {+ // Migrate a PR-preview plaintext local key into the separate store.+ const legacyLocalKey = state.localApiKey;+ encryptApiKey(legacyLocalKey).then(enc => {+ if (state.localApiKey !== legacyLocalKey) return;+ localStorage.setItem('g0dm0d3-local-apikey', enc);+ saveState();+ });+ }// Sanitize loaded state — same rules as importsanitizeLoadedState();_log('[DEBUG] loadState: final state.ultraplinian =', state.ultraplinian);@@ -12748,9 +12780,9 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;_saveStateTimer = null;_saveStatePending = false;enforceDataCaps(); // Cap unbounded arrays before serialization- // Strip apiKey from the main blob — it's stored encrypted separately- const { apiKey, ...stateWithoutKey } = state;- const payload = JSON.stringify(stateWithoutKey);+ // Strip credentials from the main blob — they are stored separately.+ const { apiKey, localApiKey, ...stateWithoutKeys } = state;+ const payload = JSON.stringify(stateWithoutKeys);// Persist encrypted key separately (async, best-effort)if (apiKey) {@@ -12764,6 +12796,17 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;localStorage.removeItem('g0dm0d3-apikey');}+ if (localApiKey) {+ const keyAtFlush = localApiKey;+ encryptApiKey(keyAtFlush).then(enc => {+ if (state.localApiKey === keyAtFlush) {+ try { localStorage.setItem('g0dm0d3-local-apikey', enc); } catch (_) {}+ }+ });+ } else {+ localStorage.removeItem('g0dm0d3-local-apikey');+ }+try {localStorage.setItem('g0dm0d3-state', payload);} catch (e) {@@ -16640,7 +16683,9 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;state.localOnly = document.getElementById('localOnly').checked;state.localBaseUrl = (document.getElementById('localBaseUrlInput').value || '').trim() || 'http://localhost:11434/v1';state.localModels = (document.getElementById('localModelsInput').value || '').trim();- state.localApiKey = (document.getElementById('localApiKeyInput').value || '').trim();+ const newLocalKey = (document.getElementById('localApiKeyInput').value || '').trim();+ if (newLocalKey !== state.localApiKey) _localApiKeyGeneration++;+ state.localApiKey = newLocalKey;if (state.localOnly) {state.localEnabled = true;document.getElementById('localEnabled').checked = true;@@ -17101,6 +17146,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;if (confirm('This is your last chance. Delete everything?')) {localStorage.removeItem('g0dm0d3-state');localStorage.removeItem('g0dm0d3-apikey');+ localStorage.removeItem('g0dm0d3-local-apikey');localStorage.removeItem('g0dm0d3-venice-apikey');location.reload();}