Open History to see the last commit
1import { createFileRoute } from '@tanstack/react-router'
2import {
3 lastRecallByThread,
4 memoryAdapter,
5 panelMemoryScope,
6 panelScopeKey,
7} from '@/lib/memory-store'
8
9/**
10 * Read side of the `/memory` demo. Returns everything the panel needs to show
11 * "what's in memory" for a scope, straight off the shared singleton adapter:
12 * the full record snapshot, the flat fact list, and what the most recent
13 * `recall` injected into the prompt. User/tenant dims are server constants —
14 * only `threadId` is taken from the query string (demo multi-thread UX).
15 */
16export const Route = createFileRoute('/api/memory-inspect')({
17 server: {
18 handlers: {
19 GET: async ({ request }) => {
20 const threadId = new URL(request.url).searchParams.get('threadId') ?? ''
21 const scope = panelMemoryScope(threadId)
22
23 const snapshot = await memoryAdapter.inspect?.(scope)
24 const facts = await memoryAdapter.listFacts?.(scope)
25 const lastRecall = lastRecallByThread.get(panelScopeKey(scope)) ?? null
26
27 return new Response(
28 JSON.stringify({
29 snapshot: snapshot ?? null,
30 facts: facts ?? [],
31 lastRecall,
32 }),
33 {
34 status: 200,
35 headers: { 'Content-Type': 'application/json' },
36 },
37 )
38 },
39 },
40 },
41})