import { useState, type ComponentProps } from 'react'; import { createRoot } from 'react-dom/client'; import { TeacherCompanion } from '../../../src/pages/Chat/TeacherCompanion'; import { AgentBrowserPanel } from '../../../src/pages/Chat/AgentBrowserPanel'; import '../../../src/styles/globals.css'; import '../../../src/pages/Chat/classroom-workspace.css'; // Render the production bubble and preview in an isolated browser. No Electron // window is launched, and no user project, provider, or live Host API is used. export function Layout() { const [bubble, setBubble] = useState(null); const [introduction, setIntroduction] = useState(null); const [visible, setVisible] = useState(!new URLSearchParams(location.search).has('quiet')); const [open, setOpen] = useState(false); const [width, setWidth] = useState(508); const [long, setLong] = useState(true); const count = Number(new URLSearchParams(location.search).get('agents') ?? 0); const [selected, setSelected] = useState(0); const agents = Array.from({ length: count }, (_, index) => ({ teacher_id: `agent-${index}`, version: index + 1, is_default: index === 0, definition: { config_id: `agent-${index}`, name: `智能体${index + 1}`, avatar_id: 'avatar-06', description: `我是智能体${index + 1},陪你把脑洞变成小作品。一起发现有趣的问题,也一起想清楚下一步怎么做。`, icon_url: new URLSearchParams(location.search).has('icons') ? `https://yuxi.example.test/api/storage/public/images/agent-${index}.png` : undefined }, })); const companion = { agents, selectedAgent: agents[selected], definition: agents[selected]?.definition ?? { name: '编程老师', avatar_id: 'avatar-06' }, invitation: visible ? { response: long ? '你刚才说想做一个宠物游戏。我们一起想想,什么样的小动作,会让你愿意一直陪它玩下去?可以先挑一个最想试的想法。' : '有什么编程问题想一起讨论?' } : null, welcome: null, enabled: true, loading: false, checking: false, error: null, dismiss: () => setVisible(false), } as ComponentProps['companion']; return
布局测试项目 › hello { if (id) setSelected(agents.findIndex((item) => item.teacher_id === id)); setOpen(true); }} onToggle={(id) => { if (!id || id === agents[selected]?.teacher_id) setOpen(!open); else { setSelected(agents.findIndex((item) => item.teacher_id === id)); setOpen(true); } }} bubbleRef={setBubble} introductionRef={setIntroduction} /> — □ ×
{}} />
{open && }
隔离布局测试:作品区域仅为占位,不连接真实项目
; } createRoot(document.getElementById('root')!).render();