Open History to see the last commit
1import { createFileRoute } from '@tanstack/react-router'
2import { runs } from '../run-durable'
3
4/**
5 * "Which run is still going for this thread?" — the reload story's first hop.
6 * A freshly loaded page has no `Last-Event-ID`, so it resolves the live run
7 * from the STABLE `threadId` and then rejoins it via `GET /api/run` (the
8 * client's `joinRun` does both automatically when chat persistence is on).
9 */
10export const Route = createFileRoute('/api/run/active')({
11 server: {
12 handlers: ({ createHandlers }) =>
13 createHandlers({
14 GET: {
15 handler: async ({ request }) => {
16 const threadId = new URL(request.url).searchParams.get('threadId')
17 if (threadId === null) {
18 return new Response('threadId is required', { status: 400 })
19 }
20 const active = await runs.findActiveRun(threadId)
21 return Response.json({ runId: active?.runId ?? null })
22 },
23 },
24 }),
25 },
26})