import { Hono } from "hono";
import type { JobStore } from "./jobs.js";
import { advanceJob, overallStatus } from "./stages.js";
export function renderIndexHtml(store: JobStore): string {
const rows = store
.list()
.map((j) => {
advanceJob(j);
return `
| ${j.id} | ${j.video_url} | ${j.question} | ${overallStatus(j)} |
`;
})
.join("");
return `video jobs
video understanding jobs
| id | video | question | status |
${rows}
JSON: /jobs, single job: /job/<id>
`;
}
export function buildApp(store: JobStore): Hono {
const app = new Hono();
app.get("/", (c) => c.html(renderIndexHtml(store)));
app.get("/jobs", (c) => c.json({ jobs: store.summaries() }));
app.get("/job/:id", (c) => {
const id = c.req.param("id");
const body = store.detail(id);
if (!body) return c.json({ error: "job not found", id }, 404);
return c.json(body);
});
return app;
}