Spaces:
Paused
Paused
Malina Claude Opus 4.8 commited on
Commit ·
9cdca50
1
Parent(s): 1308d69
aria: delete-chat-history with irreversible confirm + real DB wipe
Browse filesSettings → 'Usuń historię czatu' opens a confirm modal ('nie da się cofnąć'); on
confirm the client sends {t:clear} over the WS, the DO deletes aria_events +
aria_bubbles for the conversation, resets in-memory context, and broadcasts
{t:cleared} so every open tab wipes the view. Verified in Chrome: 5→0 bubbles, D1 0/0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cloudflare/aria-worker/src/conversation-do.js
CHANGED
|
@@ -64,6 +64,8 @@ export class AriaConversation {
|
|
| 64 |
|
| 65 |
if (msg.t === "ping") { this.send(ws, { t: "pong" }); return; }
|
| 66 |
|
|
|
|
|
|
|
| 67 |
if (msg.t === "event") {
|
| 68 |
const norm = normalizeEvent(msg.event);
|
| 69 |
if (!norm.ok) { this.send(ws, { t: "error", v: norm.error }); return; }
|
|
@@ -90,6 +92,22 @@ export class AriaConversation {
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
/* ---- run one logical turn over the clustered pending events ---- */
|
| 94 |
async flushTurn(systemEvent = null) {
|
| 95 |
if (this.busy) { // re-arm; don't overlap brain calls
|
|
|
|
| 64 |
|
| 65 |
if (msg.t === "ping") { this.send(ws, { t: "pong" }); return; }
|
| 66 |
|
| 67 |
+
if (msg.t === "clear") { await this.clearHistory(); return; }
|
| 68 |
+
|
| 69 |
if (msg.t === "event") {
|
| 70 |
const norm = normalizeEvent(msg.event);
|
| 71 |
if (!norm.ok) { this.send(ws, { t: "error", v: norm.error }); return; }
|
|
|
|
| 92 |
}
|
| 93 |
}
|
| 94 |
|
| 95 |
+
/* ---- permanently wipe this conversation's history (DB + memory) ---- */
|
| 96 |
+
async clearHistory() {
|
| 97 |
+
this.clearIdle();
|
| 98 |
+
if (this.debounceTimer) { clearTimeout(this.debounceTimer); this.debounceTimer = null; }
|
| 99 |
+
await this.env.DB.batch([
|
| 100 |
+
this.env.DB.prepare("DELETE FROM aria_bubbles WHERE conversation_id = ?").bind(this.cid),
|
| 101 |
+
this.env.DB.prepare("DELETE FROM aria_events WHERE conversation_id = ?").bind(this.cid),
|
| 102 |
+
]).catch(() => {});
|
| 103 |
+
this.recent = [];
|
| 104 |
+
this.pending = [];
|
| 105 |
+
this.lastNudge = null;
|
| 106 |
+
this.idleCount = 0;
|
| 107 |
+
this.touchConvo();
|
| 108 |
+
this.broadcast({ t: "cleared" }); // tell every open tab to wipe the view
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
/* ---- run one logical turn over the clustered pending events ---- */
|
| 112 |
async flushTurn(systemEvent = null) {
|
| 113 |
if (this.busy) { // re-arm; don't overlap brain calls
|
cloudflare/pages-integration/aria.html
CHANGED
|
@@ -92,13 +92,30 @@
|
|
| 92 |
<button class="aria-fun" id="ariaReport" type="button">🚩 Zgłoś ARIĘ</button>
|
| 93 |
</div>
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
<a class="aria-fun ghost" href="index.html">← Modele</a>
|
| 96 |
<button class="aria-fun ghost" id="ariaLogout" type="button">Wyloguj</button>
|
| 97 |
</div>
|
| 98 |
</div>
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
<div class="aria-toast" id="ariaToast" hidden></div>
|
| 101 |
|
| 102 |
-
<script type="module" src="js/aria-chat.js?v=
|
| 103 |
</body>
|
| 104 |
</html>
|
|
|
|
| 92 |
<button class="aria-fun" id="ariaReport" type="button">🚩 Zgłoś ARIĘ</button>
|
| 93 |
</div>
|
| 94 |
|
| 95 |
+
<div class="aria-set-group">
|
| 96 |
+
<label class="aria-set-label">Dane</label>
|
| 97 |
+
<button class="aria-fun danger" id="ariaClear" type="button">🗑️ Usuń historię czatu</button>
|
| 98 |
+
</div>
|
| 99 |
+
|
| 100 |
<a class="aria-fun ghost" href="index.html">← Modele</a>
|
| 101 |
<button class="aria-fun ghost" id="ariaLogout" type="button">Wyloguj</button>
|
| 102 |
</div>
|
| 103 |
</div>
|
| 104 |
|
| 105 |
+
<!-- confirm modal: clearing history is irreversible -->
|
| 106 |
+
<div class="aria-confirm" id="ariaConfirm" hidden>
|
| 107 |
+
<div class="aria-confirm-card">
|
| 108 |
+
<div class="aria-confirm-title">Usunąć historię czatu?</div>
|
| 109 |
+
<p class="aria-confirm-text">Tego <strong>nie da się cofnąć</strong>. Wszystkie wiadomości zostaną trwale usunięte z bazy.</p>
|
| 110 |
+
<div class="aria-confirm-actions">
|
| 111 |
+
<button class="aria-fun" id="ariaConfirmCancel" type="button">Anuluj</button>
|
| 112 |
+
<button class="aria-fun danger solid" id="ariaConfirmYes" type="button">Usuń na zawsze</button>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
<div class="aria-toast" id="ariaToast" hidden></div>
|
| 118 |
|
| 119 |
+
<script type="module" src="js/aria-chat.js?v=4"></script>
|
| 120 |
</body>
|
| 121 |
</html>
|
cloudflare/pages-integration/css/aria.css
CHANGED
|
@@ -142,6 +142,19 @@
|
|
| 142 |
.aria-rand:hover, .aria-fun:hover { background: var(--surface-2, #ffffff0d); }
|
| 143 |
.aria-fun.ghost { color: var(--text-soft, #b9bcc6); }
|
| 144 |
.aria-fun.on { border-color: var(--aria-me); color: var(--aria-me); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
/* ---- toast ---- */
|
| 147 |
.aria-toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--bg-2, #0a0a0f); border: 1px solid var(--line-strong, #ffffff29); padding: 11px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; }
|
|
|
|
| 142 |
.aria-rand:hover, .aria-fun:hover { background: var(--surface-2, #ffffff0d); }
|
| 143 |
.aria-fun.ghost { color: var(--text-soft, #b9bcc6); }
|
| 144 |
.aria-fun.on { border-color: var(--aria-me); color: var(--aria-me); }
|
| 145 |
+
.aria-fun.danger { color: #ff8d8d; border-color: rgba(255,90,90,0.35); }
|
| 146 |
+
.aria-fun.danger:hover { background: rgba(255,80,80,0.10); }
|
| 147 |
+
.aria-fun.danger.solid { background: #e5484d; color: #fff; border-color: #e5484d; text-align: center; }
|
| 148 |
+
.aria-fun.danger.solid:hover { background: #d23b40; }
|
| 149 |
+
|
| 150 |
+
/* confirm modal (irreversible clear) */
|
| 151 |
+
.aria-confirm { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: grid; place-items: center; z-index: 70; padding: 20px; }
|
| 152 |
+
.aria-confirm-card { width: min(380px, 94vw); background: var(--bg-2, #0a0a0f); border: 1px solid var(--line-strong, #ffffff29); border-radius: 18px; padding: 22px; animation: aria-up .2s var(--ease, ease); }
|
| 153 |
+
.aria-confirm-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
|
| 154 |
+
.aria-confirm-text { margin: 10px 0 18px; font-size: 14px; color: var(--text-soft, #b9bcc6); line-height: 1.5; }
|
| 155 |
+
.aria-confirm-text strong { color: #ff9b9b; }
|
| 156 |
+
.aria-confirm-actions { display: flex; gap: 10px; }
|
| 157 |
+
.aria-confirm-actions .aria-fun { flex: 1; text-align: center; }
|
| 158 |
|
| 159 |
/* ---- toast ---- */
|
| 160 |
.aria-toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--bg-2, #0a0a0f); border: 1px solid var(--line-strong, #ffffff29); padding: 11px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; }
|
cloudflare/pages-integration/js/aria-chat.js
CHANGED
|
@@ -42,6 +42,18 @@ function wireUi() {
|
|
| 42 |
$("ariaLogout").addEventListener("click", async () => {
|
| 43 |
await fetch("/api/auth/logout", { method: "POST" }); location.href = "index.html";
|
| 44 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
function onInput() {
|
| 47 |
autoGrow();
|
|
@@ -103,6 +115,7 @@ function openSocket(cid) {
|
|
| 103 |
if (m.t === "error") return addErrorBubble(m.v);
|
| 104 |
if (m.t === "usage") return onUsage(m);
|
| 105 |
if (m.t === "limit") return onLimit(m);
|
|
|
|
| 106 |
};
|
| 107 |
ws.onclose = () => {
|
| 108 |
clearInterval(state.pingTimer);
|
|
|
|
| 42 |
$("ariaLogout").addEventListener("click", async () => {
|
| 43 |
await fetch("/api/auth/logout", { method: "POST" }); location.href = "index.html";
|
| 44 |
});
|
| 45 |
+
// delete chat history (irreversible) — confirm modal → server wipes DB → UI clears
|
| 46 |
+
$("ariaClear").addEventListener("click", () => { $("ariaConfirm").hidden = false; });
|
| 47 |
+
$("ariaConfirmCancel").addEventListener("click", () => { $("ariaConfirm").hidden = true; });
|
| 48 |
+
$("ariaConfirmYes").addEventListener("click", () => {
|
| 49 |
+
$("ariaConfirm").hidden = true;
|
| 50 |
+
if (state.ws?.readyState === 1) {
|
| 51 |
+
send({ t: "clear" });
|
| 52 |
+
$("ariaDrawer").hidden = true;
|
| 53 |
+
} else {
|
| 54 |
+
toast("Brak połączenia — spróbuj za chwilę");
|
| 55 |
+
}
|
| 56 |
+
});
|
| 57 |
}
|
| 58 |
function onInput() {
|
| 59 |
autoGrow();
|
|
|
|
| 115 |
if (m.t === "error") return addErrorBubble(m.v);
|
| 116 |
if (m.t === "usage") return onUsage(m);
|
| 117 |
if (m.t === "limit") return onLimit(m);
|
| 118 |
+
if (m.t === "cleared") { $("ariaMessages").innerHTML = ""; toast("Historia usunięta"); return; }
|
| 119 |
};
|
| 120 |
ws.onclose = () => {
|
| 121 |
clearInterval(state.pingTimer);
|