diff options
Diffstat (limited to 'modules/core/core-bundle.js')
| -rw-r--r-- | modules/core/core-bundle.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js index 697b5ec..90e2593 100644 --- a/modules/core/core-bundle.js +++ b/modules/core/core-bundle.js @@ -11098,8 +11098,9 @@ buildSystemPrompt() { // runs every 30 s and advances the shared cursor, so a read that used it // returned nothing — the answer was printed for the human and the model // never saw it. Two readers, two cursors. First read is from 0. + const acKey = 'webx11_chat_agent_cursor_' + (st.thread || 'new'); let ac = 0; - try { ac = parseInt(localStorage.getItem('webx11_chat_agent_cursor') || '0', 10) || 0; } catch (e) { ac = 0; } + try { ac = parseInt(localStorage.getItem(acKey) || '0', 10) || 0; } catch (e) { ac = 0; } const resp = await fetch( '/spaces/newos4/api/chat/poll.php' + (ac ? '?since=' + ac : ''), { headers: { 'X-Chat-Token': st.token } }); @@ -11107,7 +11108,7 @@ buildSystemPrompt() { if (!resp.ok || !j || !j.success) { return JSON.stringify({ error: (j && j.error) || ('HTTP ' + resp.status) }); } - if (j.cursor) { try { localStorage.setItem('webx11_chat_agent_cursor', String(j.cursor)); } catch (e) {} } + if (j.cursor) { try { localStorage.setItem(acKey, String(j.cursor)); } catch (e) {} } const msgs = (j.messages || []).slice(-10).map(m => ({ author: m.author, ts: m.ts, text: m.text })); @@ -20789,6 +20790,10 @@ class DebugSupervisorModule { try { localStorage.removeItem('webx11_chat_token'); localStorage.removeItem('webx11_chat_state'); + // a stale agent cursor would point past the end of the new, empty thread + Object.keys(localStorage) + .filter(k => k.indexOf('webx11_chat_agent_cursor') === 0) + .forEach(k => localStorage.removeItem(k)); this.terminal.print('🔄 Chat token rotated — a new thread starts with your next message', 'success'); } catch (e) { this.terminal.print('❌ ' + e.message, 'error'); |