@claude-flow/memory 3.0.0-alpha.1
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/.agentic-flow/intelligence.json +16 -0
- package/README.md +249 -0
- package/__tests__/coverage/base.css +224 -0
- package/__tests__/coverage/block-navigation.js +87 -0
- package/__tests__/coverage/coverage-final.json +19 -0
- package/__tests__/coverage/favicon.png +0 -0
- package/__tests__/coverage/index.html +206 -0
- package/__tests__/coverage/lcov-report/base.css +224 -0
- package/__tests__/coverage/lcov-report/block-navigation.js +87 -0
- package/__tests__/coverage/lcov-report/favicon.png +0 -0
- package/__tests__/coverage/lcov-report/index.html +206 -0
- package/__tests__/coverage/lcov-report/prettify.css +1 -0
- package/__tests__/coverage/lcov-report/prettify.js +2 -0
- package/__tests__/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/__tests__/coverage/lcov-report/sorter.js +210 -0
- package/__tests__/coverage/lcov-report/src/agentdb-adapter.ts.html +2737 -0
- package/__tests__/coverage/lcov-report/src/agentdb-backend.ts.html +3130 -0
- package/__tests__/coverage/lcov-report/src/application/commands/delete-memory.command.ts.html +601 -0
- package/__tests__/coverage/lcov-report/src/application/commands/index.html +131 -0
- package/__tests__/coverage/lcov-report/src/application/commands/store-memory.command.ts.html +394 -0
- package/__tests__/coverage/lcov-report/src/application/queries/index.html +116 -0
- package/__tests__/coverage/lcov-report/src/application/queries/search-memory.query.ts.html +796 -0
- package/__tests__/coverage/lcov-report/src/application/services/index.html +116 -0
- package/__tests__/coverage/lcov-report/src/application/services/memory-application-service.ts.html +793 -0
- package/__tests__/coverage/lcov-report/src/cache-manager.ts.html +1633 -0
- package/__tests__/coverage/lcov-report/src/database-provider.ts.html +1618 -0
- package/__tests__/coverage/lcov-report/src/domain/entities/index.html +116 -0
- package/__tests__/coverage/lcov-report/src/domain/entities/memory-entry.ts.html +952 -0
- package/__tests__/coverage/lcov-report/src/domain/services/index.html +116 -0
- package/__tests__/coverage/lcov-report/src/domain/services/memory-domain-service.ts.html +1294 -0
- package/__tests__/coverage/lcov-report/src/hnsw-index.ts.html +3124 -0
- package/__tests__/coverage/lcov-report/src/hybrid-backend.ts.html +2167 -0
- package/__tests__/coverage/lcov-report/src/index.html +266 -0
- package/__tests__/coverage/lcov-report/src/infrastructure/repositories/hybrid-memory-repository.ts.html +1633 -0
- package/__tests__/coverage/lcov-report/src/infrastructure/repositories/index.html +116 -0
- package/__tests__/coverage/lcov-report/src/migration.ts.html +2092 -0
- package/__tests__/coverage/lcov-report/src/query-builder.ts.html +1711 -0
- package/__tests__/coverage/lcov-report/src/sqlite-backend.ts.html +2281 -0
- package/__tests__/coverage/lcov-report/src/sqljs-backend.ts.html +2374 -0
- package/__tests__/coverage/lcov-report/src/types.ts.html +2266 -0
- package/__tests__/coverage/lcov.info +10238 -0
- package/__tests__/coverage/prettify.css +1 -0
- package/__tests__/coverage/prettify.js +2 -0
- package/__tests__/coverage/sort-arrow-sprite.png +0 -0
- package/__tests__/coverage/sorter.js +210 -0
- package/__tests__/coverage/src/agentdb-adapter.ts.html +2737 -0
- package/__tests__/coverage/src/agentdb-backend.ts.html +3130 -0
- package/__tests__/coverage/src/application/commands/delete-memory.command.ts.html +601 -0
- package/__tests__/coverage/src/application/commands/index.html +131 -0
- package/__tests__/coverage/src/application/commands/store-memory.command.ts.html +394 -0
- package/__tests__/coverage/src/application/queries/index.html +116 -0
- package/__tests__/coverage/src/application/queries/search-memory.query.ts.html +796 -0
- package/__tests__/coverage/src/application/services/index.html +116 -0
- package/__tests__/coverage/src/application/services/memory-application-service.ts.html +793 -0
- package/__tests__/coverage/src/cache-manager.ts.html +1633 -0
- package/__tests__/coverage/src/database-provider.ts.html +1618 -0
- package/__tests__/coverage/src/domain/entities/index.html +116 -0
- package/__tests__/coverage/src/domain/entities/memory-entry.ts.html +952 -0
- package/__tests__/coverage/src/domain/services/index.html +116 -0
- package/__tests__/coverage/src/domain/services/memory-domain-service.ts.html +1294 -0
- package/__tests__/coverage/src/hnsw-index.ts.html +3124 -0
- package/__tests__/coverage/src/hybrid-backend.ts.html +2167 -0
- package/__tests__/coverage/src/index.html +266 -0
- package/__tests__/coverage/src/infrastructure/repositories/hybrid-memory-repository.ts.html +1633 -0
- package/__tests__/coverage/src/infrastructure/repositories/index.html +116 -0
- package/__tests__/coverage/src/migration.ts.html +2092 -0
- package/__tests__/coverage/src/query-builder.ts.html +1711 -0
- package/__tests__/coverage/src/sqlite-backend.ts.html +2281 -0
- package/__tests__/coverage/src/sqljs-backend.ts.html +2374 -0
- package/__tests__/coverage/src/types.ts.html +2266 -0
- package/benchmarks/cache-hit-rate.bench.ts +535 -0
- package/benchmarks/hnsw-indexing.bench.ts +552 -0
- package/benchmarks/memory-write.bench.ts +469 -0
- package/benchmarks/vector-search.bench.ts +449 -0
- package/dist/agentdb-adapter.d.ts +146 -0
- package/dist/agentdb-adapter.d.ts.map +1 -0
- package/dist/agentdb-adapter.js +679 -0
- package/dist/agentdb-adapter.js.map +1 -0
- package/dist/agentdb-backend.d.ts +214 -0
- package/dist/agentdb-backend.d.ts.map +1 -0
- package/dist/agentdb-backend.js +827 -0
- package/dist/agentdb-backend.js.map +1 -0
- package/dist/agentdb-backend.test.d.ts +7 -0
- package/dist/agentdb-backend.test.d.ts.map +1 -0
- package/dist/agentdb-backend.test.js +258 -0
- package/dist/agentdb-backend.test.js.map +1 -0
- package/dist/application/commands/delete-memory.command.d.ts +65 -0
- package/dist/application/commands/delete-memory.command.d.ts.map +1 -0
- package/dist/application/commands/delete-memory.command.js +129 -0
- package/dist/application/commands/delete-memory.command.js.map +1 -0
- package/dist/application/commands/store-memory.command.d.ts +48 -0
- package/dist/application/commands/store-memory.command.d.ts.map +1 -0
- package/dist/application/commands/store-memory.command.js +72 -0
- package/dist/application/commands/store-memory.command.js.map +1 -0
- package/dist/application/index.d.ts +12 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +15 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/queries/search-memory.query.d.ts +72 -0
- package/dist/application/queries/search-memory.query.d.ts.map +1 -0
- package/dist/application/queries/search-memory.query.js +143 -0
- package/dist/application/queries/search-memory.query.js.map +1 -0
- package/dist/application/services/memory-application-service.d.ts +121 -0
- package/dist/application/services/memory-application-service.d.ts.map +1 -0
- package/dist/application/services/memory-application-service.js +190 -0
- package/dist/application/services/memory-application-service.js.map +1 -0
- package/dist/cache-manager.d.ts +134 -0
- package/dist/cache-manager.d.ts.map +1 -0
- package/dist/cache-manager.js +407 -0
- package/dist/cache-manager.js.map +1 -0
- package/dist/database-provider.d.ts +86 -0
- package/dist/database-provider.d.ts.map +1 -0
- package/dist/database-provider.js +385 -0
- package/dist/database-provider.js.map +1 -0
- package/dist/database-provider.test.d.ts +7 -0
- package/dist/database-provider.test.d.ts.map +1 -0
- package/dist/database-provider.test.js +285 -0
- package/dist/database-provider.test.js.map +1 -0
- package/dist/domain/entities/memory-entry.d.ts +143 -0
- package/dist/domain/entities/memory-entry.d.ts.map +1 -0
- package/dist/domain/entities/memory-entry.js +226 -0
- package/dist/domain/entities/memory-entry.js.map +1 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +12 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
- package/dist/domain/repositories/memory-repository.interface.d.ts.map +1 -0
- package/dist/domain/repositories/memory-repository.interface.js +11 -0
- package/dist/domain/repositories/memory-repository.interface.js.map +1 -0
- package/dist/domain/services/memory-domain-service.d.ts +105 -0
- package/dist/domain/services/memory-domain-service.d.ts.map +1 -0
- package/dist/domain/services/memory-domain-service.js +297 -0
- package/dist/domain/services/memory-domain-service.js.map +1 -0
- package/dist/hnsw-index.d.ts +111 -0
- package/dist/hnsw-index.d.ts.map +1 -0
- package/dist/hnsw-index.js +781 -0
- package/dist/hnsw-index.js.map +1 -0
- package/dist/hybrid-backend.d.ts +217 -0
- package/dist/hybrid-backend.d.ts.map +1 -0
- package/dist/hybrid-backend.js +491 -0
- package/dist/hybrid-backend.js.map +1 -0
- package/dist/hybrid-backend.test.d.ts +8 -0
- package/dist/hybrid-backend.test.d.ts.map +1 -0
- package/dist/hybrid-backend.test.js +320 -0
- package/dist/hybrid-backend.test.js.map +1 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +345 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/index.d.ts +17 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +16 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
- package/dist/infrastructure/repositories/hybrid-memory-repository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
- package/dist/infrastructure/repositories/hybrid-memory-repository.js.map +1 -0
- package/dist/migration.d.ts +68 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +513 -0
- package/dist/migration.js.map +1 -0
- package/dist/query-builder.d.ts +211 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/query-builder.js +438 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/sqlite-backend.d.ts +121 -0
- package/dist/sqlite-backend.d.ts.map +1 -0
- package/dist/sqlite-backend.js +564 -0
- package/dist/sqlite-backend.js.map +1 -0
- package/dist/sqljs-backend.d.ts +128 -0
- package/dist/sqljs-backend.d.ts.map +1 -0
- package/dist/sqljs-backend.js +598 -0
- package/dist/sqljs-backend.js.map +1 -0
- package/dist/types.d.ts +481 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/docs/AGENTDB-INTEGRATION.md +388 -0
- package/docs/CROSS_PLATFORM.md +505 -0
- package/docs/WINDOWS_SUPPORT.md +422 -0
- package/examples/agentdb-example.ts +345 -0
- package/examples/cross-platform-usage.ts +326 -0
- package/framework/benchmark.ts +112 -0
- package/package.json +31 -0
- package/src/agentdb-adapter.ts +884 -0
- package/src/agentdb-backend.test.ts +339 -0
- package/src/agentdb-backend.ts +1016 -0
- package/src/application/commands/delete-memory.command.ts +172 -0
- package/src/application/commands/store-memory.command.ts +103 -0
- package/src/application/index.ts +36 -0
- package/src/application/queries/search-memory.query.ts +237 -0
- package/src/application/services/memory-application-service.ts +236 -0
- package/src/cache-manager.ts +516 -0
- package/src/database-provider.test.ts +364 -0
- package/src/database-provider.ts +511 -0
- package/src/domain/entities/memory-entry.ts +289 -0
- package/src/domain/index.ts +35 -0
- package/src/domain/repositories/memory-repository.interface.ts +120 -0
- package/src/domain/services/memory-domain-service.ts +403 -0
- package/src/hnsw-index.ts +1013 -0
- package/src/hybrid-backend.test.ts +399 -0
- package/src/hybrid-backend.ts +694 -0
- package/src/index.ts +515 -0
- package/src/infrastructure/index.ts +23 -0
- package/src/infrastructure/repositories/hybrid-memory-repository.ts +516 -0
- package/src/migration.ts +669 -0
- package/src/query-builder.ts +542 -0
- package/src/sqlite-backend.ts +732 -0
- package/src/sqljs-backend.ts +763 -0
- package/src/types.ts +727 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/verify-cross-platform.ts +170 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Entry Entity - Domain Layer
|
|
3
|
+
*
|
|
4
|
+
* Core domain entity representing a stored memory item.
|
|
5
|
+
* Implements DDD principles with encapsulated business logic.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/memory/domain/entities
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { randomUUID } from 'crypto';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Memory entry types
|
|
14
|
+
*/
|
|
15
|
+
export type MemoryType = 'semantic' | 'episodic' | 'procedural' | 'working';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Memory entry status
|
|
19
|
+
*/
|
|
20
|
+
export type MemoryStatus = 'active' | 'archived' | 'deleted';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Memory entry properties
|
|
24
|
+
*/
|
|
25
|
+
export interface MemoryEntryProps {
|
|
26
|
+
id?: string;
|
|
27
|
+
namespace: string;
|
|
28
|
+
key: string;
|
|
29
|
+
value: unknown;
|
|
30
|
+
type: MemoryType;
|
|
31
|
+
vector?: Float32Array;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
accessCount?: number;
|
|
34
|
+
lastAccessedAt?: Date;
|
|
35
|
+
createdAt?: Date;
|
|
36
|
+
updatedAt?: Date;
|
|
37
|
+
status?: MemoryStatus;
|
|
38
|
+
ttl?: number; // Time-to-live in milliseconds
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Memory Entry - Aggregate Root
|
|
43
|
+
*
|
|
44
|
+
* Represents a single memory entry with business logic
|
|
45
|
+
* for access tracking, expiration, and state management.
|
|
46
|
+
*/
|
|
47
|
+
export class MemoryEntry {
|
|
48
|
+
private _id: string;
|
|
49
|
+
private _namespace: string;
|
|
50
|
+
private _key: string;
|
|
51
|
+
private _value: unknown;
|
|
52
|
+
private _type: MemoryType;
|
|
53
|
+
private _vector?: Float32Array;
|
|
54
|
+
private _metadata: Record<string, unknown>;
|
|
55
|
+
private _accessCount: number;
|
|
56
|
+
private _lastAccessedAt: Date;
|
|
57
|
+
private _createdAt: Date;
|
|
58
|
+
private _updatedAt: Date;
|
|
59
|
+
private _status: MemoryStatus;
|
|
60
|
+
private _ttl?: number;
|
|
61
|
+
|
|
62
|
+
private constructor(props: MemoryEntryProps) {
|
|
63
|
+
const now = new Date();
|
|
64
|
+
this._id = props.id ?? randomUUID();
|
|
65
|
+
this._namespace = props.namespace;
|
|
66
|
+
this._key = props.key;
|
|
67
|
+
this._value = props.value;
|
|
68
|
+
this._type = props.type;
|
|
69
|
+
this._vector = props.vector;
|
|
70
|
+
this._metadata = props.metadata ?? {};
|
|
71
|
+
this._accessCount = props.accessCount ?? 0;
|
|
72
|
+
this._lastAccessedAt = props.lastAccessedAt ?? now;
|
|
73
|
+
this._createdAt = props.createdAt ?? now;
|
|
74
|
+
this._updatedAt = props.updatedAt ?? now;
|
|
75
|
+
this._status = props.status ?? 'active';
|
|
76
|
+
this._ttl = props.ttl;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Factory method - Create new memory entry
|
|
81
|
+
*/
|
|
82
|
+
static create(props: MemoryEntryProps): MemoryEntry {
|
|
83
|
+
return new MemoryEntry(props);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Factory method - Reconstruct from persistence
|
|
88
|
+
*/
|
|
89
|
+
static fromPersistence(props: MemoryEntryProps): MemoryEntry {
|
|
90
|
+
return new MemoryEntry(props);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Getters
|
|
94
|
+
get id(): string {
|
|
95
|
+
return this._id;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get namespace(): string {
|
|
99
|
+
return this._namespace;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get key(): string {
|
|
103
|
+
return this._key;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get value(): unknown {
|
|
107
|
+
return this._value;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get type(): MemoryType {
|
|
111
|
+
return this._type;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get vector(): Float32Array | undefined {
|
|
115
|
+
return this._vector;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get metadata(): Record<string, unknown> {
|
|
119
|
+
return { ...this._metadata };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get accessCount(): number {
|
|
123
|
+
return this._accessCount;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get lastAccessedAt(): Date {
|
|
127
|
+
return new Date(this._lastAccessedAt);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get createdAt(): Date {
|
|
131
|
+
return new Date(this._createdAt);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get updatedAt(): Date {
|
|
135
|
+
return new Date(this._updatedAt);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get status(): MemoryStatus {
|
|
139
|
+
return this._status;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get ttl(): number | undefined {
|
|
143
|
+
return this._ttl;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get compositeKey(): string {
|
|
147
|
+
return `${this._namespace}:${this._key}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Business Logic Methods
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Record an access to this memory entry
|
|
154
|
+
*/
|
|
155
|
+
recordAccess(): void {
|
|
156
|
+
this._accessCount++;
|
|
157
|
+
this._lastAccessedAt = new Date();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Update the value of this memory entry
|
|
162
|
+
*/
|
|
163
|
+
updateValue(value: unknown): void {
|
|
164
|
+
this._value = value;
|
|
165
|
+
this._updatedAt = new Date();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Update the vector embedding
|
|
170
|
+
*/
|
|
171
|
+
updateVector(vector: Float32Array): void {
|
|
172
|
+
this._vector = vector;
|
|
173
|
+
this._updatedAt = new Date();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Add or update metadata
|
|
178
|
+
*/
|
|
179
|
+
setMetadata(key: string, value: unknown): void {
|
|
180
|
+
this._metadata[key] = value;
|
|
181
|
+
this._updatedAt = new Date();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Remove metadata key
|
|
186
|
+
*/
|
|
187
|
+
removeMetadata(key: string): void {
|
|
188
|
+
delete this._metadata[key];
|
|
189
|
+
this._updatedAt = new Date();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Archive this memory entry
|
|
194
|
+
*/
|
|
195
|
+
archive(): void {
|
|
196
|
+
this._status = 'archived';
|
|
197
|
+
this._updatedAt = new Date();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Restore archived memory entry
|
|
202
|
+
*/
|
|
203
|
+
restore(): void {
|
|
204
|
+
if (this._status === 'archived') {
|
|
205
|
+
this._status = 'active';
|
|
206
|
+
this._updatedAt = new Date();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Mark as deleted (soft delete)
|
|
212
|
+
*/
|
|
213
|
+
delete(): void {
|
|
214
|
+
this._status = 'deleted';
|
|
215
|
+
this._updatedAt = new Date();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Check if memory has expired based on TTL
|
|
220
|
+
*/
|
|
221
|
+
isExpired(): boolean {
|
|
222
|
+
if (!this._ttl) return false;
|
|
223
|
+
const expiresAt = this._createdAt.getTime() + this._ttl;
|
|
224
|
+
return Date.now() > expiresAt;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Check if memory is accessible (active and not expired)
|
|
229
|
+
*/
|
|
230
|
+
isAccessible(): boolean {
|
|
231
|
+
return this._status === 'active' && !this.isExpired();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Calculate age in milliseconds
|
|
236
|
+
*/
|
|
237
|
+
getAge(): number {
|
|
238
|
+
return Date.now() - this._createdAt.getTime();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Calculate time since last access in milliseconds
|
|
243
|
+
*/
|
|
244
|
+
getTimeSinceLastAccess(): number {
|
|
245
|
+
return Date.now() - this._lastAccessedAt.getTime();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Check if memory is considered "hot" (frequently accessed)
|
|
250
|
+
*/
|
|
251
|
+
isHot(threshold: number = 10): boolean {
|
|
252
|
+
return this._accessCount >= threshold;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Check if memory is considered "cold" (not accessed recently)
|
|
257
|
+
*/
|
|
258
|
+
isCold(milliseconds: number = 3600000): boolean {
|
|
259
|
+
return this.getTimeSinceLastAccess() > milliseconds;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Convert to plain object for persistence
|
|
264
|
+
*/
|
|
265
|
+
toPersistence(): Record<string, unknown> {
|
|
266
|
+
return {
|
|
267
|
+
id: this._id,
|
|
268
|
+
namespace: this._namespace,
|
|
269
|
+
key: this._key,
|
|
270
|
+
value: this._value,
|
|
271
|
+
type: this._type,
|
|
272
|
+
vector: this._vector ? Array.from(this._vector) : undefined,
|
|
273
|
+
metadata: this._metadata,
|
|
274
|
+
accessCount: this._accessCount,
|
|
275
|
+
lastAccessedAt: this._lastAccessedAt.toISOString(),
|
|
276
|
+
createdAt: this._createdAt.toISOString(),
|
|
277
|
+
updatedAt: this._updatedAt.toISOString(),
|
|
278
|
+
status: this._status,
|
|
279
|
+
ttl: this._ttl,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Convert to JSON-serializable object
|
|
285
|
+
*/
|
|
286
|
+
toJSON(): Record<string, unknown> {
|
|
287
|
+
return this.toPersistence();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Domain Layer - Public Exports
|
|
3
|
+
*
|
|
4
|
+
* Exports all domain entities, value objects, services, and interfaces.
|
|
5
|
+
*
|
|
6
|
+
* @module v3/memory/domain
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Entities
|
|
10
|
+
export {
|
|
11
|
+
MemoryEntry,
|
|
12
|
+
type MemoryType,
|
|
13
|
+
type MemoryStatus,
|
|
14
|
+
type MemoryEntryProps,
|
|
15
|
+
} from './entities/memory-entry.js';
|
|
16
|
+
|
|
17
|
+
// Repository Interfaces
|
|
18
|
+
export {
|
|
19
|
+
type IMemoryRepository,
|
|
20
|
+
type MemoryQueryOptions,
|
|
21
|
+
type VectorSearchOptions,
|
|
22
|
+
type VectorSearchResult,
|
|
23
|
+
type BulkOperationResult,
|
|
24
|
+
type MemoryStatistics,
|
|
25
|
+
} from './repositories/memory-repository.interface.js';
|
|
26
|
+
|
|
27
|
+
// Domain Services
|
|
28
|
+
export {
|
|
29
|
+
MemoryDomainService,
|
|
30
|
+
type ConsolidationStrategy,
|
|
31
|
+
type ConsolidationOptions,
|
|
32
|
+
type ConsolidationResult,
|
|
33
|
+
type DeduplicationResult,
|
|
34
|
+
type NamespaceAnalysis,
|
|
35
|
+
} from './services/memory-domain-service.js';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Repository Interface - Domain Layer
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract for memory persistence.
|
|
5
|
+
* Following DDD, the interface belongs to the domain layer
|
|
6
|
+
* while implementations belong to infrastructure.
|
|
7
|
+
*
|
|
8
|
+
* @module v3/memory/domain/repositories
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { MemoryEntry, MemoryType, MemoryStatus } from '../entities/memory-entry.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Query options for memory retrieval
|
|
15
|
+
*/
|
|
16
|
+
export interface MemoryQueryOptions {
|
|
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
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Vector search options
|
|
28
|
+
*/
|
|
29
|
+
export interface VectorSearchOptions {
|
|
30
|
+
vector: Float32Array;
|
|
31
|
+
namespace?: string;
|
|
32
|
+
limit?: number;
|
|
33
|
+
threshold?: number; // Minimum similarity score
|
|
34
|
+
type?: MemoryType;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Vector search result
|
|
39
|
+
*/
|
|
40
|
+
export interface VectorSearchResult {
|
|
41
|
+
entry: MemoryEntry;
|
|
42
|
+
similarity: number;
|
|
43
|
+
distance: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Bulk operation result
|
|
48
|
+
*/
|
|
49
|
+
export interface BulkOperationResult {
|
|
50
|
+
success: number;
|
|
51
|
+
failed: number;
|
|
52
|
+
errors: Array<{ id: string; error: string }>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Memory statistics
|
|
57
|
+
*/
|
|
58
|
+
export interface MemoryStatistics {
|
|
59
|
+
totalEntries: number;
|
|
60
|
+
activeEntries: number;
|
|
61
|
+
archivedEntries: number;
|
|
62
|
+
deletedEntries: number;
|
|
63
|
+
totalSize: number;
|
|
64
|
+
entriesByNamespace: Record<string, number>;
|
|
65
|
+
entriesByType: Record<MemoryType, number>;
|
|
66
|
+
averageAccessCount: number;
|
|
67
|
+
hottestEntries: string[];
|
|
68
|
+
coldestEntries: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Memory Repository Interface
|
|
73
|
+
*
|
|
74
|
+
* Defines all operations for memory persistence.
|
|
75
|
+
* Implementations can use SQLite, AgentDB, or hybrid backends.
|
|
76
|
+
*/
|
|
77
|
+
export interface IMemoryRepository {
|
|
78
|
+
// Basic CRUD Operations
|
|
79
|
+
save(entry: MemoryEntry): Promise<void>;
|
|
80
|
+
findById(id: string): Promise<MemoryEntry | null>;
|
|
81
|
+
findByKey(namespace: string, key: string): Promise<MemoryEntry | null>;
|
|
82
|
+
findByCompositeKey(compositeKey: string): Promise<MemoryEntry | null>;
|
|
83
|
+
delete(id: string): Promise<boolean>;
|
|
84
|
+
exists(id: string): Promise<boolean>;
|
|
85
|
+
|
|
86
|
+
// Bulk Operations
|
|
87
|
+
saveMany(entries: MemoryEntry[]): Promise<BulkOperationResult>;
|
|
88
|
+
findByIds(ids: string[]): Promise<MemoryEntry[]>;
|
|
89
|
+
deleteMany(ids: string[]): Promise<BulkOperationResult>;
|
|
90
|
+
|
|
91
|
+
// Query Operations
|
|
92
|
+
findAll(options?: MemoryQueryOptions): Promise<MemoryEntry[]>;
|
|
93
|
+
findByNamespace(namespace: string, options?: Omit<MemoryQueryOptions, 'namespace'>): Promise<MemoryEntry[]>;
|
|
94
|
+
findByType(type: MemoryType, options?: Omit<MemoryQueryOptions, 'type'>): Promise<MemoryEntry[]>;
|
|
95
|
+
findByStatus(status: MemoryStatus, options?: Omit<MemoryQueryOptions, 'status'>): Promise<MemoryEntry[]>;
|
|
96
|
+
|
|
97
|
+
// Vector Search Operations
|
|
98
|
+
searchByVector(options: VectorSearchOptions): Promise<VectorSearchResult[]>;
|
|
99
|
+
findSimilar(entryId: string, limit?: number): Promise<VectorSearchResult[]>;
|
|
100
|
+
|
|
101
|
+
// Maintenance Operations
|
|
102
|
+
findExpired(): Promise<MemoryEntry[]>;
|
|
103
|
+
deleteExpired(): Promise<number>;
|
|
104
|
+
findCold(milliseconds: number): Promise<MemoryEntry[]>;
|
|
105
|
+
archiveCold(milliseconds: number): Promise<number>;
|
|
106
|
+
|
|
107
|
+
// Statistics
|
|
108
|
+
getStatistics(): Promise<MemoryStatistics>;
|
|
109
|
+
count(options?: MemoryQueryOptions): Promise<number>;
|
|
110
|
+
|
|
111
|
+
// Namespace Operations
|
|
112
|
+
listNamespaces(): Promise<string[]>;
|
|
113
|
+
deleteNamespace(namespace: string): Promise<number>;
|
|
114
|
+
getNamespaceSize(namespace: string): Promise<number>;
|
|
115
|
+
|
|
116
|
+
// Lifecycle
|
|
117
|
+
initialize(): Promise<void>;
|
|
118
|
+
shutdown(): Promise<void>;
|
|
119
|
+
clear(): Promise<void>;
|
|
120
|
+
}
|