From 53c2c19d694df7835a9d97a34183af9c09010f66 Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Wed, 4 Mar 2026 21:13:10 +0800 Subject: [PATCH] docs: update advanced docs; rm best-practice --- .../api-reference.tsx => APIReference.tsx} | 20 +- .../website/src/components/CodeEditor.tsx | 2 +- packages/website/src/pages/docs/Layout.tsx | 9 +- .../pages/docs/advanced/custom-ui/page.tsx | 2 +- .../docs/advanced/page-agent-core/page.tsx | 269 ++++++---------- .../pages/docs/advanced/page-agent/page.tsx | 104 +++---- .../docs/advanced/page-controller/page.tsx | 286 ++++++++++++++++++ .../security-permissions/page.tsx | 0 .../third-party-agent/page.tsx | 21 -- packages/website/src/pages/docs/index.tsx | 28 +- .../docs/integration/best-practices/page.tsx | 20 -- .../docs/introduction/limitations/page.tsx | 42 ++- packages/website/vite.config.js | 6 +- 13 files changed, 480 insertions(+), 329 deletions(-) rename packages/website/src/components/{ui/api-reference.tsx => APIReference.tsx} (91%) create mode 100644 packages/website/src/pages/docs/advanced/page-controller/page.tsx rename packages/website/src/pages/docs/{integration => advanced}/security-permissions/page.tsx (100%) rename packages/website/src/pages/docs/{integration => features}/third-party-agent/page.tsx (85%) delete mode 100644 packages/website/src/pages/docs/integration/best-practices/page.tsx diff --git a/packages/website/src/components/ui/api-reference.tsx b/packages/website/src/components/APIReference.tsx similarity index 91% rename from packages/website/src/components/ui/api-reference.tsx rename to packages/website/src/components/APIReference.tsx index a505cd6..6b6f651 100644 --- a/packages/website/src/components/ui/api-reference.tsx +++ b/packages/website/src/components/APIReference.tsx @@ -5,10 +5,9 @@ */ import * as React from 'react' +import { Badge } from '@/components/ui/badge' import { cn } from '@/lib/utils' -import { Badge } from './badge' - // ============================================================================ // Types // ============================================================================ @@ -35,6 +34,8 @@ export interface APIReferenceProps { description?: React.ReactNode /** Property definitions */ properties: PropDefinition[] + /** Display variant: 'properties' for fields, 'methods' for methods */ + variant?: 'properties' | 'methods' /** Additional CSS classes */ className?: string } @@ -43,7 +44,14 @@ export interface APIReferenceProps { // Component // ============================================================================ -export function APIReference({ title, description, properties, className }: APIReferenceProps) { +export function APIReference({ + title, + description, + properties, + variant = 'properties', + className, +}: APIReferenceProps) { + const isMethodsVariant = variant === 'methods' return (
+
{type}
{isZh - ? '配置与大语言模型的连接参数。支持 OpenAI 兼容的 API。' - : 'Configure connection parameters for the language model. Supports OpenAI-compatible APIs.'} + ? 'PageAgentCoreConfig = AgentConfig & { pageController: PageController }。AgentConfig 包含以下配置项:' + : 'PageAgentCoreConfig = AgentConfig & { pageController: PageController }. AgentConfig contains the following options:'}
+ + {/* PageController */} +- {isZh - ? '配置 Agent 的行为、生命周期钩子和扩展能力。' - : 'Configure agent behavior, lifecycle hooks, and extension capabilities.'} -
+ {/* Agent Config */} +- ⚠️ {isZh ? '警告' : 'Warning'}:{' '} {isZh - ? '这些接口高度实验性,可能在未来版本中发生变化。建议优先使用事件系统(Events)来监听 Agent 状态。' - : 'These APIs are highly experimental and may change in future versions. Prefer using the Events system for monitoring agent state.'} + ? '这些接口高度实验性,可能在未来版本中发生变化。' + : 'These APIs are highly experimental and may change in future versions. '}
- {isZh - ? '所有生命周期钩子都接收 agent 实例作为第一个参数,便于在回调中访问 Agent 状态和方法。' - : 'All lifecycle hooks receive the agent instance as first parameter, making it easy to access agent state and methods in callbacks.'} -
- {isZh - ? '配置 DOM 提取、元素交互和视觉反馈。' - : 'Configure DOM extraction, element interaction, and visual feedback.'} -
-- {isZh - ? '在非 DOM 环境中,你必须实现自定义的 PageController(例如远程操作页面或 Puppeteer)。' - : 'In non-DOM environments, you must implement a custom PageController (e.g., remote page control or Puppeteer).'} -
+{isZh - ? 'PageAgent 是带有内置 UI 面板的完整 Agent 类。它继承自 PageAgentCore,并自动创建交互面板。' - : 'PageAgent is the complete Agent class with built-in UI panel. It extends PageAgentCore and automatically creates an interactive panel.'} + ? 'PageAgent 是带有内置 UI 面板的完整 Agent 类。它继承自 PageAgentCore,并自动创建交互面板和 PageController。' + : 'PageAgent is the complete Agent class with built-in UI panel. It extends PageAgentCore and automatically creates an interactive panel and PageController.'}
{/* When to use */} @@ -29,6 +28,11 @@ export default function PageAgentDocs() { : 'In most cases, you should use PageAgent. It provides a complete out-of-the-box experience:'}- {isZh - ? 'PageAgent 使用与 PageAgentCore 相同的配置接口。' - : 'PageAgent uses the same configuration interface as PageAgentCore.'} -
-- {isZh ? ( - <> - 完整配置请参考{' '} + . All core methods and events are available. Config merges{' '} - PageAgentCore 配置文档 - - 。 - > - ) : ( - <> - See{' '} - - PageAgentCore configuration docs + AgentConfig {' '} - for complete reference. + and{' '} + + PageControllerConfig + + . > )}
{isZh - ? 'PageAgent 自动创建一个 Panel 实例。你可以通过 panel 属性访问它来控制 UI:' - : 'PageAgent automatically creates a Panel instance. You can access it via the panel property to control the UI:'} + ? 'PageAgent 自动创建一个 Panel 实例。你可以通过 panel 属性控制 UI:' + : 'PageAgent automatically creates a Panel instance. You can control the UI via the panel property:'}
- -+ {isZh + ? 'PageController 负责 DOM 提取和元素交互,独立于 LLM。它将页面状态结构化为 LLM 可消费的格式,并执行元素级操作。' + : 'PageController handles DOM extraction and element interaction, independent of LLM. It structures page state into LLM-consumable format and executes element-level actions.'} +
+ + {/* Basic Usage */} ++ {isZh + ? 'PageAgent 接受 PageController 配置项:' + : 'PageAgent accepts PageController options:'} +
++ {isZh + ? 'PageAgentCore 接受 PageController 实例:' + : 'PageAgentCore accepts a PageController instance:'} +
++ {isZh + ? 'getBrowserState() 返回的结构化浏览器状态,直接用于构建 LLM prompt。' + : 'Structured browser state returned by getBrowserState(), used directly to build LLM prompts.'} +
++ {isZh + ? '在非浏览器环境(如 Puppeteer、Playwright),你可以实现自定义 PageController。需要实现 Agent 使用的核心方法:' + : 'In non-browser environments (e.g. Puppeteer, Playwright), you can implement a custom PageController. Implement the core methods used by the agent:'} +
+- {isZh - ? '使用 page-agent 的最佳实践和常见问题解决方案。' - : 'Best practices and common solutions for using page-agent.'} -
-- {isZh - ? 'Page Agent 不使用多模态模型,不截图,没有视觉能力。仅通过 DOM 结构理解页面。' - : 'Page Agent does not use multimodal models, does not take screenshots, and has no visual capability. It reads pages through DOM structure only.'} -
-- {isZh - ? '图片、Canvas、WebGL、SVG 等视觉内容无法被识别。页面的语义化程度和可访问性直接影响 AI 的理解准确性。' - : 'Images, Canvas, WebGL, SVG and other visual content cannot be recognized. Page semantic quality and accessibility directly affect AI accuracy.'} -
-- {isZh - ? '反常识的交互逻辑、纯视觉的操作提示、快速出现消失的元素等都会降低自动化成功率。语义化的 HTML 和良好的可访问性会显著提升效果。' - : 'Counter-intuitive interactions, visual-only cues, and rapidly appearing/disappearing elements reduce automation success. Semantic HTML and good accessibility significantly improve results.'} -
-+ {isZh + ? 'Page Agent 不使用多模态模型,不截图,没有视觉能力。仅通过 DOM 结构理解页面。' + : 'Page Agent does not use multimodal models, does not take screenshots, and has no visual capability. It reads pages through DOM structure only.'} +
++ {isZh + ? '图片、Canvas、WebGL、SVG 等视觉内容无法被识别。页面的语义化程度和可访问性直接影响 AI 的理解准确性。' + : 'Images, Canvas, WebGL, SVG and other visual content cannot be recognized. Page semantic quality and accessibility directly affect AI accuracy.'} +
++ {isZh + ? '反常识的交互逻辑、纯视觉的操作提示、快速出现消失的元素等都会降低自动化成功率。语义化的 HTML 和良好的可访问性会显著提升效果。' + : 'Counter-intuitive interactions, visual-only cues, and rapidly appearing/disappearing elements reduce automation success. Semantic HTML and good accessibility significantly improve results.'} +
) diff --git a/packages/website/vite.config.js b/packages/website/vite.config.js index 09683dc..d200751 100644 --- a/packages/website/vite.config.js +++ b/packages/website/vite.config.js @@ -27,12 +27,12 @@ const SPA_ROUTES = [ 'docs/features/custom-instructions', 'docs/features/models', 'docs/features/chrome-extension', + 'docs/features/third-party-agent', 'docs/advanced/page-agent', 'docs/advanced/page-agent-core', + 'docs/advanced/page-controller', 'docs/advanced/custom-ui', - 'docs/integration/security-permissions', - 'docs/integration/best-practices', - 'docs/integration/third-party-agent', + 'docs/advanced/security-permissions', ] function spaRoutes() {