@mindstudio-ai/browser-agent 0.1.48 → 0.1.50
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/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74,7 +74,7 @@ ${h}
|
|
|
74
74
|
white-space: nowrap;
|
|
75
75
|
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
|
|
76
76
|
">${co}</div>
|
|
77
|
-
`;function so(e,t,n){return e+(t-e)*n}function mo(){window.location.search.includes("mode=iframe")&&po()}function po(){if(document.getElementById(io))return;let e=E().cursor,t=E().zoom.mobilePreview,n=document.createElement("div");n.id=io,n.innerHTML=t?fo:uo,n.style.cssText=["position: fixed","top: -100px","left: -100px","z-index: 2147483647","pointer-events: none","will-change: left, top, transform, opacity","opacity: 0"].join("; ");let r=document.createElement("div");r.id=Rs,r.style.cssText=["position: fixed","z-index: 2147483646","pointer-events: none","width: 0","height: 0","border-radius: 50%",`background: ${Fe}`,"opacity: 0","transform: translate(-50%, -50%)","transition: width 400ms ease-out, height 400ms ease-out, opacity 400ms ease-out"].join("; "),document.documentElement.appendChild(r),document.documentElement.appendChild(n),e.el=n,e.rippleEl=r}function Ds(){E().cursor.trackingFrame===null&&go()}function ho(){let e=E().cursor;e.trackingFrame!==null&&(cancelAnimationFrame(e.trackingFrame),e.trackingFrame=null),e.targetElement=null}function go(){let e=E().cursor;if(e.el){if(e.targetElement&&e.targetElement.isConnected){let t=e.targetElement.getBoundingClientRect(),n=t.left+t.width/2,r=t.top+t.height/2,i=window.innerWidth,o=window.innerHeight,a=Math.max(gt,Math.min(n,i-gt)),s=Math.max(gt,Math.min(r,o-gt));if(e.x=so(e.x,a,ao),e.y=so(e.y,s,ao),e.el.style.transition="none",e.el.style.left=`${e.x}px`,e.el.style.top=`${e.y}px`,Math.abs(e.x-a)<lo&&Math.abs(e.y-s)<lo&&(e.x=a,e.y=s,e.el.style.left=`${e.x}px`,e.el.style.top=`${e.y}px`,e.settledResolve)){let c=e.settledResolve;e.settledResolve=null,c()}}else if(e.targetElement&&!e.targetElement.isConnected){if(e.settledResolve){let t=e.settledResolve;e.settledResolve=null,t()}e.targetElement=null,e.trackingFrame=null;return}else if(!e.targetElement){e.trackingFrame=null;return}e.trackingFrame=requestAnimationFrame(go)}}async function wt(e){let t=E().cursor;if(t.el)
|
|
77
|
+
`;function so(e,t,n){return e+(t-e)*n}function mo(){window.location.search.includes("mode=iframe")&&po()}function po(){if(document.getElementById(io))return;let e=E().cursor,t=E().zoom.mobilePreview,n=document.createElement("div");n.id=io,n.innerHTML=t?fo:uo,n.style.cssText=["position: fixed","top: -100px","left: -100px","z-index: 2147483647","pointer-events: none","will-change: left, top, transform, opacity","opacity: 0"].join("; ");let r=document.createElement("div");r.id=Rs,r.style.cssText=["position: fixed","z-index: 2147483646","pointer-events: none","width: 0","height: 0","border-radius: 50%",`background: ${Fe}`,"opacity: 0","transform: translate(-50%, -50%)","transition: width 400ms ease-out, height 400ms ease-out, opacity 400ms ease-out"].join("; "),document.documentElement.appendChild(r),document.documentElement.appendChild(n),e.el=n,e.rippleEl=r}function Ds(){E().cursor.trackingFrame===null&&go()}function ho(){let e=E().cursor;e.trackingFrame!==null&&(cancelAnimationFrame(e.trackingFrame),e.trackingFrame=null),e.targetElement=null}function go(){let e=E().cursor;if(e.el){if(e.targetElement&&e.targetElement.isConnected){let t=e.targetElement.getBoundingClientRect(),n=t.left+t.width/2,r=t.top+t.height/2,i=window.innerWidth,o=window.innerHeight,a=Math.max(gt,Math.min(n,i-gt)),s=Math.max(gt,Math.min(r,o-gt));if(e.x=so(e.x,a,ao),e.y=so(e.y,s,ao),e.el.style.transition="none",e.el.style.left=`${e.x}px`,e.el.style.top=`${e.y}px`,Math.abs(e.x-a)<lo&&Math.abs(e.y-s)<lo&&(e.x=a,e.y=s,e.el.style.left=`${e.x}px`,e.el.style.top=`${e.y}px`,e.settledResolve)){let c=e.settledResolve;e.settledResolve=null,c()}}else if(e.targetElement&&!e.targetElement.isConnected){if(e.settledResolve){let t=e.settledResolve;e.settledResolve=null,t()}e.targetElement=null,e.trackingFrame=null;return}else if(!e.targetElement){e.trackingFrame=null;return}e.trackingFrame=requestAnimationFrame(go)}}async function wt(e){let t=E().cursor;if(!t.el)return;if(t.hideTimer&&(clearTimeout(t.hideTimer),t.hideTimer=null),t.settledResolve){let r=t.settledResolve;t.settledResolve=null,r()}t.targetElement=e;let n=!1;if(!t.hasPosition){let r=e.getBoundingClientRect(),i=r.left+r.width/2,o=r.top+r.height/2,a=Math.max(window.innerWidth,100),s=Math.max(window.innerHeight,100);Math.random()<.5?(t.x=a+20,t.y=o+(Math.random()-.5)*100):(t.x=i+(Math.random()-.5)*100,t.y=s+20),t.el.style.transition="none",t.el.style.left=`${t.x}px`,t.el.style.top=`${t.y}px`,t.el.style.opacity="0",t.el.offsetWidth,t.hasPosition=!0,n=!0}return t.visibilityState==="fading-out"?be("visible"):(n||!wo(t.visibilityState))&&(be("fading-in"),await H(yt),t.visibilityState==="fading-in"&&(t.visibilityState="visible")),Ds(),new Promise(r=>{t.settledResolve=r})}async function yo(){let e=E().cursor;e.el&&(e.el.style.transform="scale(0.85) translateY(1px)",e.rippleEl&&(e.rippleEl.style.transition="none",e.rippleEl.style.left=`${e.x}px`,e.rippleEl.style.top=`${e.y}px`,e.rippleEl.style.width="0",e.rippleEl.style.height="0",e.rippleEl.style.opacity="0.35",e.rippleEl.offsetWidth,e.rippleEl.style.transition="width 400ms ease-out, height 400ms ease-out, opacity 400ms ease-out",e.rippleEl.style.width="40px",e.rippleEl.style.height="40px",e.rippleEl.style.opacity="0"),await H(Ps),e.el&&(e.el.style.transform="scale(1) translateY(0)"),await H(100))}function wo(e){return e==="visible"||e==="fading-in"||e==="fading-out"||e==="force-visible"}function be(e){let t=E().cursor;if(t.visibilityState=e,!!t.el)switch(e){case"hidden":case"force-hidden":case"snapshot-hidden":t.el.style.transition="none",t.el.style.opacity="0",t.rippleEl&&(t.rippleEl.style.opacity="0");break;case"fading-in":t.el.style.transition=`opacity ${yt}ms ease`,t.el.offsetWidth,t.el.style.opacity="1";break;case"visible":case"force-visible":t.el.style.opacity="1";break;case"fading-out":t.el.style.transition=`opacity ${yt}ms ease`,t.el.style.opacity="0";break}}function ze(){let e=E().cursor;e.hideTimer&&(clearTimeout(e.hideTimer),e.hideTimer=null)}function Xe(e){E().cursor.executing=e,e?no():ro()}function cn(){ze()}function bt(){let e=E().cursor;e.el&&e.visibilityState!=="force-visible"&&(e.targetElement=null,ze(),e.hideTimer=setTimeout(()=>{e.visibilityState!=="force-visible"&&(be("fading-out"),e.hideTimer=setTimeout(()=>{e.visibilityState==="fading-out"&&(be("hidden"),ho()),e.hideTimer=null},yt))},Fs))}function bo(){let e=E().cursor;e.visibilityState!=="snapshot-hidden"&&(ze(),e.preSnapshotState=e.visibilityState,be("snapshot-hidden"))}function vo(){let e=E().cursor,t=e.preSnapshotState;e.preSnapshotState=null,!(!e.el||!t||!wo(t))&&be(t==="fading-in"?"fading-in":"visible")}function un(e){let t=E().cursor;t.el&&(t.el.innerHTML=e?fo:uo)}function vt(e){let t=E().cursor;t.executing||(e==="visible"&&!t.el&&po(),t.el&&(e==="visible"?(ze(),t.hasPosition?be("force-visible"):t.visibilityState="force-visible"):e==="hidden"?(ze(),be("force-hidden"),ho()):bt()))}var Os=750,Hs=400,Me=2,Eo=["#__mindstudio-cursor","#__mindstudio-cursor-ripple","#__mindstudio-notes-cursor","#__mindstudio-camera","#__mindstudio-flash","#__mindstudio-touch-circle"],Bs="#DD2590",Ws=`<svg width="44" height="44" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
78
78
|
<g filter="url(#filter0_d_2_302)">
|
|
79
79
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.5 21C4.57 21 3 19.43 3 17.5V10.5C3 8.57 4.57 7 6.5 7H7.5C7.966 7 8.387 6.49 8.605 6.053C9.239 4.786 10.028 4 12 4H16C17.972 4 18.761 4.786 19.395 6.053C19.613 6.49 20.034 7 20.5 7H21.5C23.43 7 25 8.57 25 10.5V17.5C25 19.43 23.43 21 21.5 21H6.5Z" fill="white"/>
|
|
80
80
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M14 18C11.238 18 9 15.762 9 13C9 10.238 11.238 8 14 8C16.762 8 19 10.238 19 13C19 15.762 16.762 18 14 18ZM21.5 8H20.5C19.5 8 18.816 7.132 18.5 6.5C18 5.5 17.5 5 16 5H14H12C10.5 5 10 5.5 9.5 6.5C9.184 7.132 8.5 8 7.5 8H6.5C5.119 8 4 9.119 4 10.5V17.5C4 18.881 5.119 20 6.5 20H21.5C22.881 20 24 18.881 24 17.5V10.5C24 9.119 22.881 8 21.5 8Z" fill="black"/>
|
|
@@ -108,7 +108,7 @@ ${h}
|
|
|
108
108
|
white-space: nowrap;
|
|
109
109
|
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
|
|
110
110
|
">Remy</div>
|
|
111
|
-
`,t.style.cssText=["position: fixed","z-index: 2147483647","pointer-events: none","opacity: 0","transition: opacity 300ms ease, left 600ms cubic-bezier(0.4, 0, 0, 1), top 600ms cubic-bezier(0.4, 0, 0, 1)","will-change: left, top, opacity"].join("; ");let n=document.createElement("div");n.id=fn,n.style.cssText=["position: fixed","top: 0","left: 0","width: 100vw","height: 100vh","background: white","opacity: 0","z-index: 2147483646","pointer-events: none","transition: opacity 600ms ease-out"].join("; "),document.documentElement.appendChild(n),document.documentElement.appendChild(t),e.cameraEl=t,e.flashEl=n}function qs(e,t){let{cameraEl:n}=E().screenshot;n&&(n.style.left=`${e}px`,n.style.top=`${t}px`,n.style.opacity="1")}function So(e,t){let{cameraEl:n}=E().screenshot;n&&(n.style.left=`${e}px`,n.style.top=`${t}px`)}async function js(){let{flashEl:e}=E().screenshot;e&&(e.style.transition="none",e.style.opacity="0.7",e.offsetWidth,e.style.transition="opacity 600ms ease-out",e.style.opacity="0",await H(600))}function Ys(){let{cameraEl:e}=E().screenshot;e&&(e.style.opacity="0")}function Vs(){let e=E().screenshot;document.getElementById(dn)?.remove(),document.getElementById(fn)?.remove(),e.cameraEl=null,e.flashEl=null}function zs(e,t,n){return new Promise(r=>{let i=e.scrollTop,o=t-i;if(Math.abs(o)<1){r();return}let a=Math.abs(o),c=Math.max(n,a/2),l=performance.now();function u(d){let f=d-l,m=Math.min(f/c,1),g=m<.5?4*m*m*m:1-Math.pow(-2*m+2,3)/2;e.scrollTop=i+o*g,m<1?requestAnimationFrame(u):r()}requestAnimationFrame(u)})}async function Ge(e){let t=E().screenshot;if(t.capturing)throw new Error("Screenshot already in progress");t.capturing=!0,bo();try{return await Xs(e)}finally{t.capturing=!1,vo()}}async function Xs(e){await zr();let t=window.innerWidth,n=window.innerHeight;if(e?.viewportOnly)return await Ks(t,n);let r=Se(),i=r!==document.documentElement,o=r.scrollTop,a=r.style.scrollBehavior;r.style.scrollBehavior="auto",Us();try{let s=Math.random()<.5?t+30:-60,c=n*.3+Math.random()*n*.4;qs(s,c),await H(200);let l=t*.4+Math.random()*t*.15,u=n*.35+Math.random()*n*.15;So(l,u),await H(700);let d=[],f=0,m=i?r.clientHeight:n,g=()=>i?r.scrollHeight:Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),h=50,p=g();for(;f<p&&d.length<h;){let k=d.length,N=g();if(N<=0){console.warn("[screenshot] skipping chunk \u2014 page height is 0");break}if(N-f<m*.05&&d.length>0)break;let D=N-m,L=Math.min(f,D);Math.abs(L-r.scrollTop)>1&&(await zs(r,L,Hs),So(l,u),await H(Os)),js();let O=r.scrollTop,U=Math.min(m,N-O);if(U<=0){console.warn("[screenshot] skipping chunk \u2014 captureHeight is 0 (page may have shrunk)"),f+=m;continue}let G=i?r.getBoundingClientRect():null;try{let _=await(await I(document.body,{embedFonts:!0,exclude:Eo})).toCanvas({width:t+1});if(_&&G){let P=_.width/t,R=_.width;if(k===0&&G.top>0){let J=Math.round(G.top*P),Z=document.createElement("canvas");Z.width=R,Z.height=J;let le=Z.getContext("2d");le&&(le.drawImage(_,0,0,R,J,0,0,R,J),d.push({y:0,canvas:Z}))}let K=Math.round(G.top*P),W=Math.round(U*P),q=document.createElement("canvas");q.width=R,q.height=W;let j=q.getContext("2d");j&&(j.drawImage(_,0,K,R,W,0,0,R,W),d.push({y:G.top+O,canvas:q}));let V=G.bottom;if(f+m>=p&&V<n){let J=Math.round(V*P),Z=_.height-J;if(Z>0){let le=document.createElement("canvas");le.width=R,le.height=Z;let Ze=le.getContext("2d");Ze&&(Ze.drawImage(_,0,J,R,Z,0,0,R,Z),d.push({y:G.top+N,canvas:le}))}}}else if(_){let P=_.width/t,R=Math.round(O*P),K=Math.min(O+U,N),W=Math.round(K*P)-R,q=_.width,j=document.createElement("canvas");j.width=q,j.height=W;let V=j.getContext("2d");V&&(V.drawImage(_,0,R,q,W,0,0,q,W),d.push({y:O,canvas:j}))}}catch(T){console.error("[screenshot] snapdom capture failed for chunk",k,T)}f+=m}if(f<p&&console.warn(`[screenshot] page truncated \u2014 captured ${d.length} chunks but page is ${p}px tall`),d.length===0)throw new Error("Screenshot capture produced no image data");let y=d[0].canvas.width,x=0;for(let k of d)x+=k.canvas.height;let b=document.createElement("canvas");b.width=y,b.height=x;let w=b.getContext("2d");if(!w)throw new Error("Failed to create output canvas");let S=0;for(let k of d)w.drawImage(k.canvas,0,S),S+=k.canvas.height;let v=b.toDataURL("image/jpeg",1).replace(/^data:image\/jpeg;base64,/,"");if(!v)throw new Error("Canvas export produced no image data");return{image:v,width:b.width,height:b.height}}finally{Ys(),Vs(),r.style.scrollBehavior="auto",r.scrollTop=o,r.style.scrollBehavior=a}}function Gs(){let e=document.getElementById("__mindstudio-notes-overlay");if(!e)return null;let t=window.scrollX,n=window.scrollY,r=e.style.cssText;return e.style.position="absolute",e.style.inset="auto",e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.width=`${window.innerWidth}px`,e.style.height=`${window.innerHeight}px`,()=>{e.style.cssText=r}}async function Ks(e,t){let n=Gs();try{let i=await(await I(document.body,{embedFonts:!0,exclude:Eo})).toCanvas({width:(e+1)*Me});if(!i)throw new Error("SnapDOM viewport capture returned empty result");let o=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),a=document.createElement("canvas");a.width=e*Me,a.height=t*Me;let s=a.getContext("2d");if(!s)throw new Error("Failed to create canvas context");let c=window.scrollY/o*i.height,l=t/o*i.height;s.drawImage(i,0,c,i.width,l,0,0,e*Me,t*Me);let d=a.toDataURL("image/jpeg",1).replace(/^data:image\/jpeg;base64,/,"");if(!d)throw new Error("Canvas export produced no image data");return{image:d,width:e*Me,height:t*Me}}finally{n?.()}}var Js=["backgroundColor","color","fontFamily","fontSize","fontWeight","fontStyle","lineHeight","letterSpacing","textAlign","textDecoration","textTransform","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","borderRadius","borderColor","borderWidth","borderStyle","boxShadow","opacity","width","height","display","flexDirection","justifyContent","alignItems","gap"];function Zs(e,t){let n=t??Js;if(e.ref||e.text||e.role||e.label||e.selector){let{element:o,matched:a}=fe(e);return{...Co(o,e.ref,n),matched:a}}let r=$e(),i=[];for(let[o,a]of r)a.isConnected&&i.push(Co(a,o,n));return i}function Co(e,t,n){let r=window.getComputedStyle(e),i={};t&&(i.ref=t),i.tag=e.tagName.toLowerCase();let o=e.textContent?.trim();o&&(i.text=o.length>60?o.slice(0,60)+"\u2026":o);for(let a of n){let s=r.getPropertyValue(a.replace(/([A-Z])/g,"-$1").toLowerCase());s&&(i[a]=s)}return i}var Mo=150,xt=100,Ke="__mindstudio_pending_nav",ko=300,hn=1e4;function Qs(e){try{let t=new URL(e,window.location.origin);return t.origin!==window.location.origin?!1:t.pathname===window.location.pathname&&t.search===window.location.search&&t.hash===window.location.hash}catch{return!1}}function Ao(e){try{let t=new URL(e,window.location.origin);return t.origin!==window.location.origin?!1:(Qs(e)||(window.history.pushState(null,"",t.pathname+t.search+t.hash),window.dispatchEvent(new PopStateEvent("popstate"))),!0)}catch{return!1}}async function mn(e=300,t=2e3){return new Promise(n=>{let r=Date.now()+t,i=Date.now(),o=Se(),a=window.scrollY,s=window.scrollX,c=document.body.scrollTop,l=document.documentElement.scrollTop,u=document.body.scrollHeight,d=document.body.scrollWidth,f=o.scrollTop,m=o.scrollLeft;function g(){if(Date.now()>r){n();return}let h=window.scrollY,p=window.scrollX,y=document.body.scrollTop,x=document.documentElement.scrollTop,b=document.body.scrollHeight,w=document.body.scrollWidth,S=o.scrollTop,C=o.scrollLeft;(h!==a||p!==s||y!==c||x!==l||b!==u||w!==d||S!==f||C!==m)&&(a=h,s=p,c=y,l=x,u=b,d=w,f=S,m=C,i=Date.now()),Date.now()-i>=e?n():requestAnimationFrame(g)}requestAnimationFrame(g)})}var ec=350;async function pn(e){let t=tc(e),n=t.map(a=>({el:a,top:a.scrollTop,left:a.scrollLeft})),r=document.documentElement.style.scrollBehavior;document.documentElement.style.scrollBehavior="auto",e.scrollIntoView({block:"center",inline:"nearest",behavior:"instant"}),document.documentElement.style.scrollBehavior=r;let i=t.map(a=>({top:a.scrollTop,left:a.scrollLeft})),o=[];for(let a=0;a<t.length;a++)(n[a].top!==i[a].top||n[a].left!==i[a].left)&&o.push({el:t[a],fromTop:n[a].top,fromLeft:n[a].left,toTop:i[a].top,toLeft:i[a].left});if(o.length===0){await new Promise(a=>requestAnimationFrame(()=>a()));return}for(let a of o)a.el.scrollTop=a.fromTop,a.el.scrollLeft=a.fromLeft;await new Promise(a=>{let s=performance.now();function c(l){let u=l-s,d=Math.min(u/ec,1),f=1-Math.pow(1-d,3);for(let m of o)m.el.scrollTop=m.fromTop+(m.toTop-m.fromTop)*f,m.el.scrollLeft=m.fromLeft+(m.toLeft-m.fromLeft)*f;d<1?requestAnimationFrame(c):a()}requestAnimationFrame(c)})}function tc(e){let t=[],n=e.parentElement;for(;n;){let r=getComputedStyle(n),i=r.overflowY,o=r.overflowX;(i==="auto"||i==="scroll"||o==="auto"||o==="scroll")&&t.push(n),n=n.parentElement}return t.push(document.scrollingElement||document.documentElement),t}async function St(e,t){let n=Date.now(),r=[],i=[],o="",a=!1,s=new Set(["click","type","select"]),c=t.some(l=>s.has(l.command));c&&(Xe(!0),cn()),Nt();try{for(let l=0;l<t.length;l++){let u=t[l],d=u.command;try{if(l>0&&await H(Mo+Math.random()*xt-xt/2),d==="navigate"){let m=u.url;if(!m)throw new Error('navigate command requires a "url" field');if(Ao(m)){r.push({index:l,command:d,result:"ok"}),await H(ko);continue}let g=t.slice(l+1);if(g.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e,startTime:n,completedSteps:r,remainingSteps:g,stepOffset:l+1}))}catch{}r.push({index:l,command:d,result:"ok"}),a=!0,window.location.href=m,await new Promise((h,p)=>{setTimeout(()=>p(new Error("Navigation did not complete within timeout")),hn)})}if(d==="reload"){let m=t.slice(l+1);if(m.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e,startTime:n,completedSteps:r,remainingSteps:m,stepOffset:l+1}))}catch{}r.push({index:l,command:d,result:"ok"}),a=!0,window.location.reload(),await new Promise((g,h)=>{setTimeout(()=>h(new Error("Reload did not complete within timeout")),hn)})}let f=await Lo(u);r.push({index:l,command:d,...f})}catch(f){r.push({index:l,command:d,error:f instanceof Error?f.message:String(f)});break}}try{o=await Le()}catch{}}finally{i=_t(),c&&(Xe(!1),bt())}return{id:e,steps:r,snapshot:o,logs:i,duration:Date.now()-n}}async function $o(){let e=null;try{let o=sessionStorage.getItem(Ke);if(!o)return null;sessionStorage.removeItem(Ke),e=JSON.parse(o)}catch{return null}if(!e)return null;let t=[...e.completedSteps],n=[],r="",i=e.remainingSteps.some(o=>o.command==="click"||o.command==="type"||o.command==="select");i&&(Xe(!0),cn()),Nt();try{for(let o=0;o<e.remainingSteps.length;o++){let a=e.remainingSteps[o],s=a.command,c=e.stepOffset+o;try{if(o>0&&await H(Mo+Math.random()*xt-xt/2),s==="navigate"){let u=a.url;if(!u)throw new Error('navigate command requires a "url" field');if(Ao(u)){t.push({index:c,command:s,result:"ok"}),await H(ko);continue}let d=e.remainingSteps.slice(o+1);if(d.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e.id,startTime:e.startTime,completedSteps:t,remainingSteps:d,stepOffset:c+1}))}catch{}t.push({index:c,command:s,result:"ok"}),window.location.href=u,await new Promise((f,m)=>{setTimeout(()=>m(new Error("Navigation did not complete within timeout")),hn)})}let l=await Lo(a);t.push({index:c,command:s,...l})}catch(l){t.push({index:c,command:s,error:l instanceof Error?l.message:String(l)});break}}try{r=await Le()}catch{}}finally{n=_t(),i&&(Xe(!1),bt())}return{id:e.id,steps:t,snapshot:r,logs:n,duration:Date.now()-e.startTime}}async function Lo(e){switch(e.command){case"snapshot":return{result:await Le()};case"click":{let{element:t,matched:n}=fe(e);return await pn(t),await wt(t),await yo(),Dt(t),await mn(),await H(1e3),{result:"ok",matched:n}}case"type":{let{element:t,matched:n}=fe(e),r=e.text;if(!r&&r!=="")throw new Error('type command requires a "text" field');return await pn(t),await wt(t),await Hn(t,r,{clear:!!e.clear}),await mn(),{result:"ok",matched:n}}case"select":{let{element:t,matched:n}=fe(e),r=e.option;if(!r)throw new Error('select command requires an "option" field');await pn(t),await wt(t);let i=Wn(t,r);return await mn(),{result:`selected "${i}"`,matched:n}}case"wait":{let{matched:t,elapsed:n}=await Bn(e);return{result:"ok",matched:t,elapsed:n}}case"styles":{let t=e.properties;return{result:Zs(e,t)}}case"evaluate":{let t=e.script;if(!t)throw new Error('evaluate command requires a "script" field');return{result:await Un(t)}}case"screenshotFullPage":{let t=Se();t.scrollTop=0,await H(500);let{image:n,width:r,height:i}=await Ge(),o=e.uploadUrl,a=e.uploadFields;if(o&&a){let s=atob(n),c=new Uint8Array(s.length);for(let f=0;f<s.length;f++)c[f]=s.charCodeAt(f);let l=new FormData;for(let[f,m]of Object.entries(a))l.append(f,m);l.append("file",new Blob([c],{type:"image/jpeg"}),"screenshot.jpg");let u=await fetch(o,{method:"POST",body:l});if(!u.ok)throw new Error(`Screenshot upload failed: ${u.status}`);let d=e._publicUrl;return{result:{width:r,height:i,uploaded:!0,...d?{_publicUrl:d}:{}}}}return{result:{image:n,width:r,height:i}}}case"screenshotViewport":{let{image:t,width:n,height:r}=await Ge({viewportOnly:!0}),i=e.uploadUrl,o=e.uploadFields;if(i&&o){let a=atob(t),s=new Uint8Array(a.length);for(let d=0;d<a.length;d++)s[d]=a.charCodeAt(d);let c=new FormData;for(let[d,f]of Object.entries(o))c.append(d,f);c.append("file",new Blob([s],{type:"image/jpeg"}),"screenshot.jpg");let l=await fetch(i,{method:"POST",body:c});if(!l.ok)throw new Error(`Screenshot upload failed: ${l.status}`);let u=e._publicUrl;return{result:{width:n,height:r,uploaded:!0,...u?{_publicUrl:u}:{}}}}return{result:{image:t,width:n,height:r}}}case"reload":return location.reload(),{result:"ok"};default:throw new Error(`Unknown command: ${e.command}`)}}var nc="/__mindstudio_dev__/ws",rc=1e3,oc=1e4;function No(){let e=E().ws;e.ws||(Sn(_o),window.addEventListener("beforeunload",()=>{e.closing=!0,e.ws&&e.ws.close()}),Ro())}function _o(){let{ws:e}=E().ws;return e&&e.readyState===WebSocket.OPEN?e:null}function ic(){return`${location.protocol==="https:"?"wss:":"ws:"}//${location.host}${nc}`}function ac(){return window.location.search.includes("mode=iframe")?"iframe":"standalone"}function Ro(){let e=E().ws;if(!e.closing){try{e.ws=new WebSocket(ic())}catch{To();return}e.ws.onopen=()=>{try{e.ws.send(JSON.stringify({type:"hello",mode:ac(),url:location.href,viewport:{w:window.innerWidth,h:window.innerHeight}}))}catch{e.ws?.close()}},e.ws.onmessage=t=>{let n;try{n=JSON.parse(t.data)}catch{return}switch(n.type){case"ack":e.clientId=n.clientId,e.reconnectDelay=rc,sc();break;case"command":lc(n.id,n.steps);break;case"broadcast":cc(n.action,n.payload);break}},e.ws.onclose=()=>{e.ws=null,e.clientId=null,e.closing||To()},e.ws.onerror=()=>{}}}function To(){let e=E().ws;e.closing||(setTimeout(()=>Ro(),e.reconnectDelay),e.reconnectDelay=Math.min(e.reconnectDelay*2,oc))}async function lc(e,t){let n=E().ws;if(n.busy){Et({id:e,steps:[],snapshot:"",logs:[],duration:0,error:"Browser agent is busy"});return}n.busy=!0,gn("command-started",{id:e,steps:t.map(r=>r.command)});try{let r=await St(e,t);Et(r),gn("command-completed",{id:e,success:!0})}catch{Et({id:e,steps:[],snapshot:"",logs:[],duration:0}),gn("command-completed",{id:e,success:!1})}finally{E().ws.busy=!1}}function Et(e){try{let t=_o();t&&t.send(JSON.stringify({type:"result",...e}))}catch{}}async function sc(){let e=await $o();e&&Et(e)}function gn(e,t){window.parent!==window&&window.parent.postMessage({channel:"mindstudio-browser-agent",command:e,...t},"*")}function cc(e,t){e==="reload"&&location.reload()}var Po="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",uc=200,Fo=`
|
|
111
|
+
`,t.style.cssText=["position: fixed","z-index: 2147483647","pointer-events: none","opacity: 0","transition: opacity 300ms ease, left 600ms cubic-bezier(0.4, 0, 0, 1), top 600ms cubic-bezier(0.4, 0, 0, 1)","will-change: left, top, opacity"].join("; ");let n=document.createElement("div");n.id=fn,n.style.cssText=["position: fixed","top: 0","left: 0","width: 100vw","height: 100vh","background: white","opacity: 0","z-index: 2147483646","pointer-events: none","transition: opacity 600ms ease-out"].join("; "),document.documentElement.appendChild(n),document.documentElement.appendChild(t),e.cameraEl=t,e.flashEl=n}function qs(e,t){let{cameraEl:n}=E().screenshot;n&&(n.style.left=`${e}px`,n.style.top=`${t}px`,n.style.opacity="1")}function So(e,t){let{cameraEl:n}=E().screenshot;n&&(n.style.left=`${e}px`,n.style.top=`${t}px`)}async function js(){let{flashEl:e}=E().screenshot;e&&(e.style.transition="none",e.style.opacity="0.7",e.offsetWidth,e.style.transition="opacity 600ms ease-out",e.style.opacity="0",await H(600))}function Ys(){let{cameraEl:e}=E().screenshot;e&&(e.style.opacity="0")}function Vs(){let e=E().screenshot;document.getElementById(dn)?.remove(),document.getElementById(fn)?.remove(),e.cameraEl=null,e.flashEl=null}function zs(e,t,n){return new Promise(r=>{let i=e.scrollTop,o=t-i;if(Math.abs(o)<1){r();return}let a=Math.abs(o),c=Math.max(n,a/2),l=performance.now();function u(d){let f=d-l,m=Math.min(f/c,1),g=m<.5?4*m*m*m:1-Math.pow(-2*m+2,3)/2;e.scrollTop=i+o*g,m<1?requestAnimationFrame(u):r()}requestAnimationFrame(u)})}async function Ge(e){let t=E().screenshot;if(t.capturing)throw new Error("Screenshot already in progress");t.capturing=!0,bo();try{return await Xs(e)}finally{t.capturing=!1,vo()}}async function Xs(e){await zr();let t=window.innerWidth,n=window.innerHeight;if(e?.viewportOnly)return await Ks(t,n);let r=Se(),i=r!==document.documentElement,o=r.scrollTop,a=r.style.scrollBehavior;r.style.scrollBehavior="auto",Us();try{let s=Math.random()<.5?t+30:-60,c=n*.3+Math.random()*n*.4;qs(s,c),await H(200);let l=t*.4+Math.random()*t*.15,u=n*.35+Math.random()*n*.15;So(l,u),await H(700);let d=[],f=0,m=i?r.clientHeight:n,g=()=>i?r.scrollHeight:Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),h=50,p=g();for(;f<p&&d.length<h;){let k=d.length,N=g();if(N<=0){console.warn("[screenshot] skipping chunk \u2014 page height is 0");break}if(N-f<m*.05&&d.length>0)break;let D=N-m,L=Math.min(f,D);Math.abs(L-r.scrollTop)>1&&(await zs(r,L,Hs),So(l,u),await H(Os)),js();let O=r.scrollTop,U=Math.min(m,N-O);if(U<=0){console.warn("[screenshot] skipping chunk \u2014 captureHeight is 0 (page may have shrunk)"),f+=m;continue}let G=i?r.getBoundingClientRect():null;try{let _=await(await I(document.body,{embedFonts:!0,exclude:Eo})).toCanvas({width:t+1});if(_&&G){let P=_.width/t,R=_.width;if(k===0&&G.top>0){let J=Math.round(G.top*P),Z=document.createElement("canvas");Z.width=R,Z.height=J;let le=Z.getContext("2d");le&&(le.drawImage(_,0,0,R,J,0,0,R,J),d.push({y:0,canvas:Z}))}let K=Math.round(G.top*P),W=Math.round(U*P),q=document.createElement("canvas");q.width=R,q.height=W;let j=q.getContext("2d");j&&(j.drawImage(_,0,K,R,W,0,0,R,W),d.push({y:G.top+O,canvas:q}));let V=G.bottom;if(f+m>=p&&V<n){let J=Math.round(V*P),Z=_.height-J;if(Z>0){let le=document.createElement("canvas");le.width=R,le.height=Z;let Ze=le.getContext("2d");Ze&&(Ze.drawImage(_,0,J,R,Z,0,0,R,Z),d.push({y:G.top+N,canvas:le}))}}}else if(_){let P=_.width/t,R=Math.round(O*P),K=Math.min(O+U,N),W=Math.round(K*P)-R,q=_.width,j=document.createElement("canvas");j.width=q,j.height=W;let V=j.getContext("2d");V&&(V.drawImage(_,0,R,q,W,0,0,q,W),d.push({y:O,canvas:j}))}}catch(T){console.error("[screenshot] snapdom capture failed for chunk",k,T)}f+=m}if(f<p&&console.warn(`[screenshot] page truncated \u2014 captured ${d.length} chunks but page is ${p}px tall`),d.length===0)throw new Error("Screenshot capture produced no image data");let y=d[0].canvas.width,x=0;for(let k of d)x+=k.canvas.height;let b=document.createElement("canvas");b.width=y,b.height=x;let w=b.getContext("2d");if(!w)throw new Error("Failed to create output canvas");let S=0;for(let k of d)w.drawImage(k.canvas,0,S),S+=k.canvas.height;let v=b.toDataURL("image/jpeg",1).replace(/^data:image\/jpeg;base64,/,"");if(!v)throw new Error("Canvas export produced no image data");return{image:v,width:b.width,height:b.height}}finally{Ys(),Vs(),r.style.scrollBehavior="auto",r.scrollTop=o,r.style.scrollBehavior=a}}function Gs(){let e=document.getElementById("__mindstudio-notes-overlay");if(!e)return null;let t=window.scrollX,n=window.scrollY,r=e.style.cssText;return e.style.position="absolute",e.style.inset="auto",e.style.left=`${t}px`,e.style.top=`${n}px`,e.style.width=`${window.innerWidth}px`,e.style.height=`${window.innerHeight}px`,()=>{e.style.cssText=r}}async function Ks(e,t){let n=Gs();try{let i=await(await I(document.body,{embedFonts:!0,exclude:Eo})).toCanvas({width:(e+1)*Me});if(!i)throw new Error("SnapDOM viewport capture returned empty result");let o=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),a=document.createElement("canvas");a.width=e*Me,a.height=t*Me;let s=a.getContext("2d");if(!s)throw new Error("Failed to create canvas context");let c=window.scrollY/o*i.height,l=t/o*i.height;s.drawImage(i,0,c,i.width,l,0,0,e*Me,t*Me);let d=a.toDataURL("image/jpeg",1).replace(/^data:image\/jpeg;base64,/,"");if(!d)throw new Error("Canvas export produced no image data");return{image:d,width:e*Me,height:t*Me}}finally{n?.()}}var Js=["backgroundColor","color","fontFamily","fontSize","fontWeight","fontStyle","lineHeight","letterSpacing","textAlign","textDecoration","textTransform","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","borderRadius","borderColor","borderWidth","borderStyle","boxShadow","opacity","width","height","display","flexDirection","justifyContent","alignItems","gap"];function Zs(e,t){let n=t??Js;if(e.ref||e.text||e.role||e.label||e.selector){let{element:o,matched:a}=fe(e);return{...Co(o,e.ref,n),matched:a}}let r=$e(),i=[];for(let[o,a]of r)a.isConnected&&i.push(Co(a,o,n));return i}function Co(e,t,n){let r=window.getComputedStyle(e),i={};t&&(i.ref=t),i.tag=e.tagName.toLowerCase();let o=e.textContent?.trim();o&&(i.text=o.length>60?o.slice(0,60)+"\u2026":o);for(let a of n){let s=r.getPropertyValue(a.replace(/([A-Z])/g,"-$1").toLowerCase());s&&(i[a]=s)}return i}var Mo=150,xt=100,Ke="__mindstudio_pending_nav",ko=300,hn=1e4;function Qs(e){try{let t=new URL(e,window.location.origin);return t.origin!==window.location.origin?!1:t.pathname===window.location.pathname&&t.search===window.location.search&&t.hash===window.location.hash}catch{return!1}}function Ao(e){try{let t=new URL(e,window.location.origin);return t.origin!==window.location.origin?!1:(Qs(e)||(window.history.pushState(null,"",t.pathname+t.search+t.hash),window.dispatchEvent(new PopStateEvent("popstate"))),!0)}catch{return!1}}async function mn(e=300,t=2e3){return new Promise(n=>{let r=Date.now()+t,i=Date.now(),o=Se(),a=window.scrollY,s=window.scrollX,c=document.body.scrollTop,l=document.documentElement.scrollTop,u=document.body.scrollHeight,d=document.body.scrollWidth,f=o.scrollTop,m=o.scrollLeft;function g(){if(Date.now()>r){n();return}let h=window.scrollY,p=window.scrollX,y=document.body.scrollTop,x=document.documentElement.scrollTop,b=document.body.scrollHeight,w=document.body.scrollWidth,S=o.scrollTop,C=o.scrollLeft;(h!==a||p!==s||y!==c||x!==l||b!==u||w!==d||S!==f||C!==m)&&(a=h,s=p,c=y,l=x,u=b,d=w,f=S,m=C,i=Date.now()),Date.now()-i>=e?n():requestAnimationFrame(g)}requestAnimationFrame(g)})}var ec=350;async function pn(e){let t=tc(e),n=t.map(a=>({el:a,top:a.scrollTop,left:a.scrollLeft})),r=document.documentElement.style.scrollBehavior;document.documentElement.style.scrollBehavior="auto",e.scrollIntoView({block:"center",inline:"nearest",behavior:"instant"}),document.documentElement.style.scrollBehavior=r;let i=t.map(a=>({top:a.scrollTop,left:a.scrollLeft})),o=[];for(let a=0;a<t.length;a++)(n[a].top!==i[a].top||n[a].left!==i[a].left)&&o.push({el:t[a],fromTop:n[a].top,fromLeft:n[a].left,toTop:i[a].top,toLeft:i[a].left});if(o.length===0){await new Promise(a=>requestAnimationFrame(()=>a()));return}for(let a of o)a.el.scrollTop=a.fromTop,a.el.scrollLeft=a.fromLeft;await new Promise(a=>{let s=performance.now();function c(l){let u=l-s,d=Math.min(u/ec,1),f=1-Math.pow(1-d,3);for(let m of o)m.el.scrollTop=m.fromTop+(m.toTop-m.fromTop)*f,m.el.scrollLeft=m.fromLeft+(m.toLeft-m.fromLeft)*f;d<1?requestAnimationFrame(c):a()}requestAnimationFrame(c)})}function tc(e){let t=[],n=e.parentElement;for(;n;){let r=getComputedStyle(n),i=r.overflowY,o=r.overflowX;(i==="auto"||i==="scroll"||o==="auto"||o==="scroll")&&t.push(n),n=n.parentElement}return t.push(document.scrollingElement||document.documentElement),t}async function St(e,t){let n=Date.now(),r=[],i=[],o="",a=!1,s=new Set(["click","type","select"]),c=t.some(l=>s.has(l.command));c&&(Xe(!0),cn()),Nt();try{for(let l=0;l<t.length;l++){let u=t[l],d=u.command;try{if(l>0&&await H(Mo+Math.random()*xt-xt/2),d==="navigate"){let m=u.url;if(!m)throw new Error('navigate command requires a "url" field');if(Ao(m)){r.push({index:l,command:d,result:"ok"}),await H(ko);continue}let g=t.slice(l+1);if(g.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e,startTime:n,completedSteps:r,remainingSteps:g,stepOffset:l+1}))}catch{}r.push({index:l,command:d,result:"ok"}),a=!0,window.location.href=m,await new Promise((h,p)=>{setTimeout(()=>p(new Error("Navigation did not complete within timeout")),hn)})}if(d==="reload"){let m=t.slice(l+1);if(m.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e,startTime:n,completedSteps:r,remainingSteps:m,stepOffset:l+1}))}catch{}r.push({index:l,command:d,result:"ok"}),a=!0,window.location.reload(),await new Promise((g,h)=>{setTimeout(()=>h(new Error("Reload did not complete within timeout")),hn)})}let f=await Lo(u);r.push({index:l,command:d,...f})}catch(f){r.push({index:l,command:d,error:f instanceof Error?f.message:String(f)});break}}try{o=await Le()}catch{}}finally{i=_t(),c&&(Xe(!1),bt())}return{id:e,steps:r,snapshot:o,logs:i,duration:Date.now()-n}}async function $o(){let e=null;try{let o=sessionStorage.getItem(Ke);if(!o)return null;sessionStorage.removeItem(Ke),e=JSON.parse(o)}catch{return null}if(!e)return null;let t=[...e.completedSteps],n=[],r="",i=e.remainingSteps.some(o=>o.command==="click"||o.command==="type"||o.command==="select");i&&(Xe(!0),cn()),Nt();try{for(let o=0;o<e.remainingSteps.length;o++){let a=e.remainingSteps[o],s=a.command,c=e.stepOffset+o;try{if(o>0&&await H(Mo+Math.random()*xt-xt/2),s==="navigate"){let u=a.url;if(!u)throw new Error('navigate command requires a "url" field');if(Ao(u)){t.push({index:c,command:s,result:"ok"}),await H(ko);continue}let d=e.remainingSteps.slice(o+1);if(d.length>0)try{sessionStorage.setItem(Ke,JSON.stringify({id:e.id,startTime:e.startTime,completedSteps:t,remainingSteps:d,stepOffset:c+1}))}catch{}t.push({index:c,command:s,result:"ok"}),window.location.href=u,await new Promise((f,m)=>{setTimeout(()=>m(new Error("Navigation did not complete within timeout")),hn)})}let l=await Lo(a);t.push({index:c,command:s,...l})}catch(l){t.push({index:c,command:s,error:l instanceof Error?l.message:String(l)});break}}try{r=await Le()}catch{}}finally{n=_t(),i&&(Xe(!1),bt())}return{id:e.id,steps:t,snapshot:r,logs:n,duration:Date.now()-e.startTime}}async function Lo(e){switch(e.command){case"snapshot":return{result:await Le()};case"click":{let{element:t,matched:n}=fe(e);return await pn(t),await wt(t),await yo(),Dt(t),await mn(),await H(1e3),{result:"ok",matched:n}}case"type":{let{element:t,matched:n}=fe(e),r=e.text;if(!r&&r!=="")throw new Error('type command requires a "text" field');return await pn(t),await wt(t),await Hn(t,r,{clear:!!e.clear}),await mn(),{result:"ok",matched:n}}case"select":{let{element:t,matched:n}=fe(e),r=e.option;if(!r)throw new Error('select command requires an "option" field');await pn(t),await wt(t);let i=Wn(t,r);return await mn(),{result:`selected "${i}"`,matched:n}}case"wait":{let{matched:t,elapsed:n}=await Bn(e);return{result:"ok",matched:t,elapsed:n}}case"styles":{let t=e.properties;return{result:Zs(e,t)}}case"evaluate":{let t=e.script;if(!t)throw new Error('evaluate command requires a "script" field');return{result:await Un(t)}}case"screenshotFullPage":{let t=Se();t.scrollTop=0,await H(500);let{image:n,width:r,height:i}=await Ge(),o=e.uploadUrl,a=e.uploadFields;if(o&&a){let s=atob(n),c=new Uint8Array(s.length);for(let f=0;f<s.length;f++)c[f]=s.charCodeAt(f);let l=new FormData;for(let[f,m]of Object.entries(a))l.append(f,m);l.append("file",new Blob([c],{type:"image/jpeg"}),"screenshot.jpg");let u=await fetch(o,{method:"POST",body:l});if(!u.ok)throw new Error(`Screenshot upload failed: ${u.status}`);let d=e._publicUrl;return{result:{width:r,height:i,uploaded:!0,...d?{_publicUrl:d}:{}}}}return{result:{image:n,width:r,height:i}}}case"screenshotViewport":{let{image:t,width:n,height:r}=await Ge({viewportOnly:!0}),i=e.uploadUrl,o=e.uploadFields;if(i&&o){let a=atob(t),s=new Uint8Array(a.length);for(let d=0;d<a.length;d++)s[d]=a.charCodeAt(d);let c=new FormData;for(let[d,f]of Object.entries(o))c.append(d,f);c.append("file",new Blob([s],{type:"image/jpeg"}),"screenshot.jpg");let l=await fetch(i,{method:"POST",body:c});if(!l.ok)throw new Error(`Screenshot upload failed: ${l.status}`);let u=e._publicUrl;return{result:{width:n,height:r,uploaded:!0,...u?{_publicUrl:u}:{}}}}return{result:{image:t,width:n,height:r}}}case"reload":return location.reload(),{result:"ok"};default:throw new Error(`Unknown command: ${e.command}`)}}var nc="/__mindstudio_dev__/ws",rc=1e3,oc=1e4;function No(){let e=E().ws;e.ws||(Sn(_o),window.addEventListener("beforeunload",()=>{e.closing=!0,e.ws&&e.ws.close()}),Ro())}function _o(){let{ws:e}=E().ws;return e&&e.readyState===WebSocket.OPEN?e:null}function ic(){return`${location.protocol==="https:"?"wss:":"ws:"}//${location.host}${nc}`}function ac(){return window.location.search.includes("mode=iframe")?"iframe":"standalone"}function Ro(){let e=E().ws;if(!e.closing){try{e.ws=new WebSocket(ic())}catch{To();return}e.ws.onopen=()=>{try{e.ws.send(JSON.stringify({type:"hello",mode:ac(),url:location.href,viewport:{w:window.innerWidth,h:window.innerHeight}}))}catch{e.ws?.close()}},e.ws.onmessage=t=>{let n;try{n=JSON.parse(t.data)}catch{return}switch(n.type){case"ack":e.clientId=n.clientId,e.reconnectDelay=rc,sc();break;case"command":lc(n.id,n.steps);break;case"broadcast":cc(n.action,n.payload);break}},e.ws.onclose=()=>{e.ws=null,e.clientId=null,e.closing||To()},e.ws.onerror=()=>{}}}function To(){let e=E().ws;e.closing||(setTimeout(()=>Ro(),e.reconnectDelay),e.reconnectDelay=Math.min(e.reconnectDelay*2,oc))}async function lc(e,t){let n=E().ws;if(n.busy){Et({id:e,steps:[],snapshot:"",logs:[],duration:0,error:"Browser agent is busy"});return}n.busy=!0,gn("command-started",{id:e,steps:t.map(r=>r.command)});try{let r=await St(e,t);Et(r),gn("command-completed",{id:e,success:!0})}catch{Et({id:e,steps:[],snapshot:"",logs:[],duration:0}),gn("command-completed",{id:e,success:!1})}finally{E().ws.busy=!1}}function Et(e){try{let t=_o();t&&t.send(JSON.stringify({type:"result",...e}))}catch{}}async function sc(){let e=await $o();e&&Et(e)}function gn(e,t){window.parent!==window&&window.parent.postMessage({channel:"mindstudio-browser-agent",command:e,...t},"*")}function cc(e,t){e==="reload"&&(document.cookie="__ms_auth=; Max-Age=0; Path=/",location.href="/")}var Po="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",uc=200,Fo=`
|
|
112
112
|
all: initial !important;
|
|
113
113
|
display: block !important;
|
|
114
114
|
box-sizing: border-box !important;
|
|
@@ -228,4 +228,4 @@ ${h}
|
|
|
228
228
|
border-radius: 12px;
|
|
229
229
|
pointer-events: none;
|
|
230
230
|
z-index: 2;
|
|
231
|
-
`,t.overlay.appendChild(t.dragPreview)),t.dragPreview.style.left=`${Math.min(t.startX,e.clientX)}px`,t.dragPreview.style.top=`${Math.min(t.startY,e.clientY)}px`,t.dragPreview.style.width=`${Math.abs(n)}px`,t.dragPreview.style.height=`${Math.abs(r)}px`)}function zo(e){let t=E().noteLayer;if(t.overlay)try{t.overlay.releasePointerCapture(e.pointerId)}catch{}if(t.movingNote){t.movingNote=null;return}if(t.consumedByDeactivation){t.consumedByDeactivation=!1,De();return}if(!t.pointerDown||!t.overlay){De();return}if(t.didDrag){t.dragPreview&&(t.dragPreview.remove(),t.dragPreview=null);let n=Math.min(t.startX,e.clientX),r=Math.min(t.startY,e.clientY),i=Math.abs(e.clientX-t.startX),o=Math.abs(e.clientY-t.startY);if(i>10&&o>10){let a=Oo(n,r,i,o);t.overlay.appendChild(a.element),t.notes.push(a),Ct(a),t.currentNote=a}}else{let n=Do(e.clientX,e.clientY);t.overlay.appendChild(n.element),t.notes.push(n),Ct(n),t.currentNote=n}De()}function Xo(){let e=E().noteLayer;e.dragPreview&&(e.dragPreview.remove(),e.dragPreview=null),e.movingNote=null,De()}function Go(e){let t=E().noteLayer;if(t.currentNote){if(e.key==="Enter"&&!e.shiftKey&&t.currentNote.state==="editing"){Ie(t.currentNote)||ke(t.currentNote),t.currentNote=null,e.preventDefault();return}if(e.key==="Escape"){t.currentNote.state==="editing"?(Ie(t.currentNote)||ke(t.currentNote),t.currentNote=null):t.currentNote.state==="selected"&&(Ie(t.currentNote),t.currentNote=null),e.preventDefault();return}if(t.currentNote.state==="selected"&&(e.key==="Delete"||e.key==="Backspace")){ke(t.currentNote),t.currentNote=null,e.preventDefault();return}t.currentNote.state==="editing"&&(e.key==="Backspace"||e.key==="Delete")&&t.currentNote.bubble.textContent?.trim()===""&&(ke(t.currentNote),t.currentNote=null,e.preventDefault())}}function Bo(e,t){let n=E().noteLayer;n.movingNote=e,n.moveOffsetX=t.clientX-e.x,n.moveOffsetY=t.clientY-e.y}function Ko(e){let t=E().noteLayer;for(let n of t.notes)if(n.element.contains(e))return n;return null}function ke(e){let t=E().noteLayer;e.element.remove(),t.notes=t.notes.filter(n=>n.id!==e.id),t.currentNote===e&&(t.currentNote=null)}function De(){let e=E().noteLayer;e.pointerDown=!1,e.startX=0,e.startY=0,e.didDrag=!1,e.dragPreview&&(e.dragPreview.remove(),e.dragPreview=null)}function Jo(){let e=E().notesMode;e.active||(e.active=!0,Wo())}function Zo(){let e=E().notesMode;e.active&&(e.active=!1,Uo())}async function Qo(){let{image:e}=await Ge({viewportOnly:!0});return e}var yn="mindstudio-browser-agent";function ei(){let e=E(),t=new URLSearchParams(window.location.search);e.zoom.pipMode=t.get("display-mode")==="pip",e.zoom.mobilePreview=t.get("preview")==="mobile";try{let n=sessionStorage.getItem("__ms_pip");n==="1"?e.zoom.pipMode=!0:n==="0"&&(e.zoom.pipMode=!1);let r=sessionStorage.getItem("__ms_mobile");r==="1"?e.zoom.mobilePreview=!0:r==="0"&&(e.zoom.mobilePreview=!1)}catch{}e.messages.handler||(e.messages.handler=async n=>{if(n.source===window)return;let r=n.data;if(!(!r||typeof r.command!="string")&&r.channel===yn)switch(r.command){case"notes-enter":Jo();break;case"notes-exit":Zo();break;case"notes-cursor-hide":qo();break;case"notes-screenshot":{try{let i=await Qo();window.parent.postMessage({channel:yn,command:"screenshot-result",image:i},"*")}catch(i){window.parent.postMessage({channel:yn,command:"screenshot-result",error:i instanceof Error?i.message:"Screenshot failed"},"*")}break}case"cursor-show":vt("visible");break;case"cursor-hide":vt("hidden");break;case"cursor-auto":vt(null);break;case"navigate":typeof r.url=="string"&&(window.history.pushState(null,"",r.url),window.dispatchEvent(new PopStateEvent("popstate")));break;case"display-mode-pip":e.zoom.pipMode=!0;try{sessionStorage.setItem("__ms_pip","1")}catch{}break;case"display-mode-full":e.zoom.pipMode=!1;try{sessionStorage.setItem("__ms_pip","0")}catch{}break;case"preview-mode-mobile":e.zoom.mobilePreview=!0;try{sessionStorage.setItem("__ms_mobile","1")}catch{}ln(),un(!0);break;case"preview-mode-desktop":e.zoom.mobilePreview=!1;try{sessionStorage.setItem("__ms_mobile","0")}catch{}to(),un(!1);break}},window.addEventListener("message",e.messages.handler))}window.__MINDSTUDIO_BROWSER_AGENT__||(window.__MINDSTUDIO_BROWSER_AGENT__=!0,Cn(),Ln(),Tn(),Nn(),Rn(),_n(),No(),ei(),mo(),eo(),Vr(),window.parent!==window&&window.parent.postMessage({channel:"mindstudio-browser-agent",command:"ready"},"*"));return gi(gc);})();
|
|
231
|
+
`,t.overlay.appendChild(t.dragPreview)),t.dragPreview.style.left=`${Math.min(t.startX,e.clientX)}px`,t.dragPreview.style.top=`${Math.min(t.startY,e.clientY)}px`,t.dragPreview.style.width=`${Math.abs(n)}px`,t.dragPreview.style.height=`${Math.abs(r)}px`)}function zo(e){let t=E().noteLayer;if(t.overlay)try{t.overlay.releasePointerCapture(e.pointerId)}catch{}if(t.movingNote){t.movingNote=null;return}if(t.consumedByDeactivation){t.consumedByDeactivation=!1,De();return}if(!t.pointerDown||!t.overlay){De();return}if(t.didDrag){t.dragPreview&&(t.dragPreview.remove(),t.dragPreview=null);let n=Math.min(t.startX,e.clientX),r=Math.min(t.startY,e.clientY),i=Math.abs(e.clientX-t.startX),o=Math.abs(e.clientY-t.startY);if(i>10&&o>10){let a=Oo(n,r,i,o);t.overlay.appendChild(a.element),t.notes.push(a),Ct(a),t.currentNote=a}}else{let n=Do(e.clientX,e.clientY);t.overlay.appendChild(n.element),t.notes.push(n),Ct(n),t.currentNote=n}De()}function Xo(){let e=E().noteLayer;e.dragPreview&&(e.dragPreview.remove(),e.dragPreview=null),e.movingNote=null,De()}function Go(e){let t=E().noteLayer;if(t.currentNote){if(e.key==="Enter"&&!e.shiftKey&&t.currentNote.state==="editing"){Ie(t.currentNote)||ke(t.currentNote),t.currentNote=null,e.preventDefault();return}if(e.key==="Escape"){t.currentNote.state==="editing"?(Ie(t.currentNote)||ke(t.currentNote),t.currentNote=null):t.currentNote.state==="selected"&&(Ie(t.currentNote),t.currentNote=null),e.preventDefault();return}if(t.currentNote.state==="selected"&&(e.key==="Delete"||e.key==="Backspace")){ke(t.currentNote),t.currentNote=null,e.preventDefault();return}t.currentNote.state==="editing"&&(e.key==="Backspace"||e.key==="Delete")&&t.currentNote.bubble.textContent?.trim()===""&&(ke(t.currentNote),t.currentNote=null,e.preventDefault())}}function Bo(e,t){let n=E().noteLayer;n.movingNote=e,n.moveOffsetX=t.clientX-e.x,n.moveOffsetY=t.clientY-e.y}function Ko(e){let t=E().noteLayer;for(let n of t.notes)if(n.element.contains(e))return n;return null}function ke(e){let t=E().noteLayer;e.element.remove(),t.notes=t.notes.filter(n=>n.id!==e.id),t.currentNote===e&&(t.currentNote=null)}function De(){let e=E().noteLayer;e.pointerDown=!1,e.startX=0,e.startY=0,e.didDrag=!1,e.dragPreview&&(e.dragPreview.remove(),e.dragPreview=null)}function Jo(){let e=E().notesMode;e.active||(e.active=!0,Wo())}function Zo(){let e=E().notesMode;e.active&&(e.active=!1,Uo())}async function Qo(){let{image:e}=await Ge({viewportOnly:!0});return e}var yn="mindstudio-browser-agent";function ei(){let e=E(),t=new URLSearchParams(window.location.search);e.zoom.pipMode=t.get("display-mode")==="pip",e.zoom.mobilePreview=t.get("preview")==="mobile"||window.innerWidth<768;try{let n=sessionStorage.getItem("__ms_pip");n==="1"?e.zoom.pipMode=!0:n==="0"&&(e.zoom.pipMode=!1);let r=sessionStorage.getItem("__ms_mobile");r==="1"?e.zoom.mobilePreview=!0:r==="0"&&(e.zoom.mobilePreview=!1)}catch{}e.messages.handler||(e.messages.handler=async n=>{if(n.source===window)return;let r=n.data;if(!(!r||typeof r.command!="string")&&r.channel===yn)switch(r.command){case"notes-enter":Jo();break;case"notes-exit":Zo();break;case"notes-cursor-hide":qo();break;case"notes-screenshot":{try{let i=await Qo();window.parent.postMessage({channel:yn,command:"screenshot-result",image:i},"*")}catch(i){window.parent.postMessage({channel:yn,command:"screenshot-result",error:i instanceof Error?i.message:"Screenshot failed"},"*")}break}case"cursor-show":vt("visible");break;case"cursor-hide":vt("hidden");break;case"cursor-auto":vt(null);break;case"navigate":typeof r.url=="string"&&(window.history.pushState(null,"",r.url),window.dispatchEvent(new PopStateEvent("popstate")));break;case"display-mode-pip":e.zoom.pipMode=!0;try{sessionStorage.setItem("__ms_pip","1")}catch{}break;case"display-mode-full":e.zoom.pipMode=!1;try{sessionStorage.setItem("__ms_pip","0")}catch{}break;case"preview-mode-mobile":e.zoom.mobilePreview=!0;try{sessionStorage.setItem("__ms_mobile","1")}catch{}ln(),un(!0);break;case"preview-mode-desktop":e.zoom.mobilePreview=!1;try{sessionStorage.setItem("__ms_mobile","0")}catch{}to(),un(!1);break}},window.addEventListener("message",e.messages.handler))}window.__MINDSTUDIO_BROWSER_AGENT__||(window.__MINDSTUDIO_BROWSER_AGENT__=!0,Cn(),Ln(),Tn(),Nn(),Rn(),_n(),No(),ei(),mo(),eo(),Vr(),window.parent!==window&&window.parent.postMessage({channel:"mindstudio-browser-agent",command:"ready"},"*"));return gi(gc);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindstudio-ai/browser-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"description": "Browser-side agent for MindStudio dev previews — captures logs, provides DOM snapshots, and enables remote interaction.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|