import { useState, useEffect } from "react"; import { createPortal } from "react-dom"; import { Search, ArrowRight, Sparkles, Zap, X } from "lucide-react"; import { useLang } from "@/contexts/LanguageContext"; import { motion, AnimatePresence } from "framer-motion"; import ComingSoonModal from "@/components/ComingSoonModal"; const agents = [ { nameKey: "ai.aism.name", tagKey: "ai.aism.tag", descKey: "ai.aism.desc", emoji: "🤖", tags: ["ai.tag.instantResponse", "ai.tag.multiRound", "ai.tag.problemTriage"], gradient: "from-blue-500/10 to-cyan-500/5", status: "online", category: "ai.customerService" }, { nameKey: "ai.meeting.name", tagKey: "ai.meeting.tag", descKey: "ai.meeting.desc", emoji: "📝", tags: ["ai.tag.speechToText", "ai.tag.keyPoints", "ai.tag.taskAllocation"], gradient: "from-violet-500/10 to-purple-500/5", status: "online", category: "ai.efficiency" }, { nameKey: "ai.deepseek.name", tagKey: "ai.deepseek.tag", descKey: "ai.deepseek.desc", emoji: "🧠", tags: ["ai.tag.deepUnderstanding", "ai.tag.accurate", "ai.tag.knowledgeable"], gradient: "from-emerald-500/10 to-teal-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.adminAssist.name", tagKey: "ai.adminAssist.tag", descKey: "ai.adminAssist.desc", emoji: "📋", tags: ["ai.tag.scheduling", "ai.tag.documents", "ai.tag.reminders"], gradient: "from-amber-500/10 to-orange-500/5", status: "busy", category: "ai.admin" }, { nameKey: "ai.strategic.name", tagKey: "ai.strategic.tag", descKey: "ai.strategic.desc", emoji: "🎯", tags: ["ai.tag.swotAnalysis", "ai.tag.competitorResearch", "ai.tag.marketInsights"], gradient: "from-rose-500/10 to-pink-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.bizplan.name", tagKey: "ai.bizplan.tag", descKey: "ai.bizplan.desc", emoji: "📈", tags: ["ai.tag.templates", "ai.tag.dataAnalysis", "ai.tag.oneClickExport"], gradient: "from-indigo-500/10 to-blue-500/5", status: "online", category: "ai.efficiency" }, { nameKey: "ai.marketReport.name", tagKey: "ai.marketReport.tag", descKey: "ai.marketReport.desc", emoji: "📊", tags: ["ai.tag.trendScan", "ai.tag.sectorBenchmark", "ai.tag.reportStructured"], gradient: "from-sky-500/10 to-blue-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.techReport.name", tagKey: "ai.techReport.tag", descKey: "ai.techReport.desc", emoji: "🔬", tags: ["ai.tag.techFeasibility", "ai.tag.riskReview", "ai.tag.implementationPath"], gradient: "from-teal-500/10 to-emerald-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.factorySourcing.name", tagKey: "ai.factorySourcing.tag", descKey: "ai.factorySourcing.desc", emoji: "🏭", tags: ["ai.tag.capacityMatch", "ai.tag.certAudit", "ai.tag.geoSourcing"], gradient: "from-orange-500/10 to-amber-500/5", status: "online", category: "ai.industrial" }, { nameKey: "ai.patentCompare.name", tagKey: "ai.patentCompare.tag", descKey: "ai.patentCompare.desc", emoji: "📑", tags: ["ai.tag.claimDiff", "ai.tag.featureOverlap", "ai.tag.priorArtHint"], gradient: "from-fuchsia-500/10 to-purple-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.zoneInspection.name", tagKey: "ai.zoneInspection.tag", descKey: "ai.zoneInspection.desc", emoji: "🔍", tags: ["ai.tag.innovationClaims", "ai.tag.listingConsistency", "ai.tag.policyAlignment"], gradient: "from-lime-500/10 to-green-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.techPrice.name", tagKey: "ai.techPrice.tag", descKey: "ai.techPrice.desc", emoji: "💰", tags: ["ai.tag.comparableTx", "ai.tag.licensingContext", "ai.tag.priceRange"], gradient: "from-rose-500/10 to-orange-500/5", status: "online", category: "ai.analyze" }, { nameKey: "ai.patentMicroNav.name", tagKey: "ai.patentMicroNav.tag", descKey: "ai.patentMicroNav.desc", emoji: "🧭", tags: ["ai.tag.citationMap", "ai.tag.techBranches", "ai.tag.landscapeBrief"], gradient: "from-cyan-500/10 to-sky-500/5", status: "online", category: "ai.analyze" }, ]; const categories = ["ai.all", ...Array.from(new Set(agents.map((a) => a.category)))]; // Optional .env overrides: VITE_*_CHATBOT_URL for each bot (see vite-env.d.ts) const MEETING_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_MEETING_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chat/CjmrnoUyQKBa9wEP"; const DEEPSEEK_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_DEEPSEEK_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/pOcS3NYaXCkOP9K6"; const AISM_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_AISM_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/grHow5qCsnZd7PYq"; const ADMIN_ASSIST_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_ADMIN_ASSIST_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/FIIxbn1rsEtmw2Yt"; const STRATEGIC_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_STRATEGIC_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/bKP9rLpTdWQgWSLA"; const BIZPLAN_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_BIZPLAN_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/u0mmSsO0YCtjh37K"; const MARKET_REPORT_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_MARKET_REPORT_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/SqVX9saxCfTdJq6F"; const TECH_REPORT_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_TECH_REPORT_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/S8fdxgEVKa3V1kWb"; const PATENT_COMPARE_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_PATENT_COMPARE_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/tvX9ytDVu0BonRZp"; const ZONE_INSPECTION_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_ZONE_INSPECTION_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/RUeFYK8U6gt9cncx"; const TECH_PRICE_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_TECH_PRICE_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/VDLRBetGCViMjEEy"; const PATENT_MICRO_NAV_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_PATENT_MICRO_NAV_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/pU0QjcVNDaz0mBzJ"; // Override with VITE_FACTORY_SOURCING_CHATBOT_URL if this id is not your factory bot. const FACTORY_SOURCING_CHATBOT_IFRAME_SRC = (import.meta.env.VITE_FACTORY_SOURCING_CHATBOT_URL as string | undefined)?.trim() || "http://nw.sgcode.cn:18181/chatbot/OstO0weOb2iRy4Ng"; const CHATBOT_IFRAME_STYLE = { width: "100%", height: "100%", minHeight: 700, border: 0, } as const; type ChatSession = { src: string; title: string } | null; export default function AITools() { const { t, lang } = useLang(); const [activeCategory, setActiveCategory] = useState("ai.all"); const [searchQuery, setSearchQuery] = useState(""); const [chatSession, setChatSession] = useState(null); const [comingSoonOpen, setComingSoonOpen] = useState(false); const filteredAgents = agents.filter((agent) => { const matchesCategory = activeCategory === "ai.all" || agent.category === activeCategory; const matchesSearch = !searchQuery || t(agent.nameKey).toLowerCase().includes(searchQuery.toLowerCase()) || t(agent.descKey).toLowerCase().includes(searchQuery.toLowerCase()); return matchesCategory && matchesSearch; }); useEffect(() => { if (!chatSession) return; const html = document.documentElement; const body = document.body; const prevHtmlOverflow = html.style.overflow; const prevBodyOverflow = body.style.overflow; const scrollY = window.scrollY; html.style.overflow = "hidden"; body.style.overflow = "hidden"; body.style.position = "fixed"; body.style.top = `-${scrollY}px`; body.style.left = "0"; body.style.right = "0"; body.style.width = "100%"; const onKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") setChatSession(null); }; window.addEventListener("keydown", onKeyDown); return () => { html.style.overflow = prevHtmlOverflow; body.style.overflow = prevBodyOverflow; body.style.position = ""; body.style.top = ""; body.style.left = ""; body.style.right = ""; body.style.width = ""; window.removeEventListener("keydown", onKeyDown); window.scrollTo(0, scrollY); }; }, [chatSession]); return (
{/* Header */}
{t("ai.tag")}

