Skip to content

πŸ™Œ OpenHands: AI-Driven Development

1.2 KB
Raw Blame
import {
  useConversationWebSocket,
  WebSocketConnectionState,
} from "#/contexts/conversation-websocket-context";

/**
 * Returns the current conversation WebSocket status.
 */
export function useUnifiedWebSocketStatus(): WebSocketConnectionState {
  const conversationContext = useConversationWebSocket();
  return conversationContext ? conversationContext.connectionState : "CLOSED";
}

/**
 * The main connection's own status, unmerged with the planning connection.
 * Use for actions that only address the main conversation (e.g. `/code`) β€”
 * `useUnifiedWebSocketStatus` can report non-OPEN purely from a momentary
 * planning reconnect.
 */
export function useMainWebSocketStatus(): WebSocketConnectionState {
  const conversationContext = useConversationWebSocket();
  return conversationContext
    ? conversationContext.mainConnectionState
    : "CLOSED";
}

/**
 * True once the conversation has connected at least once. Pair with a
 * `CONNECTING` status to tell a first-ever connect from a reconnect β€” see
 * `getStatusCode`.
 */
export function useHasConnectedOnceWebSocket(): boolean {
  const conversationContext = useConversationWebSocket();
  return conversationContext ? conversationContext.hasConnectedOnce : false;
}