"use client"; import { useCallback, useEffect, useState } from "react"; import { AlertTriangle, BookText, ChevronLeft, FileText, RefreshCw, Unlink } from "lucide-react"; import { wikiEntities, wikiEntity, wikiLint, type WikiPageSummary, type WikiPageDetail, type WikiLint } from "@/lib/api"; import { Markdown } from "@/components/Markdown"; function stripFrontmatter(md: string): string { if (md.startsWith("---")) { const end = md.indexOf("\n---", 3); if (end !== -1) return md.slice(end + 4).replace(/^\n+/, ""); } return md; } /** * Compounding Wiki inspector: browse the durable, LLM-synthesized entity pages * built from the knowledge graph at ingest. Master list → page detail. Shows a * clear disabled/empty state when the wiki layer is off or unpopulated. */ export function WikiPanel({ refreshKey }: { refreshKey?: number }) { const [state, setState] = useState<{ enabled: boolean; count: number; pages: WikiPageSummary[] }>({ enabled: false, count: 0, pages: [], }); const [loading, setLoading] = useState(true); const [selected, setSelected] = useState(null); const [loadingPage, setLoadingPage] = useState(false); const [lint, setLint] = useState(null); const load = useCallback(() => { setLoading(true); wikiEntities() .then(setState) .catch(() => {}) .finally(() => setLoading(false)); wikiLint().then(setLint).catch(() => {}); }, []); useEffect(() => { load(); }, [load, refreshKey]); const open = (id: string) => { setLoadingPage(true); wikiEntity(id) .then(setSelected) .catch(() => {}) .finally(() => setLoadingPage(false)); }; // ---- detail view ---- if (selected) { return (

{selected.title || selected.id}

{selected.mentions} mentions {selected.sources.length} source{selected.sources.length === 1 ? "" : "s"} {selected.updated && updated {selected.updated.slice(0, 10)}}
); } // ---- list view ---- return (

Compounding Wiki {state.enabled && {state.count}}

{state.enabled && lint && (lint.contradiction_count > 0 || lint.orphan_pages.length > 0) && (
{lint.contradiction_count > 0 && ( {lint.contradiction_count} contradiction {lint.contradiction_count === 1 ? "" : "s"} flagged )} {lint.orphan_pages.length > 0 && ( {lint.orphan_pages.length} orphan {lint.orphan_pages.length === 1 ? "" : "s"} )}
)} {!state.enabled ? (
The compounding wiki is off. Enable it with{" "} AURALYNQ_WIKI__ENABLED=true{" "} and re-ingest — Auralynq will synthesize durable, cited entity pages from the knowledge graph.
) : state.pages.length === 0 ? (
No wiki pages yet. Ingest documents and Auralynq will compile entity pages here.
) : (
    {state.pages.map((p) => (
  • ))}
)} {loadingPage &&
Loading page…
}
); }