"use client"; import { useCoAgentStateRender } from '@copilotkit/react-core'; import { Workflow, NodeExecutionResult } from '@/lib/workflow/types'; import { CheckCircle2, Circle, Loader2, XCircle } from 'lucide-react'; interface WorkflowExecutionRendererProps { workflow: Workflow; } interface AgentState { variables: Record; chatHistory: Array<{ role: string; content: string }>; currentNodeId: string; nodeResults: Record; pendingAuth: any | null; } /** * Real-time workflow execution renderer using CopilotKit * Automatically updates UI based on LangGraph state changes */ export function WorkflowExecutionRenderer({ workflow }: WorkflowExecutionRendererProps) { // Render agent state in real-time as it changes const StateDisplay = useCoAgentStateRender({ name: workflow.id, render: ({ state }) => { if (!state || !state.nodeResults || Object.keys(state.nodeResults).length === 0) { return null; } return (

Workflow Execution Progress

{/* Current Node Indicator */} {state.currentNodeId && (
Executing: {workflow.nodes.find(n => n.id === state.currentNodeId)?.data?.nodeName || state.currentNodeId}
)} {/* Node Results */}
{Object.entries(state.nodeResults).map(([nodeId, result]) => { const node = workflow.nodes.find(n => n.id === nodeId); const nodeName = node?.data?.nodeName || nodeId; return (
{/* Status Icon */}
{result.status === 'completed' && ( )} {result.status === 'failed' && ( )} {result.status === 'running' && ( )} {result.status === 'pending' && ( )}
{/* Node Info */}
{nodeName} {result.status}
{/* Output Preview */} {result.output && (
Output:
                            {typeof result.output === 'string'
                              ? result.output
                              : JSON.stringify(result.output, null, 2)}
                          
)} {/* Error Display */} {result.error && (
Error:
{result.error}
)} {/* Timing Info */} {(result.startedAt || result.completedAt) && (
{result.startedAt && (
Started: {new Date(result.startedAt).toLocaleTimeString()}
)} {result.completedAt && (
Completed: {new Date(result.completedAt).toLocaleTimeString()}
)}
)}
); })}
{/* Variables Display */} {state.variables && Object.keys(state.variables).length > 0 && (
Workflow Variables ({Object.keys(state.variables).length})
                  {JSON.stringify(state.variables, null, 2)}
                
)} {/* Pending Auth Display */} {state.pendingAuth && (
Waiting for authorization...
{state.pendingAuth.message && (

{state.pendingAuth.message}

)}
)}
); }, }); return StateDisplay; }