feat: add "Clear history" button in session panel
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
Add a link-style button in the active session step that calls DELETE /api/sessions/:id/history to clear server-side conversation context. Shows a 2.5s green confirmation on success. Fixes #41 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -330,6 +330,14 @@
|
||||
.panel-btn.muted { border-color: #0e2318; color: #226644; }
|
||||
.panel-btn.muted:hover:not(:disabled) { background: #0e2318; color: #44dd88; }
|
||||
|
||||
.session-link-btn {
|
||||
background: none; border: none; color: #557755; font-size: 10px;
|
||||
font-family: inherit; cursor: pointer; margin-top: 10px; padding: 4px 0;
|
||||
letter-spacing: 1px; display: block;
|
||||
}
|
||||
.session-link-btn:hover:not(:disabled) { color: #44dd88; text-decoration: underline; }
|
||||
.session-link-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||
|
||||
#job-status { font-size: 11px; margin-top: 8px; color: #5577aa; min-height: 16px; }
|
||||
#job-error { font-size: 11px; margin-top: 4px; min-height: 16px; color: #994444; }
|
||||
|
||||
@@ -622,6 +630,7 @@
|
||||
TYPE IN THE INPUT BAR TO ASK TIMMY.<br>EACH REQUEST DEDUCTS FROM YOUR BALANCE.
|
||||
</p>
|
||||
<button class="panel-btn muted" id="session-topup-btn" style="margin-top:20px">⚡ TOP UP BALANCE</button>
|
||||
<button id="session-clear-history-btn" class="session-link-btn">🗑 Clear history</button>
|
||||
<div id="session-status-active"></div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ export function initSessionPanel() {
|
||||
_on('session-back-btn', 'click', () => _setStep('active'));
|
||||
_on('topup-quick-btn', 'click', () => { _openPanel(); _setStep('topup'); });
|
||||
_on('session-hud-topup', 'click', (e) => { e.preventDefault(); _openPanel(); _setStep('topup'); });
|
||||
_on('session-clear-history-btn', 'click', _clearHistory);
|
||||
|
||||
// Amount preset buttons — deposit (quick-fill the number input)
|
||||
_panel.querySelectorAll('[data-session-step="fund"] .session-amount-btn').forEach(btn => {
|
||||
@@ -419,6 +420,30 @@ function _startTopupPolling() {
|
||||
_pollTimer = setTimeout(poll, POLL_MS);
|
||||
}
|
||||
|
||||
// ── Clear history ─────────────────────────────────────────────────────────────
|
||||
|
||||
async function _clearHistory() {
|
||||
if (!_sessionId || !_macaroon) return;
|
||||
const btn = document.getElementById('session-clear-history-btn');
|
||||
if (btn) btn.disabled = true;
|
||||
try {
|
||||
const res = await fetch(`${API}/sessions/${_sessionId}/history`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${_macaroon}` },
|
||||
});
|
||||
if (res.ok) {
|
||||
_setStatus('active', '✓ History cleared', '#44dd88');
|
||||
setTimeout(() => _setStatus('active', '', ''), 2500);
|
||||
} else {
|
||||
_setStatus('active', 'Failed to clear history', '#ff6644');
|
||||
}
|
||||
} catch (err) {
|
||||
_setStatus('active', 'Error: ' + err.message, '#ff6644');
|
||||
} finally {
|
||||
if (btn) btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Restore from localStorage ─────────────────────────────────────────────────
|
||||
|
||||
async function _tryRestore() {
|
||||
|
||||
Reference in New Issue
Block a user