agent-device 0.16.12 → 0.16.13
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/android-multitouch-helper/README.md +2 -2
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.13.apk +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.13.apk.sha256 +1 -0
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.16.12.manifest.json → agent-device-android-multitouch-helper-0.16.13.manifest.json} +4 -4
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.16.12.apk → agent-device-android-snapshot-helper-0.16.13.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.13.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.16.12.manifest.json → agent-device-android-snapshot-helper-0.16.13.manifest.json} +6 -6
- package/dist/src/1352.js +1 -1
- package/dist/src/2415.js +28 -28
- package/dist/src/9471.js +1 -1
- package/dist/src/9533.js +1 -1
- package/dist/src/9542.js +2 -2
- package/dist/src/android-adb.d.ts +7 -0
- package/dist/src/android-snapshot-helper.d.ts +7 -0
- package/dist/src/android.js +5 -5
- package/dist/src/args.js +2 -2
- package/dist/src/find.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/session.js +11 -9
- package/dist/src/snapshot.js +2 -2
- package/package.json +1 -1
- package/server.json +2 -2
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.12.apk +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.12.apk.sha256 +0 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.12.apk.sha256 +0 -1
package/dist/src/9471.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setSessionSnapshot as e,captureSnapshot as r,isNavigationSensitiveAction as t,markPendingInteractionOutcome as n,
|
|
1
|
+
import{setSessionSnapshot as e,captureSnapshot as r,isNavigationSensitiveAction as t,markPendingInteractionOutcome as n,markPostGestureStabilization as o,getSnapshotReferenceFrame as i,recordTouchVisualizationEvent as a,markAndroidSnapshotFreshness as c,stripInternalInteractionFlags as s}from"./2415.js";import{successText as d}from"./1998.js";import{getAndroidScreenSize as f}from"./input-actions.js";import{emitDiagnostic as u}from"./7599.js";async function l(t,n,o,i,a){let c={...n??{},snapshotInteractiveOnly:a.interactiveOnly,snapshotCompact:a.interactiveOnly},s=i(c,t.appBundleId,t.trace?.outPath),{snapshot:d}=await r({device:t.device,session:t,flags:c,outPath:c.out,logPath:s.logPath??"",androidFreshnessMode:a.androidFreshnessMode});return e(t,d),o.set(t.name,t),d}function p(e){var r,t,n;let o,i,a,{data:c,fallbackX:s,fallbackY:f,referenceFrame:u,extra:l}=e,p=(r=l,t=s,n=f,o="string"==typeof r?.ref?r.ref:void 0,i="string"==typeof r?.button?r.button:void 0,a="string"==typeof r?.gesture?r.gesture:void 0,("string"==typeof r?.text?`Filled ${Array.from(r.text).length} chars`:o?"longpress"===a?`Long pressed @${o} (${t}, ${n})`:i&&"primary"!==i?`Clicked ${i} @${o} (${t}, ${n})`:`Tapped @${o} (${t}, ${n})`:void 0)??("string"==typeof c?.message?c.message:void 0));return{x:s,y:f,...u??{},...l??{},...c??{},...d(p)}}function h(e){let{session:r,sessionStore:i,command:d,positionals:f,retryPositionals:u,flags:l,result:p,responseData:h,actionStartedAt:g,actionFinishedAt:m,androidFreshnessBaseline:_}=e,v=s(l);return i.recordAction(r,{command:d,positionals:f,flags:v??{},result:p}),n({session:r,command:d,positionals:u??f,flags:l,preSnapshot:r.snapshot}),t(d)&&c(r,d,_??r.snapshot),o(r,d,u??f,l),a(r,d,f,p,v??{},g,m),{ok:!0,data:h}}async function g(e){let{session:r,flags:t,sessionStore:n,contextFromFlags:o,captureSnapshotForSession:a}=e;if(!r.recording)return;if(r.recording.touchReferenceFrame)return r.recording.touchReferenceFrame;if("android"===r.device.platform){let e=await f(r.device),t={referenceWidth:e.width,referenceHeight:e.height};return r.recording&&(r.recording.touchReferenceFrame=t),t}let c=i(r.snapshot);if(c)return r.recording&&(r.recording.touchReferenceFrame=c),c;if(!r.recording)return;let s=i(await a(r,t,n,o,{interactiveOnly:!0}));return s&&r.recording&&(r.recording.touchReferenceFrame=s),s}async function m(e){try{return await g(e)}catch(r){u({level:"warn",phase:"touch_reference_frame_resolve_failed",data:{platform:e.session.device.platform,error:r instanceof Error?r.message:String(r)}});return}}function _(e){return i({nodes:e,createdAt:0})}export{p as buildTouchVisualizationResult,h as finalizeTouchInteraction,l as interaction_snapshot_captureSnapshotForSession,_ as readSnapshotNodesReferenceFrame,m as resolveDirectTouchReferenceFrameSafely};
|
package/dist/src/9533.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{promises as e}from"node:fs";import{deflateSync as t,inflateSync as n}from"node:zlib";import r from"node:path";import{asAppError as i,AppError as a}from"./9152.js";import{normalizeRef as o,centerOfRect as s,buildSnapshotPresentationKey as l,findNodeByRef as d}from"./4057.js";import{expandRect as c,intersectArea as u,isScrollableNodeLike as h,unionRects as p,rectCenter as f,clamp as w,squaredDistance as m}from"./4778.js";import{successText as b}from"./1998.js";import{whichCmd as g,runCmd as y}from"./9818.js";import{trimText as x,extractNodeText as v,findSnapshotAncestor as k,parseSelectorChain as I,isNodeVisible as N,buildSnapshotNodeByIndex as A,isNodeEditable as M,buildTextPreview as R,findNearestHittableAncestor as P,buildSelectorChainForNode as S,findSelectorChainMatch as O,resolveSelectorChain as D,findNodeByLabel as E,resolveRefLabel as _,describeTextSurface as T,extractReadableText as $,formatSelectorFailure as C,normalizeType as L,isFillableType as U}from"./940.js";import{findBestMatchesByLocator as B}from"./7556.js";import"./7847.js";import{resolveAppsFilter as G,assertResolvedAppsFilter as F}from"./1393.js";let q=["status","get","dismiss","enter","return"];function X(e){return q.includes(e)}function Y(e){let t=e?.trim().split(/\s+/,1)[0];if(!t||!t.startsWith("@")||t.length<3)return null;let n=t.slice(1);return/^[A-Za-z_-]*\d[\w-]*$/i.test(n)||/^(?:ref|node|element|el)[\w-]*$/i.test(n)?t:null}function V(e){let t=e.direction,n="up"===t||"down"===t?e.referenceHeight:e.referenceWidth,r=function(e){if(void 0===e)return .6;if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS","scroll amount must be a positive number");return e}(e.amount),i=void 0!==e.pixels?function(e){if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS","scroll pixels must be a positive integer");return Math.max(1,Math.round(e))}(e.pixels):Math.round(n*r),o=Math.max(1,Math.round(.05*n)),s=Math.max(1,Math.min(i,Math.max(1,n-2*o))),l=Math.round(s/2),d=Math.round(e.referenceWidth/2),c=Math.round(e.referenceHeight/2),u=(n,r,i,a)=>({direction:t,x1:n,y1:r,x2:i,y2:a,referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:s});switch(t){case"up":return u(d,c-l,d,c+l);case"down":return u(d,c+l,d,c-l);case"left":return u(d-l,c,d+l,c);case"right":return u(d+l,c,d-l,c)}}function H(e){return{...V({...e,direction:function(e){switch(e){case"up":return"down";case"down":return"up";case"left":return"right";case"right":return"left"}}(e.direction)}),direction:e.direction}}function z(e,t,n={}){let r=n.marginPx??8,[i,a,o]="left"===e?[85,15,65]:"right"===e?[15,85,65]:"left-edge"===e?[99,15,50]:[1,85,50],s=W(t,i,o,{marginPx:r}),l=W(t,a,o,{marginPx:r});return{preset:e,x1:s.x,y1:s.y,x2:l.x,y2:l.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function K(e){switch(e){case"left":case"right":case"left-edge":case"right-edge":return e;default:throw new a("INVALID_ARGS","gesture swipe requires left, right, left-edge, or right-edge")}}function j(e){let t=function(e){let t=e.filter(e=>(function(e){if(!e)return!1;let t=e.toLowerCase();return t.includes("application")||t.includes("window")})(e.type)&&Q(e.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(t)return t;let n=e.map(e=>e.rect).filter(Q);if(0===n.length)return;let r=Math.max(...n.map(e=>e.x+e.width)),i=Math.max(...n.map(e=>e.y+e.height));if(!(r<=0)&&!(i<=0))return{x:0,y:0,width:r,height:i}}(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function W(e,t,n,r={}){let i={x:Math.round(e.referenceWidth*t/100),y:Math.round(e.referenceHeight*n/100)};return void 0===r.marginPx?i:J(i,e,r.marginPx)}function J(e,t,n){return{x:ee(e.x,n,t.referenceWidth),y:ee(e.y,n,t.referenceHeight)}}function Z(e){switch(e){case"up":case"down":case"left":case"right":return e;default:throw new a("INVALID_ARGS",`Unknown direction: ${e}`)}}function Q(e){return!!e&&e.width>0&&e.height>0}function ee(e,t,n){let r=Math.max(t,n-t);return et(e,t,r)}function et(e,t,n){return Math.min(Math.round(n),Math.max(Math.round(t),Math.round(e)))}function en(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function er(e){let t=null,n=-1;for(let r of e){let e=r.width*r.height;e>n&&(t=r,n=e)}return t}function ei(e,t,n,r){return Math.max(e,n)<=Math.min(t,r)}function ea(e){let t=e.trim().toLowerCase();return!!t&&/^(vertical|horizontal)\s+scroll\s+bar(?:,?\s*\d+\s+pages?)?$/.test(t)}function eo(e,t){if(!(e?.trim().toLowerCase()??"").includes("vertical scroll bar"))return null;let n=function(e){if(!e)return null;let t=/^(\d{1,3})%$/.exec(e.trim());if(!t)return null;let n=Number(t[1]);return Number.isFinite(n)?Math.max(0,Math.min(100,n)):null}(t);return null===n?null:n<=1?{above:!1,below:!0}:n>=99?{above:!0,below:!1}:{above:!0,below:!0}}function es(e){let t=new Map;for(let[n,r]of e.entries())t.set(r.index,n);let n=[],r=[];for(let[i,a]of e.entries()){let e=Math.max(0,a.depth??0);for(;r.length>0&&e<=r[r.length-1].depth;)r.pop();let o="number"==typeof a.parentIndex?t.get(a.parentIndex):void 0,s="number"==typeof o&&o<i?o:r[r.length-1]?.index;n.push({...a,index:i,depth:e,parentIndex:s}),r.push({depth:e,index:i})}return n}function el(e){return new Map(e.map(e=>[e.index,e]))}function ed(e){return e.label?.trim()||e.value?.trim()||e.identifier?.trim()||""}function ec(e){if(0===e.length)return{nodes:e,hiddenCount:0,summaryLines:[]};let{byIndex:t,visibleNodeIndexes:n,offscreenNodes:r,hintedContainers:i}=eh(e),a=0===n.size?e:e.filter(e=>n.has(e.index));return{nodes:a.map(e=>(function(e,t){let n=t.get(e.index);if(!n||0===n.size)return e;let r=!!(!0===e.hiddenContentAbove||n.has("above"))||void 0,i=!!(!0===e.hiddenContentBelow||n.has("below"))||void 0;return{...e,hiddenContentAbove:r,hiddenContentBelow:i}})(e,i.directionsByContainer)),hiddenCount:0===n.size?0:e.length-a.length,summaryLines:function(e,t,n){let r=new Map;for(let i of e){let e=function(e,t,n){if(!e.rect)return null;let r=ef(e,t,n);return r?ew(e.rect,r):null}(i,t,n);if(!e)continue;let a=r.get(e)??[];a.push(i),r.set(e,a)}return["above","below"].flatMap(e=>{let t=r.get(e);if(!t||0===t.length)return[];let n=(function(e){let t=new Set,n=[];for(let r of e){let e=ed(r);!e||t.has(e)||(t.add(e),n.push(e))}return n})(t).slice(0,3).map(e=>`"${e}"`),i=1===t.length?"interactive item":"interactive items",a=n.length>0?`: ${n.join(", ")}`:"";return[`[off-screen ${e}] ${t.length} ${i}${a}`]})}(r.filter(e=>!i.coveredNodeIndexes.has(e.index)&&function(e){if(!0===e.hittable)return!0;let t=(e.type??"").toLowerCase();return t.includes("button")||t.includes("link")||t.includes("textfield")||t.includes("edittext")||t.includes("searchfield")||t.includes("checkbox")||t.includes("radio")||t.includes("switch")||t.includes("menuitem")||!!ed(e)}(e)),e,t)}}function eu(e){if(0===e.length)return new Map;let{hintedContainers:t}=eh(e);var n=t.directionsByContainer;let r=new Map;for(let[e,t]of n){let n={};t.has("above")&&(n.hiddenContentAbove=!0),t.has("below")&&(n.hiddenContentBelow=!0),(n.hiddenContentAbove||n.hiddenContentBelow)&&r.set(e,n)}return r}function eh(e){let t=el(e),n=new Set,r=[];for(let i of e){if(ep(i,e,t)){!function(e,t,n){let r=e,i=new Set;for(;r&&!i.has(r.index);)i.add(r.index),t.add(r.index),r="number"==typeof r.parentIndex?n.get(r.parentIndex):void 0}(i,n,t);continue}r.push(i)}let i=function(e,t,n,r){let i=new Map,a=new Map,o=new Set;for(let e of t){if(!e.rect)continue;let t=em(e,n,r);if(!t?.rect)continue;let s=ew(e.rect,t.rect);if(!s)continue;let l=i.get(t.index)??new Set;l.add(s),i.set(t.index,l);let d=a.get(t.index)??new Set;d.add(s),a.set(t.index,d),o.add(e.index)}return function(e,t,n,r,i){for(let a of e){let e=function(e){let t=eo(e.label,e.value);if(!t)return null;let n=new Set;return t.above&&n.add("above"),t.below&&n.add("below"),n.size>0?n:null}(a);if(!e||0===e.size)continue;let o=em(a,t,n);if(!o)continue;let s=r.get(o.index)??new Set,l=i.get(o.index);for(let t of e)(!l||!(l.size>0)||l.has(t))&&s.add(t);r.set(o.index,s)}}(e,n,r,i,a),{directionsByContainer:i,coveredNodeIndexes:o}}(e,r,n,t);return{byIndex:t,visibleNodeIndexes:n,offscreenNodes:r,hintedContainers:i}}function ep(e,t,n=el(t)){var r;if(!e.rect)return!0;let i=ef(e,t,n);return!i||(r=e.rect,ei(r.x,r.x+r.width,i.x,i.x+i.width)&&ei(r.y,r.y+r.height,i.y,i.y+i.height))}function ef(e,t,n=el(t)){var r,i;let a=(r=e,i=n,eb(r,i,e=>!!e.rect)?.rect??null);return a||function(e,t){let n=s(t),r=e.filter(e=>{var t;return!!(t=e.rect)&&Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)}),i=r.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}),a=er(i.map(e=>e.rect).filter(e=>en(e,n.x,n.y)));if(a)return a;let o=er(i.map(e=>e.rect));if(o)return o;let l=er(r.map(e=>e.rect).filter(e=>en(e,n.x,n.y)));return l||null}(t,e.rect??{x:0,y:0,width:0,height:0})}function ew(e,t){return e.y+e.height<=t.y?"above":e.y>=t.y+t.height?"below":null}function em(e,t,n){return eb(e,n,e=>t.has(e.index))}function eb(e,t,n){let r="number"==typeof e.parentIndex?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(i.add(r.index),n(r)&&h(r))return r;r="number"==typeof r.parentIndex?t.get(r.parentIndex):void 0}return null}async function eg(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=await i(r),a=function(e,t,n={}){var r,i,a;let o,s=(e??[]).map((e,t)=>({...e,ref:"ref"in e&&e.ref?e.ref:`e${t+1}`}));if(0===s.length)return{canScroll:!1,emptySnapshot:!0,signature:""};let l=eu(s),d=function(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>h(e)&&eM(e.rect));if(0===a.length)return null;let o=function(e,t){if(void 0===e)return null;let n=t.get(e);for(;n;){if(h(n)&&eM(n.rect))return n;n=void 0===n.parentIndex?void 0:t.get(n.parentIndex)}return null}(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>{var t,n;return e.rect&&(t=e.rect,(n=s).x>=t.x&&n.x<=t.x+t.width&&n.y>=t.y&&n.y<=t.y+t.height)}).sort(eI);if(e.length>0)return e.find(e=>ev(e,t.get(e.index),n))??e[0]??null}let l=a.filter(e=>ev(e,t.get(e.index),n)).sort(eN);return l.length>0?l[0]??null:a.filter(t=>ep(t,e)).sort(eN)[0]??a.sort(eN)[0]??null}(s,l,t,n),c=(d?(r=s,i=d.index,o=new Map(r.map(e=>[e.index,e])),r.filter(e=>e.index===i||function(e,t,n){let r=void 0===e.parentIndex?void 0:n.get(e.parentIndex);for(;r;){if(r.index===t)return!0;r=void 0===r.parentIndex?void 0:n.get(r.parentIndex)}return!1}(e,i,o))):s).map(e=>{let t=e.rect?["x","y","width","height"].map(t=>{var n;return n=e.rect?.[t],"number"==typeof n&&Number.isFinite(n)?n.toFixed(1):""}).join(","):"";return[String(e.index??""),String(e.parentIndex??""),String(e.type??""),String(e.label??""),String(e.value??""),t].join("|")}).join("\n");return d?{canScroll:ev(d,l.get(d.index),t),emptySnapshot:!1,signature:c,scope:[(a=d).identifier,a.label,a.value].map(e=>"string"==typeof e?e.trim():"").find(ek)}:{canScroll:!1,emptySnapshot:!1,signature:c}}(e,t,n);if(r&&a.emptySnapshot)return await eg({edge:t,target:n,captureNodes:i});return a}catch(e){var o,s,l;throw o=t,s=r,l=e,s?new a("COMMAND_FAILED",`Failed to verify scroll ${o} state for scoped container`,{scope:s,hint:`scroll ${o} could not verify the scoped scroll container. Run snapshot -i -c for the current screen and retry with a visible scroll target.`},l):new a("COMMAND_FAILED",`Failed to verify scroll ${o} state`,{hint:`scroll ${o} needs a snapshot showing hidden content ${"bottom"===o?"below":"above"} before it will move.`},l)}}async function ey(e){let t,{edge:n,captureState:r,scroll:i}=e,o=await r();o.scope&&(o=await r(o.scope));let s=0;for(;o.canScroll;){if(s>=40)throw new a("COMMAND_FAILED",`scroll ${n} reached the safety limit before the snapshot showed the edge`,{hint:"The scoped scroll container still reports hidden content. Use a smaller manual scroll + snapshot loop to inspect the current state."});t=await i(),s+=1,o=await r(o.scope)}return{passes:s,result:t}}function ex(e,t,n,r,i){return t&&0===n?`Already at ${t}; no hidden content ${"bottom"===t?"below":"above"} detected`:t?`Scrolled to ${t} with ${n} ${e} passes`:void 0!==i?`Scrolled ${e} by ${i}px`:void 0!==r?`Scrolled ${e} by ${r}`:`Scrolled ${e}`}function ev(e,t,n){return"bottom"===n?!0===e.hiddenContentBelow||t?.hiddenContentBelow===!0:!0===e.hiddenContentAbove||t?.hiddenContentAbove===!0}function ek(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function eI(e,t){return eA(e.rect)-eA(t.rect)}function eN(e,t){return eA(t.rect)-eA(e.rect)}function eA(e){return e?e.width*e.height:0}function eM(e){return!!(e&&e.width>0&&e.height>0)}function eR(e,t,n,r){if(!Number.isFinite(e)||!Number.isInteger(e)||e<n||e>r)throw new a("INVALID_ARGS",`${t} must be an integer between ${n} and ${r}`);return e}let eP=/\b(logbox|redbox|reload js|copy stack|component stack|call stack|runtime error|open debugger to view warnings)\b/,eS=/\b(redbox|runtime error|reload js|copy stack|component stack|call stack)\b/,eO=[/\b[\w.$<>/-]+\.(?:tsx?|jsx?):\d+(?::\d+)?\b/,/\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/],eD=[/^!,\s+/,/^(warn|warning|error):\s+/,/\b(?:possible\s+)?unhandled (?:promise )?rejection\b/],eE=["open debugger to view warnings","getsnapshot should be cached to avoid an infinite loop",'unique "key" prop',"unique 'key' prop","virtualizedlists should never be nested","failed prop type"],e_=new Set(["x","\xd7","✕","✖","⨯"]);function eT(e){return e$(e)}function e$(e){var t,n,r,i,a,o,l,d,c,u;let h,p,f,w,m,b,g,y,x=(h=(t=e).map(eB).join("\n").toLowerCase(),p=ej(t,eX),f=ej(t,eV),w=ej(t,eF,eH),m=ej(t,eq),b=(n=h,eO.some(e=>e.test(n))),g=eG(h),y=(r=h,i=p,a=f,i.length>0||a.length>0||/\b(reload js|copy stack)\b/.test(r)),{dismissNodes:p,minimizeNodes:f,collapsedNodes:w,redBox:(o=h,l=b,d=y,eS.test(o)||eG(o)||l&&d),detected:(c={text:h,hasReactNativeStackFrame:b,hasOverlayControl:y,hasControllessRedBoxText:g,collapsedNodes:w,openDebuggerWarningNodes:m}).collapsedNodes.length>0||c.openDebuggerWarningNodes.length>0||c.hasControllessRedBoxText||c.hasOverlayControl&&(u=c.text,eP.test(u)||c.hasReactNativeStackFrame)}),v=x.detected?function(e){let t=eJ(e.dismissNodes,eW);if(t){let e;var n,r=t,i=(n=t,(e=eQ(n)?.trim().toLowerCase())&&eY(e)?"dismiss":"close");if(!r.rect)throw Error("React Native overlay target node must have rect");return{action:i,point:s(r.rect),rect:r.rect,ref:r.ref,label:eQ(r)}}let a=eJ(e.collapsedNodes.filter(ez),eZ);return a?.rect?{action:"close-collapsed-banner",point:function(e){var t,n;if(!e.rect)throw Error("Collapsed React Native warning node must have rect");let r=Math.min(e.rect.height,52),i=Math.min(36,Math.max(18,.45*r));return{x:Math.round((t=e.rect.x+e.rect.width-i,n=e.rect.x+1,Math.min(e.rect.x+e.rect.width-1,Math.max(n,t)))),y:Math.round(e.rect.y+r/2)}}(a),rect:a.rect,ref:a.ref,label:eQ(a)}:null}(x):null;return{detected:x.detected,redBox:x.redBox,dismissNodes:x.dismissNodes,minimizeNodes:x.minimizeNodes,collapsedNodes:x.collapsedNodes,primaryAction:v}}function eC(e){return[...e.dismissNodes,...e.minimizeNodes,...e.collapsedNodes]}function eL(e){var t;return eF(e.label?.trim())&&!!(t=e.rect)&&t.x<=1&&t.y<=1&&t.width>=300&&t.height>=600}function eU(e,t){let n=e.label?.trim();return!!n&&!!eL(e)&&t.some(e=>e.label?.trim()===n&&eK(e))}function eB(e){return[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(" ")}function eG(e){return/\buncaught\b/.test(e)&&/unable to download asset/.test(e)}function eF(e){let t=e?.trim().toLowerCase();return!!t&&(eE.some(e=>t.includes(e))||eD.some(e=>e.test(t)))}function eq(e){return e.includes("open debugger to view warnings")||/^!,\s+open debugger\b/.test(e)}function eX(e){var t,n;return eY(e)||(t=e,/^close(?:\s*\([^)]*\))?$/i.test(t))||(n=e,e_.has(n))}function eY(e){return/^dismiss(?:\s*\([^)]*\))?$/i.test(e)}function eV(e){return/^minimi[sz]e(?:\b|\s|\()/i.test(e)}function eH(e){return!e.rect||e.rect.height<=180}function ez(e){let t=eQ(e)?.trim().toLowerCase()??"";return(eq(t)||/^!,\s+/.test(t))&&eK(e)}function eK(e){return!!e.rect&&e.rect.width>=120&&e.rect.height>=36&&e.rect.height<=180}function ej(e,t,n=()=>!0){let r=[];for(let i of e)i.ref&&n(i)&&[i.label,i.value,i.identifier].map(e=>e?.trim().toLowerCase()).filter(e=>!!e).some(e=>t(e))&&r.push(i);return r}function eW(e){var t;let n;return[+(!0===(n=[e.type,e.role,e.subrole].join(" ").toLowerCase(),/\b(button|menuitem|link)\b/.test(n))),+(!0===e.hittable),-((t=e.rect)?t.width*t.height:1/0)]}function eJ(e,t){let n=e.filter(e=>e.rect);return 0===n.length?null:n.sort((e,n)=>(function(e,t){for(let n=0;n<e.length;n+=1){let r=e[n]-t[n];if(0!==r)return r}return 0})(t(n),t(e)))[0]??null}function eZ(e){return[+(!0===e.hittable),e.rect?.width??0,e.rect?.y??0]}function eQ(e){return e.label??e.value??e.identifier}let e0=Buffer.from([137,80,78,71,13,10,26,10]),e1=new Map([[0,1],[2,3],[3,1],[4,2],[6,4]]),e2=new Map([[0,new Set([1,2,4,8,16])],[2,new Set([8,16])],[3,new Set([1,2,4,8])],[4,new Set([8,16])],[6,new Set([8,16])]]),e5=[{x:0,y:0,dx:8,dy:8},{x:4,y:0,dx:8,dy:8},{x:0,y:4,dx:4,dy:8},{x:2,y:0,dx:4,dy:4},{x:0,y:2,dx:2,dy:4},{x:1,y:0,dx:2,dy:2},{x:0,y:1,dx:1,dy:2}];class e4{width;height;data;static sync={read:e8,write:e3};constructor(e){this.width=ta(e.width,"width"),this.height=ta(e.height,"height");let t=this.width*this.height*4;if(this.data=e.data?Buffer.from(e.data):Buffer.alloc(t),this.data.length!==t)throw Error(`PNG data length must be ${t} bytes`)}}function e8(e){var t;let{metadata:r,idatChunks:i}=function(e){let t,n=[];for(let r of function*(e){if(!e.subarray(0,e0.length).equals(e0))throw Error("Invalid PNG signature");let t=e0.length;for(;t<e.length;){if(t+12>e.length)throw Error("Truncated PNG chunk");let n=e.readUInt32BE(t),r=e.toString("ascii",t+4,t+8),i=t+8,a=i+n;if(a+4>e.length)throw Error(`Truncated PNG ${r} chunk`);let o=e.subarray(i,a),s=e.readUInt32BE(a);if(ti(e.subarray(t+4,a))!==s)throw Error(`Invalid PNG ${r} chunk CRC`);t=a+4,yield{type:r,data:o}}}(e))if("IHDR"===r.type?t=function(e){var t;if(13!==e.length)throw Error("Invalid PNG IHDR length");let n=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],l=e[12];if(t=a,!e1.has(t))throw Error(`Unsupported PNG color type ${a}`);let d=e2.get(a);if(!d?.has(i))throw Error(`Unsupported PNG color type ${a} with bit depth ${i}`);if(0!==o)throw Error(`Unsupported PNG compression method ${o}`);if(0!==s)throw Error(`Unsupported PNG filter method ${s}`);if(0!==l&&1!==l)throw Error(`Unsupported PNG interlace method ${l}`);return{width:ta(n,"width"),height:ta(r,"height"),bitDepth:i,colorType:a,interlace:l}}(r.data):"IDAT"===r.type?n.push(Buffer.from(r.data)):t=function(e,t){if("PLTE"===e.type){if(!t)throw Error("PNG PLTE appeared before IHDR");t.palette=Buffer.from(e.data)}else if("tRNS"===e.type){if(!t)throw Error("PNG tRNS appeared before IHDR");t.transparency=Buffer.from(e.data)}return t}(r,t),"IEND"===r.type)break;return{metadata:t,idatChunks:n}}(e);if(!r)throw Error("PNG is missing IHDR");if(0===i.length)throw Error("PNG is missing IDAT");let a=function(e,t){let r=function(e){if(0===e.interlace)return function(e,t){return(tt(e)+1)*t}(e,e.height);let t=0;for(let n of e5){let r=e9(e.width,n.x,n.dx),i=e9(e.height,n.y,n.dy);0!==r&&0!==i&&(t+=function(e,t){return(tt(e)+1)*t}({...e,width:r,height:i},i))}return t}(t);try{let t=n(Buffer.concat(e),{maxOutputLength:r});if(t.length!==r)throw Error("PNG pixel data is truncated");return t}catch(e){var i;if((i=e)instanceof Error&&"code"in i&&"ERR_BUFFER_TOO_LARGE"===i.code)throw Error(`PNG pixel data exceeds expected length ${r}`);throw e}}(i,r);return new e4({width:r.width,height:r.height,data:1===r.interlace?function(e,t){let n=Buffer.alloc(t.width*t.height*4),r=0;for(let i of e5){let a=e9(t.width,i.x,i.dx),o=e9(t.height,i.y,i.dy);if(0===a||0===o)continue;let s={...t,width:a,height:o,interlace:0},l=e6({inflated:e,offset:r,scanlineLength:tt(s),height:o,bytesPerPixel:tn(s)});r=l.offset;let d=tt(s);for(let e=0;e<o;e+=1){let r=l.raw.subarray(e*d,(e+1)*d);for(let o=0;o<a;o+=1){let a=i.x+o*i.dx,l=((i.y+e*i.dy)*t.width+a)*4,[d,c,u,h]=e7(r,o,s);n[l]=d,n[l+1]=c,n[l+2]=u,n[l+3]=h}}}return n}(a,r):function(e,t){let n=Buffer.alloc(t.width*t.height*4),r=tt(t);for(let i=0;i<t.height;i+=1){let a=e.subarray(i*r,(i+1)*r);for(let e=0;e<t.width;e+=1){let r=(i*t.width+e)*4,[o,s,l,d]=e7(a,e,t);n[r]=o,n[r+1]=s,n[r+2]=l,n[r+3]=d}}return n}(e6({inflated:a,offset:0,scanlineLength:tt(t=r),height:t.height,bytesPerPixel:tn(t)}).raw,r)})}function e3(e){let n=4*e.width,r=Buffer.alloc((n+1)*e.height);for(let t=0;t<e.height;t+=1){let i=t*(n+1);r[i]=0,e.data.copy(r,i+1,t*n,(t+1)*n)}let i=Buffer.alloc(13);return i.writeUInt32BE(e.width,0),i.writeUInt32BE(e.height,4),i[8]=8,i[9]=6,i[10]=0,i[11]=0,i[12]=0,Buffer.concat([e0,tr("IHDR",i),tr("IDAT",t(r)),tr("IEND",Buffer.alloc(0))])}function e6(e){let{inflated:t,offset:n,scanlineLength:r,height:i,bytesPerPixel:a}=e,o=n+(r+1)*i;if(t.length<o)throw Error("PNG pixel data is truncated");let s=Buffer.alloc(r*i);for(let e=0;e<i;e+=1){let i=n+e*(r+1),o=e*r,l=t[i];for(let n=0;n<r;n+=1){let d=t[i+1+n],c=n>=a?s[o+n-a]:0,u=e>0?s[o+n-r]:0,h=e>0&&n>=a?s[o+n-r-a]:0;s[o+n]=function(e,t,n,r,i){if(0===e)return t;if(1===e)return t+n&255;if(2===e)return t+r&255;if(3===e)return t+Math.floor((n+r)/2)&255;if(4===e)return t+function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}(n,r,i)&255;throw Error(`Unsupported PNG filter type ${e}`)}(l,d,c,u,h)}}return{raw:s,offset:o}}function e9(e,t,n){return e<=t?0:Math.floor((e-t+n-1)/n)}function e7(e,t,n){if(3===n.colorType){var r,i,a,o,s,l,d,c=e,u=t,h=n;if(!h.palette)throw Error("Indexed PNG is missing PLTE");let p=te(c,u,h.bitDepth),f=3*p;if(f+2>=h.palette.length)throw Error("Indexed PNG palette is invalid");return[h.palette[f],h.palette[f+1],h.palette[f+2],h.transparency?.[p]??255]}if(n.bitDepth<8){let i,a;return[a=Math.round((i=te(e,t,(r=n).bitDepth))/((1<<r.bitDepth)-1)*255),a,a,255*!(r.transparency&&r.transparency.length>=2&&i===r.transparency.readUInt16BE(0))]}let p=16===n.bitDepth?2:1,f=t*e1.get(n.colorType)*p,w=t=>16===n.bitDepth?e.readUInt16BE(f+2*t):e[f+t*p],m=e=>{var t;return t=w(e),16===n.bitDepth?Math.round(t/65535*255):t};if(0===n.colorType){let e=m(0);return[e,e,e,255*(i=w(0),!(a=n).transparency||!!(a.transparency.length<2)||i!==a.transparency.readUInt16BE(0))]}if(2===n.colorType){return[m(0),m(1),m(2),255*(o=w(0),s=w(1),l=w(2),!(d=n).transparency||!!(d.transparency.length<6)||o!==d.transparency.readUInt16BE(0)||s!==d.transparency.readUInt16BE(2)||l!==d.transparency.readUInt16BE(4))]}if(4===n.colorType){let e=m(0);return[e,e,e,m(1)]}return[m(0),m(1),m(2),m(3)]}function te(e,t,n){let r=t*n;return e[Math.floor(r/8)]>>8-n-r%8&(1<<n)-1}function tt(e){let t=e1.get(e.colorType);return Math.ceil(e.width*t*e.bitDepth/8)}function tn(e){return Math.max(1,Math.ceil(e1.get(e.colorType)*e.bitDepth/8))}function tr(e,t){let n=Buffer.from(e,"ascii"),r=Buffer.alloc(8+t.length+4);return r.writeUInt32BE(t.length,0),n.copy(r,4),t.copy(r,8),r.writeUInt32BE(ti(Buffer.concat([n,t])),8+t.length),r}function ti(e){let t=0xffffffff;for(let n of e){t^=n;for(let e=0;e<8;e+=1)t=1&t?0xedb88320^t>>>1:t>>>1}return(0xffffffff^t)>>>0}function ta(e,t){if(!Number.isInteger(e)||e<1)throw Error(`PNG ${t} must be positive`);return e}function to(e,t){try{return e4.sync.read(e)}catch(e){throw new a("COMMAND_FAILED",`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}async function ts(t,n){if(!Number.isInteger(n)||n<1)throw new a("INVALID_ARGS","Screenshot max size must be a positive integer");let r=to(await e.readFile(t),"screenshot"),i=Math.max(r.width,r.height);if(i<=n)return;let o=n/i,s=Math.max(1,Math.round(r.width*o)),l=Math.max(1,Math.round(r.height*o)),d=function(e,t,n){let r=new e4({width:t,height:n});for(let i=0;i<n;i+=1){let a=i*e.height/n,o=(i+1)*e.height/n;for(let n=0;n<t;n+=1){let s=n*e.width/t,l=(n+1)*e.width/t,d=0,c=0,u=0,h=0,p=0;for(let t=Math.floor(a);t<Math.ceil(o);t+=1){let n=Math.min(t+1,o)-Math.max(t,a);for(let r=Math.floor(s);r<Math.ceil(l);r+=1){let i=n*(Math.min(r+1,l)-Math.max(r,s)),a=(t*e.width+r)*4;d+=(e.data[a]??0)*i,c+=(e.data[a+1]??0)*i,u+=(e.data[a+2]??0)*i,h+=(e.data[a+3]??0)*i,p+=i}}let f=(i*r.width+n)*4;r.data[f]=Math.round(d/p),r.data[f+1]=Math.round(c/p),r.data[f+2]=Math.round(u/p),r.data[f+3]=Math.round(h/p)}}return r}(r,s,l);await e.writeFile(t,e4.sync.write(d))}async function tl(e,t,n){if("path"===t.kind&&!e.policy.allowLocalInputPaths)throw new a("INVALID_ARGS",`Local ${n.field??"input"} paths are not allowed by command policy`);try{return await e.artifacts.resolveInput(t,n)}catch(e){throw i(e)}}async function td(e,t,n){if(t?.kind==="path"&&!e.policy.allowLocalOutputPaths)throw new a("INVALID_ARGS","Local output paths are not allowed by command policy");try{return await e.artifacts.reserveOutput(t,{...n,visibility:n.visibility??"client-visible",requestedClientPath:t?.kind==="downloadableArtifact"?t.clientPath??n.requestedClientPath:n.requestedClientPath})}catch(e){throw i(e)}}async function tc(e,t){try{return await e.artifacts.createTempFile(t)}catch(e){throw i(e)}}let tu=async(e,t)=>{let n;if(!e.backend.captureScreenshot)throw new a("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");let r=await td(e,t.out,{field:"path",ext:".png"});try{await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,appId:t.appId,appBundleId:t.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},r.path,{fullscreen:t.fullscreen,overlayRefs:t.overlayRefs,stabilize:t.stabilize,surface:t.surface}),void 0!==t.maxSize&&await ts(r.path,t.maxSize),n=await r.publish()}catch(e){throw await r.cleanup?.(),e}return{path:r.path,...n?{artifacts:[n]}:{},...b(`Saved screenshot: ${r.path}`)}},th=[0,187,255,255];function tp(e,t,n,r){if(t<0||t>=e.width||n<0||n>=e.height)return;let i=(n*e.width+t)*4;e.data[i]=r[0],e.data[i+1]=r[1],e.data[i+2]=r[2],e.data[i+3]=r[3]}function tf(e,t,n){return Math.min(Math.max(e,t),n)}let tw=[{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-1,y:0},{x:1,y:0},{x:-1,y:1},{x:0,y:1},{x:1,y:1}];function tm(e){let{mask:t,width:n,height:r,hooks:i}=e,a=new Uint8Array(t.length),o=new Int32Array(t.length),s=[];for(let e=0;e<t.length;e+=1){var l,d;if(!tb(t,a,e))continue;let c=0,u=(l=o,a[d=e]=1,l[0]=d,1),h=i.create(e);for(;c<u;){let e=o[c];c+=1,i.visit(h,e),u=function(e){let{mask:t,visited:n,queue:r,width:i,height:a,pixelIndex:o}=e,s=o%i,l=Math.floor(o/i),d=e.queueEnd;for(let e of tw){var c,u,h,p;let o=s+e.x,f=l+e.y;if(c=o,u=f,h=i,p=a,!(c>=0)||!(c<h)||!(u>=0)||!(u<p))continue;let w=f*i+o;tb(t,n,w)&&(d=function(e,t,n,r){return t[r]=1,e[n]=r,n+1}(r,n,d,w))}return d}({mask:t,visited:a,queue:o,queueEnd:u,width:n,height:r,pixelIndex:e})}s.push(h)}return s}function tb(e,t,n){return 1===e[n]&&1!==t[n]}let tg={icon:90,toggle:90,chevron:75,separator:45,visual:35,background:10},ty={leading:20,trailing:20,separator:10,unknown:0,background:-30};function tx(e){return"background"!==e.likelyKind}function tv(e,t){return e.width>=.25*t.width||e.height>=.06*t.height}function tk(e,t){let n,r=0;for(let i of t){let t=tR(e,i.rect);t<=r||(r=t,n=i)}return n}function tI(e){let t=[];for(let n of[...e].sort((e,t)=>e.rect.y-t.rect.y)){let e=t.find(e=>{var t,r;return t=e.rect,tR(t,r=n.rect)>0||Math.abs(f(t).y-f(r).y)<=.5*Math.max(t.height,r.height)});if(!e){t.push({rect:n.rect,blocks:[n]});continue}e.blocks.push(n),e.blocks.sort((e,t)=>e.rect.x-t.rect.x),e.rect=p([e.rect,n.rect])}return t}function tN(e,t){let n,r=f(e);for(let e of t){let t=Math.sqrt(m(r,f(e.rect)));n&&t>=n.distance||(n={block:e,distance:t})}return n}function tA(e){let t=tM(e);return e.differentPixels>=24&&t.width>=3&&t.height>=3}function tM(e){return{x:e.minX,y:e.minY,width:e.maxX-e.minX+1,height:e.maxY-e.minY+1}}function tR(e,t){return Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}async function tP(e){if(await g("tesseract"))try{let[t,n]=await Promise.all([tO(e.baselinePath),tO(e.currentPath)]);if(0!==t.exitCode||0!==n.exitCode)return;let r=tS(t.stdout,e.width,e.height),i=tS(n.stdout,e.width,e.height),a=function(e,t){let n=new Set,r=[];for(let a of e){var i;let e=tC(a.text),o=function(e,t,n,r){let i=null,a=1/0;for(let o=0;o<n.length;o+=1){if(r.has(o))continue;let s=n[o];if(tC(s.text)!==t)continue;let l=m(f(e.normalizedRect),f(s.normalizedRect));l>=a||(i=o,a=l)}return i}(a,e,t,n);if(null===o)continue;n.add(o);let s=function(e,t){let n={x:t.rect.x-e.rect.x,y:t.rect.y-e.rect.y,width:t.rect.width-e.rect.width,height:t.rect.height-e.rect.height},r=tB(t.rect.width/e.rect.width),i=tB(t.rect.height/e.rect.height),a=Math.abs(r-1)>=.08||Math.abs(i-1)>=.12;return{text:e.text,baselineRect:e.rect,currentRect:t.rect,delta:n,confidence:Math.round(100*Math.min(e.confidence,t.confidence))/100,possibleTextMetricMismatch:a}}(a,t[o]);i=s,(Math.abs(i.delta.x)>=2||Math.abs(i.delta.y)>=2||Math.abs(i.delta.width)>=2||Math.abs(i.delta.height)>=2||i.possibleTextMetricMismatch)&&r.push(s)}return r.sort((e,t)=>tD(t)-tD(e)).slice(0,12)}(r,i),o=function(e){let t=[];for(let n of[...e].sort((e,t)=>e.currentRect.y-t.currentRect.y)){let e=t.find(e=>32>=Math.abs(n.delta.x-tL(e.map(e=>e.delta.x))));e?e.push(n):t.push([n])}return t.filter(e=>e.length>=2).map(tE).filter(e=>e.yRange.max-e.yRange.min<=60).sort((e,t)=>t_(t)-t_(e)).slice(0,4)}(a);if(0===r.length&&0===i.length)return;return{provider:"tesseract",baselineBlocks:r.length,currentBlocks:i.length,baselineBlocksRaw:r,currentBlocksRaw:i,matches:a,...o.length>0?{movementClusters:o}:{}}}catch{return}}function tS(e,t,n){let[r,...i]=e.split(/\r?\n/);if(!r)return[];let a=new Map(r.split(" ").map((e,t)=>[e,t])),o=[];for(let e of i){var s;if(!e.trim())continue;let t=e.split(" "),n=t$(t,a,"level"),r=tT(t,a,"text").trim(),i=t$(t,a,"conf");if(5!==n||(s=r,!/[\p{L}\p{N}]/u.test(s))||i<0)continue;let l=t$(t,a,"left"),d=t$(t,a,"top"),c=t$(t,a,"width"),u=t$(t,a,"height");c<=0||u<=0||o.push({key:[tT(t,a,"page_num"),tT(t,a,"block_num"),tT(t,a,"par_num"),tT(t,a,"line_num")].join(":"),text:r,confidence:i,rect:{x:l,y:d,width:c,height:u}})}let l=new Map;for(let e of o){let t=l.get(e.key);t?t.push(e):l.set(e.key,[e])}return Array.from(l.values()).flatMap(e=>(function(e){let t=[...e].sort((e,t)=>e.rect.x-t.rect.x),n=[],r=[];for(let e of t){let t=r.at(-1);if(!t){r.push(e);continue}if(e.rect.x-(t.rect.x+t.rect.width)>Math.max(48,2.5*Math.max(t.rect.height,e.rect.height))){n.push(r),r=[e];continue}r.push(e)}return r.length>0&&n.push(r),n})(e)).map(e=>(function(e,t,n){if(0===e.length)return null;let r=[...e].sort((e,t)=>e.rect.x-t.rect.x),i=p(r.map(e=>e.rect)),a=Math.round(100*tL(r.map(e=>e.confidence)))/100;return{text:r.map(e=>e.text).join(" "),confidence:a,rect:i,normalizedRect:{x:tU(i.x/t),y:tU(i.y/n),width:tU(i.width/t),height:tU(i.height/n)}}})(e,t,n)).filter(e=>null!==e)}function tO(e){return y("tesseract",[e,"stdout","-l","eng","tsv"],{allowFailure:!0,timeoutMs:1e4})}function tD(e){return Math.abs(e.delta.x)+Math.abs(e.delta.y)+Math.abs(e.delta.width)+Math.abs(e.delta.height)+25*!!e.possibleTextMetricMismatch}function tE(e){let t=e.map(e=>e.delta.x),n=e.map(e=>e.delta.y);return{texts:e.map(e=>e.text),xRange:{min:Math.min(...t),max:Math.max(...t)},yRange:{min:Math.min(...n),max:Math.max(...n)}}}function t_(e){return 2*Math.abs((e.xRange.min+e.xRange.max)/2)+Math.abs((e.yRange.min+e.yRange.max)/2)}function tT(e,t,n){let r=t.get(n);return void 0===r?"":e[r]??""}function t$(e,t,n){let r=Number(tT(e,t,n));return Number.isFinite(r)?r:0}function tC(e){return e.trim().replace(/\s+/g," ").toLowerCase()}function tL(e){return e.reduce((e,t)=>e+t,0)/e.length}function tU(e){return Math.round(100*e*100)/100}function tB(e){return Math.round(1e3*e)/1e3}function tG(e,t,n,r){return{r:Math.round(e/r),g:Math.round(t/r),b:Math.round(n/r)}}function tF(e){return .2126*e.r+.7152*e.g+.0722*e.b}function tq(e){return`#${tX(e.r)}${tX(e.g)}${tX(e.b)}`}function tX(e){return e.toString(16).padStart(2,"0")}function tY(e){return Math.round(100*e*100)/100}let tV=255*Math.sqrt(3);async function tH(t,n,i={}){var a,o,s,l,d;let h,p,f,m;await tz(t,"Baseline image not found"),await tz(n,"Current screenshot not found");let b=i.outputPath,[g,y]=await Promise.all([e.readFile(t),e.readFile(n)]),x=to(g,"baseline screenshot"),v=to(y,"current screenshot");tK(x.width,x.height,"baseline screenshot",i.maxPixels),tK(v.width,v.height,"current screenshot",i.maxPixels);let k=i.threshold??.1;if(x.width!==v.width||x.height!==v.height){let e=x.width*x.height;return await tj(i.outputPath),{match:!1,mismatchPercentage:100,totalPixels:e,differentPixels:e,dimensionMismatch:{expected:{width:x.width,height:x.height},actual:{width:v.width,height:v.height}}}}let I=x.width*x.height,N=k*tV,A=new e4({width:x.width,height:x.height}),M=new Uint8Array(I),R=0;for(let e=0,t=0;e<x.data.length;e+=4,t+=1){if(Math.sqrt((x.data[e]-v.data[e])**2+(x.data[e+1]-v.data[e+1])**2+(x.data[e+2]-v.data[e+2])**2)>N){R+=1,M[t]=1;let n=tW(v,e);A.data[e]=tJ(n,220,.78),A.data[e+1]=tJ(n,0,.78),A.data[e+2]=tJ(n,0,.78),A.data[e+3]=255;continue}let n=tW(v,e);A.data[e]=n,A.data[e+1]=n,A.data[e+2]=n,A.data[e+3]=255}let P=R>0?(o=(h=function(e){let{diffMask:t,baseline:n,current:r}=e,{width:i,height:a}=n;return tm({mask:t,width:i,height:a,hooks:{create:e=>{var t,n;let r,a;return r=(t=e)%(n=i),{minX:r,minY:a=Math.floor(t/n),maxX:r,maxY:a,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0}},visit:(e,t)=>{var a,o,s,l,d;let c,u,h;return a=e,o=t,s=i,l=n,d=r,c=o%s,u=Math.floor(o/s),h=4*o,void(a.minX=Math.min(a.minX,c),a.minY=Math.min(a.minY,u),a.maxX=Math.max(a.maxX,c),a.maxY=Math.max(a.maxY,u),a.differentPixels+=1,a.baselineRed+=l.data[h],a.baselineGreen+=l.data[h+1],a.baselineBlue+=l.data[h+2],a.currentRed+=d.data[h],a.currentGreen+=d.data[h+1],a.currentBlue+=d.data[h+2])}}})}(a={diffMask:M,baseline:x,current:v,totalPixels:I,differentPixels:R,maxRegions:i.maxRegions})).length<=2e3?function(e){let t=[];for(let i of e.sort((e,t)=>{let n=e.minY-t.minY;return 0!==n?n:e.minX-t.minX})){var n,r;let e=t.find(e=>{var t,n,r;return t=e,n=i,r=12,t.minX-r<=n.maxX&&n.minX-r<=t.maxX&&t.minY-r<=n.maxY&&n.minY-r<=t.maxY});if(!e){t.push({...i});continue}n=e,r=i,n.minX=Math.min(n.minX,r.minX),n.minY=Math.min(n.minY,r.minY),n.maxX=Math.max(n.maxX,r.maxX),n.maxY=Math.max(n.maxY,r.maxY),n.differentPixels+=r.differentPixels,n.baselineRed+=r.baselineRed,n.baselineGreen+=r.baselineGreen,n.baselineBlue+=r.baselineBlue,n.currentRed+=r.currentRed,n.currentGreen+=r.currentGreen,n.currentBlue+=r.currentBlue}return t}(h):h,o.flatMap(e=>{var t,n,r;let i;return(t=e,n=a.baseline.width,r=a.baseline.height,i=t.maxX-t.minX+1,t.maxY-t.minY+1>=Math.max(48,Math.round(.07*r))&&i>=.35*n)?function(e,t,n){var r;let i=function(e,t){let n=[],r=null;for(let i=0;i<e.length;i+=1){if(e[i]<=t){r??=i;continue}null!==r&&(i-r>=6&&n.push([r,i-1]),r=null)}return null!==r&&e.length-r>=6&&n.push([r,e.length-1]),n}((r=function(e,t,n){let r=[];for(let i=e.minY;i<=e.maxY;i+=1){let a=0;for(let r=e.minX;r<=e.maxX;r+=1)1===t[i*n+r]&&(a+=1);r.push(a)}return r}(e,t.diffMask,t.baseline.width)).map((e,t)=>{let n=0,i=0,a=Math.max(0,t-3),o=Math.min(r.length-1,t+3);for(let e=a;e<=o;e+=1)n+=r[e],i+=1;return Math.round(n/i)}),Math.max(1,Math.round((e.maxX-e.minX+1)*.08))),a=function(e,t,n){let r=[],i=e.minY;for(let[a,o]of t){let t=e.minY+Math.round((a+o)/2);t-i+1<n||e.maxY-t<n||(r.push([i,t]),i=t+1)}return r.push([i,e.maxY]),r}(e,i,n);if(a.length<=1)return[e];let o=a.map(([n,r])=>(function(e,t,n,r){let i=null;for(let s=t;s<=n;s+=1)for(let t=e.minX;t<=e.maxX;t+=1){var a,o;let e=s*r.baseline.width+t;1===r.diffMask[e]&&function(e,t,n,r,i,a){let o=4*t;e.minX=Math.min(e.minX,n),e.minY=Math.min(e.minY,r),e.maxX=Math.max(e.maxX,n),e.maxY=Math.max(e.maxY,r),e.differentPixels+=1,e.baselineRed+=i.data[o],e.baselineGreen+=i.data[o+1],e.baselineBlue+=i.data[o+2],e.currentRed+=a.data[o],e.currentGreen+=a.data[o+1],e.currentBlue+=a.data[o+2]}(i??={minX:a=t,minY:o=s,maxX:a,maxY:o,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0},e,t,s,r.baseline,r.current)}return i})(e,n,r,t)).filter(e=>null!==e);return o.length>1?o:[e]}(e,a,Math.max(24,Math.round(.03*a.baseline.height))):[e]})).sort((e,t)=>{let n=t.differentPixels-e.differentPixels;if(0!==n)return n;let r=e.minY-t.minY;return 0!==r?r:e.minX-t.minX}).slice(0,Math.max(0,a.maxRegions??8)).map((e,t)=>{var n,r,i,o,s,l,d,c,u,h,p;let f,w,m,b,g,y,x,v,k,I,N,A,M,R,P,S,O;return n=e,r=t+1,i={width:a.baseline.width,height:a.baseline.height,totalPixels:a.totalPixels,differentPixels:a.differentPixels},y={x:n.minX,y:n.minY,width:n.maxX-n.minX+1,height:n.maxY-n.minY+1},x={x:Math.round(n.minX+y.width/2),y:Math.round(n.minY+y.height/2)},v=tG(n.baselineRed,n.baselineGreen,n.baselineBlue,n.differentPixels),k=tG(n.currentRed,n.currentGreen,n.currentBlue,n.differentPixels),I=y.width*y.height,N=tY(n.differentPixels/I),A=Math.round(tF(v)),M=Math.round(tF(k)),R=(o=y,s=i.width,l=i.height,o.width>=.55*s&&o.height>=.12*l?"large-area":o.width>=2.5*o.height?"horizontal-band":o.height>=2.5*o.width?"vertical-band":"compact"),P=(f=I/i.totalPixels)>=.04?"large":f>=.01?"medium":"small",S=(d=v,c=k,w=tF(d),Math.abs(m=tF(c)-w)>=12?m>0?"brighter":"darker":Math.max(Math.abs(c.r-d.r),Math.abs(c.g-d.g),Math.abs(c.b-d.b))>=12?"color-shift":"mixed"),O=(u=x,h=i.width,p=i.height,b=u.x<h/3?"left":u.x>2*h/3?"right":"center",g=u.y<p/3?"top":u.y>2*p/3?"bottom":"middle","center"===b&&"middle"===g?"center":`${g}-${b}`),{index:r,rect:y,normalizedRect:{x:tY(y.x/i.width),y:tY(y.y/i.height),width:tY(y.width/i.width),height:tY(y.height/i.height)},differentPixels:n.differentPixels,shareOfDiffPercentage:tY(n.differentPixels/i.differentPixels),densityPercentage:N,shape:R,size:P,location:O,averageBaselineColorHex:tq(v),averageCurrentColorHex:tq(k),baselineLuminance:A,currentLuminance:M,dominantChange:S}}):[];if(R>0&&b){for(let e of P)e.rect.width<4||e.rect.height<4||function(e,t){let n=tf(t.x,0,e.width-1),r=tf(t.y,0,e.height-1),i=tf(t.x+t.width-1,0,e.width-1),a=tf(t.y+t.height-1,0,e.height-1);for(let t=0;t<2;t+=1){for(let o=n;o<=i;o+=1)tp(e,o,r+t,th),tp(e,o,a-t,th);for(let o=r;o<=a;o+=1)tp(e,n+t,o,th),tp(e,i-t,o,th)}}(A,e.rect);await e.mkdir(r.dirname(b),{recursive:!0}),await e.writeFile(b,e4.sync.write(A))}else await tj(i.outputPath);let S=R>0?await tP({baselinePath:t,currentPath:n,width:x.width,height:x.height}):void 0,O=S&&(S.matches.length>0||(S.movementClusters?.length??0)>0)?{provider:S.provider,baselineBlocks:S.baselineBlocks,currentBlocks:S.currentBlocks,matches:S.matches,...S.movementClusters?{movementClusters:S.movementClusters}:{}}:void 0,D=R>0&&S?(p=function(e){let t=[];for(let n of e.sort((e,t)=>e.minY-t.minY||e.minX-t.minX)){let e=t.find(e=>{var t,r,i;return t=e,r=n,i=10,t.minX-i<=r.maxX&&r.minX-i<=t.maxX&&t.minY-i<=r.maxY&&r.minY-i<=t.maxY});if(!e){t.push({...n});continue}e.minX=Math.min(e.minX,n.minX),e.minY=Math.min(e.minY,n.minY),e.maxX=Math.max(e.maxX,n.maxX),e.maxY=Math.max(e.maxY,n.maxY),e.differentPixels+=n.differentPixels}return t}((l=function(e,t,n,r){let i=new Uint8Array(e);if(!r)return i;for(let e of[...r.baselineBlocksRaw,...r.currentBlocksRaw])!function(e,t,n,r){let i=w(Math.floor(r.x),0,t-1),a=w(Math.floor(r.y),0,n-1),o=w(Math.ceil(r.x+r.width),0,t),s=w(Math.ceil(r.y+r.height),0,n);for(let n=a;n<s;n+=1)for(let r=i;r<o;r+=1)e[n*t+r]=0}(i,t,n,c(e.rect,8));return i}((s={diffMask:M,width:x.width,height:x.height,regions:P,ocr:S}).diffMask,s.width,s.height,s.ocr),d=s.width,tm({mask:l,width:d,height:s.height,hooks:{create:e=>{var t,n;let r,i;return r=(t=e)%(n=d),{minX:r,minY:i=Math.floor(t/n),maxX:r,maxY:i,differentPixels:0}},visit:(e,t)=>{var n,r,i;let a,o;return n=e,a=(r=t)%(i=d),o=Math.floor(r/i),void(n.minX=Math.min(n.minX,a),n.minY=Math.min(n.minY,o),n.maxX=Math.max(n.maxX,a),n.maxY=Math.max(n.maxY,o),n.differentPixels+=1)}}}))),f=tI(s.ocr?.currentBlocksRaw??[]),m=tI(s.ocr?.baselineBlocksRaw??[]),p.filter(tA).map(e=>{var t,n,r,i,a,o,l,d,c,h,p;let w,b,g,y,x,v,k,I,N,A;return t=e,n=s,r=f,i=m,y=function(e,t){let n,r=0;for(let i of t){let t=u(e,i.rect);t<=r||(r=t,n=i)}return n?.index}(g=tM(t),n.regions),x=function(e,t,n){let r=tk(e,t);if(r)return tN(e,r.blocks);let i=tk(e,n);return i?tN(e,i.blocks):void 0}(g,r,i),v=function(e,t,n){if(e.height<=3&&e.width>=.12*n)return"separator";if(!t)return e.width>=.4*n?"background":"unknown";if(e.width>=.4*n)return"background";let r=e.x+e.width/2,i=t.x+t.width/2;return r<i-t.width/2?"leading":r>i+t.width/2?"trailing":e.width>=.35*n?"background":"unknown"}(g,x?.block.rect,n.width),k=(a=g,o=v,l=t.differentPixels,d=n,w=a.width/a.height,b=l/(a.width*a.height),"separator"===o?"separator":"background"===o?"background":"trailing"===o&&w>=1.5&&w<=3.8&&b>=.35?"toggle":"trailing"===o&&a.width<=.06*d.width&&a.height<=.04*d.height?"chevron":"leading"===o&&w>=.55&&w<=1.8?"icon":tv(a,d)?"background":"visual"),I={...y?{regionIndex:y}:{},slot:v,likelyKind:k,rect:g},{...y?{regionIndex:y}:{},slot:v,likelyKind:k,rect:g,...x?{nearestText:x.block.text.trim().replace(/^[^\p{L}\p{N}]+/u,"").replace(/^\p{L}\s+/u,"")}:{},score:(c=I,h=t.differentPixels,p=n,N=tv(c.rect,p)?-35:0,A=20*!!c.regionIndex,tg[c.likelyKind]+ty[c.slot]+A+N+Math.min(20,h/200))}}).filter(e=>e.rect.y>=.08*s.height).filter(tx).sort((e,t)=>t.score-e.score).slice(0,Math.max(0,s.maxDeltas??12)).map((e,t)=>{var n;return n=e,{index:t+1,...n.regionIndex?{regionIndex:n.regionIndex}:{},slot:n.slot,likelyKind:n.likelyKind,rect:n.rect,...n.nearestText?{nearestText:n.nearestText}:{}}})):[],E=I>0?Math.round(R/I*1e4)/100:0;return{...R>0&&b?{diffPath:b}:{},...P.length>0?{regions:P}:{},...O?{ocr:O}:{},...D.length>0?{nonTextDeltas:D}:{},totalPixels:I,differentPixels:R,mismatchPercentage:E,match:0===R}}async function tz(t,n){try{await e.access(t)}catch{throw new a("INVALID_ARGS",`${n}: ${t}`)}}function tK(e,t,n,r){if(null==r||r<=0)return;let i=e*t;if(!(i<=r))throw new a("INVALID_ARGS",`${n} is ${i} pixels, which exceeds the configured maxImagePixels limit of ${r}`)}async function tj(t){if(t)try{await e.unlink(t)}catch(e){var n;if(!("object"==typeof(n=e)&&null!==n&&"code"in n&&"ENOENT"===n.code))throw e}}function tW(e,t){return tJ(Math.round(.299*e.data[t]+.587*e.data[t+1]+.114*e.data[t+2]),255,.72)}function tJ(e,t,n){return Math.round(e*(1-n)+t*n)}function tZ(e){return e.width*e.height}function tQ(e){return Math.round(100*e*100)/100}async function t0(e,t){let n=await tc(e,{prefix:"agent-device-diff-current",ext:".png"});try{await t2(e,t,n.path,t5(t))}catch(e){throw await n.cleanup(),e}return n}async function t1(e,t,n,r,i){var a,o,s,l;if(!t.overlayRefs)return r;if(r.match||r.dimensionMismatch)return n&&await t8(n),r;let d=(a=t,o=n,a.currentOverlayOut?a.currentOverlayOut:a.out?.kind==="path"?{kind:"path",path:t4(o??a.out.path)}:a.out?.kind==="downloadableArtifact"?{kind:"downloadableArtifact",...a.out.clientPath?{clientPath:t4(a.out.clientPath)}:{},...a.out.fileName?{fileName:t4(a.out.fileName)}:{}}:void 0),c=await td(e,d,{field:"currentOverlayPath",ext:".png"});try{let n=await t2(e,t,c.path,{overlayRefs:!0,...t5(t)}),a=await c.publish();return a&&i.push(a),{...r,currentOverlayPath:n.path??c.path,...n.overlayRefs?{currentOverlayRefCount:n.overlayRefs.length}:{},...r.regions&&n.overlayRefs?{regions:(s=r.regions,l=n.overlayRefs,s.map(e=>{var t,n;let r,i=(t=e,n=l,r=tZ(t.rect),n.map(e=>{let n=e.overlayRect,i=u(t.rect,n);return i<=0?null:{ref:e.ref,...e.label?{label:e.label}:{},rect:n,overlayCoveragePercentage:tQ(i/tZ(n)),regionCoveragePercentage:tQ(i/r)}}).filter(e=>null!==e).sort((e,t)=>{let n=t.regionCoveragePercentage-e.regionCoveragePercentage;return 0!==n?n:t.overlayCoveragePercentage-e.overlayCoveragePercentage}).slice(0,3).map(e=>({ref:e.ref,...e.label?{label:e.label}:{},rect:e.rect,regionCoveragePercentage:e.regionCoveragePercentage})));return i.length>0?{...e,currentOverlayMatches:i}:e}))}:{}}}catch(e){throw await c.cleanup?.(),e}}async function t2(e,t,n,r={}){if(!e.backend.captureScreenshot)throw new a("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");return await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata},n,r)??{}}function t5(e){return e.surface?{surface:e.surface}:{}}function t4(e){let t=r.extname(e),n=t?e.slice(0,-t.length):e;return`${n}.current-overlay${t||".png"}`}async function t8(t){try{await e.unlink(t4(t))}catch(e){var n;if(!("object"==typeof(n=e)&&null!==n&&"code"in n&&"ENOENT"===n.code))throw e}}function t3(e){return"live"===e.kind}let t6={application:"application",navigationbar:"navigation-bar",tabbar:"tab-bar",button:"button",imagebutton:"button",link:"link",cell:"cell",statictext:"text",checkedtextview:"text",textfield:"text-field",edittext:"text-field",textarea:"text-view",switch:"switch",slider:"slider",image:"image",imageview:"image",webview:"webview",framelayout:"group",linearlayout:"group",relativelayout:"group",constraintlayout:"group",viewgroup:"group",view:"group",listview:"list",recyclerview:"list",collectionview:"collection",searchfield:"search",segmentedcontrol:"segmented-control",group:"group",window:"window",checkbox:"checkbox",radio:"radio",menuitem:"menu-item",toolbar:"toolbar",scrollarea:"scroll-area",scrollview:"scroll-area",nestedscrollview:"scroll-area",table:"table"};function t9(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||"",o=nt(i.type??"Element");if("group"===o&&!a)continue;for(;n.length>0&&e<=n[n.length-1];)n.pop();let s=n.length;n.push(e),r.push({node:i,depth:s,type:o,text:t7(i,s,!1,o,t)})}return r}function t7(e,t,n,r,i={}){var a,o,s,l,d,c,u,h;let p,f=r??nt(e.type??"Element"),w=T(e,f),m=(a=e,o=f,s=i,l=w,s.summarizeTextSurfaces&&l.shouldSummarize&&function(e,t,n){let r=x(e.label);if(r&&r!==n)return r;let i=x(e.identifier);if(i&&!nr(i)&&i!==n)return i;switch(t){case"text":case"text-view":return"Text view";case"text-field":return"Text field";case"search":return"Search field";default:return""}}(a,o,l.text)||ne(a,o)),b=" ".repeat(t),g=e.ref?`@${e.ref}`:"",y=(d=e,c=f,u=i,h=w,p=[],(!1===d.enabled&&p.push("disabled"),u.summarizeTextSurfaces)?(!0===d.selected&&p.push("selected"),!0===d.focused&&p.push("focused"),nn(c)&&p.push("editable"),function(e,t){if("scroll-area"===t)return!0;let n=(e.type??"").toLowerCase(),r=`${e.role??""} ${e.subrole??""}`.toLowerCase();return n.includes("scroll")||r.includes("scroll")}(d,c)&&p.push("scrollable"),p.push(...d.presentationHints??[]),h.shouldSummarize&&(p.push(`preview:"${R(h.text).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`),p.push("truncated")),ni(p)):p).map(e=>` [${e}]`).join(""),v=m?` "${m}"`:"";return n?`${b}${g} [${f}]${y}`.trimEnd():`${b}${g} [${f}]${v}${y}`.trimEnd()}function ne(e,t){var n,r;let i=e.label?.trim();if(i&&(n=t,r=i,("scroll-area"===n||"list"===n||"collection"===n||"table"===n)&&ea(r)))return"";let a=e.value?.trim();if(nn(t)){if(a)return a;if(i)return i}else if(i)return i;if(a)return a;let o=e.identifier?.trim();return!o||nr(o)&&("group"===t||"image"===t||"list"===t||"collection"===t)?"":o}function nt(e){var t;let n=e.replace(/XCUIElementType/gi,"").toLowerCase(),r=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));return(n.includes(".")&&(n=n.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,""),r&&n.includes(".")&&(n=n.slice(n.lastIndexOf(".")+1))),"textview"===n)?r?"text":"text-view":(t=n,(Object.prototype.hasOwnProperty.call(t6,t)?t6[t]:void 0)||n||"element")}function nn(e){return"text-field"===e||"text-view"===e||"search"===e}function nr(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function ni(e){return[...new Set(e)]}function na(e,t){let n=nt(e.type??"Element"),r=ne(e,n),i=!1===e.enabled?"disabled":"enabled",a=!0===e.selected?"selected":"unselected",o=!0===e.hittable?"hittable":"not-hittable";return[String(t??e.depth??0),n,r,i,a,o].join("|")}function no(e,t){return t.flatten?e.map(e=>({text:t7(e,0,!1),comparable:na(e,0)})):t9(e).map(e=>({text:e.text,comparable:na(e.node,e.depth)}))}function ns(e,t){return e.get(t)??0}function nl(e){return e.map(e=>({index:e.index,depth:e.depth,parentIndex:e.parentIndex,type:e.type,role:e.role,subrole:e.subrole,label:e.label,value:e.value,identifier:e.identifier,enabled:e.enabled,selected:e.selected,focused:e.focused,hittable:e.hittable,rect:e.rect,bundleId:e.bundleId,appName:e.appName,windowTitle:e.windowTitle,surface:e.surface,hiddenContentAbove:e.hiddenContentAbove,hiddenContentBelow:e.hiddenContentBelow}))}function nd(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function nc(e){return e.clock?.now()??Date.now()}async function nu(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}async function nh(e,t){var n,r,i,o,s,d;let c,u,h,p;if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let f=t.session??"default",w=await e.sessions.get(f),m=await e.backend.captureSnapshot({session:f,requestId:t.requestId,appId:w?.appId,appBundleId:w?.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},{interactiveOnly:t.interactiveOnly,compact:t.compact,depth:t.depth,scope:t.scope,raw:t.raw}),b=(r=m,i=e,n=r.snapshot?r.snapshot:{nodes:r.nodes??[],truncated:r.truncated,backend:r.backend,createdAt:nc(i)},n.presentationKey?n:{...n,presentationKey:l(t)}),g=nc(e);return{snapshot:b,result:m,session:w,warnings:((c=[...(o={result:m,snapshot:b,options:t,session:w,capturedAt:b.createdAt??g,runtimeNow:g}).result.warnings??[]]).push(...function(e){let t=e.result.analysis;if("android"!==e.snapshot.backend||!0!==e.options.interactiveOnly||e.snapshot.nodes.length>0||!t||(t.rawNodeCount??0)<12)return[];let n=[`Interactive snapshot is empty after filtering ${t.rawNodeCount} raw Android nodes. Likely causes: the app content is not accessibility-visible yet, a transient route change, or depth/filter options hid the target.`];return"number"==typeof e.options.depth&&"number"==typeof t.maxDepth&&t.maxDepth>=e.options.depth+2&&n.push(`Interactive output is empty at depth ${e.options.depth}; retry without -d.`),n}(o)),(u=function(e){if(e?.backend!=="uiautomator-dump")return;let t=e.fallbackReason?` Reason: ${e.fallbackReason}`:"";return`Android snapshot helper unavailable; using stock UIAutomator dump, which can time out on busy React Native UIs.${t}`}(o.result.androidSnapshot))&&c.push(u),(h=function(e){if(e$(e).detected)return"Hint: React Native warning/error overlay detected. It overlays part of the app and should be handled before interacting.\nRun: agent-device react-native dismiss-overlay\nThe command verifies the overlay is gone. Run agent-device snapshot -i -c afterward only when you need fresh refs for the next action."}(o.snapshot.nodes))&&c.push(h),(p=function(e){var t,n;let r=e.session?.snapshot,i=!!r&&[e.capturedAt,e.runtimeNow].some(e=>{let t=e-r.createdAt;return t>=0&&t<=2e3});if(!e.result.freshness&&r&&i&&(t=r.nodes.length,n=e.snapshot.nodes.length,!(t<12)&&n<=Math.floor(.2*t)))return nf}(o))&&c.push(p),c.push(...(s=o.result.freshness,d=o.snapshot.backend,s?.staleAfterRetries&&"android"===d?"stuck-route"===s.reason?[`Recent ${s.action} was followed by a nearly identical snapshot after ${s.retryCount} automatic retr${1===s.retryCount?"y":"ies"}. If you expected navigation or submit, the tree may still be stale. Use screenshot as visual truth, wait briefly, then re-snapshot once.`]:"sharp-drop"===s.reason?[nf]:[]:[])),Array.from(new Set(c)))}}function np(e,t){let n=t.session?.name??e??"default";return{...t.session??{name:n},name:n,snapshot:t.snapshot,appName:t.result.appName??t.session?.appName,appBundleId:t.result.appBundleId??t.session?.appBundleId}}let nf="Recent snapshots dropped sharply in node count, which suggests stale or mid-transition UI. Use screenshot as visual truth, wait briefly, then re-snapshot once.";function nw(e){return["visible","hidden","exists","editable","selected","text"].includes(e)}function nm(e){let{predicate:t,node:n,nodes:r,expectedText:i,platform:a}=e,o=v(n),s=M(n,a),l=!0===n.selected,d="text"===t?N(n):function(e,t,n){var r,i,a;let o;if("android"===n&&!1===e.visibleToUser)return!1;if(nb(e.rect))return function(e,t){return ep(e,t)}(e,t);if(e.rect)return!1;if("android"!==n&&!0===e.hittable)return!0;let s=(r=e,i=t,a=n,o=A(i),k(i,r,o,e=>!function(e,t){if("android"===t&&!1===e.visibleToUser)return!1;let n=L(e.type??"");return!(n.includes("application")||n.includes("window")||n.includes("scrollview")||n.includes("tableview")||n.includes("collectionview"))&&"table"!==n&&"list"!==n&&"listview"!==n&&("android"===t?!0===e.hittable&&nb(e.rect):!0===e.hittable||nb(e.rect))}(e,a)?null:e));return!!s&&(nb(s.rect)?function(e,t){return ep(e,t)}(s,t):"android"!==n&&!0===s.hittable)}(n,r,a),c=!1;switch(t){case"visible":c=d;break;case"hidden":c=!d;break;case"editable":c=s;break;case"selected":c=l;break;case"text":c=o===(i??"")}let u="text"===t?`expected="${i??""}" actual="${o}"`:`actual=${JSON.stringify({visible:d,editable:s,selected:l})}`;return{pass:c,actualText:o,details:u}}function nb(e){return!!(e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0)}async function ng(e,t){let n=t??"default",r=await e.sessions.get(n);if(!r)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");if(!r.snapshot)throw new a("INVALID_ARGS","No snapshot in session. Run snapshot first.");return{sessionName:n,session:r,snapshot:r.snapshot}}async function ny(e,t,n={updateSession:!0}){let r=e.backend.captureSnapshot;if(!r)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let i=t.session??"default",o=await e.sessions.get(i),s=await r(nd(e,t),{interactiveOnly:!1,compact:!1,depth:t.depth,scope:n.scope??t.scope,raw:t.raw}),l=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,createdAt:nc(e)};return n.updateSession&&o&&await e.sessions.set({...o,snapshot:l}),{sessionName:i,session:o,snapshot:l}}async function nx(e,t,n){if(e.backend.readText){let r=await e.backend.readText(nd(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return $(n)}let nv=async(e,t)=>{if("ref"===t.target.kind){let n=await ng(e,t.session),r=function(e,t,n){let r=o(t);if(!r)throw new a("INVALID_ARGS",n.invalidRefMessage);let i=d(e,r)??(n.fallbackLabel.length>0?E(e,n.fallbackLabel):null);if(!i)throw new a("COMMAND_FAILED",n.notFoundMessage);return{ref:r,node:i}}(n.snapshot.nodes,t.target.ref,{fallbackLabel:t.target.fallbackLabel??"",invalidRefMessage:"get text requires a ref like @e2",notFoundMessage:`Ref ${t.target.ref} not found`}),i=S(r.node,e.backend.platform,{action:"get"}),s={kind:"ref",ref:`@${r.ref}`};return"attrs"===t.property?{kind:"attrs",target:s,node:r.node,selectorChain:i}:{kind:"text",target:s,text:await nx(e,n,r.node),node:r.node,selectorChain:i}}let n=await nT(e,t,t.session??"default",{selector:t.target.selector,disambiguateAmbiguous:"text"===t.property}),r=S(n.node,e.backend.platform,{action:"get"});if("attrs"===t.property)return{kind:"attrs",target:{kind:"selector",selector:n.selector},node:n.node,selectorChain:r};let i=await nx(e,n.capture,n.node);return{kind:"text",target:{kind:"selector",selector:n.selector},text:i,node:n.node,selectorChain:r}},nk=async(e,t)=>{let n=await nv(e,{...t,property:"text",target:t.target});if("text"!==n.kind)throw new a("COMMAND_FAILED","getText returned non-text result");return n},nI=async(e,t)=>{let n=await nv(e,{...t,property:"attrs",target:t.target});if("attrs"!==n.kind)throw new a("COMMAND_FAILED","getAttrs returned non-attrs result");return n},nN=async(e,t)=>{if(!nw(t.predicate))throw new a("INVALID_ARGS","is requires predicate: visible|hidden|exists|editable|selected|text");if("text"===t.predicate&&!t.expectedText)throw new a("INVALID_ARGS","is text requires expected text value");let n=await ny(e,t,{updateSession:!0}),r=I(t.selector);if("exists"===t.predicate){let i=O(n.snapshot.nodes,r,{platform:e.backend.platform});if(!i)throw new a("COMMAND_FAILED",C(r,[],{unique:!1}));return{predicate:t.predicate,pass:!0,selector:i.selector.raw,matches:i.matches,selectorChain:r.selectors.map(e=>e.raw)}}let i=D(n.snapshot.nodes,r,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:!1});if(!i)throw new a("COMMAND_FAILED",C(r,[],{unique:!0}),{command:"is",reason:"selector_not_found",predicate:t.predicate,selector:r.raw});let o=nm({predicate:t.predicate,node:i.node,nodes:n.snapshot.nodes,expectedText:t.expectedText,platform:e.backend.platform});if(!o.pass)throw new a("COMMAND_FAILED",`is ${t.predicate} failed for selector ${i.selector.raw}: ${o.details}`,{command:"is",reason:"predicate_failed",predicate:t.predicate,selector:i.selector.raw,predicateDetails:o.details});return{predicate:t.predicate,pass:!0,selector:i.selector.raw,..."text"===t.predicate?{text:o.actualText}:{},selectorChain:r.selectors.map(e=>e.raw)}},nA=async(e,t)=>await nN(e,{...t,predicate:"visible",selector:t.target.selector}),nM=async(e,t)=>await nN(e,{...t,predicate:"hidden",selector:t.target.selector}),nR=async(e,t)=>{if("sleep"===t.target.kind)return await nu(e,t.target.durationMs),{kind:"sleep",waitedMs:t.target.durationMs};if("ref"===t.target.kind){let n=await ng(e,t.session),r=o(t.target.ref);if(!r)throw new a("INVALID_ARGS",`Invalid ref: ${t.target.ref}`);let i=d(n.snapshot.nodes,r),s=i?_(i,n.snapshot.nodes):void 0;if(!s)throw new a("COMMAND_FAILED",`Ref ${t.target.ref} not found or has no label`);return await nE(e,t,s,t.target.timeoutMs)}if("selector"===t.target.kind)return await nD(e,t,t.target.selector,t.target.timeoutMs);if(!t.target.text)throw new a("INVALID_ARGS","wait requires text");return await nE(e,t,t.target.text,t.target.timeoutMs)},nP=async(e,t)=>{let n=await nR(e,{...t,target:{kind:"text",text:t.text,timeoutMs:t.timeoutMs}});if("text"!==n.kind)throw new a("COMMAND_FAILED","waitForText returned non-text result");return n};async function nS(e,t,n){let r=t.timeoutMs??1e4,i=nc(e);for(;nc(e)-i<r;){let{match:r}=await nO(e,t,n);if(r)return{kind:"found",found:!0,waitedMs:nc(e)-i};await nu(e,300)}throw new a("COMMAND_FAILED","find wait timed out")}async function nO(e,t,n){let r=await ny(e,t,{updateSession:!0,scope:"text"===n||"label"===n||"any"===n?t.query:void 0}),i=B(r.snapshot.nodes,n,t.query,{requireRect:!1}).matches[0];return{capture:r,match:i}}async function nD(e,t,n,r){let i=r??1e4,o=nc(e),s=I(n);for(;nc(e)-o<i;){let n=O((await ny(e,t,{updateSession:!0})).snapshot.nodes,s,{platform:e.backend.platform});if(n)return{kind:"selector",selector:n.selector.raw,waitedMs:nc(e)-o};await nu(e,300)}throw new a("COMMAND_FAILED",`wait timed out for selector: ${n}`)}async function nE(e,t,n,r){let i=r??1e4,o=nc(e);for(;nc(e)-o<i;){if(e.backend.findText?(await e.backend.findText(nd(e,t),n)).found:await n_(e,t,n))return{kind:"text",text:n,waitedMs:nc(e)-o};await nu(e,300)}throw new a("COMMAND_FAILED",`wait timed out for text: ${n}`)}async function n_(e,t,n){return!!E((await ny(e,t,{updateSession:!0})).snapshot.nodes,n)}async function nT(e,t,n,r){let i=await ny(e,{...t,session:n},{updateSession:!0}),o=I(r.selector),s=D(i.snapshot.nodes,o,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:r.disambiguateAmbiguous});if(!s)throw new a("COMMAND_FAILED",C(o,[],{unique:!0}));return{capture:i,node:s.node,selector:s.selector.raw,ref:`@${s.node.ref}`}}function n$(e){let t=nC(e);if(!t)return null;let n=s(t);return Number.isFinite(n.x)&&Number.isFinite(n.y)?n:null}function nC(e){if(!e)return null;let t=Number(e.x),n=Number(e.y),r=Number(e.width),i=Number(e.height);return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)&&Number.isFinite(i)&&!(r<0)&&!(i<0)?{x:t,y:n,width:r,height:i}:null}function nL(e){return{x:nU(e.x,e.width),y:nU(e.y,e.height)}}function nU(e,t){if(t<=1)return Math.floor(e);let n=Math.ceil(e);return Math.round(Math.min(Math.floor(e+t-1),Math.max(n,e+t/2)))}let nB=["button","link","menuitem","tabitem","textfield","searchfield","securetextfield","checkbox","radio","switch","cell"];function nG(e,t){return nF(e,t).node}function nF(e,t){var n;let r=function(e,t){let n=nC(t.rect);if(!n)return null;let r=t,i=new Set;for(;!i.has(r.ref);){i.add(r.ref);let t=e.filter(e=>{if(e.parentIndex!==r.index||!e.hittable)return!1;let t=nC(e.rect);return!!t&&nX(t,n)});if(1!==t.length)break;let a=t[0];if(void 0===a)break;r=a}return r===t?null:r}(e,t);if(r?.rect&&n$(r.rect))return{node:r,reason:"same-rect-descendant"};if([(n=t).type,n.role,n.subrole].map(e=>L(e??"")).some(nq)&&t.rect&&n$(t.rect))return{node:t,reason:"semantic-target"};let i=P(e,t);return i?.rect&&n$(i.rect)?!function(e,t,n){var r,i;let a,o,l,d=nC(e.rect),c=nC(t.rect);if(!d||!c)return!1;let h=function(e,t){let n=s(t),r=e.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}).map(e=>nC(e.rect)).filter(e=>null!==e);if(0===r.length)return null;let i=r.filter(e=>en(e,n.x,n.y));return er(i.length>0?i:r)}(n,d);return!!h&&(a=u(r=c,i=h),o=r.width*r.height,l=i.width*i.height,!(a<=0)&&!(o<=0)&&!(l<=0)&&!!(a/l>=.9)&&!!(a/o>=.8))&&!nX(d,c)}(t,i,e)?{node:i,reason:"hittable-ancestor"}:{node:t,reason:"overly-broad-ancestor"}:{node:t,reason:"original"}}function nq(e){return"tab"===e||nB.some(t=>e.includes(t))}function nX(e,t){return .5>=Math.abs(e.x-t.x)&&.5>=Math.abs(e.y-t.y)&&.5>=Math.abs(e.width-t.width)&&.5>=Math.abs(e.height-t.height)}async function nY(e,t,n){if(await nH(e,t,n.action),"point"===t.target.kind)return{kind:"point",point:{x:t.target.x,y:t.target.y}};if("ref"===t.target.kind){let r=await nK(e,t,t.target),i=r.resolved,s=n.promoteToHittableAncestor?nG(r.snapshot.nodes,i.node):i.node;return function(e,t,n,r){let i=e.rect?ef(e,t):null;if(!(!e.rect||!i||ep(e,t)))throw new a("COMMAND_FAILED",`Ref ${n} is off-screen and not safe to ${r}`,{reason:"offscreen_ref",ref:o(n),rect:e.rect,viewport:i,hint:`Use scroll with the direction from the off-screen summary, take a fresh snapshot, then retry ${r} with the new ref or a selector.`})}(s,r.snapshot.nodes,t.target.ref,n.action),{kind:"ref",point:nW(s,`Ref ${t.target.ref} not found or has invalid bounds`),target:{kind:"ref",ref:`@${i.ref}`},node:s,selectorChain:S(s,e.backend.platform,{action:"fill"===n.action?"fill":"click"}),refLabel:_(s,r.snapshot.nodes)}}let r=await nV(e,t,n.requireInteractive),i=I(t.target.selector),s=D(r.snapshot.nodes,i,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if(!s||!s.node.rect)throw new a("COMMAND_FAILED",C(i,s?.diagnostics??[],{unique:!0}));let l=n.promoteToHittableAncestor?nG(r.snapshot.nodes,s.node):s.node;return{kind:"selector",point:nW(l,`Selector ${s.selector.raw} resolved to invalid bounds`),target:{kind:"selector",selector:s.selector.raw},node:l,selectorChain:S(l,e.backend.platform,{action:"fill"===n.action?"fill":"click"}),refLabel:_(l,r.snapshot.nodes)}}async function nV(e,t,n){if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let r=t.session??"default",i=await e.sessions.get(r);if(!i)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");let o=await e.backend.captureSnapshot(nd(e,t),{interactiveOnly:n,compact:n}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:nc(e)};return await e.sessions.set({...i,snapshot:s}),{snapshot:s}}async function nH(e,t,n){if("macos"!==e.backend.platform)return;let r=await nz(e,t);if(("desktop"===r||"menubar"===r)&&("menubar"!==r||"click"!==n&&"press"!==n))throw new a("UNSUPPORTED_OPERATION",`${n} is not supported on macOS ${r} sessions yet. Open an app session to act, or use the ${r} surface to inspect.`)}async function nz(e,t){let n=await e.sessions.get(t.session??"default");return n?.metadata?.surface}async function nK(e,t,n){let r=t.session??"default",i=await e.sessions.get(r);if(!i)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");if(!i.snapshot)throw new a("INVALID_ARGS","No snapshot in session. Run snapshot first.");let o=n.fallbackLabel??"",s=nj(i.snapshot.nodes,n.ref,{fallbackLabel:o,requireRect:!0});if(s)return{snapshot:i.snapshot,resolved:s};let l=await nV(e,t,!0),d=nj(l.snapshot.nodes,n.ref,{fallbackLabel:o,requireRect:!0});if(!d)throw new a("COMMAND_FAILED",`Ref ${n.ref} not found or has no bounds`);return{...l,resolved:d}}function nj(e,t,n){let r=o(t);if(!r)throw new a("INVALID_ARGS",`Invalid ref: ${t}`);let i=d(e,r);if(nJ(i,n.requireRect))return{ref:r,node:i};let s=n.fallbackLabel.length>0?E(e,n.fallbackLabel):null;return nJ(s,n.requireRect)?{ref:r,node:s}:null}function nW(e,t){if(!e.rect)throw new a("COMMAND_FAILED",t);let n=s(e.rect);if(!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new a("COMMAND_FAILED",t);return n}function nJ(e,t){if(!e)return!1;if(!t)return!0;if(!e.rect)return!1;let{x:n,y:r,width:i,height:a}=e.rect;if(!Number.isFinite(Number(n))||!Number.isFinite(Number(r))||!Number.isFinite(Number(i))||!Number.isFinite(Number(a))||0>Number(i)||0>Number(a))return!1;let o=s(e.rect);return Number.isFinite(o.x)&&Number.isFinite(o.y)}async function nZ(e,t,n){let r;if(t.from||t.to||t.direction||void 0!==t.distance)throw new a("INVALID_ARGS","gesture swipe preset cannot be combined with from, to, direction, or distance");let i=K(t.preset);await nH(e,t,"swipe");let o=z(i,{referenceWidth:(r=n8((await nV(e,t,!1)).snapshot.nodes)).width,referenceHeight:r.height},{platform:e.backend.platform}),s=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",16,1e4),l={x:o.x1,y:o.y1},d={x:o.x2,y:o.y2},c=n6(await n(nd(e,t),l,d,{durationMs:s}));return{kind:"swipe",from:l,to:d,preset:i,...void 0!==s?{durationMs:s}:{},fromTarget:{kind:"viewport"},...c?{backendResult:c}:{},...b(`Swiped ${i}`)}}async function nQ(e,t){let n=t.target??{kind:"viewport"};return"viewport"===n.kind?(await nH(e,t,"scroll"),{kind:"viewport"}):await nY(e,{...t,target:n},{action:"scroll",requireInteractive:!1,promoteToHittableAncestor:!1})}async function n0(e,t){if(t.from){var n;if("x"in(n=t.from)&&"y"in n)return await nH(e,t,"swipe"),{point:n5(t.from,"from")};let r=await nY(e,{...t,target:t.from},{action:"swipe",requireInteractive:!1,promoteToHittableAncestor:!1});return{point:r.point,target:r}}if(!t.direction)throw new a("INVALID_ARGS","swipe requires from+to or a direction");return await nH(e,t,"swipe"),{point:s(n8((await nV(e,t,!1)).snapshot.nodes)),target:{kind:"viewport"}}}async function n1(e,t,n,r,i){if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION",`scroll ${n} requires snapshot support to verify hidden content before scrolling`);let{captureSnapshot:o}=e.backend;return await eg({edge:n,target:r,scope:i,captureNodes:async n=>{let r=await o(nd(e,t),{compact:!0,scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function n2(e,t){switch(e){case"up":case"down":case"left":case"right":return e;default:throw new a("INVALID_ARGS",`${t} must be up, down, left, or right`)}}function n5(e,t){let n=Number(e.x),r=Number(e.y);if(!Number.isFinite(n)||!Number.isFinite(r))throw new a("INVALID_ARGS",`${t} point requires finite x and y`);return{x:n,y:r}}function n4(e,t){if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS",`${t} must be a positive number`);return e}function n8(e){let t=e.filter(t=>ep(t,e)).map(e=>e.rect).filter(n3),n=t.length>0?t:e.map(e=>e.rect).filter(n3);if(0===n.length)throw new a("COMMAND_FAILED","Cannot infer viewport for directional swipe");let r=Math.min(...n.map(e=>e.x)),i=Math.min(...n.map(e=>e.y));return{x:r,y:i,width:Math.max(...n.map(e=>e.x+e.width))-r,height:Math.max(...n.map(e=>e.y+e.height))-i}}function n3(e){return!!(e&&e.width>0&&e.height>0)}function n6(e){return e&&"object"==typeof e?e:void 0}async function n9(e,t,n){let r=await nY(e,t,{action:n,requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.tap)throw new a("UNSUPPORTED_OPERATION","tap is not supported by this backend");let i=n7(await e.backend.tap(nd(e,t),r.point,{button:t.button,count:t.count,intervalMs:t.intervalMs,holdMs:t.holdMs,jitterPx:t.jitterPx,doubleTap:t.doubleTap}));return{...r,...i?{backendResult:i}:{}}}function n7(e){return e&&"object"==typeof e?e:void 0}function re(e,t){if(void 0!==e)return rt(e,t)}function rt(e,t){let n=e?.trim();if(!n)throw new a("INVALID_ARGS",`${t} must be a non-empty string`);return n}function rn(e){return e&&"object"==typeof e?e:void 0}let rr=/^[A-Za-z0-9_.:-]{1,64}$/;async function ri(e,t){if(!t||"object"!=typeof t)throw new a("INVALID_ARGS","apps.push requires an input");if("json"===t.kind)return ra(t.payload,"apps.push JSON payload",8192),{backendInput:{kind:"json",payload:t.payload},inputKind:"json"};let n=await tl(e,t,{usage:"apps.push",field:"input"});return{backendInput:{kind:"file",path:n.path},inputKind:"file",...n.cleanup?{cleanup:n.cleanup}:{}}}function ra(e,t,n){if(function(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS",`${t} must be a JSON object`)}(e,t),Buffer.byteLength(function(e,t){try{let n=JSON.stringify(e);if("string"!=typeof n)throw new a("INVALID_ARGS",`${t} must be JSON-serializable`);return n}catch{throw new a("INVALID_ARGS",`${t} must be JSON-serializable`)}}(e,t),"utf8")>n)throw new a("INVALID_ARGS",`${t} exceeds ${n} bytes`)}function ro(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function rs(e){return e&&"object"==typeof e?e:void 0}async function rl(e,t,n){let r="reinstall"===n?"reinstallApp":"installApp",i=e.backend[r];if(!i)throw new a("UNSUPPORTED_OPERATION",`admin.${n} is not supported by this backend`);let o="app"in t&&void 0!==t.app?rt(t.app,"app"):void 0;if("installFromSource"!==n&&!o)throw new a("INVALID_ARGS",`admin.${n} requires app`);let s=nd(e,t),l=await rd(e,s,t.source);try{var d,c,u,h,p;let t,r,a,f,w,m,g,y,x=await i.call(e.backend,s,{...o?{app:o}:{},source:l.source});return d=n,c=o,u=l.source,h=x,t=rp(h),r=rh(h,"appName"),a=rh(h,"appId"),f=rh(h,"bundleId"),w=rh(h,"packageName"),m=rh(h,"launchTarget"),g=rh(h,"installablePath"),y=rh(h,"archivePath"),{kind:"reinstall"===d?"appReinstalled":"installFromSource"===d?"appInstalledFromSource":"appInstalled",...c?{app:c}:{},source:u,...a?{appId:a}:{},...r?{appName:r}:{},...f?{bundleId:f}:{},...w?{packageName:w}:{},...m?{launchTarget:m}:{},...g?{installablePath:g}:{},...y?{archivePath:y}:{},...t?{backendResult:t}:{},...b(`${"reinstall"===d?"Reinstalled":"Installed"}: ${r??m??c??(p=u,"path"===p.kind?p.path:"uploadedArtifact"===p.kind?p.id:p.url)}`)}}finally{await l.cleanup?.()}}async function rd(e,t,n){let r=ru(n),i=await rc(e,r);try{let n=e.backend.resolveInstallSource?await e.backend.resolveInstallSource(t,i.source):i.source;return{source:ru(n),...i.cleanup?{cleanup:i.cleanup}:{}}}catch(e){if(i.cleanup)try{await i.cleanup()}catch{}throw e}}async function rc(e,t){if("url"===t.kind)return{source:t};let n=await tl(e,t,{usage:"admin.install",field:"source"});return{source:{kind:"path",path:n.path},...n.cleanup?{cleanup:n.cleanup}:{}}}function ru(e){if(!e||"object"!=typeof e)throw new a("INVALID_ARGS","install source is required");if("path"===e.kind)return{kind:"path",path:rt(e.path,"source.path")};if("uploadedArtifact"===e.kind)return{kind:"uploadedArtifact",id:rt(e.id,"source.id")};if("url"===e.kind){let t=rt(e.url,"source.url");return function(e){let t;try{t=new URL(e)}catch{throw new a("INVALID_ARGS",`Invalid install source URL: ${e}`)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new a("INVALID_ARGS","Install source URL must use http or https")}(t),{kind:"url",url:t}}throw new a("INVALID_ARGS","install source kind must be path, uploadedArtifact, or url")}function rh(e,t){let n=e[t];return"string"==typeof n&&n.length>0?n:void 0}function rp(e){return e&&"object"==typeof e?e:void 0}function rf(e,t){if("start"===e||"stop"===e)return e;throw new a("INVALID_ARGS",`${t} action must be start or stop`)}function rw(e,t,n,r){return{kind:"start"===e?r.startKind:r.stopKind,action:e,...n?{artifact:n}:{},backendResult:t,...b("start"===e?r.startMessage:r.stopMessage)}}let rm=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i,rb=/\b[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\b/g;function rg(e){var t,n;let r=!1,i=e;return{value:(t=i=(i=(i=(i=(i=i.replaceAll(/(authorization|token|secret|password|passwd|api[-_]?key)=([^&\s]+)/gi,(e,t)=>(r=!0,`${String(t)}=[REDACTED]`))).replaceAll(/("(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)"\s*:\s*")([^"]*)(")/gi,(e,t,n,i)=>(r=!0,`${String(t)}[REDACTED]${String(i)}`))).replaceAll(/\b(Bearer\s+)([^\s",;]+)/gi,(e,t)=>(r=!0,`${String(t)}[REDACTED]`))).replaceAll(/((?:authorization|cookie|token|secret|password|passwd|api[-_]?key)\s*[:=]\s*)([^\s,;&]+)/gi,(e,t)=>(r=!0,`${String(t)}[REDACTED]`))).replaceAll(rb,()=>(r=!0,"[REDACTED]")),n=()=>{r=!0},i=/(https?:\/\/|token|secret|password|authorization|cookie|api[-_]?key)/i.test(t)?t.replaceAll(/https?:\/\/[^\s"'<>)]+/gi,e=>{let t=ry(e);return t?(t.redacted&&n(),t.value):e}):t),redacted:r}}function ry(e){try{let t=new URL(e),n=function(e){let t=!1;for(let n of Array.from(e.searchParams.keys()))rm.test(n)&&(e.searchParams.set(n,"[REDACTED]"),t=!0);return t}(t);return(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED",n=!0),{value:t.toString(),redacted:n}}catch{return}}let rx=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i;function rv(e){if(!e)return{redacted:!1};let t=!1,n={};for(let[r,i]of Object.entries(e))if(rx.test(r))n[r]="[REDACTED]",t=!0;else{let e=rA(i,2048);n[r]=e.value??"",t||=e.redacted}return{value:n,redacted:t}}function rk(e){return void 0===e?{redacted:!1}:function(e){try{let t=JSON.parse(e),n=rN(t,rg);return rM(JSON.stringify(n.value),2048,n.redacted)}catch{return}}(e)??rA(e,2048)}function rI(e){return rN(e,e=>rA(e,2048))}function rN(e,t){if(void 0===e)return{redacted:!1};if("string"==typeof e)return t(e);if(!e||"object"!=typeof e)return{value:e,redacted:!1};if(Array.isArray(e)){let n=!1;return{value:e.map(e=>{let r=rN(e,t);return n||=r.redacted,r.value}),redacted:n}}let n=!1,r={};for(let[i,a]of Object.entries(e)){if(rx.test(i)){r[i]="[REDACTED]",n=!0;continue}let e=rN(a,t);r[i]=e.value,n||=e.redacted}return{value:r,redacted:n}}function rA(e,t){if(void 0===e)return{redacted:!1};let n=rg(e);return rM(n.value,t,n.redacted)}function rM(e,t,n){if(void 0===e)return{redacted:n};let r=e;return r.length>t&&(r=`${r.slice(0,t)}...[truncated]`,n=!0),{value:r,redacted:n}}async function rR(e,t){let n=nd(e,t),r=t.session?await e.sessions.get(t.session):void 0;return{...n,...t.appId??r?.appId?{appId:t.appId??r?.appId}:{},...t.appBundleId??r?.appBundleId?{appBundleId:t.appBundleId??r?.appBundleId}:{}}}function rP(e,t,n,r){return{...rS(e),...void 0!==e.cursor?{cursor:rt(e.cursor,"cursor")}:{},limit:void 0===e.limit?t:eR(e.limit,r,1,n)}}function rS(e){return{...void 0!==e.since?{since:rt(e.since,"since")}:{},...void 0!==e.until?{until:rt(e.until,"until")}:{}}}function rO(e,t,n=50){if(!Array.isArray(e))throw new a("INVALID_ARGS",`${t} must be an array of strings`);if(e.length>n)throw new a("INVALID_ARGS",`${t} must contain at most ${n} entries`);return e.map((e,n)=>rt(e,`${t}[${n}]`))}let rD=tu,rE=async(e,t)=>{let n,r,i;if(!t.baseline)throw new a("INVALID_ARGS","diff screenshot requires a baseline image");let o=function(e){if(null==e||""===e)return .1;let t=Number(e);if(Number.isNaN(t)||t<0||t>1)throw new a("INVALID_ARGS","--threshold must be a number between 0 and 1");return t}(t.threshold),s=t.current??{kind:"live"};if(t.overlayRefs&&!t3(s))throw new a("INVALID_ARGS","diff screenshot <current.png> cannot use --overlay-refs because saved-image comparisons have no live accessibility refs");let l=await tl(e,t.baseline,{usage:"diff screenshot baseline",field:"baseline"}),d=[];try{let a;a=t3(s)?(r=await t0(e,t)).path:(n=await tl(e,s,{usage:"diff screenshot current",field:"current"})).path,i=t.out?await td(e,t.out,{field:"diffPath",ext:".png"}):void 0;let c=await tH(l.path,a,{threshold:o,outputPath:i?.path,maxPixels:e.policy.maxImagePixels});t3(s)&&(c=await t1(e,t,i?.path,c,d));let u=c.diffPath?await i?.publish():void 0;return u&&d.push(u),c.diffPath||await i?.cleanup?.(),{...c,...d.length>0?{artifacts:d}:{}}}catch(e){throw await i?.cleanup?.(),e}finally{await l.cleanup?.(),await n?.cleanup?.(),await r?.cleanup?.()}},r_=async(e,t)=>{var n;let r,i,a=await nh(e,t),o=function(e){var t,n,r,i,a;let{previous:o,current:s,options:l,identity:d}=e;if(!0===l.forceFull||!0===l.raw||!o||!1===o.comparisonSafe||!1===s.comparisonSafe||(t=o,n=s,r=d,t.backend&&n.backend&&t.backend!==n.backend||r?.previousAppBundleId&&r.currentAppBundleId&&r.previousAppBundleId!==r.currentAppBundleId)||!o.presentationKey||o.presentationKey!==s.presentationKey||(i=o,a=s,i.truncated!==a.truncated||JSON.stringify(nl(i.nodes))!==JSON.stringify(nl(a.nodes))))return;let c=l.scope?.trim();return{ageMs:Math.max(0,s.createdAt-o.createdAt),nodeCount:s.nodes.length,...!0===l.interactiveOnly?{interactiveOnly:!0}:{},...c?{scope:c}:{}}}({previous:a.session?.snapshot,current:a.snapshot,options:t,identity:{previousAppBundleId:a.session?.appBundleId,currentAppBundleId:a.result.appBundleId??a.session?.appBundleId}});return await e.sessions.set(np(t.session,a)),{nodes:a.snapshot.nodes,truncated:a.snapshot.truncated??!1,visibility:function(e){var t;let{nodes:n,backend:r,snapshotRaw:i}=e;if(i||"macos-helper"===(t=r)||"linux-atspi"===t)return{partial:!1,visibleNodeCount:n.length,totalNodeCount:n.length,reasons:[]};let a=ec(n),o=new Set;return a.hiddenCount>0&&o.add("offscreen-nodes"),a.nodes.some(e=>e.hiddenContentAbove)&&o.add("scroll-hidden-above"),a.nodes.some(e=>e.hiddenContentBelow)&&o.add("scroll-hidden-below"),{partial:o.size>0,visibleNodeCount:a.nodes.length,totalNodeCount:n.length,reasons:[...o]}}({nodes:a.snapshot.nodes,backend:a.snapshot.backend,snapshotRaw:t.raw}),...a.result.androidSnapshot?{androidSnapshot:a.result.androidSnapshot}:{},...a.warnings.length>0?{warnings:a.warnings}:{},...o?{unchanged:o}:{},...(r=(n=a).result.appName??n.session?.appName,i=n.result.appBundleId??n.session?.appBundleId,{...r||i?{appName:r??i}:{},...i?{appBundleId:i}:{}})}},rT=async(e,t)=>{let n=await nh(e,t),r=!0===t.interactiveOnly,i=n.session?.snapshot,a=np(t.session,n);if(!i){let t=function(e,t={}){return no(e,t).length}(n.snapshot.nodes,{flatten:r});return await e.sessions.set(a),{mode:"snapshot",baselineInitialized:!0,summary:{additions:0,removals:0,unchanged:t},lines:[],...n.warnings.length>0?{warnings:n.warnings}:{}}}let o=function(e,t,n={}){let r=function(e,t){let n=e.length,r=t.length,i=n+r,a=new Map,o=[];a.set(1,0);for(let s=0;s<=i;s+=1){o.push(new Map(a));for(let i=-s;i<=s;i+=2){let l=i===-s||i!==s&&ns(a,i-1)<ns(a,i+1)?ns(a,i+1):ns(a,i-1)+1,d=l-i;for(;l<n&&d<r&&e[l].comparable===t[d].comparable;)l+=1,d+=1;if(a.set(i,l),l>=n&&d>=r)return function(e,t,n,r,i){let a=[],o=r,s=i;for(let r=e.length-1;r>=0;r-=1){let i=e[r],l=o-s,d=l===-r||l!==r&&ns(i,l-1)<ns(i,l+1)?l+1:l-1,c=ns(i,d),u=c-d;for(;o>c&&s>u;)a.push({kind:"unchanged",text:n[s-1].text}),o-=1,s-=1;if(0===r)break;o===c?(a.push({kind:"added",text:n[u].text}),s=u):(a.push({kind:"removed",text:t[c].text}),o=c)}return a.reverse(),a}(o,e,t,n,r)}}return[]}(no(e,n),no(t,n)),i={additions:0,removals:0,unchanged:0};for(let e of r)"added"===e.kind&&(i.additions+=1),"removed"===e.kind&&(i.removals+=1),"unchanged"===e.kind&&(i.unchanged+=1);return{summary:i,lines:r}}(i.nodes,n.snapshot.nodes,{flatten:r});return await e.sessions.set(a),{mode:"snapshot",baselineInitialized:!1,summary:o.summary,lines:o.lines,...n.warnings.length>0?{warnings:n.warnings}:{}}},r$=async(e,t)=>{let n=t.locator??"any";if(!t.query)throw new a("INVALID_ARGS","find requires a value");if("wait"===t.action)return await nS(e,t,n);let{capture:r,match:i}=await nO(e,t,n);if(!i)throw new a("COMMAND_FAILED","find did not match any element");if("exists"===t.action)return{kind:"found",found:!0};let o=`@${i.ref}`;return"get_attrs"===t.action?{kind:"attrs",ref:o,node:i}:{kind:"text",ref:o,text:await nx(e,r,i),node:i}},rC=nv,rL=nk,rU=nI,rB=nN,rG=nA,rF=nM,rq=nR,rX=nP,rY=async(e,t)=>await n9(e,t,"click"),rV=async(e,t)=>await n9(e,t,"press"),rH=async(e,t)=>{var n;if(!t.text)throw new a("INVALID_ARGS","fill requires text");let r=await nY(e,t,{action:"fill",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.fill)throw new a("UNSUPPORTED_OPERATION","fill is not supported by this backend");let i=n7(await e.backend.fill(nd(e,t),r.point,t.text,{delayMs:t.delayMs})),o="node"in r?r.node.type??"":"",s=o&&!U(o,e.backend.platform)?`fill target ${n=r,n.target?.kind==="ref"?n.target.ref:n.target?.kind==="selector"?n.target.selector:"point"} resolved to "${o}", attempting fill anyway.`:void 0;return{...r,text:t.text,...s?{warning:s}:{},...i?{backendResult:i}:{}}},rz=async(e,t)=>{let n=t.text;if(!n)throw new a("INVALID_ARGS","type requires text");let r=Y(n);if(r)throw new a("INVALID_ARGS",`type does not accept a target ref like "${r}"`,{hint:`Use fill ${r} "text" to target that field, or press ${r} then type "text" to append.`});if(!e.backend.typeText)throw new a("UNSUPPORTED_OPERATION","type is not supported by this backend");let i=eR(t.delayMs??0,"delay-ms",0,1e4),o=n7(await e.backend.typeText(nd(e,t),n,{delayMs:i}));return{kind:"text",text:n,delayMs:i,...o?{backendResult:o}:{},...b(`Typed ${Array.from(n).length} chars`)}},rK=async(e,t)=>{let n=await nY(e,t,{action:"focus",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new a("UNSUPPORTED_OPERATION","focus is not supported by this backend");let r=n6(await e.backend.focus(nd(e,t),n.point));return{...n,...r?{backendResult:r}:{},...b(`Focused (${n.point.x}, ${n.point.y})`)}},rj=async(e,t)=>{let n=await nY(e,t,{action:"longPress",requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.longPress)throw new a("UNSUPPORTED_OPERATION","longPress is not supported by this backend");let r=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",0,12e4),i=n6(await e.backend.longPress(nd(e,t),n.point,{durationMs:r}));return{...n,...void 0!==r?{durationMs:r}:{},...i?{backendResult:i}:{},...b(`Long pressed (${n.point.x}, ${n.point.y})`)}},rW=async(e,t)=>{if(!e.backend.swipe)throw new a("UNSUPPORTED_OPERATION","swipe is not supported by this backend");if(t.preset)return await nZ(e,t,e.backend.swipe);let n=await n0(e,t),r=function(e,t){if(t.to)return{point:n5(t.to,"to")};let n=n2(t.direction,"swipe direction"),r=n4(t.distance??200,"swipe distance");switch(n){case"up":return{point:{x:e.x,y:e.y-r},direction:n,distance:r};case"down":return{point:{x:e.x,y:e.y+r},direction:n,distance:r};case"left":return{point:{x:e.x-r,y:e.y},direction:n,distance:r};case"right":return{point:{x:e.x+r,y:e.y},direction:n,distance:r}}}(n.point,t),i=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",16,1e4),o=n6(await e.backend.swipe(nd(e,t),n.point,r.point,{durationMs:i}));return{kind:"swipe",from:n.point,to:r.point,...r.direction?{direction:r.direction}:{},...void 0!==r.distance?{distance:r.distance}:{},...void 0!==i?{durationMs:i}:{},...n.target?{fromTarget:n.target}:{},...o?{backendResult:o}:{},...b("Swiped")}},rJ=async(e,t)=>{var n,r,i,o;let s;if(!e.backend.scroll)throw new a("UNSUPPORTED_OPERATION","scroll is not supported by this backend");let l="bottom"===(n=t.direction)?{direction:"down",edge:"bottom"}:"top"===n?{direction:"up",edge:"top"}:{direction:n2(n,"scroll direction")},d=(r=t.amount,i="scroll amount",void 0===r?void 0:n4(r,i)),c=function(e,t){if(void 0!==e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new a("INVALID_ARGS",`${t} must be a positive integer`);return e}}(t.pixels,"scroll pixels");if(void 0!==d&&void 0!==c)throw new a("INVALID_ARGS","scroll accepts either amount or pixels, not both");let u=await nQ(e,t),h="viewport"===u.kind?{kind:"viewport"}:{kind:"point",point:u.point},p=e.backend.scroll,f=async()=>await p(nd(e,t),h,{direction:l.direction,...void 0!==d?{amount:d}:{},...void 0!==c?{pixels:c}:{}}),w=0;if(l.edge){let n=l.edge,r="viewport"===(o=u).kind?{}:{point:o.point,nodeIndex:"node"in o?o.node.index:void 0},i=await ey({edge:n,captureState:async i=>await n1(e,t,n,r,i),scroll:f});s=i.result,w=i.passes}else s=await f(),w=1;let m=n6(s);return{...u,direction:l.direction,...l.edge?{edge:l.edge,passes:w}:{},...void 0!==d?{amount:d}:{},...void 0!==c?{pixels:c}:{},...m?{backendResult:m}:{},...b(ex(l.direction,l.edge,w,d,c))}},rZ=async(e,t)=>{if(!e.backend.pinch)throw new a("UNSUPPORTED_OPERATION","pinch is not supported by this backend");await nH(e,t,"pinch");let n=n4(t.scale,"pinch scale"),r=t.center?await nY(e,{...t,target:t.center},{action:"pinch",requireInteractive:!1,promoteToHittableAncestor:!1}):void 0,i=n6(await e.backend.pinch(nd(e,t),{scale:n,...r?{center:r.point}:{}}));return{kind:"pinch",scale:n,...r?{center:r.point,centerTarget:r}:{},...i?{backendResult:i}:{},...b(`Pinched to scale ${n}`)}},rQ=async(e,t={})=>{if(!e.backend.pressBack)throw new a("UNSUPPORTED_OPERATION","system.back is not supported by this backend");let n=t.mode??"in-app";if("in-app"!==n&&"system"!==n)throw new a("INVALID_ARGS","system.back mode must be in-app or system");let r=rn(await e.backend.pressBack(nd(e,t),{mode:n}));return{kind:"systemBack",mode:n,...r?{backendResult:r}:{},...b("Back")}},r0=async(e,t={})=>{if(!e.backend.pressHome)throw new a("UNSUPPORTED_OPERATION","system.home is not supported by this backend");let n=rn(await e.backend.pressHome(nd(e,t)));return{kind:"systemHome",...n?{backendResult:n}:{},...b("Home")}},r1=async(e,t)=>{if(!e.backend.rotate)throw new a("UNSUPPORTED_OPERATION","system.rotate is not supported by this backend");let n=function(e){switch(e){case"portrait":case"portrait-upside-down":case"landscape-left":case"landscape-right":return e;default:throw new a("INVALID_ARGS","system.rotate orientation must be portrait, portrait-upside-down, landscape-left, or landscape-right")}}(t.orientation),r=rn(await e.backend.rotate(nd(e,t),n));return{kind:"systemRotated",orientation:n,...r?{backendResult:r}:{},...b(`Rotated to ${n}`)}},r2=async(e,t={})=>{var n,r,i,o,s,l,d;if(!e.backend.setKeyboard)throw new a("UNSUPPORTED_OPERATION","system.keyboard is not supported by this backend");let c=t.action??"status";if(!X(c))throw new a("INVALID_ARGS","system.keyboard action must be status, get, dismiss, enter, or return");let u=await e.backend.setKeyboard(nd(e,t),{action:c}),h=rn(u),p=(n=u)&&"object"==typeof n?u:{};return"enter"===c||"return"===c?{kind:"keyboardEnterPressed",action:"enter",state:p,...(r=h)?{backendResult:r}:{},...b("Keyboard enter pressed")}:"dismiss"===c?(i=c,{kind:"keyboardDismissed",action:i,state:o=p,...(s=h)?{backendResult:s}:{},...b(!1===o.dismissed?"Keyboard already hidden":"Keyboard dismissed")}):(l=c,{kind:"keyboardState",action:l,state:p,...(d=h)?{backendResult:d}:{}})},r5=async(e,t)=>{if("read"===t.action){if(!e.backend.getClipboard)throw new a("UNSUPPORTED_OPERATION","system.clipboard read is not supported by this backend");let n=await e.backend.getClipboard(nd(e,t));return{kind:"clipboardText",action:"read",text:"string"==typeof n?n:n.text}}if("write"!==t.action)throw new a("INVALID_ARGS","system.clipboard action must be read or write");if(!e.backend.setClipboard)throw new a("UNSUPPORTED_OPERATION","system.clipboard write is not supported by this backend");if("string"!=typeof t.text)throw new a("INVALID_ARGS","system.clipboard write requires text");let n=rn(await e.backend.setClipboard(nd(e,t),t.text));return{kind:"clipboardUpdated",action:"write",textLength:Array.from(t.text).length,...n?{backendResult:n}:{},...b("Clipboard updated")}},r4=async(e,t={})=>{if(!e.backend.openSettings)throw new a("UNSUPPORTED_OPERATION","system.settings is not supported by this backend");let n=re(t.target,"target"),r=rn(await e.backend.openSettings(nd(e,t),n));return{kind:"settingsOpened",...n?{target:n}:{},...r?{backendResult:r}:{},...b(n?`Opened settings: ${n}`:"Opened settings")}},r8=async(e,t={})=>{var n,r;if(!e.backend.handleAlert)throw new a("UNSUPPORTED_OPERATION","system.alert is not supported by this backend");let i=t.action??"get";if("get"!==i&&"accept"!==i&&"dismiss"!==i&&"wait"!==i)throw new a("INVALID_ARGS","system.alert action must be get, accept, dismiss, or wait");let o=void 0===t.timeoutMs?void 0:eR(t.timeoutMs,"timeoutMs",0,12e4),s=await e.backend.handleAlert(nd(e,t),i,{timeoutMs:o});return n=i,r=s,"get"===n?function(e){if("alertStatus"!==e.kind)throw new a("COMMAND_FAILED","system.alert get returned an invalid backend result");return{kind:"alertStatus",action:"get",alert:e.alert}}(r):"wait"===n?function(e){if("alertWait"!==e.kind)throw new a("COMMAND_FAILED","system.alert wait returned an invalid backend result");return{kind:"alertWait",action:"wait",alert:e.alert,...void 0!==e.waitedMs?{waitedMs:e.waitedMs}:{},...void 0!==e.timedOut?{timedOut:e.timedOut}:{},...b(e.alert?"Alert visible":"Alert wait timed out")}}(r):function(e,t){if("alertHandled"!==t.kind)throw new a("COMMAND_FAILED",`system.alert ${e} returned an invalid backend result`);return{kind:"alertHandled",action:e,handled:t.handled,...t.alert?{alert:t.alert}:{},...t.button?{button:t.button}:{},...b(t.handled?`Alert ${e}ed`:"No alert handled")}}(n,r)},r3=async(e,t={})=>{if(!e.backend.openAppSwitcher)throw new a("UNSUPPORTED_OPERATION","system.appSwitcher is not supported by this backend");let n=rn(await e.backend.openAppSwitcher(nd(e,t)));return{kind:"appSwitcherOpened",...n?{backendResult:n}:{},...b("Opened app switcher")}},r6=async(e,t)=>{var n;if(!e.backend.openApp)throw new a("UNSUPPORTED_OPERATION","apps.open is not supported by this backend");let r=function(e){var t;let n=re(e.app,"app"),r=re(e.appId,"appId"),i=re(e.bundleId,"bundleId"),o=re(e.packageName,"packageName"),s=re(e.url,"url"),l=re(e.activity,"activity"),d={...n?{app:n}:{},...r?{appId:r}:{},...i?{bundleId:i}:{},...o?{packageName:o}:{},...s?{url:s}:{},...l?{activity:l}:{}};if(!((t=d).app??t.appId??t.bundleId??t.packageName??t.url??t.activity))throw new a("INVALID_ARGS","apps.open requires app, appId, bundleId, packageName, url, or activity");return d}(t),i=rs(await e.backend.openApp(ro(e,t),r,{launchArgs:t.launchArgs,relaunch:t.relaunch}));return{kind:"appOpened",target:r,relaunch:!0===t.relaunch,...i?{backendResult:i}:{},...b(`Opened: ${(n=r).app??n.appId??n.bundleId??n.packageName??n.url??n.activity??"app"}`)}},r9=async(e,t={})=>{if(!e.backend.closeApp)throw new a("UNSUPPORTED_OPERATION","apps.close is not supported by this backend");let n=re(t.app,"app"),r=rs(await e.backend.closeApp(ro(e,t),n));return{kind:"appClosed",...n?{app:n}:{},...r?{backendResult:r}:{},...b(n?`Closed: ${n}`:"Closed app")}},r7=async(e,t={})=>{if(!e.backend.listApps)throw new a("UNSUPPORTED_OPERATION","apps.list is not supported by this backend");return{kind:"appsList",apps:await e.backend.listApps(ro(e,t),F(t.filter))}},ie=async(e,t)=>{if(!e.backend.getAppState)throw new a("UNSUPPORTED_OPERATION","apps.state is not supported by this backend");let n=rt(t.app,"app"),r=await e.backend.getAppState(ro(e,t),n);return{kind:"appState",app:n,state:r}},it=async(e,t)=>{if(!e.backend.pushFile)throw new a("UNSUPPORTED_OPERATION","apps.push is not supported by this backend");let n=rt(t.app,"app"),r=await ri(e,t.input);try{let i=await e.backend.pushFile(ro(e,t),r.backendInput,n),a=rs(i);return{kind:"appPushed",app:n,inputKind:r.inputKind,...a?{backendResult:a}:{},...b(`Pushed to ${n}`)}}finally{await r.cleanup?.()}},ir=async(e,t)=>{var n,r;if(!e.backend.triggerAppEvent)throw new a("UNSUPPORTED_OPERATION","apps.triggerEvent is not supported by this backend");let i=function(e){let t=rt(e,"name");if(!rr.test(t))throw new a("INVALID_ARGS",`Invalid apps.triggerEvent name: ${t}`,{hint:"Use 1-64 chars: letters, numbers, underscore, dot, colon, or dash."});return t}(t.name);n=t.payload,r=`apps.triggerEvent payload for "${i}"`,void 0!==n&&ra(n,r,8192);let o=rs(await e.backend.triggerAppEvent(ro(e,t),{name:i,...t.payload?{payload:t.payload}:{}}));return{kind:"appEventTriggered",name:i,...t.payload?{payload:t.payload}:{},...o?{backendResult:o}:{},...b(`Triggered app event: ${i}`)}},ii=async(e,t={})=>{if(!e.backend.listDevices)throw new a("UNSUPPORTED_OPERATION","admin.devices is not supported by this backend");return{kind:"adminDevices",devices:await e.backend.listDevices(nd(e,t),t.filter)}},ia=async(e,t={})=>{if(!e.backend.bootDevice)throw new a("UNSUPPORTED_OPERATION","admin.boot is not supported by this backend");let n=function(e){if(!e)return;let t=re(e.id,"target.id"),n=re(e.name,"target.name"),r={...t?{id:t}:{},...n?{name:n}:{},...e.platform?{platform:e.platform}:{},...e.target?{target:e.target}:{},...void 0!==e.headless?{headless:e.headless}:{}};return Object.keys(r).length>0?r:void 0}(t.target),r=rp(await e.backend.bootDevice(nd(e,t),n));return{kind:"deviceBooted",...n?{target:n}:{},...r?{backendResult:r}:{},...b("Booted device")}},io=async(e,t)=>await rl(e,t,"install"),is=async(e,t)=>await rl(e,t,"reinstall"),il=async(e,t)=>await rl(e,t,"installFromSource"),id=async(e,t)=>{let n=rf(t.action,"record"),r="start"===n?e.backend.startRecording:e.backend.stopRecording;if(!r)throw new a("UNSUPPORTED_OPERATION",`record ${n} is not supported by this backend`);let i=t.out?await td(e,t.out,{field:"path",ext:".mp4"}):void 0;try{var o,s,l,d,c;let a,u,h=(o=t,s=i?.path,a=void 0===o.fps?void 0:eR(o.fps,"fps",1,60),u=void 0===o.quality?void 0:eR(o.quality,"quality",5,10),{...s?{outPath:s}:{},...void 0!==a?{fps:a}:{},...void 0!==u?{quality:u}:{},...void 0!==o.hideTouches?{showTouches:!0!==o.hideTouches}:{}}),p=await r.call(e.backend,nd(e,t),h),f=await i?.publish();return l=n,d=p,c=f,{..."string"==typeof d.path?{path:d.path}:{},..."string"==typeof d.telemetryPath?{telemetryPath:d.telemetryPath}:{},..."string"==typeof d.warning?{warning:d.warning}:{},...rw(l,d,c,{startKind:"recordingStarted",stopKind:"recordingStopped",startMessage:"Recording started",stopMessage:"Recording stopped"})}}catch(e){throw await i?.cleanup?.(),e}},ic=async(e,t)=>{let n=rf(t.action,"trace"),r="start"===n?e.backend.startTrace:e.backend.stopTrace;if(!r)throw new a("UNSUPPORTED_OPERATION",`trace ${n} is not supported by this backend`);let i=t.out?await td(e,t.out,{field:"outPath",ext:".trace"}):void 0;try{var o,s,l;let a={...i?.path?{outPath:i.path}:{}},d=await r.call(e.backend,nd(e,t),a),c=await i?.publish();return o=n,s=d,l=c,{..."string"==typeof s.outPath?{outPath:s.outPath}:{},...rw(o,s,l,{startKind:"traceStarted",stopKind:"traceStopped",startMessage:"Trace started",stopMessage:"Trace stopped"})}}catch(e){throw await i?.cleanup?.(),e}},iu=async(e,t={})=>{var n,r;let i;if(!e.backend.readLogs)throw new a("UNSUPPORTED_OPERATION","diagnostics.logs is not supported by this backend");return i=!0===(n=await e.backend.readLogs(await rR(e,t),{...rP(r=t,100,500,"logs limit"),...void 0!==r.levels?{levels:rO(r.levels,"levels")}:{},...void 0!==r.search?{search:rt(r.search,"search")}:{},...void 0!==r.source?{source:rt(r.source,"source")}:{}})).redacted,{kind:"diagnosticsLogs",entries:n.entries.map(e=>{let t=rA(e.message,4096),n=rI(e.metadata);return i||=t.redacted||n.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.level?{level:e.level}:{},message:t.value??"",...e.source?{source:e.source}:{},...n.value?{metadata:n.value}:{}}}),...n.nextCursor?{nextCursor:n.nextCursor}:{},...n.timeWindow?{timeWindow:n.timeWindow}:{},...n.backend?{backend:n.backend}:{},redacted:i,...n.notes?{notes:n.notes}:{}}},ih=async(e,t={})=>{var n,r,i;let o;if(!e.backend.dumpNetwork)throw new a("UNSUPPORTED_OPERATION","diagnostics.network is not supported by this backend");let s={...rP(i=t,25,200,"network limit"),include:function(e){if(void 0===e)return"summary";if("summary"===e||"headers"===e||"body"===e||"all"===e)return e;throw new a("INVALID_ARGS","network include must be summary, headers, body, or all")}(i.include)};return n=await e.backend.dumpNetwork(await rR(e,t),s),r=s.include??"summary",o=!0===n.redacted,{kind:"diagnosticsNetwork",entries:n.entries.map(e=>{var t;let n=e.url?ry(t=e.url)??rA(t,2048):void 0,i="headers"===r||"all"===r?rv(e.requestHeaders):void 0,a="headers"===r||"all"===r?rv(e.responseHeaders):void 0,s="body"===r||"all"===r?rk(e.requestBody):void 0,l="body"===r||"all"===r?rk(e.responseBody):void 0,d=rI(e.metadata);return o||=(n?.redacted??!1)||(i?.redacted??!1)||(a?.redacted??!1)||(s?.redacted??!1)||(l?.redacted??!1)||d.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.method?{method:e.method}:{},...n?{url:n.value}:{},...void 0!==e.status?{status:e.status}:{},...void 0!==e.durationMs?{durationMs:e.durationMs}:{},...i?.value?{requestHeaders:i.value}:{},...a?.value?{responseHeaders:a.value}:{},...s?.value!==void 0?{requestBody:s.value}:{},...l?.value!==void 0?{responseBody:l.value}:{},...d.value?{metadata:d.value}:{}}}),...n.nextCursor?{nextCursor:n.nextCursor}:{},...n.timeWindow?{timeWindow:n.timeWindow}:{},...n.backend?{backend:n.backend}:{},redacted:o,...n.notes?{notes:n.notes}:{}}},ip=async(e,t={})=>{var n,r;let i;if(!e.backend.measurePerf)throw new a("UNSUPPORTED_OPERATION","diagnostics.perf is not supported by this backend");return i=!0===(n=await e.backend.measurePerf(await rR(e,t),{...rS(r=t),...void 0!==r.sampleMs?{sampleMs:eR(r.sampleMs,"sampleMs",100,6e4)}:{},...void 0!==r.metrics?{metrics:rO(r.metrics,"metrics",20)}:{}})).redacted,{kind:"diagnosticsPerf",metrics:n.metrics.map(e=>{let t=rA(e.message,4096),n=rI(e.metadata);return i||=t.redacted||n.redacted,{name:e.name,...void 0!==e.value?{value:e.value}:{},...e.unit?{unit:e.unit}:{},...e.status?{status:e.status}:{},...void 0!==t.value?{message:t.value}:{},...n.value?{metadata:n.value}:{}}}),...n.startedAt?{startedAt:n.startedAt}:{},...n.endedAt?{endedAt:n.endedAt}:{},...n.backend?{backend:n.backend}:{},redacted:i,...n.notes?{notes:n.notes}:{}}};function iw(e){let t={backend:e.backend,artifacts:e.artifacts,sessions:e.sessions??function(e=[]){let t=new Map(e.map(e=>[e.name,im(e)]));return{get:e=>im(t.get(e)),set:e=>{t.set(e.name,im(e))},delete:e=>{t.delete(e)},list:()=>Array.from(t.values(),e=>im(e))}}(),policy:e.policy??function(e={}){return{allowLocalInputPaths:!1,allowLocalOutputPaths:!1,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}(),diagnostics:e.diagnostics,clock:e.clock,signal:e.signal};return{...t,capture:{screenshot:e=>rD(t,e),diffScreenshot:e=>rE(t,e),snapshot:e=>r_(t,e),diffSnapshot:e=>rT(t,e)},selectors:{find:e=>r$(t,e),get:e=>rC(t,e),getText:(e,n={})=>rL(t,{...n,target:e}),getAttrs:(e,n={})=>rU(t,{...n,target:e}),is:e=>rB(t,e),isVisible:(e,n={})=>rG(t,{...n,target:e}),isHidden:(e,n={})=>rF(t,{...n,target:e}),wait:e=>rq(t,e),waitForText:(e,n={})=>rX(t,{...n,text:e})},interactions:{click:(e,n={})=>rY(t,{...n,target:e}),press:(e,n={})=>rV(t,{...n,target:e}),fill:(e,n,r={})=>rH(t,{...r,target:e,text:n}),typeText:(e,n={})=>rz(t,{...n,text:e}),focus:(e,n={})=>rK(t,{...n,target:e}),longPress:(e,n={})=>rj(t,{...n,target:e}),swipe:e=>rW(t,e),scroll:e=>rJ(t,e),pinch:e=>rZ(t,e)},system:{back:e=>rQ(t,e),home:e=>r0(t,e),rotate:e=>r1(t,e),keyboard:e=>r2(t,e),clipboard:e=>r5(t,e),settings:e=>r4(t,e),alert:e=>r8(t,e),appSwitcher:e=>r3(t,e)},apps:{open:e=>r6(t,e),close:e=>r9(t,e),list:(e={})=>r7(t,{...e,filter:G(e.filter)}),state:e=>ie(t,e),push:e=>it(t,e),triggerEvent:e=>ir(t,e)},admin:{devices:e=>ii(t,e),boot:e=>ia(t,e),install:e=>io(t,e),reinstall:e=>is(t,e),installFromSource:e=>il(t,e)},recording:{record:e=>id(t,e),trace:e=>ic(t,e)},observability:{logs:e=>iu(t,e),network:e=>ih(t,e),perf:e=>ip(t,e)}}}function im(e){if(e)return{...e,...e.snapshot?{snapshot:structuredClone(e.snapshot)}:{},...e.metadata?{metadata:function(e){try{return structuredClone(e)}catch{return{...e}}}(e.metadata)}:{}}}function ib(e={}){return{allowLocalInputPaths:!0,allowLocalOutputPaths:!0,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}export{e4 as PNG,e$ as analyzeReactNativeOverlay,ec as buildMobileSnapshotPresentation,V as buildScrollGesturePlan,t9 as buildSnapshotDisplayLines,H as buildSwipeGesturePlan,z as buildSwipePresetGesturePlan,eg as captureScrollEdgeState,J as clampGesturePoint,et as clampToRange,iw as createAgentDevice,to as decodePng,eu as deriveMobileSnapshotHiddenContentHints,eT as detectReactNativeOverlay,ed as displayNodeLabel,nm as evaluateIsPredicate,Y as findMistargetedTypeRefToken,ex as formatScrollEdgeMessage,t7 as formatSnapshotLine,j as inferGestureReferenceFrame,eo as inferVerticalScrollIndicatorDirections,nU as interiorCoordinate,X as isKeyboardAction,eL as isReactNativeCollapsedWarningWrapperCandidate,eU as isReactNativeCollapsedWarningWrapperWithVisibleBanner,nw as isSupportedPredicate,ea as isSystemScrollIndicatorLabel,ib as localCommandPolicy,es as normalizeSnapshotTree,Z as parseScrollDirection,K as parseSwipePreset,W as pointFromPercent,nL as pointInsideRect,eC as readReactNativeOverlayActionNodes,eR as requireIntInRange,nG as resolveActionableTouchNode,nF as resolveActionableTouchResolution,n$ as resolveRectCenter,ey as runScrollEdgePasses};
|
|
1
|
+
import{promises as e}from"node:fs";import{deflateSync as t,inflateSync as n}from"node:zlib";import r from"node:path";import{asAppError as i,AppError as a}from"./9152.js";import{normalizeRef as o,centerOfRect as s,buildSnapshotPresentationKey as l,findNodeByRef as d}from"./4057.js";import{expandRect as c,intersectArea as u,isScrollableNodeLike as h,unionRects as p,rectCenter as f,clamp as w,squaredDistance as m}from"./4778.js";import{successText as b}from"./1998.js";import{whichCmd as g,runCmd as y}from"./9818.js";import{trimText as x,extractNodeText as v,findSnapshotAncestor as k,parseSelectorChain as I,isNodeVisible as N,buildSnapshotNodeByIndex as A,isNodeEditable as M,buildTextPreview as R,findNearestHittableAncestor as P,buildSelectorChainForNode as S,findSelectorChainMatch as O,resolveSelectorChain as D,findNodeByLabel as E,resolveRefLabel as _,describeTextSurface as T,extractReadableText as $,formatSelectorFailure as C,normalizeType as L,isFillableType as U}from"./940.js";import{findBestMatchesByLocator as B}from"./7556.js";import"./7847.js";import{resolveAppsFilter as G,assertResolvedAppsFilter as F}from"./1393.js";let q=["status","get","dismiss","enter","return"];function X(e){return q.includes(e)}function Y(e){let t=e?.trim().split(/\s+/,1)[0];if(!t||!t.startsWith("@")||t.length<3)return null;let n=t.slice(1);return/^[A-Za-z_-]*\d[\w-]*$/i.test(n)||/^(?:ref|node|element|el)[\w-]*$/i.test(n)?t:null}function V(e){let t=e.direction,n="up"===t||"down"===t?e.referenceHeight:e.referenceWidth,r=function(e){if(void 0===e)return .6;if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS","scroll amount must be a positive number");return e}(e.amount),i=void 0!==e.pixels?function(e){if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS","scroll pixels must be a positive integer");return Math.max(1,Math.round(e))}(e.pixels):Math.round(n*r),o=Math.max(1,Math.round(.05*n)),s=Math.max(1,Math.min(i,Math.max(1,n-2*o))),l=Math.round(s/2),d=Math.round(e.referenceWidth/2),c=Math.round(e.referenceHeight/2),u=(n,r,i,a)=>({direction:t,x1:n,y1:r,x2:i,y2:a,referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:s});switch(t){case"up":return u(d,c-l,d,c+l);case"down":return u(d,c+l,d,c-l);case"left":return u(d-l,c,d+l,c);case"right":return u(d+l,c,d-l,c)}}function H(e){return{...V({...e,direction:function(e){switch(e){case"up":return"down";case"down":return"up";case"left":return"right";case"right":return"left"}}(e.direction)}),direction:e.direction}}function z(e,t,n={}){let r=n.marginPx??8,[i,a,o]="left"===e?[85,15,50]:"right"===e?[15,85,50]:"left-edge"===e?[99,15,50]:[1,85,50],s=W(t,i,o,{marginPx:r}),l=W(t,a,o,{marginPx:r});return{preset:e,x1:s.x,y1:s.y,x2:l.x,y2:l.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function K(e){switch(e){case"left":case"right":case"left-edge":case"right-edge":return e;default:throw new a("INVALID_ARGS","gesture swipe requires left, right, left-edge, or right-edge")}}function j(e){let t=function(e){let t=e.filter(e=>(function(e){if(!e)return!1;let t=e.toLowerCase();return t.includes("application")||t.includes("window")})(e.type)&&Q(e.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(t)return t;let n=e.map(e=>e.rect).filter(Q);if(0===n.length)return;let r=Math.max(...n.map(e=>e.x+e.width)),i=Math.max(...n.map(e=>e.y+e.height));if(!(r<=0)&&!(i<=0))return{x:0,y:0,width:r,height:i}}(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function W(e,t,n,r={}){let i={x:Math.round(e.referenceWidth*t/100),y:Math.round(e.referenceHeight*n/100)};return void 0===r.marginPx?i:J(i,e,r.marginPx)}function J(e,t,n){return{x:ee(e.x,n,t.referenceWidth),y:ee(e.y,n,t.referenceHeight)}}function Z(e){switch(e){case"up":case"down":case"left":case"right":return e;default:throw new a("INVALID_ARGS",`Unknown direction: ${e}`)}}function Q(e){return!!e&&e.width>0&&e.height>0}function ee(e,t,n){let r=Math.max(t,n-t);return et(e,t,r)}function et(e,t,n){return Math.min(Math.round(n),Math.max(Math.round(t),Math.round(e)))}function en(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function er(e){let t=null,n=-1;for(let r of e){let e=r.width*r.height;e>n&&(t=r,n=e)}return t}function ei(e,t,n,r){return Math.max(e,n)<=Math.min(t,r)}function ea(e){let t=e.trim().toLowerCase();return!!t&&/^(vertical|horizontal)\s+scroll\s+bar(?:,?\s*\d+\s+pages?)?$/.test(t)}function eo(e,t){if(!(e?.trim().toLowerCase()??"").includes("vertical scroll bar"))return null;let n=function(e){if(!e)return null;let t=/^(\d{1,3})%$/.exec(e.trim());if(!t)return null;let n=Number(t[1]);return Number.isFinite(n)?Math.max(0,Math.min(100,n)):null}(t);return null===n?null:n<=1?{above:!1,below:!0}:n>=99?{above:!0,below:!1}:{above:!0,below:!0}}function es(e){let t=new Map;for(let[n,r]of e.entries())t.set(r.index,n);let n=[],r=[];for(let[i,a]of e.entries()){let e=Math.max(0,a.depth??0);for(;r.length>0&&e<=r[r.length-1].depth;)r.pop();let o="number"==typeof a.parentIndex?t.get(a.parentIndex):void 0,s="number"==typeof o&&o<i?o:r[r.length-1]?.index;n.push({...a,index:i,depth:e,parentIndex:s}),r.push({depth:e,index:i})}return n}function el(e){return new Map(e.map(e=>[e.index,e]))}function ed(e){return e.label?.trim()||e.value?.trim()||e.identifier?.trim()||""}function ec(e){if(0===e.length)return{nodes:e,hiddenCount:0,summaryLines:[]};let{byIndex:t,visibleNodeIndexes:n,offscreenNodes:r,hintedContainers:i}=eh(e),a=0===n.size?e:e.filter(e=>n.has(e.index));return{nodes:a.map(e=>(function(e,t){let n=t.get(e.index);if(!n||0===n.size)return e;let r=!!(!0===e.hiddenContentAbove||n.has("above"))||void 0,i=!!(!0===e.hiddenContentBelow||n.has("below"))||void 0;return{...e,hiddenContentAbove:r,hiddenContentBelow:i}})(e,i.directionsByContainer)),hiddenCount:0===n.size?0:e.length-a.length,summaryLines:function(e,t,n){let r=new Map;for(let i of e){let e=function(e,t,n){if(!e.rect)return null;let r=ef(e,t,n);return r?ew(e.rect,r):null}(i,t,n);if(!e)continue;let a=r.get(e)??[];a.push(i),r.set(e,a)}return["above","below"].flatMap(e=>{let t=r.get(e);if(!t||0===t.length)return[];let n=(function(e){let t=new Set,n=[];for(let r of e){let e=ed(r);!e||t.has(e)||(t.add(e),n.push(e))}return n})(t).slice(0,3).map(e=>`"${e}"`),i=1===t.length?"interactive item":"interactive items",a=n.length>0?`: ${n.join(", ")}`:"";return[`[off-screen ${e}] ${t.length} ${i}${a}`]})}(r.filter(e=>!i.coveredNodeIndexes.has(e.index)&&function(e){if(!0===e.hittable)return!0;let t=(e.type??"").toLowerCase();return t.includes("button")||t.includes("link")||t.includes("textfield")||t.includes("edittext")||t.includes("searchfield")||t.includes("checkbox")||t.includes("radio")||t.includes("switch")||t.includes("menuitem")||!!ed(e)}(e)),e,t)}}function eu(e){if(0===e.length)return new Map;let{hintedContainers:t}=eh(e);var n=t.directionsByContainer;let r=new Map;for(let[e,t]of n){let n={};t.has("above")&&(n.hiddenContentAbove=!0),t.has("below")&&(n.hiddenContentBelow=!0),(n.hiddenContentAbove||n.hiddenContentBelow)&&r.set(e,n)}return r}function eh(e){let t=el(e),n=new Set,r=[];for(let i of e){if(ep(i,e,t)){!function(e,t,n){let r=e,i=new Set;for(;r&&!i.has(r.index);)i.add(r.index),t.add(r.index),r="number"==typeof r.parentIndex?n.get(r.parentIndex):void 0}(i,n,t);continue}r.push(i)}let i=function(e,t,n,r){let i=new Map,a=new Map,o=new Set;for(let e of t){if(!e.rect)continue;let t=em(e,n,r);if(!t?.rect)continue;let s=ew(e.rect,t.rect);if(!s)continue;let l=i.get(t.index)??new Set;l.add(s),i.set(t.index,l);let d=a.get(t.index)??new Set;d.add(s),a.set(t.index,d),o.add(e.index)}return function(e,t,n,r,i){for(let a of e){let e=function(e){let t=eo(e.label,e.value);if(!t)return null;let n=new Set;return t.above&&n.add("above"),t.below&&n.add("below"),n.size>0?n:null}(a);if(!e||0===e.size)continue;let o=em(a,t,n);if(!o)continue;let s=r.get(o.index)??new Set,l=i.get(o.index);for(let t of e)(!l||!(l.size>0)||l.has(t))&&s.add(t);r.set(o.index,s)}}(e,n,r,i,a),{directionsByContainer:i,coveredNodeIndexes:o}}(e,r,n,t);return{byIndex:t,visibleNodeIndexes:n,offscreenNodes:r,hintedContainers:i}}function ep(e,t,n=el(t)){var r;if(!e.rect)return!0;let i=ef(e,t,n);return!i||(r=e.rect,ei(r.x,r.x+r.width,i.x,i.x+i.width)&&ei(r.y,r.y+r.height,i.y,i.y+i.height))}function ef(e,t,n=el(t)){var r,i;let a=(r=e,i=n,eb(r,i,e=>!!e.rect)?.rect??null);return a||function(e,t){let n=s(t),r=e.filter(e=>{var t;return!!(t=e.rect)&&Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)}),i=r.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}),a=er(i.map(e=>e.rect).filter(e=>en(e,n.x,n.y)));if(a)return a;let o=er(i.map(e=>e.rect));if(o)return o;let l=er(r.map(e=>e.rect).filter(e=>en(e,n.x,n.y)));return l||null}(t,e.rect??{x:0,y:0,width:0,height:0})}function ew(e,t){return e.y+e.height<=t.y?"above":e.y>=t.y+t.height?"below":null}function em(e,t,n){return eb(e,n,e=>t.has(e.index))}function eb(e,t,n){let r="number"==typeof e.parentIndex?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(i.add(r.index),n(r)&&h(r))return r;r="number"==typeof r.parentIndex?t.get(r.parentIndex):void 0}return null}async function eg(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=await i(r),a=function(e,t,n={}){var r,i,a;let o,s=(e??[]).map((e,t)=>({...e,ref:"ref"in e&&e.ref?e.ref:`e${t+1}`}));if(0===s.length)return{canScroll:!1,emptySnapshot:!0,signature:""};let l=eu(s),d=function(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>h(e)&&eM(e.rect));if(0===a.length)return null;let o=function(e,t){if(void 0===e)return null;let n=t.get(e);for(;n;){if(h(n)&&eM(n.rect))return n;n=void 0===n.parentIndex?void 0:t.get(n.parentIndex)}return null}(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>{var t,n;return e.rect&&(t=e.rect,(n=s).x>=t.x&&n.x<=t.x+t.width&&n.y>=t.y&&n.y<=t.y+t.height)}).sort(eI);if(e.length>0)return e.find(e=>ev(e,t.get(e.index),n))??e[0]??null}let l=a.filter(e=>ev(e,t.get(e.index),n)).sort(eN);return l.length>0?l[0]??null:a.filter(t=>ep(t,e)).sort(eN)[0]??a.sort(eN)[0]??null}(s,l,t,n),c=(d?(r=s,i=d.index,o=new Map(r.map(e=>[e.index,e])),r.filter(e=>e.index===i||function(e,t,n){let r=void 0===e.parentIndex?void 0:n.get(e.parentIndex);for(;r;){if(r.index===t)return!0;r=void 0===r.parentIndex?void 0:n.get(r.parentIndex)}return!1}(e,i,o))):s).map(e=>{let t=e.rect?["x","y","width","height"].map(t=>{var n;return n=e.rect?.[t],"number"==typeof n&&Number.isFinite(n)?n.toFixed(1):""}).join(","):"";return[String(e.index??""),String(e.parentIndex??""),String(e.type??""),String(e.label??""),String(e.value??""),t].join("|")}).join("\n");return d?{canScroll:ev(d,l.get(d.index),t),emptySnapshot:!1,signature:c,scope:[(a=d).identifier,a.label,a.value].map(e=>"string"==typeof e?e.trim():"").find(ek)}:{canScroll:!1,emptySnapshot:!1,signature:c}}(e,t,n);if(r&&a.emptySnapshot)return await eg({edge:t,target:n,captureNodes:i});return a}catch(e){var o,s,l;throw o=t,s=r,l=e,s?new a("COMMAND_FAILED",`Failed to verify scroll ${o} state for scoped container`,{scope:s,hint:`scroll ${o} could not verify the scoped scroll container. Run snapshot -i -c for the current screen and retry with a visible scroll target.`},l):new a("COMMAND_FAILED",`Failed to verify scroll ${o} state`,{hint:`scroll ${o} needs a snapshot showing hidden content ${"bottom"===o?"below":"above"} before it will move.`},l)}}async function ey(e){let t,{edge:n,captureState:r,scroll:i}=e,o=await r();o.scope&&(o=await r(o.scope));let s=0;for(;o.canScroll;){if(s>=40)throw new a("COMMAND_FAILED",`scroll ${n} reached the safety limit before the snapshot showed the edge`,{hint:"The scoped scroll container still reports hidden content. Use a smaller manual scroll + snapshot loop to inspect the current state."});t=await i(),s+=1,o=await r(o.scope)}return{passes:s,result:t}}function ex(e,t,n,r,i){return t&&0===n?`Already at ${t}; no hidden content ${"bottom"===t?"below":"above"} detected`:t?`Scrolled to ${t} with ${n} ${e} passes`:void 0!==i?`Scrolled ${e} by ${i}px`:void 0!==r?`Scrolled ${e} by ${r}`:`Scrolled ${e}`}function ev(e,t,n){return"bottom"===n?!0===e.hiddenContentBelow||t?.hiddenContentBelow===!0:!0===e.hiddenContentAbove||t?.hiddenContentAbove===!0}function ek(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function eI(e,t){return eA(e.rect)-eA(t.rect)}function eN(e,t){return eA(t.rect)-eA(e.rect)}function eA(e){return e?e.width*e.height:0}function eM(e){return!!(e&&e.width>0&&e.height>0)}function eR(e,t,n,r){if(!Number.isFinite(e)||!Number.isInteger(e)||e<n||e>r)throw new a("INVALID_ARGS",`${t} must be an integer between ${n} and ${r}`);return e}let eP=/\b(logbox|redbox|reload js|copy stack|component stack|call stack|runtime error|open debugger to view warnings)\b/,eS=/\b(redbox|runtime error|reload js|copy stack|component stack|call stack)\b/,eO=[/\b[\w.$<>/-]+\.(?:tsx?|jsx?):\d+(?::\d+)?\b/,/\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/],eD=[/^!,\s+/,/^(warn|warning|error):\s+/,/\b(?:possible\s+)?unhandled (?:promise )?rejection\b/],eE=["open debugger to view warnings","getsnapshot should be cached to avoid an infinite loop",'unique "key" prop',"unique 'key' prop","virtualizedlists should never be nested","failed prop type"],e_=new Set(["x","\xd7","✕","✖","⨯"]);function eT(e){return e$(e)}function e$(e){var t,n,r,i,a,o,l,d,c,u;let h,p,f,w,m,b,g,y,x=(h=(t=e).map(eB).join("\n").toLowerCase(),p=ej(t,eX),f=ej(t,eV),w=ej(t,eF,eH),m=ej(t,eq),b=(n=h,eO.some(e=>e.test(n))),g=eG(h),y=(r=h,i=p,a=f,i.length>0||a.length>0||/\b(reload js|copy stack)\b/.test(r)),{dismissNodes:p,minimizeNodes:f,collapsedNodes:w,redBox:(o=h,l=b,d=y,eS.test(o)||eG(o)||l&&d),detected:(c={text:h,hasReactNativeStackFrame:b,hasOverlayControl:y,hasControllessRedBoxText:g,collapsedNodes:w,openDebuggerWarningNodes:m}).collapsedNodes.length>0||c.openDebuggerWarningNodes.length>0||c.hasControllessRedBoxText||c.hasOverlayControl&&(u=c.text,eP.test(u)||c.hasReactNativeStackFrame)}),v=x.detected?function(e){let t=eJ(e.dismissNodes,eW);if(t){let e;var n,r=t,i=(n=t,(e=eQ(n)?.trim().toLowerCase())&&eY(e)?"dismiss":"close");if(!r.rect)throw Error("React Native overlay target node must have rect");return{action:i,point:s(r.rect),rect:r.rect,ref:r.ref,label:eQ(r)}}let a=eJ(e.collapsedNodes.filter(ez),eZ);return a?.rect?{action:"close-collapsed-banner",point:function(e){var t,n;if(!e.rect)throw Error("Collapsed React Native warning node must have rect");let r=Math.min(e.rect.height,52),i=Math.min(36,Math.max(18,.45*r));return{x:Math.round((t=e.rect.x+e.rect.width-i,n=e.rect.x+1,Math.min(e.rect.x+e.rect.width-1,Math.max(n,t)))),y:Math.round(e.rect.y+r/2)}}(a),rect:a.rect,ref:a.ref,label:eQ(a)}:null}(x):null;return{detected:x.detected,redBox:x.redBox,dismissNodes:x.dismissNodes,minimizeNodes:x.minimizeNodes,collapsedNodes:x.collapsedNodes,primaryAction:v}}function eC(e){return[...e.dismissNodes,...e.minimizeNodes,...e.collapsedNodes]}function eL(e){var t;return eF(e.label?.trim())&&!!(t=e.rect)&&t.x<=1&&t.y<=1&&t.width>=300&&t.height>=600}function eU(e,t){let n=e.label?.trim();return!!n&&!!eL(e)&&t.some(e=>e.label?.trim()===n&&eK(e))}function eB(e){return[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(" ")}function eG(e){return/\buncaught\b/.test(e)&&/unable to download asset/.test(e)}function eF(e){let t=e?.trim().toLowerCase();return!!t&&(eE.some(e=>t.includes(e))||eD.some(e=>e.test(t)))}function eq(e){return e.includes("open debugger to view warnings")||/^!,\s+open debugger\b/.test(e)}function eX(e){var t,n;return eY(e)||(t=e,/^close(?:\s*\([^)]*\))?$/i.test(t))||(n=e,e_.has(n))}function eY(e){return/^dismiss(?:\s*\([^)]*\))?$/i.test(e)}function eV(e){return/^minimi[sz]e(?:\b|\s|\()/i.test(e)}function eH(e){return!e.rect||e.rect.height<=180}function ez(e){let t=eQ(e)?.trim().toLowerCase()??"";return(eq(t)||/^!,\s+/.test(t))&&eK(e)}function eK(e){return!!e.rect&&e.rect.width>=120&&e.rect.height>=36&&e.rect.height<=180}function ej(e,t,n=()=>!0){let r=[];for(let i of e)i.ref&&n(i)&&[i.label,i.value,i.identifier].map(e=>e?.trim().toLowerCase()).filter(e=>!!e).some(e=>t(e))&&r.push(i);return r}function eW(e){var t;let n;return[+(!0===(n=[e.type,e.role,e.subrole].join(" ").toLowerCase(),/\b(button|menuitem|link)\b/.test(n))),+(!0===e.hittable),-((t=e.rect)?t.width*t.height:1/0)]}function eJ(e,t){let n=e.filter(e=>e.rect);return 0===n.length?null:n.sort((e,n)=>(function(e,t){for(let n=0;n<e.length;n+=1){let r=e[n]-t[n];if(0!==r)return r}return 0})(t(n),t(e)))[0]??null}function eZ(e){return[+(!0===e.hittable),e.rect?.width??0,e.rect?.y??0]}function eQ(e){return e.label??e.value??e.identifier}let e0=Buffer.from([137,80,78,71,13,10,26,10]),e1=new Map([[0,1],[2,3],[3,1],[4,2],[6,4]]),e2=new Map([[0,new Set([1,2,4,8,16])],[2,new Set([8,16])],[3,new Set([1,2,4,8])],[4,new Set([8,16])],[6,new Set([8,16])]]),e5=[{x:0,y:0,dx:8,dy:8},{x:4,y:0,dx:8,dy:8},{x:0,y:4,dx:4,dy:8},{x:2,y:0,dx:4,dy:4},{x:0,y:2,dx:2,dy:4},{x:1,y:0,dx:2,dy:2},{x:0,y:1,dx:1,dy:2}];class e4{width;height;data;static sync={read:e8,write:e3};constructor(e){this.width=ta(e.width,"width"),this.height=ta(e.height,"height");let t=this.width*this.height*4;if(this.data=e.data?Buffer.from(e.data):Buffer.alloc(t),this.data.length!==t)throw Error(`PNG data length must be ${t} bytes`)}}function e8(e){var t;let{metadata:r,idatChunks:i}=function(e){let t,n=[];for(let r of function*(e){if(!e.subarray(0,e0.length).equals(e0))throw Error("Invalid PNG signature");let t=e0.length;for(;t<e.length;){if(t+12>e.length)throw Error("Truncated PNG chunk");let n=e.readUInt32BE(t),r=e.toString("ascii",t+4,t+8),i=t+8,a=i+n;if(a+4>e.length)throw Error(`Truncated PNG ${r} chunk`);let o=e.subarray(i,a),s=e.readUInt32BE(a);if(ti(e.subarray(t+4,a))!==s)throw Error(`Invalid PNG ${r} chunk CRC`);t=a+4,yield{type:r,data:o}}}(e))if("IHDR"===r.type?t=function(e){var t;if(13!==e.length)throw Error("Invalid PNG IHDR length");let n=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],l=e[12];if(t=a,!e1.has(t))throw Error(`Unsupported PNG color type ${a}`);let d=e2.get(a);if(!d?.has(i))throw Error(`Unsupported PNG color type ${a} with bit depth ${i}`);if(0!==o)throw Error(`Unsupported PNG compression method ${o}`);if(0!==s)throw Error(`Unsupported PNG filter method ${s}`);if(0!==l&&1!==l)throw Error(`Unsupported PNG interlace method ${l}`);return{width:ta(n,"width"),height:ta(r,"height"),bitDepth:i,colorType:a,interlace:l}}(r.data):"IDAT"===r.type?n.push(Buffer.from(r.data)):t=function(e,t){if("PLTE"===e.type){if(!t)throw Error("PNG PLTE appeared before IHDR");t.palette=Buffer.from(e.data)}else if("tRNS"===e.type){if(!t)throw Error("PNG tRNS appeared before IHDR");t.transparency=Buffer.from(e.data)}return t}(r,t),"IEND"===r.type)break;return{metadata:t,idatChunks:n}}(e);if(!r)throw Error("PNG is missing IHDR");if(0===i.length)throw Error("PNG is missing IDAT");let a=function(e,t){let r=function(e){if(0===e.interlace)return function(e,t){return(tt(e)+1)*t}(e,e.height);let t=0;for(let n of e5){let r=e9(e.width,n.x,n.dx),i=e9(e.height,n.y,n.dy);0!==r&&0!==i&&(t+=function(e,t){return(tt(e)+1)*t}({...e,width:r,height:i},i))}return t}(t);try{let t=n(Buffer.concat(e),{maxOutputLength:r});if(t.length!==r)throw Error("PNG pixel data is truncated");return t}catch(e){var i;if((i=e)instanceof Error&&"code"in i&&"ERR_BUFFER_TOO_LARGE"===i.code)throw Error(`PNG pixel data exceeds expected length ${r}`);throw e}}(i,r);return new e4({width:r.width,height:r.height,data:1===r.interlace?function(e,t){let n=Buffer.alloc(t.width*t.height*4),r=0;for(let i of e5){let a=e9(t.width,i.x,i.dx),o=e9(t.height,i.y,i.dy);if(0===a||0===o)continue;let s={...t,width:a,height:o,interlace:0},l=e6({inflated:e,offset:r,scanlineLength:tt(s),height:o,bytesPerPixel:tn(s)});r=l.offset;let d=tt(s);for(let e=0;e<o;e+=1){let r=l.raw.subarray(e*d,(e+1)*d);for(let o=0;o<a;o+=1){let a=i.x+o*i.dx,l=((i.y+e*i.dy)*t.width+a)*4,[d,c,u,h]=e7(r,o,s);n[l]=d,n[l+1]=c,n[l+2]=u,n[l+3]=h}}}return n}(a,r):function(e,t){let n=Buffer.alloc(t.width*t.height*4),r=tt(t);for(let i=0;i<t.height;i+=1){let a=e.subarray(i*r,(i+1)*r);for(let e=0;e<t.width;e+=1){let r=(i*t.width+e)*4,[o,s,l,d]=e7(a,e,t);n[r]=o,n[r+1]=s,n[r+2]=l,n[r+3]=d}}return n}(e6({inflated:a,offset:0,scanlineLength:tt(t=r),height:t.height,bytesPerPixel:tn(t)}).raw,r)})}function e3(e){let n=4*e.width,r=Buffer.alloc((n+1)*e.height);for(let t=0;t<e.height;t+=1){let i=t*(n+1);r[i]=0,e.data.copy(r,i+1,t*n,(t+1)*n)}let i=Buffer.alloc(13);return i.writeUInt32BE(e.width,0),i.writeUInt32BE(e.height,4),i[8]=8,i[9]=6,i[10]=0,i[11]=0,i[12]=0,Buffer.concat([e0,tr("IHDR",i),tr("IDAT",t(r)),tr("IEND",Buffer.alloc(0))])}function e6(e){let{inflated:t,offset:n,scanlineLength:r,height:i,bytesPerPixel:a}=e,o=n+(r+1)*i;if(t.length<o)throw Error("PNG pixel data is truncated");let s=Buffer.alloc(r*i);for(let e=0;e<i;e+=1){let i=n+e*(r+1),o=e*r,l=t[i];for(let n=0;n<r;n+=1){let d=t[i+1+n],c=n>=a?s[o+n-a]:0,u=e>0?s[o+n-r]:0,h=e>0&&n>=a?s[o+n-r-a]:0;s[o+n]=function(e,t,n,r,i){if(0===e)return t;if(1===e)return t+n&255;if(2===e)return t+r&255;if(3===e)return t+Math.floor((n+r)/2)&255;if(4===e)return t+function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}(n,r,i)&255;throw Error(`Unsupported PNG filter type ${e}`)}(l,d,c,u,h)}}return{raw:s,offset:o}}function e9(e,t,n){return e<=t?0:Math.floor((e-t+n-1)/n)}function e7(e,t,n){if(3===n.colorType){var r,i,a,o,s,l,d,c=e,u=t,h=n;if(!h.palette)throw Error("Indexed PNG is missing PLTE");let p=te(c,u,h.bitDepth),f=3*p;if(f+2>=h.palette.length)throw Error("Indexed PNG palette is invalid");return[h.palette[f],h.palette[f+1],h.palette[f+2],h.transparency?.[p]??255]}if(n.bitDepth<8){let i,a;return[a=Math.round((i=te(e,t,(r=n).bitDepth))/((1<<r.bitDepth)-1)*255),a,a,255*!(r.transparency&&r.transparency.length>=2&&i===r.transparency.readUInt16BE(0))]}let p=16===n.bitDepth?2:1,f=t*e1.get(n.colorType)*p,w=t=>16===n.bitDepth?e.readUInt16BE(f+2*t):e[f+t*p],m=e=>{var t;return t=w(e),16===n.bitDepth?Math.round(t/65535*255):t};if(0===n.colorType){let e=m(0);return[e,e,e,255*(i=w(0),!(a=n).transparency||!!(a.transparency.length<2)||i!==a.transparency.readUInt16BE(0))]}if(2===n.colorType){return[m(0),m(1),m(2),255*(o=w(0),s=w(1),l=w(2),!(d=n).transparency||!!(d.transparency.length<6)||o!==d.transparency.readUInt16BE(0)||s!==d.transparency.readUInt16BE(2)||l!==d.transparency.readUInt16BE(4))]}if(4===n.colorType){let e=m(0);return[e,e,e,m(1)]}return[m(0),m(1),m(2),m(3)]}function te(e,t,n){let r=t*n;return e[Math.floor(r/8)]>>8-n-r%8&(1<<n)-1}function tt(e){let t=e1.get(e.colorType);return Math.ceil(e.width*t*e.bitDepth/8)}function tn(e){return Math.max(1,Math.ceil(e1.get(e.colorType)*e.bitDepth/8))}function tr(e,t){let n=Buffer.from(e,"ascii"),r=Buffer.alloc(8+t.length+4);return r.writeUInt32BE(t.length,0),n.copy(r,4),t.copy(r,8),r.writeUInt32BE(ti(Buffer.concat([n,t])),8+t.length),r}function ti(e){let t=0xffffffff;for(let n of e){t^=n;for(let e=0;e<8;e+=1)t=1&t?0xedb88320^t>>>1:t>>>1}return(0xffffffff^t)>>>0}function ta(e,t){if(!Number.isInteger(e)||e<1)throw Error(`PNG ${t} must be positive`);return e}function to(e,t){try{return e4.sync.read(e)}catch(e){throw new a("COMMAND_FAILED",`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}async function ts(t,n){if(!Number.isInteger(n)||n<1)throw new a("INVALID_ARGS","Screenshot max size must be a positive integer");let r=to(await e.readFile(t),"screenshot"),i=Math.max(r.width,r.height);if(i<=n)return;let o=n/i,s=Math.max(1,Math.round(r.width*o)),l=Math.max(1,Math.round(r.height*o)),d=function(e,t,n){let r=new e4({width:t,height:n});for(let i=0;i<n;i+=1){let a=i*e.height/n,o=(i+1)*e.height/n;for(let n=0;n<t;n+=1){let s=n*e.width/t,l=(n+1)*e.width/t,d=0,c=0,u=0,h=0,p=0;for(let t=Math.floor(a);t<Math.ceil(o);t+=1){let n=Math.min(t+1,o)-Math.max(t,a);for(let r=Math.floor(s);r<Math.ceil(l);r+=1){let i=n*(Math.min(r+1,l)-Math.max(r,s)),a=(t*e.width+r)*4;d+=(e.data[a]??0)*i,c+=(e.data[a+1]??0)*i,u+=(e.data[a+2]??0)*i,h+=(e.data[a+3]??0)*i,p+=i}}let f=(i*r.width+n)*4;r.data[f]=Math.round(d/p),r.data[f+1]=Math.round(c/p),r.data[f+2]=Math.round(u/p),r.data[f+3]=Math.round(h/p)}}return r}(r,s,l);await e.writeFile(t,e4.sync.write(d))}async function tl(e,t,n){if("path"===t.kind&&!e.policy.allowLocalInputPaths)throw new a("INVALID_ARGS",`Local ${n.field??"input"} paths are not allowed by command policy`);try{return await e.artifacts.resolveInput(t,n)}catch(e){throw i(e)}}async function td(e,t,n){if(t?.kind==="path"&&!e.policy.allowLocalOutputPaths)throw new a("INVALID_ARGS","Local output paths are not allowed by command policy");try{return await e.artifacts.reserveOutput(t,{...n,visibility:n.visibility??"client-visible",requestedClientPath:t?.kind==="downloadableArtifact"?t.clientPath??n.requestedClientPath:n.requestedClientPath})}catch(e){throw i(e)}}async function tc(e,t){try{return await e.artifacts.createTempFile(t)}catch(e){throw i(e)}}let tu=async(e,t)=>{let n;if(!e.backend.captureScreenshot)throw new a("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");let r=await td(e,t.out,{field:"path",ext:".png"});try{await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,appId:t.appId,appBundleId:t.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},r.path,{fullscreen:t.fullscreen,overlayRefs:t.overlayRefs,stabilize:t.stabilize,surface:t.surface}),void 0!==t.maxSize&&await ts(r.path,t.maxSize),n=await r.publish()}catch(e){throw await r.cleanup?.(),e}return{path:r.path,...n?{artifacts:[n]}:{},...b(`Saved screenshot: ${r.path}`)}},th=[0,187,255,255];function tp(e,t,n,r){if(t<0||t>=e.width||n<0||n>=e.height)return;let i=(n*e.width+t)*4;e.data[i]=r[0],e.data[i+1]=r[1],e.data[i+2]=r[2],e.data[i+3]=r[3]}function tf(e,t,n){return Math.min(Math.max(e,t),n)}let tw=[{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-1,y:0},{x:1,y:0},{x:-1,y:1},{x:0,y:1},{x:1,y:1}];function tm(e){let{mask:t,width:n,height:r,hooks:i}=e,a=new Uint8Array(t.length),o=new Int32Array(t.length),s=[];for(let e=0;e<t.length;e+=1){var l,d;if(!tb(t,a,e))continue;let c=0,u=(l=o,a[d=e]=1,l[0]=d,1),h=i.create(e);for(;c<u;){let e=o[c];c+=1,i.visit(h,e),u=function(e){let{mask:t,visited:n,queue:r,width:i,height:a,pixelIndex:o}=e,s=o%i,l=Math.floor(o/i),d=e.queueEnd;for(let e of tw){var c,u,h,p;let o=s+e.x,f=l+e.y;if(c=o,u=f,h=i,p=a,!(c>=0)||!(c<h)||!(u>=0)||!(u<p))continue;let w=f*i+o;tb(t,n,w)&&(d=function(e,t,n,r){return t[r]=1,e[n]=r,n+1}(r,n,d,w))}return d}({mask:t,visited:a,queue:o,queueEnd:u,width:n,height:r,pixelIndex:e})}s.push(h)}return s}function tb(e,t,n){return 1===e[n]&&1!==t[n]}let tg={icon:90,toggle:90,chevron:75,separator:45,visual:35,background:10},ty={leading:20,trailing:20,separator:10,unknown:0,background:-30};function tx(e){return"background"!==e.likelyKind}function tv(e,t){return e.width>=.25*t.width||e.height>=.06*t.height}function tk(e,t){let n,r=0;for(let i of t){let t=tR(e,i.rect);t<=r||(r=t,n=i)}return n}function tI(e){let t=[];for(let n of[...e].sort((e,t)=>e.rect.y-t.rect.y)){let e=t.find(e=>{var t,r;return t=e.rect,tR(t,r=n.rect)>0||Math.abs(f(t).y-f(r).y)<=.5*Math.max(t.height,r.height)});if(!e){t.push({rect:n.rect,blocks:[n]});continue}e.blocks.push(n),e.blocks.sort((e,t)=>e.rect.x-t.rect.x),e.rect=p([e.rect,n.rect])}return t}function tN(e,t){let n,r=f(e);for(let e of t){let t=Math.sqrt(m(r,f(e.rect)));n&&t>=n.distance||(n={block:e,distance:t})}return n}function tA(e){let t=tM(e);return e.differentPixels>=24&&t.width>=3&&t.height>=3}function tM(e){return{x:e.minX,y:e.minY,width:e.maxX-e.minX+1,height:e.maxY-e.minY+1}}function tR(e,t){return Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}async function tP(e){if(await g("tesseract"))try{let[t,n]=await Promise.all([tO(e.baselinePath),tO(e.currentPath)]);if(0!==t.exitCode||0!==n.exitCode)return;let r=tS(t.stdout,e.width,e.height),i=tS(n.stdout,e.width,e.height),a=function(e,t){let n=new Set,r=[];for(let a of e){var i;let e=tC(a.text),o=function(e,t,n,r){let i=null,a=1/0;for(let o=0;o<n.length;o+=1){if(r.has(o))continue;let s=n[o];if(tC(s.text)!==t)continue;let l=m(f(e.normalizedRect),f(s.normalizedRect));l>=a||(i=o,a=l)}return i}(a,e,t,n);if(null===o)continue;n.add(o);let s=function(e,t){let n={x:t.rect.x-e.rect.x,y:t.rect.y-e.rect.y,width:t.rect.width-e.rect.width,height:t.rect.height-e.rect.height},r=tB(t.rect.width/e.rect.width),i=tB(t.rect.height/e.rect.height),a=Math.abs(r-1)>=.08||Math.abs(i-1)>=.12;return{text:e.text,baselineRect:e.rect,currentRect:t.rect,delta:n,confidence:Math.round(100*Math.min(e.confidence,t.confidence))/100,possibleTextMetricMismatch:a}}(a,t[o]);i=s,(Math.abs(i.delta.x)>=2||Math.abs(i.delta.y)>=2||Math.abs(i.delta.width)>=2||Math.abs(i.delta.height)>=2||i.possibleTextMetricMismatch)&&r.push(s)}return r.sort((e,t)=>tD(t)-tD(e)).slice(0,12)}(r,i),o=function(e){let t=[];for(let n of[...e].sort((e,t)=>e.currentRect.y-t.currentRect.y)){let e=t.find(e=>32>=Math.abs(n.delta.x-tL(e.map(e=>e.delta.x))));e?e.push(n):t.push([n])}return t.filter(e=>e.length>=2).map(tE).filter(e=>e.yRange.max-e.yRange.min<=60).sort((e,t)=>t_(t)-t_(e)).slice(0,4)}(a);if(0===r.length&&0===i.length)return;return{provider:"tesseract",baselineBlocks:r.length,currentBlocks:i.length,baselineBlocksRaw:r,currentBlocksRaw:i,matches:a,...o.length>0?{movementClusters:o}:{}}}catch{return}}function tS(e,t,n){let[r,...i]=e.split(/\r?\n/);if(!r)return[];let a=new Map(r.split(" ").map((e,t)=>[e,t])),o=[];for(let e of i){var s;if(!e.trim())continue;let t=e.split(" "),n=t$(t,a,"level"),r=tT(t,a,"text").trim(),i=t$(t,a,"conf");if(5!==n||(s=r,!/[\p{L}\p{N}]/u.test(s))||i<0)continue;let l=t$(t,a,"left"),d=t$(t,a,"top"),c=t$(t,a,"width"),u=t$(t,a,"height");c<=0||u<=0||o.push({key:[tT(t,a,"page_num"),tT(t,a,"block_num"),tT(t,a,"par_num"),tT(t,a,"line_num")].join(":"),text:r,confidence:i,rect:{x:l,y:d,width:c,height:u}})}let l=new Map;for(let e of o){let t=l.get(e.key);t?t.push(e):l.set(e.key,[e])}return Array.from(l.values()).flatMap(e=>(function(e){let t=[...e].sort((e,t)=>e.rect.x-t.rect.x),n=[],r=[];for(let e of t){let t=r.at(-1);if(!t){r.push(e);continue}if(e.rect.x-(t.rect.x+t.rect.width)>Math.max(48,2.5*Math.max(t.rect.height,e.rect.height))){n.push(r),r=[e];continue}r.push(e)}return r.length>0&&n.push(r),n})(e)).map(e=>(function(e,t,n){if(0===e.length)return null;let r=[...e].sort((e,t)=>e.rect.x-t.rect.x),i=p(r.map(e=>e.rect)),a=Math.round(100*tL(r.map(e=>e.confidence)))/100;return{text:r.map(e=>e.text).join(" "),confidence:a,rect:i,normalizedRect:{x:tU(i.x/t),y:tU(i.y/n),width:tU(i.width/t),height:tU(i.height/n)}}})(e,t,n)).filter(e=>null!==e)}function tO(e){return y("tesseract",[e,"stdout","-l","eng","tsv"],{allowFailure:!0,timeoutMs:1e4})}function tD(e){return Math.abs(e.delta.x)+Math.abs(e.delta.y)+Math.abs(e.delta.width)+Math.abs(e.delta.height)+25*!!e.possibleTextMetricMismatch}function tE(e){let t=e.map(e=>e.delta.x),n=e.map(e=>e.delta.y);return{texts:e.map(e=>e.text),xRange:{min:Math.min(...t),max:Math.max(...t)},yRange:{min:Math.min(...n),max:Math.max(...n)}}}function t_(e){return 2*Math.abs((e.xRange.min+e.xRange.max)/2)+Math.abs((e.yRange.min+e.yRange.max)/2)}function tT(e,t,n){let r=t.get(n);return void 0===r?"":e[r]??""}function t$(e,t,n){let r=Number(tT(e,t,n));return Number.isFinite(r)?r:0}function tC(e){return e.trim().replace(/\s+/g," ").toLowerCase()}function tL(e){return e.reduce((e,t)=>e+t,0)/e.length}function tU(e){return Math.round(100*e*100)/100}function tB(e){return Math.round(1e3*e)/1e3}function tG(e,t,n,r){return{r:Math.round(e/r),g:Math.round(t/r),b:Math.round(n/r)}}function tF(e){return .2126*e.r+.7152*e.g+.0722*e.b}function tq(e){return`#${tX(e.r)}${tX(e.g)}${tX(e.b)}`}function tX(e){return e.toString(16).padStart(2,"0")}function tY(e){return Math.round(100*e*100)/100}let tV=255*Math.sqrt(3);async function tH(t,n,i={}){var a,o,s,l,d;let h,p,f,m;await tz(t,"Baseline image not found"),await tz(n,"Current screenshot not found");let b=i.outputPath,[g,y]=await Promise.all([e.readFile(t),e.readFile(n)]),x=to(g,"baseline screenshot"),v=to(y,"current screenshot");tK(x.width,x.height,"baseline screenshot",i.maxPixels),tK(v.width,v.height,"current screenshot",i.maxPixels);let k=i.threshold??.1;if(x.width!==v.width||x.height!==v.height){let e=x.width*x.height;return await tj(i.outputPath),{match:!1,mismatchPercentage:100,totalPixels:e,differentPixels:e,dimensionMismatch:{expected:{width:x.width,height:x.height},actual:{width:v.width,height:v.height}}}}let I=x.width*x.height,N=k*tV,A=new e4({width:x.width,height:x.height}),M=new Uint8Array(I),R=0;for(let e=0,t=0;e<x.data.length;e+=4,t+=1){if(Math.sqrt((x.data[e]-v.data[e])**2+(x.data[e+1]-v.data[e+1])**2+(x.data[e+2]-v.data[e+2])**2)>N){R+=1,M[t]=1;let n=tW(v,e);A.data[e]=tJ(n,220,.78),A.data[e+1]=tJ(n,0,.78),A.data[e+2]=tJ(n,0,.78),A.data[e+3]=255;continue}let n=tW(v,e);A.data[e]=n,A.data[e+1]=n,A.data[e+2]=n,A.data[e+3]=255}let P=R>0?(o=(h=function(e){let{diffMask:t,baseline:n,current:r}=e,{width:i,height:a}=n;return tm({mask:t,width:i,height:a,hooks:{create:e=>{var t,n;let r,a;return r=(t=e)%(n=i),{minX:r,minY:a=Math.floor(t/n),maxX:r,maxY:a,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0}},visit:(e,t)=>{var a,o,s,l,d;let c,u,h;return a=e,o=t,s=i,l=n,d=r,c=o%s,u=Math.floor(o/s),h=4*o,void(a.minX=Math.min(a.minX,c),a.minY=Math.min(a.minY,u),a.maxX=Math.max(a.maxX,c),a.maxY=Math.max(a.maxY,u),a.differentPixels+=1,a.baselineRed+=l.data[h],a.baselineGreen+=l.data[h+1],a.baselineBlue+=l.data[h+2],a.currentRed+=d.data[h],a.currentGreen+=d.data[h+1],a.currentBlue+=d.data[h+2])}}})}(a={diffMask:M,baseline:x,current:v,totalPixels:I,differentPixels:R,maxRegions:i.maxRegions})).length<=2e3?function(e){let t=[];for(let i of e.sort((e,t)=>{let n=e.minY-t.minY;return 0!==n?n:e.minX-t.minX})){var n,r;let e=t.find(e=>{var t,n,r;return t=e,n=i,r=12,t.minX-r<=n.maxX&&n.minX-r<=t.maxX&&t.minY-r<=n.maxY&&n.minY-r<=t.maxY});if(!e){t.push({...i});continue}n=e,r=i,n.minX=Math.min(n.minX,r.minX),n.minY=Math.min(n.minY,r.minY),n.maxX=Math.max(n.maxX,r.maxX),n.maxY=Math.max(n.maxY,r.maxY),n.differentPixels+=r.differentPixels,n.baselineRed+=r.baselineRed,n.baselineGreen+=r.baselineGreen,n.baselineBlue+=r.baselineBlue,n.currentRed+=r.currentRed,n.currentGreen+=r.currentGreen,n.currentBlue+=r.currentBlue}return t}(h):h,o.flatMap(e=>{var t,n,r;let i;return(t=e,n=a.baseline.width,r=a.baseline.height,i=t.maxX-t.minX+1,t.maxY-t.minY+1>=Math.max(48,Math.round(.07*r))&&i>=.35*n)?function(e,t,n){var r;let i=function(e,t){let n=[],r=null;for(let i=0;i<e.length;i+=1){if(e[i]<=t){r??=i;continue}null!==r&&(i-r>=6&&n.push([r,i-1]),r=null)}return null!==r&&e.length-r>=6&&n.push([r,e.length-1]),n}((r=function(e,t,n){let r=[];for(let i=e.minY;i<=e.maxY;i+=1){let a=0;for(let r=e.minX;r<=e.maxX;r+=1)1===t[i*n+r]&&(a+=1);r.push(a)}return r}(e,t.diffMask,t.baseline.width)).map((e,t)=>{let n=0,i=0,a=Math.max(0,t-3),o=Math.min(r.length-1,t+3);for(let e=a;e<=o;e+=1)n+=r[e],i+=1;return Math.round(n/i)}),Math.max(1,Math.round((e.maxX-e.minX+1)*.08))),a=function(e,t,n){let r=[],i=e.minY;for(let[a,o]of t){let t=e.minY+Math.round((a+o)/2);t-i+1<n||e.maxY-t<n||(r.push([i,t]),i=t+1)}return r.push([i,e.maxY]),r}(e,i,n);if(a.length<=1)return[e];let o=a.map(([n,r])=>(function(e,t,n,r){let i=null;for(let s=t;s<=n;s+=1)for(let t=e.minX;t<=e.maxX;t+=1){var a,o;let e=s*r.baseline.width+t;1===r.diffMask[e]&&function(e,t,n,r,i,a){let o=4*t;e.minX=Math.min(e.minX,n),e.minY=Math.min(e.minY,r),e.maxX=Math.max(e.maxX,n),e.maxY=Math.max(e.maxY,r),e.differentPixels+=1,e.baselineRed+=i.data[o],e.baselineGreen+=i.data[o+1],e.baselineBlue+=i.data[o+2],e.currentRed+=a.data[o],e.currentGreen+=a.data[o+1],e.currentBlue+=a.data[o+2]}(i??={minX:a=t,minY:o=s,maxX:a,maxY:o,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0},e,t,s,r.baseline,r.current)}return i})(e,n,r,t)).filter(e=>null!==e);return o.length>1?o:[e]}(e,a,Math.max(24,Math.round(.03*a.baseline.height))):[e]})).sort((e,t)=>{let n=t.differentPixels-e.differentPixels;if(0!==n)return n;let r=e.minY-t.minY;return 0!==r?r:e.minX-t.minX}).slice(0,Math.max(0,a.maxRegions??8)).map((e,t)=>{var n,r,i,o,s,l,d,c,u,h,p;let f,w,m,b,g,y,x,v,k,I,N,A,M,R,P,S,O;return n=e,r=t+1,i={width:a.baseline.width,height:a.baseline.height,totalPixels:a.totalPixels,differentPixels:a.differentPixels},y={x:n.minX,y:n.minY,width:n.maxX-n.minX+1,height:n.maxY-n.minY+1},x={x:Math.round(n.minX+y.width/2),y:Math.round(n.minY+y.height/2)},v=tG(n.baselineRed,n.baselineGreen,n.baselineBlue,n.differentPixels),k=tG(n.currentRed,n.currentGreen,n.currentBlue,n.differentPixels),I=y.width*y.height,N=tY(n.differentPixels/I),A=Math.round(tF(v)),M=Math.round(tF(k)),R=(o=y,s=i.width,l=i.height,o.width>=.55*s&&o.height>=.12*l?"large-area":o.width>=2.5*o.height?"horizontal-band":o.height>=2.5*o.width?"vertical-band":"compact"),P=(f=I/i.totalPixels)>=.04?"large":f>=.01?"medium":"small",S=(d=v,c=k,w=tF(d),Math.abs(m=tF(c)-w)>=12?m>0?"brighter":"darker":Math.max(Math.abs(c.r-d.r),Math.abs(c.g-d.g),Math.abs(c.b-d.b))>=12?"color-shift":"mixed"),O=(u=x,h=i.width,p=i.height,b=u.x<h/3?"left":u.x>2*h/3?"right":"center",g=u.y<p/3?"top":u.y>2*p/3?"bottom":"middle","center"===b&&"middle"===g?"center":`${g}-${b}`),{index:r,rect:y,normalizedRect:{x:tY(y.x/i.width),y:tY(y.y/i.height),width:tY(y.width/i.width),height:tY(y.height/i.height)},differentPixels:n.differentPixels,shareOfDiffPercentage:tY(n.differentPixels/i.differentPixels),densityPercentage:N,shape:R,size:P,location:O,averageBaselineColorHex:tq(v),averageCurrentColorHex:tq(k),baselineLuminance:A,currentLuminance:M,dominantChange:S}}):[];if(R>0&&b){for(let e of P)e.rect.width<4||e.rect.height<4||function(e,t){let n=tf(t.x,0,e.width-1),r=tf(t.y,0,e.height-1),i=tf(t.x+t.width-1,0,e.width-1),a=tf(t.y+t.height-1,0,e.height-1);for(let t=0;t<2;t+=1){for(let o=n;o<=i;o+=1)tp(e,o,r+t,th),tp(e,o,a-t,th);for(let o=r;o<=a;o+=1)tp(e,n+t,o,th),tp(e,i-t,o,th)}}(A,e.rect);await e.mkdir(r.dirname(b),{recursive:!0}),await e.writeFile(b,e4.sync.write(A))}else await tj(i.outputPath);let S=R>0?await tP({baselinePath:t,currentPath:n,width:x.width,height:x.height}):void 0,O=S&&(S.matches.length>0||(S.movementClusters?.length??0)>0)?{provider:S.provider,baselineBlocks:S.baselineBlocks,currentBlocks:S.currentBlocks,matches:S.matches,...S.movementClusters?{movementClusters:S.movementClusters}:{}}:void 0,D=R>0&&S?(p=function(e){let t=[];for(let n of e.sort((e,t)=>e.minY-t.minY||e.minX-t.minX)){let e=t.find(e=>{var t,r,i;return t=e,r=n,i=10,t.minX-i<=r.maxX&&r.minX-i<=t.maxX&&t.minY-i<=r.maxY&&r.minY-i<=t.maxY});if(!e){t.push({...n});continue}e.minX=Math.min(e.minX,n.minX),e.minY=Math.min(e.minY,n.minY),e.maxX=Math.max(e.maxX,n.maxX),e.maxY=Math.max(e.maxY,n.maxY),e.differentPixels+=n.differentPixels}return t}((l=function(e,t,n,r){let i=new Uint8Array(e);if(!r)return i;for(let e of[...r.baselineBlocksRaw,...r.currentBlocksRaw])!function(e,t,n,r){let i=w(Math.floor(r.x),0,t-1),a=w(Math.floor(r.y),0,n-1),o=w(Math.ceil(r.x+r.width),0,t),s=w(Math.ceil(r.y+r.height),0,n);for(let n=a;n<s;n+=1)for(let r=i;r<o;r+=1)e[n*t+r]=0}(i,t,n,c(e.rect,8));return i}((s={diffMask:M,width:x.width,height:x.height,regions:P,ocr:S}).diffMask,s.width,s.height,s.ocr),d=s.width,tm({mask:l,width:d,height:s.height,hooks:{create:e=>{var t,n;let r,i;return r=(t=e)%(n=d),{minX:r,minY:i=Math.floor(t/n),maxX:r,maxY:i,differentPixels:0}},visit:(e,t)=>{var n,r,i;let a,o;return n=e,a=(r=t)%(i=d),o=Math.floor(r/i),void(n.minX=Math.min(n.minX,a),n.minY=Math.min(n.minY,o),n.maxX=Math.max(n.maxX,a),n.maxY=Math.max(n.maxY,o),n.differentPixels+=1)}}}))),f=tI(s.ocr?.currentBlocksRaw??[]),m=tI(s.ocr?.baselineBlocksRaw??[]),p.filter(tA).map(e=>{var t,n,r,i,a,o,l,d,c,h,p;let w,b,g,y,x,v,k,I,N,A;return t=e,n=s,r=f,i=m,y=function(e,t){let n,r=0;for(let i of t){let t=u(e,i.rect);t<=r||(r=t,n=i)}return n?.index}(g=tM(t),n.regions),x=function(e,t,n){let r=tk(e,t);if(r)return tN(e,r.blocks);let i=tk(e,n);return i?tN(e,i.blocks):void 0}(g,r,i),v=function(e,t,n){if(e.height<=3&&e.width>=.12*n)return"separator";if(!t)return e.width>=.4*n?"background":"unknown";if(e.width>=.4*n)return"background";let r=e.x+e.width/2,i=t.x+t.width/2;return r<i-t.width/2?"leading":r>i+t.width/2?"trailing":e.width>=.35*n?"background":"unknown"}(g,x?.block.rect,n.width),k=(a=g,o=v,l=t.differentPixels,d=n,w=a.width/a.height,b=l/(a.width*a.height),"separator"===o?"separator":"background"===o?"background":"trailing"===o&&w>=1.5&&w<=3.8&&b>=.35?"toggle":"trailing"===o&&a.width<=.06*d.width&&a.height<=.04*d.height?"chevron":"leading"===o&&w>=.55&&w<=1.8?"icon":tv(a,d)?"background":"visual"),I={...y?{regionIndex:y}:{},slot:v,likelyKind:k,rect:g},{...y?{regionIndex:y}:{},slot:v,likelyKind:k,rect:g,...x?{nearestText:x.block.text.trim().replace(/^[^\p{L}\p{N}]+/u,"").replace(/^\p{L}\s+/u,"")}:{},score:(c=I,h=t.differentPixels,p=n,N=tv(c.rect,p)?-35:0,A=20*!!c.regionIndex,tg[c.likelyKind]+ty[c.slot]+A+N+Math.min(20,h/200))}}).filter(e=>e.rect.y>=.08*s.height).filter(tx).sort((e,t)=>t.score-e.score).slice(0,Math.max(0,s.maxDeltas??12)).map((e,t)=>{var n;return n=e,{index:t+1,...n.regionIndex?{regionIndex:n.regionIndex}:{},slot:n.slot,likelyKind:n.likelyKind,rect:n.rect,...n.nearestText?{nearestText:n.nearestText}:{}}})):[],E=I>0?Math.round(R/I*1e4)/100:0;return{...R>0&&b?{diffPath:b}:{},...P.length>0?{regions:P}:{},...O?{ocr:O}:{},...D.length>0?{nonTextDeltas:D}:{},totalPixels:I,differentPixels:R,mismatchPercentage:E,match:0===R}}async function tz(t,n){try{await e.access(t)}catch{throw new a("INVALID_ARGS",`${n}: ${t}`)}}function tK(e,t,n,r){if(null==r||r<=0)return;let i=e*t;if(!(i<=r))throw new a("INVALID_ARGS",`${n} is ${i} pixels, which exceeds the configured maxImagePixels limit of ${r}`)}async function tj(t){if(t)try{await e.unlink(t)}catch(e){var n;if(!("object"==typeof(n=e)&&null!==n&&"code"in n&&"ENOENT"===n.code))throw e}}function tW(e,t){return tJ(Math.round(.299*e.data[t]+.587*e.data[t+1]+.114*e.data[t+2]),255,.72)}function tJ(e,t,n){return Math.round(e*(1-n)+t*n)}function tZ(e){return e.width*e.height}function tQ(e){return Math.round(100*e*100)/100}async function t0(e,t){let n=await tc(e,{prefix:"agent-device-diff-current",ext:".png"});try{await t2(e,t,n.path,t5(t))}catch(e){throw await n.cleanup(),e}return n}async function t1(e,t,n,r,i){var a,o,s,l;if(!t.overlayRefs)return r;if(r.match||r.dimensionMismatch)return n&&await t8(n),r;let d=(a=t,o=n,a.currentOverlayOut?a.currentOverlayOut:a.out?.kind==="path"?{kind:"path",path:t4(o??a.out.path)}:a.out?.kind==="downloadableArtifact"?{kind:"downloadableArtifact",...a.out.clientPath?{clientPath:t4(a.out.clientPath)}:{},...a.out.fileName?{fileName:t4(a.out.fileName)}:{}}:void 0),c=await td(e,d,{field:"currentOverlayPath",ext:".png"});try{let n=await t2(e,t,c.path,{overlayRefs:!0,...t5(t)}),a=await c.publish();return a&&i.push(a),{...r,currentOverlayPath:n.path??c.path,...n.overlayRefs?{currentOverlayRefCount:n.overlayRefs.length}:{},...r.regions&&n.overlayRefs?{regions:(s=r.regions,l=n.overlayRefs,s.map(e=>{var t,n;let r,i=(t=e,n=l,r=tZ(t.rect),n.map(e=>{let n=e.overlayRect,i=u(t.rect,n);return i<=0?null:{ref:e.ref,...e.label?{label:e.label}:{},rect:n,overlayCoveragePercentage:tQ(i/tZ(n)),regionCoveragePercentage:tQ(i/r)}}).filter(e=>null!==e).sort((e,t)=>{let n=t.regionCoveragePercentage-e.regionCoveragePercentage;return 0!==n?n:t.overlayCoveragePercentage-e.overlayCoveragePercentage}).slice(0,3).map(e=>({ref:e.ref,...e.label?{label:e.label}:{},rect:e.rect,regionCoveragePercentage:e.regionCoveragePercentage})));return i.length>0?{...e,currentOverlayMatches:i}:e}))}:{}}}catch(e){throw await c.cleanup?.(),e}}async function t2(e,t,n,r={}){if(!e.backend.captureScreenshot)throw new a("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");return await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata},n,r)??{}}function t5(e){return e.surface?{surface:e.surface}:{}}function t4(e){let t=r.extname(e),n=t?e.slice(0,-t.length):e;return`${n}.current-overlay${t||".png"}`}async function t8(t){try{await e.unlink(t4(t))}catch(e){var n;if(!("object"==typeof(n=e)&&null!==n&&"code"in n&&"ENOENT"===n.code))throw e}}function t3(e){return"live"===e.kind}let t6={application:"application",navigationbar:"navigation-bar",tabbar:"tab-bar",button:"button",imagebutton:"button",link:"link",cell:"cell",statictext:"text",checkedtextview:"text",textfield:"text-field",edittext:"text-field",textarea:"text-view",switch:"switch",slider:"slider",image:"image",imageview:"image",webview:"webview",framelayout:"group",linearlayout:"group",relativelayout:"group",constraintlayout:"group",viewgroup:"group",view:"group",listview:"list",recyclerview:"list",collectionview:"collection",searchfield:"search",segmentedcontrol:"segmented-control",group:"group",window:"window",checkbox:"checkbox",radio:"radio",menuitem:"menu-item",toolbar:"toolbar",scrollarea:"scroll-area",scrollview:"scroll-area",nestedscrollview:"scroll-area",table:"table"};function t9(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||"",o=nt(i.type??"Element");if("group"===o&&!a)continue;for(;n.length>0&&e<=n[n.length-1];)n.pop();let s=n.length;n.push(e),r.push({node:i,depth:s,type:o,text:t7(i,s,!1,o,t)})}return r}function t7(e,t,n,r,i={}){var a,o,s,l,d,c,u,h;let p,f=r??nt(e.type??"Element"),w=T(e,f),m=(a=e,o=f,s=i,l=w,s.summarizeTextSurfaces&&l.shouldSummarize&&function(e,t,n){let r=x(e.label);if(r&&r!==n)return r;let i=x(e.identifier);if(i&&!nr(i)&&i!==n)return i;switch(t){case"text":case"text-view":return"Text view";case"text-field":return"Text field";case"search":return"Search field";default:return""}}(a,o,l.text)||ne(a,o)),b=" ".repeat(t),g=e.ref?`@${e.ref}`:"",y=(d=e,c=f,u=i,h=w,p=[],(!1===d.enabled&&p.push("disabled"),u.summarizeTextSurfaces)?(!0===d.selected&&p.push("selected"),!0===d.focused&&p.push("focused"),nn(c)&&p.push("editable"),function(e,t){if("scroll-area"===t)return!0;let n=(e.type??"").toLowerCase(),r=`${e.role??""} ${e.subrole??""}`.toLowerCase();return n.includes("scroll")||r.includes("scroll")}(d,c)&&p.push("scrollable"),p.push(...d.presentationHints??[]),h.shouldSummarize&&(p.push(`preview:"${R(h.text).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`),p.push("truncated")),ni(p)):p).map(e=>` [${e}]`).join(""),v=m?` "${m}"`:"";return n?`${b}${g} [${f}]${y}`.trimEnd():`${b}${g} [${f}]${v}${y}`.trimEnd()}function ne(e,t){var n,r;let i=e.label?.trim();if(i&&(n=t,r=i,("scroll-area"===n||"list"===n||"collection"===n||"table"===n)&&ea(r)))return"";let a=e.value?.trim();if(nn(t)){if(a)return a;if(i)return i}else if(i)return i;if(a)return a;let o=e.identifier?.trim();return!o||nr(o)&&("group"===t||"image"===t||"list"===t||"collection"===t)?"":o}function nt(e){var t;let n=e.replace(/XCUIElementType/gi,"").toLowerCase(),r=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));return(n.includes(".")&&(n=n.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,""),r&&n.includes(".")&&(n=n.slice(n.lastIndexOf(".")+1))),"textview"===n)?r?"text":"text-view":(t=n,(Object.prototype.hasOwnProperty.call(t6,t)?t6[t]:void 0)||n||"element")}function nn(e){return"text-field"===e||"text-view"===e||"search"===e}function nr(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function ni(e){return[...new Set(e)]}function na(e,t){let n=nt(e.type??"Element"),r=ne(e,n),i=!1===e.enabled?"disabled":"enabled",a=!0===e.selected?"selected":"unselected",o=!0===e.hittable?"hittable":"not-hittable";return[String(t??e.depth??0),n,r,i,a,o].join("|")}function no(e,t){return t.flatten?e.map(e=>({text:t7(e,0,!1),comparable:na(e,0)})):t9(e).map(e=>({text:e.text,comparable:na(e.node,e.depth)}))}function ns(e,t){return e.get(t)??0}function nl(e){return e.map(e=>({index:e.index,depth:e.depth,parentIndex:e.parentIndex,type:e.type,role:e.role,subrole:e.subrole,label:e.label,value:e.value,identifier:e.identifier,enabled:e.enabled,selected:e.selected,focused:e.focused,hittable:e.hittable,rect:e.rect,bundleId:e.bundleId,appName:e.appName,windowTitle:e.windowTitle,surface:e.surface,hiddenContentAbove:e.hiddenContentAbove,hiddenContentBelow:e.hiddenContentBelow}))}function nd(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function nc(e){return e.clock?.now()??Date.now()}async function nu(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}async function nh(e,t){var n,r,i,o,s,d;let c,u,h,p;if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let f=t.session??"default",w=await e.sessions.get(f),m=await e.backend.captureSnapshot({session:f,requestId:t.requestId,appId:w?.appId,appBundleId:w?.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},{interactiveOnly:t.interactiveOnly,compact:t.compact,depth:t.depth,scope:t.scope,raw:t.raw}),b=(r=m,i=e,n=r.snapshot?r.snapshot:{nodes:r.nodes??[],truncated:r.truncated,backend:r.backend,createdAt:nc(i)},n.presentationKey?n:{...n,presentationKey:l(t)}),g=nc(e);return{snapshot:b,result:m,session:w,warnings:((c=[...(o={result:m,snapshot:b,options:t,session:w,capturedAt:b.createdAt??g,runtimeNow:g}).result.warnings??[]]).push(...function(e){let t=e.result.analysis;if("android"!==e.snapshot.backend||!0!==e.options.interactiveOnly||e.snapshot.nodes.length>0||!t||(t.rawNodeCount??0)<12)return[];let n=[`Interactive snapshot is empty after filtering ${t.rawNodeCount} raw Android nodes. Likely causes: the app content is not accessibility-visible yet, a transient route change, or depth/filter options hid the target.`];return"number"==typeof e.options.depth&&"number"==typeof t.maxDepth&&t.maxDepth>=e.options.depth+2&&n.push(`Interactive output is empty at depth ${e.options.depth}; retry without -d.`),n}(o)),(u=function(e){if(e?.backend!=="uiautomator-dump")return;let t=e.fallbackReason?` Reason: ${e.fallbackReason}`:"";return`Android snapshot helper unavailable; using stock UIAutomator dump, which can time out on busy React Native UIs.${t}`}(o.result.androidSnapshot))&&c.push(u),(h=function(e){if(e$(e).detected)return"Hint: React Native warning/error overlay detected. It overlays part of the app and should be handled before interacting.\nRun: agent-device react-native dismiss-overlay\nThe command verifies the overlay is gone. Run agent-device snapshot -i -c afterward only when you need fresh refs for the next action."}(o.snapshot.nodes))&&c.push(h),(p=function(e){var t,n;let r=e.session?.snapshot,i=!!r&&[e.capturedAt,e.runtimeNow].some(e=>{let t=e-r.createdAt;return t>=0&&t<=2e3});if(!e.result.freshness&&r&&i&&(t=r.nodes.length,n=e.snapshot.nodes.length,!(t<12)&&n<=Math.floor(.2*t)))return nf}(o))&&c.push(p),c.push(...(s=o.result.freshness,d=o.snapshot.backend,s?.staleAfterRetries&&"android"===d?"stuck-route"===s.reason?[`Recent ${s.action} was followed by a nearly identical snapshot after ${s.retryCount} automatic retr${1===s.retryCount?"y":"ies"}. If you expected navigation or submit, the tree may still be stale. Use screenshot as visual truth, wait briefly, then re-snapshot once.`]:"sharp-drop"===s.reason?[nf]:[]:[])),Array.from(new Set(c)))}}function np(e,t){let n=t.session?.name??e??"default";return{...t.session??{name:n},name:n,snapshot:t.snapshot,appName:t.result.appName??t.session?.appName,appBundleId:t.result.appBundleId??t.session?.appBundleId}}let nf="Recent snapshots dropped sharply in node count, which suggests stale or mid-transition UI. Use screenshot as visual truth, wait briefly, then re-snapshot once.";function nw(e){return["visible","hidden","exists","editable","selected","text"].includes(e)}function nm(e){let{predicate:t,node:n,nodes:r,expectedText:i,platform:a}=e,o=v(n),s=M(n,a),l=!0===n.selected,d="text"===t?N(n):function(e,t,n){var r,i,a;let o;if("android"===n&&!1===e.visibleToUser)return!1;if(nb(e.rect))return function(e,t){return ep(e,t)}(e,t);if(e.rect)return!1;if("android"!==n&&!0===e.hittable)return!0;let s=(r=e,i=t,a=n,o=A(i),k(i,r,o,e=>!function(e,t){if("android"===t&&!1===e.visibleToUser)return!1;let n=L(e.type??"");return!(n.includes("application")||n.includes("window")||n.includes("scrollview")||n.includes("tableview")||n.includes("collectionview"))&&"table"!==n&&"list"!==n&&"listview"!==n&&("android"===t?!0===e.hittable&&nb(e.rect):!0===e.hittable||nb(e.rect))}(e,a)?null:e));return!!s&&(nb(s.rect)?function(e,t){return ep(e,t)}(s,t):"android"!==n&&!0===s.hittable)}(n,r,a),c=!1;switch(t){case"visible":c=d;break;case"hidden":c=!d;break;case"editable":c=s;break;case"selected":c=l;break;case"text":c=o===(i??"")}let u="text"===t?`expected="${i??""}" actual="${o}"`:`actual=${JSON.stringify({visible:d,editable:s,selected:l})}`;return{pass:c,actualText:o,details:u}}function nb(e){return!!(e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0)}async function ng(e,t){let n=t??"default",r=await e.sessions.get(n);if(!r)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");if(!r.snapshot)throw new a("INVALID_ARGS","No snapshot in session. Run snapshot first.");return{sessionName:n,session:r,snapshot:r.snapshot}}async function ny(e,t,n={updateSession:!0}){let r=e.backend.captureSnapshot;if(!r)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let i=t.session??"default",o=await e.sessions.get(i),s=await r(nd(e,t),{interactiveOnly:!1,compact:!1,depth:t.depth,scope:n.scope??t.scope,raw:t.raw}),l=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,createdAt:nc(e)};return n.updateSession&&o&&await e.sessions.set({...o,snapshot:l}),{sessionName:i,session:o,snapshot:l}}async function nx(e,t,n){if(e.backend.readText){let r=await e.backend.readText(nd(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return $(n)}let nv=async(e,t)=>{if("ref"===t.target.kind){let n=await ng(e,t.session),r=function(e,t,n){let r=o(t);if(!r)throw new a("INVALID_ARGS",n.invalidRefMessage);let i=d(e,r)??(n.fallbackLabel.length>0?E(e,n.fallbackLabel):null);if(!i)throw new a("COMMAND_FAILED",n.notFoundMessage);return{ref:r,node:i}}(n.snapshot.nodes,t.target.ref,{fallbackLabel:t.target.fallbackLabel??"",invalidRefMessage:"get text requires a ref like @e2",notFoundMessage:`Ref ${t.target.ref} not found`}),i=S(r.node,e.backend.platform,{action:"get"}),s={kind:"ref",ref:`@${r.ref}`};return"attrs"===t.property?{kind:"attrs",target:s,node:r.node,selectorChain:i}:{kind:"text",target:s,text:await nx(e,n,r.node),node:r.node,selectorChain:i}}let n=await nT(e,t,t.session??"default",{selector:t.target.selector,disambiguateAmbiguous:"text"===t.property}),r=S(n.node,e.backend.platform,{action:"get"});if("attrs"===t.property)return{kind:"attrs",target:{kind:"selector",selector:n.selector},node:n.node,selectorChain:r};let i=await nx(e,n.capture,n.node);return{kind:"text",target:{kind:"selector",selector:n.selector},text:i,node:n.node,selectorChain:r}},nk=async(e,t)=>{let n=await nv(e,{...t,property:"text",target:t.target});if("text"!==n.kind)throw new a("COMMAND_FAILED","getText returned non-text result");return n},nI=async(e,t)=>{let n=await nv(e,{...t,property:"attrs",target:t.target});if("attrs"!==n.kind)throw new a("COMMAND_FAILED","getAttrs returned non-attrs result");return n},nN=async(e,t)=>{if(!nw(t.predicate))throw new a("INVALID_ARGS","is requires predicate: visible|hidden|exists|editable|selected|text");if("text"===t.predicate&&!t.expectedText)throw new a("INVALID_ARGS","is text requires expected text value");let n=await ny(e,t,{updateSession:!0}),r=I(t.selector);if("exists"===t.predicate){let i=O(n.snapshot.nodes,r,{platform:e.backend.platform});if(!i)throw new a("COMMAND_FAILED",C(r,[],{unique:!1}));return{predicate:t.predicate,pass:!0,selector:i.selector.raw,matches:i.matches,selectorChain:r.selectors.map(e=>e.raw)}}let i=D(n.snapshot.nodes,r,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:!1});if(!i)throw new a("COMMAND_FAILED",C(r,[],{unique:!0}),{command:"is",reason:"selector_not_found",predicate:t.predicate,selector:r.raw});let o=nm({predicate:t.predicate,node:i.node,nodes:n.snapshot.nodes,expectedText:t.expectedText,platform:e.backend.platform});if(!o.pass)throw new a("COMMAND_FAILED",`is ${t.predicate} failed for selector ${i.selector.raw}: ${o.details}`,{command:"is",reason:"predicate_failed",predicate:t.predicate,selector:i.selector.raw,predicateDetails:o.details});return{predicate:t.predicate,pass:!0,selector:i.selector.raw,..."text"===t.predicate?{text:o.actualText}:{},selectorChain:r.selectors.map(e=>e.raw)}},nA=async(e,t)=>await nN(e,{...t,predicate:"visible",selector:t.target.selector}),nM=async(e,t)=>await nN(e,{...t,predicate:"hidden",selector:t.target.selector}),nR=async(e,t)=>{if("sleep"===t.target.kind)return await nu(e,t.target.durationMs),{kind:"sleep",waitedMs:t.target.durationMs};if("ref"===t.target.kind){let n=await ng(e,t.session),r=o(t.target.ref);if(!r)throw new a("INVALID_ARGS",`Invalid ref: ${t.target.ref}`);let i=d(n.snapshot.nodes,r),s=i?_(i,n.snapshot.nodes):void 0;if(!s)throw new a("COMMAND_FAILED",`Ref ${t.target.ref} not found or has no label`);return await nE(e,t,s,t.target.timeoutMs)}if("selector"===t.target.kind)return await nD(e,t,t.target.selector,t.target.timeoutMs);if(!t.target.text)throw new a("INVALID_ARGS","wait requires text");return await nE(e,t,t.target.text,t.target.timeoutMs)},nP=async(e,t)=>{let n=await nR(e,{...t,target:{kind:"text",text:t.text,timeoutMs:t.timeoutMs}});if("text"!==n.kind)throw new a("COMMAND_FAILED","waitForText returned non-text result");return n};async function nS(e,t,n){let r=t.timeoutMs??1e4,i=nc(e);for(;nc(e)-i<r;){let{match:r}=await nO(e,t,n);if(r)return{kind:"found",found:!0,waitedMs:nc(e)-i};await nu(e,300)}throw new a("COMMAND_FAILED","find wait timed out")}async function nO(e,t,n){let r=await ny(e,t,{updateSession:!0,scope:"text"===n||"label"===n||"any"===n?t.query:void 0}),i=B(r.snapshot.nodes,n,t.query,{requireRect:!1}).matches[0];return{capture:r,match:i}}async function nD(e,t,n,r){let i=r??1e4,o=nc(e),s=I(n);for(;nc(e)-o<i;){let n=O((await ny(e,t,{updateSession:!0})).snapshot.nodes,s,{platform:e.backend.platform});if(n)return{kind:"selector",selector:n.selector.raw,waitedMs:nc(e)-o};await nu(e,300)}throw new a("COMMAND_FAILED",`wait timed out for selector: ${n}`)}async function nE(e,t,n,r){let i=r??1e4,o=nc(e);for(;nc(e)-o<i;){if(e.backend.findText?(await e.backend.findText(nd(e,t),n)).found:await n_(e,t,n))return{kind:"text",text:n,waitedMs:nc(e)-o};await nu(e,300)}throw new a("COMMAND_FAILED",`wait timed out for text: ${n}`)}async function n_(e,t,n){return!!E((await ny(e,t,{updateSession:!0})).snapshot.nodes,n)}async function nT(e,t,n,r){let i=await ny(e,{...t,session:n},{updateSession:!0}),o=I(r.selector),s=D(i.snapshot.nodes,o,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:r.disambiguateAmbiguous});if(!s)throw new a("COMMAND_FAILED",C(o,[],{unique:!0}));return{capture:i,node:s.node,selector:s.selector.raw,ref:`@${s.node.ref}`}}function n$(e){let t=nC(e);if(!t)return null;let n=s(t);return Number.isFinite(n.x)&&Number.isFinite(n.y)?n:null}function nC(e){if(!e)return null;let t=Number(e.x),n=Number(e.y),r=Number(e.width),i=Number(e.height);return Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(r)&&Number.isFinite(i)&&!(r<0)&&!(i<0)?{x:t,y:n,width:r,height:i}:null}function nL(e){return{x:nU(e.x,e.width),y:nU(e.y,e.height)}}function nU(e,t){if(t<=1)return Math.floor(e);let n=Math.ceil(e);return Math.round(Math.min(Math.floor(e+t-1),Math.max(n,e+t/2)))}let nB=["button","link","menuitem","tabitem","textfield","searchfield","securetextfield","checkbox","radio","switch","cell"];function nG(e,t){return nF(e,t).node}function nF(e,t){var n;let r=function(e,t){let n=nC(t.rect);if(!n)return null;let r=t,i=new Set;for(;!i.has(r.ref);){i.add(r.ref);let t=e.filter(e=>{if(e.parentIndex!==r.index||!e.hittable)return!1;let t=nC(e.rect);return!!t&&nX(t,n)});if(1!==t.length)break;let a=t[0];if(void 0===a)break;r=a}return r===t?null:r}(e,t);if(r?.rect&&n$(r.rect))return{node:r,reason:"same-rect-descendant"};if([(n=t).type,n.role,n.subrole].map(e=>L(e??"")).some(nq)&&t.rect&&n$(t.rect))return{node:t,reason:"semantic-target"};let i=P(e,t);return i?.rect&&n$(i.rect)?!function(e,t,n){var r,i;let a,o,l,d=nC(e.rect),c=nC(t.rect);if(!d||!c)return!1;let h=function(e,t){let n=s(t),r=e.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}).map(e=>nC(e.rect)).filter(e=>null!==e);if(0===r.length)return null;let i=r.filter(e=>en(e,n.x,n.y));return er(i.length>0?i:r)}(n,d);return!!h&&(a=u(r=c,i=h),o=r.width*r.height,l=i.width*i.height,!(a<=0)&&!(o<=0)&&!(l<=0)&&!!(a/l>=.9)&&!!(a/o>=.8))&&!nX(d,c)}(t,i,e)?{node:i,reason:"hittable-ancestor"}:{node:t,reason:"overly-broad-ancestor"}:{node:t,reason:"original"}}function nq(e){return"tab"===e||nB.some(t=>e.includes(t))}function nX(e,t){return .5>=Math.abs(e.x-t.x)&&.5>=Math.abs(e.y-t.y)&&.5>=Math.abs(e.width-t.width)&&.5>=Math.abs(e.height-t.height)}async function nY(e,t,n){if(await nH(e,t,n.action),"point"===t.target.kind)return{kind:"point",point:{x:t.target.x,y:t.target.y}};if("ref"===t.target.kind){let r=await nK(e,t,t.target),i=r.resolved,s=n.promoteToHittableAncestor?nG(r.snapshot.nodes,i.node):i.node;return function(e,t,n,r){let i=e.rect?ef(e,t):null;if(!(!e.rect||!i||ep(e,t)))throw new a("COMMAND_FAILED",`Ref ${n} is off-screen and not safe to ${r}`,{reason:"offscreen_ref",ref:o(n),rect:e.rect,viewport:i,hint:`Use scroll with the direction from the off-screen summary, take a fresh snapshot, then retry ${r} with the new ref or a selector.`})}(s,r.snapshot.nodes,t.target.ref,n.action),{kind:"ref",point:nW(s,`Ref ${t.target.ref} not found or has invalid bounds`),target:{kind:"ref",ref:`@${i.ref}`},node:s,selectorChain:S(s,e.backend.platform,{action:"fill"===n.action?"fill":"click"}),refLabel:_(s,r.snapshot.nodes)}}let r=await nV(e,t,n.requireInteractive),i=I(t.target.selector),s=D(r.snapshot.nodes,i,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if(!s||!s.node.rect)throw new a("COMMAND_FAILED",C(i,s?.diagnostics??[],{unique:!0}));let l=n.promoteToHittableAncestor?nG(r.snapshot.nodes,s.node):s.node;return{kind:"selector",point:nW(l,`Selector ${s.selector.raw} resolved to invalid bounds`),target:{kind:"selector",selector:s.selector.raw},node:l,selectorChain:S(l,e.backend.platform,{action:"fill"===n.action?"fill":"click"}),refLabel:_(l,r.snapshot.nodes)}}async function nV(e,t,n){if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let r=t.session??"default",i=await e.sessions.get(r);if(!i)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");let o=await e.backend.captureSnapshot(nd(e,t),{interactiveOnly:n,compact:n}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:nc(e)};return await e.sessions.set({...i,snapshot:s}),{snapshot:s}}async function nH(e,t,n){if("macos"!==e.backend.platform)return;let r=await nz(e,t);if(("desktop"===r||"menubar"===r)&&("menubar"!==r||"click"!==n&&"press"!==n))throw new a("UNSUPPORTED_OPERATION",`${n} is not supported on macOS ${r} sessions yet. Open an app session to act, or use the ${r} surface to inspect.`)}async function nz(e,t){let n=await e.sessions.get(t.session??"default");return n?.metadata?.surface}async function nK(e,t,n){let r=t.session??"default",i=await e.sessions.get(r);if(!i)throw new a("SESSION_NOT_FOUND","No active session. Run open first.");if(!i.snapshot)throw new a("INVALID_ARGS","No snapshot in session. Run snapshot first.");let o=n.fallbackLabel??"",s=nj(i.snapshot.nodes,n.ref,{fallbackLabel:o,requireRect:!0});if(s)return{snapshot:i.snapshot,resolved:s};let l=await nV(e,t,!0),d=nj(l.snapshot.nodes,n.ref,{fallbackLabel:o,requireRect:!0});if(!d)throw new a("COMMAND_FAILED",`Ref ${n.ref} not found or has no bounds`);return{...l,resolved:d}}function nj(e,t,n){let r=o(t);if(!r)throw new a("INVALID_ARGS",`Invalid ref: ${t}`);let i=d(e,r);if(nJ(i,n.requireRect))return{ref:r,node:i};let s=n.fallbackLabel.length>0?E(e,n.fallbackLabel):null;return nJ(s,n.requireRect)?{ref:r,node:s}:null}function nW(e,t){if(!e.rect)throw new a("COMMAND_FAILED",t);let n=s(e.rect);if(!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new a("COMMAND_FAILED",t);return n}function nJ(e,t){if(!e)return!1;if(!t)return!0;if(!e.rect)return!1;let{x:n,y:r,width:i,height:a}=e.rect;if(!Number.isFinite(Number(n))||!Number.isFinite(Number(r))||!Number.isFinite(Number(i))||!Number.isFinite(Number(a))||0>Number(i)||0>Number(a))return!1;let o=s(e.rect);return Number.isFinite(o.x)&&Number.isFinite(o.y)}async function nZ(e,t,n){let r;if(t.from||t.to||t.direction||void 0!==t.distance)throw new a("INVALID_ARGS","gesture swipe preset cannot be combined with from, to, direction, or distance");let i=K(t.preset);await nH(e,t,"swipe");let o=z(i,{referenceWidth:(r=n8((await nV(e,t,!1)).snapshot.nodes)).width,referenceHeight:r.height},{platform:e.backend.platform}),s=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",16,1e4),l={x:o.x1,y:o.y1},d={x:o.x2,y:o.y2},c=n6(await n(nd(e,t),l,d,{durationMs:s}));return{kind:"swipe",from:l,to:d,preset:i,...void 0!==s?{durationMs:s}:{},fromTarget:{kind:"viewport"},...c?{backendResult:c}:{},...b(`Swiped ${i}`)}}async function nQ(e,t){let n=t.target??{kind:"viewport"};return"viewport"===n.kind?(await nH(e,t,"scroll"),{kind:"viewport"}):await nY(e,{...t,target:n},{action:"scroll",requireInteractive:!1,promoteToHittableAncestor:!1})}async function n0(e,t){if(t.from){var n;if("x"in(n=t.from)&&"y"in n)return await nH(e,t,"swipe"),{point:n5(t.from,"from")};let r=await nY(e,{...t,target:t.from},{action:"swipe",requireInteractive:!1,promoteToHittableAncestor:!1});return{point:r.point,target:r}}if(!t.direction)throw new a("INVALID_ARGS","swipe requires from+to or a direction");return await nH(e,t,"swipe"),{point:s(n8((await nV(e,t,!1)).snapshot.nodes)),target:{kind:"viewport"}}}async function n1(e,t,n,r,i){if(!e.backend.captureSnapshot)throw new a("UNSUPPORTED_OPERATION",`scroll ${n} requires snapshot support to verify hidden content before scrolling`);let{captureSnapshot:o}=e.backend;return await eg({edge:n,target:r,scope:i,captureNodes:async n=>{let r=await o(nd(e,t),{compact:!0,scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function n2(e,t){switch(e){case"up":case"down":case"left":case"right":return e;default:throw new a("INVALID_ARGS",`${t} must be up, down, left, or right`)}}function n5(e,t){let n=Number(e.x),r=Number(e.y);if(!Number.isFinite(n)||!Number.isFinite(r))throw new a("INVALID_ARGS",`${t} point requires finite x and y`);return{x:n,y:r}}function n4(e,t){if(!Number.isFinite(e)||e<=0)throw new a("INVALID_ARGS",`${t} must be a positive number`);return e}function n8(e){let t=e.filter(t=>ep(t,e)).map(e=>e.rect).filter(n3),n=t.length>0?t:e.map(e=>e.rect).filter(n3);if(0===n.length)throw new a("COMMAND_FAILED","Cannot infer viewport for directional swipe");let r=Math.min(...n.map(e=>e.x)),i=Math.min(...n.map(e=>e.y));return{x:r,y:i,width:Math.max(...n.map(e=>e.x+e.width))-r,height:Math.max(...n.map(e=>e.y+e.height))-i}}function n3(e){return!!(e&&e.width>0&&e.height>0)}function n6(e){return e&&"object"==typeof e?e:void 0}async function n9(e,t,n){let r=await nY(e,t,{action:n,requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.tap)throw new a("UNSUPPORTED_OPERATION","tap is not supported by this backend");let i=n7(await e.backend.tap(nd(e,t),r.point,{button:t.button,count:t.count,intervalMs:t.intervalMs,holdMs:t.holdMs,jitterPx:t.jitterPx,doubleTap:t.doubleTap}));return{...r,...i?{backendResult:i}:{}}}function n7(e){return e&&"object"==typeof e?e:void 0}function re(e,t){if(void 0!==e)return rt(e,t)}function rt(e,t){let n=e?.trim();if(!n)throw new a("INVALID_ARGS",`${t} must be a non-empty string`);return n}function rn(e){return e&&"object"==typeof e?e:void 0}let rr=/^[A-Za-z0-9_.:-]{1,64}$/;async function ri(e,t){if(!t||"object"!=typeof t)throw new a("INVALID_ARGS","apps.push requires an input");if("json"===t.kind)return ra(t.payload,"apps.push JSON payload",8192),{backendInput:{kind:"json",payload:t.payload},inputKind:"json"};let n=await tl(e,t,{usage:"apps.push",field:"input"});return{backendInput:{kind:"file",path:n.path},inputKind:"file",...n.cleanup?{cleanup:n.cleanup}:{}}}function ra(e,t,n){if(function(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS",`${t} must be a JSON object`)}(e,t),Buffer.byteLength(function(e,t){try{let n=JSON.stringify(e);if("string"!=typeof n)throw new a("INVALID_ARGS",`${t} must be JSON-serializable`);return n}catch{throw new a("INVALID_ARGS",`${t} must be JSON-serializable`)}}(e,t),"utf8")>n)throw new a("INVALID_ARGS",`${t} exceeds ${n} bytes`)}function ro(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function rs(e){return e&&"object"==typeof e?e:void 0}async function rl(e,t,n){let r="reinstall"===n?"reinstallApp":"installApp",i=e.backend[r];if(!i)throw new a("UNSUPPORTED_OPERATION",`admin.${n} is not supported by this backend`);let o="app"in t&&void 0!==t.app?rt(t.app,"app"):void 0;if("installFromSource"!==n&&!o)throw new a("INVALID_ARGS",`admin.${n} requires app`);let s=nd(e,t),l=await rd(e,s,t.source);try{var d,c,u,h,p;let t,r,a,f,w,m,g,y,x=await i.call(e.backend,s,{...o?{app:o}:{},source:l.source});return d=n,c=o,u=l.source,h=x,t=rp(h),r=rh(h,"appName"),a=rh(h,"appId"),f=rh(h,"bundleId"),w=rh(h,"packageName"),m=rh(h,"launchTarget"),g=rh(h,"installablePath"),y=rh(h,"archivePath"),{kind:"reinstall"===d?"appReinstalled":"installFromSource"===d?"appInstalledFromSource":"appInstalled",...c?{app:c}:{},source:u,...a?{appId:a}:{},...r?{appName:r}:{},...f?{bundleId:f}:{},...w?{packageName:w}:{},...m?{launchTarget:m}:{},...g?{installablePath:g}:{},...y?{archivePath:y}:{},...t?{backendResult:t}:{},...b(`${"reinstall"===d?"Reinstalled":"Installed"}: ${r??m??c??(p=u,"path"===p.kind?p.path:"uploadedArtifact"===p.kind?p.id:p.url)}`)}}finally{await l.cleanup?.()}}async function rd(e,t,n){let r=ru(n),i=await rc(e,r);try{let n=e.backend.resolveInstallSource?await e.backend.resolveInstallSource(t,i.source):i.source;return{source:ru(n),...i.cleanup?{cleanup:i.cleanup}:{}}}catch(e){if(i.cleanup)try{await i.cleanup()}catch{}throw e}}async function rc(e,t){if("url"===t.kind)return{source:t};let n=await tl(e,t,{usage:"admin.install",field:"source"});return{source:{kind:"path",path:n.path},...n.cleanup?{cleanup:n.cleanup}:{}}}function ru(e){if(!e||"object"!=typeof e)throw new a("INVALID_ARGS","install source is required");if("path"===e.kind)return{kind:"path",path:rt(e.path,"source.path")};if("uploadedArtifact"===e.kind)return{kind:"uploadedArtifact",id:rt(e.id,"source.id")};if("url"===e.kind){let t=rt(e.url,"source.url");return function(e){let t;try{t=new URL(e)}catch{throw new a("INVALID_ARGS",`Invalid install source URL: ${e}`)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new a("INVALID_ARGS","Install source URL must use http or https")}(t),{kind:"url",url:t}}throw new a("INVALID_ARGS","install source kind must be path, uploadedArtifact, or url")}function rh(e,t){let n=e[t];return"string"==typeof n&&n.length>0?n:void 0}function rp(e){return e&&"object"==typeof e?e:void 0}function rf(e,t){if("start"===e||"stop"===e)return e;throw new a("INVALID_ARGS",`${t} action must be start or stop`)}function rw(e,t,n,r){return{kind:"start"===e?r.startKind:r.stopKind,action:e,...n?{artifact:n}:{},backendResult:t,...b("start"===e?r.startMessage:r.stopMessage)}}let rm=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i,rb=/\b[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\b/g;function rg(e){var t,n;let r=!1,i=e;return{value:(t=i=(i=(i=(i=(i=i.replaceAll(/(authorization|token|secret|password|passwd|api[-_]?key)=([^&\s]+)/gi,(e,t)=>(r=!0,`${String(t)}=[REDACTED]`))).replaceAll(/("(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)"\s*:\s*")([^"]*)(")/gi,(e,t,n,i)=>(r=!0,`${String(t)}[REDACTED]${String(i)}`))).replaceAll(/\b(Bearer\s+)([^\s",;]+)/gi,(e,t)=>(r=!0,`${String(t)}[REDACTED]`))).replaceAll(/((?:authorization|cookie|token|secret|password|passwd|api[-_]?key)\s*[:=]\s*)([^\s,;&]+)/gi,(e,t)=>(r=!0,`${String(t)}[REDACTED]`))).replaceAll(rb,()=>(r=!0,"[REDACTED]")),n=()=>{r=!0},i=/(https?:\/\/|token|secret|password|authorization|cookie|api[-_]?key)/i.test(t)?t.replaceAll(/https?:\/\/[^\s"'<>)]+/gi,e=>{let t=ry(e);return t?(t.redacted&&n(),t.value):e}):t),redacted:r}}function ry(e){try{let t=new URL(e),n=function(e){let t=!1;for(let n of Array.from(e.searchParams.keys()))rm.test(n)&&(e.searchParams.set(n,"[REDACTED]"),t=!0);return t}(t);return(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED",n=!0),{value:t.toString(),redacted:n}}catch{return}}let rx=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i;function rv(e){if(!e)return{redacted:!1};let t=!1,n={};for(let[r,i]of Object.entries(e))if(rx.test(r))n[r]="[REDACTED]",t=!0;else{let e=rA(i,2048);n[r]=e.value??"",t||=e.redacted}return{value:n,redacted:t}}function rk(e){return void 0===e?{redacted:!1}:function(e){try{let t=JSON.parse(e),n=rN(t,rg);return rM(JSON.stringify(n.value),2048,n.redacted)}catch{return}}(e)??rA(e,2048)}function rI(e){return rN(e,e=>rA(e,2048))}function rN(e,t){if(void 0===e)return{redacted:!1};if("string"==typeof e)return t(e);if(!e||"object"!=typeof e)return{value:e,redacted:!1};if(Array.isArray(e)){let n=!1;return{value:e.map(e=>{let r=rN(e,t);return n||=r.redacted,r.value}),redacted:n}}let n=!1,r={};for(let[i,a]of Object.entries(e)){if(rx.test(i)){r[i]="[REDACTED]",n=!0;continue}let e=rN(a,t);r[i]=e.value,n||=e.redacted}return{value:r,redacted:n}}function rA(e,t){if(void 0===e)return{redacted:!1};let n=rg(e);return rM(n.value,t,n.redacted)}function rM(e,t,n){if(void 0===e)return{redacted:n};let r=e;return r.length>t&&(r=`${r.slice(0,t)}...[truncated]`,n=!0),{value:r,redacted:n}}async function rR(e,t){let n=nd(e,t),r=t.session?await e.sessions.get(t.session):void 0;return{...n,...t.appId??r?.appId?{appId:t.appId??r?.appId}:{},...t.appBundleId??r?.appBundleId?{appBundleId:t.appBundleId??r?.appBundleId}:{}}}function rP(e,t,n,r){return{...rS(e),...void 0!==e.cursor?{cursor:rt(e.cursor,"cursor")}:{},limit:void 0===e.limit?t:eR(e.limit,r,1,n)}}function rS(e){return{...void 0!==e.since?{since:rt(e.since,"since")}:{},...void 0!==e.until?{until:rt(e.until,"until")}:{}}}function rO(e,t,n=50){if(!Array.isArray(e))throw new a("INVALID_ARGS",`${t} must be an array of strings`);if(e.length>n)throw new a("INVALID_ARGS",`${t} must contain at most ${n} entries`);return e.map((e,n)=>rt(e,`${t}[${n}]`))}let rD=tu,rE=async(e,t)=>{let n,r,i;if(!t.baseline)throw new a("INVALID_ARGS","diff screenshot requires a baseline image");let o=function(e){if(null==e||""===e)return .1;let t=Number(e);if(Number.isNaN(t)||t<0||t>1)throw new a("INVALID_ARGS","--threshold must be a number between 0 and 1");return t}(t.threshold),s=t.current??{kind:"live"};if(t.overlayRefs&&!t3(s))throw new a("INVALID_ARGS","diff screenshot <current.png> cannot use --overlay-refs because saved-image comparisons have no live accessibility refs");let l=await tl(e,t.baseline,{usage:"diff screenshot baseline",field:"baseline"}),d=[];try{let a;a=t3(s)?(r=await t0(e,t)).path:(n=await tl(e,s,{usage:"diff screenshot current",field:"current"})).path,i=t.out?await td(e,t.out,{field:"diffPath",ext:".png"}):void 0;let c=await tH(l.path,a,{threshold:o,outputPath:i?.path,maxPixels:e.policy.maxImagePixels});t3(s)&&(c=await t1(e,t,i?.path,c,d));let u=c.diffPath?await i?.publish():void 0;return u&&d.push(u),c.diffPath||await i?.cleanup?.(),{...c,...d.length>0?{artifacts:d}:{}}}catch(e){throw await i?.cleanup?.(),e}finally{await l.cleanup?.(),await n?.cleanup?.(),await r?.cleanup?.()}},r_=async(e,t)=>{var n;let r,i,a=await nh(e,t),o=function(e){var t,n,r,i,a;let{previous:o,current:s,options:l,identity:d}=e;if(!0===l.forceFull||!0===l.raw||!o||!1===o.comparisonSafe||!1===s.comparisonSafe||(t=o,n=s,r=d,t.backend&&n.backend&&t.backend!==n.backend||r?.previousAppBundleId&&r.currentAppBundleId&&r.previousAppBundleId!==r.currentAppBundleId)||!o.presentationKey||o.presentationKey!==s.presentationKey||(i=o,a=s,i.truncated!==a.truncated||JSON.stringify(nl(i.nodes))!==JSON.stringify(nl(a.nodes))))return;let c=l.scope?.trim();return{ageMs:Math.max(0,s.createdAt-o.createdAt),nodeCount:s.nodes.length,...!0===l.interactiveOnly?{interactiveOnly:!0}:{},...c?{scope:c}:{}}}({previous:a.session?.snapshot,current:a.snapshot,options:t,identity:{previousAppBundleId:a.session?.appBundleId,currentAppBundleId:a.result.appBundleId??a.session?.appBundleId}});return await e.sessions.set(np(t.session,a)),{nodes:a.snapshot.nodes,truncated:a.snapshot.truncated??!1,visibility:function(e){var t;let{nodes:n,backend:r,snapshotRaw:i}=e;if(i||"macos-helper"===(t=r)||"linux-atspi"===t)return{partial:!1,visibleNodeCount:n.length,totalNodeCount:n.length,reasons:[]};let a=ec(n),o=new Set;return a.hiddenCount>0&&o.add("offscreen-nodes"),a.nodes.some(e=>e.hiddenContentAbove)&&o.add("scroll-hidden-above"),a.nodes.some(e=>e.hiddenContentBelow)&&o.add("scroll-hidden-below"),{partial:o.size>0,visibleNodeCount:a.nodes.length,totalNodeCount:n.length,reasons:[...o]}}({nodes:a.snapshot.nodes,backend:a.snapshot.backend,snapshotRaw:t.raw}),...a.result.androidSnapshot?{androidSnapshot:a.result.androidSnapshot}:{},...a.warnings.length>0?{warnings:a.warnings}:{},...o?{unchanged:o}:{},...(r=(n=a).result.appName??n.session?.appName,i=n.result.appBundleId??n.session?.appBundleId,{...r||i?{appName:r??i}:{},...i?{appBundleId:i}:{}})}},rT=async(e,t)=>{let n=await nh(e,t),r=!0===t.interactiveOnly,i=n.session?.snapshot,a=np(t.session,n);if(!i){let t=function(e,t={}){return no(e,t).length}(n.snapshot.nodes,{flatten:r});return await e.sessions.set(a),{mode:"snapshot",baselineInitialized:!0,summary:{additions:0,removals:0,unchanged:t},lines:[],...n.warnings.length>0?{warnings:n.warnings}:{}}}let o=function(e,t,n={}){let r=function(e,t){let n=e.length,r=t.length,i=n+r,a=new Map,o=[];a.set(1,0);for(let s=0;s<=i;s+=1){o.push(new Map(a));for(let i=-s;i<=s;i+=2){let l=i===-s||i!==s&&ns(a,i-1)<ns(a,i+1)?ns(a,i+1):ns(a,i-1)+1,d=l-i;for(;l<n&&d<r&&e[l].comparable===t[d].comparable;)l+=1,d+=1;if(a.set(i,l),l>=n&&d>=r)return function(e,t,n,r,i){let a=[],o=r,s=i;for(let r=e.length-1;r>=0;r-=1){let i=e[r],l=o-s,d=l===-r||l!==r&&ns(i,l-1)<ns(i,l+1)?l+1:l-1,c=ns(i,d),u=c-d;for(;o>c&&s>u;)a.push({kind:"unchanged",text:n[s-1].text}),o-=1,s-=1;if(0===r)break;o===c?(a.push({kind:"added",text:n[u].text}),s=u):(a.push({kind:"removed",text:t[c].text}),o=c)}return a.reverse(),a}(o,e,t,n,r)}}return[]}(no(e,n),no(t,n)),i={additions:0,removals:0,unchanged:0};for(let e of r)"added"===e.kind&&(i.additions+=1),"removed"===e.kind&&(i.removals+=1),"unchanged"===e.kind&&(i.unchanged+=1);return{summary:i,lines:r}}(i.nodes,n.snapshot.nodes,{flatten:r});return await e.sessions.set(a),{mode:"snapshot",baselineInitialized:!1,summary:o.summary,lines:o.lines,...n.warnings.length>0?{warnings:n.warnings}:{}}},r$=async(e,t)=>{let n=t.locator??"any";if(!t.query)throw new a("INVALID_ARGS","find requires a value");if("wait"===t.action)return await nS(e,t,n);let{capture:r,match:i}=await nO(e,t,n);if(!i)throw new a("COMMAND_FAILED","find did not match any element");if("exists"===t.action)return{kind:"found",found:!0};let o=`@${i.ref}`;return"get_attrs"===t.action?{kind:"attrs",ref:o,node:i}:{kind:"text",ref:o,text:await nx(e,r,i),node:i}},rC=nv,rL=nk,rU=nI,rB=nN,rG=nA,rF=nM,rq=nR,rX=nP,rY=async(e,t)=>await n9(e,t,"click"),rV=async(e,t)=>await n9(e,t,"press"),rH=async(e,t)=>{var n;if(!t.text)throw new a("INVALID_ARGS","fill requires text");let r=await nY(e,t,{action:"fill",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.fill)throw new a("UNSUPPORTED_OPERATION","fill is not supported by this backend");let i=n7(await e.backend.fill(nd(e,t),r.point,t.text,{delayMs:t.delayMs})),o="node"in r?r.node.type??"":"",s=o&&!U(o,e.backend.platform)?`fill target ${n=r,n.target?.kind==="ref"?n.target.ref:n.target?.kind==="selector"?n.target.selector:"point"} resolved to "${o}", attempting fill anyway.`:void 0;return{...r,text:t.text,...s?{warning:s}:{},...i?{backendResult:i}:{}}},rz=async(e,t)=>{let n=t.text;if(!n)throw new a("INVALID_ARGS","type requires text");let r=Y(n);if(r)throw new a("INVALID_ARGS",`type does not accept a target ref like "${r}"`,{hint:`Use fill ${r} "text" to target that field, or press ${r} then type "text" to append.`});if(!e.backend.typeText)throw new a("UNSUPPORTED_OPERATION","type is not supported by this backend");let i=eR(t.delayMs??0,"delay-ms",0,1e4),o=n7(await e.backend.typeText(nd(e,t),n,{delayMs:i}));return{kind:"text",text:n,delayMs:i,...o?{backendResult:o}:{},...b(`Typed ${Array.from(n).length} chars`)}},rK=async(e,t)=>{let n=await nY(e,t,{action:"focus",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new a("UNSUPPORTED_OPERATION","focus is not supported by this backend");let r=n6(await e.backend.focus(nd(e,t),n.point));return{...n,...r?{backendResult:r}:{},...b(`Focused (${n.point.x}, ${n.point.y})`)}},rj=async(e,t)=>{let n=await nY(e,t,{action:"longPress",requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.longPress)throw new a("UNSUPPORTED_OPERATION","longPress is not supported by this backend");let r=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",0,12e4),i=n6(await e.backend.longPress(nd(e,t),n.point,{durationMs:r}));return{...n,...void 0!==r?{durationMs:r}:{},...i?{backendResult:i}:{},...b(`Long pressed (${n.point.x}, ${n.point.y})`)}},rW=async(e,t)=>{if(!e.backend.swipe)throw new a("UNSUPPORTED_OPERATION","swipe is not supported by this backend");if(t.preset)return await nZ(e,t,e.backend.swipe);let n=await n0(e,t),r=function(e,t){if(t.to)return{point:n5(t.to,"to")};let n=n2(t.direction,"swipe direction"),r=n4(t.distance??200,"swipe distance");switch(n){case"up":return{point:{x:e.x,y:e.y-r},direction:n,distance:r};case"down":return{point:{x:e.x,y:e.y+r},direction:n,distance:r};case"left":return{point:{x:e.x-r,y:e.y},direction:n,distance:r};case"right":return{point:{x:e.x+r,y:e.y},direction:n,distance:r}}}(n.point,t),i=void 0===t.durationMs?void 0:eR(t.durationMs,"durationMs",16,1e4),o=n6(await e.backend.swipe(nd(e,t),n.point,r.point,{durationMs:i}));return{kind:"swipe",from:n.point,to:r.point,...r.direction?{direction:r.direction}:{},...void 0!==r.distance?{distance:r.distance}:{},...void 0!==i?{durationMs:i}:{},...n.target?{fromTarget:n.target}:{},...o?{backendResult:o}:{},...b("Swiped")}},rJ=async(e,t)=>{var n,r,i,o;let s;if(!e.backend.scroll)throw new a("UNSUPPORTED_OPERATION","scroll is not supported by this backend");let l="bottom"===(n=t.direction)?{direction:"down",edge:"bottom"}:"top"===n?{direction:"up",edge:"top"}:{direction:n2(n,"scroll direction")},d=(r=t.amount,i="scroll amount",void 0===r?void 0:n4(r,i)),c=function(e,t){if(void 0!==e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new a("INVALID_ARGS",`${t} must be a positive integer`);return e}}(t.pixels,"scroll pixels");if(void 0!==d&&void 0!==c)throw new a("INVALID_ARGS","scroll accepts either amount or pixels, not both");let u=await nQ(e,t),h="viewport"===u.kind?{kind:"viewport"}:{kind:"point",point:u.point},p=e.backend.scroll,f=async()=>await p(nd(e,t),h,{direction:l.direction,...void 0!==d?{amount:d}:{},...void 0!==c?{pixels:c}:{}}),w=0;if(l.edge){let n=l.edge,r="viewport"===(o=u).kind?{}:{point:o.point,nodeIndex:"node"in o?o.node.index:void 0},i=await ey({edge:n,captureState:async i=>await n1(e,t,n,r,i),scroll:f});s=i.result,w=i.passes}else s=await f(),w=1;let m=n6(s);return{...u,direction:l.direction,...l.edge?{edge:l.edge,passes:w}:{},...void 0!==d?{amount:d}:{},...void 0!==c?{pixels:c}:{},...m?{backendResult:m}:{},...b(ex(l.direction,l.edge,w,d,c))}},rZ=async(e,t)=>{if(!e.backend.pinch)throw new a("UNSUPPORTED_OPERATION","pinch is not supported by this backend");await nH(e,t,"pinch");let n=n4(t.scale,"pinch scale"),r=t.center?await nY(e,{...t,target:t.center},{action:"pinch",requireInteractive:!1,promoteToHittableAncestor:!1}):void 0,i=n6(await e.backend.pinch(nd(e,t),{scale:n,...r?{center:r.point}:{}}));return{kind:"pinch",scale:n,...r?{center:r.point,centerTarget:r}:{},...i?{backendResult:i}:{},...b(`Pinched to scale ${n}`)}},rQ=async(e,t={})=>{if(!e.backend.pressBack)throw new a("UNSUPPORTED_OPERATION","system.back is not supported by this backend");let n=t.mode??"in-app";if("in-app"!==n&&"system"!==n)throw new a("INVALID_ARGS","system.back mode must be in-app or system");let r=rn(await e.backend.pressBack(nd(e,t),{mode:n}));return{kind:"systemBack",mode:n,...r?{backendResult:r}:{},...b("Back")}},r0=async(e,t={})=>{if(!e.backend.pressHome)throw new a("UNSUPPORTED_OPERATION","system.home is not supported by this backend");let n=rn(await e.backend.pressHome(nd(e,t)));return{kind:"systemHome",...n?{backendResult:n}:{},...b("Home")}},r1=async(e,t)=>{if(!e.backend.rotate)throw new a("UNSUPPORTED_OPERATION","system.rotate is not supported by this backend");let n=function(e){switch(e){case"portrait":case"portrait-upside-down":case"landscape-left":case"landscape-right":return e;default:throw new a("INVALID_ARGS","system.rotate orientation must be portrait, portrait-upside-down, landscape-left, or landscape-right")}}(t.orientation),r=rn(await e.backend.rotate(nd(e,t),n));return{kind:"systemRotated",orientation:n,...r?{backendResult:r}:{},...b(`Rotated to ${n}`)}},r2=async(e,t={})=>{var n,r,i,o,s,l,d;if(!e.backend.setKeyboard)throw new a("UNSUPPORTED_OPERATION","system.keyboard is not supported by this backend");let c=t.action??"status";if(!X(c))throw new a("INVALID_ARGS","system.keyboard action must be status, get, dismiss, enter, or return");let u=await e.backend.setKeyboard(nd(e,t),{action:c}),h=rn(u),p=(n=u)&&"object"==typeof n?u:{};return"enter"===c||"return"===c?{kind:"keyboardEnterPressed",action:"enter",state:p,...(r=h)?{backendResult:r}:{},...b("Keyboard enter pressed")}:"dismiss"===c?(i=c,{kind:"keyboardDismissed",action:i,state:o=p,...(s=h)?{backendResult:s}:{},...b(!1===o.dismissed?"Keyboard already hidden":"Keyboard dismissed")}):(l=c,{kind:"keyboardState",action:l,state:p,...(d=h)?{backendResult:d}:{}})},r5=async(e,t)=>{if("read"===t.action){if(!e.backend.getClipboard)throw new a("UNSUPPORTED_OPERATION","system.clipboard read is not supported by this backend");let n=await e.backend.getClipboard(nd(e,t));return{kind:"clipboardText",action:"read",text:"string"==typeof n?n:n.text}}if("write"!==t.action)throw new a("INVALID_ARGS","system.clipboard action must be read or write");if(!e.backend.setClipboard)throw new a("UNSUPPORTED_OPERATION","system.clipboard write is not supported by this backend");if("string"!=typeof t.text)throw new a("INVALID_ARGS","system.clipboard write requires text");let n=rn(await e.backend.setClipboard(nd(e,t),t.text));return{kind:"clipboardUpdated",action:"write",textLength:Array.from(t.text).length,...n?{backendResult:n}:{},...b("Clipboard updated")}},r4=async(e,t={})=>{if(!e.backend.openSettings)throw new a("UNSUPPORTED_OPERATION","system.settings is not supported by this backend");let n=re(t.target,"target"),r=rn(await e.backend.openSettings(nd(e,t),n));return{kind:"settingsOpened",...n?{target:n}:{},...r?{backendResult:r}:{},...b(n?`Opened settings: ${n}`:"Opened settings")}},r8=async(e,t={})=>{var n,r;if(!e.backend.handleAlert)throw new a("UNSUPPORTED_OPERATION","system.alert is not supported by this backend");let i=t.action??"get";if("get"!==i&&"accept"!==i&&"dismiss"!==i&&"wait"!==i)throw new a("INVALID_ARGS","system.alert action must be get, accept, dismiss, or wait");let o=void 0===t.timeoutMs?void 0:eR(t.timeoutMs,"timeoutMs",0,12e4),s=await e.backend.handleAlert(nd(e,t),i,{timeoutMs:o});return n=i,r=s,"get"===n?function(e){if("alertStatus"!==e.kind)throw new a("COMMAND_FAILED","system.alert get returned an invalid backend result");return{kind:"alertStatus",action:"get",alert:e.alert}}(r):"wait"===n?function(e){if("alertWait"!==e.kind)throw new a("COMMAND_FAILED","system.alert wait returned an invalid backend result");return{kind:"alertWait",action:"wait",alert:e.alert,...void 0!==e.waitedMs?{waitedMs:e.waitedMs}:{},...void 0!==e.timedOut?{timedOut:e.timedOut}:{},...b(e.alert?"Alert visible":"Alert wait timed out")}}(r):function(e,t){if("alertHandled"!==t.kind)throw new a("COMMAND_FAILED",`system.alert ${e} returned an invalid backend result`);return{kind:"alertHandled",action:e,handled:t.handled,...t.alert?{alert:t.alert}:{},...t.button?{button:t.button}:{},...b(t.handled?`Alert ${e}ed`:"No alert handled")}}(n,r)},r3=async(e,t={})=>{if(!e.backend.openAppSwitcher)throw new a("UNSUPPORTED_OPERATION","system.appSwitcher is not supported by this backend");let n=rn(await e.backend.openAppSwitcher(nd(e,t)));return{kind:"appSwitcherOpened",...n?{backendResult:n}:{},...b("Opened app switcher")}},r6=async(e,t)=>{var n;if(!e.backend.openApp)throw new a("UNSUPPORTED_OPERATION","apps.open is not supported by this backend");let r=function(e){var t;let n=re(e.app,"app"),r=re(e.appId,"appId"),i=re(e.bundleId,"bundleId"),o=re(e.packageName,"packageName"),s=re(e.url,"url"),l=re(e.activity,"activity"),d={...n?{app:n}:{},...r?{appId:r}:{},...i?{bundleId:i}:{},...o?{packageName:o}:{},...s?{url:s}:{},...l?{activity:l}:{}};if(!((t=d).app??t.appId??t.bundleId??t.packageName??t.url??t.activity))throw new a("INVALID_ARGS","apps.open requires app, appId, bundleId, packageName, url, or activity");return d}(t),i=rs(await e.backend.openApp(ro(e,t),r,{launchArgs:t.launchArgs,relaunch:t.relaunch}));return{kind:"appOpened",target:r,relaunch:!0===t.relaunch,...i?{backendResult:i}:{},...b(`Opened: ${(n=r).app??n.appId??n.bundleId??n.packageName??n.url??n.activity??"app"}`)}},r9=async(e,t={})=>{if(!e.backend.closeApp)throw new a("UNSUPPORTED_OPERATION","apps.close is not supported by this backend");let n=re(t.app,"app"),r=rs(await e.backend.closeApp(ro(e,t),n));return{kind:"appClosed",...n?{app:n}:{},...r?{backendResult:r}:{},...b(n?`Closed: ${n}`:"Closed app")}},r7=async(e,t={})=>{if(!e.backend.listApps)throw new a("UNSUPPORTED_OPERATION","apps.list is not supported by this backend");return{kind:"appsList",apps:await e.backend.listApps(ro(e,t),F(t.filter))}},ie=async(e,t)=>{if(!e.backend.getAppState)throw new a("UNSUPPORTED_OPERATION","apps.state is not supported by this backend");let n=rt(t.app,"app"),r=await e.backend.getAppState(ro(e,t),n);return{kind:"appState",app:n,state:r}},it=async(e,t)=>{if(!e.backend.pushFile)throw new a("UNSUPPORTED_OPERATION","apps.push is not supported by this backend");let n=rt(t.app,"app"),r=await ri(e,t.input);try{let i=await e.backend.pushFile(ro(e,t),r.backendInput,n),a=rs(i);return{kind:"appPushed",app:n,inputKind:r.inputKind,...a?{backendResult:a}:{},...b(`Pushed to ${n}`)}}finally{await r.cleanup?.()}},ir=async(e,t)=>{var n,r;if(!e.backend.triggerAppEvent)throw new a("UNSUPPORTED_OPERATION","apps.triggerEvent is not supported by this backend");let i=function(e){let t=rt(e,"name");if(!rr.test(t))throw new a("INVALID_ARGS",`Invalid apps.triggerEvent name: ${t}`,{hint:"Use 1-64 chars: letters, numbers, underscore, dot, colon, or dash."});return t}(t.name);n=t.payload,r=`apps.triggerEvent payload for "${i}"`,void 0!==n&&ra(n,r,8192);let o=rs(await e.backend.triggerAppEvent(ro(e,t),{name:i,...t.payload?{payload:t.payload}:{}}));return{kind:"appEventTriggered",name:i,...t.payload?{payload:t.payload}:{},...o?{backendResult:o}:{},...b(`Triggered app event: ${i}`)}},ii=async(e,t={})=>{if(!e.backend.listDevices)throw new a("UNSUPPORTED_OPERATION","admin.devices is not supported by this backend");return{kind:"adminDevices",devices:await e.backend.listDevices(nd(e,t),t.filter)}},ia=async(e,t={})=>{if(!e.backend.bootDevice)throw new a("UNSUPPORTED_OPERATION","admin.boot is not supported by this backend");let n=function(e){if(!e)return;let t=re(e.id,"target.id"),n=re(e.name,"target.name"),r={...t?{id:t}:{},...n?{name:n}:{},...e.platform?{platform:e.platform}:{},...e.target?{target:e.target}:{},...void 0!==e.headless?{headless:e.headless}:{}};return Object.keys(r).length>0?r:void 0}(t.target),r=rp(await e.backend.bootDevice(nd(e,t),n));return{kind:"deviceBooted",...n?{target:n}:{},...r?{backendResult:r}:{},...b("Booted device")}},io=async(e,t)=>await rl(e,t,"install"),is=async(e,t)=>await rl(e,t,"reinstall"),il=async(e,t)=>await rl(e,t,"installFromSource"),id=async(e,t)=>{let n=rf(t.action,"record"),r="start"===n?e.backend.startRecording:e.backend.stopRecording;if(!r)throw new a("UNSUPPORTED_OPERATION",`record ${n} is not supported by this backend`);let i=t.out?await td(e,t.out,{field:"path",ext:".mp4"}):void 0;try{var o,s,l,d,c;let a,u,h=(o=t,s=i?.path,a=void 0===o.fps?void 0:eR(o.fps,"fps",1,60),u=void 0===o.quality?void 0:eR(o.quality,"quality",5,10),{...s?{outPath:s}:{},...void 0!==a?{fps:a}:{},...void 0!==u?{quality:u}:{},...void 0!==o.hideTouches?{showTouches:!0!==o.hideTouches}:{}}),p=await r.call(e.backend,nd(e,t),h),f=await i?.publish();return l=n,d=p,c=f,{..."string"==typeof d.path?{path:d.path}:{},..."string"==typeof d.telemetryPath?{telemetryPath:d.telemetryPath}:{},..."string"==typeof d.warning?{warning:d.warning}:{},...rw(l,d,c,{startKind:"recordingStarted",stopKind:"recordingStopped",startMessage:"Recording started",stopMessage:"Recording stopped"})}}catch(e){throw await i?.cleanup?.(),e}},ic=async(e,t)=>{let n=rf(t.action,"trace"),r="start"===n?e.backend.startTrace:e.backend.stopTrace;if(!r)throw new a("UNSUPPORTED_OPERATION",`trace ${n} is not supported by this backend`);let i=t.out?await td(e,t.out,{field:"outPath",ext:".trace"}):void 0;try{var o,s,l;let a={...i?.path?{outPath:i.path}:{}},d=await r.call(e.backend,nd(e,t),a),c=await i?.publish();return o=n,s=d,l=c,{..."string"==typeof s.outPath?{outPath:s.outPath}:{},...rw(o,s,l,{startKind:"traceStarted",stopKind:"traceStopped",startMessage:"Trace started",stopMessage:"Trace stopped"})}}catch(e){throw await i?.cleanup?.(),e}},iu=async(e,t={})=>{var n,r;let i;if(!e.backend.readLogs)throw new a("UNSUPPORTED_OPERATION","diagnostics.logs is not supported by this backend");return i=!0===(n=await e.backend.readLogs(await rR(e,t),{...rP(r=t,100,500,"logs limit"),...void 0!==r.levels?{levels:rO(r.levels,"levels")}:{},...void 0!==r.search?{search:rt(r.search,"search")}:{},...void 0!==r.source?{source:rt(r.source,"source")}:{}})).redacted,{kind:"diagnosticsLogs",entries:n.entries.map(e=>{let t=rA(e.message,4096),n=rI(e.metadata);return i||=t.redacted||n.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.level?{level:e.level}:{},message:t.value??"",...e.source?{source:e.source}:{},...n.value?{metadata:n.value}:{}}}),...n.nextCursor?{nextCursor:n.nextCursor}:{},...n.timeWindow?{timeWindow:n.timeWindow}:{},...n.backend?{backend:n.backend}:{},redacted:i,...n.notes?{notes:n.notes}:{}}},ih=async(e,t={})=>{var n,r,i;let o;if(!e.backend.dumpNetwork)throw new a("UNSUPPORTED_OPERATION","diagnostics.network is not supported by this backend");let s={...rP(i=t,25,200,"network limit"),include:function(e){if(void 0===e)return"summary";if("summary"===e||"headers"===e||"body"===e||"all"===e)return e;throw new a("INVALID_ARGS","network include must be summary, headers, body, or all")}(i.include)};return n=await e.backend.dumpNetwork(await rR(e,t),s),r=s.include??"summary",o=!0===n.redacted,{kind:"diagnosticsNetwork",entries:n.entries.map(e=>{var t;let n=e.url?ry(t=e.url)??rA(t,2048):void 0,i="headers"===r||"all"===r?rv(e.requestHeaders):void 0,a="headers"===r||"all"===r?rv(e.responseHeaders):void 0,s="body"===r||"all"===r?rk(e.requestBody):void 0,l="body"===r||"all"===r?rk(e.responseBody):void 0,d=rI(e.metadata);return o||=(n?.redacted??!1)||(i?.redacted??!1)||(a?.redacted??!1)||(s?.redacted??!1)||(l?.redacted??!1)||d.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.method?{method:e.method}:{},...n?{url:n.value}:{},...void 0!==e.status?{status:e.status}:{},...void 0!==e.durationMs?{durationMs:e.durationMs}:{},...i?.value?{requestHeaders:i.value}:{},...a?.value?{responseHeaders:a.value}:{},...s?.value!==void 0?{requestBody:s.value}:{},...l?.value!==void 0?{responseBody:l.value}:{},...d.value?{metadata:d.value}:{}}}),...n.nextCursor?{nextCursor:n.nextCursor}:{},...n.timeWindow?{timeWindow:n.timeWindow}:{},...n.backend?{backend:n.backend}:{},redacted:o,...n.notes?{notes:n.notes}:{}}},ip=async(e,t={})=>{var n,r;let i;if(!e.backend.measurePerf)throw new a("UNSUPPORTED_OPERATION","diagnostics.perf is not supported by this backend");return i=!0===(n=await e.backend.measurePerf(await rR(e,t),{...rS(r=t),...void 0!==r.sampleMs?{sampleMs:eR(r.sampleMs,"sampleMs",100,6e4)}:{},...void 0!==r.metrics?{metrics:rO(r.metrics,"metrics",20)}:{}})).redacted,{kind:"diagnosticsPerf",metrics:n.metrics.map(e=>{let t=rA(e.message,4096),n=rI(e.metadata);return i||=t.redacted||n.redacted,{name:e.name,...void 0!==e.value?{value:e.value}:{},...e.unit?{unit:e.unit}:{},...e.status?{status:e.status}:{},...void 0!==t.value?{message:t.value}:{},...n.value?{metadata:n.value}:{}}}),...n.startedAt?{startedAt:n.startedAt}:{},...n.endedAt?{endedAt:n.endedAt}:{},...n.backend?{backend:n.backend}:{},redacted:i,...n.notes?{notes:n.notes}:{}}};function iw(e){let t={backend:e.backend,artifacts:e.artifacts,sessions:e.sessions??function(e=[]){let t=new Map(e.map(e=>[e.name,im(e)]));return{get:e=>im(t.get(e)),set:e=>{t.set(e.name,im(e))},delete:e=>{t.delete(e)},list:()=>Array.from(t.values(),e=>im(e))}}(),policy:e.policy??function(e={}){return{allowLocalInputPaths:!1,allowLocalOutputPaths:!1,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}(),diagnostics:e.diagnostics,clock:e.clock,signal:e.signal};return{...t,capture:{screenshot:e=>rD(t,e),diffScreenshot:e=>rE(t,e),snapshot:e=>r_(t,e),diffSnapshot:e=>rT(t,e)},selectors:{find:e=>r$(t,e),get:e=>rC(t,e),getText:(e,n={})=>rL(t,{...n,target:e}),getAttrs:(e,n={})=>rU(t,{...n,target:e}),is:e=>rB(t,e),isVisible:(e,n={})=>rG(t,{...n,target:e}),isHidden:(e,n={})=>rF(t,{...n,target:e}),wait:e=>rq(t,e),waitForText:(e,n={})=>rX(t,{...n,text:e})},interactions:{click:(e,n={})=>rY(t,{...n,target:e}),press:(e,n={})=>rV(t,{...n,target:e}),fill:(e,n,r={})=>rH(t,{...r,target:e,text:n}),typeText:(e,n={})=>rz(t,{...n,text:e}),focus:(e,n={})=>rK(t,{...n,target:e}),longPress:(e,n={})=>rj(t,{...n,target:e}),swipe:e=>rW(t,e),scroll:e=>rJ(t,e),pinch:e=>rZ(t,e)},system:{back:e=>rQ(t,e),home:e=>r0(t,e),rotate:e=>r1(t,e),keyboard:e=>r2(t,e),clipboard:e=>r5(t,e),settings:e=>r4(t,e),alert:e=>r8(t,e),appSwitcher:e=>r3(t,e)},apps:{open:e=>r6(t,e),close:e=>r9(t,e),list:(e={})=>r7(t,{...e,filter:G(e.filter)}),state:e=>ie(t,e),push:e=>it(t,e),triggerEvent:e=>ir(t,e)},admin:{devices:e=>ii(t,e),boot:e=>ia(t,e),install:e=>io(t,e),reinstall:e=>is(t,e),installFromSource:e=>il(t,e)},recording:{record:e=>id(t,e),trace:e=>ic(t,e)},observability:{logs:e=>iu(t,e),network:e=>ih(t,e),perf:e=>ip(t,e)}}}function im(e){if(e)return{...e,...e.snapshot?{snapshot:structuredClone(e.snapshot)}:{},...e.metadata?{metadata:function(e){try{return structuredClone(e)}catch{return{...e}}}(e.metadata)}:{}}}function ib(e={}){return{allowLocalInputPaths:!0,allowLocalOutputPaths:!0,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}export{e4 as PNG,e$ as analyzeReactNativeOverlay,ec as buildMobileSnapshotPresentation,V as buildScrollGesturePlan,t9 as buildSnapshotDisplayLines,H as buildSwipeGesturePlan,z as buildSwipePresetGesturePlan,eg as captureScrollEdgeState,J as clampGesturePoint,et as clampToRange,iw as createAgentDevice,to as decodePng,eu as deriveMobileSnapshotHiddenContentHints,eT as detectReactNativeOverlay,ed as displayNodeLabel,nm as evaluateIsPredicate,Y as findMistargetedTypeRefToken,ex as formatScrollEdgeMessage,t7 as formatSnapshotLine,j as inferGestureReferenceFrame,eo as inferVerticalScrollIndicatorDirections,nU as interiorCoordinate,X as isKeyboardAction,eL as isReactNativeCollapsedWarningWrapperCandidate,eU as isReactNativeCollapsedWarningWrapperWithVisibleBanner,nw as isSupportedPredicate,ea as isSystemScrollIndicatorLabel,ib as localCommandPolicy,es as normalizeSnapshotTree,Z as parseScrollDirection,K as parseSwipePreset,W as pointFromPercent,nL as pointInsideRect,eC as readReactNativeOverlayActionNodes,eR as requireIntInRange,nG as resolveActionableTouchNode,nF as resolveActionableTouchResolution,n$ as resolveRectCenter,ey as runScrollEdgePasses};
|