@mzhub/mem-ts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +335 -0
- package/dist/BaseAdapter-BoRh1T7O.d.mts +75 -0
- package/dist/BaseAdapter-CQVX-gcA.d.ts +75 -0
- package/dist/BaseProvider-CEoiLGj5.d.ts +34 -0
- package/dist/BaseProvider-edMh_R9t.d.mts +34 -0
- package/dist/adapters/index.d.mts +259 -0
- package/dist/adapters/index.d.ts +259 -0
- package/dist/adapters/index.js +1570 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +1542 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/index-Ci5Q9G9H.d.mts +289 -0
- package/dist/index-Dl-Q2au9.d.ts +289 -0
- package/dist/index.d.mts +1206 -0
- package/dist/index.d.ts +1206 -0
- package/dist/index.js +5126 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5058 -0
- package/dist/index.mjs.map +1 -0
- package/dist/middleware/index.d.mts +4 -0
- package/dist/middleware/index.d.ts +4 -0
- package/dist/middleware/index.js +63 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/index.mjs +59 -0
- package/dist/middleware/index.mjs.map +1 -0
- package/dist/providers/index.d.mts +96 -0
- package/dist/providers/index.d.ts +96 -0
- package/dist/providers/index.js +379 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +370 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/types-G9qmfSeZ.d.mts +260 -0
- package/dist/types-G9qmfSeZ.d.ts +260 -0
- package/logo.png +0 -0
- package/package.json +114 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { B as BaseAdapter } from '../BaseAdapter-BoRh1T7O.mjs';
|
|
2
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-G9qmfSeZ.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory storage adapter for development and testing.
|
|
6
|
+
* Data is lost when the process exits.
|
|
7
|
+
*/
|
|
8
|
+
declare class InMemoryAdapter extends BaseAdapter {
|
|
9
|
+
private users;
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
private getUserData;
|
|
13
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
14
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
15
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
16
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
17
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
18
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
19
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
20
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
21
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
22
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
23
|
+
createSession(userId: string): Promise<Session>;
|
|
24
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
25
|
+
/**
|
|
26
|
+
* Clear all data for a user (useful for testing)
|
|
27
|
+
*/
|
|
28
|
+
clearUser(userId: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Clear all data (useful for testing)
|
|
31
|
+
*/
|
|
32
|
+
clearAll(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Export all data for a user (for portability)
|
|
35
|
+
*/
|
|
36
|
+
exportUser(userId: string): Promise<{
|
|
37
|
+
facts: MemoryFact[];
|
|
38
|
+
conversations: ConversationExchange[];
|
|
39
|
+
sessions: Session[];
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Import data for a user
|
|
43
|
+
*/
|
|
44
|
+
importUser(userId: string, data: {
|
|
45
|
+
facts: MemoryFact[];
|
|
46
|
+
conversations: ConversationExchange[];
|
|
47
|
+
sessions: Session[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface JSONUserData {
|
|
52
|
+
facts: MemoryFact[];
|
|
53
|
+
conversations: ConversationExchange[];
|
|
54
|
+
sessions: Session[];
|
|
55
|
+
}
|
|
56
|
+
interface JSONFileAdapterConfig {
|
|
57
|
+
/** Base path for storing JSON files (default: ./.mem-ts) */
|
|
58
|
+
path?: string;
|
|
59
|
+
/** Pretty print JSON files (default: true in dev, false in prod) */
|
|
60
|
+
prettyPrint?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* JSON file-based storage adapter for MVP/single-server deployments.
|
|
64
|
+
* Stores each user's data in separate JSON files for portability.
|
|
65
|
+
*
|
|
66
|
+
* Directory structure:
|
|
67
|
+
* .mem-ts/
|
|
68
|
+
* ├── users/
|
|
69
|
+
* │ ├── {userId}/
|
|
70
|
+
* │ │ ├── facts.json
|
|
71
|
+
* │ │ ├── conversations.json
|
|
72
|
+
* │ │ └── sessions.json
|
|
73
|
+
*/
|
|
74
|
+
declare class JSONFileAdapter extends BaseAdapter {
|
|
75
|
+
private basePath;
|
|
76
|
+
private prettyPrint;
|
|
77
|
+
constructor(config?: JSONFileAdapterConfig);
|
|
78
|
+
initialize(): Promise<void>;
|
|
79
|
+
close(): Promise<void>;
|
|
80
|
+
private getUserPath;
|
|
81
|
+
private ensureUserDir;
|
|
82
|
+
private readFile;
|
|
83
|
+
private writeFile;
|
|
84
|
+
private dateReviver;
|
|
85
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
86
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
87
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
88
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
89
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
90
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
91
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
92
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
93
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
94
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
95
|
+
createSession(userId: string): Promise<Session>;
|
|
96
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
97
|
+
/**
|
|
98
|
+
* Export all data for a user (for portability)
|
|
99
|
+
*/
|
|
100
|
+
exportUser(userId: string): Promise<JSONUserData>;
|
|
101
|
+
/**
|
|
102
|
+
* Import data for a user
|
|
103
|
+
*/
|
|
104
|
+
importUser(userId: string, data: JSONUserData): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete all data for a user
|
|
107
|
+
*/
|
|
108
|
+
deleteUser(userId: string): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for MongoDB adapter
|
|
113
|
+
*/
|
|
114
|
+
interface MongoDBAdapterConfig {
|
|
115
|
+
/** MongoDB connection URI */
|
|
116
|
+
uri: string;
|
|
117
|
+
/** Database name */
|
|
118
|
+
database?: string;
|
|
119
|
+
/** Collection prefix (default: 'memts_') */
|
|
120
|
+
collectionPrefix?: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* MongoDB storage adapter for production deployments.
|
|
124
|
+
* Requires: npm install mongodb
|
|
125
|
+
*
|
|
126
|
+
* Collections created:
|
|
127
|
+
* - memts_facts: User facts (knowledge graph)
|
|
128
|
+
* - memts_conversations: Conversation history
|
|
129
|
+
* - memts_sessions: Session metadata
|
|
130
|
+
*/
|
|
131
|
+
declare class MongoDBAdapter extends BaseAdapter {
|
|
132
|
+
private config;
|
|
133
|
+
private client;
|
|
134
|
+
private db;
|
|
135
|
+
private collectionPrefix;
|
|
136
|
+
constructor(config: MongoDBAdapterConfig);
|
|
137
|
+
private getClient;
|
|
138
|
+
private getCollection;
|
|
139
|
+
initialize(): Promise<void>;
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
142
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
143
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
144
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
145
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
146
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
147
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
148
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
149
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
150
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
151
|
+
createSession(userId: string): Promise<Session>;
|
|
152
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
153
|
+
private docToFact;
|
|
154
|
+
private docToConversation;
|
|
155
|
+
private docToSession;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for PostgreSQL adapter
|
|
160
|
+
*/
|
|
161
|
+
interface PostgresAdapterConfig {
|
|
162
|
+
/** PostgreSQL connection string */
|
|
163
|
+
connectionString: string;
|
|
164
|
+
/** Schema name (default: 'memts') */
|
|
165
|
+
schema?: string;
|
|
166
|
+
/** Enable pgvector for semantic search (requires pgvector extension) */
|
|
167
|
+
enableVector?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* PostgreSQL storage adapter for production deployments.
|
|
171
|
+
* Requires: npm install pg
|
|
172
|
+
*
|
|
173
|
+
* Tables created:
|
|
174
|
+
* - memts.facts: User facts (knowledge graph)
|
|
175
|
+
* - memts.conversations: Conversation history
|
|
176
|
+
* - memts.sessions: Session metadata
|
|
177
|
+
*/
|
|
178
|
+
declare class PostgresAdapter extends BaseAdapter {
|
|
179
|
+
private config;
|
|
180
|
+
private pool;
|
|
181
|
+
private schema;
|
|
182
|
+
constructor(config: PostgresAdapterConfig);
|
|
183
|
+
private getPool;
|
|
184
|
+
private query;
|
|
185
|
+
initialize(): Promise<void>;
|
|
186
|
+
close(): Promise<void>;
|
|
187
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
188
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
189
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
190
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
191
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
192
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
193
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
194
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
195
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
196
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
197
|
+
createSession(userId: string): Promise<Session>;
|
|
198
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
199
|
+
private camelToSnake;
|
|
200
|
+
private rowToFact;
|
|
201
|
+
private rowToConversation;
|
|
202
|
+
private rowToSession;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Configuration for Upstash Redis adapter
|
|
207
|
+
*/
|
|
208
|
+
interface UpstashRedisAdapterConfig {
|
|
209
|
+
/** Upstash Redis REST URL */
|
|
210
|
+
url: string;
|
|
211
|
+
/** Upstash Redis REST Token */
|
|
212
|
+
token: string;
|
|
213
|
+
/** Key prefix (default: 'memts:') */
|
|
214
|
+
prefix?: string;
|
|
215
|
+
/** TTL for hot cache entries in seconds (default: 3600) */
|
|
216
|
+
cacheTtl?: number;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Upstash Redis adapter for serverless hot cache layer.
|
|
220
|
+
* Uses the Upstash REST API - no Redis connection needed.
|
|
221
|
+
*
|
|
222
|
+
* Key structure:
|
|
223
|
+
* - memts:{userId}:facts - Hash of facts
|
|
224
|
+
* - memts:{userId}:conversations - List of conversations
|
|
225
|
+
* - memts:{userId}:sessions - Hash of sessions
|
|
226
|
+
*/
|
|
227
|
+
declare class UpstashRedisAdapter extends BaseAdapter {
|
|
228
|
+
private config;
|
|
229
|
+
private prefix;
|
|
230
|
+
private defaultTtl;
|
|
231
|
+
constructor(config: UpstashRedisAdapterConfig);
|
|
232
|
+
private redis;
|
|
233
|
+
private key;
|
|
234
|
+
initialize(): Promise<void>;
|
|
235
|
+
close(): Promise<void>;
|
|
236
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
237
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
238
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
239
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
240
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
241
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
242
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
243
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
244
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
245
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
246
|
+
createSession(userId: string): Promise<Session>;
|
|
247
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
248
|
+
/**
|
|
249
|
+
* Set TTL on a user's data (useful for expiring cache)
|
|
250
|
+
* If no TTL is provided, uses the configured default TTL.
|
|
251
|
+
*/
|
|
252
|
+
setUserTtl(userId: string, ttlSeconds?: number): Promise<void>;
|
|
253
|
+
/**
|
|
254
|
+
* Clear all data for a user
|
|
255
|
+
*/
|
|
256
|
+
clearUser(userId: string): Promise<void>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { BaseAdapter, InMemoryAdapter, JSONFileAdapter, type JSONFileAdapterConfig, MongoDBAdapter, type MongoDBAdapterConfig, PostgresAdapter, type PostgresAdapterConfig, UpstashRedisAdapter, type UpstashRedisAdapterConfig };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { B as BaseAdapter } from '../BaseAdapter-CQVX-gcA.js';
|
|
2
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-G9qmfSeZ.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory storage adapter for development and testing.
|
|
6
|
+
* Data is lost when the process exits.
|
|
7
|
+
*/
|
|
8
|
+
declare class InMemoryAdapter extends BaseAdapter {
|
|
9
|
+
private users;
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
private getUserData;
|
|
13
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
14
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
15
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
16
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
17
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
18
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
19
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
20
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
21
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
22
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
23
|
+
createSession(userId: string): Promise<Session>;
|
|
24
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
25
|
+
/**
|
|
26
|
+
* Clear all data for a user (useful for testing)
|
|
27
|
+
*/
|
|
28
|
+
clearUser(userId: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Clear all data (useful for testing)
|
|
31
|
+
*/
|
|
32
|
+
clearAll(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Export all data for a user (for portability)
|
|
35
|
+
*/
|
|
36
|
+
exportUser(userId: string): Promise<{
|
|
37
|
+
facts: MemoryFact[];
|
|
38
|
+
conversations: ConversationExchange[];
|
|
39
|
+
sessions: Session[];
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Import data for a user
|
|
43
|
+
*/
|
|
44
|
+
importUser(userId: string, data: {
|
|
45
|
+
facts: MemoryFact[];
|
|
46
|
+
conversations: ConversationExchange[];
|
|
47
|
+
sessions: Session[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface JSONUserData {
|
|
52
|
+
facts: MemoryFact[];
|
|
53
|
+
conversations: ConversationExchange[];
|
|
54
|
+
sessions: Session[];
|
|
55
|
+
}
|
|
56
|
+
interface JSONFileAdapterConfig {
|
|
57
|
+
/** Base path for storing JSON files (default: ./.mem-ts) */
|
|
58
|
+
path?: string;
|
|
59
|
+
/** Pretty print JSON files (default: true in dev, false in prod) */
|
|
60
|
+
prettyPrint?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* JSON file-based storage adapter for MVP/single-server deployments.
|
|
64
|
+
* Stores each user's data in separate JSON files for portability.
|
|
65
|
+
*
|
|
66
|
+
* Directory structure:
|
|
67
|
+
* .mem-ts/
|
|
68
|
+
* ├── users/
|
|
69
|
+
* │ ├── {userId}/
|
|
70
|
+
* │ │ ├── facts.json
|
|
71
|
+
* │ │ ├── conversations.json
|
|
72
|
+
* │ │ └── sessions.json
|
|
73
|
+
*/
|
|
74
|
+
declare class JSONFileAdapter extends BaseAdapter {
|
|
75
|
+
private basePath;
|
|
76
|
+
private prettyPrint;
|
|
77
|
+
constructor(config?: JSONFileAdapterConfig);
|
|
78
|
+
initialize(): Promise<void>;
|
|
79
|
+
close(): Promise<void>;
|
|
80
|
+
private getUserPath;
|
|
81
|
+
private ensureUserDir;
|
|
82
|
+
private readFile;
|
|
83
|
+
private writeFile;
|
|
84
|
+
private dateReviver;
|
|
85
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
86
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
87
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
88
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
89
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
90
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
91
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
92
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
93
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
94
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
95
|
+
createSession(userId: string): Promise<Session>;
|
|
96
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
97
|
+
/**
|
|
98
|
+
* Export all data for a user (for portability)
|
|
99
|
+
*/
|
|
100
|
+
exportUser(userId: string): Promise<JSONUserData>;
|
|
101
|
+
/**
|
|
102
|
+
* Import data for a user
|
|
103
|
+
*/
|
|
104
|
+
importUser(userId: string, data: JSONUserData): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete all data for a user
|
|
107
|
+
*/
|
|
108
|
+
deleteUser(userId: string): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for MongoDB adapter
|
|
113
|
+
*/
|
|
114
|
+
interface MongoDBAdapterConfig {
|
|
115
|
+
/** MongoDB connection URI */
|
|
116
|
+
uri: string;
|
|
117
|
+
/** Database name */
|
|
118
|
+
database?: string;
|
|
119
|
+
/** Collection prefix (default: 'memts_') */
|
|
120
|
+
collectionPrefix?: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* MongoDB storage adapter for production deployments.
|
|
124
|
+
* Requires: npm install mongodb
|
|
125
|
+
*
|
|
126
|
+
* Collections created:
|
|
127
|
+
* - memts_facts: User facts (knowledge graph)
|
|
128
|
+
* - memts_conversations: Conversation history
|
|
129
|
+
* - memts_sessions: Session metadata
|
|
130
|
+
*/
|
|
131
|
+
declare class MongoDBAdapter extends BaseAdapter {
|
|
132
|
+
private config;
|
|
133
|
+
private client;
|
|
134
|
+
private db;
|
|
135
|
+
private collectionPrefix;
|
|
136
|
+
constructor(config: MongoDBAdapterConfig);
|
|
137
|
+
private getClient;
|
|
138
|
+
private getCollection;
|
|
139
|
+
initialize(): Promise<void>;
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
142
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
143
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
144
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
145
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
146
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
147
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
148
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
149
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
150
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
151
|
+
createSession(userId: string): Promise<Session>;
|
|
152
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
153
|
+
private docToFact;
|
|
154
|
+
private docToConversation;
|
|
155
|
+
private docToSession;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for PostgreSQL adapter
|
|
160
|
+
*/
|
|
161
|
+
interface PostgresAdapterConfig {
|
|
162
|
+
/** PostgreSQL connection string */
|
|
163
|
+
connectionString: string;
|
|
164
|
+
/** Schema name (default: 'memts') */
|
|
165
|
+
schema?: string;
|
|
166
|
+
/** Enable pgvector for semantic search (requires pgvector extension) */
|
|
167
|
+
enableVector?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* PostgreSQL storage adapter for production deployments.
|
|
171
|
+
* Requires: npm install pg
|
|
172
|
+
*
|
|
173
|
+
* Tables created:
|
|
174
|
+
* - memts.facts: User facts (knowledge graph)
|
|
175
|
+
* - memts.conversations: Conversation history
|
|
176
|
+
* - memts.sessions: Session metadata
|
|
177
|
+
*/
|
|
178
|
+
declare class PostgresAdapter extends BaseAdapter {
|
|
179
|
+
private config;
|
|
180
|
+
private pool;
|
|
181
|
+
private schema;
|
|
182
|
+
constructor(config: PostgresAdapterConfig);
|
|
183
|
+
private getPool;
|
|
184
|
+
private query;
|
|
185
|
+
initialize(): Promise<void>;
|
|
186
|
+
close(): Promise<void>;
|
|
187
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
188
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
189
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
190
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
191
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
192
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
193
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
194
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
195
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
196
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
197
|
+
createSession(userId: string): Promise<Session>;
|
|
198
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
199
|
+
private camelToSnake;
|
|
200
|
+
private rowToFact;
|
|
201
|
+
private rowToConversation;
|
|
202
|
+
private rowToSession;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Configuration for Upstash Redis adapter
|
|
207
|
+
*/
|
|
208
|
+
interface UpstashRedisAdapterConfig {
|
|
209
|
+
/** Upstash Redis REST URL */
|
|
210
|
+
url: string;
|
|
211
|
+
/** Upstash Redis REST Token */
|
|
212
|
+
token: string;
|
|
213
|
+
/** Key prefix (default: 'memts:') */
|
|
214
|
+
prefix?: string;
|
|
215
|
+
/** TTL for hot cache entries in seconds (default: 3600) */
|
|
216
|
+
cacheTtl?: number;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Upstash Redis adapter for serverless hot cache layer.
|
|
220
|
+
* Uses the Upstash REST API - no Redis connection needed.
|
|
221
|
+
*
|
|
222
|
+
* Key structure:
|
|
223
|
+
* - memts:{userId}:facts - Hash of facts
|
|
224
|
+
* - memts:{userId}:conversations - List of conversations
|
|
225
|
+
* - memts:{userId}:sessions - Hash of sessions
|
|
226
|
+
*/
|
|
227
|
+
declare class UpstashRedisAdapter extends BaseAdapter {
|
|
228
|
+
private config;
|
|
229
|
+
private prefix;
|
|
230
|
+
private defaultTtl;
|
|
231
|
+
constructor(config: UpstashRedisAdapterConfig);
|
|
232
|
+
private redis;
|
|
233
|
+
private key;
|
|
234
|
+
initialize(): Promise<void>;
|
|
235
|
+
close(): Promise<void>;
|
|
236
|
+
getFacts(userId: string, filter?: FactFilter): Promise<MemoryFact[]>;
|
|
237
|
+
getFactById(userId: string, factId: string): Promise<MemoryFact | null>;
|
|
238
|
+
upsertFact(userId: string, fact: Omit<MemoryFact, "id" | "createdAt" | "updatedAt">): Promise<MemoryFact>;
|
|
239
|
+
updateFact(userId: string, factId: string, updates: Partial<MemoryFact>): Promise<MemoryFact>;
|
|
240
|
+
deleteFact(userId: string, factId: string, _reason?: string): Promise<void>;
|
|
241
|
+
hardDeleteFact(userId: string, factId: string): Promise<void>;
|
|
242
|
+
getConversationHistory(userId: string, limit?: number, sessionId?: string): Promise<ConversationExchange[]>;
|
|
243
|
+
saveConversation(userId: string, exchange: Omit<ConversationExchange, "id">): Promise<ConversationExchange>;
|
|
244
|
+
getSessions(userId: string, limit?: number): Promise<Session[]>;
|
|
245
|
+
getSession(userId: string, sessionId: string): Promise<Session | null>;
|
|
246
|
+
createSession(userId: string): Promise<Session>;
|
|
247
|
+
endSession(userId: string, sessionId: string, summary?: string): Promise<Session>;
|
|
248
|
+
/**
|
|
249
|
+
* Set TTL on a user's data (useful for expiring cache)
|
|
250
|
+
* If no TTL is provided, uses the configured default TTL.
|
|
251
|
+
*/
|
|
252
|
+
setUserTtl(userId: string, ttlSeconds?: number): Promise<void>;
|
|
253
|
+
/**
|
|
254
|
+
* Clear all data for a user
|
|
255
|
+
*/
|
|
256
|
+
clearUser(userId: string): Promise<void>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { BaseAdapter, InMemoryAdapter, JSONFileAdapter, type JSONFileAdapterConfig, MongoDBAdapter, type MongoDBAdapterConfig, PostgresAdapter, type PostgresAdapterConfig, UpstashRedisAdapter, type UpstashRedisAdapterConfig };
|