返回 CodeWhale
route.ts
根目录 / web / app / api / facts / route.ts
1 import { NextResponse } from "next/server";
2 import { releaseView } from "@/lib/capabilities";
3 import { BUILD_FACTS, getFactsWithProvenance, type RepoFacts } from "@/lib/facts";
4 import { cloudFactsSummary } from "@/lib/cloud-facts";
5 import { getEnv } from "@/lib/kv";
6 import { liveRecord } from "@/lib/repo-activity";
7
8 export const dynamic = "force-dynamic";
9 export const revalidate = 0;
10
11 function summary(facts: RepoFacts) {
12 return {
13 generatedAt: facts.generatedAt,
14 sourceRevision: facts.sourceRevision,
15 sourceCommittedAt: facts.sourceCommittedAt,
16 version: facts.version,
17 providerCount: facts.providers.length,
18 modelCount: facts.models.length,
19 toolCount: facts.toolCount,
20 contributorCount: facts.contributorCount,
21 };
22 }
23
24 /** Public, credential-free source/deployment drift receipt. */
25 export async function GET() {
26 const resolution = await getFactsWithProvenance();
27 // Additive: the cloud facts channel currently served by /api/facts/v1/stable
28 // (null when unconfigured or unverifiable), so deployed-facts checks can
29 // later assert served == published.
30 const cloudFacts = await cloudFactsSummary(await getEnv());
31 return NextResponse.json(
32 {
33 schemaVersion: 1,
34 deployed: summary(BUILD_FACTS),
35 resolved: {
36 ...summary(resolution.facts),
37 source: resolution.source,
38 reason: resolution.reason,
39 },
40 latestPublishedRelease: resolution.facts.latestPublishedRelease,
41 releaseCounts: releaseView(resolution.facts).counts,
42 cloudFacts,
43 liveRecord: liveRecord(),
44 },
45 {
46 headers: {
47 "Cache-Control": "no-store",
48 },
49 },
50 );
51 }
52
52 lines TYPESCRIPT