/** * Read-only queries powering the /dashboard HTML endpoint. * Extracted here so tests can exercise them independently of the route layer. */ import type { DB } from '../../storage/db.js'; import { type UsefulnessRate } from '../../storage/usefulness.js'; import type { HealthState } from '../health-state.js'; export interface MemoryCountByType { type: string; count: number; } export interface RecentMemory { id: string; type: string; text: string; importance: number; confidence: number; session_id: string | null; created_at: number; /** `memories.project` — nullable, rendered as '—' when absent. */ project: string | null; /** Best-effort extraction-profile provenance — see * `queryExtractProfilesBySession`'s doc comment for exactly what this is * (and is not) derived from. `null` when session_id is null, no * transcript row exists for that session, or the envelope never set * extract_profile. */ profile: string | null; } export interface JobStateCount { state: string; count: number; } /** FEAT-410: job counts grouped by (kind, state) — distinguishes e.g. * distill:poison=2 from reembed:poison=1, which the state-only * `queryJobStates` cannot. */ export interface JobStateByKind { kind: string; state: string; count: number; } /** FEAT-410: pending consolidation-proposal count + oldest created_at. */ export interface ConsolidationSummary { count: number; oldest: number | null; } /** FEAT-410: a failed/poison job row with its error text, for the * "what failed and why" surface. */ export interface RecentFailedJob { id: string; kind: string; state: string; last_error: string | null; updated_at: number; } /** FEAT-410: entity-linking pipeline-stage visibility. */ export interface EntityLinkage { entityCount: number; unlinkedMemoryCount: number; } /** FEAT-410: subsystem health rolled up from the boot-time HealthState — * reuses the same instance /health reads instead of recomputing anything. */ export interface DashboardHealth { status: ReturnType; uptimeSeconds: number; embed: { ok: boolean | null; lastOkAt: number | null; lastError: string | null; attempts: number; }; worker: { alive: boolean; lastTickAt: number | null; lastTickAgoMs: number | null; }; diskFreeBytes: number | null; } export interface HourlyThroughput { hour: string; count: number; } export interface BudgetSpendRow { day: string; usd_total: number; calls: number; } export interface DashboardData { memoryCounts: MemoryCountByType[]; recentMemories: RecentMemory[]; jobStates: JobStateCount[]; jobStatesByKind: JobStateByKind[]; hourlyThroughput: HourlyThroughput[]; todaySpend: BudgetSpendRow | null; mtdSpend: number; mtdCalls: number; usefulness: UsefulnessRate; consolidation: ConsolidationSummary; recentFailedJobs: RecentFailedJob[]; entityLinkage: EntityLinkage; /** null when no HealthState was wired in (e.g. bare test apps) — callers * degrade the same way /health does when this field is absent. */ health: DashboardHealth | null; /** project/profile filters actually applied to `recentMemories` this * render — echoed back so the renderer can mark the active `` * dropdowns — independent of `recentMemories`' own LIMIT 25 window so an * option doesn't disappear just because its rows fell off the recent * window. */ filterOptions: { projects: string[]; profiles: string[]; }; } /** * project/profile filter state for the recent-memories listing. * `undefined` = no filter on that dimension (matches everything). * `null` = the '—'/"none" filter option — match rows where the value is * NULL/undeterminable (no `memories.project`, or no derivable profile). * A `string` = exact match on that value. */ export interface MemoryListFilters { project?: string | null; profile?: string | null; } /** Query-param sentinel for "match NULL/undeterminable rows" — the '—' * option in the filter ``. * Independent of the LIMIT 25 recent-memories window. */ export declare function queryProjectOptions(db: DB): string[]; /** Distinct `transcripts.extract_profile` values, for populating the filter * `