page-agent 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PageAgent 🤖🪄
2
2
 
3
- > Unfinished Project. See [**Roadmap**](./ROADMAP.md)
3
+ > ⚠️ See [**Roadmap**](./ROADMAP.md)
4
4
 
5
5
  ![banner](https://img.alicdn.com/imgextra/i1/O1CN01RY0Wvh26ATVeDIX7v_!!6000000007621-0-tps-1672-512.jpg)
6
6
 
@@ -32,11 +32,9 @@ An in-page UI agent in javascript. Control web interfaces with natural language.
32
32
 
33
33
  ### CDN Integration
34
34
 
35
- > **TODO**: CDN endpoint to be determined.
36
-
37
35
  ```html
38
- <!-- CDN script tag - URL to be updated -->
39
- <script src="TODO-CDN-URL"></script>
36
+ <!-- temporary CDN URL. May change in the future -->
37
+ <script src="https://hwcxiuzfylggtcktqgij.supabase.co/storage/v1/object/public/demo-public/v0.0.2/page-agent.js" crossorigin="true" type="text/javascript"></script>
40
38
  ```
41
39
 
42
40
  ### NPM Installation
@@ -48,10 +46,18 @@ npm install page-agent
48
46
  ```javascript
49
47
  import { PageAgent } from 'page-agent'
50
48
 
49
+ // test server
50
+ // @note: rate limit. prompt limit. Origin limit. May change anytime. Use your own llm!
51
+ // @note Using official DeepSeek-chat(3.2). Go to DeepSeek website for privacy policy.
52
+ const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
53
+ const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
54
+ const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
55
+
51
56
  const agent = new PageAgent({
52
- modelName: 'gpt-4.1-mini',
53
- baseURL: 'xxxx',
54
- apiKey: 'xxxx'
57
+ modelName: DEMO_MODEL,
58
+ baseURL: DEMO_BASE_URL,
59
+ apiKey: DEMO_API_KEY,
60
+ language: 'en-US'
55
61
  })
56
62
 
57
63
  await agent.execute("Click the login button")
@@ -91,7 +97,6 @@ Please read our [Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing Guide](C
91
97
  This project builds upon the excellent work of:
92
98
 
93
99
  - **[browser-use](https://github.com/browser-use/browser-use)**
94
- - **[ai-sdk](https://ai-sdk.dev/)**
95
100
 
96
101
  PageAgent is designed for **client-side web enhancement**, not server-side automation.
97
102
 
@@ -22,7 +22,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
22
22
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
23
23
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
24
24
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
25
- var _bus, _wrapper, _indicator, _statusText, _historySection, _expandButton, _pauseButton, _stopButton, _inputSection, _taskInput, _bus2, _state, _isExpanded, _pageAgent, _userAnswerResolver, _isWaitingForUserAnswer, _Panel_instances, update_fn, show_fn, hide_fn, reset_fn, togglePause_fn, updatePauseButton_fn, stopAgent_fn, submitTask_fn, handleUserAnswer_fn, showInputArea_fn, hideInputArea_fn, shouldShowInputArea_fn, createWrapper_fn, setupEventListeners_fn, toggle_fn, expand_fn, collapse_fn, animateTextChange_fn, updateStatusIndicator_fn, updateHistory_fn, scrollToBottom_fn, createHistoryItem_fn, _cursor, _currentCursorX, _currentCursorY, _targetCursorX, _targetCursorY, _SimulatorMask_instances, createCursor_fn, moveCursorToTarget_fn, _llm, _totalWaitTime, _abortController, _PageAgent_instances, packMacroTool_fn, getSystemPrompt_fn, assembleUserPrompt_fn, onDone_fn, getBrowserState_fn, updateTree_fn;
25
+ var _bus, _wrapper, _indicator, _statusText, _historySection, _expandButton, _pauseButton, _stopButton, _inputSection, _taskInput, _bus2, _state, _isExpanded, _pageAgent, _userAnswerResolver, _isWaitingForUserAnswer, _headerUpdateTimer, _pendingHeaderText, _isAnimating, _Panel_instances, update_fn, show_fn, hide_fn, reset_fn, togglePause_fn, updatePauseButton_fn, stopAgent_fn, submitTask_fn, handleUserAnswer_fn, showInputArea_fn, hideInputArea_fn, shouldShowInputArea_fn, createWrapper_fn, setupEventListeners_fn, toggle_fn, expand_fn, collapse_fn, startHeaderUpdateLoop_fn, stopHeaderUpdateLoop_fn, checkAndUpdateHeader_fn, animateTextChange_fn, updateStatusIndicator_fn, updateHistory_fn, scrollToBottom_fn, createHistoryItem_fn, _cursor, _currentCursorX, _currentCursorY, _targetCursorX, _targetCursorY, _SimulatorMask_instances, createCursor_fn, moveCursorToTarget_fn, _llm, _totalWaitTime, _abortController, _PageAgent_instances, packMacroTool_fn, getSystemPrompt_fn, assembleUserPrompt_fn, onDone_fn, getBrowserState_fn, updateTree_fn;
26
26
  import chalk from "chalk";
27
27
  import zod, { z } from "zod";
28
28
  import { Motion } from "ai-motion";
@@ -2626,6 +2626,9 @@ const _Panel = class _Panel {
2626
2626
  __privateAdd(this, _pageAgent);
2627
2627
  __privateAdd(this, _userAnswerResolver, null);
2628
2628
  __privateAdd(this, _isWaitingForUserAnswer, false);
2629
+ __privateAdd(this, _headerUpdateTimer, null);
2630
+ __privateAdd(this, _pendingHeaderText, null);
2631
+ __privateAdd(this, _isAnimating, false);
2629
2632
  __privateSet(this, _pageAgent, pageAgent);
2630
2633
  __privateSet(this, _bus2, pageAgent.bus);
2631
2634
  __privateSet(this, _wrapper, __privateMethod(this, _Panel_instances, createWrapper_fn).call(this));
@@ -2638,6 +2641,7 @@ const _Panel = class _Panel {
2638
2641
  __privateSet(this, _inputSection, __privateGet(this, _wrapper).querySelector(`.${styles$1.inputSectionWrapper}`));
2639
2642
  __privateSet(this, _taskInput, __privateGet(this, _wrapper).querySelector(`.${styles$1.taskInput}`));
2640
2643
  __privateMethod(this, _Panel_instances, setupEventListeners_fn).call(this);
2644
+ __privateMethod(this, _Panel_instances, startHeaderUpdateLoop_fn).call(this);
2641
2645
  __privateMethod(this, _Panel_instances, showInputArea_fn).call(this);
2642
2646
  __privateGet(this, _bus2).on("panel:show", () => __privateMethod(this, _Panel_instances, show_fn).call(this));
2643
2647
  __privateGet(this, _bus2).on("panel:hide", () => __privateMethod(this, _Panel_instances, hide_fn).call(this));
@@ -2671,6 +2675,7 @@ const _Panel = class _Panel {
2671
2675
  */
2672
2676
  dispose() {
2673
2677
  __privateSet(this, _isWaitingForUserAnswer, false);
2678
+ __privateMethod(this, _Panel_instances, stopHeaderUpdateLoop_fn).call(this);
2674
2679
  this.wrapper.remove();
2675
2680
  }
2676
2681
  };
@@ -2689,13 +2694,17 @@ _isExpanded = new WeakMap();
2689
2694
  _pageAgent = new WeakMap();
2690
2695
  _userAnswerResolver = new WeakMap();
2691
2696
  _isWaitingForUserAnswer = new WeakMap();
2697
+ _headerUpdateTimer = new WeakMap();
2698
+ _pendingHeaderText = new WeakMap();
2699
+ _isAnimating = new WeakMap();
2692
2700
  _Panel_instances = new WeakSet();
2693
- update_fn = /* @__PURE__ */ __name(async function(stepData) {
2701
+ /**
2702
+ * Update status
2703
+ */
2704
+ update_fn = /* @__PURE__ */ __name(function(stepData) {
2694
2705
  const step = __privateGet(this, _state).addStep(stepData);
2695
2706
  const headerText = truncate(step.displayText, 20);
2696
- if (__privateGet(this, _statusText).textContent !== headerText) {
2697
- await __privateMethod(this, _Panel_instances, animateTextChange_fn).call(this, headerText);
2698
- }
2707
+ __privateSet(this, _pendingHeaderText, headerText);
2699
2708
  __privateMethod(this, _Panel_instances, updateStatusIndicator_fn).call(this, step.type);
2700
2709
  __privateMethod(this, _Panel_instances, updateHistory_fn).call(this);
2701
2710
  if (step.type === "completed" || step.type === "error") {
@@ -2933,19 +2942,53 @@ collapse_fn = /* @__PURE__ */ __name(function() {
2933
2942
  this.wrapper.classList.add(styles$1.collapsed);
2934
2943
  __privateGet(this, _expandButton).textContent = "▼";
2935
2944
  }, "#collapse");
2936
- animateTextChange_fn = /* @__PURE__ */ __name(async function(newText) {
2937
- return new Promise((resolve) => {
2938
- __privateGet(this, _statusText).classList.add(styles$1.fadeOut);
2945
+ /**
2946
+ * Start periodic header update loop
2947
+ */
2948
+ startHeaderUpdateLoop_fn = /* @__PURE__ */ __name(function() {
2949
+ __privateSet(this, _headerUpdateTimer, setInterval(() => {
2950
+ __privateMethod(this, _Panel_instances, checkAndUpdateHeader_fn).call(this);
2951
+ }, 450));
2952
+ }, "#startHeaderUpdateLoop");
2953
+ /**
2954
+ * Stop periodic header update loop
2955
+ */
2956
+ stopHeaderUpdateLoop_fn = /* @__PURE__ */ __name(function() {
2957
+ if (__privateGet(this, _headerUpdateTimer)) {
2958
+ clearInterval(__privateGet(this, _headerUpdateTimer));
2959
+ __privateSet(this, _headerUpdateTimer, null);
2960
+ }
2961
+ }, "#stopHeaderUpdateLoop");
2962
+ /**
2963
+ * Check if header needs update and trigger animation if not currently animating
2964
+ */
2965
+ checkAndUpdateHeader_fn = /* @__PURE__ */ __name(function() {
2966
+ if (!__privateGet(this, _pendingHeaderText) || __privateGet(this, _isAnimating)) {
2967
+ return;
2968
+ }
2969
+ if (__privateGet(this, _statusText).textContent === __privateGet(this, _pendingHeaderText)) {
2970
+ __privateSet(this, _pendingHeaderText, null);
2971
+ return;
2972
+ }
2973
+ const textToShow = __privateGet(this, _pendingHeaderText);
2974
+ __privateSet(this, _pendingHeaderText, null);
2975
+ __privateMethod(this, _Panel_instances, animateTextChange_fn).call(this, textToShow);
2976
+ }, "#checkAndUpdateHeader");
2977
+ /**
2978
+ * Animate text change with fade out/in effect
2979
+ */
2980
+ animateTextChange_fn = /* @__PURE__ */ __name(function(newText) {
2981
+ __privateSet(this, _isAnimating, true);
2982
+ __privateGet(this, _statusText).classList.add(styles$1.fadeOut);
2983
+ setTimeout(() => {
2984
+ __privateGet(this, _statusText).textContent = newText;
2985
+ __privateGet(this, _statusText).classList.remove(styles$1.fadeOut);
2986
+ __privateGet(this, _statusText).classList.add(styles$1.fadeIn);
2939
2987
  setTimeout(() => {
2940
- __privateGet(this, _statusText).textContent = newText;
2941
- __privateGet(this, _statusText).classList.remove(styles$1.fadeOut);
2942
- __privateGet(this, _statusText).classList.add(styles$1.fadeIn);
2943
- setTimeout(() => {
2944
- __privateGet(this, _statusText).classList.remove(styles$1.fadeIn);
2945
- resolve();
2946
- }, 300);
2947
- }, 150);
2948
- });
2988
+ __privateGet(this, _statusText).classList.remove(styles$1.fadeIn);
2989
+ __privateSet(this, _isAnimating, false);
2990
+ }, 300);
2991
+ }, 150);
2949
2992
  }, "#animateTextChange");
2950
2993
  updateStatusIndicator_fn = /* @__PURE__ */ __name(function(type) {
2951
2994
  __privateGet(this, _indicator).className = styles$1.indicator;