Download src/app/api/cron/reflector/route.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/cron/reflector/route.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/app/api/cron/reflector/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/cron/reflector/route.ts
1.61 kB
| import { NextRequest, NextResponse } from "next/server"; | |
| import { writeFile } from "fs/promises"; | |
| import { join } from "path"; | |
| import { runReflector } from "@/lib/judge/reflector"; | |
| const PROPOSALS_PATH = join( | |
| process.cwd(), | |
| "src/lib/judge/reflector-proposals.json", | |
| ); | |
| /** | |
| * POST /api/cron/reflector | |
| * | |
| * Designed to be called by an external cron job every ~2 days. | |
| * Runs the full reflector pipeline: | |
| * 1. Detect judge/human score divergence via LangSmith | |
| * 2. Analyze patterns and propose rubric changes via Claude | |
| * 3. Store output to reflector-proposals.json | |
| * | |
| * Does NOT auto-apply changes — human approval is required via | |
| * POST /api/judge/reflector. | |
| * | |
| * Expects a CRON_SECRET header for authentication. | |
| */ | |
| export async function POST(request: NextRequest) { | |
| const secret = request.headers.get("x-cron-secret"); | |
| if (!process.env.CRON_SECRET || secret !== process.env.CRON_SECRET) { | |
| return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | |
| } | |
| try { | |
| const output = await runReflector(); | |
| await writeFile( | |
| PROPOSALS_PATH, | |
| JSON.stringify(output, null, 2) + "\n", | |
| ); | |
| return NextResponse.json({ | |
| success: true, | |
| divergenceCases: output.divergenceCases.length, | |
| proposedChanges: output.proposedChanges.length, | |
| timestamp: output.timestamp, | |
| }); | |
| } catch (err) { | |
| const message = err instanceof Error ? err.message : String(err); | |
| console.error(`[cron/reflector] Failed: ${message}`); | |
| return NextResponse.json( | |
| { error: "Reflector run failed", details: message }, | |
| { status: 500 }, | |
| ); | |
| } | |
| } | |