Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix(demo): guard against undefined data in useMemories hook (v2 async response) (#5029)

Harshit Anandcf268da19d01
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",