import { ArrowUpRight, Loader2, RefreshCw, X } from 'lucide-react'; import { useState, type CSSProperties, type Ref } from 'react'; import { Provider as TooltipProvider } from '@radix-ui/react-tooltip'; import { TeacherAvatar } from './TeacherAvatar'; import { TeacherIntroduction } from './TeacherIntroduction'; import type { useTeacherCompanion } from './use-teacher-companion'; type Companion = ReturnType; export function TeacherCompanion({ companion, open, onOpen, onToggle, bubbleRef, introductionRef }: { companion: Companion; open: boolean; onOpen(agentId?: string): void; onToggle?(agentId?: string): void; bubbleRef?: Ref; introductionRef?: Ref; }) { const { definition, invitation, welcome, welcomes, loading, enabled, checking, error } = companion; const [introductionId, setIntroductionId] = useState(null); const introductionProps = (id: string) => ({ open: introductionId === id, onOpenChange: (next: boolean) => setIntroductionId((current) => next ? id : current === id ? null : current), }); const name = definition?.name || '智能体'; const activeId = companion.selectedAgent?.teacher_id; const agents = companion.selectedAgent && !companion.agents.some((item) => item.teacher_id === activeId) ? [...companion.agents, companion.selectedAgent] : companion.agents; const viewConversation = () => { companion.dismiss(); onOpen(); }; const meetTeacher = (agentId: string) => { setIntroductionId(null); companion.dismissWelcomes(); onOpen(agentId); }; const status = loading ? '正在连接智能体…' : checking ? '智能体在看看你最近的进展…' : error || (!enabled ? '智能体暂未开放,仍可查看以往讨论' : open ? '我们慢慢聊,想到什么都可以说' : '点我聊聊,想到什么都可以说'); const refreshMessage = companion.refreshing ? '正在刷新…' : companion.refreshStatus === 'error' ? '刷新失败,请重试' : companion.refreshStatus === 'success' ? '已更新' : ''; return (
{refreshMessage} {!invitation && welcomes.length > 0 &&
{welcomes.map((item, index) =>
)}
} {(invitation || welcome) &&
{name}

{invitation?.response ?? welcome}

}
); }