"use client"; import ReactMarkdown from "react-markdown"; import { IconMessageQuestion, IconCheck, IconX } from "@tabler/icons-react"; import { markdownComponents, remarkPlugins } from "@/components/shared/markdown-components"; import type { Message, ClarificationRequestMetadata } from "@/lib/types/http"; type ClarificationRequestMessageProps = { comment: Message; }; /** * Displays a resolved clarification request in the chat history. * Pending clarifications are shown in the input area instead. */ export function ClarificationRequestMessage({ comment }: ClarificationRequestMessageProps) { const metadata = comment.metadata as ClarificationRequestMetadata | undefined; if (!metadata?.question) { return null; } const question = metadata.question; const status = metadata.status; const isAnswered = status === "answered"; const isSkipped = status === "rejected"; const isExpired = status === "expired"; const isCancelled = status === "cancelled"; const getStatusIndicator = () => { if (isAnswered) { return ; } if (isSkipped || isCancelled) { return ; } if (isExpired) { return ; } return null; }; // Get the answer summary for display const getAnswerSummary = () => { const response = metadata.response; if (!response) return "No selection"; const parts: string[] = []; // Get selected option labels if (response.selected_options?.length) { for (const optionId of response.selected_options) { const option = question.options.find((o) => o.option_id === optionId); if (option) { parts.push(option.label); } } } // Add custom text if (response.custom_text) { parts.push(`"${response.custom_text}"`); } return parts.length > 0 ? parts.join(", ") : "No selection"; }; return (
{/* Icon */}
{/* Content */}
{/* Question */}
{question.prompt}
{/* Answer - indented below question */} {isAnswered && (
{getStatusIndicator()} {getAnswerSummary()} {metadata.agent_disconnected && ( ยท sent as new message )}
)} {isSkipped && (
{getStatusIndicator()} Skipped
)} {isCancelled && (
{getStatusIndicator()} Cancelled
)} {isExpired && (
{getStatusIndicator()} Timed out (agent moved on)
)}
); }