From cf268da19d01bd433751b849b8ffc65a8f2b0d3e Mon Sep 17 00:00:00 2001 From: Harshit Anand Date: Thu, 11 Jun 2026 21:50:35 +0530 Subject: [PATCH] fix(demo): guard against undefined data in useMemories hook (v2 async response) (#5029) Co-authored-by: Kartik --- .../components/assistant-ui/memory-ui.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/mem0-demo/components/assistant-ui/memory-ui.tsx b/examples/mem0-demo/components/assistant-ui/memory-ui.tsx index 60c482e86..3e93d7d70 100644 --- a/examples/mem0-demo/components/assistant-ui/memory-ui.tsx +++ b/examples/mem0-demo/components/assistant-ui/memory-ui.tsx @@ -16,10 +16,10 @@ type RetrievedMemory = { type NewMemory = { id: string; - data: { + data?: { memory: string; }; - event: "ADD" | "DELETE"; + event: "ADD" | "UPDATE" | "DELETE" | "GET"; }; type NewMemoryAnnotation = { @@ -47,14 +47,16 @@ const useMemories = (): Memory[] => { () => annotations?.filter(isMemoryAnnotation).flatMap((a) => { if (a.type === "mem0-update") { - return a.memories.map( - (m): Memory => ({ - event: m.event, - id: m.id, - memory: m.data.memory, - score: 1, - }) - ); + return a.memories + .filter((m): m is NewMemory & { data: { memory: string } } => m.data != null) + .map( + (m): Memory => ({ + event: m.event, + id: m.id, + memory: m.data.memory, + score: 1, + }) + ); } else if (a.type === "mem0-get") { return a.memories.map((m) => ({ event: "GET",