import type { RealtimeItem } from "@openai/agents/realtime"; import { useAgent } from "agents/react"; import { useEffect, useState } from "react"; import { createRoot } from "react-dom/client"; import "./styles.css"; interface Message { itemId: string; type: string; role: "user" | "assistant"; status: "completed" | "in_progress"; content: Array<{ type: string; transcript: string; // oxlint-disable-next-line @typescript-eslint/no-explicit-any -- OpenAI SDK audio type not exposed audio?: any; }>; } function App() { const [state, setState] = useState<{ history: RealtimeItem[] }>({ history: [] }); const [callStatus, setCallStatus] = useState< "connecting" | "connected" | "disconnected" >("connecting"); const [callDuration, setCallDuration] = useState(0); useAgent<{ history: RealtimeItem[] }>({ agent: "my-agent", name: "123", onStateUpdate(newState) { setState(newState); // Update call status based on state if (newState.history && newState.history.length > 0) { setCallStatus("connected"); } } }); // Timer for call duration useEffect(() => { let interval: NodeJS.Timeout; if (callStatus === "connected") { interval = setInterval(() => { setCallDuration((prev) => prev + 1); }, 1000); } return () => clearInterval(interval); }, [callStatus]); const formatDuration = (seconds: number) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; return `${mins.toString().padStart(2, "0")}:${secs .toString() .padStart(2, "0")}`; }; const getStatusColor = (status: string) => { switch (status) { case "completed": return "#22c55e"; case "in_progress": return "#f59e0b"; default: return "#6b7280"; } }; const getStatusText = (status: string) => { switch (status) { case "completed": return "✓"; case "in_progress": return "●"; default: return "○"; } }; return (
Waiting for call to begin...