fixed, chat messages, reload
This commit is contained in:
+20
-13
@@ -1362,19 +1362,26 @@ async function handleLoadChatHistory(clientWs) {
|
|||||||
if (!line.trim()) continue;
|
if (!line.trim()) continue;
|
||||||
try {
|
try {
|
||||||
const obj = JSON.parse(line);
|
const obj = JSON.parse(line);
|
||||||
// User-Nachrichten
|
// OpenClaw Format: {"type":"message","message":{"role":"user|assistant","content":[...]}}
|
||||||
if (obj.role === "user" && obj.content) {
|
if (obj.type !== "message" || !obj.message) continue;
|
||||||
const text = typeof obj.content === "string" ? obj.content
|
const msg = obj.message;
|
||||||
: Array.isArray(obj.content) ? obj.content.filter(c => c.type === "text").map(c => c.text).join("\n")
|
const role = msg.role;
|
||||||
: "";
|
if (!role) continue;
|
||||||
if (text) chatMessages.push({ type: "sent", text, meta: "Gateway direkt", ts: obj.timestamp || 0 });
|
|
||||||
}
|
// Text aus content-Array extrahieren
|
||||||
// Assistant-Nachrichten
|
let text = "";
|
||||||
if (obj.role === "assistant" && obj.content) {
|
if (typeof msg.content === "string") text = msg.content;
|
||||||
const text = typeof obj.content === "string" ? obj.content
|
else if (Array.isArray(msg.content)) text = msg.content.filter(c => c.type === "text").map(c => c.text || "").join("\n");
|
||||||
: Array.isArray(obj.content) ? obj.content.filter(c => c.type === "text").map(c => c.text).join("\n")
|
if (!text) continue;
|
||||||
: "";
|
|
||||||
if (text) chatMessages.push({ type: "received", text, meta: "chat:final", ts: obj.timestamp || 0 });
|
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();
|
||||||
|
chatMessages.push({ type: "sent", text, meta: "Gateway direkt", ts: msg.timestamp || obj.timestamp || 0 });
|
||||||
|
} else if (role === "assistant") {
|
||||||
|
// Reply-Prefix entfernen: "[[reply_to_current]] "
|
||||||
|
text = text.replace(/^\[\[reply_to_\w+\]\]\s*/g, "").trim();
|
||||||
|
if (text) chatMessages.push({ type: "received", text, meta: "chat:final", ts: msg.timestamp || obj.timestamp || 0 });
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user