import { memo, useCallback, useEffect, useRef } from 'react'; import { useWatch } from 'react-hook-form'; import { Button, TooltipAnchor } from '@librechat/client'; import { ChevronDown, CornerDownLeft, TriangleAlert } from 'lucide-react'; import AskUserQuestions from '~/components/Chat/Messages/Content/AskUserQuestions'; import useAskAnswerMode from '~/hooks/Input/useAskAnswerMode'; import AskOptions from '~/components/Chat/ask/options'; import { useChatFormContext } from '~/Providers'; import { isCancelKey } from '~/utils/shortcuts'; import { useComposerOverlay } from './overlay'; import { useLocalize } from '~/hooks'; /** * Composer popover for a live `ask_user_question` pause. Single-select rows * submit on click; a digit `1..N` activates its row like a click whether * focus is in the composer or on the popover (arrows/Enter highlight+confirm * from the empty composer); multi-select rows toggle checks and an explicit * Submit confirms — * folding in any free-form text typed in the composer, exactly like Enter * would. The footer hint is a button that focuses the composer — the * free-form answer box. The chevron moves the question to the chat card and * releases the composer (the card's chevron moves it back). Pure rendering * off {@link useAskAnswerMode}; disappears the moment an answer submits from * any surface, and locks while one is in flight. Registers as an open composer * panel for as long as it shows, so the thread's scroll-to-bottom control * stands down instead of landing on its footer. */ function AskUserQuestionPopoverContent({ conversationId, textAreaRef, }: { conversationId: string; textAreaRef?: React.RefObject; }) { const ask = useAskAnswerMode(conversationId); const { collapse, popoverVisible } = ask; useComposerOverlay(conversationId, popoverVisible); /** * Escape from inside the popover does what it does from the composer: moves * the question to the chat. Focus then returns to the composer, which a * batch keeps disabled until the popover is gone, hence after the commit. */ const refocusComposer = useRef(false); const escapeToChat = useCallback(() => { refocusComposer.current = true; collapse(); }, [collapse]); useEffect(() => { if (popoverVisible || !refocusComposer.current) { return; } refocusComposer.current = false; textAreaRef?.current?.focus(); }, [popoverVisible, textAreaRef]); if (!popoverVisible || !ask.liveAsk) { return null; } if (ask.liveAsk.questions != null && ask.liveAsk.questions.length > 0) { return ; } return ( ); } function AskUserQuestionsPopoverPanel({ ask, onEscape, }: { ask: ReturnType; onEscape: () => void; }) { const { liveAsk, collapse } = ask; const questions = liveAsk?.questions; if (liveAsk == null || questions == null || questions.length === 0) { return null; } return (
{/* The prompt and answers each scroll within their own caps; this outer cap keeps the whole card on screen when both are at their limit on a short viewport. */}
{/* Kept at full height so the cap above scrolls it rather than clipping its end. */} } />
); } /** Moves the question to the chat card and hands the composer back. */ function MoveToChatButton({ onClick }: { onClick: () => void }) { const localize = useLocalize(); return (