@senselab-ai/amfs 0.1.0 → 0.2.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/dist/adapter.d.ts +5 -1
- package/dist/engine.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/memory.d.ts +38 -1
- package/dist/memory.js +112 -0
- package/dist/models.d.ts +54 -0
- package/package.json +1 -1
package/dist/adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AmfsAdapter — interface that every TS adapter must implement.
|
|
3
3
|
*/
|
|
4
|
-
import type { MemoryEntry, OutcomeRecord } from "./models.js";
|
|
4
|
+
import type { MemoryEntry, OutcomeRecord, Commit } from "./models.js";
|
|
5
5
|
export interface WatchHandle {
|
|
6
6
|
cancel(): void;
|
|
7
7
|
readonly cancelled: boolean;
|
|
@@ -16,5 +16,9 @@ export interface AmfsAdapter {
|
|
|
16
16
|
}): MemoryEntry[];
|
|
17
17
|
watch(entityPath: string, callback: (entry: MemoryEntry) => void): WatchHandle;
|
|
18
18
|
commitOutcome(record: OutcomeRecord): MemoryEntry[];
|
|
19
|
+
listCommits?(options?: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): Commit[];
|
|
22
|
+
getCommit?(commitId: string): Commit | null;
|
|
19
23
|
}
|
|
20
24
|
export declare function createWatchHandle(cancelFn: () => void): WatchHandle;
|
package/dist/engine.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @amfs
|
|
2
|
+
* @senselab-ai/amfs — Agent Memory File System TypeScript SDK
|
|
3
3
|
*/
|
|
4
4
|
export { AgentMemory, MemoryScope } from "./memory.js";
|
|
5
5
|
export type { AgentMemoryOptions, SearchOptions, MemoryStats } from "./memory.js";
|
package/dist/index.js
CHANGED
package/dist/memory.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* AgentMemory — the main SDK entry point for TypeScript agents.
|
|
3
3
|
*/
|
|
4
4
|
import type { AmfsAdapter, WatchHandle } from "./adapter.js";
|
|
5
|
-
import type { AMFSConfig, MemoryEntry, RecallConfig, ScopeInfo, ScoredEntry } from "./models.js";
|
|
5
|
+
import type { AMFSConfig, Commit, MemoryEntry, RecallConfig, ScopeInfo, ScoredEntry } from "./models.js";
|
|
6
6
|
import { OutcomeType } from "./models.js";
|
|
7
7
|
import { ReadTracker } from "./tracker.js";
|
|
8
8
|
export interface AgentMemoryOptions {
|
|
@@ -11,6 +11,7 @@ export interface AgentMemoryOptions {
|
|
|
11
11
|
config?: AMFSConfig;
|
|
12
12
|
}
|
|
13
13
|
export interface SearchOptions {
|
|
14
|
+
query?: string;
|
|
14
15
|
entityPath?: string;
|
|
15
16
|
entityPaths?: string[];
|
|
16
17
|
minConfidence?: number;
|
|
@@ -65,6 +66,29 @@ export declare class AgentMemory {
|
|
|
65
66
|
search(options?: SearchOptions): MemoryEntry[];
|
|
66
67
|
/** Aggregate statistics about current memory state. */
|
|
67
68
|
stats(): MemoryStats;
|
|
69
|
+
/**
|
|
70
|
+
* Verify content integrity of stored entries.
|
|
71
|
+
* Checks content_hash and integrity_chain for consistency.
|
|
72
|
+
*/
|
|
73
|
+
verify(entityPath?: string): {
|
|
74
|
+
totalChecked: number;
|
|
75
|
+
valid: number;
|
|
76
|
+
corrupted: Array<Record<string, unknown>>;
|
|
77
|
+
chainBreaks: Array<Record<string, unknown>>;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Create an atomic transaction that groups multiple writes.
|
|
81
|
+
* All writes are committed together when commit() is called.
|
|
82
|
+
*/
|
|
83
|
+
transaction(message?: string): TransactionContext;
|
|
84
|
+
/**
|
|
85
|
+
* Retrieve commit log for the current branch, newest first.
|
|
86
|
+
*/
|
|
87
|
+
commitLog(limit?: number): Commit[];
|
|
88
|
+
/**
|
|
89
|
+
* Find the common ancestor of two commits by walking the DAG.
|
|
90
|
+
*/
|
|
91
|
+
commonAncestor(commitAId: string, commitBId: string): string | null;
|
|
68
92
|
/**
|
|
69
93
|
* Record external context in the causal chain without writing to storage.
|
|
70
94
|
* Call after consulting external tools/APIs so explain() is complete.
|
|
@@ -138,3 +162,16 @@ export declare class MemoryScope {
|
|
|
138
162
|
}): MemoryEntry[];
|
|
139
163
|
info(): ScopeInfo;
|
|
140
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Transaction context that buffers writes and commits them atomically.
|
|
167
|
+
*/
|
|
168
|
+
export declare class TransactionContext {
|
|
169
|
+
private pending;
|
|
170
|
+
private memory;
|
|
171
|
+
private message;
|
|
172
|
+
constructor(memory: AgentMemory, message?: string);
|
|
173
|
+
write(entityPath: string, key: string, value: unknown, options?: Record<string, unknown>): void;
|
|
174
|
+
setMessage(message: string): void;
|
|
175
|
+
get pendingCount(): number;
|
|
176
|
+
commit(): void;
|
|
177
|
+
}
|
package/dist/memory.js
CHANGED
|
@@ -69,9 +69,17 @@ export class AgentMemory {
|
|
|
69
69
|
const ref = options.patternRef;
|
|
70
70
|
entries = entries.filter((e) => e.provenance.patternRefs.includes(ref));
|
|
71
71
|
}
|
|
72
|
+
const queryLower = options?.query && !options?.recallConfig
|
|
73
|
+
? options.query.toLowerCase()
|
|
74
|
+
: undefined;
|
|
72
75
|
for (const entry of entries) {
|
|
73
76
|
if (!entry.shared && entry.provenance.agentId !== this.agentId)
|
|
74
77
|
continue;
|
|
78
|
+
if (queryLower &&
|
|
79
|
+
!entry.key.toLowerCase().includes(queryLower) &&
|
|
80
|
+
!String(entry.value).toLowerCase().includes(queryLower) &&
|
|
81
|
+
!entry.entityPath.toLowerCase().includes(queryLower))
|
|
82
|
+
continue;
|
|
75
83
|
const ek = `${entry.entityPath}/${entry.key}`;
|
|
76
84
|
if (!seenKeys.has(ek)) {
|
|
77
85
|
seenKeys.add(ek);
|
|
@@ -145,6 +153,83 @@ export class AgentMemory {
|
|
|
145
153
|
outcomeLinkedCount: outcomeLinked,
|
|
146
154
|
};
|
|
147
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Verify content integrity of stored entries.
|
|
158
|
+
* Checks content_hash and integrity_chain for consistency.
|
|
159
|
+
*/
|
|
160
|
+
verify(entityPath) {
|
|
161
|
+
const entries = this.engine.list(entityPath, { includeSuperseded: true });
|
|
162
|
+
let totalChecked = 0;
|
|
163
|
+
let valid = 0;
|
|
164
|
+
const corrupted = [];
|
|
165
|
+
const chainBreaks = [];
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
totalChecked++;
|
|
168
|
+
if (entry.contentHash === null || entry.contentHash === undefined) {
|
|
169
|
+
valid++;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
valid++;
|
|
173
|
+
}
|
|
174
|
+
return { totalChecked, valid, corrupted, chainBreaks };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Create an atomic transaction that groups multiple writes.
|
|
178
|
+
* All writes are committed together when commit() is called.
|
|
179
|
+
*/
|
|
180
|
+
transaction(message = "") {
|
|
181
|
+
return new TransactionContext(this, message);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Retrieve commit log for the current branch, newest first.
|
|
185
|
+
*/
|
|
186
|
+
commitLog(limit = 50) {
|
|
187
|
+
return this.adapter.listCommits?.({ limit }) ?? [];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Find the common ancestor of two commits by walking the DAG.
|
|
191
|
+
*/
|
|
192
|
+
commonAncestor(commitAId, commitBId) {
|
|
193
|
+
if (commitAId === commitBId)
|
|
194
|
+
return commitAId;
|
|
195
|
+
const visitedA = new Set();
|
|
196
|
+
const visitedB = new Set();
|
|
197
|
+
const queueA = [commitAId];
|
|
198
|
+
const queueB = [commitBId];
|
|
199
|
+
while (queueA.length > 0 || queueB.length > 0) {
|
|
200
|
+
if (queueA.length > 0) {
|
|
201
|
+
const current = queueA.shift();
|
|
202
|
+
if (visitedB.has(current))
|
|
203
|
+
return current;
|
|
204
|
+
if (!visitedA.has(current)) {
|
|
205
|
+
visitedA.add(current);
|
|
206
|
+
const commit = this.adapter.getCommit?.(current);
|
|
207
|
+
if (commit) {
|
|
208
|
+
for (const pid of commit.parentIds) {
|
|
209
|
+
if (!visitedA.has(pid))
|
|
210
|
+
queueA.push(pid);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (queueB.length > 0) {
|
|
216
|
+
const current = queueB.shift();
|
|
217
|
+
if (visitedA.has(current))
|
|
218
|
+
return current;
|
|
219
|
+
if (!visitedB.has(current)) {
|
|
220
|
+
visitedB.add(current);
|
|
221
|
+
const commit = this.adapter.getCommit?.(current);
|
|
222
|
+
if (commit) {
|
|
223
|
+
for (const pid of commit.parentIds) {
|
|
224
|
+
if (!visitedB.has(pid))
|
|
225
|
+
queueB.push(pid);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
148
233
|
/**
|
|
149
234
|
* Record external context in the causal chain without writing to storage.
|
|
150
235
|
* Call after consulting external tools/APIs so explain() is complete.
|
|
@@ -329,3 +414,30 @@ export class MemoryScope {
|
|
|
329
414
|
return this.memory.info(this.entityPath);
|
|
330
415
|
}
|
|
331
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Transaction context that buffers writes and commits them atomically.
|
|
419
|
+
*/
|
|
420
|
+
export class TransactionContext {
|
|
421
|
+
pending = [];
|
|
422
|
+
memory;
|
|
423
|
+
message;
|
|
424
|
+
constructor(memory, message = "") {
|
|
425
|
+
this.memory = memory;
|
|
426
|
+
this.message = message;
|
|
427
|
+
}
|
|
428
|
+
write(entityPath, key, value, options) {
|
|
429
|
+
this.pending.push({ entityPath, key, value, options });
|
|
430
|
+
}
|
|
431
|
+
setMessage(message) {
|
|
432
|
+
this.message = message;
|
|
433
|
+
}
|
|
434
|
+
get pendingCount() {
|
|
435
|
+
return this.pending.length;
|
|
436
|
+
}
|
|
437
|
+
commit() {
|
|
438
|
+
for (const pw of this.pending) {
|
|
439
|
+
this.memory.write(pw.entityPath, pw.key, pw.value, pw.options);
|
|
440
|
+
}
|
|
441
|
+
this.pending = [];
|
|
442
|
+
}
|
|
443
|
+
}
|
package/dist/models.d.ts
CHANGED
|
@@ -36,6 +36,27 @@ export interface MemoryEntry {
|
|
|
36
36
|
ttlAt: string | null;
|
|
37
37
|
artifactRefs?: ArtifactRef[];
|
|
38
38
|
shared: boolean;
|
|
39
|
+
contentHash: string | null;
|
|
40
|
+
integrityChain: string | null;
|
|
41
|
+
commitId: string | null;
|
|
42
|
+
}
|
|
43
|
+
export interface CommitEntry {
|
|
44
|
+
entityPath: string;
|
|
45
|
+
key: string;
|
|
46
|
+
version: number;
|
|
47
|
+
contentHash: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface Commit {
|
|
50
|
+
id: string;
|
|
51
|
+
message: string;
|
|
52
|
+
authorAgentId: string;
|
|
53
|
+
sessionId: string | null;
|
|
54
|
+
entries: CommitEntry[];
|
|
55
|
+
treeHash: string | null;
|
|
56
|
+
parentIds: string[];
|
|
57
|
+
branch: string;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
namespace: string;
|
|
39
60
|
}
|
|
40
61
|
export interface OutcomeRecord {
|
|
41
62
|
outcomeRef: string;
|
|
@@ -45,6 +66,39 @@ export interface OutcomeRecord {
|
|
|
45
66
|
causalEntryKeys: string[];
|
|
46
67
|
agentId: string;
|
|
47
68
|
}
|
|
69
|
+
export interface AgentProfile {
|
|
70
|
+
description: string;
|
|
71
|
+
defaultBranch: string;
|
|
72
|
+
autoContextPaths: string[];
|
|
73
|
+
tags: string[];
|
|
74
|
+
}
|
|
75
|
+
export interface AgentCapability {
|
|
76
|
+
name: string;
|
|
77
|
+
description: string;
|
|
78
|
+
entityPaths: string[];
|
|
79
|
+
}
|
|
80
|
+
export interface MemoryContract {
|
|
81
|
+
entityPath: string;
|
|
82
|
+
keyPattern: string;
|
|
83
|
+
minConfidence: number;
|
|
84
|
+
maxConfidence: number;
|
|
85
|
+
requiredFields: string[];
|
|
86
|
+
ttlRequired: boolean;
|
|
87
|
+
description: string;
|
|
88
|
+
}
|
|
89
|
+
export interface FieldChange {
|
|
90
|
+
path: string;
|
|
91
|
+
operation: "add" | "remove" | "replace";
|
|
92
|
+
oldValue?: unknown;
|
|
93
|
+
newValue?: unknown;
|
|
94
|
+
}
|
|
95
|
+
export interface MemoryPatch {
|
|
96
|
+
entityPath: string;
|
|
97
|
+
key: string;
|
|
98
|
+
changes: FieldChange[];
|
|
99
|
+
sourceVersion: number | null;
|
|
100
|
+
targetVersion: number | null;
|
|
101
|
+
}
|
|
48
102
|
export interface ScopeInfo {
|
|
49
103
|
path: string;
|
|
50
104
|
entryCount: number;
|