import { useState } from "react"; import { Link, useParams } from "react-router"; import { api, type ApiDetail as AD, type Project } from "../api"; import { useFetch, fmtDate, short } from "../hooks"; import { Badge, Bool, Empty, ErrorBox, JobStatus, JsonTree, KV, Loading, Tabs, Td } from "../components/ui"; import { DebtTable, EndpointRow, EvidenceList, LifecycleButtons } from "../components/shared"; export default function ApiDetail() { const { id } = useParams(); const { data, error, loading, reload } = useFetch(`apis/${id}`); const projects = useFetch<{ projects: Project[] }>("projects"); const [tab, setTab] = useState("Endpoints"); const [driftJob, setDriftJob] = useState(null); if (loading) return ; if (error) return ; if (!data) return null; const a = data; const projs = projects.data?.projects.map((p) => ({ slug: p.slug, name: `${p.name} (${p.policy_mode})` })) ?? [{ slug: "default", name: "default" }]; return (

{a.name} {a.opaque_internal_implementation && }

{a.provider_name} · {a.kind} ·
{a.current_version_id && }
{a.base_url ?? "—"}], ["Docs", a.docs_url ? {a.docs_url} : "—"], ["Auth", {JSON.stringify(a.auth_scheme)}], ["Provider license", (a.provider_license?.name as string) ?? ], ["Snapshots", (a.provider_license?.snapshots as string) ?? "metadata_only"], ["Description", a.description ?? "—"], ["Tags", a.tags.join(", ") || "—"], ["Current version", a.current_version_id ? {short(a.current_version_id)} : "—"], ["Created", fmtDate(a.created_at)]]} />

Lifecycle transitions (state machine enforced server-side; evidence required for tested/registered)

{ await api(`apis/${a.id}/lifecycle`, { body: { to, reason } }); reload(); }} />
{tab === "Endpoints" && (a.endpoints?.length ?
{a.endpoints.map((e) => )}
: No endpoints in the current version.)} {tab === "Variables" && (a.variables?.length ? {a.variables.map((v) => )}
NamePathTypeUnitConceptDescription
{v.name}{v.json_path}{v.data_type}{v.unit ?? "—"}{v.semantic_concept ?? "—"}{v.description}
: No variables extracted.)} {tab === "Versions" && {a.versions.map((v) => )}
VersionLifecycleSourceEndpointsContract hashCreated
{v.version}{v.id === a.current_version_id && }{v.source_kind}{v.source_url &&
{v.source_url}
}
{v.endpoints}{short(v.contract_hash, 16)}{fmtDate(v.created_at)}
} {tab === "Packages" && (a.packages.length ? {a.packages.map((k) => )}
AKPVersionLifecycleKnowledgeHashCredentialCreated
{k.akp_id}{k.superseded_by && }v{k.version}{short(k.hash, 12)}{fmtDate(k.created_at)}
: No knowledge package compiled yet.)} {tab === "Evidence" && } {tab === "Debt" && } {tab === "Drift" && (a.drift.length ?
{a.drift.map((d) =>
{d.kind} {fmtDate(d.detected_at)} · affected projects {d.affected_projects.length}
)}
: No drift alerts.)} {tab === "Executions" && (a.executions.length ? {a.executions.map((e) => )}
WhenStateModeRequestStatusms
{fmtDate(e.created_at)}{e.policy_mode}{e.method} {e.url}{e.status_code ?? "—"}{e.duration_ms ?? "—"}
: No executions for this API.)}
); }