feat: remove @page-agent/cdn
This commit is contained in:
13
AGENTS.md
13
AGENTS.md
@@ -10,7 +10,6 @@ This is a **monorepo** with npm workspaces:
|
|||||||
Internal packages:
|
Internal packages:
|
||||||
|
|
||||||
- **Core** (`packages/core/`) - PageAgentCore without UI (npm: `@page-agent/core`)
|
- **Core** (`packages/core/`) - PageAgentCore without UI (npm: `@page-agent/core`)
|
||||||
- **CDN** (`packages/cdn/`) - IIFE builds for script tag usage (npm: `@page-agent/cdn`)
|
|
||||||
- **LLMs** (`packages/llms/`) - LLM client with reflection-before-action mental model
|
- **LLMs** (`packages/llms/`) - LLM client with reflection-before-action mental model
|
||||||
- **Page Controller** (`packages/page-controller/`) - DOM operations and visual feedback (SimulatorMask), independent of LLM
|
- **Page Controller** (`packages/page-controller/`) - DOM operations and visual feedback (SimulatorMask), independent of LLM
|
||||||
- **UI** (`packages/ui/`) - Panel and i18n. Decoupled from PageAgent
|
- **UI** (`packages/ui/`) - Panel and i18n. Decoupled from PageAgent
|
||||||
@@ -32,9 +31,8 @@ Simple monorepo solution: TypeScript references + Vite aliases. Update tsconfig
|
|||||||
|
|
||||||
```
|
```
|
||||||
packages/
|
packages/
|
||||||
├── page-agent/ # npm: "page-agent" ⭐ MAIN (with Panel UI)
|
├── page-agent/ # npm: "page-agent" ⭐ MAIN (with Panel UI + IIFE builds)
|
||||||
├── core/ # npm: "@page-agent/core" (headless, no UI)
|
├── core/ # npm: "@page-agent/core" (headless, no UI)
|
||||||
├── cdn/ # npm: "@page-agent/cdn" (IIFE builds)
|
|
||||||
├── website/ # @page-agent/website (private)
|
├── website/ # @page-agent/website (private)
|
||||||
├── llms/ # @page-agent/llms
|
├── llms/ # @page-agent/llms
|
||||||
├── page-controller/ # @page-agent/page-controller
|
├── page-controller/ # @page-agent/page-controller
|
||||||
@@ -74,7 +72,7 @@ const pageInfo = await this.pageController.getPageInfo()
|
|||||||
3. **LLM Processing**: AI returns action plans (page-agent)
|
3. **LLM Processing**: AI returns action plans (page-agent)
|
||||||
4. **Indexed Operations**: PageAgent calls PageController by element index
|
4. **Indexed Operations**: PageAgent calls PageController by element index
|
||||||
|
|
||||||
### CDN Builds (`packages/cdn/`)
|
### IIFE Builds (`packages/page-agent/dist/iife/`)
|
||||||
|
|
||||||
Two IIFE builds for script tag usage:
|
Two IIFE builds for script tag usage:
|
||||||
|
|
||||||
@@ -85,14 +83,17 @@ Two IIFE builds for script tag usage:
|
|||||||
|
|
||||||
Demo build supports query params (e.g., `?model=gpt-4&lang=en-US`).
|
Demo build supports query params (e.g., `?model=gpt-4&lang=en-US`).
|
||||||
|
|
||||||
|
Build with `npm run build:iife --workspace=page-agent`.
|
||||||
|
|
||||||
## Key Files Reference
|
## Key Files Reference
|
||||||
|
|
||||||
### Page Agent (`packages/page-agent/`)
|
### Page Agent (`packages/page-agent/`)
|
||||||
|
|
||||||
| File | Description |
|
| File | Description |
|
||||||
| ------------------ | ---------------------------------------------- |
|
| ----------------------- | -------------------------------------------- |
|
||||||
| `src/PageAgent.ts` | ⭐ Main class with UI, extends PageAgentCore |
|
| `src/PageAgent.ts` | ⭐ Main class with UI, extends PageAgentCore |
|
||||||
| `src/iife.ts` | IIFE/CDN entry |
|
| `src/entry-iife.ts` | IIFE entry (exposes PageAgent class) |
|
||||||
|
| `src/entry-iife-demo.ts`| IIFE demo entry (auto-init with demo API) |
|
||||||
|
|
||||||
### Core (`packages/core/`)
|
### Core (`packages/core/`)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"packages/llms",
|
"packages/llms",
|
||||||
"packages/core",
|
"packages/core",
|
||||||
"packages/page-agent",
|
"packages/page-agent",
|
||||||
"packages/cdn",
|
|
||||||
"packages/website"
|
"packages/website"
|
||||||
],
|
],
|
||||||
"description": "AI-powered UI agent for web applications",
|
"description": "AI-powered UI agent for web applications",
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@page-agent/cdn",
|
|
||||||
"private": false,
|
|
||||||
"version": "0.2.5",
|
|
||||||
"type": "module",
|
|
||||||
"files": [
|
|
||||||
"dist/"
|
|
||||||
],
|
|
||||||
"description": "CDN builds for page-agent - IIFE bundles for script tag usage",
|
|
||||||
"author": "Simon<gaomeng1900>",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/alibaba/page-agent.git"
|
|
||||||
},
|
|
||||||
"homepage": "https://alibaba.github.io/page-agent/",
|
|
||||||
"scripts": {
|
|
||||||
"build": "vite build && vite build --mode demo"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"page-agent": "0.2.5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
/**
|
|
||||||
* Demo CDN build for page-agent
|
|
||||||
* Auto-initializes with built-in demo API for testing
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* <script src="https://unpkg.com/@page-agent/cdn/dist/page-agent.demo.js"></script>
|
|
||||||
*/
|
|
||||||
import { PageAgent } from 'page-agent'
|
|
||||||
|
|
||||||
// Clean up existing instances to prevent multiple injections from bookmarklet
|
|
||||||
if (window.pageAgent) {
|
|
||||||
window.pageAgent.dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount to global window object
|
|
||||||
window.PageAgent = PageAgent
|
|
||||||
|
|
||||||
// Export for IIFE
|
|
||||||
export { PageAgent }
|
|
||||||
|
|
||||||
console.log('🚀 page-agent.js loaded!')
|
|
||||||
|
|
||||||
const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
|
||||||
const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
|
|
||||||
// Demo warning
|
|
||||||
console.log(
|
|
||||||
'%c⚠️ DEMO MODE %c\n' +
|
|
||||||
'This build uses a shared testing LLM with rate limits.\n' +
|
|
||||||
'For production, use page-agent.js with your own API key:\n' +
|
|
||||||
'https://alibaba.github.io/page-agent/#/docs/features/models',
|
|
||||||
'background: #f59e0b; color: #000; font-size: 14px; font-weight: bold; padding: 4px 8px; border-radius: 4px;',
|
|
||||||
'color: #f59e0b; font-size: 12px;'
|
|
||||||
)
|
|
||||||
|
|
||||||
// in case document.x is not ready yet
|
|
||||||
setTimeout(() => {
|
|
||||||
const currentScript = document.currentScript
|
|
||||||
|
|
||||||
if (currentScript) {
|
|
||||||
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
|
||||||
const url = new URL(currentScript.src)
|
|
||||||
const model = url.searchParams.get('model') || DEMO_MODEL
|
|
||||||
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
|
||||||
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
|
||||||
const language = url.searchParams.get('lang') || 'zh-CN'
|
|
||||||
const config = { model, baseURL, apiKey, language }
|
|
||||||
window.pageAgent = new PageAgent(config)
|
|
||||||
} else {
|
|
||||||
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
|
||||||
const config = {
|
|
||||||
model: DEMO_MODEL,
|
|
||||||
baseURL: DEMO_BASE_URL,
|
|
||||||
apiKey: DEMO_API_KEY,
|
|
||||||
}
|
|
||||||
window.pageAgent = new PageAgent(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
|
||||||
|
|
||||||
window.pageAgent.panel.show()
|
|
||||||
})
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
/**
|
|
||||||
* Full CDN build for page-agent
|
|
||||||
* Exposes PageAgent class for manual instantiation and configuration
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* <script src="https://unpkg.com/@page-agent/cdn/dist/page-agent.js"></script>
|
|
||||||
* <script>
|
|
||||||
* const agent = new PageAgent({ model: 'gpt-4o', apiKey: 'your-key' })
|
|
||||||
* agent.panel.show()
|
|
||||||
* </script>
|
|
||||||
*/
|
|
||||||
import { PageAgent } from 'page-agent'
|
|
||||||
|
|
||||||
export { PageAgent }
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { dirname, resolve } from 'path'
|
|
||||||
import { fileURLToPath } from 'url'
|
|
||||||
import { defineConfig } from 'vite'
|
|
||||||
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CDN IIFE builds for page-agent
|
|
||||||
*
|
|
||||||
* Build targets (via --mode):
|
|
||||||
* - demo: page-agent.demo.js with auto-init and built-in API
|
|
||||||
* - full (default): page-agent.js exposes PageAgent class only
|
|
||||||
*/
|
|
||||||
export default defineConfig(({ mode }) => {
|
|
||||||
const isDemo = mode === 'demo'
|
|
||||||
const entry = isDemo ? resolve(__dirname, 'src/demo.js') : resolve(__dirname, 'src/full.js')
|
|
||||||
const fileName = isDemo ? 'page-agent.demo' : 'page-agent'
|
|
||||||
|
|
||||||
return {
|
|
||||||
plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })],
|
|
||||||
publicDir: false,
|
|
||||||
esbuild: {
|
|
||||||
keepNames: true,
|
|
||||||
},
|
|
||||||
build: {
|
|
||||||
lib: {
|
|
||||||
entry,
|
|
||||||
name: 'PageAgent',
|
|
||||||
fileName: () => `${fileName}.js`,
|
|
||||||
formats: ['iife'],
|
|
||||||
},
|
|
||||||
outDir: resolve(__dirname, 'dist'),
|
|
||||||
emptyOutDir: !isDemo, // only empty on first build (full)
|
|
||||||
minify: false,
|
|
||||||
cssCodeSplit: true,
|
|
||||||
rollupOptions: {
|
|
||||||
onwarn: function (message, handler) {
|
|
||||||
if (message.code === 'EVAL') return
|
|
||||||
handler(message)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
define: {
|
|
||||||
'process.env.NODE_ENV': '"production"',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -37,8 +37,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://alibaba.github.io/page-agent/",
|
"homepage": "https://alibaba.github.io/page-agent/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build && npm run build:iife && npm run build:demo",
|
||||||
"dev:iife": "concurrently \"vite build --config vite.iife.config.js --watch\" \"npx serve dist/iife -p 5174\"",
|
"build:iife": "vite build --config vite.iife.config.js",
|
||||||
|
"build:demo": "vite build --config vite.iife.config.js --mode demo",
|
||||||
|
"dev:iife": "concurrently \"vite build --config vite.iife.config.js --watch --mode demo\" \"npx serve dist/iife -p 5174\"",
|
||||||
"prepublishOnly": "node -e \"const fs=require('fs');['README.md','LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
"prepublishOnly": "node -e \"const fs=require('fs');['README.md','LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
||||||
"postpublish": "node -e \"['README.md','LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
"postpublish": "node -e \"['README.md','LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Auto-run entry for page-agent.js. Insert this script into your page to get page-agent functionality.
|
* IIFE demo entry - auto-initializes with built-in demo API for testing
|
||||||
*/
|
*/
|
||||||
import { Panel } from '@page-agent/ui'
|
import { PageAgent, type PageAgentConfig } from '../PageAgent'
|
||||||
|
|
||||||
import { PageAgent, type PageAgentConfig } from './PageAgent'
|
|
||||||
|
|
||||||
// Clean up existing instances to prevent multiple injections from bookmarklet
|
// Clean up existing instances to prevent multiple injections from bookmarklet
|
||||||
if (window.pageAgent) {
|
if (window.pageAgent) {
|
||||||
@@ -13,9 +11,6 @@ if (window.pageAgent) {
|
|||||||
// Mount to global window object
|
// Mount to global window object
|
||||||
window.PageAgent = PageAgent
|
window.PageAgent = PageAgent
|
||||||
|
|
||||||
// Export for ES module usage
|
|
||||||
// export { PageAgent }
|
|
||||||
|
|
||||||
console.log('🚀 page-agent.js loaded!')
|
console.log('🚀 page-agent.js loaded!')
|
||||||
|
|
||||||
const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
9
packages/page-agent/src/iife/page-agent.ts
Normal file
9
packages/page-agent/src/iife/page-agent.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* IIFE entry
|
||||||
|
*/
|
||||||
|
import { PageAgent } from '../PageAgent'
|
||||||
|
|
||||||
|
// Mount to global window object
|
||||||
|
window.PageAgent = PageAgent
|
||||||
|
|
||||||
|
export { PageAgent }
|
||||||
@@ -14,7 +14,14 @@ dotenvConfig({ path: resolve(__dirname, '../../.env') })
|
|||||||
// - alias all local packages so that they can be build in
|
// - alias all local packages so that they can be build in
|
||||||
// - no external
|
// - no external
|
||||||
// - no d.ts. dts does not work with monorepo aliasing
|
// - no d.ts. dts does not work with monorepo aliasing
|
||||||
export default defineConfig(({ mode }) => ({
|
export default defineConfig(({ mode }) => {
|
||||||
|
const isDemo = mode === 'demo'
|
||||||
|
const entry = isDemo
|
||||||
|
? resolve(__dirname, 'src/iife/page-agent.demo.ts')
|
||||||
|
: resolve(__dirname, 'src/iife/page-agent.ts')
|
||||||
|
const fileName = isDemo ? 'page-agent.demo' : 'page-agent'
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })],
|
plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })],
|
||||||
publicDir: false,
|
publicDir: false,
|
||||||
esbuild: {
|
esbuild: {
|
||||||
@@ -22,7 +29,10 @@ export default defineConfig(({ mode }) => ({
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@page-agent/page-controller': resolve(__dirname, '../page-controller/src/PageController.ts'),
|
'@page-agent/page-controller': resolve(
|
||||||
|
__dirname,
|
||||||
|
'../page-controller/src/PageController.ts'
|
||||||
|
),
|
||||||
'@page-agent/llms': resolve(__dirname, '../llms/src/index.ts'),
|
'@page-agent/llms': resolve(__dirname, '../llms/src/index.ts'),
|
||||||
'@page-agent/core': resolve(__dirname, '../core/src/PageAgentCore.ts'),
|
'@page-agent/core': resolve(__dirname, '../core/src/PageAgentCore.ts'),
|
||||||
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
||||||
@@ -30,19 +40,20 @@ export default defineConfig(({ mode }) => ({
|
|||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'src/iife.ts'),
|
entry,
|
||||||
name: 'PageAgent',
|
name: 'PageAgent',
|
||||||
fileName: 'page-agent',
|
fileName: () => `${fileName}.js`,
|
||||||
formats: ['iife'],
|
formats: ['iife'],
|
||||||
},
|
},
|
||||||
outDir: resolve(__dirname, 'dist', 'iife'),
|
outDir: resolve(__dirname, 'dist', 'iife'),
|
||||||
|
emptyOutDir: !isDemo, // only empty on first build
|
||||||
cssCodeSplit: true,
|
cssCodeSplit: true,
|
||||||
minify: false,
|
minify: false,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
// output: {
|
||||||
// force use .js as extension
|
// // force use .js as extension
|
||||||
entryFileNames: 'page-agent.js',
|
// entryFileNames: 'page-agent.js',
|
||||||
},
|
// },
|
||||||
onwarn: function (message, handler) {
|
onwarn: function (message, handler) {
|
||||||
if (message.code === 'EVAL') return
|
if (message.code === 'EVAL') return
|
||||||
handler(message)
|
handler(message)
|
||||||
@@ -54,4 +65,5 @@ export default defineConfig(({ mode }) => ({
|
|||||||
'import.meta.env.LLM_API_KEY': JSON.stringify(process.env.LLM_API_KEY),
|
'import.meta.env.LLM_API_KEY': JSON.stringify(process.env.LLM_API_KEY),
|
||||||
'import.meta.env.LLM_BASE_URL': JSON.stringify(process.env.LLM_BASE_URL),
|
'import.meta.env.LLM_BASE_URL': JSON.stringify(process.env.LLM_BASE_URL),
|
||||||
},
|
},
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Suspense, lazy } from 'react'
|
import { Suspense, lazy } from 'react'
|
||||||
import { Route, Switch } from 'wouter'
|
import { Route, Switch } from 'wouter'
|
||||||
|
|
||||||
// Lazy load pages
|
import HomePage from './pages/Home'
|
||||||
const HomePage = lazy(() => import('./pages/Home'))
|
import DocsPages from './pages/docs/index'
|
||||||
const DocsPages = lazy(() => import('./pages/docs/index'))
|
|
||||||
|
// const DocsPages = lazy(() => import('./pages/docs/index'))
|
||||||
|
|
||||||
export default function Router() {
|
export default function Router() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user