import { readFileSync } from "node:fs"; /** * POST /api/rectification/agent as source text: route.ts (Supabase clients * and assembly) plus the branch modules it was split into * (TASK-rectification-code-split-20260926). A whole-source contract that held * on route.ts before the split holds on this concatenation after it, because * the code is the same code in more files. Slices between two anchors that * no longer sit in one file are rewritten per test. */ export const rectificationAgentRouteFiles = [ "../src/app/api/rectification/agent/route.ts", "../src/lib/rectification-agentic/v9/agent-route-support.ts", "../src/lib/rectification-agentic/v9/agent-route-request.ts", "../src/lib/rectification-agentic/v9/agent-route-structured-choice.ts", "../src/lib/rectification-agentic/v9/agent-route-typed-message.ts", "../src/lib/rectification-agentic/v9/agent-route-agent-turn.ts", "../src/lib/rectification-agentic/v9/agent-route-billing.ts", ] as const; export function readRectificationAgentRouteFile(relativePath: (typeof rectificationAgentRouteFiles)[number]): string { return readFileSync(new URL(relativePath, import.meta.url), "utf8"); } export const rectificationAgentRouteSurface = rectificationAgentRouteFiles .map((relativePath) => readRectificationAgentRouteFile(relativePath)) .join("\n"); /** * The typed-message fast path as it stood in route.ts between * `if (action === "message")` and `const requestTime`: the focus preflight, * the immediate-response exit, the unfocused classification and the deferred * replay. After the split the same code sits in agent-route-typed-message.ts, * the tail of route.ts, and the head of agent-route-agent-turn.ts. */ export function rectificationTypedMessageFastPath(): string { const route = readRectificationAgentRouteFile("../src/app/api/rectification/agent/route.ts"); const agentTurn = readRectificationAgentRouteFile("../src/lib/rectification-agentic/v9/agent-route-agent-turn.ts"); const routeStart = route.indexOf('if (action === "message")'); const turnEnd = agentTurn.indexOf("const requestTime"); if (routeStart < 0 || turnEnd < 0) throw new Error("typed-message fast path markers moved"); return [ readRectificationAgentRouteFile("../src/lib/rectification-agentic/v9/agent-route-typed-message.ts"), route.slice(routeStart), agentTurn.slice(0, turnEnd), ].join("\n"); }