"use client"; import { useRef, useState, type ReactNode } from "react"; import { IconAt, IconChevronsLeft, IconDots } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { EnhancePromptButton } from "@/components/enhance-prompt-button"; import { SessionsDropdown } from "@/components/task/sessions-dropdown"; import { ModelSelector } from "@/components/task/model-selector"; import { ModeSelector } from "@/components/task/mode-selector"; import { TokenUsageDisplay } from "@/components/task/chat/token-usage-display"; import { useToolbarCollapsed } from "@/hooks/use-toolbar-collapsed"; import { cn } from "@/lib/utils"; import { ResetContextButton } from "./reset-context-button"; import { ImplementPlanButton } from "./implement-plan-button"; import { VoiceInputButton } from "./voice-input-button"; import { ContextPopover } from "./context-popover"; import { AttachFilesButton, McpIndicator, PlanToggleButton, SubmitButton, } from "./chat-input-toolbar-primitives"; import { type ChatInputToolbarProps } from "./chat-input-toolbar"; import type { ContextFile } from "@/lib/state/context-files-store"; import type { SHORTCUTS } from "@/lib/keyboard/constants"; type ToolbarItemConfig = { id: string; section: "left" | "right"; render: () => ReactNode; visible?: boolean; }; type DesktopToolbarProps = ChatInputToolbarProps & { planModeAvailable: boolean; mcpServers: string[]; submitShortcut: (typeof SHORTCUTS)[keyof typeof SHORTCUTS]; contextCount: number; contextPopoverOpen: boolean; planContextEnabled: boolean; contextFiles: ContextFile[]; isEnhancingPrompt: boolean; isUtilityConfigured: boolean; hideAgentControls: boolean; hidePlanMode: boolean; }; function ToolbarExpandToggle(props: { isExpanded: boolean; onToggle: () => void }) { return ( {props.isExpanded ? "Collapse" : "More actions"} ); } function CollapsibleItems(props: { items: ToolbarItemConfig[]; testIdPrefix: string }) { return props.items.map((i) => (
{i.render()}
)); } function buildCollapsibleItems(props: DesktopToolbarProps): ToolbarItemConfig[] { if (props.hideAgentControls) return []; return [ { id: "mcp", section: "left", render: () => , }, { id: "mode", section: "left", render: () => , }, { id: "reset-context", section: "right", visible: !!props.sessionId && !props.isAgentBusy, render: () => , }, { id: "sessions", section: "right", visible: !props.hideSessionsDropdown, render: () => ( ), }, { id: "model", section: "right", render: () => , }, { id: "enhance", section: "right", visible: !props.isAgentBusy, render: () => ( {})} isLoading={props.isEnhancingPrompt} isConfigured={props.isUtilityConfigured} /> ), }, ]; } function DesktopRightSection(props: { showCollapsed: boolean; rightItems: ToolbarItemConfig[]; sessionId: string | null; planModeEnabled: boolean; isAgentBusy: boolean; hasContent: boolean; onImplementPlan?: (fresh: boolean) => void; isDisabled: boolean; submitDisabledReason?: string; isSending: boolean; onCancel: () => void | Promise; onSubmit: () => void; submitShortcut: (typeof SHORTCUTS)[keyof typeof SHORTCUTS]; onVoiceTranscript?: (text: string) => void; onVoiceAutoSend?: () => void; }) { return (
{!props.showCollapsed && ( )} {props.planModeEnabled && !props.isAgentBusy && props.onImplementPlan && ( )}
{props.onVoiceTranscript && ( )}
); } export function DesktopChatInputToolbar(props: DesktopToolbarProps) { const toolbarRef = useRef(null); const isCollapsed = useToolbarCollapsed(toolbarRef); const [isExpanded, setIsExpanded] = useState(false); const showCollapsed = isCollapsed && !isExpanded; const items = buildCollapsibleItems(props); const leftItems = items.filter((i) => i.section === "left" && i.visible !== false); const rightItems = items.filter((i) => i.section === "right" && i.visible !== false); return (
{!props.hidePlanMode && ( )} {!showCollapsed && } {props.onAttachFiles && } {})} trigger={ } sessionId={props.sessionId} planContextEnabled={props.planContextEnabled} contextFiles={props.contextFiles} onToggleFile={props.onToggleFile ?? (() => {})} /> {isCollapsed && ( setIsExpanded((v) => !v)} /> )}
); }