"use client"; import { useEffect, useId, useRef } from "react"; import type { FormEvent, RefObject } from "react"; import { Send, Square } from "lucide-react"; import { Button } from "@/components/ui/button"; import type { AIMode } from "./workspace-mode"; import { submitComposer } from "./composer-events"; export function shouldSubmitOnEnter(event: { key: string; shiftKey: boolean; isComposing: boolean; }): boolean { return event.key === "Enter" && !event.shiftKey && !event.isComposing; } interface WorkspaceComposerProps { mode: AIMode; input: string; onInputChange: (value: string) => void; onSubmit: (event: FormEvent) => void; busy?: boolean; onStop?: () => void; inputRef?: RefObject; active?: boolean; } export function WorkspaceComposer({ mode, input, onInputChange, onSubmit, busy = false, onStop, inputRef, active = true, }: WorkspaceComposerProps) { const localRef = useRef(null); const ref = inputRef ?? localRef; const hintId = useId(); const isChat = mode === "chat"; useEffect(() => { if (!active || !ref.current) return; ref.current.style.height = "auto"; ref.current.style.height = `${Math.min(ref.current.scrollHeight, 200)}px`; }, [input, active, ref]); return (
{ submitComposer(event, input, busy, onSubmit, () => ref.current?.focus(), ); }} className="mx-auto flex max-w-3xl items-end gap-3" >