fixed chat textjson format, selected session for all, fixed android echo

This commit is contained in:
2026-03-29 03:18:02 +02:00
parent f2aebcbad9
commit 1972c4d1b4
3 changed files with 50 additions and 12 deletions
+13 -3
View File
@@ -35,7 +35,10 @@ const state = {
rvs: { status: "disconnected", lastError: null },
proxy: { status: "unknown", lastError: null },
};
let activeSessionKey = "aria-diag-v3";
const SESSION_KEY_FILE = "/tmp/aria-active-session";
let activeSessionKey = (() => {
try { return fs.readFileSync(SESSION_KEY_FILE, "utf-8").trim(); } catch { return "main"; }
})();
const logs = [];
let gatewayWs = null;
let rvsWs = null;
@@ -924,6 +927,9 @@ const server = http.createServer((req, res) => {
} else if (req.url === "/api/state") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ state, logs: logs.slice(-100) }));
} else if (req.url === "/api/session") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ sessionKey: activeSessionKey }));
} else {
res.writeHead(404);
res.end("Not Found");
@@ -1375,8 +1381,10 @@ async function handleLoadChatHistory(clientWs) {
if (!text) continue;
if (role === "user") {
// Metadata-Prefix entfernen: "Sender (untrusted metadata):\n```json\n{...}\n```\n\n[timestamp] "
text = text.replace(/^Sender \(untrusted metadata\):[\s\S]*?```\s*\n*(?:\[.*?\]\s*)?/m, "").trim();
// Metadata-Prefix entfernen: "Sender (untrusted metadata):\n```json\n{...}\n```\n\n[timestamp] Text"
text = text.replace(/^Sender \(untrusted metadata\):[\s\S]*?```[\s\S]*?```\s*\n*/m, "").trim();
// Timestamp-Prefix entfernen: "[Sat 2026-03-28 14:51 UTC] "
text = text.replace(/^\[.*?\]\s*/, "").trim();
chatMessages.push({ type: "sent", text, meta: "Gateway direkt", ts: msg.timestamp || obj.timestamp || 0 });
} else if (role === "assistant") {
// Reply-Prefix entfernen: "[[reply_to_current]] "
@@ -1401,6 +1409,7 @@ function handleSetActiveSession(clientWs, sessionKey) {
return;
}
activeSessionKey = sessionKey;
try { fs.writeFileSync(SESSION_KEY_FILE, activeSessionKey); } catch {}
log("info", "server", `Aktive Session: ${activeSessionKey}`);
// Allen Clients mitteilen
for (const c of browserClients) {
@@ -1417,6 +1426,7 @@ async function handleCreateSession(clientWs, sessionName) {
try {
// Session wird automatisch erstellt wenn man die erste Nachricht sendet
activeSessionKey = sessionName;
try { fs.writeFileSync(SESSION_KEY_FILE, activeSessionKey); } catch {}
log("info", "server", `Neue Session erstellt und aktiviert: ${sessionName}`);
// Allen Clients mitteilen
for (const c of browserClients) {