"use client"; import { useState } from "react"; interface ResearchState { question: string; phase: string; status: string; plan: Array<{ id: number; question: string; status: string; }>; current_question_index: number; current_search: { query: string; type: string; results?: Array<{ chunk: string; score: number; source: string; expanded: boolean; }>; } | null; insights: Array<{ summary: string; confidence: number; sources: string[]; }>; confidence: number; final_report: { title: string; summary: string; findings: string[]; conclusions: string[]; sources: string[]; } | null; } interface StateDisplayProps { state: ResearchState; } export default function StateDisplay({ state }: StateDisplayProps) { const [expandedSections, setExpandedSections] = useState< Record >({ plan: true, search: true, insights: true, report: true, }); const toggleSection = (section: string) => { setExpandedSections((prev) => ({ ...prev, [section]: !prev[section], })); }; // Phase indicator const phases = [ "idle", "planning", "searching", "analyzing", "evaluating", "done", ]; const currentPhaseIndex = phases.indexOf(state.phase); return (

Research State

{/* Phase Progress */}
Progress
{phases.slice(1).map((phase, idx) => (
{phase}
{idx < phases.length - 2 && (
)}
))}
{/* Question */} {state.question && (
Question
{state.question}
)} {/* Confidence Meter */} {state.confidence > 0 && (
Confidence
0.8 ? "#48bb78" : state.confidence > 0.5 ? "#ed8936" : "#f56565", transition: "width 0.3s ease", }} />
0.8 ? "#48bb78" : state.confidence > 0.5 ? "#ed8936" : "#f56565", }} > {(state.confidence * 100).toFixed(0)}%
)} {/* Research Plan */} {state.plan.length > 0 && (
{expandedSections.plan && (
{state.plan.map((item) => (
{item.status === "done" ? "✓" : item.status === "searching" ? "🔍" : "⏳"}
{item.question}
))}
)}
)} {/* Current Search Results */} {state.current_search && (
{expandedSections.search && (
{state.current_search.results && (
Type: {state.current_search.type} |{" "} {state.current_search.results.length} results
{state.current_search.results.map((result, idx) => (
{result.source}
{result.expanded && ( Expanded )} 0.8 ? "#48bb78" : result.score > 0.6 ? "#ed8936" : "#a0aec0", }} > {result.score.toFixed(2)}
{result.chunk}...
))}
)}
)}
)} {/* Insights */} {state.insights.length > 0 && (
{expandedSections.insights && (
{state.insights.map((insight, idx) => (
{(insight.confidence * 100).toFixed(0)}% confidence {insight.sources.length} sources
{insight.summary}
))}
)}
)} {/* Final Report */} {state.final_report && (
{expandedSections.report && (

{state.final_report.title}

Executive Summary

{state.final_report.summary}

Main Findings

    {state.final_report.findings.map((finding) => (
  • {finding}
  • ))}

Conclusions

    {state.final_report.conclusions.map((conclusion) => (
  • {conclusion}
  • ))}

Sources

{state.final_report.sources.map((source) => (
{source}
))}
)}
)}
); }