import { APIDivider, APIReference } from '@/components/APIReference' import CodeEditor from '@/components/CodeEditor' import { Heading } from '@/components/Heading' import { useLanguage } from '@/i18n/context' export default function CustomUIDocs() { const { isZh } = useLanguage() return (

{isZh ? '自定义 UI' : 'Custom UI'}

{isZh ? 'PageAgent 的核心逻辑(PageAgentCore)和 UI 完全解耦,通过事件通讯。你可以用自己的 UI 替换内置 Panel。' : 'PageAgent core logic (PageAgentCore) is fully decoupled from UI through events. You can replace the built-in Panel with your own UI.'}

{/* Architecture */}
{isZh ? '架构' : 'Architecture'}

{isZh ? 'PageAgent 由三个独立模块组成,可自由组合:' : 'PageAgent consists of three independent modules that can be freely combined:'}

{/* Two Event Streams */}
{isZh ? '两个事件流' : 'Two Event Streams'}

{isZh ? 'PageAgentCore 提供两种不同性质的事件流,方便 UI 渲染:' : 'PageAgentCore provides two distinct event streams for UI rendering:'}

{/* Comparison Table */}
Historical Events Activity Events
{isZh ? '事件名' : 'Event Name'} historychange activity
{isZh ? '持久性' : 'Persistence'} {isZh ? '持久化到 agent.history' : 'Persisted in agent.history'} {isZh ? '瞬态' : 'Transient'}
{isZh ? '传给 LLM' : 'Sent to LLM'} {isZh ? '是' : 'Yes'} {isZh ? '否' : 'No'}
{isZh ? '用途' : 'Purpose'} {isZh ? '构成 Agent 记忆,显示历史步骤' : 'Forms agent memory, displays history'} {isZh ? '实时 UI 反馈(如 loading 状态)' : 'Real-time UI feedback (e.g., loading state)'}
{/* All Events */}
{isZh ? '所有事件' : 'All Events'} ', description: isZh ? '实时活动反馈:thinking, executing, executed, retrying, error' : 'Real-time activity: thinking, executing, executed, retrying, error', }, { name: 'dispose', type: 'Event', description: isZh ? 'Agent 被销毁' : 'Agent is disposed', }, ]} />
{/* HistoricalEvent Types */}
HistoricalEvent

{isZh ? 'agent.history 数组中的事件类型:' : 'Event types in agent.history array:'}

{/* AgentActivity Types */}
AgentActivity

{isZh ? 'activity 事件的 detail 类型:' : 'The detail type of activity events:'}

{/* React Hooks Example */}
{isZh ? '使用 React Hooks' : 'Using React Hooks'}

{isZh ? '监听事件并更新 React 状态:' : 'Listen to events and update React state:'}

(null) useEffect(() => { const onStatus = () => setStatus(agent.status) const onHistory = () => setHistory([...agent.history]) const onActivity = (e: Event) => setActivity((e as CustomEvent).detail) agent.addEventListener('statuschange', onStatus) agent.addEventListener('historychange', onHistory) agent.addEventListener('activity', onActivity) return () => { agent.removeEventListener('statuschange', onStatus) agent.removeEventListener('historychange', onHistory) agent.removeEventListener('activity', onActivity) } }, [agent]) return { status, history, activity } }`} />
{/* Assembly Example */}
{isZh ? '组装 Core + Controller + 自定义 UI' : 'Assembling Core + Controller + Custom UI'}

{isZh ? '参考内置 PageAgent 的实现方式,用自定义 UI 替换 Panel:' : 'Following the built-in PageAgent pattern, replace Panel with custom UI:'}

) // 4. Handle user input (optional) agent.onAskUser = async (question) => window.prompt(question) || '' // 5. Execute task await agent.execute('Fill the form with test data') // 6. Cleanup agent.dispose()`} />
) }