fixed delete session and added create button

This commit is contained in:
2026-03-13 17:19:50 +01:00
parent 8d7bb90a82
commit 08256c6113
2 changed files with 126 additions and 10 deletions
+67 -2
View File
@@ -35,6 +35,7 @@ const state = {
rvs: { status: "disconnected", lastError: null },
proxy: { status: "unknown", lastError: null },
};
let activeSessionKey = "aria-diag-v3";
const logs = [];
let gatewayWs = null;
let rvsWs = null;
@@ -385,7 +386,7 @@ function sendToGateway(text, isPipeline) {
id: reqId,
method: "chat.send",
params: {
sessionKey: "aria-diag-v3",
sessionKey: activeSessionKey,
message: text,
idempotencyKey: crypto.randomUUID(),
},
@@ -976,6 +977,12 @@ wss.on("connection", (ws) => {
handleReadSession(ws, msg.sessionPath);
} else if (msg.action === "delete_session") {
handleDeleteSession(ws, msg.sessionPath);
} else if (msg.action === "set_active_session") {
handleSetActiveSession(ws, msg.sessionKey);
} else if (msg.action === "get_active_session") {
ws.send(JSON.stringify({ type: "active_session", sessionKey: activeSessionKey }));
} else if (msg.action === "create_session") {
handleCreateSession(ws, msg.sessionName);
} else if (msg.action === "list_brain") {
handleListBrain(ws);
} else if (msg.action === "read_brain_file") {
@@ -1230,7 +1237,31 @@ async function handleDeleteSession(clientWs, sessionPath) {
}
try {
log("warn", "server", `Loesche Session: ${sessionPath}`);
await dockerExec("aria-core", `rm '${sessionPath.replace(/'/g, "")}'`);
const safePath = sessionPath.replace(/'/g, "");
// Session-ID aus Pfad extrahieren (UUID.jsonl)
const filename = safePath.split("/").pop();
const sessionId = filename.replace(".jsonl", "");
// 1. JSONL-Datei loeschen
await dockerExec("aria-core", `rm -f '${safePath}'`);
// 2. Eintrag aus sessions.json entfernen
try {
const sFile = `${SESSIONS_DIR}/sessions.json`;
const script = [
'const fs=require("fs");',
`const f="${sFile}",sid="${sessionId}";`,
'try{const d=JSON.parse(fs.readFileSync(f,"utf8"));',
'for(const k of Object.keys(d)){const v=d[k];',
'if(v&&(v.sessionId===sid||v.id===sid))delete d[k];}',
'fs.writeFileSync(f,JSON.stringify(d,null,2));}catch(e){}',
].join("");
const b64 = Buffer.from(script).toString("base64");
await dockerExec("aria-core", `echo ${b64} | base64 -d | node`);
} catch (e) {
log("warn", "server", `sessions.json Update fehlgeschlagen: ${e.message}`);
}
clientWs.send(JSON.stringify({ type: "session_deleted", ok: true, path: sessionPath }));
log("info", "server", "Session geloescht");
} catch (err) {
@@ -1238,6 +1269,40 @@ async function handleDeleteSession(clientWs, sessionPath) {
}
}
// ── Session aktivieren ─────────────────────────────────
function handleSetActiveSession(clientWs, sessionKey) {
if (!sessionKey || typeof sessionKey !== "string") {
clientWs.send(JSON.stringify({ type: "active_session", ok: false, error: "Kein sessionKey" }));
return;
}
activeSessionKey = sessionKey;
log("info", "server", `Aktive Session: ${activeSessionKey}`);
// Allen Clients mitteilen
for (const c of browserClients) {
c.send(JSON.stringify({ type: "active_session", sessionKey: activeSessionKey }));
}
}
// ── Session erstellen ──────────────────────────────────
async function handleCreateSession(clientWs, sessionName) {
if (!sessionName || typeof sessionName !== "string" || !/^[a-zA-Z0-9_-]+$/.test(sessionName)) {
clientWs.send(JSON.stringify({ type: "session_created", ok: false, error: "Ungueltiger Name (nur a-z, 0-9, -, _)" }));
return;
}
try {
// Session wird automatisch erstellt wenn man die erste Nachricht sendet
activeSessionKey = sessionName;
log("info", "server", `Neue Session erstellt und aktiviert: ${sessionName}`);
// Allen Clients mitteilen
for (const c of browserClients) {
c.send(JSON.stringify({ type: "active_session", sessionKey: activeSessionKey }));
}
clientWs.send(JSON.stringify({ type: "session_created", ok: true, sessionKey: sessionName }));
} catch (err) {
clientWs.send(JSON.stringify({ type: "session_created", ok: false, error: err.message }));
}
}
// ── Brain Viewer ────────────────────────────────────────
async function handleListBrain(clientWs) {