added log for sending text and aria-setup.sh
This commit is contained in:
+63
-5
@@ -41,6 +41,47 @@ let rvsWs = null;
|
||||
let reqIdCounter = 0;
|
||||
const browserClients = new Set();
|
||||
|
||||
// ── Pipeline Tracking ──────────────────────────────────
|
||||
let pipelineActive = false;
|
||||
let pipelineStartTime = 0;
|
||||
|
||||
function plog(message, level) {
|
||||
const elapsed = pipelineActive ? `+${Date.now() - pipelineStartTime}ms` : "";
|
||||
const entry = { ts: new Date().toISOString(), level: level || "info", source: "pipeline", message: `${elapsed ? `[${elapsed}] ` : ""}${message}` };
|
||||
logs.push(entry);
|
||||
if (logs.length > 500) logs.shift();
|
||||
console.log(`[PIPELINE] ${entry.message}`);
|
||||
broadcast({ type: "log", entry });
|
||||
}
|
||||
|
||||
let pipelineTimeout = null;
|
||||
|
||||
function pipelineStart(method, text) {
|
||||
// Falls noch eine Pipeline laeuft, beenden
|
||||
if (pipelineActive) pipelineEnd(false, "Abgebrochen (neue Nachricht)");
|
||||
pipelineActive = true;
|
||||
pipelineStartTime = Date.now();
|
||||
if (pipelineTimeout) clearTimeout(pipelineTimeout);
|
||||
pipelineTimeout = setTimeout(() => {
|
||||
if (pipelineActive) pipelineEnd(false, "Timeout — keine Antwort nach 60s");
|
||||
}, 60000);
|
||||
plog(`━━━ Pipeline Start: ${method} ━━━`);
|
||||
plog(`Nachricht: "${text}"`);
|
||||
}
|
||||
|
||||
function pipelineEnd(ok, detail) {
|
||||
if (!pipelineActive) return;
|
||||
if (pipelineTimeout) { clearTimeout(pipelineTimeout); pipelineTimeout = null; }
|
||||
const elapsed = Date.now() - pipelineStartTime;
|
||||
if (ok) {
|
||||
plog(`>>> Fertig (${elapsed}ms): ${detail}`);
|
||||
} else {
|
||||
plog(`>>> FEHLER (${elapsed}ms): ${detail}`, "error");
|
||||
}
|
||||
plog(`━━━ Pipeline Ende ━━━`);
|
||||
pipelineActive = false;
|
||||
}
|
||||
|
||||
function nextReqId() {
|
||||
return `diag-${++reqIdCounter}`;
|
||||
}
|
||||
@@ -202,6 +243,10 @@ function handleGatewayMessage(msg) {
|
||||
if (msg.type === "res") {
|
||||
const status = msg.ok ? "OK" : `FEHLER: ${JSON.stringify(msg.error).slice(0, 100)}`;
|
||||
log("info", "gateway", `Response [${msg.id}]: ${status}`);
|
||||
if (pipelineActive) {
|
||||
if (msg.ok) plog(`Gateway ACK [${msg.id}] — Nachricht angenommen`);
|
||||
else plog(`Gateway NACK [${msg.id}] — ${JSON.stringify(msg.error).slice(0, 100)}`, "error");
|
||||
}
|
||||
broadcast({ type: "response", msg });
|
||||
return;
|
||||
}
|
||||
@@ -214,6 +259,7 @@ function handleGatewayMessage(msg) {
|
||||
const delta = payload.delta || payload.text || "";
|
||||
if (delta) {
|
||||
log("info", "gateway", `Delta: "${delta.slice(0, 60)}"`);
|
||||
if (pipelineActive) plog(`Streaming Delta: "${delta.slice(0, 80)}"`);
|
||||
broadcast({ type: "chat_delta", delta, payload });
|
||||
}
|
||||
return;
|
||||
@@ -222,6 +268,7 @@ function handleGatewayMessage(msg) {
|
||||
if (event === "chat:final") {
|
||||
const text = payload.text || payload.message || "";
|
||||
log("info", "gateway", `ANTWORT: "${text.slice(0, 200)}"`);
|
||||
if (pipelineActive) pipelineEnd(true, `"${text.slice(0, 120)}"`);
|
||||
broadcast({ type: "chat_final", text, payload });
|
||||
return;
|
||||
}
|
||||
@@ -229,6 +276,7 @@ function handleGatewayMessage(msg) {
|
||||
if (event === "chat:error") {
|
||||
const error = payload.error || payload.message || "Unbekannt";
|
||||
log("error", "gateway", `Chat-Fehler: ${error}`);
|
||||
if (pipelineActive) pipelineEnd(false, error);
|
||||
broadcast({ type: "chat_error", error, payload });
|
||||
return;
|
||||
}
|
||||
@@ -238,9 +286,10 @@ function handleGatewayMessage(msg) {
|
||||
}
|
||||
}
|
||||
|
||||
function sendToGateway(text) {
|
||||
function sendToGateway(text, isPipeline) {
|
||||
if (!gatewayWs || gatewayWs.readyState !== WebSocket.OPEN) {
|
||||
log("error", "gateway", "Nicht verbunden — kann nicht senden");
|
||||
if (isPipeline) pipelineEnd(false, "Gateway nicht verbunden");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -258,6 +307,7 @@ function sendToGateway(text) {
|
||||
|
||||
gatewayWs.send(JSON.stringify(msg));
|
||||
log("info", "gateway", `chat.send [${reqId}]: "${text}"`);
|
||||
if (isPipeline) plog(`chat.send [${reqId}] an Gateway gesendet — warte auf ACK...`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -294,7 +344,11 @@ function connectRVS(forcePlain) {
|
||||
try {
|
||||
const msg = JSON.parse(raw.toString());
|
||||
if (msg.type === "chat" && msg.payload) {
|
||||
log("info", "rvs", `Chat von ${msg.payload.sender || "?"}: "${(msg.payload.text || "").slice(0, 100)}"`);
|
||||
const sender = msg.payload.sender || "?";
|
||||
log("info", "rvs", `Chat von ${sender}: "${(msg.payload.text || "").slice(0, 100)}"`);
|
||||
if (pipelineActive && sender !== "diagnostic") {
|
||||
pipelineEnd(true, `Antwort via RVS von ${sender}: "${(msg.payload.text || "").slice(0, 120)}"`);
|
||||
}
|
||||
broadcast({ type: "rvs_chat", msg });
|
||||
} else if (msg.type === "heartbeat") {
|
||||
// ignorieren
|
||||
@@ -327,9 +381,10 @@ function connectRVS(forcePlain) {
|
||||
});
|
||||
}
|
||||
|
||||
function sendToRVS(text) {
|
||||
function sendToRVS(text, isPipeline) {
|
||||
if (!rvsWs || rvsWs.readyState !== WebSocket.OPEN) {
|
||||
log("error", "rvs", "Nicht verbunden");
|
||||
if (isPipeline) pipelineEnd(false, "RVS nicht verbunden");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -339,6 +394,7 @@ function sendToRVS(text) {
|
||||
timestamp: Date.now(),
|
||||
}));
|
||||
log("info", "rvs", `Gesendet via RVS: "${text}"`);
|
||||
if (isPipeline) plog(`Nachricht an RVS gesendet — warte auf Antwort via RVS...`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -792,9 +848,11 @@ wss.on("connection", (ws) => {
|
||||
const msg = JSON.parse(raw.toString());
|
||||
|
||||
if (msg.action === "test_gateway") {
|
||||
sendToGateway(msg.text || "aria lebst du noch?");
|
||||
pipelineStart("Gateway", msg.text || "aria lebst du noch?");
|
||||
sendToGateway(msg.text || "aria lebst du noch?", true);
|
||||
} else if (msg.action === "test_rvs") {
|
||||
sendToRVS(msg.text || "aria lebst du noch?");
|
||||
pipelineStart("RVS", msg.text || "aria lebst du noch?");
|
||||
sendToRVS(msg.text || "aria lebst du noch?", true);
|
||||
} else if (msg.action === "reconnect_gateway") {
|
||||
connectGateway();
|
||||
} else if (msg.action === "reconnect_rvs") {
|
||||
|
||||
Reference in New Issue
Block a user