pi-mega-compact 0.13.0 → 0.13.2
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.
- package/dist/extensions/dashboard-server/api-contracts/embedder-health.js +11 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints/registry.js +225 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints/types.js +1 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints.js +5 -224
- package/dist/extensions/dashboard-server/api-contracts/raptor.js +8 -0
- package/dist/extensions/dashboard-server/api-contracts.test/_helpers.js +32 -0
- package/dist/extensions/dashboard-server/routes-cache.test/_helpers.js +48 -0
- package/dist/extensions/dashboard-server/routes-embedder-health.js +67 -0
- package/dist/extensions/dashboard-server/routes-raptor.js +88 -0
- package/dist/extensions/dashboard-server/routes-setup.js +1 -1
- package/dist/extensions/dashboard-server/routes.js +2 -0
- package/dist/extensions/dashboard-server/server.js +5 -1
- package/dist/extensions/mega-cache-replay.test/_helpers.js +175 -0
- package/dist/extensions/mega-commands/dataCommands.js +151 -0
- package/dist/extensions/mega-commands/helpers.js +61 -0
- package/dist/extensions/mega-commands/historyCommands.js +97 -0
- package/dist/extensions/mega-commands/setupCommand.js +200 -0
- package/dist/extensions/mega-commands.js +14 -499
- package/dist/extensions/mega-compact-s38.test/_helpers.js +194 -0
- package/dist/extensions/mega-compact.js +12 -2
- package/dist/extensions/mega-compact.test/_helpers.js +225 -0
- package/dist/extensions/mega-events/agent-handlers/agentEndHandler.js +211 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/cacheStripe.js +49 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/contextHealth.js +33 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/errorRetry.js +387 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/event.js +7 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/gameScoring.js +55 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/lengthStop.js +12 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/memoryReview.js +22 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler/recordTurnRow.js +38 -0
- package/dist/extensions/mega-events/agent-handlers/turnEndHandler.js +36 -0
- package/dist/extensions/mega-events/agent-handlers.js +4 -799
- package/dist/extensions/mega-events/context-handler/afterCompact.js +163 -0
- package/dist/extensions/mega-events/context-handler/messageText.js +12 -0
- package/dist/extensions/mega-events/context-handler/tailResult.js +46 -0
- package/dist/extensions/mega-events/context-handler.js +11 -198
- package/dist/extensions/mega-events/separated-prompt.test/_helpers.js +25 -0
- package/dist/src/config.js +2 -0
- package/dist/src/dedup-engine.test/_helpers.js +55 -0
- package/dist/src/e2e.test/_helpers.js +52 -0
- package/dist/src/embedder.js +1 -0
- package/dist/src/httpEmbedder.js +6 -0
- package/dist/src/hyde.js +146 -0
- package/dist/src/importance.test/_helpers.js +5 -0
- package/dist/src/memoryGraph/sources/checkpoints.js +78 -0
- package/dist/src/memoryGraph/sources/edges.js +17 -0
- package/dist/src/memoryGraph/sources/flags.js +22 -0
- package/dist/src/memoryGraph/sources/helpers.js +14 -0
- package/dist/src/memoryGraph/sources/memories.js +88 -0
- package/dist/src/memoryGraph/sources/raptor.js +26 -0
- package/dist/src/memoryGraph/sources/turns.js +176 -0
- package/dist/src/memoryGraph/sources.js +15 -441
- package/dist/src/memoryGraph-gates.test/_helpers.js +120 -0
- package/dist/src/ratio.bench.test/_helpers.js +198 -0
- package/dist/src/recall/async.js +112 -0
- package/dist/src/recall/format.js +149 -0
- package/dist/src/recall/memory.js +62 -0
- package/dist/src/recall/reformulate.js +82 -0
- package/dist/src/recall/sync.js +169 -0
- package/dist/src/recall/types.js +1 -0
- package/dist/src/recall.js +13 -530
- package/dist/src/store/sqlite/schema/core.js +232 -0
- package/dist/src/store/sqlite/schema/game.js +65 -0
- package/dist/src/store/sqlite/schema/plan-v2.js +107 -0
- package/dist/src/store/sqlite/schema/turns.js +59 -0
- package/dist/src/store/sqlite/schema.js +8 -441
- package/dist/src/store/turns/contract-compliance.test/_helpers.js +21 -0
- package/dist/src/store/turns/sqlite-store/admin.js +171 -0
- package/dist/src/store/turns/sqlite-store/ctx.js +1 -0
- package/dist/src/store/turns/sqlite-store/read.js +111 -0
- package/dist/src/store/turns/sqlite-store/rows.js +42 -0
- package/dist/src/store/turns/sqlite-store/write.js +102 -0
- package/dist/src/store/turns/sqlite-store.js +31 -367
- package/dist/src/vectorStore/class.js +356 -0
- package/dist/src/vectorStore/hash.js +10 -0
- package/dist/src/vectorStore/types.js +2 -0
- package/dist/src/vectorStore.js +8 -359
- package/dist/src/vectorStore.test/_helpers.js +17 -0
- package/extensions/dashboard-client/dist/assets/{CacheTab-BZNnKhh5.js → CacheTab-DPRHjYZ0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-BZNnKhh5.js.map → CacheTab-DPRHjYZ0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-CzF5L42U.js → EventsTab-CgwYq-Qf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-CzF5L42U.js.map → EventsTab-CgwYq-Qf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-BLpidMrX.js → HealthTab-BgOCjVzR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-BLpidMrX.js.map → HealthTab-BgOCjVzR.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/MaintenanceTab-Yw1yFpsy.js +2 -0
- package/extensions/dashboard-client/dist/assets/MaintenanceTab-Yw1yFpsy.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-yHUX7Yzi.js +2 -0
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-yHUX7Yzi.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{MetricsTab-B0PCysqs.js → MetricsTab-CcH9fP8P.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-B0PCysqs.js.map → MetricsTab-CcH9fP8P.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DsOhqFu4.js → OverviewTab-BOs8ZNev.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DsOhqFu4.js.map → OverviewTab-BOs8ZNev.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-B3YKYuOf.js → ReposTab-B-MfSPvg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-B3YKYuOf.js.map → ReposTab-B-MfSPvg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-B96FWcrC.js → SessionsTab-BmeN649Q.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-B96FWcrC.js.map → SessionsTab-BmeN649Q.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-nOknoph5.js +2 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-nOknoph5.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BfkUVTvA.js → TimeSavedCard-DnPg0L0z.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BfkUVTvA.js.map → TimeSavedCard-DnPg0L0z.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TopicsTab-DLRsZmXJ.js → TopicsTab-BODHOg_b.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TopicsTab-DLRsZmXJ.js.map → TopicsTab-BODHOg_b.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DKGU2Bf6.js → TurnsTab-BK0I7hKr.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DKGU2Bf6.js.map → TurnsTab-BK0I7hKr.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-D-lPLRWB.js → index-mOlljTFI.js} +10 -10
- package/extensions/dashboard-client/dist/assets/index-mOlljTFI.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{useSSE-ClbbcgIp.js → useSSE-BYOtv1-3.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-ClbbcgIp.js.map → useSSE-BYOtv1-3.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/App.tsx +0 -4
- package/extensions/dashboard-client/src/api/client.ts +16 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab/ActionsCard.tsx +178 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab/DbStatsCard.tsx +140 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab/DebugBundleCard.tsx +109 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab/HealthMitigationCard.tsx +98 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab/SchemaHealthCard.tsx +108 -0
- package/extensions/dashboard-client/src/tabs/MaintenanceTab.tsx +12 -598
- package/extensions/dashboard-client/src/tabs/MemoryMapTab/MemoryMapView.tsx +476 -0
- package/extensions/dashboard-client/src/tabs/MemoryMapTab/RaptorTreeView.tsx +163 -0
- package/extensions/dashboard-client/src/tabs/MemoryMapTab.tsx +56 -466
- package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderHealthCard.tsx +109 -0
- package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetup.tsx +468 -0
- package/extensions/dashboard-client/src/tabs/SetupTab.tsx +23 -484
- package/extensions/dashboard-server/api-contracts/embedder-health.ts +32 -0
- package/extensions/dashboard-server/api-contracts/endpoints/registry.ts +360 -0
- package/extensions/dashboard-server/api-contracts/endpoints/types.ts +350 -0
- package/extensions/dashboard-server/api-contracts/endpoints.ts +27 -648
- package/extensions/dashboard-server/api-contracts/index.ts +6 -0
- package/extensions/dashboard-server/api-contracts/raptor.ts +49 -0
- package/extensions/dashboard-server/api-contracts.test/_helpers.ts +47 -0
- package/extensions/dashboard-server/routes-cache.test/_helpers.ts +94 -0
- package/extensions/dashboard-server/routes-embedder-health.ts +77 -0
- package/extensions/dashboard-server/routes-raptor.ts +128 -0
- package/extensions/dashboard-server/routes-setup.ts +1 -1
- package/extensions/dashboard-server/routes.ts +2 -0
- package/extensions/dashboard-server/server.ts +4 -0
- package/extensions/mega-cache-replay.test/_helpers.ts +188 -0
- package/extensions/mega-commands/dataCommands.ts +169 -0
- package/extensions/mega-commands/helpers.ts +62 -0
- package/extensions/mega-commands/historyCommands.ts +117 -0
- package/extensions/mega-commands/setupCommand.ts +235 -0
- package/extensions/mega-commands.ts +25 -538
- package/extensions/mega-compact-s38.test/_helpers.ts +201 -0
- package/extensions/mega-compact.test/_helpers.ts +237 -0
- package/extensions/mega-compact.ts +12 -2
- package/extensions/mega-events/agent-handlers/agentEndHandler.ts +238 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/cacheStripe.ts +74 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/contextHealth.ts +50 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/errorRetry.ts +421 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/event.ts +16 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/gameScoring.ts +73 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/lengthStop.ts +29 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/memoryReview.ts +42 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler/recordTurnRow.ts +61 -0
- package/extensions/mega-events/agent-handlers/turnEndHandler.ts +64 -0
- package/extensions/mega-events/agent-handlers.ts +15 -861
- package/extensions/mega-events/context-handler/afterCompact.ts +213 -0
- package/extensions/mega-events/context-handler/messageText.ts +20 -0
- package/extensions/mega-events/context-handler/tailResult.ts +63 -0
- package/extensions/mega-events/context-handler.ts +17 -235
- package/extensions/mega-events/separated-prompt.test/_helpers.ts +35 -0
- package/package.json +1 -1
- package/src/config.ts +4 -0
- package/src/dedup-engine.test/_helpers.ts +79 -0
- package/src/e2e.test/_helpers.ts +59 -0
- package/src/embedder.ts +4 -0
- package/src/httpEmbedder.ts +7 -0
- package/src/hyde.ts +162 -0
- package/src/importance.test/_helpers.ts +5 -0
- package/src/memoryGraph/sources/checkpoints.ts +99 -0
- package/src/memoryGraph/sources/edges.ts +23 -0
- package/src/memoryGraph/sources/flags.ts +26 -0
- package/src/memoryGraph/sources/helpers.ts +13 -0
- package/src/memoryGraph/sources/memories.ts +108 -0
- package/src/memoryGraph/sources/raptor.ts +37 -0
- package/src/memoryGraph/sources/turns.ts +226 -0
- package/src/memoryGraph/sources.ts +19 -544
- package/src/memoryGraph-gates.test/_helpers.ts +164 -0
- package/src/ratio.bench.test/_helpers.ts +268 -0
- package/src/recall/async.ts +142 -0
- package/src/recall/format.ts +173 -0
- package/src/recall/memory.ts +90 -0
- package/src/recall/reformulate.ts +111 -0
- package/src/recall/sync.ts +196 -0
- package/src/recall/types.ts +63 -0
- package/src/recall.ts +25 -712
- package/src/store/sqlite/schema/core.ts +233 -0
- package/src/store/sqlite/schema/game.ts +66 -0
- package/src/store/sqlite/schema/plan-v2.ts +108 -0
- package/src/store/sqlite/schema/turns.ts +60 -0
- package/src/store/sqlite/schema.ts +13 -441
- package/src/store/turns/contract-compliance.test/_helpers.ts +38 -0
- package/src/store/turns/sqlite-store/admin.ts +249 -0
- package/src/store/turns/sqlite-store/ctx.ts +14 -0
- package/src/store/turns/sqlite-store/read.ts +174 -0
- package/src/store/turns/sqlite-store/rows.ts +55 -0
- package/src/store/turns/sqlite-store/write.ts +193 -0
- package/src/store/turns/sqlite-store.ts +33 -514
- package/src/vectorStore/class.ts +433 -0
- package/src/vectorStore/hash.ts +11 -0
- package/src/vectorStore/types.ts +58 -0
- package/src/vectorStore.test/_helpers.ts +20 -0
- package/src/vectorStore.ts +13 -489
- package/extensions/dashboard-client/dist/assets/ConfigTab-DG0WkuuG.js +0 -2
- package/extensions/dashboard-client/dist/assets/ConfigTab-DG0WkuuG.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/MaintenanceTab-BQF7W7xX.js +0 -2
- package/extensions/dashboard-client/dist/assets/MaintenanceTab-BQF7W7xX.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-CPtHLv0A.js +0 -2
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-CPtHLv0A.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-hbzQ_NZv.js +0 -2
- package/extensions/dashboard-client/dist/assets/SetupTab-hbzQ_NZv.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-D-lPLRWB.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/embedder-health.ts — Embedder health probe response types.
|
|
3
|
+
*
|
|
4
|
+
* Types for the GET /api/embedder-health endpoint used by the dashboard Setup
|
|
5
|
+
* tab's EmbedderHealthCard. Describes the result of round-tripping a test
|
|
6
|
+
* embed through the active embedder (latency + dimensions + reachability).
|
|
7
|
+
*
|
|
8
|
+
* PREVENT-PI-004: type definitions only, no network code.
|
|
9
|
+
* PREVENT-011: no `any` type — all types are explicit.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// ─── ENDPOINTS Registry ─────────────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Central registry of all 14 dashboard API endpoints. Each entry is an
|
|
4
|
+
* `EndpointDef` or `SseEndpointDef` instance serving as the single source of
|
|
5
|
+
* truth for route paths, methods, descriptions, and typed request/response
|
|
6
|
+
* contracts.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { ENDPOINTS } from './api-contracts';
|
|
10
|
+
* ENDPOINTS.snapshot.path // '/api/snapshot'
|
|
11
|
+
* ENDPOINTS.snapshot.method // 'GET'
|
|
12
|
+
*/
|
|
13
|
+
export const ENDPOINTS = {
|
|
14
|
+
/** GET /api/snapshot — Full session, store, compression, and context snapshot. */
|
|
15
|
+
snapshot: {
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: "/api/snapshot",
|
|
18
|
+
description: "Full session, store, compression, and context snapshot.",
|
|
19
|
+
},
|
|
20
|
+
/** GET /api/version — Dashboard server version string. */
|
|
21
|
+
version: {
|
|
22
|
+
method: "GET",
|
|
23
|
+
path: "/api/version",
|
|
24
|
+
description: "Dashboard server version for stale-server detection.",
|
|
25
|
+
},
|
|
26
|
+
/** GET /api/index — Multi-repo aggregate index (or fallback when unavailable). */
|
|
27
|
+
index: {
|
|
28
|
+
method: "GET",
|
|
29
|
+
path: "/api/index",
|
|
30
|
+
description: "Machine-wide multi-repo registry with checkpoints, tokens, and model info.",
|
|
31
|
+
},
|
|
32
|
+
/** GET /api/repos — Registry list with optional active-window filter. */
|
|
33
|
+
repos: {
|
|
34
|
+
method: "GET",
|
|
35
|
+
path: "/api/repos",
|
|
36
|
+
description: "Repo registry list, optionally filtered by recent activity.",
|
|
37
|
+
},
|
|
38
|
+
/** GET /api/summary — Lightweight header tiles without the full repo list. */
|
|
39
|
+
summary: {
|
|
40
|
+
method: "GET",
|
|
41
|
+
path: "/api/summary",
|
|
42
|
+
description: "Aggregate summary with active/total repo counts (no repo list).",
|
|
43
|
+
},
|
|
44
|
+
/** GET /api/drift — Cross-repo drift report. */
|
|
45
|
+
drift: {
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: "/api/drift",
|
|
48
|
+
description: "Cross-repo drift report flagging stale repos, compaction lag, and model churn.",
|
|
49
|
+
},
|
|
50
|
+
/** GET /api/servers — Recently-active repo servers with live snapshot data. */
|
|
51
|
+
servers: {
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/api/servers",
|
|
54
|
+
description: "Recently-active repo servers with live snapshot data.",
|
|
55
|
+
},
|
|
56
|
+
/** GET /api/events — SSE stream of dashboard events. */
|
|
57
|
+
events: {
|
|
58
|
+
type: "sse",
|
|
59
|
+
method: "GET",
|
|
60
|
+
path: "/api/events",
|
|
61
|
+
description: "Server-Sent Events stream of all dashboard events.",
|
|
62
|
+
event: "data",
|
|
63
|
+
},
|
|
64
|
+
/** GET /api/game-state — Current game-mode settings. */
|
|
65
|
+
getGameState: {
|
|
66
|
+
method: "GET",
|
|
67
|
+
path: "/api/game-state",
|
|
68
|
+
description: "Current game-mode configuration and active ritual state.",
|
|
69
|
+
},
|
|
70
|
+
/** PUT /api/game-state — Apply a partial patch to game-mode settings. */
|
|
71
|
+
putGameState: {
|
|
72
|
+
method: "PUT",
|
|
73
|
+
path: "/api/game-state",
|
|
74
|
+
description: "Apply a partial patch to game-mode settings and return the updated state.",
|
|
75
|
+
},
|
|
76
|
+
/** GET /api/game-scores — High-score leaderboard for a metric. */
|
|
77
|
+
gameScores: {
|
|
78
|
+
method: "GET",
|
|
79
|
+
path: "/api/game-scores",
|
|
80
|
+
description: "High-score leaderboard for a game metric.",
|
|
81
|
+
},
|
|
82
|
+
/** GET /api/perf — Rolling-window performance aggregates. */
|
|
83
|
+
perf: {
|
|
84
|
+
method: "GET",
|
|
85
|
+
path: "/api/perf",
|
|
86
|
+
description: "Rolling-window performance aggregates over perf_samples.",
|
|
87
|
+
},
|
|
88
|
+
/** GET /api/achievements — Achievement tiles with unlock state. */
|
|
89
|
+
achievements: {
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "/api/achievements",
|
|
92
|
+
description: "All achievement rows with unlock state.",
|
|
93
|
+
},
|
|
94
|
+
/** GET /api/sessions — Active sessions with latest token usage (S39). */
|
|
95
|
+
sessions: {
|
|
96
|
+
method: "GET",
|
|
97
|
+
path: "/api/sessions",
|
|
98
|
+
description: "Active pi sessions with latest token usage + heartbeat.",
|
|
99
|
+
},
|
|
100
|
+
/** GET /api/sessions/timeseries — Stacked per-session token timeseries (S39). */
|
|
101
|
+
sessionTimeseries: {
|
|
102
|
+
method: "GET",
|
|
103
|
+
path: "/api/sessions/timeseries",
|
|
104
|
+
description: "Recharts-ready per-session token timeseries for the stacked memory graph.",
|
|
105
|
+
},
|
|
106
|
+
/** GET /api/topics — Auto-categorizing wiki topics (S51). */
|
|
107
|
+
topics: {
|
|
108
|
+
method: "GET",
|
|
109
|
+
path: "/api/topics",
|
|
110
|
+
description: "Auto-categorized wiki topics from k-means + TF-IDF over real embeddings.",
|
|
111
|
+
},
|
|
112
|
+
/** GET /api/turns — Turn-by-turn memory tracking + recall (S52). */
|
|
113
|
+
turns: {
|
|
114
|
+
method: "GET",
|
|
115
|
+
path: "/api/turns",
|
|
116
|
+
description: "Per-conversation turn list with recall + epoch provenance (turn-by-turn memory tracking).",
|
|
117
|
+
},
|
|
118
|
+
/** GET /api/turns/conversation/:convId — per-turn detail + recall hits. */
|
|
119
|
+
conversationTurns: {
|
|
120
|
+
method: "GET",
|
|
121
|
+
path: "/api/turns/conversation/:convId",
|
|
122
|
+
description: "Per-turn metrics + injected-checkpoint recall provenance for one conversation.",
|
|
123
|
+
},
|
|
124
|
+
/** GET /api/turns/intents — pending rewind intents (S52A). */
|
|
125
|
+
turnIntents: {
|
|
126
|
+
method: "GET",
|
|
127
|
+
path: "/api/turns/intents",
|
|
128
|
+
description: "Pending rewind intents queued by the dashboard for the host to consume.",
|
|
129
|
+
},
|
|
130
|
+
/** POST /api/turns/intent — post a rewind intent. */
|
|
131
|
+
postTurnIntent: {
|
|
132
|
+
method: "POST",
|
|
133
|
+
path: "/api/turns/intent",
|
|
134
|
+
description: "Queue a rewind-to-turn-N intent for the host to apply at before_agent_start.",
|
|
135
|
+
},
|
|
136
|
+
/** POST /api/fork — fork a conversation at a turn. */
|
|
137
|
+
fork: {
|
|
138
|
+
method: "POST",
|
|
139
|
+
path: "/api/fork",
|
|
140
|
+
description: "Branch a child conversation off a parent turn + return the recall set to rehydrate.",
|
|
141
|
+
},
|
|
142
|
+
/** POST /api/turns/prune — admin prune (capability-gated). */
|
|
143
|
+
pruneTurns: {
|
|
144
|
+
method: "POST",
|
|
145
|
+
path: "/api/turns/prune",
|
|
146
|
+
description: "Prune old turns (admin capability — dashboard uses asAdmin()).",
|
|
147
|
+
},
|
|
148
|
+
/** GET /api/topics/:topicId/memories — wiki topic drill-down (S52). */
|
|
149
|
+
topicMemories: {
|
|
150
|
+
method: "GET",
|
|
151
|
+
path: "/api/topics/:topicId/memories",
|
|
152
|
+
description: "Member memories assigned to a wiki topic (drill-down).",
|
|
153
|
+
},
|
|
154
|
+
// ─── S49B Maintenance Tab ─────────────────────────────────────────
|
|
155
|
+
/** GET /api/maintenance — DB stats (table row counts + storage). */
|
|
156
|
+
maintenanceStats: {
|
|
157
|
+
method: "GET",
|
|
158
|
+
path: "/api/maintenance",
|
|
159
|
+
description: "SQLite table row counts, storage stats, and DB file sizes.",
|
|
160
|
+
},
|
|
161
|
+
/** GET /api/maintenance/schema-health — Schema version + integrity audit. */
|
|
162
|
+
schemaHealth: {
|
|
163
|
+
method: "GET",
|
|
164
|
+
path: "/api/maintenance/schema-health",
|
|
165
|
+
description: "SCHEMA_VERSION, PRAGMA integrity_check, FK check, and per-column audit.",
|
|
166
|
+
},
|
|
167
|
+
/** POST /api/maintenance/action — Trigger a maintenance action. */
|
|
168
|
+
maintenanceAction: {
|
|
169
|
+
method: "POST",
|
|
170
|
+
path: "/api/maintenance/action",
|
|
171
|
+
description: "Run vacuum, checkpoint, reindex, fts5-rebuild, reconcile-dedup, prune, or integrity-check.",
|
|
172
|
+
},
|
|
173
|
+
// ─── Provider Cache (Sprint A.2) ─────────────────────────────────
|
|
174
|
+
/** GET /api/provider-cache — Lifetime provider prompt cache aggregates + $ savings. */
|
|
175
|
+
providerCache: {
|
|
176
|
+
method: "GET",
|
|
177
|
+
path: "/api/provider-cache",
|
|
178
|
+
description: "Lifetime provider prompt cache hit-rate aggregates + dollar savings estimate.",
|
|
179
|
+
},
|
|
180
|
+
// ─── A3 Cache Stripes (PLAN_V2 Phase 4) ───────────────────────────
|
|
181
|
+
/** GET /api/cache-stripes — Per-stripe distribution + health score. */
|
|
182
|
+
cacheStripes: {
|
|
183
|
+
method: "GET",
|
|
184
|
+
path: "/api/cache-stripes",
|
|
185
|
+
description: "Per-stripe distribution counts, average stability scores, and composite cache health.",
|
|
186
|
+
},
|
|
187
|
+
// ─── Memory Effectiveness (S53B) ───────────────────────────────────────
|
|
188
|
+
/** GET /api/memory-status — Memory store aggregate statistics. */
|
|
189
|
+
memoryStatus: {
|
|
190
|
+
method: "GET",
|
|
191
|
+
path: "/api/memory-status",
|
|
192
|
+
description: "Memory store statistics: total count, 30-day window, top-N stable memories, avg recall score.",
|
|
193
|
+
},
|
|
194
|
+
/** GET /api/setup-status — Current embedder configuration. */
|
|
195
|
+
setupStatus: {
|
|
196
|
+
method: "GET",
|
|
197
|
+
path: "/api/setup-status",
|
|
198
|
+
description: "Current embedder configuration (which embedder is active, embedding URL, cache, MiniLM flag).",
|
|
199
|
+
},
|
|
200
|
+
/** GET /api/setup-detect — Detect available local embedder backends. */
|
|
201
|
+
setupDetect: {
|
|
202
|
+
method: "GET",
|
|
203
|
+
path: "/api/setup-detect",
|
|
204
|
+
description: "Best-effort detection of local embedder backends (ollama, llama.cpp, ONNX) available on the machine.",
|
|
205
|
+
},
|
|
206
|
+
/** POST /api/setup-configure — Write embedder config to .mega-compact.env. */
|
|
207
|
+
setupConfigure: {
|
|
208
|
+
method: "POST",
|
|
209
|
+
path: "/api/setup-configure",
|
|
210
|
+
description: "Write the chosen embedder configuration to .mega-compact.env (loaded at next startup). Returns whether a restart is required.",
|
|
211
|
+
},
|
|
212
|
+
// ─── RAPTOR tree (Part B) ───────────────────────────────────────
|
|
213
|
+
/** GET /api/raptor-tree — Hierarchical RAPTOR summary tree for a session. */
|
|
214
|
+
raptorTree: {
|
|
215
|
+
method: "GET",
|
|
216
|
+
path: "/api/raptor-tree",
|
|
217
|
+
description: "Hierarchical RAPTOR tree (summary nodes by level) for a session; defaults to the latest session with nodes.",
|
|
218
|
+
},
|
|
219
|
+
/** GET /api/embedder-health — Round-trip a test embed through the active embedder. */
|
|
220
|
+
embedderHealth: {
|
|
221
|
+
method: "GET",
|
|
222
|
+
path: "/api/embedder-health",
|
|
223
|
+
description: "Probe the active embedder with a test embed and report status, latency, dimensions, and masked URL.",
|
|
224
|
+
},
|
|
225
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,231 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* api-contracts/endpoints.ts — Central registry of all dashboard API endpoints.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Delegate-shell (extensions split): single source of truth for all dashboard
|
|
5
|
+
* API routes. The inline response types + game-types re-exports live in
|
|
6
|
+
* ./endpoints/types.ts and the ENDPOINTS object literal in ./endpoints/registry.ts;
|
|
7
|
+
* this pointer re-exports the full public surface unchanged.
|
|
7
8
|
*
|
|
8
9
|
* Sprint A1 — PREVENT-PI-004: zero network code (type definitions only).
|
|
9
10
|
* PREVENT-011: no `any` type — all types are explicit.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
// ─── Game Score & Achievement Types ─────────────────────────────────────────
|
|
13
|
-
// (moved to game-types.ts; re-exported for backwards compatibility)
|
|
14
|
-
// ─── Sessions Memory Graph (S39) ─────────────────────────────────────────
|
|
15
|
-
// (moved to game-types.ts; re-exported for backwards compatibility)
|
|
16
|
-
// ─── Game State Patch (PUT request body) ────────────────────────────────────
|
|
17
|
-
// (moved to game-types.ts; re-exported for backwards compatibility)
|
|
18
|
-
// ─── SSE Endpoint Definition ────────────────────────────────────────────────
|
|
19
|
-
// (moved to game-types.ts; re-exported for backwards compatibility)
|
|
20
|
-
// ─── ENDPOINTS Registry ─────────────────────────────────────────────────────
|
|
21
|
-
/**
|
|
22
|
-
* Central registry of all 14 dashboard API endpoints. Each entry is an
|
|
23
|
-
* `EndpointDef` or `SseEndpointDef` instance serving as the single source of
|
|
24
|
-
* truth for route paths, methods, descriptions, and typed request/response
|
|
25
|
-
* contracts.
|
|
26
|
-
*
|
|
27
|
-
* Usage:
|
|
28
|
-
* import { ENDPOINTS } from './api-contracts';
|
|
29
|
-
* ENDPOINTS.snapshot.path // '/api/snapshot'
|
|
30
|
-
* ENDPOINTS.snapshot.method // 'GET'
|
|
31
|
-
*/
|
|
32
|
-
export const ENDPOINTS = {
|
|
33
|
-
/** GET /api/snapshot — Full session, store, compression, and context snapshot. */
|
|
34
|
-
snapshot: {
|
|
35
|
-
method: "GET",
|
|
36
|
-
path: "/api/snapshot",
|
|
37
|
-
description: "Full session, store, compression, and context snapshot.",
|
|
38
|
-
},
|
|
39
|
-
/** GET /api/version — Dashboard server version string. */
|
|
40
|
-
version: {
|
|
41
|
-
method: "GET",
|
|
42
|
-
path: "/api/version",
|
|
43
|
-
description: "Dashboard server version for stale-server detection.",
|
|
44
|
-
},
|
|
45
|
-
/** GET /api/index — Multi-repo aggregate index (or fallback when unavailable). */
|
|
46
|
-
index: {
|
|
47
|
-
method: "GET",
|
|
48
|
-
path: "/api/index",
|
|
49
|
-
description: "Machine-wide multi-repo registry with checkpoints, tokens, and model info.",
|
|
50
|
-
},
|
|
51
|
-
/** GET /api/repos — Registry list with optional active-window filter. */
|
|
52
|
-
repos: {
|
|
53
|
-
method: "GET",
|
|
54
|
-
path: "/api/repos",
|
|
55
|
-
description: "Repo registry list, optionally filtered by recent activity.",
|
|
56
|
-
},
|
|
57
|
-
/** GET /api/summary — Lightweight header tiles without the full repo list. */
|
|
58
|
-
summary: {
|
|
59
|
-
method: "GET",
|
|
60
|
-
path: "/api/summary",
|
|
61
|
-
description: "Aggregate summary with active/total repo counts (no repo list).",
|
|
62
|
-
},
|
|
63
|
-
/** GET /api/drift — Cross-repo drift report. */
|
|
64
|
-
drift: {
|
|
65
|
-
method: "GET",
|
|
66
|
-
path: "/api/drift",
|
|
67
|
-
description: "Cross-repo drift report flagging stale repos, compaction lag, and model churn.",
|
|
68
|
-
},
|
|
69
|
-
/** GET /api/servers — Recently-active repo servers with live snapshot data. */
|
|
70
|
-
servers: {
|
|
71
|
-
method: "GET",
|
|
72
|
-
path: "/api/servers",
|
|
73
|
-
description: "Recently-active repo servers with live snapshot data.",
|
|
74
|
-
},
|
|
75
|
-
/** GET /api/events — SSE stream of dashboard events. */
|
|
76
|
-
events: {
|
|
77
|
-
type: "sse",
|
|
78
|
-
method: "GET",
|
|
79
|
-
path: "/api/events",
|
|
80
|
-
description: "Server-Sent Events stream of all dashboard events.",
|
|
81
|
-
event: "data",
|
|
82
|
-
},
|
|
83
|
-
/** GET /api/game-state — Current game-mode settings. */
|
|
84
|
-
getGameState: {
|
|
85
|
-
method: "GET",
|
|
86
|
-
path: "/api/game-state",
|
|
87
|
-
description: "Current game-mode configuration and active ritual state.",
|
|
88
|
-
},
|
|
89
|
-
/** PUT /api/game-state — Apply a partial patch to game-mode settings. */
|
|
90
|
-
putGameState: {
|
|
91
|
-
method: "PUT",
|
|
92
|
-
path: "/api/game-state",
|
|
93
|
-
description: "Apply a partial patch to game-mode settings and return the updated state.",
|
|
94
|
-
},
|
|
95
|
-
/** GET /api/game-scores — High-score leaderboard for a metric. */
|
|
96
|
-
gameScores: {
|
|
97
|
-
method: "GET",
|
|
98
|
-
path: "/api/game-scores",
|
|
99
|
-
description: "High-score leaderboard for a game metric.",
|
|
100
|
-
},
|
|
101
|
-
/** GET /api/perf — Rolling-window performance aggregates. */
|
|
102
|
-
perf: {
|
|
103
|
-
method: "GET",
|
|
104
|
-
path: "/api/perf",
|
|
105
|
-
description: "Rolling-window performance aggregates over perf_samples.",
|
|
106
|
-
},
|
|
107
|
-
/** GET /api/achievements — Achievement tiles with unlock state. */
|
|
108
|
-
achievements: {
|
|
109
|
-
method: "GET",
|
|
110
|
-
path: "/api/achievements",
|
|
111
|
-
description: "All achievement rows with unlock state.",
|
|
112
|
-
},
|
|
113
|
-
/** GET /api/sessions — Active sessions with latest token usage (S39). */
|
|
114
|
-
sessions: {
|
|
115
|
-
method: "GET",
|
|
116
|
-
path: "/api/sessions",
|
|
117
|
-
description: "Active pi sessions with latest token usage + heartbeat.",
|
|
118
|
-
},
|
|
119
|
-
/** GET /api/sessions/timeseries — Stacked per-session token timeseries (S39). */
|
|
120
|
-
sessionTimeseries: {
|
|
121
|
-
method: "GET",
|
|
122
|
-
path: "/api/sessions/timeseries",
|
|
123
|
-
description: "Recharts-ready per-session token timeseries for the stacked memory graph.",
|
|
124
|
-
},
|
|
125
|
-
/** GET /api/topics — Auto-categorizing wiki topics (S51). */
|
|
126
|
-
topics: {
|
|
127
|
-
method: "GET",
|
|
128
|
-
path: "/api/topics",
|
|
129
|
-
description: "Auto-categorized wiki topics from k-means + TF-IDF over real embeddings.",
|
|
130
|
-
},
|
|
131
|
-
/** GET /api/turns — Turn-by-turn memory tracking + recall (S52). */
|
|
132
|
-
turns: {
|
|
133
|
-
method: "GET",
|
|
134
|
-
path: "/api/turns",
|
|
135
|
-
description: "Per-conversation turn list with recall + epoch provenance (turn-by-turn memory tracking).",
|
|
136
|
-
},
|
|
137
|
-
/** GET /api/turns/conversation/:convId — per-turn detail + recall hits. */
|
|
138
|
-
conversationTurns: {
|
|
139
|
-
method: "GET",
|
|
140
|
-
path: "/api/turns/conversation/:convId",
|
|
141
|
-
description: "Per-turn metrics + injected-checkpoint recall provenance for one conversation.",
|
|
142
|
-
},
|
|
143
|
-
/** GET /api/turns/intents — pending rewind intents (S52A). */
|
|
144
|
-
turnIntents: {
|
|
145
|
-
method: "GET",
|
|
146
|
-
path: "/api/turns/intents",
|
|
147
|
-
description: "Pending rewind intents queued by the dashboard for the host to consume.",
|
|
148
|
-
},
|
|
149
|
-
/** POST /api/turns/intent — post a rewind intent. */
|
|
150
|
-
postTurnIntent: {
|
|
151
|
-
method: "POST",
|
|
152
|
-
path: "/api/turns/intent",
|
|
153
|
-
description: "Queue a rewind-to-turn-N intent for the host to apply at before_agent_start.",
|
|
154
|
-
},
|
|
155
|
-
/** POST /api/fork — fork a conversation at a turn. */
|
|
156
|
-
fork: {
|
|
157
|
-
method: "POST",
|
|
158
|
-
path: "/api/fork",
|
|
159
|
-
description: "Branch a child conversation off a parent turn + return the recall set to rehydrate.",
|
|
160
|
-
},
|
|
161
|
-
/** POST /api/turns/prune — admin prune (capability-gated). */
|
|
162
|
-
pruneTurns: {
|
|
163
|
-
method: "POST",
|
|
164
|
-
path: "/api/turns/prune",
|
|
165
|
-
description: "Prune old turns (admin capability — dashboard uses asAdmin()).",
|
|
166
|
-
},
|
|
167
|
-
/** GET /api/topics/:topicId/memories — wiki topic drill-down (S52). */
|
|
168
|
-
topicMemories: {
|
|
169
|
-
method: "GET",
|
|
170
|
-
path: "/api/topics/:topicId/memories",
|
|
171
|
-
description: "Member memories assigned to a wiki topic (drill-down).",
|
|
172
|
-
},
|
|
173
|
-
// ─── S49B Maintenance Tab ─────────────────────────────────────────
|
|
174
|
-
/** GET /api/maintenance — DB stats (table row counts + storage). */
|
|
175
|
-
maintenanceStats: {
|
|
176
|
-
method: "GET",
|
|
177
|
-
path: "/api/maintenance",
|
|
178
|
-
description: "SQLite table row counts, storage stats, and DB file sizes.",
|
|
179
|
-
},
|
|
180
|
-
/** GET /api/maintenance/schema-health — Schema version + integrity audit. */
|
|
181
|
-
schemaHealth: {
|
|
182
|
-
method: "GET",
|
|
183
|
-
path: "/api/maintenance/schema-health",
|
|
184
|
-
description: "SCHEMA_VERSION, PRAGMA integrity_check, FK check, and per-column audit.",
|
|
185
|
-
},
|
|
186
|
-
/** POST /api/maintenance/action — Trigger a maintenance action. */
|
|
187
|
-
maintenanceAction: {
|
|
188
|
-
method: "POST",
|
|
189
|
-
path: "/api/maintenance/action",
|
|
190
|
-
description: "Run vacuum, checkpoint, reindex, fts5-rebuild, reconcile-dedup, prune, or integrity-check.",
|
|
191
|
-
},
|
|
192
|
-
// ─── Provider Cache (Sprint A.2) ─────────────────────────────────
|
|
193
|
-
/** GET /api/provider-cache — Lifetime provider prompt cache aggregates + $ savings. */
|
|
194
|
-
providerCache: {
|
|
195
|
-
method: "GET",
|
|
196
|
-
path: "/api/provider-cache",
|
|
197
|
-
description: "Lifetime provider prompt cache hit-rate aggregates + dollar savings estimate.",
|
|
198
|
-
},
|
|
199
|
-
// ─── A3 Cache Stripes (PLAN_V2 Phase 4) ───────────────────────────
|
|
200
|
-
/** GET /api/cache-stripes — Per-stripe distribution + health score. */
|
|
201
|
-
cacheStripes: {
|
|
202
|
-
method: "GET",
|
|
203
|
-
path: "/api/cache-stripes",
|
|
204
|
-
description: "Per-stripe distribution counts, average stability scores, and composite cache health.",
|
|
205
|
-
},
|
|
206
|
-
// ─── Memory Effectiveness (S53B) ───────────────────────────────────────
|
|
207
|
-
/** GET /api/memory-status — Memory store aggregate statistics. */
|
|
208
|
-
memoryStatus: {
|
|
209
|
-
method: "GET",
|
|
210
|
-
path: "/api/memory-status",
|
|
211
|
-
description: "Memory store statistics: total count, 30-day window, top-N stable memories, avg recall score.",
|
|
212
|
-
},
|
|
213
|
-
/** GET /api/setup-status — Current embedder configuration. */
|
|
214
|
-
setupStatus: {
|
|
215
|
-
method: "GET",
|
|
216
|
-
path: "/api/setup-status",
|
|
217
|
-
description: "Current embedder configuration (which embedder is active, embedding URL, cache, MiniLM flag).",
|
|
218
|
-
},
|
|
219
|
-
/** GET /api/setup-detect — Detect available local embedder backends. */
|
|
220
|
-
setupDetect: {
|
|
221
|
-
method: "GET",
|
|
222
|
-
path: "/api/setup-detect",
|
|
223
|
-
description: "Best-effort detection of local embedder backends (ollama, llama.cpp, ONNX) available on the machine.",
|
|
224
|
-
},
|
|
225
|
-
/** POST /api/setup-configure — Write embedder config to .mega-compact.env. */
|
|
226
|
-
setupConfigure: {
|
|
227
|
-
method: "POST",
|
|
228
|
-
path: "/api/setup-configure",
|
|
229
|
-
description: "Write the chosen embedder configuration to .mega-compact.env (loaded at next startup). Returns whether a restart is required.",
|
|
230
|
-
},
|
|
231
|
-
};
|
|
12
|
+
export { ENDPOINTS } from "./endpoints/registry.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/raptor.ts — RAPTOR tree API contract.
|
|
3
|
+
*
|
|
4
|
+
* Response shape for GET /api/raptor-tree: the hierarchical RAPTOR tree
|
|
5
|
+
* (summary nodes by level) for a session. Client-safe — the raw 512-dim
|
|
6
|
+
* embedding vector is stripped before sending.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared runtime-helpers for the api-contracts split test files.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from api-contracts.test.ts so each per-endpoint describe file can
|
|
5
|
+
* reuse the same field/type assertion primitives without duplicating them.
|
|
6
|
+
* Only runtime helpers live here — compile-time `satisfies` checks and the
|
|
7
|
+
* ENDPOINTS registry assertions stay in endpoints-registry.test.ts.
|
|
8
|
+
*/
|
|
9
|
+
import assert from "node:assert/strict";
|
|
10
|
+
/** Primitive type name from a JSON-parsed value (matches typeof for JSON types). */
|
|
11
|
+
export function primitiveType(v) {
|
|
12
|
+
if (v === null)
|
|
13
|
+
return "null";
|
|
14
|
+
if (Array.isArray(v))
|
|
15
|
+
return "array";
|
|
16
|
+
return typeof v;
|
|
17
|
+
}
|
|
18
|
+
/** Assert that a field exists on an object and has one of the expected primitive types. */
|
|
19
|
+
export function assertField(obj, field, expected) {
|
|
20
|
+
assert.ok(field in obj, `field "${field}" must exist`);
|
|
21
|
+
const actual = primitiveType(obj[field]);
|
|
22
|
+
assert.ok(expected.includes(actual), `field "${field}" expected type ${expected.join("|")}, got ${actual}`);
|
|
23
|
+
}
|
|
24
|
+
/** Assert that a nested object field exists and is an object (or null if allowed). */
|
|
25
|
+
export function assertObject(obj, field, allowNull = false) {
|
|
26
|
+
assert.ok(field in obj, `field "${field}" must exist`);
|
|
27
|
+
const val = obj[field];
|
|
28
|
+
if (allowNull && val === null)
|
|
29
|
+
return null;
|
|
30
|
+
assert.equal(primitiveType(val), "object", `field "${field}" must be an object${allowNull ? " or null" : ""}`);
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared harness + types for the routes-cache split files.
|
|
3
|
+
* Extracted from routes-cache.test.ts: spawn-and-fetch server harness + DTOs.
|
|
4
|
+
*/
|
|
5
|
+
import { mkdtempSync, rmSync, readFileSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
const SERVER_ENTRY = new URL("../server.js", import.meta.url).pathname;
|
|
10
|
+
export function waitFor(cond, timeoutMs = 6000) {
|
|
11
|
+
const start = Date.now();
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const tick = async () => {
|
|
14
|
+
if (await cond())
|
|
15
|
+
return resolve();
|
|
16
|
+
if (Date.now() - start > timeoutMs)
|
|
17
|
+
return reject(new Error("timeout"));
|
|
18
|
+
setTimeout(tick, 50);
|
|
19
|
+
};
|
|
20
|
+
tick();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function freshDir(prefix) {
|
|
24
|
+
return mkdtempSync(join(tmpdir(), prefix));
|
|
25
|
+
}
|
|
26
|
+
export async function withServer(port, dir, fn) {
|
|
27
|
+
process.env.MEGACOMPACT_DASHBOARD_PORT = port;
|
|
28
|
+
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
29
|
+
try {
|
|
30
|
+
await waitFor(async () => {
|
|
31
|
+
try {
|
|
32
|
+
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
33
|
+
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
34
|
+
return res.ok;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
41
|
+
return await fn(raw.port);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
child.kill("SIGTERM");
|
|
45
|
+
delete process.env.MEGACOMPACT_DASHBOARD_PORT;
|
|
46
|
+
rmSync(dir, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-embedder-health.ts — Embedder health probe route.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/embedder-health — Round-trips a test embed through the active
|
|
5
|
+
* embedder and reports reachability + latency + dimensions.
|
|
6
|
+
*
|
|
7
|
+
* PREVENT-PI-004: probes the active embedder, which is either the built-in
|
|
8
|
+
* TrigramEmbedder (pure local math) or the HttpEmbedder pointed at a
|
|
9
|
+
* user-spawned localhost server — the existing audited loopback exception
|
|
10
|
+
* (see httpEmbedder.ts). No new network paths are introduced here.
|
|
11
|
+
*/
|
|
12
|
+
import { performance } from "node:perf_hooks";
|
|
13
|
+
import { detectCurrentEmbedder } from "./routes-setup.js";
|
|
14
|
+
import { defaultEmbedder } from "../../src/embedder.js";
|
|
15
|
+
/** Mask an embedding URL down to scheme://hostname:port, stripping path +
|
|
16
|
+
* any embedded credentials. Returns null when the env URL is unset/empty. */
|
|
17
|
+
function maskEmbeddingUrl() {
|
|
18
|
+
const raw = process.env["MEGACOMPACT_EMBEDDING_URL"];
|
|
19
|
+
if (!raw || raw.trim().length === 0)
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const u = new URL(raw);
|
|
23
|
+
return `${u.protocol}//${u.hostname}${u.port ? `:${u.port}` : ""}`;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function handleEmbedderHealth(req, res, _ctx) {
|
|
30
|
+
if (req.url !== "/api/embedder-health")
|
|
31
|
+
return false;
|
|
32
|
+
if (req.method !== "GET") {
|
|
33
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
34
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
35
|
+
res.end(JSON.stringify({ error: "method_not_allowed" }));
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const activeEmbedder = detectCurrentEmbedder();
|
|
39
|
+
const url = maskEmbeddingUrl();
|
|
40
|
+
let status = "ok";
|
|
41
|
+
let dim = 0;
|
|
42
|
+
let error;
|
|
43
|
+
const start = performance.now();
|
|
44
|
+
try {
|
|
45
|
+
const embedder = defaultEmbedder();
|
|
46
|
+
embedder.embed("mega-compact health probe");
|
|
47
|
+
dim = embedder.dim;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
51
|
+
status = /unreachable/i.test(msg) ? "unreachable" : "error";
|
|
52
|
+
error = msg;
|
|
53
|
+
}
|
|
54
|
+
const latencyMs = performance.now() - start;
|
|
55
|
+
const body = {
|
|
56
|
+
activeEmbedder,
|
|
57
|
+
status,
|
|
58
|
+
latencyMs,
|
|
59
|
+
dim,
|
|
60
|
+
url,
|
|
61
|
+
...(error !== undefined ? { error } : {}),
|
|
62
|
+
};
|
|
63
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
64
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
65
|
+
res.end(JSON.stringify(body));
|
|
66
|
+
return true;
|
|
67
|
+
}
|