{"repo": "agribeacon/agribeacon-landingpage", "files": {"src/components/ChatBot.tsx": {"3fcd14a9beaf030cc7694b3504ee4112e9f530f7": {"t": 1785846946.0062146, "n": 9883, "h": "f74d330b203c01a3", "c": "import { FormEvent, KeyboardEvent, useEffect, useRef, useState } from \"react\";\nimport { Bot, Loader2, MessageCircle, Send, Sprout, User, X } from \"lucide-react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Textarea } from \"@/components/ui/textarea\";\nimport { cn } from \"@/lib/utils\";\n\ntype ChatMessage = {\n id: string;\n role: \"user\" | \"assistant\";\n content: string;\n};\n\nconst starterMessages: ChatMessage[] = [\n {\n id: \"welcome\",\n role: \"assistant\",\n content:\n \"Xin chào, mình là Tiểu Thần Nông AI của AgriBeacon. Bạn có thể hỏi về canh tác, cảm biến IoT, UAV, robot, bản đồ nông trại, dự báo năng suất hoặc giải pháp AgriBeacon.\",\n },\n];\n\nconst quickPrompts = [\n \"Vườn sầu riêng nên đặt cảm biến gì?\",\n \"Robot phun thuốc phù hợp diện tích nào?\",\n \"Làm sao dự báo năng suất tốt hơn?\",\n];\n\nconst createId = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`;\n\nconst renderInlineMarkdown = (text: string) => {\n const parts = text.split(/(\\*\\*[^*\\n]+\\*\\*)/g);\n\n return parts.map((part, index) => {\n if (part.startsWith(\"**\") && part.endsWith(\"**\") && part.length > 4) {\n return (\n \n {part.slice(2, -2)}\n \n );\n }\n\n return {part};\n });\n};\n\nconst renderAssistantMarkdown = (content: string) => {\n const elements: JSX.Element[] = [];\n let listType: \"ul\" | \"ol\" | null = null;\n let listItems: string[] = [];\n\n const flushList = () => {\n if (!listType || listItems.length === 0) return;\n\n const ListTag = listType;\n elements.push(\n
\n {renderInlineMarkdown(trimmed)}\n
,\n );\n });\n\n flushList();\n\n returnTrợ lý AgriBeacon
\n