"use client"; import { CopilotKit, useCoAgent, useCoAgentStateRender, useCopilotAction, } from "@copilotkit/react-core"; import { CopilotChat } from "@copilotkit/react-ui"; import "@copilotkit/react-ui/styles.css"; import StateDisplay from "./StateDisplay"; interface SourceRef { chunk_id: string; document_uri: string; document_title: string; chunk_position: number; } interface ResearchState { question: string; phase: string; status: string; plan: Array<{ id: number; question: string; status: string; search_results?: { type: string; results: Array<{ chunk: string; chunk_id: string; document_uri: string; document_title: string; chunk_position: number; full_chunk_content: string; score: number; expanded: boolean; }>; }; }>; current_question_index: number; insights: Array<{ summary: string; confidence: number; source_refs: SourceRef[]; }>; document_registry: Record< string, { title: string; chunks_referenced: string[]; } >; current_document: { uri: string; title: string; content: string; total_chunks: number; metadata?: Record; } | null; confidence: number; final_report: { title: string; summary: string; findings: string[]; conclusions: string[]; sources: string[]; citations: Array<{ document_uri: string; document_title: string; chunk_ids: string[]; }>; } | null; } function AgentContent() { const { state } = useCoAgent({ name: "research_agent", initialState: { question: "", phase: "idle", status: "", plan: [], current_question_index: 0, insights: [], document_registry: {}, current_document: null, confidence: 0.0, final_report: null, }, }); useCopilotAction({ name: "approve_research_plan", description: "Request user approval for the research plan. Returns 'APPROVED' if approved or 'REVISE' if user wants to revise.", parameters: [], renderAndWaitForResponse: ({ respond, status }) => (

Research Plan Approval

Please review the research plan in the right pane.

), }); useCoAgentStateRender({ name: "research_agent", render: ({ state: newState }) => { const phaseMessages: Record = { planning: "Planning research...", searching: "Searching...", analyzing: "Extracting insights...", evaluating: `Evaluating confidence: ${(newState.confidence * 100).toFixed(0)}%`, synthesizing: "Generating final report...", done: "Research complete!", }; const phaseMessage = phaseMessages[newState.phase] || newState.status || "Ready"; return (
Research Update: {phaseMessage}
); }, }); return ( <>
{/* Chat on the left */}
{/* State display on the right */}

Research State

Live updates from the research agent

); } export default function Agent() { return ( ); }