import { Match, Show, Switch, createSignal, type JSX } from "solid-js"; import type { RagMessage } from "@/api/client"; import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; import { IconAlert, IconCopy, IconRefresh } from "@/components/ui/icons"; import { RagCitations } from "@/components/rag/rag-citations"; import { RagThinkingLabel } from "@/components/rag/rag-thinking-label"; import { cn } from "@/lib/cn"; export function RagMessageRow(props: { message: RagMessage; /** Rendered under the citations of an answer (e.g. study actions). */ footer?: JSX.Element; /** * Re-asks the question this answer replies to. Passed only for the newest * answer — re-asking an older one would append it at the end of the * transcript, far from the turn the reader was looking at. */ onRetry?: () => void; labels: { thinking: string; thinking2: string; thinking3: string; copy: string; copied: string; retry: string; sources: string; source: string; subject: string; pages: string; document: string; failed: string; failedWithCode: (code: string) => string; abstained: string; abstainedReason: (reason: string) => string; }; }) { const [copied, setCopied] = createSignal(false); const assistant = () => props.message.role === "assistant"; const failure = () => props.message.error_code ? props.labels.failedWithCode(props.message.error_code) : props.labels.failed; const settled = () => props.message.status === "complete" || props.message.status === "failed"; const copyable = () => assistant() && props.message.status === "complete" && !!props.message.content; const copy = async () => { await navigator.clipboard.writeText(props.message.content); setCopied(true); window.setTimeout(() => setCopied(false), 1_500); }; return ( // The user's turn is a bubble; the answer is not. An answer is the page's // content, not a message in a thread, so it runs the full reading column // with no frame and no avatar competing with the first line of text.

{failure()}

{props.message.content || props.labels.abstained}

{props.labels.abstainedReason(props.message.reason)}

{props.footer}
{(retry) => ( )}
); }