import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons"; import { OpenHandsAction } from "#/types/core/actions"; import { isUserMessage, isErrorObservation, isAssistantMessage, isOpenHandsAction, isOpenHandsObservation, isFinishAction, isRejectObservation, isMcpObservation, } from "#/types/core/guards"; import { OpenHandsObservation } from "#/types/core/observations"; import { ImageCarousel } from "../images/image-carousel"; import { ChatMessage } from "./chat-message"; import { ErrorMessage } from "./error-message"; import { MCPObservationContent } from "./mcp-observation-content"; import { getObservationResult } from "./event-content-helpers/get-observation-result"; import { getEventContent } from "./event-content-helpers/get-event-content"; import { GenericEventMessage } from "./generic-event-message"; const hasThoughtProperty = ( obj: Record, ): obj is { thought: string } => "thought" in obj && !!obj.thought; interface EventMessageProps { event: OpenHandsAction | OpenHandsObservation; hasObservationPair: boolean; isAwaitingUserConfirmation: boolean; isLastMessage: boolean; } export function EventMessage({ event, hasObservationPair, isAwaitingUserConfirmation, isLastMessage, }: EventMessageProps) { const shouldShowConfirmationButtons = isLastMessage && event.source === "agent" && isAwaitingUserConfirmation; if (isErrorObservation(event)) { return ( ); } if (hasObservationPair && isOpenHandsAction(event)) { if (hasThoughtProperty(event.args)) { return ; } return null; } if (isFinishAction(event)) { return ( ); } if (isUserMessage(event) || isAssistantMessage(event)) { return ( {event.args.image_urls && event.args.image_urls.length > 0 && ( )} {shouldShowConfirmationButtons && } ); } if (isRejectObservation(event)) { return ; } if (isMcpObservation(event)) { return (
} success={getObservationResult(event)} /> {shouldShowConfirmationButtons && }
); } return (
{isOpenHandsAction(event) && hasThoughtProperty(event.args) && ( )} {shouldShowConfirmationButtons && }
); }