/* eslint-disable react-dom/no-dangerously-set-innerhtml */ import type { PageAgent as PageAgentType } from 'page-agent' import { useEffect, useState } from 'react' import { Link, useSearchParams } from 'wouter' import { AnimatedGradientText } from '../../components/ui/animated-gradient-text' import { Highlighter } from '../../components/ui/highlighter' import { NeonGradientCard } from '../../components/ui/neon-gradient-card' import { Particles } from '../../components/ui/particles' import { CDN_DEMO_CN_URL, CDN_DEMO_URL, // DEMO_API_KEY, DEMO_BASE_URL, DEMO_MODEL, } from '../../constants' import { useLanguage } from '../../i18n/context' let pageAgentModule: Promise | null = null function getInjection(useCN?: boolean) { const cdn = useCN ? CDN_DEMO_CN_URL : CDN_DEMO_URL const injection = encodeURI( `javascript:(function(){var s=document.createElement('script');s.src=\`${cdn}?t=\${Math.random()}\`;s.setAttribute('crossorigin', true);s.type="text/javascript";s.onload=()=>console.log('PageAgent script loaded!');document.body.appendChild(s);})();` ) return ` ✨PageAgent ` } export default function HeroSection() { const { language, isZh } = useLanguage() const defaultTask = isZh ? '从导航栏中进入文档页,打开"快速开始"相关的文档,帮我总结成 markdown' : 'Goto docs in navigation bar, find Quick-Start section, and summarize in markdown' const [task, setTask] = useState(() => defaultTask) useEffect(() => { setTask(defaultTask) }, [defaultTask]) const [params] = useSearchParams() const isOther = params.has('try_other') const [activeTab, setActiveTab] = useState<'try' | 'other'>(isOther ? 'other' : 'try') const [cdnSource, setCdnSource] = useState<'international' | 'china'>('international') const [ready, setReady] = useState(false) useEffect(() => { pageAgentModule ??= import('page-agent') pageAgentModule.then(() => setReady(true)) }, []) const handleExecute = async () => { if (!task.trim() || !ready || !pageAgentModule) return const { PageAgent } = await pageAgentModule const win = window as any if (!win.pageAgent || win.pageAgent.disposed) { win.pageAgent = new (PageAgent as typeof PageAgentType)({ interactiveBlacklist: [document.getElementById('root')!], language: language, instructions: { system: 'You are a helpful assistant on PageAgent website.', getPageInstructions: (url: string) => { const hint = url.includes('page-agent') ? 'This is PageAgent demo page.' : undefined console.log('[instructions] getPageInstructions:', url, '->', hint) return hint }, }, model: import.meta.env.DEV && import.meta.env.LLM_MODEL_NAME ? import.meta.env.LLM_MODEL_NAME : DEMO_MODEL, baseURL: import.meta.env.DEV && import.meta.env.LLM_BASE_URL ? import.meta.env.LLM_BASE_URL : DEMO_BASE_URL, apiKey: import.meta.env.DEV && import.meta.env.LLM_API_KEY ? import.meta.env.LLM_API_KEY : undefined, }) } const result = await win.pageAgent.execute(task) console.log(result) } return (
{/* Background Pattern + Particles */}
AI Agent In Your Webpage

{isZh ? ( <> 你网站里的 AI 操作员 The AI Operator Living in Your Web Page ) : ( <> The AI Operator
Living in Your Web Page )}

{isZh ? '🪄一行代码' : '🪄One line of code'} {isZh ? ',让你的网站变身 AI 原生应用。' : ', turns your website into an AI-native app.'}
{isZh ? '用户/答疑机器人给出文字指示,AI 帮你操作页面。' : 'Users give natural language commands, AI handles the rest.'}

{/* Try It Now Section - Tab Card */}
{/* Tab Headers */}
{/* Tab Content */}
{activeTab === 'try' && (
setTask(e.target.value)} placeholder={ isZh ? '输入您想要 AI 执行的任务...' : 'Describe what you want AI to do...' } className="w-full px-4 py-3 pr-20 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none text-sm mb-0" data-page-agent-not-interactive />

{isZh ? ( <> 使用免费测试 LLM API,点击执行即表示您同意 使用条款 ) : ( <> Powered by free testing LLM API. By clicking Run you agree to the{' '} Terms of Use )}

)} {activeTab === 'other' && (
{/* 左侧:操作步骤 */}

{isZh ? '步骤 1:' : 'Step 1:'}{' '} {isZh ? '显示收藏夹栏' : 'Show your bookmarks bar'}

Ctrl + Shift + B {isZh ? '或' : 'or'} ⌘ + Shift + B

{isZh ? '步骤 2:' : 'Step 2:'}{' '} {isZh ? '拖拽下面按钮到收藏夹栏' : 'Drag this button to your bookmarks'}

{isZh ? '步骤 3:' : 'Step 3:'}{' '} {isZh ? '在其他网站点击收藏夹中的按钮即可使用' : 'Click the bookmark on any site to activate'}

{/* 右侧:注意事项 */}

{isZh ? '⚠️ 注意' : '⚠️ Heads Up'}

  • {isZh ? ( 使用免费测试 LLM API,使用即表示同意 使用条款 ) : ( Uses free testing LLM API. By using you agree to the{' '} Terms of Use )}
  • {isZh ? '数据通过中国大陆服务器处理' : 'Data processed via servers in Mainland China'}
  • {isZh ? '部分网站屏蔽了链接嵌入,将无反应' : 'Some sites block script injection (CSP policies)'}
  • {isZh ? '支持单页应用' : 'Works on single-page apps'}
  • {isZh ? '仅识别文本,不识别图像,不支持拖拽等复杂交互' : 'Text-only understanding—no image recognition or drag-and-drop'}
  • {isZh ? '详细使用限制参照' : 'Full limitations in'} {isZh ? '《文档》' : 'Docs'}
)}
  • {isZh ? '纯前端方案' : 'Pure Front-end Solution'}
  • {isZh ? '支持私有模型' : 'Your Own Models'}
  • {isZh ? '无痛脱敏' : 'Built-in Privacy'}
  • {isZh ? 'MIT 开源' : 'MIT Open Source'}
) }