fix(demo): guard against undefined data in useMemories hook (v2 async response) (#5029)
Co-authored-by: Kartik <kartik.labhshetwar@mem0.ai>
This commit is contained in:
@@ -16,10 +16,10 @@ type RetrievedMemory = {
|
|||||||
|
|
||||||
type NewMemory = {
|
type NewMemory = {
|
||||||
id: string;
|
id: string;
|
||||||
data: {
|
data?: {
|
||||||
memory: string;
|
memory: string;
|
||||||
};
|
};
|
||||||
event: "ADD" | "DELETE";
|
event: "ADD" | "UPDATE" | "DELETE" | "GET";
|
||||||
};
|
};
|
||||||
|
|
||||||
type NewMemoryAnnotation = {
|
type NewMemoryAnnotation = {
|
||||||
@@ -47,14 +47,16 @@ const useMemories = (): Memory[] => {
|
|||||||
() =>
|
() =>
|
||||||
annotations?.filter(isMemoryAnnotation).flatMap((a) => {
|
annotations?.filter(isMemoryAnnotation).flatMap((a) => {
|
||||||
if (a.type === "mem0-update") {
|
if (a.type === "mem0-update") {
|
||||||
return a.memories.map(
|
return a.memories
|
||||||
(m): Memory => ({
|
.filter((m): m is NewMemory & { data: { memory: string } } => m.data != null)
|
||||||
event: m.event,
|
.map(
|
||||||
id: m.id,
|
(m): Memory => ({
|
||||||
memory: m.data.memory,
|
event: m.event,
|
||||||
score: 1,
|
id: m.id,
|
||||||
})
|
memory: m.data.memory,
|
||||||
);
|
score: 1,
|
||||||
|
})
|
||||||
|
);
|
||||||
} else if (a.type === "mem0-get") {
|
} else if (a.type === "mem0-get") {
|
||||||
return a.memories.map((m) => ({
|
return a.memories.map((m) => ({
|
||||||
event: "GET",
|
event: "GET",
|
||||||
|
|||||||
Reference in New Issue
Block a user