Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b36a0c0261 | |||
| 339b066d2d | |||
| c8efffa80a | |||
| 59235263ad | |||
| bc1e8fea3c | |||
| 85a4096b2d | |||
| 0ef84bac13 | |||
| a7834c77e1 | |||
| 030e5cfc54 | |||
| aa694e3b85 | |||
| 2fee2d5ea3 | |||
| 3082843810 | |||
| 34098e2f66 | |||
| 8461006c91 | |||
| 2e76a35188 | |||
| abc96b415f | |||
| 77ce3b0b49 | |||
| 3742f75d14 | |||
| c2e9e6a571 | |||
| 54eb50f7be | |||
| 9351948794 | |||
| 68d1a10dd0 | |||
| b9fe8146b6 | |||
| 2a727226bc | |||
| 0167377b2f |
@@ -25,7 +25,7 @@ jobs:
|
|||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build demo
|
- name: Build demo
|
||||||
run: npm run build
|
run: npm run build:website
|
||||||
|
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
uses: actions/configure-pages@v5
|
uses: actions/configure-pages@v5
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ jobs:
|
|||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build:libs
|
||||||
|
|
||||||
- name: Publish all public packages
|
- name: Publish all public packages
|
||||||
run: npm publish --workspaces --access public
|
run: npm publish --workspaces --access public
|
||||||
@@ -7,9 +7,10 @@ This is a **monorepo** with npm workspaces containing **two main packages**:
|
|||||||
1. **Core Library** (`packages/page-agent/`) - Pure JavaScript/TypeScript AI agent library for browser DOM automation, published as `page-agent` on npm
|
1. **Core Library** (`packages/page-agent/`) - Pure JavaScript/TypeScript AI agent library for browser DOM automation, published as `page-agent` on npm
|
||||||
2. **Website** (`packages/website/`) - React documentation and landing page. Also as demo and test page for the core lib. private package `@page-agent/website`
|
2. **Website** (`packages/website/`) - React documentation and landing page. Also as demo and test page for the core lib. private package `@page-agent/website`
|
||||||
|
|
||||||
And other internal packages. Such as:
|
And other internal packages:
|
||||||
|
|
||||||
- **Page Controller** (`packages/page-controller/`) - DOM operations and element interactions module. Independent of LLM, can be tested in unit tests.
|
- **Page Controller** (`packages/page-controller/`) - DOM operations and element interactions. Independent of LLM.
|
||||||
|
- **UI** (`packages/ui/`) - Panel, SimulatorMask, and i18n. Decoupled from PageAgent.
|
||||||
|
|
||||||
## Development Commands
|
## Development Commands
|
||||||
|
|
||||||
@@ -18,22 +19,11 @@ And other internal packages. Such as:
|
|||||||
```bash
|
```bash
|
||||||
npm start # Start website dev server
|
npm start # Start website dev server
|
||||||
npm run build # Build all packages
|
npm run build # Build all packages
|
||||||
npm run build:lib # Build page-agent library only
|
npm run build:libs # Build all libraries
|
||||||
|
npm run build:website # Build the website
|
||||||
npm run lint # ESLint with TypeScript strict rules
|
npm run lint # ESLint with TypeScript strict rules
|
||||||
```
|
```
|
||||||
|
|
||||||
### Package-specific Commands
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Core library
|
|
||||||
npm run build --workspace=page-agent
|
|
||||||
npm run build:watch --workspace=page-agent
|
|
||||||
|
|
||||||
# Website
|
|
||||||
npm run dev --workspace=@page-agent/website
|
|
||||||
npm run build --workspace=@page-agent/website
|
|
||||||
```
|
|
||||||
|
|
||||||
## Architecture & Critical Patterns
|
## Architecture & Critical Patterns
|
||||||
|
|
||||||
### Monorepo Structure
|
### Monorepo Structure
|
||||||
@@ -45,11 +35,10 @@ You must update tsconfig and vite config if you add/remove/rename a package.
|
|||||||
```bash
|
```bash
|
||||||
packages/
|
packages/
|
||||||
├── page-agent/ # npm: "page-agent" ⭐ MAIN
|
├── page-agent/ # npm: "page-agent" ⭐ MAIN
|
||||||
│ ├── src/ # AI agent source
|
│ ├── src/
|
||||||
│ │ ├── PageAgent.ts # Main AI agent class
|
│ │ ├── PageAgent.ts # Main AI agent class
|
||||||
│ │ ├── tools/ # LLM tool definitions
|
│ │ ├── tools/ # LLM tool definitions
|
||||||
│ │ ├── llms/ # LLM integration
|
│ │ └── llms/ # LLM integration
|
||||||
│ │ └── ui/ # UI components
|
|
||||||
│ ├── vite.config.js # Library build (ES + UMD)
|
│ ├── vite.config.js # Library build (ES + UMD)
|
||||||
│ └── package.json
|
│ └── package.json
|
||||||
├── website/ # npm: "@page-agent/website" (private) ⭐ MAIN
|
├── website/ # npm: "@page-agent/website" (private) ⭐ MAIN
|
||||||
@@ -58,19 +47,25 @@ packages/
|
|||||||
│
|
│
|
||||||
│ # ...internal packages below...
|
│ # ...internal packages below...
|
||||||
│
|
│
|
||||||
└── page-controller/ # npm: "@page-agent/page-controller"
|
├── page-controller/ # npm: "@page-agent/page-controller"
|
||||||
└── src/ # DOM operations source
|
│ └── src/ # DOM operations
|
||||||
├── PageController.ts # Main controller class
|
│ ├── PageController.ts
|
||||||
├── actions.ts # Element interaction actions
|
│ ├── actions.ts
|
||||||
└── dom/ # DOM tree extraction
|
│ └── dom/
|
||||||
|
└── ui/ # npm: "@page-agent/ui"
|
||||||
|
└── src/ # Panel and Mask Effects
|
||||||
|
├── Panel.ts
|
||||||
|
├── SimulatorMask.ts
|
||||||
|
└── i18n/
|
||||||
```
|
```
|
||||||
|
|
||||||
`workspaces` must be written in topological order to guarantee build order.
|
`workspaces` must be written in topological order to guarantee build order.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
// internal deps ...
|
// internal deps (topological order)
|
||||||
"packages/page-controller",
|
"packages/page-controller",
|
||||||
|
"packages/ui",
|
||||||
"packages/page-agent",
|
"packages/page-agent",
|
||||||
"packages/website"
|
"packages/website"
|
||||||
],
|
],
|
||||||
@@ -79,8 +74,9 @@ packages/
|
|||||||
### Module Boundaries (Critical)
|
### Module Boundaries (Critical)
|
||||||
|
|
||||||
- **Website** (`packages/website/`): CAN import from `page-agent` for demos. Alias `@/` → `website/src/`
|
- **Website** (`packages/website/`): CAN import from `page-agent` for demos. Alias `@/` → `website/src/`
|
||||||
- **Page Agent** (`packages/page-agent/`): The core lib. Imports from all internal packages. Never import from website.
|
- **Page Agent** (`packages/page-agent/`): The core lib. Imports from `@page-agent/page-controller` and `@page-agent/ui`.
|
||||||
- **Page Controller** (`packages/page-controller/`): Internal lib. Pure DOM operations, NO LLM dependency. Never import from page-agent.
|
- **UI** (`packages/ui/`): Panel, Mask, i18n. No dependency on page-agent.
|
||||||
|
- **Page Controller** (`packages/page-controller/`): Pure DOM operations. No LLM or UI dependency.
|
||||||
|
|
||||||
### PageController ↔ PageAgent Communication
|
### PageController ↔ PageAgent Communication
|
||||||
|
|
||||||
@@ -132,9 +128,8 @@ Query params configure `PageAgentConfig` automatically in `src/entry.ts`.
|
|||||||
| File | Description |
|
| File | Description |
|
||||||
|------|-------------|
|
|------|-------------|
|
||||||
| `src/PageAgent.ts` | ⭐ Main AI agent class orchestrating tools and LLM |
|
| `src/PageAgent.ts` | ⭐ Main AI agent class orchestrating tools and LLM |
|
||||||
| `src/entry.ts` | CDN/UMD entry point with auto-initialization |
|
| `src/umd.ts` | CDN/UMD entry point with auto-initialization |
|
||||||
| `src/tools/` | Tool definitions that call PageController methods |
|
| `src/tools/` | Tool definitions that call PageController methods |
|
||||||
| `src/ui/` | UI components (Panel, SimulatorMask) with CSS modules |
|
|
||||||
| `src/llms/` | LLM integration and communication layer |
|
| `src/llms/` | LLM integration and communication layer |
|
||||||
| `vite.config.js` | Library build configuration (ES + UMD) |
|
| `vite.config.js` | Library build configuration (ES + UMD) |
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -112,16 +112,16 @@ npm start # React development server
|
|||||||
> @TODO this part is outdated. Update this.
|
> @TODO this part is outdated. Update this.
|
||||||
|
|
||||||
- Config your LLM API
|
- Config your LLM API
|
||||||
- Start a local script
|
- Start and serve a local umd script
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build:watch --workspace=page-agent # UMD with auto rebuild
|
npm run dev:umd # Serving UMD with auto rebuild at http://localhost:5173/page-agent.umd.cjs
|
||||||
```
|
```
|
||||||
|
|
||||||
- Add a new bookmark enable it on other website
|
- Add a new bookmark enable it on other website
|
||||||
|
|
||||||
```
|
```
|
||||||
javascript:(function(){var s=document.createElement('script');s.src=`http://localhost:5173/dist/lib/page-agent.umd.cjs?t=${Math.random()}`;s.onload=()=>console.log(%27PageAgent ready!%27);document.head.appendChild(s);})();
|
javascript:(function(){var s=document.createElement('script');s.src=`http://localhost:5173/page-agent.umd.cjs?t=${Math.random()}`;s.onload=()=>console.log(%27PageAgent ready!%27);document.head.appendChild(s);})();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adding Documentation
|
### Adding Documentation
|
||||||
|
|||||||
+8
-10
@@ -31,10 +31,11 @@
|
|||||||
### CDN 集成
|
### CDN 集成
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<!-- 临时 CDN URL. 未来会变更 -->
|
// CDN - https://cdn.jsdelivr.net/npm/page-agent@latest/dist/umd/page-agent.js
|
||||||
<script
|
// Mirror(CN) - https://registry.npmmirror.com/page-agent/latest/files/dist/umd/page-agent.js
|
||||||
src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js"
|
<script
|
||||||
crossorigin="true"
|
src="https://registry.npmmirror.com/page-agent/latest/files/dist/umd/page-agent.js"
|
||||||
|
crossorigin="true"
|
||||||
type="text/javascript"
|
type="text/javascript"
|
||||||
></script>
|
></script>
|
||||||
```
|
```
|
||||||
@@ -72,12 +73,9 @@ PageAgent adopts a simplified monorepo structure:
|
|||||||
```
|
```
|
||||||
packages/
|
packages/
|
||||||
├── page-agent/ # AI agent (npm: page-agent)
|
├── page-agent/ # AI agent (npm: page-agent)
|
||||||
│ ├── PageAgent # Agent main loop
|
├── page-controller/ # DOM 操作 (npm: @page-agent/page-controller)
|
||||||
│ ├── tools/ # LLM tool definitions
|
├── ui/ # 面板 & 蒙层 & 模拟鼠标 (npm: @page-agent/ui)
|
||||||
│ ├── ui/ # UI components & panels
|
└── website/ # 文档站点
|
||||||
│ └── llms/ # LLM integration layer
|
|
||||||
├── page-controller/ # DOM operations (npm: @page-agent/page-controller)
|
|
||||||
└── website/ # Documentation site
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🤝 贡献
|
## 🤝 贡献
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# PageAgent 🤖🪄
|
# PageAgent 🤖🪄
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://badge.fury.io/js/page-agent) [](https://opensource.org/licenses/MIT) [](http://www.typescriptlang.org/) [](https://www.npmjs.com/package/page-agent) [](https://bundlephobia.com/package/page-agent) [](https://github.com/alibaba/page-agent)
|
[](https://badge.fury.io/js/page-agent) [](https://opensource.org/licenses/MIT) [](http://www.typescriptlang.org/) [](https://www.npmjs.com/package/page-agent) [](https://bundlephobia.com/package/page-agent) [](https://github.com/alibaba/page-agent)
|
||||||
|
|
||||||
@@ -31,10 +31,11 @@ The GUI Agent Living in Your Webpage. Control web interfaces with natural langua
|
|||||||
### CDN Integration
|
### CDN Integration
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<!-- temporary CDN URL. May change in the future -->
|
// CDN - https://cdn.jsdelivr.net/npm/page-agent@latest/dist/umd/page-agent.js
|
||||||
<script
|
// Mirror(CN) - https://registry.npmmirror.com/page-agent/latest/files/dist/umd/page-agent.js
|
||||||
src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js"
|
<script
|
||||||
crossorigin="true"
|
src="https://cdn.jsdelivr.net/npm/page-agent@latest/dist/umd/page-agent.js"
|
||||||
|
crossorigin="true"
|
||||||
type="text/javascript"
|
type="text/javascript"
|
||||||
></script>
|
></script>
|
||||||
```
|
```
|
||||||
@@ -72,11 +73,8 @@ PageAgent adopts a simplified monorepo structure:
|
|||||||
```
|
```
|
||||||
packages/
|
packages/
|
||||||
├── page-agent/ # AI agent (npm: page-agent)
|
├── page-agent/ # AI agent (npm: page-agent)
|
||||||
│ ├── PageAgent # Agent main loop
|
|
||||||
│ ├── tools/ # LLM tool definitions
|
|
||||||
│ ├── ui/ # UI components & panels
|
|
||||||
│ └── llms/ # LLM integration layer
|
|
||||||
├── page-controller/ # DOM operations (npm: @page-agent/page-controller)
|
├── page-controller/ # DOM operations (npm: @page-agent/page-controller)
|
||||||
|
├── ui/ # Panel & Mask & Mouse Animation (npm: @page-agent/ui)
|
||||||
└── website/ # Demo & Documentation site
|
└── website/ # Demo & Documentation site
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Generated
+631
-451
File diff suppressed because it is too large
Load Diff
+17
-14
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "root",
|
"name": "root",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.8",
|
"version": "0.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/page-controller",
|
"packages/page-controller",
|
||||||
@@ -23,33 +23,36 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npm run dev --workspace=@page-agent/website",
|
"start": "npm run dev --workspace=@page-agent/website",
|
||||||
"build": "npm run build --workspaces --if-present",
|
"build:website": "npm run build:website --workspace=@page-agent/website",
|
||||||
"build:lib": "npm run build:lib --workspace=page-agent",
|
"build:libs": "npm run build --workspaces --if-present",
|
||||||
|
"build": "npm run build:libs && npm run build:website",
|
||||||
|
"dev:umd": "npm run dev:umd --workspace=page-agent",
|
||||||
"version": "node scripts/sync-version.js",
|
"version": "node scripts/sync-version.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^20.1.0",
|
"@commitlint/cli": "^20.2.0",
|
||||||
"@commitlint/config-conventional": "^20.0.0",
|
"@commitlint/config-conventional": "^20.2.0",
|
||||||
"@eslint/js": "^9.39.1",
|
"@eslint/js": "^9.39.2",
|
||||||
|
"@microsoft/api-extractor": "^7.55.2",
|
||||||
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
|
"@trivago/prettier-plugin-sort-imports": "^6.0.0",
|
||||||
|
"concurrently": "^9.2.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.2",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-react-dom": "^2.3.9",
|
"eslint-plugin-react-dom": "^2.3.13",
|
||||||
"eslint-plugin-react-hooks": "^7.0.1",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
"eslint-plugin-react-refresh": "^0.4.24",
|
"eslint-plugin-react-refresh": "^0.4.25",
|
||||||
"eslint-plugin-react-x": "^2.3.9",
|
"eslint-plugin-react-x": "^2.3.13",
|
||||||
"globals": "^16.4.0",
|
"globals": "^16.4.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"lint-staged": "^16.2.4",
|
"lint-staged": "^16.2.4",
|
||||||
"prettier": "^3.6.2",
|
"prettier": "^3.7.4",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"typescript-eslint": "^8.48.1",
|
"typescript-eslint": "^8.50.0",
|
||||||
"vite": "^7.2.6",
|
|
||||||
"@microsoft/api-extractor": "^7.55.1",
|
|
||||||
"unplugin-dts": "^1.0.0-beta.6",
|
"unplugin-dts": "^1.0.0-beta.6",
|
||||||
|
"vite": "^7.3.0",
|
||||||
"vite-plugin-css-injected-by-js": "^3.5.2"
|
"vite-plugin-css-injected-by-js": "^3.5.2"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "page-agent",
|
"name": "page-agent",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "0.0.8",
|
"version": "0.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/lib/page-agent.js",
|
"main": "./dist/esm/page-agent.js",
|
||||||
"module": "./dist/lib/page-agent.js",
|
"module": "./dist/esm/page-agent.js",
|
||||||
"types": "./dist/lib/PageAgent.d.ts",
|
"types": "./dist/esm/PageAgent.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/lib/PageAgent.d.ts",
|
"types": "./dist/esm/PageAgent.d.ts",
|
||||||
"import": "./dist/lib/page-agent.js",
|
"import": "./dist/esm/page-agent.js",
|
||||||
"default": "./dist/lib/page-agent.js"
|
"default": "./dist/esm/page-agent.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -37,17 +37,16 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://alibaba.github.io/page-agent/",
|
"homepage": "https://alibaba.github.io/page-agent/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run build:lib && npm run build:umd",
|
"build": "vite build && vite build --config vite.umd.config.js",
|
||||||
"build:lib": "MODE=lib vite build",
|
"serve": "npx serve dist/umd -p 5173",
|
||||||
"build:umd": "MODE=umd vite build",
|
"dev:umd": "concurrently \"vite build --config vite.umd.config.js --watch\" \"npm run serve\"",
|
||||||
"build:watch": "MODE=umd vite build --watch",
|
|
||||||
"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{}})\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
"zod": "^4.1.12",
|
"zod": "^4.2.0",
|
||||||
"@page-agent/page-controller": "0.0.8",
|
"@page-agent/page-controller": "0.0.13",
|
||||||
"@page-agent/ui": "0.0.8"
|
"@page-agent/ui": "0.0.13"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,21 +20,25 @@ const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|||||||
const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
||||||
const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
|
||||||
const currentScript = document.currentScript as HTMLScriptElement | null
|
// in case document.x is not ready yet
|
||||||
if (currentScript) {
|
// @todo give a switch to disable auto-init
|
||||||
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
setTimeout(() => {
|
||||||
const url = new URL(currentScript.src)
|
const currentScript = document.currentScript as HTMLScriptElement | null
|
||||||
const model = url.searchParams.get('model') || DEMO_MODEL
|
if (currentScript) {
|
||||||
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
||||||
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
const url = new URL(currentScript.src)
|
||||||
const language = (url.searchParams.get('lang') as 'zh-CN' | 'en-US') || 'zh-CN'
|
const model = url.searchParams.get('model') || DEMO_MODEL
|
||||||
const config: PageAgentConfig = { model, baseURL, apiKey, language }
|
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
||||||
window.pageAgent = new PageAgent(config)
|
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
||||||
} else {
|
const language = (url.searchParams.get('lang') as 'zh-CN' | 'en-US') || 'zh-CN'
|
||||||
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
const config: PageAgentConfig = { model, baseURL, apiKey, language }
|
||||||
window.pageAgent = new PageAgent()
|
window.pageAgent = new PageAgent(config)
|
||||||
}
|
} else {
|
||||||
|
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
||||||
|
window.pageAgent = new PageAgent()
|
||||||
|
}
|
||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
||||||
|
|
||||||
window.pageAgent.panel.show() // Show panel
|
window.pageAgent.panel.show() // Show panel
|
||||||
|
})
|
||||||
|
|||||||
@@ -7,10 +7,16 @@
|
|||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@page-agent/page-controller": ["../page-controller/src/PageController.ts"]
|
//
|
||||||
|
"@page-agent/page-controller": ["../page-controller/src/PageController.ts"],
|
||||||
|
"@page-agent/ui": ["../ui/src/index.ts"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts"],
|
"include": ["**/*.ts"],
|
||||||
"exclude": ["dist", "node_modules"],
|
"exclude": ["dist", "node_modules"],
|
||||||
"references": [{ "path": "../page-controller" }]
|
"references": [
|
||||||
|
//
|
||||||
|
{ "path": "../page-controller" },
|
||||||
|
{ "path": "../ui" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
import chalk from 'chalk'
|
|
||||||
import 'dotenv/config'
|
|
||||||
import process from 'node:process'
|
|
||||||
import { dirname, resolve } from 'path'
|
import { dirname, resolve } from 'path'
|
||||||
import dts from 'unplugin-dts/vite'
|
import dts from 'unplugin-dts/vite'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
@@ -10,15 +7,11 @@ import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
|
|||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
// ============================================================================
|
// ES Module for NPM Package
|
||||||
// Library Config (ES Module for NPM Package)
|
export default defineConfig({
|
||||||
// ============================================================================
|
|
||||||
/** @type {import('vite').UserConfig} */
|
|
||||||
const libConfig = {
|
|
||||||
clearScreen: false,
|
clearScreen: false,
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({ tsconfigPath: './tsconfig.dts.json', bundleTypes: true }),
|
dts({ tsconfigPath: './tsconfig.dts.json', bundleTypes: true }),
|
||||||
// dts({ tsconfigPath: './tsconfig.json', bundleTypes: true, compilerOptions: { paths: {} } }),
|
|
||||||
cssInjectedByJsPlugin({ relativeCSSInjection: true }),
|
cssInjectedByJsPlugin({ relativeCSSInjection: true }),
|
||||||
],
|
],
|
||||||
publicDir: false,
|
publicDir: false,
|
||||||
@@ -32,9 +25,14 @@ const libConfig = {
|
|||||||
fileName: 'page-agent',
|
fileName: 'page-agent',
|
||||||
formats: ['es'],
|
formats: ['es'],
|
||||||
},
|
},
|
||||||
outDir: resolve(__dirname, 'dist', 'lib'),
|
outDir: resolve(__dirname, 'dist', 'esm'),
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['ai', 'ai-motion', 'chalk', 'zod', '@page-agent/*'],
|
external: [
|
||||||
|
'chalk',
|
||||||
|
'zod',
|
||||||
|
// all the internal packages
|
||||||
|
/^@page-agent\//,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
minify: false,
|
minify: false,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
@@ -43,53 +41,4 @@ const libConfig = {
|
|||||||
define: {
|
define: {
|
||||||
'process.env.NODE_ENV': '"production"',
|
'process.env.NODE_ENV': '"production"',
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// UMD Config (Browser Bundle for CDN)
|
|
||||||
// - alias all local packages so that they can be build in
|
|
||||||
// - no external
|
|
||||||
// - no d.ts. dts does not work with monorepo aliasing
|
|
||||||
// ============================================================================
|
|
||||||
/** @type {import('vite').UserConfig} */
|
|
||||||
const umdConfig = {
|
|
||||||
plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })],
|
|
||||||
publicDir: false,
|
|
||||||
esbuild: {
|
|
||||||
keepNames: true,
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
'@page-agent/page-controller': resolve(__dirname, '../page-controller/src/PageController.ts'),
|
|
||||||
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
build: {
|
|
||||||
lib: {
|
|
||||||
entry: resolve(__dirname, 'src/umd.ts'),
|
|
||||||
name: 'PageAgent',
|
|
||||||
fileName: 'page-agent',
|
|
||||||
formats: ['umd'],
|
|
||||||
},
|
|
||||||
outDir: resolve(__dirname, 'dist', 'umd'),
|
|
||||||
cssCodeSplit: true,
|
|
||||||
},
|
|
||||||
define: {
|
|
||||||
'process.env.NODE_ENV': '"production"',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
const MODE = process.env.MODE
|
|
||||||
|
|
||||||
console.log(chalk.cyan(`📦 Build mode: ${chalk.bold(MODE || 'lib')}`))
|
|
||||||
|
|
||||||
let config
|
|
||||||
if (MODE === 'umd') {
|
|
||||||
config = umdConfig
|
|
||||||
} else {
|
|
||||||
config = libConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
export default defineConfig(config)
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// @ts-check
|
||||||
|
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))
|
||||||
|
|
||||||
|
// UMD Bundle for CDN
|
||||||
|
// - alias all local packages so that they can be build in
|
||||||
|
// - no external
|
||||||
|
// - no d.ts. dts does not work with monorepo aliasing
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [cssInjectedByJsPlugin({ relativeCSSInjection: true })],
|
||||||
|
publicDir: false,
|
||||||
|
esbuild: {
|
||||||
|
keepNames: true,
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@page-agent/page-controller': resolve(__dirname, '../page-controller/src/PageController.ts'),
|
||||||
|
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: resolve(__dirname, 'src/umd.ts'),
|
||||||
|
name: 'PageAgent',
|
||||||
|
fileName: 'page-agent',
|
||||||
|
formats: ['umd'],
|
||||||
|
},
|
||||||
|
outDir: resolve(__dirname, 'dist', 'umd'),
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
// force use .js as extension
|
||||||
|
entryFileNames: 'page-agent.js',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cssCodeSplit: true,
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
'process.env.NODE_ENV': '"production"',
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@page-agent/page-controller",
|
"name": "@page-agent/page-controller",
|
||||||
"version": "0.0.8",
|
"version": "0.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/lib/page-controller.js",
|
"main": "./dist/lib/page-controller.js",
|
||||||
"module": "./dist/lib/page-controller.js",
|
"module": "./dist/lib/page-controller.js",
|
||||||
@@ -32,7 +32,6 @@
|
|||||||
"homepage": "https://alibaba.github.io/page-agent/",
|
"homepage": "https://alibaba.github.io/page-agent/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"build:watch": "vite build --watch",
|
|
||||||
"prepublishOnly": "node -e \"const fs=require('fs');['LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
"prepublishOnly": "node -e \"const fs=require('fs');['LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
||||||
"postpublish": "node -e \"['LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
"postpublish": "node -e \"['LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@page-agent/ui",
|
"name": "@page-agent/ui",
|
||||||
"version": "0.0.8",
|
"version": "0.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/lib/page-agent-ui.js",
|
"main": "./dist/lib/page-agent-ui.js",
|
||||||
"module": "./dist/lib/page-agent-ui.js",
|
"module": "./dist/lib/page-agent-ui.js",
|
||||||
@@ -32,7 +32,6 @@
|
|||||||
"homepage": "https://alibaba.github.io/page-agent/",
|
"homepage": "https://alibaba.github.io/page-agent/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"build:watch": "vite build --watch",
|
|
||||||
"prepublishOnly": "node -e \"const fs=require('fs');['LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
"prepublishOnly": "node -e \"const fs=require('fs');['LICENSE'].forEach(f=>fs.copyFileSync('../../'+f,f))\"",
|
||||||
"postpublish": "node -e \"['LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
"postpublish": "node -e \"['LICENSE'].forEach(f=>{try{require('fs').unlinkSync(f)}catch{}})\""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
* @returns {boolean} - True if a common dark mode class is found.
|
* @returns {boolean} - True if a common dark mode class is found.
|
||||||
*/
|
*/
|
||||||
function hasDarkModeClass() {
|
function hasDarkModeClass() {
|
||||||
const DFEAULT_DARK_MODE_CLASSES = ['dark', 'dark-mode', 'theme-dark', 'night', 'night-mode']
|
const DEFAULT_DARK_MODE_CLASSES = ['dark', 'dark-mode', 'theme-dark', 'night', 'night-mode']
|
||||||
|
|
||||||
const htmlElement = document.documentElement
|
const htmlElement = document.documentElement
|
||||||
const bodyElement = document.body
|
const bodyElement = document.body || document.documentElement // can be null in some cases
|
||||||
|
|
||||||
// Check class names on <html> and <body>
|
// Check class names on <html> and <body>
|
||||||
for (const className of DFEAULT_DARK_MODE_CLASSES) {
|
for (const className of DEFAULT_DARK_MODE_CLASSES) {
|
||||||
if (htmlElement.classList.contains(className) || bodyElement.classList.contains(className)) {
|
if (htmlElement.classList.contains(className) || bodyElement?.classList.contains(className)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ function isColorDark(colorString: string, threshold = 128) {
|
|||||||
function isBackgroundDark() {
|
function isBackgroundDark() {
|
||||||
// We check both <html> and <body> because some pages set the color on <html>
|
// We check both <html> and <body> because some pages set the color on <html>
|
||||||
const htmlStyle = window.getComputedStyle(document.documentElement)
|
const htmlStyle = window.getComputedStyle(document.documentElement)
|
||||||
const bodyStyle = window.getComputedStyle(document.body)
|
const bodyStyle = window.getComputedStyle(document.body || document.documentElement)
|
||||||
|
|
||||||
// Get background colors
|
// Get background colors
|
||||||
const htmlBgColor = htmlStyle.backgroundColor
|
const htmlBgColor = htmlStyle.backgroundColor
|
||||||
@@ -93,18 +93,23 @@ function isBackgroundDark() {
|
|||||||
* @returns {boolean} - True if the page is likely dark.
|
* @returns {boolean} - True if the page is likely dark.
|
||||||
*/
|
*/
|
||||||
export function isPageDark() {
|
export function isPageDark() {
|
||||||
// Strategy 1: Check for common dark mode classes
|
try {
|
||||||
if (hasDarkModeClass()) {
|
// Strategy 1: Check for common dark mode classes
|
||||||
return true
|
if (hasDarkModeClass()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strategy 2: Analyze the computed background color
|
||||||
|
if (isBackgroundDark()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO add more checks here, e.g., analyzing text color,
|
||||||
|
// or checking the background of major layout elements like <main> or #app.
|
||||||
|
|
||||||
|
return false
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error determining if page is dark:', error)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strategy 2: Analyze the computed background color
|
|
||||||
if (isBackgroundDark()) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// @TODO add more checks here, e.g., analyzing text color,
|
|
||||||
// or checking the background of major layout elements like <main> or #app.
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "@page-agent/website",
|
"name": "@page-agent/website",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.8",
|
"version": "0.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build:website": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/vite": "^4.1.14",
|
"@tailwindcss/vite": "^4.1.18",
|
||||||
"@types/react": "^19.2.2",
|
"@types/react": "^19.2.2",
|
||||||
"@types/react-dom": "^19.2.1",
|
"@types/react-dom": "^19.2.1",
|
||||||
"@vitejs/plugin-react-swc": "^4.1.0",
|
"@vitejs/plugin-react-swc": "^4.1.0",
|
||||||
"i18next": "^25.7.1",
|
"i18next": "^25.7.3",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.3",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.3",
|
||||||
"react-i18next": "^16.1.4",
|
"react-i18next": "^16.5.0",
|
||||||
"tailwindcss": "^4.1.14",
|
"tailwindcss": "^4.1.14",
|
||||||
"wouter": "^3.7.1"
|
"wouter": "^3.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export const CDN_URL = 'https://cdn.jsdelivr.net/npm/page-agent@latest/dist/umd/page-agent.js'
|
||||||
|
export const CDN_CN_URL =
|
||||||
|
'https://registry.npmmirror.com/page-agent/latest/files/dist/umd/page-agent.js'
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import BetaNotice from '@/components/BetaNotice'
|
import BetaNotice from '@/components/BetaNotice'
|
||||||
import CodeEditor from '@/components/CodeEditor'
|
import CodeEditor from '@/components/CodeEditor'
|
||||||
|
import { CDN_CN_URL, CDN_URL } from '@/constants'
|
||||||
|
|
||||||
export default function CdnSetup() {
|
export default function CdnSetup() {
|
||||||
return (
|
return (
|
||||||
@@ -15,11 +16,16 @@ export default function CdnSetup() {
|
|||||||
<CodeEditor
|
<CodeEditor
|
||||||
className="mb-8"
|
className="mb-8"
|
||||||
code={`
|
code={`
|
||||||
// 仅供测试使用,稳定 CDN 待定
|
// CDN: \t${CDN_URL}
|
||||||
<script src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js" crossorigin="true" type="text/javascript"></script>
|
// Mirror: \t${CDN_CN_URL}
|
||||||
|
<script
|
||||||
|
src="${CDN_URL}"
|
||||||
|
crossorigin="true"
|
||||||
|
type="text/javascript"
|
||||||
|
></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.pageAgent.panel.show()
|
// window.pageAgent
|
||||||
</script>`}
|
</script>`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default function Overview() {
|
|||||||
{/* 头图 */}
|
{/* 头图 */}
|
||||||
<figure className="mb-8 rounded-xl overflow-hidden">
|
<figure className="mb-8 rounded-xl overflow-hidden">
|
||||||
<img
|
<img
|
||||||
src="https://img.alicdn.com/imgextra/i1/O1CN01RY0Wvh26ATVeDIX7v_!!6000000007621-0-tps-1672-512.jpg"
|
src="https://img.alicdn.com/imgextra/i3/O1CN014xLeic1gnF2iWdzjJ_!!6000000004186-49-tps-1280-353.webp"
|
||||||
alt="page-agent"
|
alt="page-agent"
|
||||||
className="w-full h-64 object-cover"
|
className="w-full h-64 object-cover"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
|
|
||||||
import BetaNotice from '@/components/BetaNotice'
|
import BetaNotice from '@/components/BetaNotice'
|
||||||
import CodeEditor from '@/components/CodeEditor'
|
import CodeEditor from '@/components/CodeEditor'
|
||||||
|
import { CDN_CN_URL, CDN_URL } from '@/constants'
|
||||||
|
|
||||||
export default function QuickStart() {
|
export default function QuickStart() {
|
||||||
const { t } = useTranslation('docs')
|
const { t } = useTranslation('docs')
|
||||||
@@ -23,8 +24,9 @@ export default function QuickStart() {
|
|||||||
<div>
|
<div>
|
||||||
<p className="text-sm font-medium mb-2">{t('quick_start.step1_cdn')}</p>
|
<p className="text-sm font-medium mb-2">{t('quick_start.step1_cdn')}</p>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
code={`// 仅供测试使用
|
code={`// CDN: \t${CDN_URL}
|
||||||
<script src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js" crossorigin="true" type="text/javascript"></script>`}
|
// Mirror: \t${CDN_CN_URL}
|
||||||
|
<script src="${CDN_URL}" crossorigin="true" type="text/javascript"></script>`}
|
||||||
language="html"
|
language="html"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export default {
|
|||||||
step1_content: 'Show your bookmarks bar',
|
step1_content: 'Show your bookmarks bar',
|
||||||
step2_title: 'Step 2:',
|
step2_title: 'Step 2:',
|
||||||
step2_content: 'Drag this button to your bookmarks',
|
step2_content: 'Drag this button to your bookmarks',
|
||||||
|
cdn_label: 'CDN Source',
|
||||||
|
cdn_international: 'International',
|
||||||
|
cdn_china: 'China Mirror',
|
||||||
step3_title: 'Step 3:',
|
step3_title: 'Step 3:',
|
||||||
step3_content: 'Click the bookmark on any site to activate',
|
step3_content: 'Click the bookmark on any site to activate',
|
||||||
notice_title: '⚠️ Heads Up',
|
notice_title: '⚠️ Heads Up',
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export default {
|
|||||||
step1_content: '显示收藏夹栏',
|
step1_content: '显示收藏夹栏',
|
||||||
step2_title: '步骤 2:',
|
step2_title: '步骤 2:',
|
||||||
step2_content: '拖拽下面按钮到收藏夹栏',
|
step2_content: '拖拽下面按钮到收藏夹栏',
|
||||||
|
cdn_label: 'CDN 源',
|
||||||
|
cdn_international: '国际',
|
||||||
|
cdn_china: '国内镜像',
|
||||||
step3_title: '步骤 3:',
|
step3_title: '步骤 3:',
|
||||||
step3_content: '在其他网站点击收藏夹中的按钮即可使用',
|
step3_content: '在其他网站点击收藏夹中的按钮即可使用',
|
||||||
notice_title: '⚠️ 注意',
|
notice_title: '⚠️ 注意',
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { useHashLocation } from 'wouter/use-hash-location'
|
|||||||
|
|
||||||
import './i18n/config'
|
import './i18n/config'
|
||||||
import './i18n/types'
|
import './i18n/types'
|
||||||
import { default as PagesRouter } from './router.tsx'
|
import { default as PagesRouter } from './router'
|
||||||
import { default as TestPagesRouter } from './test-pages/router.tsx'
|
import { default as TestPagesRouter } from './test-pages/router'
|
||||||
|
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
|
||||||
|
|||||||
@@ -6,23 +6,27 @@ import { Link, useSearchParams } from 'wouter'
|
|||||||
|
|
||||||
import Footer from './components/Footer'
|
import Footer from './components/Footer'
|
||||||
import Header from './components/Header'
|
import Header from './components/Header'
|
||||||
|
import { CDN_CN_URL, CDN_URL } from './constants'
|
||||||
|
|
||||||
const injection = encodeURI(
|
function getInjection(useCN?: boolean) {
|
||||||
"javascript:(function(){var s=document.createElement('script');s.src=`https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.4/page-agent.js?t=${Math.random()}`;s.setAttribute('crossorigin', true);s.type=`text/javascript`;s.onload=()=>console.log('PageAgent script loaded!');document.body.appendChild(s);})();"
|
const cdn = useCN ? CDN_CN_URL : CDN_URL
|
||||||
)
|
|
||||||
|
|
||||||
const injectionA = `
|
const injection = encodeURI(
|
||||||
<a
|
`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);})();`
|
||||||
href=${injection}
|
)
|
||||||
class="inline-flex items-center text-xs px-3 py-2 bg-blue-500 text-white font-medium rounded-lg hover:shadow-md transform hover:scale-105 transition-all duration-200 cursor-move border-2 border-dashed border-green-300"
|
|
||||||
draggable="true"
|
|
||||||
onclick="return false;"
|
|
||||||
title="Drag me to your bookmarks bar!"
|
|
||||||
>
|
|
||||||
✨PageAgent
|
|
||||||
</a>
|
|
||||||
|
|
||||||
`
|
return `
|
||||||
|
<a
|
||||||
|
href=${injection}
|
||||||
|
class="inline-flex items-center text-xs px-3 py-2 bg-blue-500 text-white font-medium rounded-lg hover:shadow-md transform hover:scale-105 transition-all duration-200 cursor-move border-2 border-dashed border-green-300"
|
||||||
|
draggable="true"
|
||||||
|
onclick="return false;"
|
||||||
|
title="Drag me to your bookmarks bar!"
|
||||||
|
>
|
||||||
|
✨PageAgent
|
||||||
|
</a>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const { t, i18n } = useTranslation(['home', 'common'])
|
const { t, i18n } = useTranslation(['home', 'common'])
|
||||||
@@ -38,6 +42,7 @@ export default function HomePage() {
|
|||||||
const isOther = params.has('try_other')
|
const isOther = params.has('try_other')
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState<'try' | 'other'>(isOther ? 'other' : 'try')
|
const [activeTab, setActiveTab] = useState<'try' | 'other'>(isOther ? 'other' : 'try')
|
||||||
|
const [cdnSource, setCdnSource] = useState<'international' | 'china'>('international')
|
||||||
|
|
||||||
const handleExecute = async () => {
|
const handleExecute = async () => {
|
||||||
if (!task.trim()) return
|
if (!task.trim()) return
|
||||||
@@ -194,10 +199,25 @@ export default function HomePage() {
|
|||||||
</span>{' '}
|
</span>{' '}
|
||||||
{t('home:try_other.step2_content')}
|
{t('home:try_other.step2_content')}
|
||||||
</p>
|
</p>
|
||||||
<div
|
<div className="flex items-center justify-center gap-3">
|
||||||
className="flex items-center justify-center gap-2 text-gray-500 dark:text-gray-400"
|
<select
|
||||||
dangerouslySetInnerHTML={{ __html: injectionA }}
|
value={cdnSource}
|
||||||
></div>
|
onChange={(e) =>
|
||||||
|
setCdnSource(e.target.value as 'international' | 'china')
|
||||||
|
}
|
||||||
|
className="px-2 py-1.5 text-xs border border-gray-300 dark:border-gray-500 rounded bg-white dark:bg-gray-600 text-gray-700 dark:text-gray-200"
|
||||||
|
>
|
||||||
|
<option value="international">
|
||||||
|
{t('home:try_other.cdn_international')}
|
||||||
|
</option>
|
||||||
|
<option value="china">{t('home:try_other.cdn_china')}</option>
|
||||||
|
</select>
|
||||||
|
<div
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: getInjection(cdnSource === 'china'),
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Usage Instructions */}
|
{/* Usage Instructions */}
|
||||||
|
|||||||
@@ -11,11 +11,17 @@
|
|||||||
"@/*": ["src/*"],
|
"@/*": ["src/*"],
|
||||||
|
|
||||||
// Simplified monorepo solution (raw npm workspace with hoisting)
|
// Simplified monorepo solution (raw npm workspace with hoisting)
|
||||||
|
"page-agent": ["../page-agent/src/PageAgent.ts"],
|
||||||
"@page-agent/page-controller": ["../page-controller/src/PageController.ts"],
|
"@page-agent/page-controller": ["../page-controller/src/PageController.ts"],
|
||||||
"page-agent": ["../page-agent/src/PageAgent.ts"]
|
"@page-agent/ui": ["../ui/src/index.ts"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts", "**/*.tsx"],
|
"include": ["**/*.ts", "**/*.tsx"],
|
||||||
"exclude": ["dist", "node_modules"],
|
"exclude": ["dist", "node_modules"],
|
||||||
"references": [{ "path": "../page-controller" }, { "path": "../page-agent" }]
|
"references": [
|
||||||
|
//
|
||||||
|
{ "path": "../page-agent" },
|
||||||
|
{ "path": "../page-controller" },
|
||||||
|
{ "path": "../ui" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import tailwindcss from '@tailwindcss/vite'
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
import react from '@vitejs/plugin-react-swc'
|
import react from '@vitejs/plugin-react-swc'
|
||||||
import 'dotenv/config'
|
import { config as dotenvConfig } from 'dotenv'
|
||||||
import process from 'node:process'
|
import process from 'node:process'
|
||||||
import { dirname, resolve } from 'path'
|
import { dirname, resolve } from 'path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
@@ -8,6 +8,9 @@ import { defineConfig } from 'vite'
|
|||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
// Load .env from repo root
|
||||||
|
dotenvConfig({ path: resolve(__dirname, '../../.env') })
|
||||||
|
|
||||||
// Website Config (React Documentation Site)
|
// Website Config (React Documentation Site)
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
base: './',
|
base: './',
|
||||||
|
|||||||
Reference in New Issue
Block a user