/** * [INPUT]: None (pure type definitions) * [OUTPUT]: All core data types for NanoMem * [POS]: Foundation layer — every other module imports from here */ /** Pluggable LLM function: system prompt + user message → raw text response */ export type LlmFn = (systemPrompt: string, userMessage: string) => Promise; export interface MemoryScope { userId?: string; agentId?: string; } /** Structured data for Facets (Pattern/Struggle) memory types */ export type FacetData = { kind: "pattern"; trigger: string; behavior: string; } | { kind: "struggle"; problem: string; attempts: string[]; solution: string; }; export interface MemoryEntry { id: string; type: "fact" | "lesson" | "preference" | "decision" | "entity" | "pattern" | "struggle"; content: string; tags: string[]; project: string; importance: number; /** Adaptive memory strength (days). Grows with each successful recall — Ebbinghaus spaced repetition. */ strength?: number; /** Ingestion time: when the system recorded this entry */ created: string; /** Event time: when the fact actually occurred (bi-temporal, defaults to created) */ eventTime?: string; lastAccessed?: string; accessCount: number; /** A-MEM style links to related memory entries */ relatedIds?: string[]; /** TTL in days — auto-evicted after expiry. undefined = permanent */ ttl?: number; scope?: MemoryScope; /** Structured data for pattern/struggle types (Facets) */ facetData?: FacetData; } export interface Episode { sessionId: string; project: string; date: string; summary: string; userGoal?: string; filesModified: string[]; toolsUsed: Record; keyObservations: string[]; errors: string[]; tags: string[]; importance: number; consolidated: boolean; scope?: MemoryScope; } export interface WorkEntry { id: string; goal: string; summary: string; project: string; tags: string[]; importance: number; strength?: number; created: string; eventTime?: string; lastAccessed?: string; accessCount: number; relatedIds?: string[]; ttl?: number; scope?: MemoryScope; } export interface Meta { totalSessions: number; lastConsolidation?: string; version: number; } /** Mem0-style update operations */ export type UpdateAction = "add" | "update" | "delete" | "noop"; export interface ExtractedItem { type: "preference" | "fact" | "lesson" | "decision" | "retract" | "pattern" | "struggle"; content: string; /** Structured data for pattern/struggle types (populated by LLM extraction) */ facetData?: FacetData; } export interface ExtractedWork { goal: string; summary: string; } export interface PatternInsight { entry: MemoryEntry; weight: number; trigger: string; behavior: string; } export interface StruggleInsight { entry: MemoryEntry; weight: number; problem: string; attempts: string[]; solution: string; resolved: boolean; } export interface InsightsReport { patterns: PatternInsight[]; struggles: StruggleInsight[]; topLessons: MemoryEntry[]; topKnowledge: MemoryEntry[]; preferences: MemoryEntry[]; stats: { knowledge: number; lessons: number; preferences: number; facets: number; episodes: number; work: number; totalSessions: number; }; recommendations: string[]; generatedAt: string; } export interface FullInsightsAtAGlance { working: string; hindering: string; quickWins: string; ambitious: string; } export interface FullInsightsProjectArea { name: string; sessionCount: number; description: string; } export interface FullInsightsChartRow { label: string; value: number; } export interface FullInsightsChart { id: string; title: string; rows: FullInsightsChartRow[]; } export interface FullInsightsWin { title: string; description: string; } export interface FullInsightsFriction { title: string; description: string; examples?: string[]; } export interface FullInsightsFeatureToTry { title: string; oneLiner: string; whyForYou: string; exampleCode?: string; } export interface FullInsightsUsagePattern { title: string; summary: string; detail: string; pastePrompt?: string; } export interface FullInsightsReport { stats: { knowledge: number; lessons: number; preferences: number; facets: number; episodes: number; work: number; totalSessions: number; aggregateToolCount?: number; aggregateFileCount?: number; }; atAGlance: FullInsightsAtAGlance; projectAreas: FullInsightsProjectArea[]; charts: FullInsightsChart[]; wins: FullInsightsWin[]; frictions: FullInsightsFriction[]; patterns: PatternInsight[]; recommendations: string[]; featuresToTry: FullInsightsFeatureToTry[]; usagePatterns: FullInsightsUsagePattern[]; generatedAt: string; locale: string; }