-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmemory.ts
More file actions
25 lines (23 loc) · 749 Bytes
/
memory.ts
File metadata and controls
25 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export const MEMORY_CATEGORIES = [
"preference",
"fact",
"decision",
"entity",
"other",
] as const
export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number]
export function detectCategory(text: string): MemoryCategory {
const lower = text.toLowerCase()
if (/prefer|like|love|hate|want/i.test(lower)) return "preference"
if (/decided|will use|going with/i.test(lower)) return "decision"
if (/\+\d{10,}|@[\w.-]+\.\w+|is called/i.test(lower)) return "entity"
if (/is|are|has|have/i.test(lower)) return "fact"
return "other"
}
export function buildDocumentId(sessionKey: string): string {
const sanitized = sessionKey
.replace(/[^a-zA-Z0-9_]/g, "_")
.replace(/_+/g, "_")
.replace(/^_|_$/g, "")
return `session_${sanitized}`
}