import { createEffect, createSignal, For, onCleanup, onMount, Show } from "solid-js"; import type { Agent } from "../types"; import type { QueuedMessage } from "../App"; import { AgentSwitcher } from "./AgentSwitcher"; interface InputBarProps { value: string; onInput: (value: string) => void; onSubmit: () => void; onCancel: () => void; onQueue: () => void; disabled: boolean; isThinking: boolean; selectedAgent: string | null; agents: Agent[]; onAgentChange: (agentName: string) => void; queuedMessages: QueuedMessage[]; onRemoveFromQueue: (id: string) => void; onEditQueuedMessage: (id: string) => void; } export function InputBar(props: InputBarProps) { let inputRef!: HTMLTextAreaElement; const [isShiftHeld, setIsShiftHeld] = createSignal(false); const adjustTextareaHeight = () => { if (inputRef) { inputRef.style.height = "auto"; inputRef.style.height = `${Math.min(inputRef.scrollHeight, 120)}px`; } }; createEffect(() => { props.value; adjustTextareaHeight(); }); onMount(() => { inputRef?.focus(); const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Shift") { setIsShiftHeld(true); } }; const handleKeyUp = (e: KeyboardEvent) => { if (e.key === "Shift") { setIsShiftHeld(false); } }; window.addEventListener("keydown", handleKeyDown); window.addEventListener("keyup", handleKeyUp); onCleanup(() => { window.removeEventListener("keydown", handleKeyDown); window.removeEventListener("keyup", handleKeyUp); }); }); const handleSubmit = (e: Event) => { e.preventDefault(); if (props.isThinking && !props.value.trim()) { props.onCancel(); return; } if (!props.value.trim() || props.disabled) { return; } props.onSubmit(); }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape" && props.isThinking) { e.preventDefault(); props.onCancel(); return; } if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); if (props.isThinking && e.shiftKey && props.value.trim()) { props.onQueue(); } else if (!props.isThinking || props.value.trim()) { handleSubmit(e); } } }; const handleContainerClick = (e: MouseEvent) => { const target = e.target as HTMLElement; if ( !target.closest("button") && !target.closest(".agent-switcher-button") && !target.closest(".queued-message") && inputRef ) { inputRef.focus(); } }; const hasText = () => props.value.trim().length > 0; const showQueueButton = () => props.isThinking && hasText() && isShiftHeld(); const showSubmitButton = () => !props.isThinking || hasText(); const showStopButton = () => props.isThinking && !hasText(); return (
0}>
{(message) => (
props.onEditQueuedMessage(message.id)} > {message.text}
)}