"use client"; import { useState, memo } from "react"; import ReactMarkdown from "react-markdown"; import { IconMinus, IconPlus, IconMaximize } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@kandev/ui/dialog"; import { markdownComponents, normalizeMarkdown, remarkPlugins, } from "@/components/shared/markdown-components"; import type { Message } from "@/lib/types/http"; function parsePlanContent(text: string): { title: string; body: string } { const lines = text.split("\n"); const firstContentIdx = lines.findIndex((l) => l.trim().length > 0); if (firstContentIdx === -1) return { title: "Agent Plan", body: "" }; const firstLine = lines[firstContentIdx]; const isHeading = /^#{1,6}\s+/.test(firstLine); const title = isHeading ? firstLine.replace(/^#{1,6}\s+/, "").trim() : firstLine.trim(); const body = isHeading ? lines.slice(firstContentIdx + 1).join("\n") : text; return { title: title || "Agent Plan", body }; } function PlanMarkdownBody({ text, className }: { text: string; className?: string }) { return (
*]:my-2 [&>p]:my-2 [&>ul]:my-2 [&>ol]:my-2 ${className ?? ""}`} > {normalizeMarkdown(text)}
); } export const AgentPlanMessage = memo(function AgentPlanMessage({ comment }: { comment: Message }) { const [collapsed, setCollapsed] = useState(false); const [dialogOpen, setDialogOpen] = useState(false); const text = comment.content; if (!text) return null; const { title, body } = parsePlanContent(text); return ( <>
{title}
{!collapsed && (
)}
{title} ); });