@smyslenny/agent-memory 2.1.0 → 3.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/dist/index.d.ts CHANGED
@@ -77,51 +77,6 @@ declare function getPathsByDomain(db: Database.Database, domain: string, agent_i
77
77
  declare function getPathsByPrefix(db: Database.Database, prefix: string, agent_id?: string): Path[];
78
78
  declare function deletePath(db: Database.Database, id: string): boolean;
79
79
 
80
- type RelationType = "related" | "caused" | "reminds" | "evolved" | "contradicts";
81
- interface Link {
82
- agent_id: string;
83
- source_id: string;
84
- target_id: string;
85
- relation: RelationType;
86
- weight: number;
87
- created_at: string;
88
- }
89
- declare function createLink(db: Database.Database, sourceId: string, targetId: string, relation: RelationType, weight?: number, agent_id?: string): Link;
90
- declare function getLinks(db: Database.Database, memoryId: string, agent_id?: string): Link[];
91
- declare function getOutgoingLinks(db: Database.Database, sourceId: string, agent_id?: string): Link[];
92
- /**
93
- * Multi-hop traversal: find all memories reachable within N hops
94
- * Inspired by PowerMem's knowledge graph traversal
95
- */
96
- declare function traverse(db: Database.Database, startId: string, maxHops?: number, agent_id?: string): Array<{
97
- id: string;
98
- hop: number;
99
- relation: string;
100
- }>;
101
- declare function deleteLink(db: Database.Database, sourceId: string, targetId: string, agent_id?: string): boolean;
102
-
103
- type SnapshotAction = "create" | "update" | "delete" | "merge";
104
- interface Snapshot {
105
- id: string;
106
- memory_id: string;
107
- content: string;
108
- changed_by: string | null;
109
- action: SnapshotAction;
110
- created_at: string;
111
- }
112
- /**
113
- * Create a snapshot before modifying a memory.
114
- * Call this BEFORE any update/delete operation.
115
- */
116
- declare function createSnapshot(db: Database.Database, memoryId: string, action: SnapshotAction, changedBy?: string): Snapshot;
117
- declare function getSnapshots(db: Database.Database, memoryId: string): Snapshot[];
118
- declare function getSnapshot(db: Database.Database, id: string): Snapshot | null;
119
- /**
120
- * Rollback a memory to a specific snapshot.
121
- * Creates a new snapshot of the current state before rolling back.
122
- */
123
- declare function rollback(db: Database.Database, snapshotId: string): boolean;
124
-
125
80
  type GuardAction = "add" | "update" | "skip" | "merge";
126
81
  interface GuardResult {
127
82
  action: GuardAction;
@@ -177,102 +132,62 @@ declare function searchBM25(db: Database.Database, query: string, opts?: {
177
132
  */
178
133
  declare function tokenize(text: string): string[];
179
134
 
180
- type SearchIntent = "factual" | "exploratory" | "temporal" | "causal";
181
- interface IntentResult {
182
- intent: SearchIntent;
183
- confidence: number;
135
+ interface IngestBlock {
136
+ title: string;
137
+ content: string;
184
138
  }
185
- /**
186
- * Classify the intent of a search query.
187
- * Uses keyword pattern matching + structural analysis.
188
- * Enhanced for Chinese with jieba-aware token analysis.
189
- */
190
- declare function classifyIntent(query: string): IntentResult;
191
- /**
192
- * Get search strategy based on intent
193
- */
194
- declare function getStrategy(intent: SearchIntent): {
195
- boostRecent: boolean;
196
- boostPriority: boolean;
197
- limit: number;
198
- };
199
-
200
- /**
201
- * Rerank search results based on intent strategy and priority weighting.
202
- */
203
- declare function rerank(results: SearchResult[], opts: {
204
- intent?: SearchIntent;
205
- boostRecent: boolean;
206
- boostPriority: boolean;
207
- limit: number;
208
- }): SearchResult[];
209
-
210
- interface EmbeddingProvider {
211
- id: string;
212
- model: string;
213
- dimension?: number;
214
- embed(text: string): Promise<number[]>;
139
+ interface IngestExtractedItem {
140
+ index: number;
141
+ title: string;
142
+ content: string;
143
+ type: MemoryType;
144
+ uri: string;
215
145
  }
216
- declare function getEmbeddingProviderFromEnv(): EmbeddingProvider | null;
217
- declare function createOpenAIProvider(opts: {
218
- apiKey: string;
219
- model: string;
220
- baseUrl?: string;
221
- }): EmbeddingProvider;
222
- declare function createDashScopeProvider(opts: {
223
- apiKey: string;
224
- model: string;
225
- baseUrl?: string;
226
- }): EmbeddingProvider;
227
-
228
- interface HybridSearchOptions {
229
- agent_id?: string;
230
- limit?: number;
231
- bm25CandidateMultiplier?: number;
232
- semanticCandidates?: number;
233
- rrfK?: number;
234
- embeddingProvider?: EmbeddingProvider | null;
235
- embeddingModel?: string;
146
+ interface IngestDryRunDetail {
147
+ index: number;
148
+ type: MemoryType;
149
+ uri: string;
150
+ preview: string;
236
151
  }
237
- declare function searchHybrid(db: Database.Database, query: string, opts?: HybridSearchOptions): Promise<SearchResult[]>;
238
-
239
- interface StoredEmbedding {
240
- agent_id: string;
241
- memory_id: string;
242
- model: string;
243
- dim: number;
244
- vector: Float32Array;
245
- created_at: string;
246
- updated_at: string;
152
+ interface IngestWriteDetail {
153
+ index: number;
154
+ type: MemoryType;
155
+ uri: string;
156
+ action: "added" | "updated" | "merged" | "skipped";
157
+ reason: string;
158
+ memoryId?: string;
247
159
  }
248
- declare function encodeEmbedding(vector: number[] | Float32Array): Buffer;
249
- declare function decodeEmbedding(buf: Buffer): Float32Array;
250
- declare function upsertEmbedding(db: Database.Database, input: {
251
- agent_id: string;
252
- memory_id: string;
253
- model: string;
254
- vector: number[] | Float32Array;
255
- }): void;
256
- declare function getEmbedding(db: Database.Database, agent_id: string, memory_id: string, model: string): StoredEmbedding | null;
257
- declare function listEmbeddings(db: Database.Database, agent_id: string, model: string): Array<{
258
- memory_id: string;
259
- vector: Float32Array;
260
- }>;
160
+ interface IngestResult {
161
+ extracted: number;
162
+ written: number;
163
+ skipped: number;
164
+ dry_run: boolean;
165
+ details: Array<IngestDryRunDetail | IngestWriteDetail>;
166
+ }
167
+ interface IngestRunOptions {
168
+ text: string;
169
+ source?: string;
170
+ dryRun?: boolean;
171
+ agentId?: string;
172
+ }
173
+ declare function slugify(input: string): string;
174
+ declare function classifyIngestType(text: string): MemoryType;
175
+ declare function splitIngestBlocks(text: string): IngestBlock[];
176
+ declare function extractIngestItems(text: string, source?: string): IngestExtractedItem[];
177
+ declare function ingestText(db: Database.Database, options: IngestRunOptions): IngestResult;
261
178
 
262
- declare function embedMemory(db: Database.Database, memoryId: string, provider: EmbeddingProvider, opts?: {
263
- agent_id?: string;
264
- model?: string;
265
- maxChars?: number;
266
- }): Promise<boolean>;
267
- declare function embedMissingForAgent(db: Database.Database, provider: EmbeddingProvider, opts?: {
268
- agent_id?: string;
269
- model?: string;
270
- limit?: number;
271
- maxChars?: number;
272
- }): Promise<{
273
- embedded: number;
274
- scanned: number;
275
- }>;
179
+ interface AutoIngestWatcherOptions {
180
+ db: Database.Database;
181
+ workspaceDir: string;
182
+ agentId: string;
183
+ debounceMs?: number;
184
+ initialScan?: boolean;
185
+ logger?: Pick<Console, "log" | "warn" | "error">;
186
+ }
187
+ interface AutoIngestWatcher {
188
+ close: () => void;
189
+ }
190
+ declare function runAutoIngestWatcher(options: AutoIngestWatcherOptions): AutoIngestWatcher;
276
191
 
277
192
  /**
278
193
  * Calculate vitality using Ebbinghaus forgetting curve.
@@ -333,30 +248,25 @@ declare function syncBatch(db: Database.Database, inputs: SyncInput[]): SyncResu
333
248
  interface TidyResult {
334
249
  archived: number;
335
250
  orphansCleaned: number;
336
- snapshotsPruned: number;
337
251
  }
338
252
  /**
339
253
  * Run the tidy (deep sleep) cycle:
340
254
  * 1. Archive decayed P3 memories (vitality < threshold)
341
255
  * 2. Clean orphan paths (paths with no memory)
342
- * 3. Prune old snapshots (keep last N per memory)
343
256
  */
344
257
  declare function runTidy(db: Database.Database, opts?: {
345
258
  vitalityThreshold?: number;
346
- maxSnapshotsPerMemory?: number;
347
259
  agent_id?: string;
348
260
  }): TidyResult;
349
261
 
350
262
  interface GovernResult {
351
263
  orphanPaths: number;
352
- orphanLinks: number;
353
264
  emptyMemories: number;
354
265
  }
355
266
  /**
356
267
  * Run governance checks and cleanup:
357
268
  * 1. Remove orphan paths (no parent memory)
358
- * 2. Remove orphan links (source or target missing)
359
- * 3. Remove empty memories (blank content)
269
+ * 2. Remove empty memories (blank content)
360
270
  */
361
271
  declare function runGovern(db: Database.Database, opts?: {
362
272
  agent_id?: string;
@@ -375,4 +285,4 @@ declare function boot(db: Database.Database, opts?: {
375
285
  corePaths?: string[];
376
286
  }): BootResult;
377
287
 
378
- export { type BootResult, type CreateMemoryInput, type EmbeddingProvider, type ExportResult, type GovernResult, type GuardAction, type GuardResult, type HybridSearchOptions, type IntentResult, type Link, type Memory, type MemoryType, type Path, type Priority, type RelationType, type SearchIntent, type SearchResult, type Snapshot, type SnapshotAction, type StoredEmbedding, type SyncInput, type SyncResult, type TidyResult, type UpdateMemoryInput, boot, calculateVitality, classifyIntent, contentHash, countMemories, createDashScopeProvider, createLink, createMemory, createOpenAIProvider, createPath, createSnapshot, decodeEmbedding, deleteLink, deleteMemory, deletePath, embedMemory, embedMissingForAgent, encodeEmbedding, exportMemories, getDecayedMemories, getEmbedding, getEmbeddingProviderFromEnv, getLinks, getMemory, getOutgoingLinks, getPath, getPathByUri, getPathsByDomain, getPathsByMemory, getPathsByPrefix, getSnapshot, getSnapshots, getStrategy, guard, listEmbeddings, listMemories, parseUri, recordAccess, rerank, rollback, runDecay, runGovern, runTidy, searchBM25, searchHybrid, syncBatch, syncOne, tokenize, traverse, updateMemory, upsertEmbedding };
288
+ export { type AutoIngestWatcher, type AutoIngestWatcherOptions, type BootResult, type CreateMemoryInput, type ExportResult, type GovernResult, type GuardAction, type GuardResult, type IngestExtractedItem, type IngestResult, type IngestRunOptions, type Memory, type MemoryType, type Path, type Priority, type SearchResult, type SyncInput, type SyncResult, type TidyResult, type UpdateMemoryInput, boot, calculateVitality, classifyIngestType, contentHash, countMemories, createMemory, createPath, deleteMemory, deletePath, exportMemories, extractIngestItems, getDecayedMemories, getMemory, getPath, getPathByUri, getPathsByDomain, getPathsByMemory, getPathsByPrefix, guard, ingestText, listMemories, parseUri, recordAccess, runAutoIngestWatcher, runDecay, runGovern, runTidy, searchBM25, slugify, splitIngestBlocks, syncBatch, syncOne, tokenize, updateMemory };