Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32be34bcb1 | |||
| 7063b8199d | |||
| 64f1a8c443 | |||
| 635416f964 | |||
| 7c2d000e29 | |||
| b36a0c0261 | |||
| 339b066d2d | |||
| c8efffa80a | |||
| 59235263ad | |||
| bc1e8fea3c | |||
| 85a4096b2d | |||
| 0ef84bac13 | |||
| a7834c77e1 | |||
| 030e5cfc54 | |||
| aa694e3b85 | |||
| 2fee2d5ea3 | |||
| 3082843810 | |||
| 34098e2f66 | |||
| 8461006c91 | |||
| 2e76a35188 | |||
| abc96b415f | |||
| 77ce3b0b49 | |||
| 3742f75d14 | |||
| c2e9e6a571 | |||
| 54eb50f7be | |||
| 9351948794 | |||
| 68d1a10dd0 | |||
| b9fe8146b6 | |||
| 2a727226bc |
@@ -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
|
||||||
Vendored
+8
-1
@@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"editor.fontLigatures": true,
|
"editor.fontLigatures": true,
|
||||||
"cSpell.words": ["HITL", "innerhtml", "opensource", "retryable", "wouter"],
|
"cSpell.words": [
|
||||||
|
"HITL",
|
||||||
|
"innerhtml",
|
||||||
|
"llms",
|
||||||
|
"opensource",
|
||||||
|
"retryable",
|
||||||
|
"wouter"
|
||||||
|
],
|
||||||
"markdownlint.config": {
|
"markdownlint.config": {
|
||||||
// "comment": "Relaxed rules",
|
// "comment": "Relaxed rules",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ 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.
|
- **LLMs** (`packages/llms/`) - LLM client with reflection-before-action mental model.
|
||||||
|
- **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 +20,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 +36,9 @@ 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
|
|
||||||
│ │ └── 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,31 @@ packages/
|
|||||||
│
|
│
|
||||||
│ # ...internal packages below...
|
│ # ...internal packages below...
|
||||||
│
|
│
|
||||||
└── page-controller/ # npm: "@page-agent/page-controller"
|
├── llms/ # npm: "@page-agent/llms"
|
||||||
└── src/ # DOM operations source
|
│ └── src/ # LLM client (reflection-before-action model)
|
||||||
├── PageController.ts # Main controller class
|
│ ├── index.ts
|
||||||
├── actions.ts # Element interaction actions
|
│ ├── types.ts # MacroToolInput, AgentBrain, LLMConfig
|
||||||
└── dom/ # DOM tree extraction
|
│ └── OpenAI*.ts # OpenAI-compatible clients
|
||||||
|
├── page-controller/ # npm: "@page-agent/page-controller"
|
||||||
|
│ └── src/ # DOM operations
|
||||||
|
│ ├── PageController.ts
|
||||||
|
│ ├── actions.ts
|
||||||
|
│ └── 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/llms",
|
||||||
"packages/page-agent",
|
"packages/page-agent",
|
||||||
"packages/website"
|
"packages/website"
|
||||||
],
|
],
|
||||||
@@ -79,8 +80,10 @@ 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/llms`, `@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.
|
- **LLMs** (`packages/llms/`): LLM client with MacroToolInput contract. No dependency on 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,12 +135,19 @@ 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 |
|
|
||||||
| `vite.config.js` | Library build configuration (ES + UMD) |
|
| `vite.config.js` | Library build configuration (ES + UMD) |
|
||||||
|
|
||||||
|
### LLMs (`packages/llms/`)
|
||||||
|
|
||||||
|
| File | Description |
|
||||||
|
|------|-------------|
|
||||||
|
| `src/index.ts` | ⭐ LLM class with retry logic |
|
||||||
|
| `src/types.ts` | MacroToolInput, AgentBrain, LLMConfig definitions |
|
||||||
|
| `src/OpenAILenientClient.ts` | OpenAI-compatible client with lenient parsing |
|
||||||
|
| `src/utils.ts` | Zod-to-OpenAI conversion, model patches |
|
||||||
|
|
||||||
### Page Controller (`packages/page-controller/`)
|
### Page Controller (`packages/page-controller/`)
|
||||||
|
|
||||||
| File | Description |
|
| File | Description |
|
||||||
|
|||||||
+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
|
||||||
|
|||||||
+9
-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,10 @@ 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
|
├── llms/ # LLM 客户端 (npm: @page-agent/llms)
|
||||||
│ ├── tools/ # LLM tool definitions
|
├── page-controller/ # DOM 操作 (npm: @page-agent/page-controller)
|
||||||
│ ├── ui/ # UI components & panels
|
├── ui/ # 面板 & 蒙层 & 模拟鼠标 (npm: @page-agent/ui)
|
||||||
│ └── llms/ # LLM integration layer
|
└── website/ # 文档站点
|
||||||
├── 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,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
|
├── llms/ # LLM client (npm: @page-agent/llms)
|
||||||
│ ├── 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
+647
-452
File diff suppressed because it is too large
Load Diff
+18
-14
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "root",
|
"name": "root",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.9",
|
"version": "0.0.15",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/page-controller",
|
"packages/page-controller",
|
||||||
"packages/ui",
|
"packages/ui",
|
||||||
|
"packages/llms",
|
||||||
"packages/page-agent",
|
"packages/page-agent",
|
||||||
"packages/website"
|
"packages/website"
|
||||||
],
|
],
|
||||||
@@ -23,33 +24,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": {
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# @page-agent/llms
|
||||||
|
|
||||||
|
LLM client with a **reflection-before-action** mental model for page-agent.
|
||||||
|
|
||||||
|
## Why This Package Exists
|
||||||
|
|
||||||
|
The LLM module and the agent logic are inherently coupled. This package exists not to decouple them, but to **define the interface contract** between the LLM and the agent.
|
||||||
|
|
||||||
|
The core abstraction is the `MacroToolInput` — a structured output format that **forces the model to reflect before acting**.
|
||||||
|
|
||||||
|
## The Reflection-Before-Action Model
|
||||||
|
|
||||||
|
Every tool call must first output its reasoning state before the actual action:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface MacroToolInput {
|
||||||
|
// Reflection (mandatory before any action)
|
||||||
|
evaluation_previous_goal?: string // How well did the previous action work?
|
||||||
|
memory?: string // Key information to remember
|
||||||
|
next_goal?: string // What to accomplish next
|
||||||
|
|
||||||
|
// Action (the actual operation)
|
||||||
|
action: Record<string, any>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This design ensures that:
|
||||||
|
|
||||||
|
1. **The model evaluates its previous action** before deciding the next step
|
||||||
|
2. **Working memory is explicitly maintained** across conversation turns
|
||||||
|
3. **Goals are clearly stated**, making the agent's reasoning transparent and debuggable
|
||||||
|
|
||||||
|
## Key Components
|
||||||
|
|
||||||
|
| Export | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `LLM` | Main LLM client class with retry logic |
|
||||||
|
| `MacroToolInput` | The reflection-before-action input schema |
|
||||||
|
| `AgentBrain` | Agent's thinking state (eval, memory, goal) |
|
||||||
|
| `LLMConfig` | Configuration for LLM connection |
|
||||||
|
| `parseLLMConfig` | Parse and apply defaults to config |
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"name": "@page-agent/llms",
|
||||||
|
"version": "0.0.15",
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/lib/page-agent-llms.js",
|
||||||
|
"module": "./dist/lib/page-agent-llms.js",
|
||||||
|
"types": "./dist/lib/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/lib/index.d.ts",
|
||||||
|
"import": "./dist/lib/page-agent-llms.js",
|
||||||
|
"default": "./dist/lib/page-agent-llms.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist/"
|
||||||
|
],
|
||||||
|
"description": "LLM client with reflection-before-action mental model for page-agent",
|
||||||
|
"keywords": [
|
||||||
|
"page-agent",
|
||||||
|
"llm",
|
||||||
|
"openai",
|
||||||
|
"tool-calling",
|
||||||
|
"agent"
|
||||||
|
],
|
||||||
|
"author": "Simon<gaomeng1900>",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/alibaba/page-agent.git",
|
||||||
|
"directory": "packages/llms"
|
||||||
|
},
|
||||||
|
"homepage": "https://alibaba.github.io/page-agent/",
|
||||||
|
"scripts": {
|
||||||
|
"build": "vite build",
|
||||||
|
"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{}})\""
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.6.2",
|
||||||
|
"zod": "^4.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-2
@@ -1,9 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAI Client implementation
|
* OpenAI Client implementation
|
||||||
*/
|
*/
|
||||||
import type { MacroToolInput } from '../PageAgent'
|
|
||||||
import { InvokeError, InvokeErrorType } from './errors'
|
import { InvokeError, InvokeErrorType } from './errors'
|
||||||
import type { InvokeResult, LLMClient, Message, OpenAIClientConfig, Tool } from './types'
|
import type {
|
||||||
|
InvokeResult,
|
||||||
|
LLMClient,
|
||||||
|
MacroToolInput,
|
||||||
|
Message,
|
||||||
|
OpenAIClientConfig,
|
||||||
|
Tool,
|
||||||
|
} from './types'
|
||||||
import { lenientParseMacroToolCall, modelPatch, zodToOpenAITool } from './utils'
|
import { lenientParseMacroToolCall, modelPatch, zodToOpenAITool } from './utils'
|
||||||
|
|
||||||
export class OpenAIClient implements LLMClient {
|
export class OpenAIClient implements LLMClient {
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Dev environment: use .env config if available, otherwise fallback to testing api
|
||||||
|
export const DEFAULT_MODEL_NAME: string =
|
||||||
|
import.meta.env.DEV && import.meta.env.LLM_MODEL_NAME
|
||||||
|
? import.meta.env.LLM_MODEL_NAME
|
||||||
|
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
|
||||||
|
export const DEFAULT_API_KEY: string =
|
||||||
|
import.meta.env.DEV && import.meta.env.LLM_API_KEY
|
||||||
|
? import.meta.env.LLM_API_KEY
|
||||||
|
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
|
||||||
|
export const DEFAULT_BASE_URL: string =
|
||||||
|
import.meta.env.DEV && import.meta.env.LLM_BASE_URL
|
||||||
|
? import.meta.env.LLM_BASE_URL
|
||||||
|
: 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
||||||
|
|
||||||
|
// internal
|
||||||
|
|
||||||
|
export const LLM_MAX_RETRIES = 2
|
||||||
|
export const DEFAULT_TEMPERATURE = 0.7 // higher randomness helps auto-recovery
|
||||||
|
export const DEFAULT_MAX_TOKENS = 4096
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
@@ -31,13 +31,48 @@
|
|||||||
* - 永远使用 tool call 来返回结构化数据,禁止模型直接返回(视为出错)
|
* - 永远使用 tool call 来返回结构化数据,禁止模型直接返回(视为出错)
|
||||||
* - 不能假设 tool 参数合法,必须有修复机制,而且修复也应该使用 tool call 返回
|
* - 不能假设 tool 参数合法,必须有修复机制,而且修复也应该使用 tool call 返回
|
||||||
*/
|
*/
|
||||||
import type { LLMConfig } from '../config'
|
|
||||||
import { parseLLMConfig } from '../config'
|
|
||||||
import { OpenAIClient } from './OpenAILenientClient'
|
import { OpenAIClient } from './OpenAILenientClient'
|
||||||
|
import {
|
||||||
|
DEFAULT_API_KEY,
|
||||||
|
DEFAULT_BASE_URL,
|
||||||
|
DEFAULT_MAX_TOKENS,
|
||||||
|
DEFAULT_MODEL_NAME,
|
||||||
|
DEFAULT_TEMPERATURE,
|
||||||
|
LLM_MAX_RETRIES,
|
||||||
|
} from './constants'
|
||||||
import { InvokeError } from './errors'
|
import { InvokeError } from './errors'
|
||||||
import type { InvokeResult, LLMClient, Message, Tool } from './types'
|
import type {
|
||||||
|
AgentBrain,
|
||||||
|
InvokeResult,
|
||||||
|
LLMClient,
|
||||||
|
LLMConfig,
|
||||||
|
MacroToolInput,
|
||||||
|
MacroToolResult,
|
||||||
|
Message,
|
||||||
|
Tool,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
export type { Message, Tool, InvokeResult, LLMClient }
|
export type {
|
||||||
|
AgentBrain,
|
||||||
|
InvokeResult,
|
||||||
|
LLMClient,
|
||||||
|
LLMConfig,
|
||||||
|
MacroToolInput,
|
||||||
|
MacroToolResult,
|
||||||
|
Message,
|
||||||
|
Tool,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
|
||||||
|
return {
|
||||||
|
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
||||||
|
apiKey: config.apiKey ?? DEFAULT_API_KEY,
|
||||||
|
model: config.model ?? DEFAULT_MODEL_NAME,
|
||||||
|
temperature: config.temperature ?? DEFAULT_TEMPERATURE,
|
||||||
|
maxTokens: config.maxTokens ?? DEFAULT_MAX_TOKENS,
|
||||||
|
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class LLM extends EventTarget {
|
export class LLM extends EventTarget {
|
||||||
config: Required<LLMConfig>
|
config: Required<LLMConfig>
|
||||||
@@ -75,3 +75,48 @@ export interface OpenAIClientConfig {
|
|||||||
maxTokens?: number
|
maxTokens?: number
|
||||||
maxRetries?: number
|
maxRetries?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LLM configuration for PageAgent
|
||||||
|
*/
|
||||||
|
export interface LLMConfig {
|
||||||
|
baseURL?: string
|
||||||
|
apiKey?: string
|
||||||
|
model?: string
|
||||||
|
temperature?: number
|
||||||
|
maxTokens?: number
|
||||||
|
maxRetries?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent brain state - the reflection-before-action model
|
||||||
|
*
|
||||||
|
* Every tool call must first reflect on:
|
||||||
|
* - evaluation_previous_goal: How well did the previous action achieve its goal?
|
||||||
|
* - memory: Key information to remember for future steps
|
||||||
|
* - next_goal: What should be accomplished in the next action?
|
||||||
|
*/
|
||||||
|
export interface AgentBrain {
|
||||||
|
// thinking?: string
|
||||||
|
evaluation_previous_goal: string
|
||||||
|
memory: string
|
||||||
|
next_goal: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MacroTool input structure
|
||||||
|
*
|
||||||
|
* This is the core abstraction that enforces the "reflection-before-action" mental model.
|
||||||
|
* Before executing any action, the LLM must output its reasoning state.
|
||||||
|
*/
|
||||||
|
export interface MacroToolInput extends AgentBrain {
|
||||||
|
action: Record<string, any>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MacroTool output structure
|
||||||
|
*/
|
||||||
|
export interface MacroToolResult {
|
||||||
|
input: MacroToolInput
|
||||||
|
output: string
|
||||||
|
}
|
||||||
@@ -4,9 +4,8 @@
|
|||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import type { MacroToolInput } from '../PageAgent'
|
|
||||||
import { InvokeError, InvokeErrorType } from './errors'
|
import { InvokeError, InvokeErrorType } from './errors'
|
||||||
import type { Tool } from './types'
|
import type { MacroToolInput, Tool } from './types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert Zod schema to OpenAI tool format
|
* Convert Zod schema to OpenAI tool format
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
// @workaround DTS bug
|
||||||
|
// dts do not work with monorepo path mapping
|
||||||
|
// disable path mapping for it
|
||||||
|
"paths": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo",
|
||||||
|
"noEmit": false,
|
||||||
|
"allowImportingTsExtensions": false,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"outDir": "dist"
|
||||||
|
},
|
||||||
|
"include": ["**/*.ts"],
|
||||||
|
"exclude": ["dist", "node_modules"]
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// @ts-check
|
||||||
|
import chalk from 'chalk'
|
||||||
|
import { dirname, resolve } from 'path'
|
||||||
|
import dts from 'unplugin-dts/vite'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
import { defineConfig } from 'vite'
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
console.log(chalk.cyan(`📦 Building @page-agent/llms`))
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
clearScreen: false,
|
||||||
|
plugins: [dts({ tsconfigPath: './tsconfig.dts.json', bundleTypes: true })],
|
||||||
|
publicDir: false,
|
||||||
|
esbuild: {
|
||||||
|
keepNames: true,
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: resolve(__dirname, 'src/index.ts'),
|
||||||
|
name: 'PageAgentLLMs',
|
||||||
|
fileName: 'page-agent-llms',
|
||||||
|
formats: ['es'],
|
||||||
|
},
|
||||||
|
outDir: resolve(__dirname, 'dist', 'lib'),
|
||||||
|
rollupOptions: {
|
||||||
|
external: ['chalk', 'zod'],
|
||||||
|
},
|
||||||
|
minify: false,
|
||||||
|
sourcemap: true,
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
'process.env.NODE_ENV': '"production"',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "page-agent",
|
"name": "page-agent",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "0.0.9",
|
"version": "0.0.15",
|
||||||
"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,17 @@
|
|||||||
},
|
},
|
||||||
"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.9",
|
"@page-agent/llms": "0.0.15",
|
||||||
"@page-agent/ui": "0.0.9"
|
"@page-agent/page-controller": "0.0.15",
|
||||||
|
"@page-agent/ui": "0.0.15"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
* Copyright (C) 2025 Alibaba Group Holding Limited
|
* Copyright (C) 2025 Alibaba Group Holding Limited
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
import {
|
||||||
|
type AgentBrain,
|
||||||
|
LLM,
|
||||||
|
type MacroToolInput,
|
||||||
|
type MacroToolResult,
|
||||||
|
type Tool,
|
||||||
|
} from '@page-agent/llms'
|
||||||
import { PageController } from '@page-agent/page-controller'
|
import { PageController } from '@page-agent/page-controller'
|
||||||
import { Panel, SimulatorMask } from '@page-agent/ui'
|
import { Panel, SimulatorMask } from '@page-agent/ui'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
@@ -9,7 +16,6 @@ import zod from 'zod'
|
|||||||
|
|
||||||
import type { PageAgentConfig } from './config'
|
import type { PageAgentConfig } from './config'
|
||||||
import { MAX_STEPS } from './config/constants'
|
import { MAX_STEPS } from './config/constants'
|
||||||
import { LLM, type Tool } from './llms'
|
|
||||||
import SYSTEM_PROMPT from './prompts/system_prompt.md?raw'
|
import SYSTEM_PROMPT from './prompts/system_prompt.md?raw'
|
||||||
import { tools } from './tools'
|
import { tools } from './tools'
|
||||||
import { trimLines, uid, waitUntil } from './utils'
|
import { trimLines, uid, waitUntil } from './utils'
|
||||||
@@ -17,31 +23,7 @@ import { assert } from './utils/assert'
|
|||||||
|
|
||||||
export type { PageAgentConfig }
|
export type { PageAgentConfig }
|
||||||
export { tool, type PageAgentTool } from './tools'
|
export { tool, type PageAgentTool } from './tools'
|
||||||
|
export type { AgentBrain, MacroToolInput, MacroToolResult }
|
||||||
export interface AgentBrain {
|
|
||||||
// thinking?: string
|
|
||||||
evaluation_previous_goal: string
|
|
||||||
memory: string
|
|
||||||
next_goal: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MacroTool input structure
|
|
||||||
*/
|
|
||||||
export interface MacroToolInput {
|
|
||||||
evaluation_previous_goal?: string
|
|
||||||
memory?: string
|
|
||||||
next_goal?: string
|
|
||||||
action: Record<string, any>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MacroTool output structure
|
|
||||||
*/
|
|
||||||
export interface MacroToolResult {
|
|
||||||
input: MacroToolInput
|
|
||||||
output: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AgentHistory {
|
export interface AgentHistory {
|
||||||
brain: AgentBrain
|
brain: AgentBrain
|
||||||
|
|||||||
@@ -1,22 +1,2 @@
|
|||||||
// Dev environment: use .env config if available, otherwise fallback to testing api
|
// Agent-specific constants (LLM constants moved to @page-agent/llms)
|
||||||
export const DEFAULT_MODEL_NAME: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_MODEL_NAME
|
|
||||||
? import.meta.env.LLM_MODEL_NAME
|
|
||||||
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
|
|
||||||
export const DEFAULT_API_KEY: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_API_KEY
|
|
||||||
? import.meta.env.LLM_API_KEY
|
|
||||||
: 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|
||||||
|
|
||||||
export const DEFAULT_BASE_URL: string =
|
|
||||||
import.meta.env.DEV && import.meta.env.LLM_BASE_URL
|
|
||||||
? import.meta.env.LLM_BASE_URL
|
|
||||||
: 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
|
||||||
|
|
||||||
// internal
|
|
||||||
|
|
||||||
export const LLM_MAX_RETRIES = 2
|
|
||||||
export const MAX_STEPS = 20
|
export const MAX_STEPS = 20
|
||||||
export const DEFAULT_TEMPERATURE = 0.7 // higher randomness helps auto-recovery
|
|
||||||
export const DEFAULT_MAX_TOKENS = 4096
|
|
||||||
|
|||||||
@@ -1,25 +1,11 @@
|
|||||||
|
import type { LLMConfig } from '@page-agent/llms'
|
||||||
import type { PageControllerConfig } from '@page-agent/page-controller'
|
import type { PageControllerConfig } from '@page-agent/page-controller'
|
||||||
import type { SupportedLanguage } from '@page-agent/ui'
|
import type { SupportedLanguage } from '@page-agent/ui'
|
||||||
|
|
||||||
import type { AgentHistory, ExecutionResult, PageAgent } from '../PageAgent'
|
import type { AgentHistory, ExecutionResult, PageAgent } from '../PageAgent'
|
||||||
import type { PageAgentTool } from '../tools'
|
import type { PageAgentTool } from '../tools'
|
||||||
import {
|
|
||||||
DEFAULT_API_KEY,
|
|
||||||
DEFAULT_BASE_URL,
|
|
||||||
DEFAULT_MAX_TOKENS,
|
|
||||||
DEFAULT_MODEL_NAME,
|
|
||||||
DEFAULT_TEMPERATURE,
|
|
||||||
LLM_MAX_RETRIES,
|
|
||||||
} from './constants'
|
|
||||||
|
|
||||||
export interface LLMConfig {
|
export type { LLMConfig }
|
||||||
baseURL?: string
|
|
||||||
apiKey?: string
|
|
||||||
model?: string
|
|
||||||
temperature?: number
|
|
||||||
maxTokens?: number
|
|
||||||
maxRetries?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AgentConfig {
|
export interface AgentConfig {
|
||||||
// theme?: 'light' | 'dark'
|
// theme?: 'light' | 'dark'
|
||||||
@@ -96,14 +82,3 @@ export interface AgentConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type PageAgentConfig = LLMConfig & AgentConfig & PageControllerConfig
|
export type PageAgentConfig = LLMConfig & AgentConfig & PageControllerConfig
|
||||||
|
|
||||||
export function parseLLMConfig(config: LLMConfig): Required<LLMConfig> {
|
|
||||||
return {
|
|
||||||
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
|
||||||
apiKey: config.apiKey ?? DEFAULT_API_KEY,
|
|
||||||
model: config.model ?? DEFAULT_MODEL_NAME,
|
|
||||||
temperature: config.temperature ?? DEFAULT_TEMPERATURE,
|
|
||||||
maxTokens: config.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
||||||
maxRetries: config.maxRetries ?? LLM_MAX_RETRIES,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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,18 @@
|
|||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@page-agent/page-controller": ["../page-controller/src/PageController.ts"]
|
//
|
||||||
|
"@page-agent/llms": ["../llms/src/index.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": "../llms" },
|
||||||
|
{ "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,45 @@
|
|||||||
|
// @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/llms': resolve(__dirname, '../llms/src/index.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.9",
|
"version": "0.0.15",
|
||||||
"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.9",
|
"version": "0.0.15",
|
||||||
"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.9",
|
"version": "0.0.15",
|
||||||
"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,19 @@
|
|||||||
"@/*": ["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/llms": ["../llms/src/index.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": "../llms" },
|
||||||
|
{ "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: './',
|
||||||
@@ -19,6 +22,7 @@ export default defineConfig({
|
|||||||
'@': resolve(__dirname, 'src'),
|
'@': resolve(__dirname, 'src'),
|
||||||
|
|
||||||
// Monorepo packages (always bundle local code instead of npm versions)
|
// Monorepo packages (always bundle local code instead of npm versions)
|
||||||
|
'@page-agent/llms': resolve(__dirname, '../llms/src/index.ts'),
|
||||||
'@page-agent/page-controller': resolve(__dirname, '../page-controller/src/PageController.ts'),
|
'@page-agent/page-controller': resolve(__dirname, '../page-controller/src/PageController.ts'),
|
||||||
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
'@page-agent/ui': resolve(__dirname, '../ui/src/index.ts'),
|
||||||
'page-agent': resolve(__dirname, '../page-agent/src/PageAgent.ts'),
|
'page-agent': resolve(__dirname, '../page-agent/src/PageAgent.ts'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"references": [
|
"references": [
|
||||||
{ "path": "./packages/page-controller" },
|
{ "path": "./packages/page-controller" },
|
||||||
{ "path": "./packages/ui" },
|
{ "path": "./packages/ui" },
|
||||||
|
{ "path": "./packages/llms" },
|
||||||
{ "path": "./packages/page-agent" },
|
{ "path": "./packages/page-agent" },
|
||||||
{ "path": "./packages/website" }
|
{ "path": "./packages/website" }
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user