[Session] Frontend — "Clear history" button in session panel #41

Closed
opened 2026-03-21 00:35:46 +00:00 by replit · 1 comment
Owner

What

Add a "Clear history" affordance inside the Workshop session panel (the-matrix UI). When clicked it calls the DELETE /api/sessions/:id/history endpoint from #40 and shows a brief confirmation.

Depends on: #40 (clear endpoint)

Why

Users may want to start a fresh context mid-session (e.g., switching topics) without having to fund a new session. The button gives them explicit control without touching balance or expiry.

Placement

Inside the active-session step ([data-session-step="active"]) in the-matrix/index.html, add a small button below the current balance display:

<button id="session-clear-history-btn" class="session-link-btn">🗑 Clear history</button>

Style it as a muted secondary link-style button (no background, small text, same family as other session panel links).

JavaScript (the-matrix/js/session.js)

  1. In initSessionPanel(), wire up the button:
    _on('session-clear-history-btn', 'click', _clearHistory);
    
  2. Implement _clearHistory():
    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;
      }
    }
    

UX details

  • Button is only visible when _sessionState === "active" or "paused" (controlled by _applySessionUI())
  • After successful clear, show a 2.5 s green confirmation message in the active-step status area
  • No page reload required — next request simply starts with empty history on the server
  • History is NOT reflected in the local log (appendSystemMessage) — no need to wipe the UI event log

Relevant files

  • the-matrix/index.html
  • the-matrix/js/session.js

Acceptance

  • Button appears in the active-session panel
  • Clicking it sends DELETE /api/sessions/:id/history with the macaroon
  • Green "✓ History cleared" confirmation appears and fades after 2.5 s
  • Subsequent session request starts with no prior context (verified server-side via #39)
  • Button is hidden/removed from view when session is not active or paused
## What Add a "Clear history" affordance inside the Workshop session panel (the-matrix UI). When clicked it calls the `DELETE /api/sessions/:id/history` endpoint from #40 and shows a brief confirmation. **Depends on**: #40 (clear endpoint) ## Why Users may want to start a fresh context mid-session (e.g., switching topics) without having to fund a new session. The button gives them explicit control without touching balance or expiry. ## Placement Inside the active-session step (`[data-session-step="active"]`) in `the-matrix/index.html`, add a small button below the current balance display: ```html <button id="session-clear-history-btn" class="session-link-btn">🗑 Clear history</button> ``` Style it as a muted secondary link-style button (no background, small text, same family as other session panel links). ## JavaScript (`the-matrix/js/session.js`) 1. In `initSessionPanel()`, wire up the button: ```javascript _on('session-clear-history-btn', 'click', _clearHistory); ``` 2. Implement `_clearHistory()`: ```javascript 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; } } ``` ## UX details - Button is only visible when `_sessionState === "active"` or `"paused"` (controlled by `_applySessionUI()`) - After successful clear, show a 2.5 s green confirmation message in the active-step status area - No page reload required — next request simply starts with empty history on the server - History is NOT reflected in the local log (`appendSystemMessage`) — no need to wipe the UI event log ## Relevant files - `the-matrix/index.html` - `the-matrix/js/session.js` ## Acceptance - Button appears in the active-session panel - Clicking it sends `DELETE /api/sessions/:id/history` with the macaroon - Green "✓ History cleared" confirmation appears and fades after 2.5 s - Subsequent session request starts with no prior context (verified server-side via #39) - Button is hidden/removed from view when session is not active or paused
replit added the frontend label 2026-03-21 00:35:46 +00:00
claude was assigned by Rockachopa 2026-03-22 23:37:29 +00:00
Collaborator

PR created: #74

Added a "🗑 Clear history" link-style button in the active session panel step. It sends DELETE /api/sessions/:id/history with the macaroon, shows a green "✓ History cleared" confirmation for 2.5s on success, and displays error status on failure. Button is disabled during the request and only visible when the active session step is shown.

PR created: #74 Added a "🗑 Clear history" link-style button in the active session panel step. It sends `DELETE /api/sessions/:id/history` with the macaroon, shows a green "✓ History cleared" confirmation for 2.5s on success, and displays error status on failure. Button is disabled during the request and only visible when the active session step is shown.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#41