"use client"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { apiFetch } from "@/lib/api"; import { AgentChat } from "@/components/agent-chat"; interface CurrentUser { user_type?: string; employee_role?: string | null; } export function AgentMount() { const pathname = usePathname(); const [employee, setEmployee] = useState(false); useEffect(() => { if (!pathname.startsWith("/admin")) return; void apiFetch<{ user: CurrentUser }>("/auth/me") .then(({ user }) => { const advisorRole = user.employee_role === "投顾" || user.employee_role === "投顾专员" || user.employee_role === "ADMIN"; setEmployee((user.user_type === "EMPLOYEE" || user.user_type === "ADMIN") && advisorRole); }) .catch(() => setEmployee(false)); }, [pathname]); if (pathname.startsWith("/admin") && employee) return ; if (pathname.startsWith("/admin")) return null; return ; }