{t("ai.title")}

{t("ai.subtitle")}

setSearchQuery(e.target.value)} className="w-full pl-10 pr-4 py-3 rounded-xl glass-card text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 placeholder:text-muted-foreground border-0" /> {searchQuery && ( setSearchQuery("")} > ✕ )}
{/* Category pills with animated indicator */} {categories.map((cat) => ( setActiveCategory(cat)} className={`relative px-4 py-2 rounded-xl text-xs font-medium transition-colors duration-200 ${ activeCategory === cat ? "text-background" : "glass-pill text-muted-foreground hover:text-foreground" }`} whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.97 }} > {activeCategory === cat && ( )} {t(cat)} ))} {/* Agent grid */} {filteredAgents.length === 0 && ( {lang === "zh" ? "没有找到匹配的智能体" : "No matching agents found"} )} {filteredAgents.map((agent, i) => ( = 3 ? "lg:col-span-2 lg:row-span-1" : "" }`} style={{ boxShadow: "none" }} > {/* Gradient header */}
{agent.emoji}
{agent.status}
{t(agent.tagKey)}
{t(agent.nameKey)}

{t(agent.descKey)}

{agent.tags.map((tag) => ( {t(tag)} ))}
))} {/* Portal modal with viewport padding (not full-bleed) */} {typeof document !== "undefined" && createPortal( {chatSession && ( setChatSession(null)} > e.stopPropagation()} >