The background extraction pipeline is invisible on the home surface — essential observability per the user's directive: the graph view must show what is currently running (extracting / auditing / merging) and for which chat. - extraction.ts: module-level registry of in-flight runs (chatId, phase, startedAt), updated at each phase transition in runExtraction and cleared in finally (done or failed). extractionStatuses() is the read; one process, one registry. - GET /api/graph/status: thin transport over the registry, chat titles joined from the chat store. - graph-view: polls every 2s and shows one chip per running pipeline (spinner + phase + title + elapsed seconds, bottom-left); when a run finishes (some -> none) the graph refetches, so merges land live. Status is cosmetic — poll errors never surface. - Unit test drives a mocked pipeline run and observes the registry mid-flight: 'extracting' during the extractor's generate, 'auditing' during the auditor's, empty after.
22 lines
780 B
TypeScript
22 lines
780 B
TypeScript
/**
|
|
* GET /api/graph/status — the in-flight background extraction runs
|
|
* (vision §1: the pipeline status must be visible on the home graph).
|
|
* Thin transport over the pipeline's module-level registry: phase
|
|
* (extracting / auditing / merging) per chat, oldest first. Titles joined
|
|
* from the chat store; a missing chat record still reports the run.
|
|
*/
|
|
import { extractionStatuses } from "@/src/agent/subagents/extraction.ts";
|
|
import { chatStore } from "@/src/store/chats.ts";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET() {
|
|
const runs = extractionStatuses().map((run) => ({
|
|
chatId: run.chatId,
|
|
title: chatStore.getChat(run.chatId)?.title ?? run.chatId,
|
|
phase: run.phase,
|
|
startedAt: run.startedAt,
|
|
}));
|
|
return Response.json({ runs });
|
|
}
|