/** * React Hook for Claude Code WebSocket (Bidirectional) * * Provides real-time bidirectional communication with Claude Code agents. */ import type { ClaudeCodeEventExtended, ClaudeCodeResult } from "../types.js"; import { type ClaudeCodeEventState } from "./event-state-reducer.js"; /** * Pending approval state */ export interface PendingApproval { toolCallId: string; toolName: string; input: Record; reason: string; timeout?: number; requestedAt: number; } /** * Pending input request state */ export interface PendingInput { prompt: string; defaultValue?: string; timeout?: number; requestedAt: number; } /** * State for Claude Code WebSocket */ export interface UseClaudeCodeWebSocketState extends ClaudeCodeEventState { /** Whether currently connected */ isConnected: boolean; /** Whether agent was cancelled */ isCancelled: boolean; /** Pending approval requests */ pendingApprovals: PendingApproval[]; /** Pending input request (if any) */ pendingInput: PendingInput | null; } /** * Options for useClaudeCodeWebSocket hook */ export interface UseClaudeCodeWebSocketOptions { /** WebSocket endpoint URL */ url: string; /** Run ID to connect to */ runId: string; /** Auto-connect on mount */ autoConnect?: boolean; /** Reconnect on disconnect */ autoReconnect?: boolean; /** Max reconnect attempts */ maxReconnectAttempts?: number; /** Reconnect delay (ms) */ reconnectDelay?: number; /** Ping interval (ms) */ pingInterval?: number; /** Callbacks */ onEvent?: (event: ClaudeCodeEventExtended) => void; onConnect?: () => void; onDisconnect?: () => void; onError?: (error: Error) => void; onComplete?: (result: ClaudeCodeResult) => void; onApprovalRequest?: (approval: PendingApproval) => void; onInputRequest?: (input: PendingInput) => void; } /** * Actions returned by the hook */ export interface UseClaudeCodeWebSocketActions { /** Connect to WebSocket */ connect: () => void; /** Disconnect from WebSocket */ disconnect: () => void; /** Cancel the agent execution */ cancel: (reason?: string) => void; /** Approve a pending tool call */ approve: (toolCallId: string) => void; /** Reject a pending tool call */ reject: (toolCallId: string, reason?: string) => void; /** Send user input */ sendInput: (content: string) => void; } /** * React hook for bidirectional Claude Code streaming * * @example * ```tsx * function AgentController({ runId }: { runId: string }) { * const { * isRunning, * text, * pendingApprovals, * cancel, * approve, * reject, * } = useClaudeCodeWebSocket({ * url: '/api/workflows/ws', * runId, * }); * * return ( *
*
{text}
* * {pendingApprovals.map(pa => ( *
*

Approve {pa.toolName}?

*
{JSON.stringify(pa.input, null, 2)}
* * *
* ))} * * {isRunning && ( * * )} *
* ); * } * ``` */ export declare function useClaudeCodeWebSocket(options: UseClaudeCodeWebSocketOptions): UseClaudeCodeWebSocketState & UseClaudeCodeWebSocketActions; //# sourceMappingURL=use-claude-code-websocket.d.ts.map