import { Fragment } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { GlassCard, Notice, Tag, domainOf } from './primitives'; /** * A finished research report: the markdown body with live [n] citation markers, the * numbered sources panel they jump to, the contradictions callout, and a collapsible * telemetry footer. */ export default function ReportView({ result, savedToHistory }) { const contradictions = result.fact_check?.contradictions || []; const sources = result.sources || []; // The writer occasionally returns nothing usable. Saying so is better than presenting // an empty card as though it were the finished report; the retrieved sources below are // still real and still worth showing. const hasReport = Boolean((result.report || '').trim()); return (
Research report

{result.query}

{savedToHistory && Saved to history} {result.is_fallback && Fallback mode}
{result.is_fallback && (

One of the agents fell back to its simpler backup method for this run, so parts of this report are less detailed than usual. The findings and sources below are still the real result of the run.

)}
{hasReport ? (
{result.report}
) : ( The first four agents finished, but the writer returned no text for this run. The sources it gathered are listed below, and running the question again usually produces a full report. )}
{contradictions.length > 0 && } {sources.length > 0 && }
); } /* ===== Contradictions ======================================================= */ function ContradictionsCallout({ contradictions }) { return (

These sources disagree with each other. The fact-checker cross-references what sources claim; it cannot decide which of them is right.

{contradictions.map((item, index) => (
{item.topic}
{item.conflict}
{item.conflicting_sources?.length > 0 && (
Sources{' '} {item.conflicting_sources.map((id, i) => ( {i > 0 && ', '} {id} ))}
)}
))}
); } /* ===== Sources ============================================================== */ function SourcesPanel({ sources }) { return (
Sources

{sources.length} source{sources.length === 1 ? '' : 's'} retrieved for this report.

{sources.map((source) => (
{source.index}
{source.title || 'Untitled source'} {domainOf(source.url)} {source.excerpt &&

{source.excerpt}…

}
))}
); } /* ===== Telemetry ============================================================ */ function TelemetryFooter({ telemetry }) { if (!telemetry) return null; const usage = telemetry.usage || {}; // Per-step timings are only available on a live run; a report reloaded from history // carries the total and the token count, so absent rows are simply dropped. const rows = [ ['Planning', telemetry.planning_time_sec], ['Search', telemetry.search_time_sec], ['Summarizing', telemetry.summarization_time_sec], ['Fact-checking', telemetry.fact_check_time_sec], ['Writing', telemetry.synthesis_time_sec], ['Total time', telemetry.total_time_sec], ] .filter(([, value]) => value !== undefined && value !== null) .map(([label, value]) => [label, `${value}s`]); rows.push(['Tokens used', (usage.total_tokens ?? 0).toLocaleString()]); return (
Run details · {telemetry.total_time_sec}s · {(usage.total_tokens ?? 0).toLocaleString()} tokens
{rows.map(([label, value]) => (
{label} {value}
))}
); } /* ===== Markdown rendering =================================================== */ const CITATION_PATTERN = /(\[\d{1,3}\])/g; /** * Turns inline [1][2] markers in the report body into anchors that scroll down to the * matching numbered entry in the Sources panel. */ function linkCitations(children) { return children.map((child, index) => { if (typeof child !== 'string') return {child}; const parts = child.split(CITATION_PATTERN); return ( {parts.map((part, partIndex) => { const match = /^\[(\d{1,3})\]$/.exec(part); if (!match) return {part}; return ( {match[1]} ); })} ); }); } function withCitations(element) { const Element = element; return function Renderer({ children, ...rest }) { return {linkCitations(Array.isArray(children) ? children : [children])}; }; } const markdownComponents = { p: withCitations('p'), li: withCitations('li'), td: withCitations('td'), a: ({ children, href, ...rest }) => ( {children} ), };