@windagency/valora-plugin-memory-vault 1.0.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.
Potentially problematic release.
This version of @windagency/valora-plugin-memory-vault might be problematic. Click here for more details.
- package/dist/config-schema.d.ts +134 -0
- package/dist/config-schema.d.ts.map +1 -0
- package/dist/config-schema.js +61 -0
- package/dist/config-schema.js.map +1 -0
- package/dist/consolidation/cluster.d.ts +17 -0
- package/dist/consolidation/cluster.d.ts.map +1 -0
- package/dist/consolidation/cluster.js +59 -0
- package/dist/consolidation/cluster.js.map +1 -0
- package/dist/consolidation-service.d.ts +75 -0
- package/dist/consolidation-service.d.ts.map +1 -0
- package/dist/consolidation-service.js +373 -0
- package/dist/consolidation-service.js.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +30 -0
- package/dist/constants.js.map +1 -0
- package/dist/decay.d.ts +51 -0
- package/dist/decay.d.ts.map +1 -0
- package/dist/decay.js +59 -0
- package/dist/decay.js.map +1 -0
- package/dist/embeddings/embedder.port.d.ts +9 -0
- package/dist/embeddings/embedder.port.d.ts.map +1 -0
- package/dist/embeddings/embedder.port.js +2 -0
- package/dist/embeddings/embedder.port.js.map +1 -0
- package/dist/embeddings/llm-provider-embedder.d.ts +26 -0
- package/dist/embeddings/llm-provider-embedder.d.ts.map +1 -0
- package/dist/embeddings/llm-provider-embedder.js +34 -0
- package/dist/embeddings/llm-provider-embedder.js.map +1 -0
- package/dist/embeddings/resolve-embedder.d.ts +27 -0
- package/dist/embeddings/resolve-embedder.d.ts.map +1 -0
- package/dist/embeddings/resolve-embedder.js +38 -0
- package/dist/embeddings/resolve-embedder.js.map +1 -0
- package/dist/embeddings/vector-store.d.ts +35 -0
- package/dist/embeddings/vector-store.d.ts.map +1 -0
- package/dist/embeddings/vector-store.js +174 -0
- package/dist/embeddings/vector-store.js.map +1 -0
- package/dist/extraction-service.d.ts +33 -0
- package/dist/extraction-service.d.ts.map +1 -0
- package/dist/extraction-service.js +168 -0
- package/dist/extraction-service.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6498 -0
- package/dist/index.js.map +1 -0
- package/dist/manager.d.ts +62 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +377 -0
- package/dist/manager.js.map +1 -0
- package/dist/migration/auto-migrate.d.ts +20 -0
- package/dist/migration/auto-migrate.d.ts.map +1 -0
- package/dist/migration/auto-migrate.js +49 -0
- package/dist/migration/auto-migrate.js.map +1 -0
- package/dist/migration/json-to-vault.d.ts +10 -0
- package/dist/migration/json-to-vault.d.ts.map +1 -0
- package/dist/migration/json-to-vault.js +88 -0
- package/dist/migration/json-to-vault.js.map +1 -0
- package/dist/migration/vault-version.d.ts +4 -0
- package/dist/migration/vault-version.d.ts.map +1 -0
- package/dist/migration/vault-version.js +19 -0
- package/dist/migration/vault-version.js.map +1 -0
- package/dist/retrieval/cosine-ann.d.ts +13 -0
- package/dist/retrieval/cosine-ann.d.ts.map +1 -0
- package/dist/retrieval/cosine-ann.js +26 -0
- package/dist/retrieval/cosine-ann.js.map +1 -0
- package/dist/retrieval/spreading-activation.d.ts +12 -0
- package/dist/retrieval/spreading-activation.d.ts.map +1 -0
- package/dist/retrieval/spreading-activation.js +70 -0
- package/dist/retrieval/spreading-activation.js.map +1 -0
- package/dist/store.d.ts +38 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +192 -0
- package/dist/store.js.map +1 -0
- package/dist/vault/default-vault-dir.d.ts +17 -0
- package/dist/vault/default-vault-dir.d.ts.map +1 -0
- package/dist/vault/default-vault-dir.js +23 -0
- package/dist/vault/default-vault-dir.js.map +1 -0
- package/dist/vault/file-format.d.ts +44 -0
- package/dist/vault/file-format.d.ts.map +1 -0
- package/dist/vault/file-format.js +214 -0
- package/dist/vault/file-format.js.map +1 -0
- package/dist/vault/vault-index.d.ts +28 -0
- package/dist/vault/vault-index.d.ts.map +1 -0
- package/dist/vault/vault-index.js +98 -0
- package/dist/vault/vault-index.js.map +1 -0
- package/dist/vault/vault-store.d.ts +75 -0
- package/dist/vault/vault-store.d.ts.map +1 -0
- package/dist/vault/vault-store.js +369 -0
- package/dist/vault/vault-store.js.map +1 -0
- package/dist/vault-memory-provider.d.ts +53 -0
- package/dist/vault-memory-provider.d.ts.map +1 -0
- package/dist/vault-memory-provider.js +139 -0
- package/dist/vault-memory-provider.js.map +1 -0
- package/package.json +58 -0
- package/valora-plugin.json +10 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Consolidation Service.
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates the full consolidation cycle for the agent memory system:
|
|
5
|
+
* 1. Prune decayed entries below the strength threshold
|
|
6
|
+
* 2. Run git-based invalidation to weaken memories referencing changed files
|
|
7
|
+
* 3. Detect similar episodic entries and merge them into semantic patterns
|
|
8
|
+
* 4. Auto-promote high-access verified entries to semantic store
|
|
9
|
+
*
|
|
10
|
+
* Designed to be called from the `valora consolidate` CLI command
|
|
11
|
+
* or as a post-feedback automatic maintenance step.
|
|
12
|
+
*/
|
|
13
|
+
import { generateMemoryId, SafeExecutor } from '@windagency/valora-runtime';
|
|
14
|
+
import { centroidSummary, cosineClusters } from './consolidation/cluster.js';
|
|
15
|
+
import { resolveEmbedder } from './embeddings/resolve-embedder.js';
|
|
16
|
+
import { openVectorStore, readVectorStoreMeta } from './embeddings/vector-store.js';
|
|
17
|
+
import { MemoryManager } from './manager.js';
|
|
18
|
+
import { runAutoMigrationIfNeeded } from './migration/auto-migrate.js';
|
|
19
|
+
import { getDefaultVaultDir, getLegacyJsonDir } from './vault/default-vault-dir.js';
|
|
20
|
+
import { VaultStore } from './vault/vault-store.js';
|
|
21
|
+
/** Compute Jaccard similarity between two tag sets. */
|
|
22
|
+
function jaccardSimilarity(a, b) {
|
|
23
|
+
const setA = new Set(a);
|
|
24
|
+
const setB = new Set(b);
|
|
25
|
+
const intersection = [...setA].filter((t) => setB.has(t)).length;
|
|
26
|
+
const union = new Set([...a, ...b]).size;
|
|
27
|
+
return union === 0 ? 0 : intersection / union;
|
|
28
|
+
}
|
|
29
|
+
/** Parse `git log --name-only --format=COMMIT:%H %s --since=<date>` output. */
|
|
30
|
+
function parseGitLogOutput(output) {
|
|
31
|
+
const commits = [];
|
|
32
|
+
let current = null;
|
|
33
|
+
for (const line of output.split('\n')) {
|
|
34
|
+
const trimmed = line.trim();
|
|
35
|
+
if (trimmed.startsWith('COMMIT:')) {
|
|
36
|
+
if (current !== null) {
|
|
37
|
+
commits.push(current);
|
|
38
|
+
}
|
|
39
|
+
// Format: "COMMIT:<hash> <message>"
|
|
40
|
+
const rest = trimmed.slice('COMMIT:'.length);
|
|
41
|
+
const spaceIndex = rest.indexOf(' ');
|
|
42
|
+
const hash = spaceIndex === -1 ? rest : rest.slice(0, spaceIndex);
|
|
43
|
+
const message = spaceIndex === -1 ? '' : rest.slice(spaceIndex + 1);
|
|
44
|
+
current = { changedFiles: [], hash, message };
|
|
45
|
+
} else if (trimmed.length > 0 && current !== null) {
|
|
46
|
+
current.changedFiles.push(trimmed);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (current !== null) {
|
|
50
|
+
commits.push(current);
|
|
51
|
+
}
|
|
52
|
+
return commits;
|
|
53
|
+
}
|
|
54
|
+
const COSINE_CLUSTER_THRESHOLD = 0.82;
|
|
55
|
+
export class MemoryConsolidationService {
|
|
56
|
+
context;
|
|
57
|
+
embedder;
|
|
58
|
+
manager;
|
|
59
|
+
store;
|
|
60
|
+
constructor(store, embedder, context = {}) {
|
|
61
|
+
this.store = store ?? buildDefaultVaultStore();
|
|
62
|
+
this.embedder = embedder;
|
|
63
|
+
this.context = context;
|
|
64
|
+
this.manager = new MemoryManager(this.store, undefined, embedder);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build a service with the embedder resolved from the host-provided
|
|
68
|
+
* `providerLookup`. Used by the singleton helper and the CLI entry
|
|
69
|
+
* points so cosine consolidation fires automatically when a provider
|
|
70
|
+
* with `embed?()` is available.
|
|
71
|
+
*
|
|
72
|
+
* Without a provider lookup, the service is constructed embedder-less
|
|
73
|
+
* and falls back to the Jaccard merge path.
|
|
74
|
+
*/
|
|
75
|
+
static async create(context = {}) {
|
|
76
|
+
let embedder;
|
|
77
|
+
try {
|
|
78
|
+
embedder = await resolveEmbedder(undefined, context.providerLookup);
|
|
79
|
+
} catch {
|
|
80
|
+
embedder = undefined;
|
|
81
|
+
}
|
|
82
|
+
return new MemoryConsolidationService(undefined, embedder, context);
|
|
83
|
+
}
|
|
84
|
+
async consolidate(options = {}) {
|
|
85
|
+
const startMs = Date.now();
|
|
86
|
+
const { dryRun = false, pruneOnly = false } = options;
|
|
87
|
+
let pruned = 0;
|
|
88
|
+
let gitInvalidated = 0;
|
|
89
|
+
let staleMarked = 0;
|
|
90
|
+
let merged = 0;
|
|
91
|
+
let promoted = 0;
|
|
92
|
+
// Step 1: Prune decayed entries
|
|
93
|
+
if (!dryRun) {
|
|
94
|
+
pruned = await this.manager.prune();
|
|
95
|
+
}
|
|
96
|
+
// Step 2: Git-based invalidation
|
|
97
|
+
const gitResult = await this.runGitInvalidation(options.since);
|
|
98
|
+
gitInvalidated = gitResult.invalidated;
|
|
99
|
+
staleMarked = gitResult.staleMarked;
|
|
100
|
+
// Step 3: Detect similar episodic entries and merge (skip if pruneOnly)
|
|
101
|
+
if (!pruneOnly) {
|
|
102
|
+
merged = await this.mergeEpisodicEntries(dryRun);
|
|
103
|
+
}
|
|
104
|
+
// Step 4: Auto-promote high-value episodic entries (skip if pruneOnly)
|
|
105
|
+
if (!pruneOnly) {
|
|
106
|
+
promoted = await this.autoPromoteEntries(dryRun);
|
|
107
|
+
}
|
|
108
|
+
// Step 5: Update consolidation timestamp
|
|
109
|
+
if (!dryRun) {
|
|
110
|
+
await this.store.setLastConsolidatedAt(new Date().toISOString());
|
|
111
|
+
}
|
|
112
|
+
await this.manager.flush();
|
|
113
|
+
const durationMs = Date.now() - startMs;
|
|
114
|
+
// Step 6: Emit event via the host-provided listener (no-op when absent).
|
|
115
|
+
const result = {
|
|
116
|
+
durationMs,
|
|
117
|
+
gitInvalidated,
|
|
118
|
+
merged,
|
|
119
|
+
promoted,
|
|
120
|
+
pruned,
|
|
121
|
+
staleMarked
|
|
122
|
+
};
|
|
123
|
+
this.context.onComplete?.(result);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
async autoPromoteEntries(dryRun) {
|
|
127
|
+
const entries = await this.store.getEntries('episodic');
|
|
128
|
+
let promotedCount = 0;
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
if (entry.accessCount >= 5 && entry.confidence === 'verified' && entry.supersededBy === undefined) {
|
|
131
|
+
if (!dryRun) {
|
|
132
|
+
await this.manager.promote(entry.id, entry.content, entry.tags);
|
|
133
|
+
}
|
|
134
|
+
promotedCount++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return promotedCount;
|
|
138
|
+
}
|
|
139
|
+
buildCluster(entryI, group, startIdx, visited) {
|
|
140
|
+
const cluster = [entryI];
|
|
141
|
+
for (let j = startIdx + 1; j < group.length; j++) {
|
|
142
|
+
if (visited.has(j)) continue;
|
|
143
|
+
const entryJ = group[j];
|
|
144
|
+
if (entryJ === undefined) continue;
|
|
145
|
+
if (jaccardSimilarity(entryI.tags, entryJ.tags) >= 0.6) {
|
|
146
|
+
cluster.push(entryJ);
|
|
147
|
+
visited.add(j);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return cluster;
|
|
151
|
+
}
|
|
152
|
+
async mergeCluster(cluster, dryRun) {
|
|
153
|
+
const primaryEntry = cluster[0];
|
|
154
|
+
if (primaryEntry === undefined) return false;
|
|
155
|
+
const combinedContent = cluster.map((e) => e.content).join('\n\n');
|
|
156
|
+
const combinedTags = [...new Set(cluster.flatMap((e) => e.tags))];
|
|
157
|
+
const bestConfidence = cluster.reduce(
|
|
158
|
+
(best, e) => (confidenceRank(e.confidence) > confidenceRank(best) ? e.confidence : best),
|
|
159
|
+
primaryEntry.confidence
|
|
160
|
+
);
|
|
161
|
+
if (!dryRun) {
|
|
162
|
+
if (bestConfidence !== primaryEntry.confidence) {
|
|
163
|
+
await this.manager.update('episodic', primaryEntry.id, { confidence: bestConfidence });
|
|
164
|
+
}
|
|
165
|
+
const promoted = await this.manager.promote(primaryEntry.id, combinedContent, combinedTags);
|
|
166
|
+
// Persist `decays_from` edges for the rest of the cluster. A single
|
|
167
|
+
// appendEntryWithLinks call writes all edges at once — per-member
|
|
168
|
+
// calls would overwrite the file each iteration, losing all but the
|
|
169
|
+
// last edge (H14). The supersedes edge for the primary was already
|
|
170
|
+
// written by promote(); include it again here to survive the overwrite.
|
|
171
|
+
const vault = this.store instanceof VaultStore ? this.store : undefined;
|
|
172
|
+
if (vault !== undefined && cluster.length > 1) {
|
|
173
|
+
const allEdges = [
|
|
174
|
+
{ fromId: promoted.id, kind: 'supersedes', toId: primaryEntry.id },
|
|
175
|
+
...cluster.slice(1).map((m) => ({ fromId: promoted.id, kind: 'decays_from', toId: m.id }))
|
|
176
|
+
];
|
|
177
|
+
await vault.appendEntryWithLinks('semantic', promoted, allEdges);
|
|
178
|
+
}
|
|
179
|
+
for (const entry of cluster.slice(1)) {
|
|
180
|
+
await this.manager.delete('episodic', entry.id);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
readSemanticHalfLifeOrDefault() {
|
|
186
|
+
return this.context.semanticHalfLifeDays ?? 30;
|
|
187
|
+
}
|
|
188
|
+
/** Groups episodic entries by their primary tag; entries with no tags are excluded. */
|
|
189
|
+
buildTagGroups(entries) {
|
|
190
|
+
const groups = new Map();
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
if (entry.tags.length === 0) continue;
|
|
193
|
+
const primaryTag = entry.tags[0];
|
|
194
|
+
if (!groups.has(primaryTag)) groups.set(primaryTag, []);
|
|
195
|
+
groups.get(primaryTag).push(entry);
|
|
196
|
+
}
|
|
197
|
+
return groups;
|
|
198
|
+
}
|
|
199
|
+
async mergeClusterCosine(cluster, vaultStore) {
|
|
200
|
+
const now = new Date().toISOString();
|
|
201
|
+
const id = generateMemoryId();
|
|
202
|
+
const content = centroidSummary(cluster);
|
|
203
|
+
const tags = [...new Set(cluster.flatMap((e) => e.tags))];
|
|
204
|
+
const bestConfidence = cluster.reduce(
|
|
205
|
+
(best, e) => (confidenceRank(e.confidence) > confidenceRank(best) ? e.confidence : best),
|
|
206
|
+
cluster[0].confidence
|
|
207
|
+
);
|
|
208
|
+
// Half-life from injected config so cosine and Jaccard paths agree (H13).
|
|
209
|
+
// Falls back to the default constant when config has not been loaded
|
|
210
|
+
// (e.g. unit/integration tests that bypass the loader).
|
|
211
|
+
const semanticHalfLife = this.readSemanticHalfLifeOrDefault();
|
|
212
|
+
const newEntry = {
|
|
213
|
+
accessCount: 0,
|
|
214
|
+
agentRole: cluster[0].agentRole,
|
|
215
|
+
category: 'semantic',
|
|
216
|
+
confidence: bestConfidence,
|
|
217
|
+
content,
|
|
218
|
+
createdAt: now,
|
|
219
|
+
halfLifeDays: semanticHalfLife,
|
|
220
|
+
id,
|
|
221
|
+
isError: false,
|
|
222
|
+
lastAccessedAt: now,
|
|
223
|
+
relatedPaths: [...new Set(cluster.flatMap((e) => e.relatedPaths))],
|
|
224
|
+
sessionId: cluster[0].sessionId,
|
|
225
|
+
source: cluster[0].source,
|
|
226
|
+
tags,
|
|
227
|
+
updatedAt: now
|
|
228
|
+
};
|
|
229
|
+
const links = cluster.map((m) => ({ fromId: id, kind: 'decays_from', toId: m.id }));
|
|
230
|
+
await vaultStore.appendEntryWithLinks('semantic', newEntry, links);
|
|
231
|
+
// Mark all cluster members as stale
|
|
232
|
+
for (const member of cluster) {
|
|
233
|
+
await vaultStore.updateEntry('episodic', member.id, { confidence: 'stale', supersededBy: id });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async mergeCosine(dryRun) {
|
|
237
|
+
const vaultStore = this.store;
|
|
238
|
+
const vaultDir = vaultStore.getVaultDir();
|
|
239
|
+
// Cosine consolidation requires existing on-disk embeddings; align with
|
|
240
|
+
// the persisted model/dim so the strict mismatch guard does not throw.
|
|
241
|
+
const meta = readVectorStoreMeta(vaultDir);
|
|
242
|
+
if (meta === null) return 0;
|
|
243
|
+
const entries = await vaultStore.getEntries('episodic');
|
|
244
|
+
const vs = openVectorStore(vaultDir, meta.model, meta.dim);
|
|
245
|
+
const clusters = cosineClusters(entries, vs, COSINE_CLUSTER_THRESHOLD);
|
|
246
|
+
let mergedCount = 0;
|
|
247
|
+
for (const cluster of clusters) {
|
|
248
|
+
if (dryRun) {
|
|
249
|
+
mergedCount++;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
await this.mergeClusterCosine(cluster, vaultStore);
|
|
253
|
+
mergedCount++;
|
|
254
|
+
}
|
|
255
|
+
return mergedCount;
|
|
256
|
+
}
|
|
257
|
+
async mergeEpisodicEntries(dryRun) {
|
|
258
|
+
if (this.embedder && this.store instanceof VaultStore) {
|
|
259
|
+
const cosineMerged = await this.mergeCosine(dryRun);
|
|
260
|
+
if (cosineMerged > 0) return cosineMerged;
|
|
261
|
+
// No embeddings on disk — fall back to Jaccard so consolidation still runs.
|
|
262
|
+
}
|
|
263
|
+
return this.mergeJaccard(dryRun);
|
|
264
|
+
}
|
|
265
|
+
async mergeJaccard(dryRun) {
|
|
266
|
+
const entries = await this.store.getEntries('episodic');
|
|
267
|
+
const groups = this.buildTagGroups(entries);
|
|
268
|
+
let mergedCount = 0;
|
|
269
|
+
for (const [, group] of groups) {
|
|
270
|
+
if (group.length < 2) continue;
|
|
271
|
+
const visited = new Set();
|
|
272
|
+
for (let i = 0; i < group.length; i++) {
|
|
273
|
+
if (visited.has(i)) continue;
|
|
274
|
+
const entryI = group[i];
|
|
275
|
+
if (entryI === undefined) continue;
|
|
276
|
+
visited.add(i);
|
|
277
|
+
const cluster = this.buildCluster(entryI, group, i, visited);
|
|
278
|
+
if (cluster.length < 2) continue;
|
|
279
|
+
if (await this.mergeCluster(cluster, dryRun)) {
|
|
280
|
+
mergedCount++;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return mergedCount;
|
|
285
|
+
}
|
|
286
|
+
async runGitInvalidation(sinceOverride) {
|
|
287
|
+
// Get last consolidated timestamp from episodic metadata
|
|
288
|
+
let sinceDate;
|
|
289
|
+
if (sinceOverride !== undefined) {
|
|
290
|
+
sinceDate = sinceOverride;
|
|
291
|
+
} else {
|
|
292
|
+
const metadata = await this.store.getMetadata('episodic');
|
|
293
|
+
if (metadata.lastConsolidatedAt !== undefined) {
|
|
294
|
+
sinceDate = metadata.lastConsolidatedAt;
|
|
295
|
+
} else {
|
|
296
|
+
// Default: 7 days ago
|
|
297
|
+
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
|
298
|
+
sinceDate = sevenDaysAgo.toISOString();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
let gitOutput = '';
|
|
302
|
+
try {
|
|
303
|
+
const result = await SafeExecutor.executeGit([
|
|
304
|
+
'log',
|
|
305
|
+
'--name-only',
|
|
306
|
+
`--format=COMMIT:%H %s`,
|
|
307
|
+
`--since=${sinceDate}`
|
|
308
|
+
]);
|
|
309
|
+
gitOutput = result.stdout;
|
|
310
|
+
} catch {
|
|
311
|
+
// Git not available or not in a git repo — skip invalidation gracefully
|
|
312
|
+
return { invalidated: 0, staleMarked: 0 };
|
|
313
|
+
}
|
|
314
|
+
const commits = parseGitLogOutput(gitOutput);
|
|
315
|
+
const allChangedFiles = new Set();
|
|
316
|
+
const staleFiles = new Set();
|
|
317
|
+
const revertPattern = /\b(revert|remove|delete|migrate\s+from)\b/i;
|
|
318
|
+
for (const commit of commits) {
|
|
319
|
+
for (const file of commit.changedFiles) {
|
|
320
|
+
allChangedFiles.add(file);
|
|
321
|
+
}
|
|
322
|
+
if (revertPattern.test(commit.message)) {
|
|
323
|
+
for (const file of commit.changedFiles) {
|
|
324
|
+
staleFiles.add(file);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
let invalidated = 0;
|
|
329
|
+
let staleMarkedCount = 0;
|
|
330
|
+
if (allChangedFiles.size > 0) {
|
|
331
|
+
invalidated = await this.manager.invalidateByPaths([...allChangedFiles]);
|
|
332
|
+
}
|
|
333
|
+
if (staleFiles.size > 0) {
|
|
334
|
+
staleMarkedCount = await this.manager.markStaleByPaths([...staleFiles]);
|
|
335
|
+
}
|
|
336
|
+
return { invalidated, staleMarked: staleMarkedCount };
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function buildDefaultVaultStore() {
|
|
340
|
+
const vaultDir = getDefaultVaultDir();
|
|
341
|
+
runAutoMigrationIfNeeded(getLegacyJsonDir(), vaultDir);
|
|
342
|
+
return new VaultStore(vaultDir);
|
|
343
|
+
}
|
|
344
|
+
const CONFIDENCE_RANK = {
|
|
345
|
+
inferred: 1,
|
|
346
|
+
observed: 2,
|
|
347
|
+
stale: 0,
|
|
348
|
+
verified: 3
|
|
349
|
+
};
|
|
350
|
+
function confidenceRank(confidence) {
|
|
351
|
+
return CONFIDENCE_RANK[confidence];
|
|
352
|
+
}
|
|
353
|
+
let consolidationInstance = null;
|
|
354
|
+
let consolidationPromise = null;
|
|
355
|
+
/**
|
|
356
|
+
* Returns the shared {@link MemoryConsolidationService} for this process,
|
|
357
|
+
* resolving the configured embedder on first use so cosine consolidation can
|
|
358
|
+
* fire when a provider implements `embed?()`. Subsequent calls return the same
|
|
359
|
+
* instance without re-resolving.
|
|
360
|
+
*/
|
|
361
|
+
export async function getMemoryConsolidation() {
|
|
362
|
+
if (consolidationInstance !== null) return consolidationInstance;
|
|
363
|
+
consolidationPromise ??= MemoryConsolidationService.create().then((service) => {
|
|
364
|
+
consolidationInstance = service;
|
|
365
|
+
return service;
|
|
366
|
+
});
|
|
367
|
+
return consolidationPromise;
|
|
368
|
+
}
|
|
369
|
+
export function resetMemoryConsolidation() {
|
|
370
|
+
consolidationInstance = null;
|
|
371
|
+
consolidationPromise = null;
|
|
372
|
+
}
|
|
373
|
+
//# sourceMappingURL=consolidation-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consolidation-service.js","sourceRoot":"","sources":["../src/consolidation-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI5E,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAuB,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAkCpD,uDAAuD;AACvD,SAAS,iBAAiB,CAAC,CAAW,EAAE,CAAW;IAClD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,O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AAE,gBAAgB,EAAE,CAAC;IACvD,CAAC;CACD;AAED,SAAS,sBAAsB;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;IACtC,wBAAwB,CAAC,gBAAgB,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,eAAe,GAA8C;IAClE,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,QAAQ,EAAE,CAAC;CACX,CAAC;AAEF,SAAS,cAAc,CAAC,UAAqC;IAC5D,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AAED,IAAI,qBAAqB,GAAsC,IAAI,CAAC;AACpE,IAAI,oBAAoB,GAA+C,IAAI,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC3C,IAAI,qBAAqB,KAAK,IAAI;QAAE,OAAO,qBAAqB,CAAC;IACjE,oBAAoB,KAAK,0BAA0B,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7E,qBAAqB,GAAG,OAAO,CAAC;QAChC,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,OAAO,oBAAoB,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,wBAAwB;IACvC,qBAAqB,GAAG,IAAI,CAAC;IAC7B,oBAAoB,GAAG,IAAI,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-domain constants for the bundled vault implementation.
|
|
3
|
+
*
|
|
4
|
+
* These are the defaults the vault uses when configuration omits them. The
|
|
5
|
+
* host's `config/constants` re-exports these for back-compat with the Zod
|
|
6
|
+
* memory schema and any other host code that referenced them.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MS_PER_DAY: number;
|
|
9
|
+
export declare const MEMORY_STORE_VERSION = 1;
|
|
10
|
+
export declare const MEMORY_HALF_LIFE_CAP_MULTIPLIER = 10;
|
|
11
|
+
export declare const MEMORY_PERSIST_DEBOUNCE_MS = 2000;
|
|
12
|
+
export declare const DEFAULT_MEMORY_ENABLED = true;
|
|
13
|
+
export declare const DEFAULT_MEMORY_BACKEND: 'vault';
|
|
14
|
+
export declare const DEFAULT_MEMORY_EPISODIC_HALF_LIFE_DAYS = 7;
|
|
15
|
+
export declare const DEFAULT_MEMORY_SEMANTIC_HALF_LIFE_DAYS = 30;
|
|
16
|
+
export declare const DEFAULT_MEMORY_DECISION_HALF_LIFE_DAYS = 21;
|
|
17
|
+
export declare const DEFAULT_MEMORY_RETRIEVAL_BOOST_DAYS = 2;
|
|
18
|
+
export declare const DEFAULT_MEMORY_PRUNE_THRESHOLD = 0.05;
|
|
19
|
+
export declare const DEFAULT_MEMORY_MAX_ENTRIES_PER_STORE = 500;
|
|
20
|
+
export declare const DEFAULT_MEMORY_ERROR_HALF_LIFE_MULTIPLIER = 2;
|
|
21
|
+
export declare const DEFAULT_MEMORY_INJECTION_TOKEN_BUDGET = 2000;
|
|
22
|
+
export declare const DEFAULT_MEMORY_INJECTION_STRENGTH_THRESHOLD = 0.2;
|
|
23
|
+
export declare const DEFAULT_MEMORY_EMBED_MODEL = 'nomic-embed-text';
|
|
24
|
+
export declare const DEFAULT_MEMORY_EMBED_DIM = 768;
|
|
25
|
+
export declare const DEFAULT_MEMORY_EMBED_BATCH_SIZE = 32;
|
|
26
|
+
export declare const DEFAULT_MEMORY_RECALL_SEED_K = 12;
|
|
27
|
+
export declare const DEFAULT_MEMORY_RECALL_WALK_DEPTH = 2;
|
|
28
|
+
export declare const DEFAULT_MEMORY_RECALL_WALK_DECAY = 0.6;
|
|
29
|
+
export declare const DEFAULT_MEMORY_RECALL_CO_ACCESS_INCREMENT = 1;
|
|
30
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,UAAU,QAAsB,CAAC;AAE9C,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAClD,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,sBAAsB,EAAG,OAAgB,CAAC;AAEvD,eAAO,MAAM,sCAAsC,IAAI,CAAC;AACxD,eAAO,MAAM,sCAAsC,KAAK,CAAC;AACzD,eAAO,MAAM,sCAAsC,KAAK,CAAC;AACzD,eAAO,MAAM,mCAAmC,IAAI,CAAC;AACrD,eAAO,MAAM,8BAA8B,OAAO,CAAC;AACnD,eAAO,MAAM,oCAAoC,MAAM,CAAC;AACxD,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAE3D,eAAO,MAAM,qCAAqC,OAAO,CAAC;AAC1D,eAAO,MAAM,2CAA2C,MAAM,CAAC;AAE/D,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAC7D,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAClD,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,eAAO,MAAM,yCAAyC,IAAI,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-domain constants for the bundled vault implementation.
|
|
3
|
+
*
|
|
4
|
+
* These are the defaults the vault uses when configuration omits them. The
|
|
5
|
+
* host's `config/constants` re-exports these for back-compat with the Zod
|
|
6
|
+
* memory schema and any other host code that referenced them.
|
|
7
|
+
*/
|
|
8
|
+
export const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
9
|
+
export const MEMORY_STORE_VERSION = 1;
|
|
10
|
+
export const MEMORY_HALF_LIFE_CAP_MULTIPLIER = 10;
|
|
11
|
+
export const MEMORY_PERSIST_DEBOUNCE_MS = 2000;
|
|
12
|
+
export const DEFAULT_MEMORY_ENABLED = true;
|
|
13
|
+
export const DEFAULT_MEMORY_BACKEND = 'vault';
|
|
14
|
+
export const DEFAULT_MEMORY_EPISODIC_HALF_LIFE_DAYS = 7;
|
|
15
|
+
export const DEFAULT_MEMORY_SEMANTIC_HALF_LIFE_DAYS = 30;
|
|
16
|
+
export const DEFAULT_MEMORY_DECISION_HALF_LIFE_DAYS = 21;
|
|
17
|
+
export const DEFAULT_MEMORY_RETRIEVAL_BOOST_DAYS = 2;
|
|
18
|
+
export const DEFAULT_MEMORY_PRUNE_THRESHOLD = 0.05;
|
|
19
|
+
export const DEFAULT_MEMORY_MAX_ENTRIES_PER_STORE = 500;
|
|
20
|
+
export const DEFAULT_MEMORY_ERROR_HALF_LIFE_MULTIPLIER = 2;
|
|
21
|
+
export const DEFAULT_MEMORY_INJECTION_TOKEN_BUDGET = 2000;
|
|
22
|
+
export const DEFAULT_MEMORY_INJECTION_STRENGTH_THRESHOLD = 0.2;
|
|
23
|
+
export const DEFAULT_MEMORY_EMBED_MODEL = 'nomic-embed-text';
|
|
24
|
+
export const DEFAULT_MEMORY_EMBED_DIM = 768;
|
|
25
|
+
export const DEFAULT_MEMORY_EMBED_BATCH_SIZE = 32;
|
|
26
|
+
export const DEFAULT_MEMORY_RECALL_SEED_K = 12;
|
|
27
|
+
export const DEFAULT_MEMORY_RECALL_WALK_DEPTH = 2;
|
|
28
|
+
export const DEFAULT_MEMORY_RECALL_WALK_DECAY = 0.6;
|
|
29
|
+
export const DEFAULT_MEMORY_RECALL_CO_ACCESS_INCREMENT = 1;
|
|
30
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory decay computation.
|
|
3
|
+
*
|
|
4
|
+
* Implements exponential decay: strength = 0.5^(elapsed_days / halfLifeDays)
|
|
5
|
+
* Biologically inspired by the Ebbinghaus forgetting curve.
|
|
6
|
+
*
|
|
7
|
+
* All functions are pure with no side effects, making them easily testable
|
|
8
|
+
* and safe to call during hot paths (e.g. query filtering).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Compute current memory strength using exponential decay.
|
|
12
|
+
*
|
|
13
|
+
* Strength ranges from (0, 1] — it approaches 0 asymptotically but
|
|
14
|
+
* never reaches it. A strength of 1.0 means "just created/accessed".
|
|
15
|
+
*
|
|
16
|
+
* @param referenceAt - ISO 8601 timestamp to measure elapsed time from
|
|
17
|
+
* @param halfLifeDays - Number of days for strength to halve
|
|
18
|
+
* @param now - Current time in milliseconds (injectable for testing, defaults to Date.now())
|
|
19
|
+
* @returns Strength in range (0, 1]
|
|
20
|
+
*/
|
|
21
|
+
export declare function computeStrength(referenceAt: string, halfLifeDays: number, now?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Compute the effective half-life for a memory entry.
|
|
24
|
+
*
|
|
25
|
+
* The base half-life is extended by:
|
|
26
|
+
* - Error multiplier: error memories decay more slowly to preserve hard lessons
|
|
27
|
+
* - Retrieval boost: each access adds boostDays to the half-life (spaced repetition)
|
|
28
|
+
*
|
|
29
|
+
* @param baseHalfLifeDays - The category's default half-life in days
|
|
30
|
+
* @param accessCount - Number of times the entry has been retrieved
|
|
31
|
+
* @param isError - Whether the entry records an error (gets errorMultiplier × halfLife)
|
|
32
|
+
* @param retrievalBoostDays - Days added to half-life per retrieval
|
|
33
|
+
* @param errorMultiplier - Multiplier applied to base half-life for error entries
|
|
34
|
+
* @returns Effective half-life in days
|
|
35
|
+
*/
|
|
36
|
+
export declare function computeEffectiveHalfLife(
|
|
37
|
+
baseHalfLifeDays: number,
|
|
38
|
+
accessCount: number,
|
|
39
|
+
isError: boolean,
|
|
40
|
+
retrievalBoostDays: number,
|
|
41
|
+
errorMultiplier: number
|
|
42
|
+
): number;
|
|
43
|
+
/**
|
|
44
|
+
* Determine whether a memory entry should be pruned based on its strength.
|
|
45
|
+
*
|
|
46
|
+
* @param strength - Current computed strength (0-1)
|
|
47
|
+
* @param threshold - Minimum strength to retain the entry
|
|
48
|
+
* @returns true if the entry should be removed
|
|
49
|
+
*/
|
|
50
|
+
export declare function shouldPrune(strength: number, threshold: number): boolean;
|
|
51
|
+
//# sourceMappingURL=decay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decay.d.ts","sourceRoot":"","sources":["../src/decay.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,MAAM,CAInG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACvC,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,MAAM,EAC1B,eAAe,EAAE,MAAM,GACrB,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAExE"}
|
package/dist/decay.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory decay computation.
|
|
3
|
+
*
|
|
4
|
+
* Implements exponential decay: strength = 0.5^(elapsed_days / halfLifeDays)
|
|
5
|
+
* Biologically inspired by the Ebbinghaus forgetting curve.
|
|
6
|
+
*
|
|
7
|
+
* All functions are pure with no side effects, making them easily testable
|
|
8
|
+
* and safe to call during hot paths (e.g. query filtering).
|
|
9
|
+
*/
|
|
10
|
+
// Inlined to keep this leaf module self-contained at the package boundary.
|
|
11
|
+
// The host's `config/constants` exposes the same value; if other parts of
|
|
12
|
+
// this package end up needing it too, lift it into a shared
|
|
13
|
+
// `./constants.ts` and re-export it from the host for back-compat.
|
|
14
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
15
|
+
/**
|
|
16
|
+
* Compute current memory strength using exponential decay.
|
|
17
|
+
*
|
|
18
|
+
* Strength ranges from (0, 1] — it approaches 0 asymptotically but
|
|
19
|
+
* never reaches it. A strength of 1.0 means "just created/accessed".
|
|
20
|
+
*
|
|
21
|
+
* @param referenceAt - ISO 8601 timestamp to measure elapsed time from
|
|
22
|
+
* @param halfLifeDays - Number of days for strength to halve
|
|
23
|
+
* @param now - Current time in milliseconds (injectable for testing, defaults to Date.now())
|
|
24
|
+
* @returns Strength in range (0, 1]
|
|
25
|
+
*/
|
|
26
|
+
export function computeStrength(referenceAt, halfLifeDays, now = Date.now()) {
|
|
27
|
+
const elapsedMs = now - new Date(referenceAt).getTime();
|
|
28
|
+
const elapsedDays = elapsedMs / MS_PER_DAY;
|
|
29
|
+
return Math.pow(0.5, elapsedDays / halfLifeDays);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Compute the effective half-life for a memory entry.
|
|
33
|
+
*
|
|
34
|
+
* The base half-life is extended by:
|
|
35
|
+
* - Error multiplier: error memories decay more slowly to preserve hard lessons
|
|
36
|
+
* - Retrieval boost: each access adds boostDays to the half-life (spaced repetition)
|
|
37
|
+
*
|
|
38
|
+
* @param baseHalfLifeDays - The category's default half-life in days
|
|
39
|
+
* @param accessCount - Number of times the entry has been retrieved
|
|
40
|
+
* @param isError - Whether the entry records an error (gets errorMultiplier × halfLife)
|
|
41
|
+
* @param retrievalBoostDays - Days added to half-life per retrieval
|
|
42
|
+
* @param errorMultiplier - Multiplier applied to base half-life for error entries
|
|
43
|
+
* @returns Effective half-life in days
|
|
44
|
+
*/
|
|
45
|
+
export function computeEffectiveHalfLife(baseHalfLifeDays, accessCount, isError, retrievalBoostDays, errorMultiplier) {
|
|
46
|
+
const base = isError ? baseHalfLifeDays * errorMultiplier : baseHalfLifeDays;
|
|
47
|
+
return base + accessCount * retrievalBoostDays;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Determine whether a memory entry should be pruned based on its strength.
|
|
51
|
+
*
|
|
52
|
+
* @param strength - Current computed strength (0-1)
|
|
53
|
+
* @param threshold - Minimum strength to retain the entry
|
|
54
|
+
* @returns true if the entry should be removed
|
|
55
|
+
*/
|
|
56
|
+
export function shouldPrune(strength, threshold) {
|
|
57
|
+
return strength < threshold;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=decay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decay.js","sourceRoot":"","sources":["../src/decay.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,2EAA2E;AAC3E,0EAA0E;AAC1E,4DAA4D;AAC5D,mEAAmE;AACnE,MAAM,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB,EAAE,YAAoB,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IAC1F,MAAM,SAAS,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;IAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB,CACvC,gBAAwB,EACxB,WAAmB,EACnB,OAAgB,EAChB,kBAA0B,EAC1B,eAAuB;IAEvB,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,gBAAgB,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAC7E,OAAO,IAAI,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,SAAiB;IAC9D,OAAO,QAAQ,GAAG,SAAS,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PluginEmbeddingRequest as EmbeddingRequest,
|
|
3
|
+
PluginEmbeddingResult as EmbeddingResult
|
|
4
|
+
} from '@windagency/valora-plugin-api';
|
|
5
|
+
export type { EmbeddingRequest, EmbeddingResult };
|
|
6
|
+
export interface EmbedderPort {
|
|
7
|
+
embed(req: EmbeddingRequest): Promise<EmbeddingResult>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=embedder.port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedder.port.d.ts","sourceRoot":"","sources":["../../src/embeddings/embedder.port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,sBAAsB,IAAI,gBAAgB,EAC1C,qBAAqB,IAAI,eAAe,EACxC,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAElD,MAAM,WAAW,YAAY;IAC5B,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedder.port.js","sourceRoot":"","sources":["../../src/embeddings/embedder.port.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LLMProviderContract as LLMProvider } from '@windagency/valora-plugin-api';
|
|
2
|
+
import type { EmbedderPort, EmbeddingRequest, EmbeddingResult } from './embedder.port.js';
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when the wrapped {@link LLMProvider} does not implement the optional
|
|
5
|
+
* `embed?()` method. ADR-013 §4 mandates graceful degradation: callers should
|
|
6
|
+
* detect this error and fall back to the lexical recall path rather than fail
|
|
7
|
+
* the entire pipeline.
|
|
8
|
+
*/
|
|
9
|
+
export declare class EmbedderNotSupportedError extends Error {
|
|
10
|
+
constructor(providerName: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Adapter that exposes an {@link LLMProvider}'s optional `embed?()` method
|
|
14
|
+
* through the {@link EmbedderPort} contract used by the memory subsystem.
|
|
15
|
+
*
|
|
16
|
+
* Per ADR-013 §4 and CODE-QUALITY-GUIDELINES.md (Adapter Pattern, Appendix B),
|
|
17
|
+
* memory must reach embedders only via this port — never via direct LLM-SDK
|
|
18
|
+
* imports — so swapping providers (Ollama, OpenAI, Anthropic) is a one-line
|
|
19
|
+
* change in DI wiring.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LlmProviderEmbedder implements EmbedderPort {
|
|
22
|
+
private readonly provider;
|
|
23
|
+
constructor(provider: LLMProvider);
|
|
24
|
+
embed(req: EmbeddingRequest): Promise<EmbeddingResult>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=llm-provider-embedder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-provider-embedder.d.ts","sourceRoot":"","sources":["../../src/embeddings/llm-provider-embedder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAExF,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1F;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;gBACvC,YAAY,EAAE,MAAM;CAIhC;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,WAAW;IAE5C,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CAM5D"}
|