feat: update pages

This commit is contained in:
Simon
2025-10-21 22:02:51 +08:00
parent e81291f54b
commit 55a3ce16e5
3 changed files with 92 additions and 33 deletions

View File

@@ -6,8 +6,6 @@ export default function CdnSetup() {
<div>
<h1 className="text-4xl font-bold mb-6">CDN </h1>
<BetaNotice />
<p className="text-xl text-gray-600 dark:text-gray-300 mb-6 leading-relaxed">
CDN page-agent
</p>
@@ -16,13 +14,12 @@ export default function CdnSetup() {
<CodeEditor
className="mb-8"
code={`<!-- 在 HTML 中引入 -->
// @todo find a cdn
<script src="https://some-cdn.com/page-agent.umd.js"></script>
code={`
// 仅供测试使用,稳定 CDN 待定
<script src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.2/page-agent.js" crossorigin="true" type="text/javascript"></script>
<script>
const pageAgent = new PageAgent()
pageAgent.panel.show()
window.pageAgent.panel.show()
</script>`}
/>

View File

@@ -1,4 +1,3 @@
import BetaNotice from '@pages/components/BetaNotice'
import CodeEditor from '@pages/components/CodeEditor'
export default function Configuration() {
@@ -6,33 +5,96 @@ export default function Configuration() {
<div>
<h1 className="text-4xl font-bold mb-6"></h1>
<BetaNotice />
<CodeEditor
className="mb-8"
language="typescript"
code={`// config
type PageAgentConfig = LLMConfig & AgentConfig & DomConfig
<p className="text-xl text-foreground/80 mb-6 leading-relaxed">
page-agent
</p>
interface LLMConfig {
baseURL?: string
apiKey?: string
model?: string
temperature?: number
maxTokens?: number
maxRetries?: number
}
<h2 className="text-2xl font-bold mb-3"></h2>
interface AgentConfig {
language?: "en-US" | "zh-CN"
<CodeEditor className="mb-8" code={`// TODO`} />
/**
* Custom tools to extend PageAgent capabilities
* @experimental
* @note You can also override or remove internal tools by using the same name.
* @see [tools](../tools/index.ts)
*
* @example
* // override internal tool
* import { tool } from 'page-agent'
* const customTools = {
* ask_user: tool({
* description:
* 'Ask the user or parent model a question and wait for their answer. Use this if you need more information or clarification.',
* inputSchema: zod.object({
* question: zod.string(),
* }),
* execute: async function (this: PageAgent, input) {
* const answer = await do_some_thing(input.question)
* return "✅ Received user answer: " + answer
* },
* })
* }
*
* @example
* // remove internal tool
* const customTools = {
* ask_user: null // never ask user questions
* }
*/
customTools?: Record<string, PageAgentTool | null>
<h2 className="text-2xl font-bold mb-3"></h2>
// lifecycle hooks
// @todo: use event instead of hooks
<div className="space-y-4">
<div className="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg">
<h3 className="text-lg font-semibold mb-2 text-blue-900 dark:text-blue-300">
🎯
</h3>
<p className="text-foreground/80"> AI </p>
</div>
onBeforeStep?: (this: PageAgent, stepCnt: number) => Promise<void> | void
onAfterStep?: (this: PageAgent, stepCnt: number, history: AgentHistory[]) => Promise<void> | void
onBeforeTask?: (this: PageAgent) => Promise<void> | void
onAfterTask?: (this: PageAgent, result: ExecutionResult) => Promise<void> | void
<div className="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg">
<h3 className="text-lg font-semibold mb-2 text-green-900 dark:text-green-300">
</h3>
<p className="text-foreground/80"></p>
</div>
</div>
/**
* @note this hook can block the disposal process
* @note when dispose caused by page unload, "reason" will be 'PAGE_UNLOADING'. this method CANNOT block unloading. async operations may be cut.
*/
onDispose?: (this: PageAgent, reason?: string) => void
// page behavior hooks
/**
* TODO: @unimplemented
* hook when action causes a new page to be opened
* @note PageAgent will try to detect new pages and decide if it's caused by an action. But not very reliable.
*/
onNewPageOpen?: (this: PageAgent, url: string) => Promise<void> | void
/**
* TODO: @unimplemented
* try to navigate to a new page instead of opening a new tab/window.
* @note will unload the current page when a action tries to open a new page. so that things keep in the same tab/window.
*/
experimentalPreventNewPage?: boolean
}
interface DomConfig {
interactiveBlacklist?: (Element | (() => Element))[]
interactiveWhitelist?: (Element | (() => Element))[]
include_attributes?: string[]
highlightOpacity?: number
highlightLabelOpacity?: number
}
`}
/>
</div>
)
}