moflo 4.0.2 → 4.0.3
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/package.json +114 -110
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +194 -81
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +1892 -1841
- package/v3/@claude-flow/memory/README.md +587 -0
- package/v3/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
- package/v3/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
- package/v3/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
- package/v3/@claude-flow/memory/dist/agent-memory-scope.test.js +463 -0
- package/v3/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
- package/v3/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
- package/v3/@claude-flow/memory/dist/agentdb-backend.d.ts +214 -0
- package/v3/@claude-flow/memory/dist/agentdb-backend.js +844 -0
- package/v3/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
- package/v3/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
- package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
- package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
- package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
- package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
- package/v3/@claude-flow/memory/dist/application/index.d.ts +12 -0
- package/v3/@claude-flow/memory/dist/application/index.js +15 -0
- package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
- package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
- package/v3/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
- package/v3/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
- package/v3/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
- package/v3/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
- package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
- package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.js +754 -0
- package/v3/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
- package/v3/@claude-flow/memory/dist/benchmark.test.js +277 -0
- package/v3/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
- package/v3/@claude-flow/memory/dist/cache-manager.js +407 -0
- package/v3/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
- package/v3/@claude-flow/memory/dist/controller-registry.js +893 -0
- package/v3/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
- package/v3/@claude-flow/memory/dist/controller-registry.test.js +636 -0
- package/v3/@claude-flow/memory/dist/database-provider.d.ts +87 -0
- package/v3/@claude-flow/memory/dist/database-provider.js +410 -0
- package/v3/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
- package/v3/@claude-flow/memory/dist/database-provider.test.js +285 -0
- package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
- package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
- package/v3/@claude-flow/memory/dist/domain/index.d.ts +11 -0
- package/v3/@claude-flow/memory/dist/domain/index.js +12 -0
- package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
- package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
- package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
- package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
- package/v3/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
- package/v3/@claude-flow/memory/dist/hnsw-index.js +781 -0
- package/v3/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
- package/v3/@claude-flow/memory/dist/hnsw-lite.js +168 -0
- package/v3/@claude-flow/memory/dist/hybrid-backend.d.ts +245 -0
- package/v3/@claude-flow/memory/dist/hybrid-backend.js +569 -0
- package/v3/@claude-flow/memory/dist/hybrid-backend.test.d.ts +8 -0
- package/v3/@claude-flow/memory/dist/hybrid-backend.test.js +320 -0
- package/v3/@claude-flow/memory/dist/index.d.ts +208 -0
- package/v3/@claude-flow/memory/dist/index.js +362 -0
- package/v3/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
- package/v3/@claude-flow/memory/dist/infrastructure/index.js +16 -0
- package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
- package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
- package/v3/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
- package/v3/@claude-flow/memory/dist/learning-bridge.js +335 -0
- package/v3/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
- package/v3/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
- package/v3/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
- package/v3/@claude-flow/memory/dist/memory-graph.js +333 -0
- package/v3/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
- package/v3/@claude-flow/memory/dist/memory-graph.test.js +609 -0
- package/v3/@claude-flow/memory/dist/migration.d.ts +68 -0
- package/v3/@claude-flow/memory/dist/migration.js +513 -0
- package/v3/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
- package/v3/@claude-flow/memory/dist/persistent-sona.js +332 -0
- package/v3/@claude-flow/memory/dist/query-builder.d.ts +211 -0
- package/v3/@claude-flow/memory/dist/query-builder.js +438 -0
- package/v3/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
- package/v3/@claude-flow/memory/dist/rvf-backend.js +481 -0
- package/v3/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
- package/v3/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
- package/v3/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
- package/v3/@claude-flow/memory/dist/rvf-migration.js +254 -0
- package/v3/@claude-flow/memory/dist/sqlite-backend.d.ts +121 -0
- package/v3/@claude-flow/memory/dist/sqlite-backend.js +564 -0
- package/v3/@claude-flow/memory/dist/sqljs-backend.d.ts +128 -0
- package/v3/@claude-flow/memory/dist/sqljs-backend.js +601 -0
- package/v3/@claude-flow/memory/dist/types.d.ts +484 -0
- package/v3/@claude-flow/memory/dist/types.js +58 -0
- package/v3/@claude-flow/memory/package.json +46 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentDB Backend Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for agentdb@2.0.0-alpha.3.4 integration with V3 memory system
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import { AgentDBBackend } from './agentdb-backend.js';
|
|
8
|
+
import { createDefaultEntry } from './types.js';
|
|
9
|
+
describe('AgentDBBackend', () => {
|
|
10
|
+
let backend;
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
backend = new AgentDBBackend({
|
|
13
|
+
dbPath: ':memory:',
|
|
14
|
+
namespace: 'test',
|
|
15
|
+
vectorDimension: 384,
|
|
16
|
+
});
|
|
17
|
+
await backend.initialize();
|
|
18
|
+
});
|
|
19
|
+
afterEach(async () => {
|
|
20
|
+
await backend.shutdown();
|
|
21
|
+
});
|
|
22
|
+
describe('Initialization', () => {
|
|
23
|
+
it('should initialize successfully', async () => {
|
|
24
|
+
expect(backend).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
it('should handle missing agentdb gracefully', async () => {
|
|
27
|
+
const fallbackBackend = new AgentDBBackend();
|
|
28
|
+
await fallbackBackend.initialize();
|
|
29
|
+
// Should still work with in-memory fallback
|
|
30
|
+
expect(fallbackBackend).toBeDefined();
|
|
31
|
+
await fallbackBackend.shutdown();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('Basic CRUD Operations', () => {
|
|
35
|
+
it('should store and retrieve entries', async () => {
|
|
36
|
+
const entry = createDefaultEntry({
|
|
37
|
+
key: 'test-key',
|
|
38
|
+
content: 'Test content',
|
|
39
|
+
type: 'episodic',
|
|
40
|
+
});
|
|
41
|
+
await backend.store(entry);
|
|
42
|
+
const retrieved = await backend.get(entry.id);
|
|
43
|
+
expect(retrieved).toBeDefined();
|
|
44
|
+
expect(retrieved?.content).toBe('Test content');
|
|
45
|
+
});
|
|
46
|
+
it('should get entry by key', async () => {
|
|
47
|
+
const entry = createDefaultEntry({
|
|
48
|
+
key: 'unique-key',
|
|
49
|
+
content: 'Unique content',
|
|
50
|
+
namespace: 'test',
|
|
51
|
+
});
|
|
52
|
+
await backend.store(entry);
|
|
53
|
+
const retrieved = await backend.getByKey('test', 'unique-key');
|
|
54
|
+
expect(retrieved).toBeDefined();
|
|
55
|
+
expect(retrieved?.content).toBe('Unique content');
|
|
56
|
+
});
|
|
57
|
+
it('should update entries', async () => {
|
|
58
|
+
const entry = createDefaultEntry({
|
|
59
|
+
key: 'update-test',
|
|
60
|
+
content: 'Original content',
|
|
61
|
+
});
|
|
62
|
+
await backend.store(entry);
|
|
63
|
+
const originalVersion = entry.version;
|
|
64
|
+
const updated = await backend.update(entry.id, {
|
|
65
|
+
content: 'Updated content',
|
|
66
|
+
});
|
|
67
|
+
expect(updated?.content).toBe('Updated content');
|
|
68
|
+
expect(updated?.version).toBe(originalVersion + 1);
|
|
69
|
+
});
|
|
70
|
+
it('should delete entries', async () => {
|
|
71
|
+
const entry = createDefaultEntry({
|
|
72
|
+
key: 'delete-test',
|
|
73
|
+
content: 'To be deleted',
|
|
74
|
+
});
|
|
75
|
+
await backend.store(entry);
|
|
76
|
+
const deleted = await backend.delete(entry.id);
|
|
77
|
+
expect(deleted).toBe(true);
|
|
78
|
+
const retrieved = await backend.get(entry.id);
|
|
79
|
+
expect(retrieved).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('Query Operations', () => {
|
|
83
|
+
beforeEach(async () => {
|
|
84
|
+
// Insert test data
|
|
85
|
+
await backend.store(createDefaultEntry({
|
|
86
|
+
key: 'entry-1',
|
|
87
|
+
content: 'First entry',
|
|
88
|
+
namespace: 'test',
|
|
89
|
+
tags: ['tag1', 'tag2'],
|
|
90
|
+
}));
|
|
91
|
+
await backend.store(createDefaultEntry({
|
|
92
|
+
key: 'entry-2',
|
|
93
|
+
content: 'Second entry',
|
|
94
|
+
namespace: 'test',
|
|
95
|
+
tags: ['tag2', 'tag3'],
|
|
96
|
+
}));
|
|
97
|
+
await backend.store(createDefaultEntry({
|
|
98
|
+
key: 'entry-3',
|
|
99
|
+
content: 'Third entry',
|
|
100
|
+
namespace: 'other',
|
|
101
|
+
tags: ['tag1'],
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
it('should query by namespace', async () => {
|
|
105
|
+
const results = await backend.query({
|
|
106
|
+
type: 'hybrid',
|
|
107
|
+
namespace: 'test',
|
|
108
|
+
limit: 10,
|
|
109
|
+
});
|
|
110
|
+
expect(results.length).toBe(2);
|
|
111
|
+
});
|
|
112
|
+
it('should query by exact key', async () => {
|
|
113
|
+
const results = await backend.query({
|
|
114
|
+
type: 'exact',
|
|
115
|
+
namespace: 'test',
|
|
116
|
+
key: 'entry-1',
|
|
117
|
+
limit: 10,
|
|
118
|
+
});
|
|
119
|
+
expect(results.length).toBe(1);
|
|
120
|
+
expect(results[0].content).toBe('First entry');
|
|
121
|
+
});
|
|
122
|
+
it('should query by prefix', async () => {
|
|
123
|
+
const results = await backend.query({
|
|
124
|
+
type: 'prefix',
|
|
125
|
+
keyPrefix: 'entry-',
|
|
126
|
+
limit: 10,
|
|
127
|
+
});
|
|
128
|
+
expect(results.length).toBeGreaterThanOrEqual(2);
|
|
129
|
+
});
|
|
130
|
+
it('should query by tags', async () => {
|
|
131
|
+
const results = await backend.query({
|
|
132
|
+
type: 'tag',
|
|
133
|
+
tags: ['tag2'],
|
|
134
|
+
limit: 10,
|
|
135
|
+
});
|
|
136
|
+
expect(results.length).toBe(2);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('Vector Search', () => {
|
|
140
|
+
it('should perform brute-force search when agentdb unavailable', async () => {
|
|
141
|
+
const entry = createDefaultEntry({
|
|
142
|
+
key: 'vector-test',
|
|
143
|
+
content: 'Vector content',
|
|
144
|
+
});
|
|
145
|
+
// Create a fake embedding
|
|
146
|
+
entry.embedding = new Float32Array([0.1, 0.2, 0.3, 0.4]);
|
|
147
|
+
await backend.store(entry);
|
|
148
|
+
const queryEmbedding = new Float32Array([0.1, 0.2, 0.3, 0.4]);
|
|
149
|
+
const results = await backend.search(queryEmbedding, { k: 5 });
|
|
150
|
+
expect(results.length).toBeGreaterThan(0);
|
|
151
|
+
expect(results[0].entry.id).toBe(entry.id);
|
|
152
|
+
});
|
|
153
|
+
it('should handle semantic queries', async () => {
|
|
154
|
+
const entry = createDefaultEntry({
|
|
155
|
+
key: 'semantic-test',
|
|
156
|
+
content: 'Semantic content',
|
|
157
|
+
});
|
|
158
|
+
entry.embedding = new Float32Array([0.5, 0.5, 0.5, 0.5]);
|
|
159
|
+
await backend.store(entry);
|
|
160
|
+
const results = await backend.query({
|
|
161
|
+
type: 'semantic',
|
|
162
|
+
embedding: new Float32Array([0.5, 0.5, 0.5, 0.5]),
|
|
163
|
+
limit: 5,
|
|
164
|
+
});
|
|
165
|
+
expect(results.length).toBeGreaterThan(0);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('Bulk Operations', () => {
|
|
169
|
+
it('should bulk insert entries', async () => {
|
|
170
|
+
const entries = [
|
|
171
|
+
createDefaultEntry({ key: 'bulk-1', content: 'Bulk 1' }),
|
|
172
|
+
createDefaultEntry({ key: 'bulk-2', content: 'Bulk 2' }),
|
|
173
|
+
createDefaultEntry({ key: 'bulk-3', content: 'Bulk 3' }),
|
|
174
|
+
];
|
|
175
|
+
await backend.bulkInsert(entries);
|
|
176
|
+
const count = await backend.count();
|
|
177
|
+
expect(count).toBeGreaterThanOrEqual(3);
|
|
178
|
+
});
|
|
179
|
+
it('should bulk delete entries', async () => {
|
|
180
|
+
const entries = [
|
|
181
|
+
createDefaultEntry({ key: 'delete-1', content: 'Delete 1' }),
|
|
182
|
+
createDefaultEntry({ key: 'delete-2', content: 'Delete 2' }),
|
|
183
|
+
];
|
|
184
|
+
await backend.bulkInsert(entries);
|
|
185
|
+
const ids = entries.map((e) => e.id);
|
|
186
|
+
const deleted = await backend.bulkDelete(ids);
|
|
187
|
+
expect(deleted).toBe(2);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('Statistics and Health', () => {
|
|
191
|
+
it('should provide backend statistics', async () => {
|
|
192
|
+
await backend.store(createDefaultEntry({ key: 'stats-test', content: 'Stats content' }));
|
|
193
|
+
const stats = await backend.getStats();
|
|
194
|
+
expect(stats.totalEntries).toBeGreaterThan(0);
|
|
195
|
+
expect(stats.avgQueryTime).toBeGreaterThanOrEqual(0);
|
|
196
|
+
expect(stats.memoryUsage).toBeGreaterThan(0);
|
|
197
|
+
});
|
|
198
|
+
it('should perform health checks', async () => {
|
|
199
|
+
const health = await backend.healthCheck();
|
|
200
|
+
expect(health.status).toBeDefined();
|
|
201
|
+
expect(['healthy', 'degraded', 'unhealthy']).toContain(health.status);
|
|
202
|
+
expect(health.components).toBeDefined();
|
|
203
|
+
expect(health.components.storage).toBeDefined();
|
|
204
|
+
expect(health.components.index).toBeDefined();
|
|
205
|
+
expect(health.components.cache).toBeDefined();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('Namespace Operations', () => {
|
|
209
|
+
beforeEach(async () => {
|
|
210
|
+
await backend.store(createDefaultEntry({
|
|
211
|
+
key: 'ns1-entry',
|
|
212
|
+
content: 'NS1',
|
|
213
|
+
namespace: 'namespace1',
|
|
214
|
+
}));
|
|
215
|
+
await backend.store(createDefaultEntry({
|
|
216
|
+
key: 'ns2-entry',
|
|
217
|
+
content: 'NS2',
|
|
218
|
+
namespace: 'namespace2',
|
|
219
|
+
}));
|
|
220
|
+
});
|
|
221
|
+
it('should list namespaces', async () => {
|
|
222
|
+
const namespaces = await backend.listNamespaces();
|
|
223
|
+
expect(namespaces).toContain('namespace1');
|
|
224
|
+
expect(namespaces).toContain('namespace2');
|
|
225
|
+
});
|
|
226
|
+
it('should count entries by namespace', async () => {
|
|
227
|
+
const count = await backend.count('namespace1');
|
|
228
|
+
expect(count).toBe(1);
|
|
229
|
+
});
|
|
230
|
+
it('should clear namespace', async () => {
|
|
231
|
+
const cleared = await backend.clearNamespace('namespace1');
|
|
232
|
+
expect(cleared).toBe(1);
|
|
233
|
+
const count = await backend.count('namespace1');
|
|
234
|
+
expect(count).toBe(0);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
describe('Graceful Degradation', () => {
|
|
238
|
+
it('should work without agentdb package', async () => {
|
|
239
|
+
const fallbackBackend = new AgentDBBackend({
|
|
240
|
+
dbPath: ':memory:',
|
|
241
|
+
});
|
|
242
|
+
await fallbackBackend.initialize();
|
|
243
|
+
const entry = createDefaultEntry({
|
|
244
|
+
key: 'fallback-test',
|
|
245
|
+
content: 'Fallback content',
|
|
246
|
+
});
|
|
247
|
+
await fallbackBackend.store(entry);
|
|
248
|
+
const retrieved = await fallbackBackend.get(entry.id);
|
|
249
|
+
expect(retrieved).toBeDefined();
|
|
250
|
+
expect(retrieved?.content).toBe('Fallback content');
|
|
251
|
+
await fallbackBackend.shutdown();
|
|
252
|
+
});
|
|
253
|
+
it('should indicate availability status', () => {
|
|
254
|
+
expect(typeof backend.isAvailable()).toBe('boolean');
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
//# sourceMappingURL=agentdb-backend.test.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delete Memory Command - Application Layer (CQRS)
|
|
3
|
+
*
|
|
4
|
+
* Command for deleting memory entries.
|
|
5
|
+
* Supports soft delete and hard delete.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/application/commands
|
|
8
|
+
*/
|
|
9
|
+
import { IMemoryRepository } from '../../domain/repositories/memory-repository.interface.js';
|
|
10
|
+
/**
|
|
11
|
+
* Delete Memory Command Input
|
|
12
|
+
*/
|
|
13
|
+
export interface DeleteMemoryInput {
|
|
14
|
+
id?: string;
|
|
15
|
+
namespace?: string;
|
|
16
|
+
key?: string;
|
|
17
|
+
hardDelete?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Delete Memory Command Result
|
|
21
|
+
*/
|
|
22
|
+
export interface DeleteMemoryResult {
|
|
23
|
+
success: boolean;
|
|
24
|
+
deleted: boolean;
|
|
25
|
+
entryId?: string;
|
|
26
|
+
wasHardDelete: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Delete Memory Command Handler
|
|
30
|
+
*/
|
|
31
|
+
export declare class DeleteMemoryCommandHandler {
|
|
32
|
+
private readonly repository;
|
|
33
|
+
constructor(repository: IMemoryRepository);
|
|
34
|
+
execute(input: DeleteMemoryInput): Promise<DeleteMemoryResult>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Bulk Delete Command Input
|
|
38
|
+
*/
|
|
39
|
+
export interface BulkDeleteMemoryInput {
|
|
40
|
+
ids?: string[];
|
|
41
|
+
namespace?: string;
|
|
42
|
+
olderThan?: Date;
|
|
43
|
+
hardDelete?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Bulk Delete Command Result
|
|
47
|
+
*/
|
|
48
|
+
export interface BulkDeleteMemoryResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
deletedCount: number;
|
|
51
|
+
failedCount: number;
|
|
52
|
+
errors: Array<{
|
|
53
|
+
id: string;
|
|
54
|
+
error: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bulk Delete Memory Command Handler
|
|
59
|
+
*/
|
|
60
|
+
export declare class BulkDeleteMemoryCommandHandler {
|
|
61
|
+
private readonly repository;
|
|
62
|
+
constructor(repository: IMemoryRepository);
|
|
63
|
+
execute(input: BulkDeleteMemoryInput): Promise<BulkDeleteMemoryResult>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=delete-memory.command.d.ts.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delete Memory Command - Application Layer (CQRS)
|
|
3
|
+
*
|
|
4
|
+
* Command for deleting memory entries.
|
|
5
|
+
* Supports soft delete and hard delete.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/application/commands
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Delete Memory Command Handler
|
|
11
|
+
*/
|
|
12
|
+
export class DeleteMemoryCommandHandler {
|
|
13
|
+
repository;
|
|
14
|
+
constructor(repository) {
|
|
15
|
+
this.repository = repository;
|
|
16
|
+
}
|
|
17
|
+
async execute(input) {
|
|
18
|
+
let entryId;
|
|
19
|
+
// Find entry by ID or by namespace:key
|
|
20
|
+
if (input.id) {
|
|
21
|
+
entryId = input.id;
|
|
22
|
+
}
|
|
23
|
+
else if (input.namespace && input.key) {
|
|
24
|
+
const entry = await this.repository.findByKey(input.namespace, input.key);
|
|
25
|
+
entryId = entry?.id;
|
|
26
|
+
}
|
|
27
|
+
if (!entryId) {
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
deleted: false,
|
|
31
|
+
wasHardDelete: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (input.hardDelete) {
|
|
35
|
+
// Hard delete - remove from database
|
|
36
|
+
const deleted = await this.repository.delete(entryId);
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
deleted,
|
|
40
|
+
entryId,
|
|
41
|
+
wasHardDelete: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Soft delete - mark as deleted
|
|
46
|
+
const entry = await this.repository.findById(entryId);
|
|
47
|
+
if (entry) {
|
|
48
|
+
entry.delete();
|
|
49
|
+
await this.repository.save(entry);
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
deleted: true,
|
|
53
|
+
entryId,
|
|
54
|
+
wasHardDelete: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
deleted: false,
|
|
61
|
+
entryId,
|
|
62
|
+
wasHardDelete: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Bulk Delete Memory Command Handler
|
|
68
|
+
*/
|
|
69
|
+
export class BulkDeleteMemoryCommandHandler {
|
|
70
|
+
repository;
|
|
71
|
+
constructor(repository) {
|
|
72
|
+
this.repository = repository;
|
|
73
|
+
}
|
|
74
|
+
async execute(input) {
|
|
75
|
+
let idsToDelete = [];
|
|
76
|
+
if (input.ids) {
|
|
77
|
+
idsToDelete = input.ids;
|
|
78
|
+
}
|
|
79
|
+
else if (input.namespace) {
|
|
80
|
+
const entries = await this.repository.findByNamespace(input.namespace);
|
|
81
|
+
idsToDelete = entries
|
|
82
|
+
.filter((e) => !input.olderThan || e.createdAt < input.olderThan)
|
|
83
|
+
.map((e) => e.id);
|
|
84
|
+
}
|
|
85
|
+
if (idsToDelete.length === 0) {
|
|
86
|
+
return {
|
|
87
|
+
success: true,
|
|
88
|
+
deletedCount: 0,
|
|
89
|
+
failedCount: 0,
|
|
90
|
+
errors: [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (input.hardDelete) {
|
|
94
|
+
const result = await this.repository.deleteMany(idsToDelete);
|
|
95
|
+
return {
|
|
96
|
+
success: result.failed === 0,
|
|
97
|
+
deletedCount: result.success,
|
|
98
|
+
failedCount: result.failed,
|
|
99
|
+
errors: result.errors,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Soft delete
|
|
104
|
+
const entries = await this.repository.findByIds(idsToDelete);
|
|
105
|
+
let deletedCount = 0;
|
|
106
|
+
const errors = [];
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
try {
|
|
109
|
+
entry.delete();
|
|
110
|
+
await this.repository.save(entry);
|
|
111
|
+
deletedCount++;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
errors.push({
|
|
115
|
+
id: entry.id,
|
|
116
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
success: errors.length === 0,
|
|
122
|
+
deletedCount,
|
|
123
|
+
failedCount: errors.length,
|
|
124
|
+
errors,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=delete-memory.command.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store Memory Command - Application Layer (CQRS)
|
|
3
|
+
*
|
|
4
|
+
* Command for storing a new memory entry.
|
|
5
|
+
* Implements CQRS pattern per ADR-002.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/application/commands
|
|
8
|
+
*/
|
|
9
|
+
import { MemoryEntry, MemoryType } from '../../domain/entities/memory-entry.js';
|
|
10
|
+
import { IMemoryRepository } from '../../domain/repositories/memory-repository.interface.js';
|
|
11
|
+
import { MemoryDomainService } from '../../domain/services/memory-domain-service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Store Memory Command Input
|
|
14
|
+
*/
|
|
15
|
+
export interface StoreMemoryInput {
|
|
16
|
+
namespace: string;
|
|
17
|
+
key: string;
|
|
18
|
+
value: unknown;
|
|
19
|
+
type?: MemoryType;
|
|
20
|
+
vector?: Float32Array;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
ttl?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Store Memory Command Result
|
|
26
|
+
*/
|
|
27
|
+
export interface StoreMemoryResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
entryId: string;
|
|
30
|
+
entry: MemoryEntry;
|
|
31
|
+
isUpdate: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Store Memory Command Handler
|
|
35
|
+
*
|
|
36
|
+
* Handles the command to store a memory entry.
|
|
37
|
+
* Coordinates between domain services and repository.
|
|
38
|
+
*/
|
|
39
|
+
export declare class StoreMemoryCommandHandler {
|
|
40
|
+
private readonly repository;
|
|
41
|
+
private readonly domainService;
|
|
42
|
+
constructor(repository: IMemoryRepository, domainService: MemoryDomainService);
|
|
43
|
+
/**
|
|
44
|
+
* Execute the store memory command
|
|
45
|
+
*/
|
|
46
|
+
execute(input: StoreMemoryInput): Promise<StoreMemoryResult>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=store-memory.command.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store Memory Command - Application Layer (CQRS)
|
|
3
|
+
*
|
|
4
|
+
* Command for storing a new memory entry.
|
|
5
|
+
* Implements CQRS pattern per ADR-002.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/application/commands
|
|
8
|
+
*/
|
|
9
|
+
import { MemoryEntry } from '../../domain/entities/memory-entry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Store Memory Command Handler
|
|
12
|
+
*
|
|
13
|
+
* Handles the command to store a memory entry.
|
|
14
|
+
* Coordinates between domain services and repository.
|
|
15
|
+
*/
|
|
16
|
+
export class StoreMemoryCommandHandler {
|
|
17
|
+
repository;
|
|
18
|
+
domainService;
|
|
19
|
+
constructor(repository, domainService) {
|
|
20
|
+
this.repository = repository;
|
|
21
|
+
this.domainService = domainService;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Execute the store memory command
|
|
25
|
+
*/
|
|
26
|
+
async execute(input) {
|
|
27
|
+
// Check if entry already exists
|
|
28
|
+
const existing = await this.repository.findByKey(input.namespace, input.key);
|
|
29
|
+
const isUpdate = existing !== null;
|
|
30
|
+
let entry;
|
|
31
|
+
if (existing) {
|
|
32
|
+
// Update existing entry
|
|
33
|
+
existing.updateValue(input.value);
|
|
34
|
+
if (input.vector) {
|
|
35
|
+
existing.updateVector(input.vector);
|
|
36
|
+
}
|
|
37
|
+
if (input.metadata) {
|
|
38
|
+
for (const [key, value] of Object.entries(input.metadata)) {
|
|
39
|
+
existing.setMetadata(key, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
await this.repository.save(existing);
|
|
43
|
+
entry = existing;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Create new entry
|
|
47
|
+
if (input.type) {
|
|
48
|
+
entry = MemoryEntry.create({
|
|
49
|
+
namespace: input.namespace,
|
|
50
|
+
key: input.key,
|
|
51
|
+
value: input.value,
|
|
52
|
+
type: input.type,
|
|
53
|
+
vector: input.vector,
|
|
54
|
+
metadata: input.metadata,
|
|
55
|
+
ttl: input.ttl,
|
|
56
|
+
});
|
|
57
|
+
await this.repository.save(entry);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Use domain service for type detection
|
|
61
|
+
entry = await this.domainService.storeWithTypeDetection(input.namespace, input.key, input.value, input.vector);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
success: true,
|
|
66
|
+
entryId: entry.id,
|
|
67
|
+
entry,
|
|
68
|
+
isUpdate,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=store-memory.command.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Application Layer - Public Exports
|
|
3
|
+
*
|
|
4
|
+
* Exports all application services, commands, and queries.
|
|
5
|
+
*
|
|
6
|
+
* @module v3/memory/application
|
|
7
|
+
*/
|
|
8
|
+
export { StoreMemoryCommandHandler, type StoreMemoryInput, type StoreMemoryResult, } from './commands/store-memory.command.js';
|
|
9
|
+
export { DeleteMemoryCommandHandler, BulkDeleteMemoryCommandHandler, type DeleteMemoryInput, type DeleteMemoryResult, type BulkDeleteMemoryInput, type BulkDeleteMemoryResult, } from './commands/delete-memory.command.js';
|
|
10
|
+
export { SearchMemoryQueryHandler, GetMemoryByKeyQueryHandler, type SearchMemoryInput, type SearchMemoryResult, type GetMemoryByKeyInput, type GetMemoryByKeyResult, } from './queries/search-memory.query.js';
|
|
11
|
+
export { MemoryApplicationService } from './services/memory-application-service.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Application Layer - Public Exports
|
|
3
|
+
*
|
|
4
|
+
* Exports all application services, commands, and queries.
|
|
5
|
+
*
|
|
6
|
+
* @module v3/memory/application
|
|
7
|
+
*/
|
|
8
|
+
// Commands
|
|
9
|
+
export { StoreMemoryCommandHandler, } from './commands/store-memory.command.js';
|
|
10
|
+
export { DeleteMemoryCommandHandler, BulkDeleteMemoryCommandHandler, } from './commands/delete-memory.command.js';
|
|
11
|
+
// Queries
|
|
12
|
+
export { SearchMemoryQueryHandler, GetMemoryByKeyQueryHandler, } from './queries/search-memory.query.js';
|
|
13
|
+
// Application Service
|
|
14
|
+
export { MemoryApplicationService } from './services/memory-application-service.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Memory Query - Application Layer (CQRS)
|
|
3
|
+
*
|
|
4
|
+
* Query for searching memory entries.
|
|
5
|
+
* Supports text search, vector search, and filtering.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/application/queries
|
|
8
|
+
*/
|
|
9
|
+
import { MemoryEntry, MemoryType, MemoryStatus } from '../../domain/entities/memory-entry.js';
|
|
10
|
+
import { IMemoryRepository } from '../../domain/repositories/memory-repository.interface.js';
|
|
11
|
+
/**
|
|
12
|
+
* Search Memory Query Input
|
|
13
|
+
*/
|
|
14
|
+
export interface SearchMemoryInput {
|
|
15
|
+
vector?: Float32Array;
|
|
16
|
+
similarityThreshold?: number;
|
|
17
|
+
namespace?: string;
|
|
18
|
+
type?: MemoryType;
|
|
19
|
+
status?: MemoryStatus;
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
orderBy?: 'createdAt' | 'updatedAt' | 'accessCount' | 'lastAccessedAt';
|
|
23
|
+
orderDirection?: 'asc' | 'desc';
|
|
24
|
+
textQuery?: string;
|
|
25
|
+
trackAccess?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Search Memory Query Result
|
|
29
|
+
*/
|
|
30
|
+
export interface SearchMemoryResult {
|
|
31
|
+
entries: MemoryEntry[];
|
|
32
|
+
total: number;
|
|
33
|
+
hasMore: boolean;
|
|
34
|
+
searchType: 'vector' | 'filter' | 'text';
|
|
35
|
+
similarities?: number[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Search Memory Query Handler
|
|
39
|
+
*/
|
|
40
|
+
export declare class SearchMemoryQueryHandler {
|
|
41
|
+
private readonly repository;
|
|
42
|
+
constructor(repository: IMemoryRepository);
|
|
43
|
+
execute(input: SearchMemoryInput): Promise<SearchMemoryResult>;
|
|
44
|
+
private executeVectorSearch;
|
|
45
|
+
private executeTextSearch;
|
|
46
|
+
private executeFilterSearch;
|
|
47
|
+
private trackEntryAccess;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get Memory By Key Query Input
|
|
51
|
+
*/
|
|
52
|
+
export interface GetMemoryByKeyInput {
|
|
53
|
+
namespace: string;
|
|
54
|
+
key: string;
|
|
55
|
+
trackAccess?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get Memory By Key Query Result
|
|
59
|
+
*/
|
|
60
|
+
export interface GetMemoryByKeyResult {
|
|
61
|
+
found: boolean;
|
|
62
|
+
entry?: MemoryEntry;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get Memory By Key Query Handler
|
|
66
|
+
*/
|
|
67
|
+
export declare class GetMemoryByKeyQueryHandler {
|
|
68
|
+
private readonly repository;
|
|
69
|
+
constructor(repository: IMemoryRepository);
|
|
70
|
+
execute(input: GetMemoryByKeyInput): Promise<GetMemoryByKeyResult>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=search-memory.query.d.ts.map
|