@usecrow/client 0.1.27 → 0.1.29

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.
@@ -1,120 +0,0 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(`._wrapper_gf8tz_1{position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483641;cursor:wait;overflow:hidden;display:none}._cursor_1dgwb_2{position:absolute;width:var(--cursor-size, 75px);height:var(--cursor-size, 75px);pointer-events:none;z-index:10000}._cursorBorder_1dgwb_10{position:absolute;width:100%;height:100%;background:linear-gradient(45deg,#39b6ff,#bd45fb);-webkit-mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");-webkit-mask-size:100% 100%;mask-size:100% 100%;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorFilling_1dgwb_25{position:absolute;width:100%;height:100%;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");background-size:100% 100%;background-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorRipple_1dgwb_39{position:absolute;width:100%;height:100%;pointer-events:none;margin-left:-50%;margin-top:-50%}._cursorRipple_1dgwb_39:after{content:"";opacity:0;position:absolute;top:0;right:0;bottom:0;left:0;border:4px solid rgba(57,182,255,1);border-radius:50%}._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39:after{animation:_cursor-ripple_1dgwb_1 .3s ease-out forwards}@keyframes _cursor-ripple_1dgwb_1{0%{transform:scale(0);opacity:1}to{transform:scale(2);opacity:0}}`)),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- var v = (s) => {
3
- throw TypeError(s);
4
- };
5
- var w = (s, t, e) => t.has(s) || v("Cannot " + e);
6
- var r = (s, t, e) => (w(s, t, "read from private field"), e ? e.call(s) : t.get(s)), l = (s, t, e) => t.has(s) ? v("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, e), o = (s, t, e, i) => (w(s, t, "write to private field"), i ? i.call(s, e) : t.set(s, e), e), g = (s, t, e) => (w(s, t, "access private method"), e);
7
- import { Motion as b } from "ai-motion";
8
- function y() {
9
- const s = ["dark", "dark-mode", "theme-dark", "night", "night-mode"], t = document.documentElement, e = document.body || document.documentElement;
10
- for (const m of s)
11
- if (t.classList.contains(m) || e != null && e.classList.contains(m))
12
- return !0;
13
- const i = t.getAttribute("data-theme");
14
- return !!(i != null && i.toLowerCase().includes("dark"));
15
- }
16
- function E(s) {
17
- const t = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(s);
18
- return t ? {
19
- r: parseInt(t[1]),
20
- g: parseInt(t[2]),
21
- b: parseInt(t[3])
22
- } : null;
23
- }
24
- function C(s, t = 128) {
25
- if (!s || s === "transparent" || s.startsWith("rgba(0, 0, 0, 0)"))
26
- return !1;
27
- const e = E(s);
28
- return e ? 0.299 * e.r + 0.587 * e.g + 0.114 * e.b < t : !1;
29
- }
30
- function _() {
31
- const s = window.getComputedStyle(document.documentElement), t = window.getComputedStyle(document.body || document.documentElement), e = s.backgroundColor, i = t.backgroundColor;
32
- return C(i) ? !0 : i === "transparent" || i.startsWith("rgba(0, 0, 0, 0)") ? C(e) : !1;
33
- }
34
- function L() {
35
- try {
36
- return !!(y() || _());
37
- } catch (s) {
38
- return console.warn("Error determining if page is dark:", s), !1;
39
- }
40
- }
41
- const D = "_wrapper_gf8tz_1", P = {
42
- wrapper: D
43
- }, A = "_cursor_1dgwb_2", x = "_cursorBorder_1dgwb_10", M = "_cursorFilling_1dgwb_25", B = "_cursorRipple_1dgwb_39", R = "_clicking_1dgwb_57", d = {
44
- cursor: A,
45
- cursorBorder: x,
46
- cursorFilling: M,
47
- cursorRipple: B,
48
- clicking: R
49
- };
50
- var n, a, c, p, h, u, k, f;
51
- class S {
52
- constructor() {
53
- l(this, u);
54
- l(this, n);
55
- l(this, a);
56
- l(this, c);
57
- l(this, p);
58
- l(this, h);
59
- this.shown = !1, this.wrapper = document.createElement("div"), this.motion = new b({
60
- mode: L() ? "dark" : "light",
61
- styles: {
62
- position: "absolute",
63
- inset: "0"
64
- }
65
- }), o(this, n, document.createElement("div")), o(this, a, 0), o(this, c, 0), o(this, p, 0), o(this, h, 0), this.wrapper.id = "page-agent-runtime_simulator-mask", this.wrapper.className = P.wrapper, this.wrapper.setAttribute("data-browser-use-ignore", "true"), this.wrapper.appendChild(this.motion.element), this.motion.autoResize(this.wrapper), this.wrapper.addEventListener("click", (t) => {
66
- t.stopPropagation(), t.preventDefault();
67
- }), this.wrapper.addEventListener("mousedown", (t) => {
68
- t.stopPropagation(), t.preventDefault();
69
- }), this.wrapper.addEventListener("mouseup", (t) => {
70
- t.stopPropagation(), t.preventDefault();
71
- }), this.wrapper.addEventListener("mousemove", (t) => {
72
- t.stopPropagation(), t.preventDefault();
73
- }), this.wrapper.addEventListener("wheel", (t) => {
74
- t.stopPropagation(), t.preventDefault();
75
- }), this.wrapper.addEventListener("keydown", (t) => {
76
- t.stopPropagation(), t.preventDefault();
77
- }), this.wrapper.addEventListener("keyup", (t) => {
78
- t.stopPropagation(), t.preventDefault();
79
- }), g(this, u, k).call(this), document.body.appendChild(this.wrapper), g(this, u, f).call(this), window.addEventListener("PageAgent::MovePointerTo", (t) => {
80
- const { x: e, y: i } = t.detail;
81
- this.setCursorPosition(e, i);
82
- }), window.addEventListener("PageAgent::ClickPointer", (t) => {
83
- this.triggerClickAnimation();
84
- });
85
- }
86
- setCursorPosition(t, e) {
87
- o(this, p, t), o(this, h, e);
88
- }
89
- triggerClickAnimation() {
90
- r(this, n).classList.remove(d.clicking), r(this, n).offsetHeight, r(this, n).classList.add(d.clicking);
91
- }
92
- show() {
93
- this.shown || (this.shown = !0, this.motion.start(), this.motion.fadeIn(), this.wrapper.style.display = "block", o(this, a, window.innerWidth / 2), o(this, c, window.innerHeight / 2), o(this, p, r(this, a)), o(this, h, r(this, c)), r(this, n).style.left = `${r(this, a)}px`, r(this, n).style.top = `${r(this, c)}px`);
94
- }
95
- hide() {
96
- this.shown && (this.shown = !1, this.motion.fadeOut(), this.motion.pause(), r(this, n).classList.remove(d.clicking), setTimeout(() => {
97
- this.wrapper.style.display = "none";
98
- }, 800));
99
- }
100
- dispose() {
101
- this.motion.dispose(), this.wrapper.remove();
102
- }
103
- }
104
- n = new WeakMap(), a = new WeakMap(), c = new WeakMap(), p = new WeakMap(), h = new WeakMap(), u = new WeakSet(), k = function() {
105
- r(this, n).className = d.cursor;
106
- const t = document.createElement("div");
107
- t.className = d.cursorRipple, r(this, n).appendChild(t);
108
- const e = document.createElement("div");
109
- e.className = d.cursorFilling, r(this, n).appendChild(e);
110
- const i = document.createElement("div");
111
- i.className = d.cursorBorder, r(this, n).appendChild(i), this.wrapper.appendChild(r(this, n));
112
- }, f = function() {
113
- const t = r(this, a) + (r(this, p) - r(this, a)) * 0.2, e = r(this, c) + (r(this, h) - r(this, c)) * 0.2, i = Math.abs(t - r(this, p));
114
- i > 0 && (i < 2 ? o(this, a, r(this, p)) : o(this, a, t), r(this, n).style.left = `${r(this, a)}px`);
115
- const m = Math.abs(e - r(this, h));
116
- m > 0 && (m < 2 ? o(this, c, r(this, h)) : o(this, c, e), r(this, n).style.top = `${r(this, c)}px`), requestAnimationFrame(() => g(this, u, f).call(this));
117
- };
118
- export {
119
- S as SimulatorMask
120
- };
@@ -1,2 +0,0 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(`._wrapper_gf8tz_1{position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483641;cursor:wait;overflow:hidden;display:none}._cursor_1dgwb_2{position:absolute;width:var(--cursor-size, 75px);height:var(--cursor-size, 75px);pointer-events:none;z-index:10000}._cursorBorder_1dgwb_10{position:absolute;width:100%;height:100%;background:linear-gradient(45deg,#39b6ff,#bd45fb);-webkit-mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");mask-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");-webkit-mask-size:100% 100%;mask-size:100% 100%;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorFilling_1dgwb_25{position:absolute;width:100%;height:100%;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");background-size:100% 100%;background-repeat:no-repeat;transform-origin:center;transform:rotate(-135deg) scale(1.2);margin-left:-10px;margin-top:-18px}._cursorRipple_1dgwb_39{position:absolute;width:100%;height:100%;pointer-events:none;margin-left:-50%;margin-top:-50%}._cursorRipple_1dgwb_39:after{content:"";opacity:0;position:absolute;top:0;right:0;bottom:0;left:0;border:4px solid rgba(57,182,255,1);border-radius:50%}._cursor_1dgwb_2._clicking_1dgwb_57 ._cursorRipple_1dgwb_39:after{animation:_cursor-ripple_1dgwb_1 .3s ease-out forwards}@keyframes _cursor-ripple_1dgwb_1{0%{transform:scale(0);opacity:1}to{transform:scale(2);opacity:0}}`)),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- "use strict";var v=s=>{throw TypeError(s)};var w=(s,t,e)=>t.has(s)||v("Cannot "+e);var r=(s,t,e)=>(w(s,t,"read from private field"),e?e.call(s):t.get(s)),h=(s,t,e)=>t.has(s)?v("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),o=(s,t,e,i)=>(w(s,t,"write to private field"),i?i.call(s,e):t.set(s,e),e),g=(s,t,e)=>(w(s,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("ai-motion");function y(){const s=["dark","dark-mode","theme-dark","night","night-mode"],t=document.documentElement,e=document.body||document.documentElement;for(const m of s)if(t.classList.contains(m)||e!=null&&e.classList.contains(m))return!0;const i=t.getAttribute("data-theme");return!!(i!=null&&i.toLowerCase().includes("dark"))}function E(s){const t=/rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(s);return t?{r:parseInt(t[1]),g:parseInt(t[2]),b:parseInt(t[3])}:null}function C(s,t=128){if(!s||s==="transparent"||s.startsWith("rgba(0, 0, 0, 0)"))return!1;const e=E(s);return e?.299*e.r+.587*e.g+.114*e.b<t:!1}function _(){const s=window.getComputedStyle(document.documentElement),t=window.getComputedStyle(document.body||document.documentElement),e=s.backgroundColor,i=t.backgroundColor;return C(i)?!0:i==="transparent"||i.startsWith("rgba(0, 0, 0, 0)")?C(e):!1}function L(){try{return!!(y()||_())}catch(s){return console.warn("Error determining if page is dark:",s),!1}}const D="_wrapper_gf8tz_1",P={wrapper:D},M="_cursor_1dgwb_2",A="_cursorBorder_1dgwb_10",S="_cursorFilling_1dgwb_25",x="_cursorRipple_1dgwb_39",B="_clicking_1dgwb_57",u={cursor:M,cursorBorder:A,cursorFilling:S,cursorRipple:x,clicking:B};var n,a,c,l,p,d,b,f;class R{constructor(){h(this,d);h(this,n);h(this,a);h(this,c);h(this,l);h(this,p);this.shown=!1,this.wrapper=document.createElement("div"),this.motion=new k.Motion({mode:L()?"dark":"light",styles:{position:"absolute",inset:"0"}}),o(this,n,document.createElement("div")),o(this,a,0),o(this,c,0),o(this,l,0),o(this,p,0),this.wrapper.id="page-agent-runtime_simulator-mask",this.wrapper.className=P.wrapper,this.wrapper.setAttribute("data-browser-use-ignore","true"),this.wrapper.appendChild(this.motion.element),this.motion.autoResize(this.wrapper),this.wrapper.addEventListener("click",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mousedown",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mouseup",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("mousemove",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("wheel",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("keydown",t=>{t.stopPropagation(),t.preventDefault()}),this.wrapper.addEventListener("keyup",t=>{t.stopPropagation(),t.preventDefault()}),g(this,d,b).call(this),document.body.appendChild(this.wrapper),g(this,d,f).call(this),window.addEventListener("PageAgent::MovePointerTo",t=>{const{x:e,y:i}=t.detail;this.setCursorPosition(e,i)}),window.addEventListener("PageAgent::ClickPointer",t=>{this.triggerClickAnimation()})}setCursorPosition(t,e){o(this,l,t),o(this,p,e)}triggerClickAnimation(){r(this,n).classList.remove(u.clicking),r(this,n).offsetHeight,r(this,n).classList.add(u.clicking)}show(){this.shown||(this.shown=!0,this.motion.start(),this.motion.fadeIn(),this.wrapper.style.display="block",o(this,a,window.innerWidth/2),o(this,c,window.innerHeight/2),o(this,l,r(this,a)),o(this,p,r(this,c)),r(this,n).style.left=`${r(this,a)}px`,r(this,n).style.top=`${r(this,c)}px`)}hide(){this.shown&&(this.shown=!1,this.motion.fadeOut(),this.motion.pause(),r(this,n).classList.remove(u.clicking),setTimeout(()=>{this.wrapper.style.display="none"},800))}dispose(){this.motion.dispose(),this.wrapper.remove()}}n=new WeakMap,a=new WeakMap,c=new WeakMap,l=new WeakMap,p=new WeakMap,d=new WeakSet,b=function(){r(this,n).className=u.cursor;const t=document.createElement("div");t.className=u.cursorRipple,r(this,n).appendChild(t);const e=document.createElement("div");e.className=u.cursorFilling,r(this,n).appendChild(e);const i=document.createElement("div");i.className=u.cursorBorder,r(this,n).appendChild(i),this.wrapper.appendChild(r(this,n))},f=function(){const t=r(this,a)+(r(this,l)-r(this,a))*.2,e=r(this,c)+(r(this,p)-r(this,c))*.2,i=Math.abs(t-r(this,l));i>0&&(i<2?o(this,a,r(this,l)):o(this,a,t),r(this,n).style.left=`${r(this,a)}px`);const m=Math.abs(e-r(this,p));m>0&&(m<2?o(this,c,r(this,p)):o(this,c,e),r(this,n).style.top=`${r(this,c)}px`),requestAnimationFrame(()=>g(this,d,f).call(this))};exports.SimulatorMask=R;
@@ -1 +0,0 @@
1
- "use strict";let c=null,l=null;function p(i){c=i}async function w(){if(c)return c;if(!l)try{l=await Promise.resolve().then(()=>require("./PageController-GcMFZYwU.cjs"))}catch{throw new Error('PageController not available. Either import from "@usecrow/client/browser" or use the bundled version.')}return l.PageController}class u{constructor(t){this.pageController=null,this.sessionId=null,this.maxSteps=20,this.config=t}async initPageController(){if(this.pageController)return this.pageController;try{const t=await w();this.pageController=new t({enableMask:!0,viewportExpansion:500,highlightLabelOpacity:0,highlightOpacity:0}),await this.pageController.showMask();const e=this.pageController.mask;return e!=null&&e.wrapper&&(e.wrapper.style.pointerEvents="none"),console.log("[CrowBrowserUse] PageController initialized with non-blocking pointer"),this.pageController}catch(t){throw console.error("[CrowBrowserUse] Failed to initialize PageController:",t),new Error("Failed to initialize browser automation. Please import from @usecrow/client/browser.")}}async execute(t){console.log("[CrowBrowserUse] Starting task:",t);try{const e=await this.initPageController(),o=await this.startSession(t);this.sessionId=o.session_id,this.maxSteps=o.max_steps,console.log("[CrowBrowserUse] Session started:",this.sessionId);let r=0,s;for(;r<this.maxSteps;){r++;const a=await e.getBrowserState(),n=await this.processStep(a,s);if(n.done)return console.log("[CrowBrowserUse] Task completed:",n.message),await this.cleanup(),{status:n.success?"success":"error",data:{message:n.message,steps:r},error:n.success?void 0:n.message};if(n.error)return console.error("[CrowBrowserUse] Error:",n.error),await this.cleanup(),{status:"error",error:n.error};n.action&&(s=await this.executeAction(e,n.action),console.log(`[CrowBrowserUse] Step ${r}:`,s)),n.reflection&&console.log("[CrowBrowserUse] Reflection:",n.reflection.next_goal)}return await this.cleanup(),{status:"error",error:`Task incomplete after ${this.maxSteps} steps`}}catch(e){return console.error("[CrowBrowserUse] Error:",e),await this.cleanup(),{status:"error",error:e instanceof Error?e.message:String(e)}}}async startSession(t){const e=await fetch(`${this.config.apiUrl}/api/browser-use/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({product_id:this.config.productId,task:t})});if(!e.ok){const o=await e.json().catch(()=>({detail:"Unknown error"}));throw new Error(o.detail||`Failed to start session: ${e.status}`)}return e.json()}async processStep(t,e){const o=await fetch(`${this.config.apiUrl}/api/browser-use/step`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:this.sessionId,product_id:this.config.productId,browser_state:t,action_result:e})});if(!o.ok){const r=await o.json().catch(()=>({detail:"Unknown error"}));throw new Error(r.detail||`Failed to process step: ${o.status}`)}return o.json()}async executeAction(t,e){const o=Object.keys(e)[0],r=e[o];try{switch(o){case"click_element_by_index":return(await t.clickElement(r.index)).message;case"input_text":return(await t.inputText(r.index,r.text)).message;case"select_dropdown_option":return(await t.selectOption(r.index,r.text)).message;case"scroll":return(await t.scroll({down:r.down,numPages:r.num_pages,pixels:r.pixels,index:r.index})).message;case"scroll_horizontally":return(await t.scrollHorizontally({right:r.right,pixels:r.pixels,index:r.index})).message;case"wait":{const s=r.seconds||1;return await new Promise(a=>setTimeout(a,s*1e3)),`Waited ${s} seconds`}case"done":return"Task completed";default:return`Unknown action: ${o}`}}catch(s){return`Action failed: ${s instanceof Error?s.message:String(s)}`}}async cleanup(){if(this.pageController){try{await this.pageController.hideMask(),await this.pageController.cleanUpHighlights(),this.pageController.dispose()}catch(t){console.warn("[CrowBrowserUse] Cleanup error:",t)}this.pageController=null}if(this.sessionId){try{await fetch(`${this.config.apiUrl}/api/browser-use/end`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:this.sessionId,product_id:this.config.productId})})}catch{}this.sessionId=null}}async stop(){await this.cleanup()}}exports.CrowBrowserUse=u;exports.setPageController=p;
@@ -1,205 +0,0 @@
1
- let c = null, l = null;
2
- function w(i) {
3
- c = i;
4
- }
5
- async function p() {
6
- if (c)
7
- return c;
8
- if (!l)
9
- try {
10
- l = await import("./PageController-KoeqDxMP.js");
11
- } catch {
12
- throw new Error(
13
- 'PageController not available. Either import from "@usecrow/client/browser" or use the bundled version.'
14
- );
15
- }
16
- return l.PageController;
17
- }
18
- class u {
19
- constructor(t) {
20
- this.pageController = null, this.sessionId = null, this.maxSteps = 20, this.config = t;
21
- }
22
- /**
23
- * Initialize PageController with non-blocking pointer
24
- */
25
- async initPageController() {
26
- if (this.pageController)
27
- return this.pageController;
28
- try {
29
- const t = await p();
30
- this.pageController = new t({
31
- enableMask: !0,
32
- viewportExpansion: 500,
33
- highlightLabelOpacity: 0,
34
- // Hide numbered labels from users
35
- highlightOpacity: 0
36
- // Hide highlight boxes from users
37
- }), await this.pageController.showMask();
38
- const e = this.pageController.mask;
39
- return e != null && e.wrapper && (e.wrapper.style.pointerEvents = "none"), console.log("[CrowBrowserUse] PageController initialized with non-blocking pointer"), this.pageController;
40
- } catch (t) {
41
- throw console.error("[CrowBrowserUse] Failed to initialize PageController:", t), new Error(
42
- "Failed to initialize browser automation. Please import from @usecrow/client/browser."
43
- );
44
- }
45
- }
46
- /**
47
- * Execute a browser automation task
48
- */
49
- async execute(t) {
50
- console.log("[CrowBrowserUse] Starting task:", t);
51
- try {
52
- const e = await this.initPageController(), o = await this.startSession(t);
53
- this.sessionId = o.session_id, this.maxSteps = o.max_steps, console.log("[CrowBrowserUse] Session started:", this.sessionId);
54
- let r = 0, s;
55
- for (; r < this.maxSteps; ) {
56
- r++;
57
- const a = await e.getBrowserState(), n = await this.processStep(a, s);
58
- if (n.done)
59
- return console.log("[CrowBrowserUse] Task completed:", n.message), await this.cleanup(), {
60
- status: n.success ? "success" : "error",
61
- data: {
62
- message: n.message,
63
- steps: r
64
- },
65
- error: n.success ? void 0 : n.message
66
- };
67
- if (n.error)
68
- return console.error("[CrowBrowserUse] Error:", n.error), await this.cleanup(), {
69
- status: "error",
70
- error: n.error
71
- };
72
- n.action && (s = await this.executeAction(e, n.action), console.log(`[CrowBrowserUse] Step ${r}:`, s)), n.reflection && console.log("[CrowBrowserUse] Reflection:", n.reflection.next_goal);
73
- }
74
- return await this.cleanup(), {
75
- status: "error",
76
- error: `Task incomplete after ${this.maxSteps} steps`
77
- };
78
- } catch (e) {
79
- return console.error("[CrowBrowserUse] Error:", e), await this.cleanup(), {
80
- status: "error",
81
- error: e instanceof Error ? e.message : String(e)
82
- };
83
- }
84
- }
85
- /**
86
- * Start a browser-use session on the server
87
- */
88
- async startSession(t) {
89
- const e = await fetch(`${this.config.apiUrl}/api/browser-use/start`, {
90
- method: "POST",
91
- headers: { "Content-Type": "application/json" },
92
- body: JSON.stringify({
93
- product_id: this.config.productId,
94
- task: t
95
- })
96
- });
97
- if (!e.ok) {
98
- const o = await e.json().catch(() => ({ detail: "Unknown error" }));
99
- throw new Error(o.detail || `Failed to start session: ${e.status}`);
100
- }
101
- return e.json();
102
- }
103
- /**
104
- * Process a step on the server
105
- */
106
- async processStep(t, e) {
107
- const o = await fetch(`${this.config.apiUrl}/api/browser-use/step`, {
108
- method: "POST",
109
- headers: { "Content-Type": "application/json" },
110
- body: JSON.stringify({
111
- session_id: this.sessionId,
112
- product_id: this.config.productId,
113
- browser_state: t,
114
- action_result: e
115
- })
116
- });
117
- if (!o.ok) {
118
- const r = await o.json().catch(() => ({ detail: "Unknown error" }));
119
- throw new Error(r.detail || `Failed to process step: ${o.status}`);
120
- }
121
- return o.json();
122
- }
123
- /**
124
- * Execute an action using PageController
125
- */
126
- async executeAction(t, e) {
127
- const o = Object.keys(e)[0], r = e[o];
128
- try {
129
- switch (o) {
130
- case "click_element_by_index":
131
- return (await t.clickElement(r.index)).message;
132
- case "input_text":
133
- return (await t.inputText(
134
- r.index,
135
- r.text
136
- )).message;
137
- case "select_dropdown_option":
138
- return (await t.selectOption(
139
- r.index,
140
- r.text
141
- )).message;
142
- case "scroll":
143
- return (await t.scroll({
144
- down: r.down,
145
- numPages: r.num_pages,
146
- pixels: r.pixels,
147
- index: r.index
148
- })).message;
149
- case "scroll_horizontally":
150
- return (await t.scrollHorizontally({
151
- right: r.right,
152
- pixels: r.pixels,
153
- index: r.index
154
- })).message;
155
- case "wait": {
156
- const s = r.seconds || 1;
157
- return await new Promise((a) => setTimeout(a, s * 1e3)), `Waited ${s} seconds`;
158
- }
159
- case "done":
160
- return "Task completed";
161
- default:
162
- return `Unknown action: ${o}`;
163
- }
164
- } catch (s) {
165
- return `Action failed: ${s instanceof Error ? s.message : String(s)}`;
166
- }
167
- }
168
- /**
169
- * Cleanup resources
170
- */
171
- async cleanup() {
172
- if (this.pageController) {
173
- try {
174
- await this.pageController.hideMask(), await this.pageController.cleanUpHighlights(), this.pageController.dispose();
175
- } catch (t) {
176
- console.warn("[CrowBrowserUse] Cleanup error:", t);
177
- }
178
- this.pageController = null;
179
- }
180
- if (this.sessionId) {
181
- try {
182
- await fetch(`${this.config.apiUrl}/api/browser-use/end`, {
183
- method: "POST",
184
- headers: { "Content-Type": "application/json" },
185
- body: JSON.stringify({
186
- session_id: this.sessionId,
187
- product_id: this.config.productId
188
- })
189
- });
190
- } catch {
191
- }
192
- this.sessionId = null;
193
- }
194
- }
195
- /**
196
- * Stop the current task
197
- */
198
- async stop() {
199
- await this.cleanup();
200
- }
201
- }
202
- export {
203
- u as C,
204
- w as s
205
- };