feat(memory): define MemoryAdapter interface types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jarvis
2026-04-02 20:24:16 -05:00
parent e797676a02
commit 41961a6980
2 changed files with 79 additions and 0 deletions

View File

@@ -13,3 +13,10 @@ export {
type SearchResult, type SearchResult,
} from './insights.js'; } from './insights.js';
export type { VectorStore, VectorSearchResult, EmbeddingProvider } from './vector-store.js'; export type { VectorStore, VectorSearchResult, EmbeddingProvider } from './vector-store.js';
export type {
MemoryAdapter,
MemoryConfig,
NewInsight as AdapterNewInsight,
Insight as AdapterInsight,
InsightSearchResult,
} from './types.js';

View File

@@ -0,0 +1,72 @@
export type { EmbeddingProvider, VectorSearchResult } from './vector-store.js';
import type { EmbeddingProvider } from './vector-store.js';
/* ------------------------------------------------------------------ */
/* Insight types (adapter-level, decoupled from Drizzle schema) */
/* ------------------------------------------------------------------ */
export interface NewInsight {
userId: string;
content: string;
source: string;
category: string;
relevanceScore: number;
metadata?: Record<string, unknown>;
embedding?: number[];
}
export interface Insight extends NewInsight {
id: string;
createdAt: Date;
updatedAt?: Date;
decayedAt?: Date;
}
export interface InsightSearchResult {
id: string;
content: string;
score: number;
metadata?: Record<string, unknown>;
}
/* ------------------------------------------------------------------ */
/* MemoryAdapter interface */
/* ------------------------------------------------------------------ */
export interface MemoryAdapter {
readonly name: string;
// Preferences
getPreference(userId: string, key: string): Promise<unknown | null>;
setPreference(userId: string, key: string, value: unknown, category?: string): Promise<void>;
deletePreference(userId: string, key: string): Promise<boolean>;
listPreferences(
userId: string,
category?: string,
): Promise<Array<{ key: string; value: unknown; category: string }>>;
// Insights
storeInsight(insight: NewInsight): Promise<Insight>;
getInsight(id: string): Promise<Insight | null>;
searchInsights(
userId: string,
query: string,
opts?: { limit?: number; embedding?: number[] },
): Promise<InsightSearchResult[]>;
deleteInsight(id: string): Promise<boolean>;
// Embedding
readonly embedder: EmbeddingProvider | null;
// Lifecycle
close(): Promise<void>;
}
/* ------------------------------------------------------------------ */
/* MemoryConfig */
/* ------------------------------------------------------------------ */
export type MemoryConfig =
| { type: 'pgvector'; embedder?: EmbeddingProvider }
| { type: 'sqlite-vec'; embedder?: EmbeddingProvider }
| { type: 'keyword' };