import { useState, type JSX } from "react"; import { canonicalInteractionKey } from "@tutti-os/agent-activity-core"; import { Button } from "@tutti-os/ui-system"; import { MessageSquareMoreIcon } from "../../../app/renderer/components/icons/MessageSquareMoreIcon"; import styles from "../../../agent-gui/agentGuiNode/AgentGUIConversation.styles"; import type { AgentConversationPromptVM } from "../contracts/agentConversationVM"; import { buildAskUserAnswerPayload } from "../interactiveAnswerPayload"; import type { AgentInteractivePromptConversationReturn, AgentInteractivePromptSurfaceProps, AgentInteractivePromptVariant } from "./AgentInteractivePromptSurface"; import { interactiveOptionLabel, interactivePromptCardClassName, interactivePromptClassName, stripPromptTitlePunctuation } from "./interactivePromptPresentation"; import { useAskUserAnswerFlow } from "./useAskUserAnswerFlow"; type AskUserPrompt = Extract; type SharedAskUserSurfaceProps = Pick< AgentInteractivePromptSurfaceProps, "edgeGlow" | "isInteractionDisabled" | "isSubmitting" | "labels" | "onSubmit" > & { embedded?: boolean; prompt: AskUserPrompt; }; export function AgentAskUserPromptSurface({ prompt, variant, conversationReturn, ...props }: SharedAskUserSurfaceProps & { variant: AgentInteractivePromptVariant; conversationReturn?: AgentInteractivePromptConversationReturn; }): JSX.Element { "use memo"; const question = prompt.questions[0] ?? null; const useCompactQuickAnswer = variant === "compact" && prompt.questions.length === 1 && question !== null && !question.multiSelect && question.options.length > 0; if (useCompactQuickAnswer) { return ( ); } return ( ); } function CompactQuickAnswerSurface({ prompt, question, embedded = false, edgeGlow = false, isSubmitting, isInteractionDisabled = false, onSubmit }: Omit & { question: AskUserPrompt["questions"][number]; }): JSX.Element { return (
{stripPromptTitlePunctuation(question.header)}
{question.question}
{question.options.map((option) => ( ))}
); } function AskUserAnswerFlowSurface({ prompt, conversationReturn, embedded = false, edgeGlow = false, isSubmitting, isInteractionDisabled = false, onSubmit, labels }: SharedAskUserSurfaceProps & { conversationReturn?: AgentInteractivePromptConversationReturn; }): JSX.Element { "use memo"; const [collapsed, setCollapsed] = useState(false); const flow = useAskUserAnswerFlow({ isSubmitting: isSubmitting || isInteractionDisabled, questions: prompt.questions }); const question = flow.currentQuestion; if (!question) { return (
); } if (collapsed && conversationReturn) { return (
{stripPromptTitlePunctuation(labels.waitingForAnswer)}
); } return (
{stripPromptTitlePunctuation(question.header)} {flow.currentIndex + 1}/{prompt.questions.length}
{question.question}
{question.options.length > 0 ? (
{question.options.map((option) => { const active = flow.selectedOptions.includes(option.label); return ( ); })}
) : null} {question.allowFreeText !== false && (!conversationReturn || question.options.length === 0) ? (