"use client"; import type { UIMessage } from "ai"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { ChatMessage } from "./chat-message"; import { createStreamParser } from "./chat-panel"; import { UnicodeSpinner } from "./unicode-spinner"; import { ChatEditor, type ChatEditorHandle } from "./tiptap/chat-editor"; type SubagentPanelProps = { sessionKey: string; task: string; label?: string; onBack: () => void; onSubagentClick?: (task: string) => void; onFilePathClick?: (path: string) => Promise | boolean | void; }; type QueuedMessage = { id: string; text: string; mentionedFiles: Array<{ name: string; path: string }>; }; function QueueItem({ msg, idx, onEdit, onSendNow, onRemove, }: { msg: QueuedMessage; idx: number; onEdit: (id: string, text: string) => void; onSendNow: (id: string) => void; onRemove: (id: string) => void; }) { const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(msg.text); const inputRef = useRef(null); const autoResize = () => { const el = inputRef.current; if (!el) { return; } el.style.height = "auto"; el.style.height = `${el.scrollHeight}px`; }; useEffect(() => { if (!editing) { return; } inputRef.current?.focus(); const len = inputRef.current?.value.length ?? 0; inputRef.current?.setSelectionRange(len, len); autoResize(); }, [editing]); const commitEdit = () => { const trimmed = draft.trim(); if (trimmed && trimmed !== msg.text) { onEdit(msg.id, trimmed); } else { setDraft(msg.text); } setEditing(false); }; return (
0 ? "border-t" : ""}`} style={idx > 0 ? { borderColor: "var(--color-border)" } : undefined} > {idx + 1} {editing ? (