Blame · Line-by-line history
memory.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| d0bc8c2 | 1 | /** |
| 2 | * Memory API routes — read/write platform memory for AI continuity. | |
| 3 | * | |
| 4 | * These endpoints let the AI subsystem (and admin tools) persist and | |
| 5 | * retrieve learned context across sessions and requests. | |
| 6 | */ | |
| 7 | ||
| 8 | import { Hono } from "hono"; | |
| 9 | import { requireAuth } from "../middleware/auth"; | |
| 10 | import type { AuthEnv } from "../middleware/auth"; | |
| 11 | import { memoryStore, memoryRecall, memorySummary } from "../lib/memory"; | |
| 12 | ||
| 13 | const memory = new Hono<AuthEnv>(); | |
| 14 | ||
| 15 | memory.get("/api/memory/recall", requireAuth, async (c) => { | |
| 16 | const query = c.req.query("q") || "*"; | |
| 17 | const category = c.req.query("category"); | |
| 18 | const limit = parseInt(c.req.query("limit") || "10", 10); | |
| 19 | ||
| 20 | const results = await memoryRecall(query, { category, limit }); | |
| 21 | return c.json({ results }); | |
| 22 | }); | |
| 23 | ||
| 24 | memory.post("/api/memory/store", requireAuth, async (c) => { | |
| 25 | const body = await c.req.json().catch(() => ({})); | |
| 26 | const { key, value, category, confidence, scope, language } = body as Record< | |
| 27 | string, | |
| 28 | string | number | undefined | |
| 29 | >; | |
| 30 | ||
| 31 | if (!key || !value) { | |
| 32 | return c.json({ error: "key and value are required" }, 400); | |
| 33 | } | |
| 34 | ||
| 35 | await memoryStore(String(key), String(value), { | |
| 36 | category: category ? String(category) : undefined, | |
| 37 | confidence: typeof confidence === "number" ? confidence : undefined, | |
| 38 | scope: scope ? String(scope) : undefined, | |
| 39 | language: language ? String(language) : undefined, | |
| 40 | }); | |
| 41 | ||
| 42 | return c.json({ stored: true }); | |
| 43 | }); | |
| 44 | ||
| 45 | memory.get("/api/memory/summary", requireAuth, async (c) => { | |
| 46 | const summary = await memorySummary(); | |
| 47 | return c.json({ summary }); | |
| 48 | }); | |
| 49 | ||
| 50 | export default memory; |