"use client";
import { IconMessageQuestion, IconCheck, IconX } from "@tabler/icons-react";
import type {
ClarificationAnswer,
ClarificationQuestion,
Message,
ClarificationRequestMetadata,
} from "@/lib/types/http";
import { useTranslation } from "react-i18next";
import { ClarificationMarkdown } from "../clarification-markdown";
type ClarificationRequestMessageProps = {
comment: Message;
};
function AnswerSummary({
question,
response,
}: {
question: ClarificationQuestion;
response: ClarificationAnswer | undefined;
}) {
const { t } = useTranslation();
if (!response) return {t("task:clarificationNoSelection")};
const selectedOptions = (response.selected_options ?? [])
.map((optionId) => question.options.find((option) => option.option_id === optionId))
.filter((option) => option !== undefined);
const hasCustomText = Boolean(response.custom_text);
if (selectedOptions.length === 0 && !hasCustomText) {
return {t("task:clarificationNoSelection")};
}
return (
{selectedOptions.map((option, index) => (
{index > 0 ? ", " : null}
{option.label}
))}
{response.custom_text && (
{selectedOptions.length > 0 ? ", " : null}
{`"${response.custom_text}"`}
)}
);
}
/**
* Displays a resolved or superseded clarification request in the chat history.
* The active pending clarification is shown in the input area instead.
*/
export function ClarificationRequestMessage({ comment }: ClarificationRequestMessageProps) {
const { t } = useTranslation();
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;
};
return (
{/* Icon */}
{/* Content */}
{/* Question */}
{question.title && (
{question.title}
)}
{question.prompt}
{/* Answer - indented below question */}
{isAnswered && (
{getStatusIndicator()}
{metadata.agent_disconnected && (
{t("task:sentAsNewMessage")}
)}
)}
{isSkipped && (
{getStatusIndicator()}
{t("task:skipped")}
)}
{isCancelled && (
{getStatusIndicator()}
{t("task:cancelled")}
)}
{isExpired && (
{getStatusIndicator()}
{t("task:timedOutAgentMovedOn")}
)}
);
}