@easbot/memory 0.1.11
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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/assets/txt/assets/jieba_dict.txt +349046 -0
- package/dist/index.cjs +177 -0
- package/dist/index.d.cts +309 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.mjs +177 -0
- package/package.json +88 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { MemoryKnowledgeConfigWithModels } from '@easbot/types';
|
|
2
|
+
export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
|
|
3
|
+
import Database, { Database as Database$1 } from 'better-sqlite3';
|
|
4
|
+
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
5
|
+
|
|
6
|
+
type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'other';
|
|
7
|
+
declare const MEMORY_CATEGORIES: MemoryCategory[];
|
|
8
|
+
type MemorySource = 'session_self_write' | 'historical';
|
|
9
|
+
interface MemoryFact {
|
|
10
|
+
id: string;
|
|
11
|
+
agentId: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
msgId?: string;
|
|
14
|
+
parentMsgId?: string;
|
|
15
|
+
content: string;
|
|
16
|
+
category: MemoryCategory;
|
|
17
|
+
importance: number;
|
|
18
|
+
source: MemorySource;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
nodeIds?: number[];
|
|
21
|
+
filePath?: string;
|
|
22
|
+
createdAt: number;
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
}
|
|
25
|
+
interface MemoryVector {
|
|
26
|
+
factId: string;
|
|
27
|
+
embedding: Float32Array;
|
|
28
|
+
}
|
|
29
|
+
interface ShortTermEntry {
|
|
30
|
+
id: string;
|
|
31
|
+
agentId: string;
|
|
32
|
+
sessionId: string;
|
|
33
|
+
messageId: string;
|
|
34
|
+
parentId?: string;
|
|
35
|
+
role: 'user' | 'assistant';
|
|
36
|
+
content: string;
|
|
37
|
+
modelId?: string;
|
|
38
|
+
providerId?: string;
|
|
39
|
+
createdAt: number;
|
|
40
|
+
}
|
|
41
|
+
interface SessionMessage {
|
|
42
|
+
id: string;
|
|
43
|
+
parentId?: string;
|
|
44
|
+
role: 'user' | 'assistant';
|
|
45
|
+
content: string;
|
|
46
|
+
modelId?: string;
|
|
47
|
+
providerId?: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
}
|
|
50
|
+
interface MemoryQuery {
|
|
51
|
+
agentId: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
query?: string;
|
|
54
|
+
category?: MemoryCategory;
|
|
55
|
+
minImportance?: number;
|
|
56
|
+
source?: MemorySource;
|
|
57
|
+
maxResults?: number;
|
|
58
|
+
fromTime?: number;
|
|
59
|
+
toTime?: number;
|
|
60
|
+
minScore?: number;
|
|
61
|
+
vectorWeight?: number;
|
|
62
|
+
textWeight?: number;
|
|
63
|
+
candidateFactIds?: string[];
|
|
64
|
+
}
|
|
65
|
+
interface MemoryRecallResult {
|
|
66
|
+
memoryId: string;
|
|
67
|
+
category: MemoryCategory;
|
|
68
|
+
importance: number;
|
|
69
|
+
agentId: string;
|
|
70
|
+
snippet: string;
|
|
71
|
+
score: number;
|
|
72
|
+
createdAt: number;
|
|
73
|
+
source: MemorySource;
|
|
74
|
+
filePath?: string;
|
|
75
|
+
nodes?: Array<{
|
|
76
|
+
id: number;
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
edges?: Array<{
|
|
80
|
+
relation: string;
|
|
81
|
+
targetId: number;
|
|
82
|
+
targetName: string;
|
|
83
|
+
targetType: string;
|
|
84
|
+
}>;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
type MemorySystemConfig = MemoryKnowledgeConfigWithModels;
|
|
88
|
+
interface IMemorySystem {
|
|
89
|
+
remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
|
|
90
|
+
query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
|
|
91
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
92
|
+
update(agentId: string, memoryId: string, patch: {
|
|
93
|
+
content?: string;
|
|
94
|
+
importance?: number;
|
|
95
|
+
tags?: string[];
|
|
96
|
+
}): Promise<MemoryFact>;
|
|
97
|
+
extractFromSession(agentId: string, sessionId: string, messages: SessionMessage[]): Promise<void>;
|
|
98
|
+
appendShortTerm(entry: Omit<ShortTermEntry, 'id' | 'createdAt'>): Promise<void>;
|
|
99
|
+
getShortTerm(agentId: string, sessionId: string, limit?: number): Promise<ShortTermEntry[]>;
|
|
100
|
+
listAgentIds(): Promise<string[]>;
|
|
101
|
+
queryForSummary(agentId: string, limit?: number): Promise<MemoryFact[]>;
|
|
102
|
+
archive(): Promise<void>;
|
|
103
|
+
clear(): Promise<void>;
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
declare class MemoryError extends Error {
|
|
107
|
+
readonly code: string;
|
|
108
|
+
cause?: Error | undefined;
|
|
109
|
+
constructor(message: string, code: string, cause?: Error | undefined);
|
|
110
|
+
}
|
|
111
|
+
declare class MemoryValidationError extends MemoryError {
|
|
112
|
+
constructor(message: string, cause?: Error);
|
|
113
|
+
}
|
|
114
|
+
declare class MemoryNotFoundError extends MemoryError {
|
|
115
|
+
constructor(memoryId: string);
|
|
116
|
+
}
|
|
117
|
+
declare class MemoryPermissionError extends MemoryError {
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
declare class MemoryDatabaseError extends MemoryError {
|
|
121
|
+
constructor(message: string, cause?: Error);
|
|
122
|
+
}
|
|
123
|
+
declare class MemoryFileError extends MemoryError {
|
|
124
|
+
constructor(message: string, cause?: Error);
|
|
125
|
+
}
|
|
126
|
+
declare class MemorySearchError extends MemoryError {
|
|
127
|
+
constructor(message: string, cause?: Error);
|
|
128
|
+
}
|
|
129
|
+
declare class MemoryEmbeddingError extends MemoryError {
|
|
130
|
+
constructor(message: string, cause?: Error);
|
|
131
|
+
}
|
|
132
|
+
declare enum MemoryErrorCode {
|
|
133
|
+
VALIDATION_ERROR = "MEMORY_VALIDATION_ERROR",
|
|
134
|
+
NOT_FOUND = "MEMORY_NOT_FOUND",
|
|
135
|
+
PERMISSION_ERROR = "MEMORY_PERMISSION_ERROR",
|
|
136
|
+
DATABASE_ERROR = "MEMORY_DATABASE_ERROR",
|
|
137
|
+
FILE_ERROR = "MEMORY_FILE_ERROR",
|
|
138
|
+
SEARCH_ERROR = "MEMORY_SEARCH_ERROR",
|
|
139
|
+
EMBEDDING_ERROR = "MEMORY_EMBEDDING_ERROR"
|
|
140
|
+
}
|
|
141
|
+
interface MemoryNode {
|
|
142
|
+
id: number;
|
|
143
|
+
name: string;
|
|
144
|
+
type: string;
|
|
145
|
+
properties?: Record<string, unknown>;
|
|
146
|
+
createdAt: number;
|
|
147
|
+
updatedAt: number;
|
|
148
|
+
}
|
|
149
|
+
interface MemoryEdge {
|
|
150
|
+
id: number;
|
|
151
|
+
source: number;
|
|
152
|
+
target: number;
|
|
153
|
+
relation: string;
|
|
154
|
+
properties?: Record<string, unknown>;
|
|
155
|
+
createdAt: number;
|
|
156
|
+
}
|
|
157
|
+
interface MemoryNodeWithEdges extends MemoryNode {
|
|
158
|
+
edges?: MemoryEdge[];
|
|
159
|
+
}
|
|
160
|
+
interface NodeQueryFilter {
|
|
161
|
+
ids?: number[];
|
|
162
|
+
name?: string;
|
|
163
|
+
type?: string;
|
|
164
|
+
limit?: number;
|
|
165
|
+
}
|
|
166
|
+
interface EdgeQueryFilter {
|
|
167
|
+
ids?: number[];
|
|
168
|
+
source?: number;
|
|
169
|
+
target?: number;
|
|
170
|
+
sourceOrTarget?: number[];
|
|
171
|
+
relation?: string;
|
|
172
|
+
limit?: number;
|
|
173
|
+
}
|
|
174
|
+
interface ArchiveRecord {
|
|
175
|
+
source: string;
|
|
176
|
+
target: string;
|
|
177
|
+
timestamp: number;
|
|
178
|
+
}
|
|
179
|
+
interface ArchiveResult {
|
|
180
|
+
archivedCount: number;
|
|
181
|
+
records: ArchiveRecord[];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare function initTokenizer(params?: {
|
|
185
|
+
dictPath?: string[];
|
|
186
|
+
}): Promise<void>;
|
|
187
|
+
declare function loadCustomDict(dictPath: string): Promise<void>;
|
|
188
|
+
declare function tokenize(text: string): string[];
|
|
189
|
+
declare function tokenizeForSearch(text: string): string[];
|
|
190
|
+
declare function addWord(word: string, freq?: number, tag?: string): void;
|
|
191
|
+
declare function isInitialized(): boolean;
|
|
192
|
+
declare function closeTokenizer(): Promise<void>;
|
|
193
|
+
declare function toFtsTokens(text: string): string;
|
|
194
|
+
declare function toFtsTokensForSearch(text: string): string;
|
|
195
|
+
|
|
196
|
+
declare class MemoryDatabaseManager {
|
|
197
|
+
private db;
|
|
198
|
+
private readonly storagePath;
|
|
199
|
+
private initialized;
|
|
200
|
+
private initPromise;
|
|
201
|
+
constructor(storagePath: string);
|
|
202
|
+
initialize(): Promise<void>;
|
|
203
|
+
private doInitialize;
|
|
204
|
+
private openDatabaseAsync;
|
|
205
|
+
private createTables;
|
|
206
|
+
query<T>(sql: string, params?: unknown[]): T[];
|
|
207
|
+
run(sql: string, params?: unknown[]): {
|
|
208
|
+
lastID: number;
|
|
209
|
+
changes: number;
|
|
210
|
+
};
|
|
211
|
+
transaction<T>(fn: () => T): T;
|
|
212
|
+
prepare(sql: string): Database.Statement;
|
|
213
|
+
exec(sql: string): void;
|
|
214
|
+
getDb(): Database.Database;
|
|
215
|
+
getPath(): string;
|
|
216
|
+
close(): void;
|
|
217
|
+
healthCheck(): boolean;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
declare class MemoryFormatter {
|
|
221
|
+
static generateId(): string;
|
|
222
|
+
static serialize(fact: MemoryFact): string;
|
|
223
|
+
static serializeFile(facts: MemoryFact[]): string;
|
|
224
|
+
static parse(content: string): MemoryFact[];
|
|
225
|
+
private static parseFrontmatter;
|
|
226
|
+
private static validateFrontmatter;
|
|
227
|
+
private static parseArrayField;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare class MemoryFileManager {
|
|
231
|
+
static getMemoryMdPath(workspaceDir: string): string;
|
|
232
|
+
static getActiveFilePath(workspaceDir: string, category: MemoryCategory, date?: Date): string;
|
|
233
|
+
static getArchiveFilePath(workspaceDir: string, category: MemoryCategory, createdAt: number, filename: string): string;
|
|
234
|
+
static readMemoryMd(workspaceDir: string): Promise<string | null>;
|
|
235
|
+
static write(workspaceDir: string, fact: MemoryFact): Promise<string>;
|
|
236
|
+
static read(filePath: string): Promise<MemoryFact[]>;
|
|
237
|
+
static delete(filePath: string, memoryId: string): Promise<void>;
|
|
238
|
+
static update(filePath: string, memoryId: string, patch: {
|
|
239
|
+
content?: string;
|
|
240
|
+
importance?: number;
|
|
241
|
+
tags?: string[];
|
|
242
|
+
}): Promise<void>;
|
|
243
|
+
static listActiveFiles(workspaceDir: string): Promise<string[]>;
|
|
244
|
+
private static scanDir;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
declare class MemoryArchiver {
|
|
248
|
+
private db;
|
|
249
|
+
private config;
|
|
250
|
+
constructor(db: Database$1, config: MemorySystemConfig);
|
|
251
|
+
archive(): Promise<ArchiveResult>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class GraphStore {
|
|
255
|
+
private db;
|
|
256
|
+
constructor(db: Database$1);
|
|
257
|
+
upsertNode(name: string, type: string, properties?: Record<string, unknown>): Promise<number>;
|
|
258
|
+
deleteNode(id: number): Promise<void>;
|
|
259
|
+
upsertEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<number>;
|
|
260
|
+
queryNodes(filter?: NodeQueryFilter): Promise<MemoryNode[]>;
|
|
261
|
+
queryEdges(filter?: EdgeQueryFilter): Promise<MemoryEdge[]>;
|
|
262
|
+
queryNeighbors(nodeId: number, depth?: number): Promise<MemoryNodeWithEdges[]>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
declare class MemorySystem implements IMemorySystem {
|
|
266
|
+
private readonly config;
|
|
267
|
+
private readonly db;
|
|
268
|
+
private archiver;
|
|
269
|
+
private searchEngine;
|
|
270
|
+
private graphStore;
|
|
271
|
+
private embeddingModel;
|
|
272
|
+
private vectorDims;
|
|
273
|
+
constructor(config: MemorySystemConfig);
|
|
274
|
+
initialize(): Promise<void>;
|
|
275
|
+
remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
|
|
276
|
+
query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
|
|
277
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
278
|
+
update(agentId: string, memoryId: string, patch: {
|
|
279
|
+
content?: string;
|
|
280
|
+
importance?: number;
|
|
281
|
+
tags?: string[];
|
|
282
|
+
}): Promise<MemoryFact>;
|
|
283
|
+
extractFromSession(agentId: string, sessionId: string, messages: SessionMessage[]): Promise<void>;
|
|
284
|
+
appendShortTerm(entry: Omit<ShortTermEntry, 'id' | 'createdAt'>): Promise<void>;
|
|
285
|
+
getShortTerm(agentId: string, sessionId: string, limit?: number): Promise<ShortTermEntry[]>;
|
|
286
|
+
listAgentIds(): Promise<string[]>;
|
|
287
|
+
queryForSummary(agentId: string, limit?: number): Promise<MemoryFact[]>;
|
|
288
|
+
archive(): Promise<void>;
|
|
289
|
+
cleanupOrphanRecords(): Promise<void>;
|
|
290
|
+
clear(): Promise<void>;
|
|
291
|
+
close(): Promise<void>;
|
|
292
|
+
private extractEntities;
|
|
293
|
+
private extractEntitiesWithLlm;
|
|
294
|
+
private buildEntityExtractionPrompt;
|
|
295
|
+
private storeEntitiesAndRelations;
|
|
296
|
+
private embed;
|
|
297
|
+
private embedAndStore;
|
|
298
|
+
private writeFts;
|
|
299
|
+
private parseEntityExtractionResult;
|
|
300
|
+
private normalizeExtractionResult;
|
|
301
|
+
private sanitizeEntityToken;
|
|
302
|
+
private inferEntityType;
|
|
303
|
+
private getSearchEngine;
|
|
304
|
+
private getGraphStore;
|
|
305
|
+
private getArchiver;
|
|
306
|
+
}
|
|
307
|
+
declare function createMemorySystem(config: MemorySystemConfig): Promise<IMemorySystem>;
|
|
308
|
+
|
|
309
|
+
export { type ArchiveRecord, type ArchiveResult, type EdgeQueryFilter, GraphStore, type IMemorySystem, MEMORY_CATEGORIES, MemoryArchiver, type MemoryCategory, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, MemoryFileManager, MemoryFormatter, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemorySystem, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, type SessionMessage, type ShortTermEntry, addWord, closeTokenizer, createMemorySystem, initTokenizer, isInitialized, loadCustomDict, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { MemoryKnowledgeConfigWithModels } from '@easbot/types';
|
|
2
|
+
export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
|
|
3
|
+
import Database, { Database as Database$1 } from 'better-sqlite3';
|
|
4
|
+
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
5
|
+
|
|
6
|
+
type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'other';
|
|
7
|
+
declare const MEMORY_CATEGORIES: MemoryCategory[];
|
|
8
|
+
type MemorySource = 'session_self_write' | 'historical';
|
|
9
|
+
interface MemoryFact {
|
|
10
|
+
id: string;
|
|
11
|
+
agentId: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
msgId?: string;
|
|
14
|
+
parentMsgId?: string;
|
|
15
|
+
content: string;
|
|
16
|
+
category: MemoryCategory;
|
|
17
|
+
importance: number;
|
|
18
|
+
source: MemorySource;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
nodeIds?: number[];
|
|
21
|
+
filePath?: string;
|
|
22
|
+
createdAt: number;
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
}
|
|
25
|
+
interface MemoryVector {
|
|
26
|
+
factId: string;
|
|
27
|
+
embedding: Float32Array;
|
|
28
|
+
}
|
|
29
|
+
interface ShortTermEntry {
|
|
30
|
+
id: string;
|
|
31
|
+
agentId: string;
|
|
32
|
+
sessionId: string;
|
|
33
|
+
messageId: string;
|
|
34
|
+
parentId?: string;
|
|
35
|
+
role: 'user' | 'assistant';
|
|
36
|
+
content: string;
|
|
37
|
+
modelId?: string;
|
|
38
|
+
providerId?: string;
|
|
39
|
+
createdAt: number;
|
|
40
|
+
}
|
|
41
|
+
interface SessionMessage {
|
|
42
|
+
id: string;
|
|
43
|
+
parentId?: string;
|
|
44
|
+
role: 'user' | 'assistant';
|
|
45
|
+
content: string;
|
|
46
|
+
modelId?: string;
|
|
47
|
+
providerId?: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
}
|
|
50
|
+
interface MemoryQuery {
|
|
51
|
+
agentId: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
query?: string;
|
|
54
|
+
category?: MemoryCategory;
|
|
55
|
+
minImportance?: number;
|
|
56
|
+
source?: MemorySource;
|
|
57
|
+
maxResults?: number;
|
|
58
|
+
fromTime?: number;
|
|
59
|
+
toTime?: number;
|
|
60
|
+
minScore?: number;
|
|
61
|
+
vectorWeight?: number;
|
|
62
|
+
textWeight?: number;
|
|
63
|
+
candidateFactIds?: string[];
|
|
64
|
+
}
|
|
65
|
+
interface MemoryRecallResult {
|
|
66
|
+
memoryId: string;
|
|
67
|
+
category: MemoryCategory;
|
|
68
|
+
importance: number;
|
|
69
|
+
agentId: string;
|
|
70
|
+
snippet: string;
|
|
71
|
+
score: number;
|
|
72
|
+
createdAt: number;
|
|
73
|
+
source: MemorySource;
|
|
74
|
+
filePath?: string;
|
|
75
|
+
nodes?: Array<{
|
|
76
|
+
id: number;
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
edges?: Array<{
|
|
80
|
+
relation: string;
|
|
81
|
+
targetId: number;
|
|
82
|
+
targetName: string;
|
|
83
|
+
targetType: string;
|
|
84
|
+
}>;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
type MemorySystemConfig = MemoryKnowledgeConfigWithModels;
|
|
88
|
+
interface IMemorySystem {
|
|
89
|
+
remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
|
|
90
|
+
query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
|
|
91
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
92
|
+
update(agentId: string, memoryId: string, patch: {
|
|
93
|
+
content?: string;
|
|
94
|
+
importance?: number;
|
|
95
|
+
tags?: string[];
|
|
96
|
+
}): Promise<MemoryFact>;
|
|
97
|
+
extractFromSession(agentId: string, sessionId: string, messages: SessionMessage[]): Promise<void>;
|
|
98
|
+
appendShortTerm(entry: Omit<ShortTermEntry, 'id' | 'createdAt'>): Promise<void>;
|
|
99
|
+
getShortTerm(agentId: string, sessionId: string, limit?: number): Promise<ShortTermEntry[]>;
|
|
100
|
+
listAgentIds(): Promise<string[]>;
|
|
101
|
+
queryForSummary(agentId: string, limit?: number): Promise<MemoryFact[]>;
|
|
102
|
+
archive(): Promise<void>;
|
|
103
|
+
clear(): Promise<void>;
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
declare class MemoryError extends Error {
|
|
107
|
+
readonly code: string;
|
|
108
|
+
cause?: Error | undefined;
|
|
109
|
+
constructor(message: string, code: string, cause?: Error | undefined);
|
|
110
|
+
}
|
|
111
|
+
declare class MemoryValidationError extends MemoryError {
|
|
112
|
+
constructor(message: string, cause?: Error);
|
|
113
|
+
}
|
|
114
|
+
declare class MemoryNotFoundError extends MemoryError {
|
|
115
|
+
constructor(memoryId: string);
|
|
116
|
+
}
|
|
117
|
+
declare class MemoryPermissionError extends MemoryError {
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
declare class MemoryDatabaseError extends MemoryError {
|
|
121
|
+
constructor(message: string, cause?: Error);
|
|
122
|
+
}
|
|
123
|
+
declare class MemoryFileError extends MemoryError {
|
|
124
|
+
constructor(message: string, cause?: Error);
|
|
125
|
+
}
|
|
126
|
+
declare class MemorySearchError extends MemoryError {
|
|
127
|
+
constructor(message: string, cause?: Error);
|
|
128
|
+
}
|
|
129
|
+
declare class MemoryEmbeddingError extends MemoryError {
|
|
130
|
+
constructor(message: string, cause?: Error);
|
|
131
|
+
}
|
|
132
|
+
declare enum MemoryErrorCode {
|
|
133
|
+
VALIDATION_ERROR = "MEMORY_VALIDATION_ERROR",
|
|
134
|
+
NOT_FOUND = "MEMORY_NOT_FOUND",
|
|
135
|
+
PERMISSION_ERROR = "MEMORY_PERMISSION_ERROR",
|
|
136
|
+
DATABASE_ERROR = "MEMORY_DATABASE_ERROR",
|
|
137
|
+
FILE_ERROR = "MEMORY_FILE_ERROR",
|
|
138
|
+
SEARCH_ERROR = "MEMORY_SEARCH_ERROR",
|
|
139
|
+
EMBEDDING_ERROR = "MEMORY_EMBEDDING_ERROR"
|
|
140
|
+
}
|
|
141
|
+
interface MemoryNode {
|
|
142
|
+
id: number;
|
|
143
|
+
name: string;
|
|
144
|
+
type: string;
|
|
145
|
+
properties?: Record<string, unknown>;
|
|
146
|
+
createdAt: number;
|
|
147
|
+
updatedAt: number;
|
|
148
|
+
}
|
|
149
|
+
interface MemoryEdge {
|
|
150
|
+
id: number;
|
|
151
|
+
source: number;
|
|
152
|
+
target: number;
|
|
153
|
+
relation: string;
|
|
154
|
+
properties?: Record<string, unknown>;
|
|
155
|
+
createdAt: number;
|
|
156
|
+
}
|
|
157
|
+
interface MemoryNodeWithEdges extends MemoryNode {
|
|
158
|
+
edges?: MemoryEdge[];
|
|
159
|
+
}
|
|
160
|
+
interface NodeQueryFilter {
|
|
161
|
+
ids?: number[];
|
|
162
|
+
name?: string;
|
|
163
|
+
type?: string;
|
|
164
|
+
limit?: number;
|
|
165
|
+
}
|
|
166
|
+
interface EdgeQueryFilter {
|
|
167
|
+
ids?: number[];
|
|
168
|
+
source?: number;
|
|
169
|
+
target?: number;
|
|
170
|
+
sourceOrTarget?: number[];
|
|
171
|
+
relation?: string;
|
|
172
|
+
limit?: number;
|
|
173
|
+
}
|
|
174
|
+
interface ArchiveRecord {
|
|
175
|
+
source: string;
|
|
176
|
+
target: string;
|
|
177
|
+
timestamp: number;
|
|
178
|
+
}
|
|
179
|
+
interface ArchiveResult {
|
|
180
|
+
archivedCount: number;
|
|
181
|
+
records: ArchiveRecord[];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare function initTokenizer(params?: {
|
|
185
|
+
dictPath?: string[];
|
|
186
|
+
}): Promise<void>;
|
|
187
|
+
declare function loadCustomDict(dictPath: string): Promise<void>;
|
|
188
|
+
declare function tokenize(text: string): string[];
|
|
189
|
+
declare function tokenizeForSearch(text: string): string[];
|
|
190
|
+
declare function addWord(word: string, freq?: number, tag?: string): void;
|
|
191
|
+
declare function isInitialized(): boolean;
|
|
192
|
+
declare function closeTokenizer(): Promise<void>;
|
|
193
|
+
declare function toFtsTokens(text: string): string;
|
|
194
|
+
declare function toFtsTokensForSearch(text: string): string;
|
|
195
|
+
|
|
196
|
+
declare class MemoryDatabaseManager {
|
|
197
|
+
private db;
|
|
198
|
+
private readonly storagePath;
|
|
199
|
+
private initialized;
|
|
200
|
+
private initPromise;
|
|
201
|
+
constructor(storagePath: string);
|
|
202
|
+
initialize(): Promise<void>;
|
|
203
|
+
private doInitialize;
|
|
204
|
+
private openDatabaseAsync;
|
|
205
|
+
private createTables;
|
|
206
|
+
query<T>(sql: string, params?: unknown[]): T[];
|
|
207
|
+
run(sql: string, params?: unknown[]): {
|
|
208
|
+
lastID: number;
|
|
209
|
+
changes: number;
|
|
210
|
+
};
|
|
211
|
+
transaction<T>(fn: () => T): T;
|
|
212
|
+
prepare(sql: string): Database.Statement;
|
|
213
|
+
exec(sql: string): void;
|
|
214
|
+
getDb(): Database.Database;
|
|
215
|
+
getPath(): string;
|
|
216
|
+
close(): void;
|
|
217
|
+
healthCheck(): boolean;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
declare class MemoryFormatter {
|
|
221
|
+
static generateId(): string;
|
|
222
|
+
static serialize(fact: MemoryFact): string;
|
|
223
|
+
static serializeFile(facts: MemoryFact[]): string;
|
|
224
|
+
static parse(content: string): MemoryFact[];
|
|
225
|
+
private static parseFrontmatter;
|
|
226
|
+
private static validateFrontmatter;
|
|
227
|
+
private static parseArrayField;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare class MemoryFileManager {
|
|
231
|
+
static getMemoryMdPath(workspaceDir: string): string;
|
|
232
|
+
static getActiveFilePath(workspaceDir: string, category: MemoryCategory, date?: Date): string;
|
|
233
|
+
static getArchiveFilePath(workspaceDir: string, category: MemoryCategory, createdAt: number, filename: string): string;
|
|
234
|
+
static readMemoryMd(workspaceDir: string): Promise<string | null>;
|
|
235
|
+
static write(workspaceDir: string, fact: MemoryFact): Promise<string>;
|
|
236
|
+
static read(filePath: string): Promise<MemoryFact[]>;
|
|
237
|
+
static delete(filePath: string, memoryId: string): Promise<void>;
|
|
238
|
+
static update(filePath: string, memoryId: string, patch: {
|
|
239
|
+
content?: string;
|
|
240
|
+
importance?: number;
|
|
241
|
+
tags?: string[];
|
|
242
|
+
}): Promise<void>;
|
|
243
|
+
static listActiveFiles(workspaceDir: string): Promise<string[]>;
|
|
244
|
+
private static scanDir;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
declare class MemoryArchiver {
|
|
248
|
+
private db;
|
|
249
|
+
private config;
|
|
250
|
+
constructor(db: Database$1, config: MemorySystemConfig);
|
|
251
|
+
archive(): Promise<ArchiveResult>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class GraphStore {
|
|
255
|
+
private db;
|
|
256
|
+
constructor(db: Database$1);
|
|
257
|
+
upsertNode(name: string, type: string, properties?: Record<string, unknown>): Promise<number>;
|
|
258
|
+
deleteNode(id: number): Promise<void>;
|
|
259
|
+
upsertEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<number>;
|
|
260
|
+
queryNodes(filter?: NodeQueryFilter): Promise<MemoryNode[]>;
|
|
261
|
+
queryEdges(filter?: EdgeQueryFilter): Promise<MemoryEdge[]>;
|
|
262
|
+
queryNeighbors(nodeId: number, depth?: number): Promise<MemoryNodeWithEdges[]>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
declare class MemorySystem implements IMemorySystem {
|
|
266
|
+
private readonly config;
|
|
267
|
+
private readonly db;
|
|
268
|
+
private archiver;
|
|
269
|
+
private searchEngine;
|
|
270
|
+
private graphStore;
|
|
271
|
+
private embeddingModel;
|
|
272
|
+
private vectorDims;
|
|
273
|
+
constructor(config: MemorySystemConfig);
|
|
274
|
+
initialize(): Promise<void>;
|
|
275
|
+
remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
|
|
276
|
+
query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
|
|
277
|
+
forget(agentId: string, memoryId: string): Promise<void>;
|
|
278
|
+
update(agentId: string, memoryId: string, patch: {
|
|
279
|
+
content?: string;
|
|
280
|
+
importance?: number;
|
|
281
|
+
tags?: string[];
|
|
282
|
+
}): Promise<MemoryFact>;
|
|
283
|
+
extractFromSession(agentId: string, sessionId: string, messages: SessionMessage[]): Promise<void>;
|
|
284
|
+
appendShortTerm(entry: Omit<ShortTermEntry, 'id' | 'createdAt'>): Promise<void>;
|
|
285
|
+
getShortTerm(agentId: string, sessionId: string, limit?: number): Promise<ShortTermEntry[]>;
|
|
286
|
+
listAgentIds(): Promise<string[]>;
|
|
287
|
+
queryForSummary(agentId: string, limit?: number): Promise<MemoryFact[]>;
|
|
288
|
+
archive(): Promise<void>;
|
|
289
|
+
cleanupOrphanRecords(): Promise<void>;
|
|
290
|
+
clear(): Promise<void>;
|
|
291
|
+
close(): Promise<void>;
|
|
292
|
+
private extractEntities;
|
|
293
|
+
private extractEntitiesWithLlm;
|
|
294
|
+
private buildEntityExtractionPrompt;
|
|
295
|
+
private storeEntitiesAndRelations;
|
|
296
|
+
private embed;
|
|
297
|
+
private embedAndStore;
|
|
298
|
+
private writeFts;
|
|
299
|
+
private parseEntityExtractionResult;
|
|
300
|
+
private normalizeExtractionResult;
|
|
301
|
+
private sanitizeEntityToken;
|
|
302
|
+
private inferEntityType;
|
|
303
|
+
private getSearchEngine;
|
|
304
|
+
private getGraphStore;
|
|
305
|
+
private getArchiver;
|
|
306
|
+
}
|
|
307
|
+
declare function createMemorySystem(config: MemorySystemConfig): Promise<IMemorySystem>;
|
|
308
|
+
|
|
309
|
+
export { type ArchiveRecord, type ArchiveResult, type EdgeQueryFilter, GraphStore, type IMemorySystem, MEMORY_CATEGORIES, MemoryArchiver, type MemoryCategory, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, MemoryFileManager, MemoryFormatter, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemorySystem, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, type SessionMessage, type ShortTermEntry, addWord, closeTokenizer, createMemorySystem, initTokenizer, isInitialized, loadCustomDict, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch };
|