page-agent 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alibaba
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,23 @@
1
+ Page-Agent
2
+ Copyright (c) 2025 Alibaba Group Holding Limited
3
+ Author: Simon<gaomeng1900>
4
+
5
+ This project incorporates work covered by the following copyright and permission notices:
6
+
7
+ ================================================================================
8
+
9
+ Browser Use
10
+ Copyright (c) 2024 Gregor Zunic
11
+ Licensed under the MIT License
12
+
13
+ Original browser-use project: https://github.com/browser-use/browser-use
14
+ License: MIT License
15
+
16
+ We gratefully acknowledge the browser-use project and its contributors for their
17
+ excellent work on web automation and DOM interaction patterns that helped make
18
+ this project possible.
19
+
20
+ ================================================================================
21
+
22
+ Third-party dependencies and their licenses can be found in the package.json
23
+ file and in the node_modules directory after installation.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # PageAgent πŸ€–
2
+
3
+ [![npm version](https://badge.fury.io/js/page-agent.svg)](https://badge.fury.io/js/page-agent) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) [![Downloads](https://img.shields.io/npm/dt/page-agent.svg)](https://www.npmjs.com/package/page-agent) [![Bundle Size](https://img.shields.io/bundlephobia/minzip/page-agent)](https://bundlephobia.com/package/page-agent) [![GitHub stars](https://img.shields.io/github/stars/gaomeng1900/page-agent.svg)](https://github.com/gaomeng1900/page-agent)
4
+
5
+ **Transform any webpage into an AI-powered application with a single script tag.**
6
+
7
+ PageAgent is an intelligent UI agent for web automation and DOM interaction. Built on browser-use architecture, it enables natural language control of web interfaces through LLM integration.
8
+
9
+ 🌐 **English** | [δΈ­ζ–‡](./README-zh.md)
10
+
11
+ πŸ‘‰ [πŸ“– **Documentation**](#) | [πŸš€ **Try Demo**](#)
12
+
13
+ ---
14
+
15
+ ## ✨ Features
16
+
17
+ - **🎯 Easy Integration** - Add to any webpage via CDN or npm
18
+ - **πŸ” Client-Side Processing** - No data leaves the browser
19
+ - **🧠 DOM Extraction**
20
+ - **πŸ’¬ Natural Language Interface**
21
+ - **🎨 UI with Human in the loop**
22
+
23
+ ## πŸ—ΊοΈ Roadmap
24
+
25
+ πŸ‘‰ [**Roadmap**](./ROADMAP.md)
26
+
27
+ ## πŸš€ Quick Start
28
+
29
+ ### CDN Integration
30
+
31
+ > **TODO**: CDN endpoint to be determined.
32
+
33
+ ```html
34
+ <!-- CDN script tag - URL to be updated -->
35
+ <script src="TODO-CDN-URL"></script>
36
+ ```
37
+
38
+ ### NPM Installation
39
+
40
+ ```bash
41
+ npm install page-agent
42
+ ```
43
+
44
+ ```javascript
45
+ import { PageAgent } from 'page-agent'
46
+
47
+ const agent = new PageAgent({
48
+ modelName: 'gpt-4.1-mini'
49
+ baseURL: 'xxxx',
50
+ apiKey: 'xxxx'
51
+ })
52
+
53
+ await agent.execute("Click the login button")
54
+ ```
55
+
56
+ ## πŸ—οΈ Structure
57
+
58
+ PageAgent follows a clean, modular architecture:
59
+
60
+ ```
61
+ src/
62
+ β”œβ”€β”€ PageAgent.ts # Agent main loop
63
+ β”œβ”€β”€ dom/ # DOM processing
64
+ β”œβ”€β”€ tools/ # Agent tools
65
+ β”œβ”€β”€ ui/ # UI components & panels
66
+ β”œβ”€β”€ llms/ # LLM integration layer
67
+ └── utils/ # Event bus & utilities
68
+ ```
69
+
70
+ ## 🀝 Contributing
71
+
72
+ We welcome contributions from the community! Here's how to get started:
73
+
74
+ ### Setup
75
+
76
+ 1. Fork the repository
77
+ 2. Clone your fork: `git clone https://github.com/alibaba/page-agent.git && cd page-agent`
78
+ 3. Install dependencies: `npm install`
79
+ 4. Start development: `npm start`
80
+
81
+ ### Contributing Guidelines
82
+
83
+ Please read our [Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing Guide](CONTRIBUTING.md) before contributing.
84
+
85
+ ## πŸ‘ Acknowledgments
86
+
87
+ This project builds upon the excellent work of:
88
+
89
+ - **[browser-use](https://github.com/browser-use/browser-use)**
90
+ - **[ai-sdk](https://ai-sdk.dev/)**
91
+
92
+ PageAgent is designed for **client-side web enhancement**, not server-side automation.
93
+
94
+ ## πŸ“„ License
95
+
96
+ MIT License - see the [LICENSE](LICENSE) file for details.
97
+
98
+ DOM processing components and prompt are derived from [browser-use](https://github.com/browser-use/browser-use) (MIT License). See [NOTICE](NOTICE) for full attribution.
99
+
100
+ ---
101
+
102
+ **⭐ Star this repo if you find PageAgent helpful!**
@@ -0,0 +1,297 @@
1
+ import { LanguageModelUsage } from 'ai';
2
+ import { Motion } from 'ai-motion';
3
+ import { Tool } from 'ai';
4
+
5
+ export declare interface AgentBrain {
6
+ evaluation_previous_goal: string;
7
+ memory: string;
8
+ next_goal: string;
9
+ }
10
+
11
+ export declare interface AgentHistory {
12
+ brain: AgentBrain;
13
+ action: {
14
+ name: string;
15
+ input: any;
16
+ output: any;
17
+ };
18
+ usage: LanguageModelUsage;
19
+ }
20
+
21
+ declare interface DomConfig {
22
+ interactiveBlacklist?: (Element | (() => Element))[];
23
+ interactiveWhitelist?: (Element | (() => Element))[];
24
+ include_attributes?: string[];
25
+ highlightOpacity?: number;
26
+ highlightLabelOpacity?: number;
27
+ }
28
+
29
+ declare type DomNode = TextDomNode | ElementDomNode | InteractiveElementDomNode;
30
+
31
+ declare interface ElementDomNode {
32
+ tagName: string;
33
+ attributes?: Record<string, string>;
34
+ xpath?: string;
35
+ children?: string[];
36
+ isVisible?: boolean;
37
+ isTopElement?: boolean;
38
+ isInViewport?: boolean;
39
+ isNew?: boolean;
40
+ isInteractive?: false;
41
+ highlightIndex?: number;
42
+ extra?: Record<string, any>;
43
+ [key: string]: unknown;
44
+ }
45
+
46
+ /**
47
+ * Type-safe event bus
48
+ * @note Mainly used to decouple logic and UI
49
+ * @note All modules of a PageAgent instance share the same EventBus instance for communication
50
+ * @note Use with caution if delivery guarantee is needed for logic communication
51
+ * @note `on` `once` `emit` methods handle built-in events with type protection, use `addEventListener` for other events
52
+ */
53
+ declare class EventBus extends EventTarget {
54
+ /**
55
+ * Listen to built-in events
56
+ */
57
+ on<T extends keyof PageAgentEventMap>(event: T, handler: EventHandler<T & keyof PageAgentEventMap>): void;
58
+ /**
59
+ * Listen to built-in events (one-time)
60
+ */
61
+ once<T extends keyof PageAgentEventMap>(event: T, handler: EventHandler<T & keyof PageAgentEventMap>): void;
62
+ /**
63
+ * Emit built-in events
64
+ */
65
+ emit<T extends keyof PageAgentEventMap>(event: T, ...args: PageAgentEventMap[T]['params'] extends undefined ? [] : [PageAgentEventMap[T]['params']]): void;
66
+ }
67
+
68
+ /**
69
+ * Event handler type definitions
70
+ */
71
+ declare type EventHandler<T extends keyof PageAgentEventMap> = PageAgentEventMap[T]['params'] extends undefined ? () => void : (params: PageAgentEventMap[T]['params']) => void;
72
+
73
+ export declare interface ExecutionResult {
74
+ success: boolean;
75
+ data: string;
76
+ history: AgentHistory[];
77
+ }
78
+
79
+ declare interface FlatDomTree {
80
+ rootId: string;
81
+ map: Record<string, DomNode>;
82
+ }
83
+
84
+ declare class I18n {
85
+ private language;
86
+ private translations;
87
+ constructor(language?: SupportedLanguage);
88
+ t(key: TranslationKey, params?: TranslationParams): string;
89
+ private getNestedValue;
90
+ private interpolate;
91
+ getLanguage(): SupportedLanguage;
92
+ }
93
+
94
+ declare interface InteractiveElementDomNode {
95
+ tagName: string;
96
+ attributes?: Record<string, string>;
97
+ xpath?: string;
98
+ children?: string[];
99
+ isVisible?: boolean;
100
+ isTopElement?: boolean;
101
+ isInViewport?: boolean;
102
+ isInteractive: true;
103
+ highlightIndex: number;
104
+ /**
105
+ * ε―δΊ€δΊ’ε…ƒη΄ ηš„ dom 引用
106
+ */
107
+ ref: HTMLElement;
108
+ [key: string]: unknown;
109
+ }
110
+
111
+ declare interface LLMConfig {
112
+ baseURL?: string;
113
+ apiKey?: string;
114
+ modelName?: string;
115
+ maxRetries?: number;
116
+ }
117
+
118
+ declare const locales: {
119
+ readonly 'zh-CN': TranslationSchema;
120
+ readonly 'en-US': TranslationSchema;
121
+ };
122
+
123
+ declare type NestedKeyOf<ObjectType extends object> = {
124
+ [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}` | `${Key}.${NestedKeyOf<ObjectType[Key]>}` : `${Key}`;
125
+ }[keyof ObjectType & (string | number)];
126
+
127
+ export declare class PageAgent extends EventTarget {
128
+ #private;
129
+ config: PageAgentConfig;
130
+ id: string;
131
+ bus: EventBus;
132
+ i18n: I18n;
133
+ paused: boolean;
134
+ disposed: boolean;
135
+ task: string;
136
+ /** Corresponds to eval_page in browser-use */
137
+ flatTree: FlatDomTree | null;
138
+ /**
139
+ * All highlighted index-mapped interactive elements
140
+ * Corresponds to DOMState.selector_map in browser-use
141
+ */
142
+ selectorMap: Map<number, InteractiveElementDomNode>;
143
+ /** highlight index -> element text */
144
+ elementTextMap: Map<number, string>;
145
+ /** Corresponds to clickable_elements_to_string in browser-use */
146
+ simplifiedHTML: string;
147
+ /** last time the tree was updated */
148
+ lastTimeUpdate: number;
149
+ /** Corresponds to actions in browser-use */
150
+ tools: Map<string, Tool>;
151
+ /** Fullscreen mask */
152
+ mask: SimulatorMask;
153
+ /** Interactive panel */
154
+ panel: Panel;
155
+ /** History records */
156
+ history: AgentHistory[];
157
+ constructor(config?: PageAgentConfig);
158
+ /**
159
+ * @todo maybe return something?
160
+ */
161
+ execute(task: string): Promise<ExecutionResult>;
162
+ dispose(): void;
163
+ }
164
+
165
+ export declare type PageAgentConfig = LLMConfig & DomConfig & UIConfig;
166
+
167
+ /**
168
+ * Event mapping definitions
169
+ * @note Event bus callbacks must be repeatable without errors
170
+ */
171
+ declare interface PageAgentEventMap {
172
+ 'panel:show': {
173
+ params: undefined;
174
+ };
175
+ 'panel:hide': {
176
+ params: undefined;
177
+ };
178
+ 'panel:reset': {
179
+ params: undefined;
180
+ };
181
+ 'panel:update': {
182
+ params: Omit<Step, 'id' | 'stepNumber' | 'timestamp'>;
183
+ };
184
+ 'panel:expand': {
185
+ params: undefined;
186
+ };
187
+ 'panel:collapse': {
188
+ params: undefined;
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Agent control panel
194
+ */
195
+ declare class Panel {
196
+ #private;
197
+ get wrapper(): HTMLElement;
198
+ constructor(pageAgent: PageAgent);
199
+ /**
200
+ * Ask for user input
201
+ */
202
+ askUser(question: string): Promise<string>;
203
+ /**
204
+ * Dispose panel
205
+ */
206
+ dispose(): void;
207
+ }
208
+
209
+ declare class SimulatorMask {
210
+ #private;
211
+ wrapper: HTMLDivElement;
212
+ motion: Motion;
213
+ constructor();
214
+ setCursorPosition(x: number, y: number): void;
215
+ triggerClickAnimation(): void;
216
+ show(): void;
217
+ hide(): void;
218
+ dispose(): void;
219
+ }
220
+
221
+ /**
222
+ * Agent execution state management
223
+ */
224
+ declare interface Step {
225
+ id: string;
226
+ stepNumber: number;
227
+ timestamp: Date;
228
+ type: 'thinking' | 'tool_executing' | 'completed' | 'error' | 'output' | 'input' | 'retry';
229
+ toolName?: string;
230
+ toolArgs?: any;
231
+ toolResult?: any;
232
+ displayText: string;
233
+ duration?: number;
234
+ }
235
+
236
+ declare type SupportedLanguage = keyof typeof locales;
237
+
238
+ declare interface TextDomNode {
239
+ type: 'TEXT_NODE';
240
+ text: string;
241
+ isVisible: boolean;
242
+ [key: string]: unknown;
243
+ }
244
+
245
+ declare type TranslationKey = NestedKeyOf<TranslationSchema>;
246
+
247
+ declare type TranslationParams = Record<string, string | number>;
248
+
249
+ declare interface TranslationSchema {
250
+ ui: {
251
+ panel: {
252
+ ready: string;
253
+ thinking: string;
254
+ paused: string;
255
+ taskInput: string;
256
+ userAnswerPrompt: string;
257
+ taskTerminated: string;
258
+ taskCompleted: string;
259
+ continueExecution: string;
260
+ userAnswer: string;
261
+ pause: string;
262
+ continue: string;
263
+ stop: string;
264
+ expand: string;
265
+ collapse: string;
266
+ step: string;
267
+ };
268
+ tools: {
269
+ clicking: string;
270
+ inputting: string;
271
+ selecting: string;
272
+ scrolling: string;
273
+ waiting: string;
274
+ done: string;
275
+ clicked: string;
276
+ inputted: string;
277
+ selected: string;
278
+ scrolled: string;
279
+ waited: string;
280
+ executing: string;
281
+ };
282
+ errors: {
283
+ elementNotFound: string;
284
+ taskRequired: string;
285
+ executionFailed: string;
286
+ notInputElement: string;
287
+ notSelectElement: string;
288
+ optionNotFound: string;
289
+ };
290
+ };
291
+ }
292
+
293
+ declare interface UIConfig {
294
+ language?: SupportedLanguage;
295
+ }
296
+
297
+ export { }