From 8a47ce098bce469398c3cdf384accc674e658a6f Mon Sep 17 00:00:00 2001 From: Abel Kuruvilla Date: Fri, 6 Mar 2026 00:24:04 -0600 Subject: [PATCH] Improve content extraction in auto-capture logic OpenClaw sometimes sends content as an array of blocks (e.g. `[{ type: "text", text: "..." }]`), so `.trim()` fails. --- index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/index.ts b/index.ts index cad1b6d..5b50d38 100644 --- a/index.ts +++ b/index.ts @@ -407,18 +407,20 @@ export default { if (config.autoCapture) { api.on("agent_end", async (event: any) => { const messages = event.messages || []; - + const contentToText = (content: unknown): string => { + if (typeof content === "string") return content; + if (Array.isArray(content)) { + return content.map((part: any) => (part?.text != null ? String(part.text) : "")).join(""); + } + return ""; + }; + for (const msg of messages) { if (msg.role === "user" || msg.role === "assistant") { - const text = msg.content || ""; - - // Skip recalled memory context to prevent feedback loops + const text = contentToText(msg.content); if (text.includes("")) continue; - - // Only capture substantial messages if (text.trim().length < 50) continue; - - await client.add(text, event.agentId); + await client.add(text.trim(), event.agentId); } } });