// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates // SPDX-License-Identifier: MIT import { AnimatePresence, motion } from "framer-motion"; import { ArrowUp, X } from "lucide-react"; import { type KeyboardEvent, useCallback, useEffect, useRef, useState, } from "react"; import { Detective } from "~/components/deer-flow/icons/detective"; import { Tooltip } from "~/components/deer-flow/tooltip"; import { Button } from "~/components/ui/button"; import type { Option } from "~/core/messages"; import { setEnableBackgroundInvestigation, useSettingsStore, } from "~/core/store"; import { cn } from "~/lib/utils"; export function InputBox({ className, size, responding, feedback, onSend, onCancel, onRemoveFeedback, }: { className?: string; size?: "large" | "normal"; responding?: boolean; feedback?: { option: Option } | null; onSend?: (message: string, options?: { interruptFeedback?: string }) => void; onCancel?: () => void; onRemoveFeedback?: () => void; }) { const [message, setMessage] = useState(""); const [imeStatus, setImeStatus] = useState<"active" | "inactive">("inactive"); const [indent, setIndent] = useState(0); const backgroundInvestigation = useSettingsStore( (state) => state.general.enableBackgroundInvestigation, ); const textareaRef = useRef(null); const feedbackRef = useRef(null); useEffect(() => { if (feedback) { setMessage(""); setTimeout(() => { if (feedbackRef.current) { setIndent(feedbackRef.current.offsetWidth); } }, 200); } setTimeout(() => { textareaRef.current?.focus(); }, 0); }, [feedback]); const handleSendMessage = useCallback(() => { if (responding) { onCancel?.(); } else { if (message.trim() === "") { return; } if (onSend) { onSend(message, { interruptFeedback: feedback?.option.value, }); setMessage(""); onRemoveFeedback?.(); } } }, [responding, onCancel, message, onSend, feedback, onRemoveFeedback]); const handleKeyDown = useCallback( (event: KeyboardEvent) => { if (responding) { return; } if ( event.key === "Enter" && !event.shiftKey && !event.metaKey && !event.ctrlKey && imeStatus === "inactive" ) { event.preventDefault(); handleSendMessage(); } }, [responding, imeStatus, handleSendMessage], ); return (
{feedback && (
{feedback.option.text}
)}