diff options
Diffstat (limited to 'modules/core/ollama-manager.js')
| -rw-r--r-- | modules/core/ollama-manager.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/core/ollama-manager.js b/modules/core/ollama-manager.js index 1201280..5684210 100644 --- a/modules/core/ollama-manager.js +++ b/modules/core/ollama-manager.js @@ -27,6 +27,22 @@ class OllamaManager { return err; } + _sessionRepairNotice() { + // A 401 here means the cookie/Bearer we sent is not in any session store: the store + // moved on (another device signed in, poll race, expired) and this tab kept the old + // value. Clear the local copy so the next attempt is anonymous-demo instead of a + // permanent 401, and say what to do. (2026-11-02) + try { + localStorage.removeItem('webx11_session_id'); + localStorage.removeItem('webx11_session'); + localStorage.removeItem('webx11_encrypted_session'); + document.cookie = 'webx11_session=; path=/; max-age=0'; + } catch (e) {} + this.terminal.print('π Your login session is no longer valid on the server. ' + + 'Open https://webx11.duckdns.org/dashboard.html , sign in with Telegram ' + + '(or βSign in with a codeβ), then reload this page.', 'warning'); + } + constructor(terminal) { this.terminal = terminal; // --- Backward-compat properties (reflected from active provider) --- @@ -123,6 +139,7 @@ class OllamaManager { enabled: true }]; } + this.providers.forEach(p => { if (p.endpoint) p.endpoint = p.endpoint.replace(/\/+$/, ''); }); } _saveProviders() { @@ -633,6 +650,7 @@ class OllamaManager { } catch (error) { // Remember why this provider failed so chat() can name the real cause // instead of falling back to the generic "No provider responded". + if (error.status === 401) { this._sessionRepairNotice(); } this._lastChatError = error.message || String(error); if (fullText && fullText.length > 0) { this.terminal.printStreamingResponse(`\n\n[Stream error: ${error.message}]`, true); @@ -1041,6 +1059,7 @@ class OllamaManager { if (error.message === 'Failed to fetch' && provider.type === 'ollama') { return await this.chatWithToolsFallback(messages, tools, useModel); } + if (error.status === 401) { this._sessionRepairNotice(); } this.terminal.print(`${provider.name} /api/chat error: ${error.message}`, 'error'); this._lastChatError = error.message || String(error); return { message: null, tool_calls: null, error: error.message }; @@ -1294,6 +1313,7 @@ Only output XML function calls for tool tasks. If no tool is needed, answer norm // βββ Backward-compat methods βββββββββββββββββββββββββββββββββββββββββββββ setEndpoint(url) { + if (typeof url === 'string') url = url.replace(/\/+$/, ''); this.endpoint = url; // Also update the current provider's endpoint if it exists if (this.currentProvider) { |