File size: 1,203 Bytes
8c867c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
api/memory.py
Bridge: exposes the FormulationMemoryNetwork as the `memory` singleton
used throughout the API (controller.py, main.py, odata endpoints).

Replaces the previous 21-line MemoryBus stub with the full 568-line
engine from modules/memory_network.py.
"""
import types
from modules.memory_network import get_memory_network

# Module-level singleton β€” same interface the rest of the app expects
memory = get_memory_network()


# ── Add the thin compat methods the rest of the app still calls ────────────────
#    (FormulationMemoryNetwork already has .record() with matching positional args)

def _recent(self, n=10):
    """Return last n events (MemoryBus compat)."""
    return self.state.events[-n:]

def _query(self, filter_fn):
    """Filter events by predicate (MemoryBus compat)."""
    return [e for e in self.state.events if filter_fn(e)]

def _get_all(self):
    """Return all recorded events."""
    return self.state.events


# Bind as instance methods (self will be passed correctly)
memory.recent  = types.MethodType(_recent,  memory)
memory.query   = types.MethodType(_query,   memory)
memory.get_all = types.MethodType(_get_all, memory)