fixed, aria reuse old session, and reload chat

This commit is contained in:
duffyduck 2026-03-29 01:55:57 +01:00
parent 242f67ec2b
commit 4722e1a0ee
17 changed files with 132 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
#Wed Mar 11 22:28:07 CET 2026
#Wed Mar 25 20:38:28 CET 2026
base.2=/home/duffy/Dokumente/programmierung/ARIA-AGENT/android/android/app/build/intermediates/dex/release/mergeDexRelease/classes2.dex
path.2=classes2.dex
base.1=/home/duffy/Dokumente/programmierung/ARIA-AGENT/android/android/app/build/intermediates/global_synthetics_dex/release/classes.dex

View File

@ -43,7 +43,7 @@ docker exec aria-core sh -c 'cat > /home/node/.openclaw/openclaw.json << '"'"'IN
"compaction": {
"mode": "safeguard"
},
"timeoutSeconds": 300,
"timeoutSeconds": 900,
"maxConcurrent": 4,
"subagents": {
"maxConcurrent": 8

View File

@ -471,6 +471,7 @@
ws.onopen = () => {
addLog('info', 'browser', 'Verbunden mit Diagnostic Server');
send({ action: 'get_active_session' });
send({ action: 'load_chat_history' });
};
ws.onclose = () => {
addLog('warn', 'browser', 'Verbindung zum Diagnostic Server verloren — Reconnect in 2s');
@ -567,6 +568,24 @@
showDockerLogs(msg);
return;
}
// Chat-History (nach F5 / Reconnect)
if (msg.type === 'chat_history') {
if (msg.messages && msg.messages.length > 0) {
chatBox.innerHTML = '';
for (const m of msg.messages) {
const el = document.createElement('div');
el.className = `chat-msg ${m.type}`;
const escaped = escapeHtml(m.text);
const linked = linkifyText(escaped);
const time = m.ts ? new Date(m.ts).toLocaleTimeString('de-DE') : '?';
el.innerHTML = `${linked}<div class="meta">${escapeHtml(m.meta)} — ${time}</div>`;
chatBox.appendChild(el);
}
chatBox.scrollTop = chatBox.scrollHeight;
}
return;
}
// Session + Brain Viewer
if (msg.type === 'sessions_list') { renderSessions(msg); return; }
if (msg.type === 'session_detail') { renderSessionDetail(msg); return; }

View File

@ -224,6 +224,11 @@ async function connectGateway() {
gatewayWs = ws;
broadcastState();
// Nach (Re-)Connect: letzte aktive Session aus OpenClaw wiederherstellen
resolveActiveSession().catch(err => {
log("warn", "server", `Session-Aufloesung fehlgeschlagen: ${err.message}`);
});
// Nachrichten-Loop — RAW logging fuer Debugging
ws.on("message", (raw) => {
try {
@ -971,6 +976,8 @@ wss.on("connection", (ws) => {
if (ws._sshSock) { ws._sshSock.end(); ws._sshSock = null; }
} else if (msg.action === "check_desktop") {
checkDesktopAvailable(ws);
} else if (msg.action === "load_chat_history") {
handleLoadChatHistory(ws);
} else if (msg.action === "list_sessions") {
handleListSessions(ws);
} else if (msg.action === "read_session") {
@ -1279,6 +1286,107 @@ async function handleDeleteSession(clientWs, sessionPath) {
}
}
// ── Session-Aufloesung: letzte aktive Session finden ────
async function resolveActiveSession() {
const indexRaw = await dockerExec("aria-core", `cat ${SESSIONS_DIR}/sessions.json 2>/dev/null || echo '{}'`);
let sessionsIndex = {};
try { sessionsIndex = JSON.parse(indexRaw.trim()); } catch { return; }
const entries = Array.isArray(sessionsIndex) ? sessionsIndex
: Array.isArray(sessionsIndex.sessions) ? sessionsIndex.sessions
: Object.entries(sessionsIndex).map(([k, v]) => ({ key: k, ...(typeof v === "object" ? v : { id: v }) }));
if (entries.length === 0) return;
// Pruefen ob aktuelle Session noch existiert
const currentExists = entries.some(e => (e.key || e.sessionKey || e.name || "") === activeSessionKey);
if (currentExists) {
log("info", "server", `Aktive Session '${activeSessionKey}' existiert noch`);
return;
}
// Neueste Session nehmen (nach updatedAt sortieren)
let newest = null;
let newestTime = 0;
for (const entry of entries) {
const t = entry.updatedAt || entry.createdAt || 0;
if (t >= newestTime) {
newestTime = t;
newest = entry;
}
}
if (newest) {
const key = newest.key || newest.sessionKey || newest.name || "";
if (key) {
activeSessionKey = key;
log("info", "server", `Aktive Session auf neueste gewechselt: '${activeSessionKey}'`);
for (const c of browserClients) {
c.send(JSON.stringify({ type: "active_session", sessionKey: activeSessionKey }));
}
}
}
}
// ── Chat-History aus aktiver Session laden (Display-Only) ──
async function handleLoadChatHistory(clientWs) {
try {
// Session-ID fuer den aktiven sessionKey finden
const indexRaw = await dockerExec("aria-core", `cat ${SESSIONS_DIR}/sessions.json 2>/dev/null || echo '{}'`);
let sessionsIndex = {};
try { sessionsIndex = JSON.parse(indexRaw.trim()); } catch {}
const entries = Array.isArray(sessionsIndex) ? sessionsIndex
: Array.isArray(sessionsIndex.sessions) ? sessionsIndex.sessions
: Object.entries(sessionsIndex).map(([k, v]) => ({ key: k, ...(typeof v === "object" ? v : { id: v }) }));
let sessionId = null;
for (const entry of entries) {
const key = entry.key || entry.sessionKey || entry.name || "";
if (key === activeSessionKey) {
sessionId = entry.id || entry.sessionId || "";
break;
}
}
if (!sessionId) {
clientWs.send(JSON.stringify({ type: "chat_history", messages: [] }));
return;
}
const sessionFile = `${SESSIONS_DIR}/${sessionId}.jsonl`;
const raw = await dockerExec("aria-core", `cat '${sessionFile}' 2>/dev/null || echo ''`);
const chatMessages = [];
for (const line of raw.split("\n")) {
if (!line.trim()) continue;
try {
const obj = JSON.parse(line);
// User-Nachrichten
if (obj.role === "user" && obj.content) {
const text = typeof obj.content === "string" ? obj.content
: Array.isArray(obj.content) ? obj.content.filter(c => c.type === "text").map(c => c.text).join("\n")
: "";
if (text) chatMessages.push({ type: "sent", text, meta: "Gateway direkt", ts: obj.timestamp || 0 });
}
// Assistant-Nachrichten
if (obj.role === "assistant" && obj.content) {
const text = typeof obj.content === "string" ? obj.content
: Array.isArray(obj.content) ? obj.content.filter(c => c.type === "text").map(c => c.text).join("\n")
: "";
if (text) chatMessages.push({ type: "received", text, meta: "chat:final", ts: obj.timestamp || 0 });
}
} catch {}
}
clientWs.send(JSON.stringify({ type: "chat_history", messages: chatMessages }));
log("info", "server", `Chat-History geladen: ${chatMessages.length} Nachrichten`);
} catch (err) {
log("error", "server", `Chat-History laden fehlgeschlagen: ${err.message}`);
clientWs.send(JSON.stringify({ type: "chat_history", messages: [], error: err.message }));
}
}
// ── Session aktivieren ─────────────────────────────────
function handleSetActiveSession(clientWs, sessionKey) {
if (!sessionKey || typeof sessionKey !== "string") {