import { useAgent } from "agents/react"; import { useState } from "react"; import { createRoot } from "react-dom/client"; import type { AgentState, MyAgent } from "./server"; /** * The OpenAI Agents SDK exports SerializedRunState (a Zod schema) from * @openai/agents-core, but its inferred type is deeply nested with dozens * of fields. This interface covers only the subset the UI actually reads. */ interface RunResultState { currentAgent?: { name: string }; originalInput?: string; currentStep?: { type: string; output?: string; data?: { interruptions?: ToolApprovalItem[] }; }; lastProcessedResponse?: { toolsUsed?: string[] }; generatedItems?: unknown[]; } // Types for the agent state structure interface ToolApprovalItem { type: "tool_approval_item"; rawItem: { type: "function_call"; id: string; callId: string; name: string; status: string; arguments: string; providerData: { id: string; type: "function_call"; }; }; agent: { name: string; }; } // Modal component for tool approval function ApprovalModal({ interruption, onApprove, onReject }: { interruption: ToolApprovalItem; onApprove: () => void; onReject: () => void; }) { let args: unknown; try { args = JSON.parse(interruption.rawItem.arguments); } catch { args = { raw: interruption.rawItem.arguments }; } return (
{JSON.stringify(args, null, 2)}
{JSON.stringify(state.generatedItems, null, 2)}