Move-only (TASK-rectification-code-split-20260926 T2/T4). No behavior, API, copy, DB, Skill, billing or scoring change. - route.ts: 1077 -> 152 lines; POST 927 -> 114. It builds the Supabase clients (so the setup-failure mapping stays here) and assembles: agent-route-request.ts (auth / product / schema / flag / Case-Session binding), agent-route-typed-message.ts (declared-window reply, typed-answer preflight, unfocused classification), agent-route-structured-choice.ts, agent-route-agent-turn.ts (opening / read-only / typed agent stream and its exit gate), agent-route-billing.ts, agent-route-support.ts (schema, one-shot NDJSON reply, context types). - The four mutable preflight lets (expectedWrite, collectIntent, writeClassified, classifierDiagnostic) that crossed branches are one turnState object; values and flow unchanged. - Tests: whole-source contracts read tests/rectification-agent-route-surface.ts; the typed fast-path slice is rebuilt from the new files; billing, declared-window and structured-choice slices now call the handlers (billing in a child process because feature-pricing imports server-only), each with 原值/新值/原因. Route growth caps added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
48 lines
2.3 KiB
TypeScript
48 lines
2.3 KiB
TypeScript
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");
|
|
}
|