@aman_asmuei/amem 0.19.0 → 0.20.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/cli.js +6 -7
- package/dist/cli.js.map +1 -1
- package/dist/dashboard.d.ts +1 -1
- package/dist/dashboard.js +1 -1
- package/dist/dashboard.js.map +1 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/tools/advanced.d.ts +1 -1
- package/dist/tools/advanced.js +1 -5
- package/dist/tools/advanced.js.map +1 -1
- package/dist/tools/graph.d.ts +1 -1
- package/dist/tools/graph.js +1 -2
- package/dist/tools/graph.js.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +2 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/log.d.ts +1 -1
- package/dist/tools/log.js +1 -2
- package/dist/tools/log.js.map +1 -1
- package/dist/tools/memory.d.ts +1 -2
- package/dist/tools/memory.js +16 -22
- package/dist/tools/memory.js.map +1 -1
- package/dist/tools/reminders.d.ts +1 -1
- package/dist/tools/reminders.js +4 -5
- package/dist/tools/reminders.js.map +1 -1
- package/dist/tools/versions.d.ts +1 -1
- package/dist/tools/versions.js +3 -4
- package/dist/tools/versions.js.map +1 -1
- package/dist/tools.test.js +1 -2
- package/dist/tools.test.js.map +1 -1
- package/package.json +3 -9
- package/dist/ann.d.ts +0 -26
- package/dist/ann.js +0 -155
- package/dist/ann.js.map +0 -1
- package/dist/auto-relate.d.ts +0 -14
- package/dist/auto-relate.js +0 -47
- package/dist/auto-relate.js.map +0 -1
- package/dist/config.d.ts +0 -51
- package/dist/config.js +0 -130
- package/dist/config.js.map +0 -1
- package/dist/database.d.ts +0 -165
- package/dist/database.js +0 -831
- package/dist/database.js.map +0 -1
- package/dist/database.test.d.ts +0 -1
- package/dist/database.test.js +0 -275
- package/dist/database.test.js.map +0 -1
- package/dist/doctor.d.ts +0 -23
- package/dist/doctor.js +0 -107
- package/dist/doctor.js.map +0 -1
- package/dist/embeddings.d.ts +0 -38
- package/dist/embeddings.js +0 -251
- package/dist/embeddings.js.map +0 -1
- package/dist/embeddings.test.d.ts +0 -1
- package/dist/embeddings.test.js +0 -106
- package/dist/embeddings.test.js.map +0 -1
- package/dist/extractor.d.ts +0 -13
- package/dist/extractor.js +0 -89
- package/dist/extractor.js.map +0 -1
- package/dist/memory.d.ts +0 -134
- package/dist/memory.js +0 -432
- package/dist/memory.js.map +0 -1
- package/dist/memory.test.d.ts +0 -1
- package/dist/memory.test.js +0 -172
- package/dist/memory.test.js.map +0 -1
- package/dist/query-expand.d.ts +0 -9
- package/dist/query-expand.js +0 -71
- package/dist/query-expand.js.map +0 -1
- package/dist/reflection.d.ts +0 -82
- package/dist/reflection.js +0 -414
- package/dist/reflection.js.map +0 -1
- package/dist/reflection.test.d.ts +0 -1
- package/dist/reflection.test.js +0 -453
- package/dist/reflection.test.js.map +0 -1
- package/dist/repair.d.ts +0 -8
- package/dist/repair.js +0 -90
- package/dist/repair.js.map +0 -1
- package/dist/schemas.d.ts +0 -1075
- package/dist/schemas.js +0 -311
- package/dist/schemas.js.map +0 -1
- package/dist/sync.d.ts +0 -85
- package/dist/sync.js +0 -304
- package/dist/sync.js.map +0 -1
- package/dist/tools/helpers.d.ts +0 -7
- package/dist/tools/helpers.js +0 -23
- package/dist/tools/helpers.js.map +0 -1
package/dist/ann.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export interface VectorSearchResult {
|
|
2
|
-
id: string;
|
|
3
|
-
similarity: number;
|
|
4
|
-
}
|
|
5
|
-
export declare class VectorIndex {
|
|
6
|
-
private dims;
|
|
7
|
-
private hnsw;
|
|
8
|
-
private labelToId;
|
|
9
|
-
private idToLabel;
|
|
10
|
-
private nextLabel;
|
|
11
|
-
private deletedLabels;
|
|
12
|
-
private capacity;
|
|
13
|
-
private entries;
|
|
14
|
-
constructor(dimensions: number);
|
|
15
|
-
private _initHnsw;
|
|
16
|
-
private _ensureCapacity;
|
|
17
|
-
add(id: string, embedding: Float32Array): void;
|
|
18
|
-
remove(id: string): void;
|
|
19
|
-
has(id: string): boolean;
|
|
20
|
-
size(): number;
|
|
21
|
-
search(query: Float32Array, k: number, minSimilarity?: number): VectorSearchResult[];
|
|
22
|
-
buildFrom(entries: Array<{
|
|
23
|
-
id: string;
|
|
24
|
-
embedding: Float32Array;
|
|
25
|
-
}>): void;
|
|
26
|
-
}
|
package/dist/ann.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { cosineSimilarity } from "./embeddings.js";
|
|
3
|
-
// Attempt to load hnswlib-node using createRequire (ESM-safe)
|
|
4
|
-
let HierarchicalNSW = null;
|
|
5
|
-
try {
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const hnswlib = require("hnswlib-node");
|
|
8
|
-
HierarchicalNSW = hnswlib.HierarchicalNSW;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
// hnswlib-node not available, will fall back to brute-force
|
|
12
|
-
}
|
|
13
|
-
export class VectorIndex {
|
|
14
|
-
dims;
|
|
15
|
-
// HNSW state
|
|
16
|
-
hnsw = null;
|
|
17
|
-
labelToId = new Map();
|
|
18
|
-
idToLabel = new Map();
|
|
19
|
-
nextLabel = 0;
|
|
20
|
-
deletedLabels = new Set();
|
|
21
|
-
capacity = 0;
|
|
22
|
-
// Brute-force fallback state
|
|
23
|
-
entries = new Map();
|
|
24
|
-
constructor(dimensions) {
|
|
25
|
-
this.dims = dimensions;
|
|
26
|
-
if (HierarchicalNSW) {
|
|
27
|
-
this._initHnsw(200);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_initHnsw(initialCapacity) {
|
|
31
|
-
const index = new HierarchicalNSW("cosine", this.dims);
|
|
32
|
-
index.initIndex(initialCapacity, 16, 200, 100);
|
|
33
|
-
this.hnsw = index;
|
|
34
|
-
this.capacity = initialCapacity;
|
|
35
|
-
}
|
|
36
|
-
_ensureCapacity(needed) {
|
|
37
|
-
if (needed > this.capacity) {
|
|
38
|
-
const newCapacity = Math.max(needed, this.capacity * 2);
|
|
39
|
-
this.hnsw.resizeIndex(newCapacity);
|
|
40
|
-
this.capacity = newCapacity;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
add(id, embedding) {
|
|
44
|
-
if (this.hnsw) {
|
|
45
|
-
// If id already exists, mark old label deleted and reuse a new one
|
|
46
|
-
if (this.idToLabel.has(id)) {
|
|
47
|
-
const oldLabel = this.idToLabel.get(id);
|
|
48
|
-
try {
|
|
49
|
-
this.hnsw.markDelete(oldLabel);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// ignore if already deleted
|
|
53
|
-
}
|
|
54
|
-
this.deletedLabels.add(oldLabel);
|
|
55
|
-
this.labelToId.delete(oldLabel);
|
|
56
|
-
}
|
|
57
|
-
const label = this.nextLabel++;
|
|
58
|
-
this._ensureCapacity(label + 1);
|
|
59
|
-
this.hnsw.addPoint(Array.from(embedding), label);
|
|
60
|
-
this.labelToId.set(label, id);
|
|
61
|
-
this.idToLabel.set(id, label);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.entries.set(id, embedding);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
remove(id) {
|
|
68
|
-
if (this.hnsw) {
|
|
69
|
-
if (!this.idToLabel.has(id))
|
|
70
|
-
return;
|
|
71
|
-
const label = this.idToLabel.get(id);
|
|
72
|
-
try {
|
|
73
|
-
this.hnsw.markDelete(label);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// ignore
|
|
77
|
-
}
|
|
78
|
-
this.deletedLabels.add(label);
|
|
79
|
-
this.labelToId.delete(label);
|
|
80
|
-
this.idToLabel.delete(id);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.entries.delete(id);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
has(id) {
|
|
87
|
-
if (this.hnsw) {
|
|
88
|
-
return this.idToLabel.has(id);
|
|
89
|
-
}
|
|
90
|
-
return this.entries.has(id);
|
|
91
|
-
}
|
|
92
|
-
size() {
|
|
93
|
-
if (this.hnsw) {
|
|
94
|
-
return this.idToLabel.size;
|
|
95
|
-
}
|
|
96
|
-
return this.entries.size;
|
|
97
|
-
}
|
|
98
|
-
search(query, k, minSimilarity = 0.0) {
|
|
99
|
-
if (this.hnsw) {
|
|
100
|
-
const liveCount = this.idToLabel.size;
|
|
101
|
-
if (liveCount === 0)
|
|
102
|
-
return [];
|
|
103
|
-
// Over-request to compensate for tombstoned entries that HNSW may return
|
|
104
|
-
const totalLabels = this.nextLabel;
|
|
105
|
-
const actualK = Math.min(Math.max(k * 2, k + 10), totalLabels);
|
|
106
|
-
const { neighbors, distances } = this.hnsw.searchKnn(Array.from(query), actualK);
|
|
107
|
-
const results = [];
|
|
108
|
-
for (let i = 0; i < neighbors.length; i++) {
|
|
109
|
-
const label = neighbors[i];
|
|
110
|
-
const id = this.labelToId.get(label);
|
|
111
|
-
if (id === undefined)
|
|
112
|
-
continue; // deleted tombstone
|
|
113
|
-
const similarity = 1 - distances[i];
|
|
114
|
-
if (similarity >= minSimilarity) {
|
|
115
|
-
results.push({ id, similarity });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
results.sort((a, b) => b.similarity - a.similarity);
|
|
119
|
-
return results.slice(0, k);
|
|
120
|
-
}
|
|
121
|
-
// Brute-force fallback
|
|
122
|
-
const results = [];
|
|
123
|
-
for (const [id, embedding] of this.entries) {
|
|
124
|
-
const similarity = cosineSimilarity(query, embedding);
|
|
125
|
-
if (similarity >= minSimilarity) {
|
|
126
|
-
results.push({ id, similarity });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
results.sort((a, b) => b.similarity - a.similarity);
|
|
130
|
-
return results.slice(0, k);
|
|
131
|
-
}
|
|
132
|
-
buildFrom(entries) {
|
|
133
|
-
if (this.hnsw) {
|
|
134
|
-
// Re-init to clear tombstones and reset state
|
|
135
|
-
this._initHnsw(Math.max(entries.length, 200));
|
|
136
|
-
this.labelToId.clear();
|
|
137
|
-
this.idToLabel.clear();
|
|
138
|
-
this.nextLabel = 0;
|
|
139
|
-
this.deletedLabels.clear();
|
|
140
|
-
for (const entry of entries) {
|
|
141
|
-
const label = this.nextLabel++;
|
|
142
|
-
this.hnsw.addPoint(Array.from(entry.embedding), label);
|
|
143
|
-
this.labelToId.set(label, entry.id);
|
|
144
|
-
this.idToLabel.set(entry.id, label);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
this.entries.clear();
|
|
149
|
-
for (const entry of entries) {
|
|
150
|
-
this.entries.set(entry.id, entry.embedding);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
//# sourceMappingURL=ann.js.map
|
package/dist/ann.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ann.js","sourceRoot":"","sources":["../src/ann.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAOnD,8DAA8D;AAC9D,IAAI,eAAe,GAAQ,IAAI,CAAC;AAChC,IAAI,CAAC;IACH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACxC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;AAC5C,CAAC;AAAC,MAAM,CAAC;IACP,4DAA4D;AAC9D,CAAC;AAED,MAAM,OAAO,WAAW;IACd,IAAI,CAAS;IAErB,aAAa;IACL,IAAI,GAAQ,IAAI,CAAC;IACjB,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC3C,SAAS,GAAwB,IAAI,GAAG,EAAE,C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C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;YAC9C,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;YACnB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAE3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;gBACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;gBACpC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/auto-relate.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AmemDatabase } from "./database.js";
|
|
2
|
-
export interface AutoRelateOptions {
|
|
3
|
-
minSimilarity?: number;
|
|
4
|
-
maxRelations?: number;
|
|
5
|
-
maxCandidates?: number;
|
|
6
|
-
}
|
|
7
|
-
export interface AutoRelateResult {
|
|
8
|
-
created: number;
|
|
9
|
-
relations: Array<{
|
|
10
|
-
toId: string;
|
|
11
|
-
similarity: number;
|
|
12
|
-
}>;
|
|
13
|
-
}
|
|
14
|
-
export declare function autoRelateMemory(db: AmemDatabase, newMemoryId: string, options?: AutoRelateOptions): AutoRelateResult;
|
package/dist/auto-relate.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { cosineSimilarity } from "./embeddings.js";
|
|
2
|
-
export function autoRelateMemory(db, newMemoryId, options) {
|
|
3
|
-
const minSimilarity = options?.minSimilarity ?? 0.6;
|
|
4
|
-
const maxRelations = options?.maxRelations ?? 3;
|
|
5
|
-
const maxCandidates = options?.maxCandidates ?? 200;
|
|
6
|
-
const empty = { created: 0, relations: [] };
|
|
7
|
-
// 1. Get the new memory, return early if no embedding
|
|
8
|
-
const newMemory = db.getById(newMemoryId);
|
|
9
|
-
if (!newMemory?.embedding)
|
|
10
|
-
return empty;
|
|
11
|
-
// 2. Get recent memories with embeddings (up to maxCandidates)
|
|
12
|
-
const candidates = db.getRecentWithEmbeddings(maxCandidates);
|
|
13
|
-
// 3. Score each by cosine similarity, filter >= minSimilarity and < 0.95 (skip near-dupes)
|
|
14
|
-
const scored = [];
|
|
15
|
-
for (const mem of candidates) {
|
|
16
|
-
if (mem.id === newMemoryId)
|
|
17
|
-
continue;
|
|
18
|
-
if (!mem.embedding)
|
|
19
|
-
continue;
|
|
20
|
-
const sim = cosineSimilarity(newMemory.embedding, mem.embedding);
|
|
21
|
-
if (sim >= minSimilarity && sim < 0.95) {
|
|
22
|
-
scored.push({ id: mem.id, similarity: sim });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// 4. Sort descending, take top maxRelations
|
|
26
|
-
scored.sort((a, b) => b.similarity - a.similarity);
|
|
27
|
-
const top = scored.slice(0, maxRelations);
|
|
28
|
-
// 5. Check existing relations to avoid duplicates, then create edges
|
|
29
|
-
const existingRelations = db.getRelations(newMemoryId);
|
|
30
|
-
const existingTargets = new Set(existingRelations.map((r) => (r.fromId === newMemoryId ? r.toId : r.fromId)));
|
|
31
|
-
const created = [];
|
|
32
|
-
for (const candidate of top) {
|
|
33
|
-
if (existingTargets.has(candidate.id))
|
|
34
|
-
continue;
|
|
35
|
-
// 6. Create "related_to" edges with similarity as strength
|
|
36
|
-
try {
|
|
37
|
-
db.addRelation(newMemoryId, candidate.id, "related_to", candidate.similarity);
|
|
38
|
-
created.push({ toId: candidate.id, similarity: candidate.similarity });
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// UNIQUE constraint may fire — safe to ignore
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// 7. Return count and details
|
|
45
|
-
return { created: created.length, relations: created };
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=auto-relate.js.map
|
package/dist/auto-relate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-relate.js","sourceRoot":"","sources":["../src/auto-relate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAanD,MAAM,UAAU,gBAAgB,CAC9B,EAAgB,EAChB,WAAmB,EACnB,OAA2B;IAE3B,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,GAAG,CAAC;IACpD,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,GAAG,CAAC;IAEpD,MAAM,KAAK,GAAqB,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IAE9D,sDAAsD;IACtD,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,CAAC,SAAS,EAAE,SAAS;QAAE,OAAO,KAAK,CAAC;IAExC,+DAA+D;IAC/D,MAAM,UAAU,GAAG,EAAE,CAAC,uBAAuB,CAAC,aAAa,CAAC,CAAC;IAE7D,2FAA2F;IAC3F,MAAM,MAAM,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E,SAAS,CAAC,EAAE,EAAE,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;YAC9E,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;QACzE,CAAC;QAAC,MAAM,CAAC;YACP,8CAA8C;QAChD,CAAC;IACH,CAAC;IAED,8BAA8B;IAC9B,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AACzD,CAAC"}
|
package/dist/config.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export interface AmemConfig {
|
|
2
|
-
embeddingModel: string;
|
|
3
|
-
embeddingDimensions: number;
|
|
4
|
-
embeddingCacheSize: number;
|
|
5
|
-
retrieval: {
|
|
6
|
-
semanticWeight: number;
|
|
7
|
-
ftsWeight: number;
|
|
8
|
-
graphWeight: number;
|
|
9
|
-
temporalWeight: number;
|
|
10
|
-
maxCandidates: number;
|
|
11
|
-
rerankerEnabled: boolean;
|
|
12
|
-
rerankerTopK: number;
|
|
13
|
-
};
|
|
14
|
-
consolidation: {
|
|
15
|
-
maxStaleDays: number;
|
|
16
|
-
minConfidence: number;
|
|
17
|
-
minAccessCount: number;
|
|
18
|
-
enableDecay: boolean;
|
|
19
|
-
decayFactor: number;
|
|
20
|
-
};
|
|
21
|
-
privacy: {
|
|
22
|
-
enablePrivateTags: boolean;
|
|
23
|
-
redactPatterns: string[];
|
|
24
|
-
};
|
|
25
|
-
hooks: {
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
captureToolUse: boolean;
|
|
28
|
-
captureSessionEnd: boolean;
|
|
29
|
-
autoExtractInterval: number;
|
|
30
|
-
};
|
|
31
|
-
tiers: {
|
|
32
|
-
coreMaxTokens: number;
|
|
33
|
-
workingMaxTokens: number;
|
|
34
|
-
};
|
|
35
|
-
team: {
|
|
36
|
-
enabled: boolean;
|
|
37
|
-
syncPath: string | null;
|
|
38
|
-
syncInterval: number;
|
|
39
|
-
userId: string | null;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export declare function getConfigPath(): string;
|
|
43
|
-
export declare function loadConfig(): AmemConfig;
|
|
44
|
-
export declare function saveConfig(config: Partial<AmemConfig>): void;
|
|
45
|
-
export declare function getDefaultConfig(): AmemConfig;
|
|
46
|
-
export declare function resetConfigCache(): void;
|
|
47
|
-
/**
|
|
48
|
-
* Strip <private>...</private> tags and redact patterns from content before storage.
|
|
49
|
-
* Returns cleaned content, or null if the entire content is private.
|
|
50
|
-
*/
|
|
51
|
-
export declare function sanitizeContent(content: string, config?: AmemConfig): string | null;
|
package/dist/config.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
const DEFAULT_CONFIG = {
|
|
5
|
-
embeddingModel: "Xenova/bge-small-en-v1.5",
|
|
6
|
-
embeddingDimensions: 384,
|
|
7
|
-
embeddingCacheSize: 128,
|
|
8
|
-
retrieval: {
|
|
9
|
-
semanticWeight: 0.4,
|
|
10
|
-
ftsWeight: 0.3,
|
|
11
|
-
graphWeight: 0.15,
|
|
12
|
-
temporalWeight: 0.15,
|
|
13
|
-
maxCandidates: 50000,
|
|
14
|
-
rerankerEnabled: false,
|
|
15
|
-
rerankerTopK: 20,
|
|
16
|
-
},
|
|
17
|
-
consolidation: {
|
|
18
|
-
maxStaleDays: 60,
|
|
19
|
-
minConfidence: 0.3,
|
|
20
|
-
minAccessCount: 2,
|
|
21
|
-
enableDecay: false,
|
|
22
|
-
decayFactor: 0.95,
|
|
23
|
-
},
|
|
24
|
-
privacy: {
|
|
25
|
-
enablePrivateTags: true,
|
|
26
|
-
redactPatterns: [
|
|
27
|
-
"(?:api[_-]?key|secret|token|password|passwd|credential)\\s*[:=]\\s*['\"]?[A-Za-z0-9_\\-\\.]{8,}",
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
hooks: {
|
|
31
|
-
enabled: true,
|
|
32
|
-
captureToolUse: true,
|
|
33
|
-
captureSessionEnd: true,
|
|
34
|
-
autoExtractInterval: 0,
|
|
35
|
-
},
|
|
36
|
-
tiers: {
|
|
37
|
-
coreMaxTokens: 500,
|
|
38
|
-
workingMaxTokens: 2000,
|
|
39
|
-
},
|
|
40
|
-
team: {
|
|
41
|
-
enabled: false,
|
|
42
|
-
syncPath: null,
|
|
43
|
-
syncInterval: 30,
|
|
44
|
-
userId: null,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
let loadedConfig = null;
|
|
48
|
-
export function getConfigPath() {
|
|
49
|
-
const amemDir = process.env.AMEM_DIR || path.join(os.homedir(), ".amem");
|
|
50
|
-
return path.join(amemDir, "config.json");
|
|
51
|
-
}
|
|
52
|
-
export function loadConfig() {
|
|
53
|
-
if (loadedConfig)
|
|
54
|
-
return loadedConfig;
|
|
55
|
-
const configPath = getConfigPath();
|
|
56
|
-
try {
|
|
57
|
-
if (fs.existsSync(configPath)) {
|
|
58
|
-
const raw = fs.readFileSync(configPath, "utf-8").trim();
|
|
59
|
-
if (raw) {
|
|
60
|
-
const userConfig = JSON.parse(raw);
|
|
61
|
-
loadedConfig = deepMerge(DEFAULT_CONFIG, userConfig);
|
|
62
|
-
return loadedConfig;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.error("[amem] Failed to load config, using defaults:", error instanceof Error ? error.message : String(error));
|
|
68
|
-
}
|
|
69
|
-
loadedConfig = { ...DEFAULT_CONFIG };
|
|
70
|
-
return loadedConfig;
|
|
71
|
-
}
|
|
72
|
-
export function saveConfig(config) {
|
|
73
|
-
const configPath = getConfigPath();
|
|
74
|
-
const dir = path.dirname(configPath);
|
|
75
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
76
|
-
// Merge with existing config
|
|
77
|
-
const existing = loadConfig();
|
|
78
|
-
const merged = deepMerge(existing, config);
|
|
79
|
-
fs.writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n");
|
|
80
|
-
loadedConfig = merged;
|
|
81
|
-
}
|
|
82
|
-
export function getDefaultConfig() {
|
|
83
|
-
return { ...DEFAULT_CONFIG };
|
|
84
|
-
}
|
|
85
|
-
export function resetConfigCache() {
|
|
86
|
-
loadedConfig = null;
|
|
87
|
-
}
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
-
function deepMerge(base, override) {
|
|
90
|
-
const result = { ...base };
|
|
91
|
-
for (const key of Object.keys(override)) {
|
|
92
|
-
const val = override[key];
|
|
93
|
-
if (val !== undefined && val !== null) {
|
|
94
|
-
if (typeof val === "object" && !Array.isArray(val) && typeof result[key] === "object" && !Array.isArray(result[key])) {
|
|
95
|
-
result[key] = deepMerge(result[key], val);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
result[key] = val;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
// ── Privacy helpers ─────────────────────────────────────
|
|
105
|
-
/**
|
|
106
|
-
* Strip <private>...</private> tags and redact patterns from content before storage.
|
|
107
|
-
* Returns cleaned content, or null if the entire content is private.
|
|
108
|
-
*/
|
|
109
|
-
export function sanitizeContent(content, config) {
|
|
110
|
-
const cfg = config ?? loadConfig();
|
|
111
|
-
if (!cfg.privacy.enablePrivateTags)
|
|
112
|
-
return content;
|
|
113
|
-
// Strip <private>...</private> blocks
|
|
114
|
-
let cleaned = content.replace(/<private>[\s\S]*?<\/private>/gi, "[REDACTED]");
|
|
115
|
-
// If entire content was private, return null (don't store)
|
|
116
|
-
if (cleaned.trim() === "[REDACTED]" || cleaned.trim() === "")
|
|
117
|
-
return null;
|
|
118
|
-
// Apply regex redaction patterns
|
|
119
|
-
for (const pattern of cfg.privacy.redactPatterns) {
|
|
120
|
-
try {
|
|
121
|
-
const regex = new RegExp(pattern, "g");
|
|
122
|
-
cleaned = cleaned.replace(regex, "[REDACTED]");
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
// Invalid regex pattern — skip
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return cleaned;
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AAyDzB,MAAM,cAAc,GAAe;IACjC,cAAc,EAAE,0BAA0B;IAC1C,mBAAmB,EAAE,GAAG;IACxB,kBAAkB,EAAE,GAAG;IAEvB,SAAS,EAAE;QACT,cAAc,EAAE,GAAG;QACnB,SAAS,EAAE,GAAG;QACd,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,KAAK;QACpB,eAAe,EAAE,KAAK;QACtB,YAAY,EAAE,EAAE;KACjB;IAED,aAAa,EAAE;QACb,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,GAAG;QAClB,cAAc,EAAE,CAAC;QACjB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,IAAI;KAClB;IAED,OAAO,EAAE;QACP,iBAAiB,EAAE,IAAI;QACvB,cAAc,EAAE;YACd,iGAAiG;SAClG;KACF;IAED,KAAK,EAAE;QACL,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,IAAI;QACpB,iBAAiB,EAAE,IAAI;QACvB,mBAAmB,EAAE,CAAC;KACvB;IAED,KAAK,EAAE;QACL,aAAa,EAAE,GAAG;QAClB,gBAAgB,EAAE,IAAI;KACvB;IAED,IAAI,EAAE;QACJ,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,IA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C,GAAG,CAAC,GAAG,GAAG,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2DAA2D;AAE3D;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,MAAmB;IAClE,MAAM,GAAG,GAAG,MAAM,IAAI,UAAU,EAAE,CAAC;IAEnC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB;QAAE,OAAO,OAAO,CAAC;IAEnD,sCAAsC;IACtC,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,gCAAgC,EAAE,YAAY,CAAC,CAAC;IAE9E,2DAA2D;IAC3D,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,YAAY,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAE1E,iCAAiC;IACjC,KAAK,MAAM,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACvC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,+BAA+B;QACjC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/database.d.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import type { Memory, MemoryTypeValue } from "./memory.js";
|
|
2
|
-
export interface MemoryInput {
|
|
3
|
-
content: string;
|
|
4
|
-
type: MemoryTypeValue;
|
|
5
|
-
tags: string[];
|
|
6
|
-
confidence: number;
|
|
7
|
-
source: string;
|
|
8
|
-
embedding: Float32Array | null;
|
|
9
|
-
scope: string;
|
|
10
|
-
validFrom?: number;
|
|
11
|
-
validUntil?: number;
|
|
12
|
-
tier?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface SessionSummary {
|
|
15
|
-
id: string;
|
|
16
|
-
sessionId: string;
|
|
17
|
-
summary: string;
|
|
18
|
-
keyDecisions: string[];
|
|
19
|
-
keyCorrections: string[];
|
|
20
|
-
memoriesExtracted: number;
|
|
21
|
-
project: string;
|
|
22
|
-
createdAt: number;
|
|
23
|
-
}
|
|
24
|
-
export interface MemoryStats {
|
|
25
|
-
total: number;
|
|
26
|
-
byType: Record<string, number>;
|
|
27
|
-
}
|
|
28
|
-
export interface LogEntry {
|
|
29
|
-
id: string;
|
|
30
|
-
sessionId: string;
|
|
31
|
-
role: "user" | "assistant" | "system";
|
|
32
|
-
content: string;
|
|
33
|
-
timestamp: number;
|
|
34
|
-
project: string;
|
|
35
|
-
metadata: Record<string, unknown>;
|
|
36
|
-
}
|
|
37
|
-
export interface LogEntryInput {
|
|
38
|
-
sessionId: string;
|
|
39
|
-
role: "user" | "assistant" | "system";
|
|
40
|
-
content: string;
|
|
41
|
-
project: string;
|
|
42
|
-
metadata?: Record<string, unknown>;
|
|
43
|
-
}
|
|
44
|
-
export interface MemoryVersion {
|
|
45
|
-
versionId: string;
|
|
46
|
-
memoryId: string;
|
|
47
|
-
content: string;
|
|
48
|
-
confidence: number;
|
|
49
|
-
editedAt: number;
|
|
50
|
-
reason: string;
|
|
51
|
-
}
|
|
52
|
-
export interface MemoryRelation {
|
|
53
|
-
id: string;
|
|
54
|
-
fromId: string;
|
|
55
|
-
toId: string;
|
|
56
|
-
relationshipType: string;
|
|
57
|
-
strength: number;
|
|
58
|
-
createdAt: number;
|
|
59
|
-
validFrom?: number | null;
|
|
60
|
-
validUntil?: number | null;
|
|
61
|
-
}
|
|
62
|
-
export interface PatchInput {
|
|
63
|
-
field: "content" | "confidence" | "tags" | "type";
|
|
64
|
-
value: string | number | string[];
|
|
65
|
-
reason: string;
|
|
66
|
-
skipSnapshot?: boolean;
|
|
67
|
-
}
|
|
68
|
-
export interface KnowledgeGap {
|
|
69
|
-
id: string;
|
|
70
|
-
queryPattern: string;
|
|
71
|
-
hitCount: number;
|
|
72
|
-
avgConfidence: number;
|
|
73
|
-
avgResults: number;
|
|
74
|
-
firstSeen: number;
|
|
75
|
-
lastSeen: number;
|
|
76
|
-
resolved: boolean;
|
|
77
|
-
}
|
|
78
|
-
export interface AmemDatabase {
|
|
79
|
-
insertMemory(input: MemoryInput): string;
|
|
80
|
-
findByContentHash(content: string): Memory | null;
|
|
81
|
-
getById(id: string): Memory | null;
|
|
82
|
-
searchByType(type: MemoryTypeValue): Memory[];
|
|
83
|
-
searchByTag(tag: string): Memory[];
|
|
84
|
-
getAllWithEmbeddings(): Memory[];
|
|
85
|
-
getRecentWithEmbeddings(limit: number): Memory[];
|
|
86
|
-
getAll(): Memory[];
|
|
87
|
-
updateConfidence(id: string, confidence: number): void;
|
|
88
|
-
updateEmbedding(id: string, embedding: Float32Array): void;
|
|
89
|
-
touchAccess(id: string): void;
|
|
90
|
-
deleteMemory(id: string): void;
|
|
91
|
-
getStats(): MemoryStats;
|
|
92
|
-
searchByScope(scope: string): Memory[];
|
|
93
|
-
getAllForProject(project: string): Memory[];
|
|
94
|
-
listTables(): string[];
|
|
95
|
-
close(): void;
|
|
96
|
-
appendLog(entry: LogEntryInput): string;
|
|
97
|
-
getLogBySession(sessionId: string): LogEntry[];
|
|
98
|
-
searchLog(query: string, limit?: number): LogEntry[];
|
|
99
|
-
getRecentLog(limit: number, project?: string): LogEntry[];
|
|
100
|
-
deleteLogBefore(timestamp: number): number;
|
|
101
|
-
getLogCount(): number;
|
|
102
|
-
snapshotVersion(memoryId: string, reason: string): void;
|
|
103
|
-
getVersionHistory(memoryId: string): MemoryVersion[];
|
|
104
|
-
patchMemory(id: string, patch: PatchInput): boolean;
|
|
105
|
-
addRelation(fromId: string, toId: string, type: string, strength?: number): string;
|
|
106
|
-
getRelations(memoryId: string): MemoryRelation[];
|
|
107
|
-
removeRelation(relationId: string): void;
|
|
108
|
-
getRelatedMemories(memoryId: string): Memory[];
|
|
109
|
-
getMemoriesByDateRange(from: number, to: number): Memory[];
|
|
110
|
-
getMemoriesSince(timestamp: number): Memory[];
|
|
111
|
-
fullTextSearch(query: string, limit?: number, scopeProject?: string): Memory[];
|
|
112
|
-
insertReminder(content: string, dueAt: number | null, scope: string): string;
|
|
113
|
-
listReminders(includeCompleted?: boolean, scope?: string): Array<{
|
|
114
|
-
id: string;
|
|
115
|
-
content: string;
|
|
116
|
-
dueAt: number | null;
|
|
117
|
-
completed: boolean;
|
|
118
|
-
createdAt: number;
|
|
119
|
-
scope: string;
|
|
120
|
-
}>;
|
|
121
|
-
checkReminders(): Array<{
|
|
122
|
-
id: string;
|
|
123
|
-
content: string;
|
|
124
|
-
dueAt: number | null;
|
|
125
|
-
status: "overdue" | "today" | "upcoming";
|
|
126
|
-
scope: string;
|
|
127
|
-
}>;
|
|
128
|
-
completeReminder(id: string): boolean;
|
|
129
|
-
getConfidenceStats(): {
|
|
130
|
-
high: number;
|
|
131
|
-
medium: number;
|
|
132
|
-
low: number;
|
|
133
|
-
};
|
|
134
|
-
getEmbeddingCount(): number;
|
|
135
|
-
transaction(fn: () => void): void;
|
|
136
|
-
resolveId(partialId: string): string | null;
|
|
137
|
-
resolveReminderId(partialId: string): string | null;
|
|
138
|
-
getAllRelations(): MemoryRelation[];
|
|
139
|
-
expireMemory(id: string, timestamp?: number): void;
|
|
140
|
-
getValidMemories(asOf?: number): Memory[];
|
|
141
|
-
updateTier(id: string, tier: string): void;
|
|
142
|
-
getByTier(tier: string, scope?: string): Memory[];
|
|
143
|
-
insertSummary(input: {
|
|
144
|
-
sessionId: string;
|
|
145
|
-
summary: string;
|
|
146
|
-
keyDecisions: string[];
|
|
147
|
-
keyCorrections: string[];
|
|
148
|
-
memoriesExtracted: number;
|
|
149
|
-
project: string;
|
|
150
|
-
}): string;
|
|
151
|
-
getSummaryBySession(sessionId: string): SessionSummary | null;
|
|
152
|
-
getRecentSummaries(project: string, limit?: number): SessionSummary[];
|
|
153
|
-
expireRelation(relationId: string, timestamp?: number): void;
|
|
154
|
-
getValidRelations(asOf?: number): MemoryRelation[];
|
|
155
|
-
insertSynthesisLineage(synthesisId: string, sourceIds: string[]): void;
|
|
156
|
-
getSynthesisSources(synthesisId: string): string[];
|
|
157
|
-
hasAnySynthesis(sourceIds: string[]): boolean;
|
|
158
|
-
upsertKnowledgeGap(queryPattern: string, avgConfidence: number, resultCount: number): string;
|
|
159
|
-
getActiveKnowledgeGaps(limit?: number): KnowledgeGap[];
|
|
160
|
-
resolveKnowledgeGap(id: string): void;
|
|
161
|
-
bumpUtilityScore(id: string): void;
|
|
162
|
-
getReflectionMeta(key: string): string | null;
|
|
163
|
-
setReflectionMeta(key: string, value: string): void;
|
|
164
|
-
}
|
|
165
|
-
export declare function createDatabase(dbPath: string): AmemDatabase;
|