import { useState } from "react"; import type { ZCodePlanStep } from "@zcode/shared"; import { Button } from "@/components/ui/button.js"; import { Plan, PlanAction, PlanContent, PlanDescription, PlanHeader, PlanTitle, } from "@/components/ai-elements/plan.js"; import { QueueItem, QueueItemContent, QueueItemIndicator, QueueList, } from "@/components/ai-elements/queue.js"; import { ChevronsUpDownIcon, ListTodo, LoaderIcon, } from "lucide-react"; import { useZCodeIntl } from "@/i18n/IntlProvider.js"; import { ControlHintTooltip } from "@/ControlHintTooltip.js"; import { cn } from "./components/lib/utils.js"; const todoStatusIndicatorClasses: Record = { pending: "text-foreground-subtlest", in_progress: "text-foreground", completed: "text-success", }; const todoStatusContentClassesStreaming: Record = { pending: "text-foreground-subtle", in_progress: "animated-gradient-text", completed: "text-foreground-subtlest line-through", }; // Bugfix: 任务停止/结束后 plan 可能还留着 in_progress 项,如果继续套 animated-gradient-text, // 面板就会一直显示 loading 态。非运行期降级为普通文本,仅保留状态色。 const todoStatusContentClassesIdle: Record = { pending: "text-foreground-subtle", in_progress: "text-foreground", completed: "text-foreground-subtlest line-through", }; export function TodoPanel({ plan, isStreaming, }: { plan: ZCodePlanStep[] | null; isStreaming: boolean; }) { const { intl } = useZCodeIntl(); const [isOpen, setIsOpen] = useState(false); if (!plan || plan.length === 0) { return null; } const completedCount = plan.filter( (step) => step.status === "completed", ).length; const isAllCompleted = completedCount === plan.length; // Bugfix: provider 可能先把 todo 全部标成 completed,再稍后才推 task_complete 清空 store。 // 这段间隙继续展示“已完成 todo”会让用户误以为还有待处理事项,所以全完成后直接隐藏面板。 if (isAllCompleted) { return null; } // Bugfix: 展开态之前会把 completed 项继续画出来,只是加删除线;完成项越多面板越长。 // 这里仅保留未完成项,让 todo 面板专注显示还需要关注的后续工作。 const visiblePlan = plan.filter((step) => step.status !== "completed"); const activeStep = plan.find((step) => step.status === "in_progress") ?? plan.find((step) => step.status !== "completed") ?? plan[plan.length - 1]; // Bugfix: loading 视觉只在任务真正运行期出现。task 已完成/失败/被停止时, // 即便 plan 仍残留 in_progress 项,也不再转菊花或做渐变动画。 const showLoadingState = isStreaming && !isAllCompleted; const todoStatusContentClasses = isStreaming ? todoStatusContentClassesStreaming : todoStatusContentClassesIdle; const toggleLabel = intl.formatMessage({ id: "todo.panel.toggle" }); const toggleOpen = () => setIsOpen((current) => !current); return ( {/* 修复原因:PlanHeader 负责撑满布局,不能再承担点击展开,否则空白区域也会误触。 展开逻辑收敛到内容宽度按钮和右侧图标按钮,保留键盘与读屏状态。 */}
{visiblePlan.map((step) => (
{step.title}
))}
); }