mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
Merge remote-tracking branch 'pr/4942' into release/memory-3.3.1
This commit is contained in:
commit
397a8932d1
2 files changed
+35
-2
No files matched your search
@@ -331,6 +331,24 @@ describe('LearningBridge', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve a stored key and update the entry by its internal id', async () => {
|
||||
const entry = createTestEntry({
|
||||
id: 'internal-1',
|
||||
key: 'insight:debugging:12345:0',
|
||||
metadata: { confidence: 0.5 },
|
||||
});
|
||||
backend.storedEntries.push(entry);
|
||||
|
||||
await bridge.onInsightAccessed(entry.key);
|
||||
|
||||
expect(backend.getByKey).toHaveBeenCalledWith('learnings', entry.key);
|
||||
expect(backend.get).not.toHaveBeenCalled();
|
||||
expect(backend.update).toHaveBeenCalledWith('internal-1', {
|
||||
metadata: expect.objectContaining({ confidence: 0.53 }),
|
||||
});
|
||||
expect(entry.metadata?.confidence).toBeCloseTo(0.53);
|
||||
});
|
||||
|
||||
it('should cap confidence at maxConfidence', async () => {
|
||||
const entry = createTestEntry({ metadata: { confidence: 0.99 } });
|
||||
(backend.get as any).mockResolvedValueOnce(entry);
|
||||
|
||||
@@ -218,7 +218,7 @@ export class LearningBridge extends EventEmitter {
|
||||
async onInsightAccessed(entryId: string): Promise<void> {
|
||||
if (!this.config.enabled || this.destroyed) return;
|
||||
|
||||
const entry = await this.backend.get(entryId);
|
||||
const entry = await this.getInsightEntry(entryId);
|
||||
if (!entry) return;
|
||||
|
||||
const currentConf = (entry.metadata?.confidence as number) ?? 0.5;
|
||||
@@ -227,7 +227,7 @@ export class LearningBridge extends EventEmitter {
|
||||
currentConf + this.config.accessBoostAmount,
|
||||
);
|
||||
|
||||
await this.backend.update(entryId, {
|
||||
await this.backend.update(entry.id, {
|
||||
metadata: { ...entry.metadata, confidence: newConf },
|
||||
});
|
||||
|
||||
@@ -251,6 +251,21 @@ export class LearningBridge extends EventEmitter {
|
||||
this.emit('insight:accessed', { entryId, newConfidence: newConf });
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an insight the caller addresses by the key it was stored under.
|
||||
* `get()` only knows the backend's internal `entry.id`, and
|
||||
* `createDefaultEntry` mints that id independently of the caller's key, so a
|
||||
* key lookup must go through `getByKey` first; fall back to `get()` for
|
||||
* callers that really pass an id.
|
||||
*/
|
||||
private async getInsightEntry(entryId: string): Promise<MemoryEntry | null> {
|
||||
if (typeof this.backend.getByKey === 'function') {
|
||||
const byKey = await this.backend.getByKey(this.config.insightNamespace, entryId);
|
||||
if (byKey) return byKey;
|
||||
}
|
||||
return this.backend.get(entryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consolidate active trajectories by completing them in the neural system.
|
||||
* Only runs when there are enough active trajectories to justify the cost.
|
||||
|
||||
Reference in new issue
Block a user