agent-device 0.21.19 → 0.21.20

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.
Files changed (114) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.19.apk → agent-device-android-ime-helper-0.21.20.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.20.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.19.manifest.json → agent-device-android-ime-helper-0.21.20.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.19.apk → agent-device-android-snapshot-helper-0.21.20.apk} +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.20.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.19.manifest.json → agent-device-android-snapshot-helper-0.21.20.manifest.json} +6 -6
  7. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +12 -0
  8. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -14
  9. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +14 -16
  10. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +40 -14
  11. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +20 -5
  12. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +2 -15
  13. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +10 -25
  14. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -18
  15. package/dist/src/adapter.js +1 -1
  16. package/dist/src/adb-failure.js +1 -1
  17. package/dist/src/agent-browser-process-record.js +1 -1
  18. package/dist/src/agent-browser-provider.js +1 -1
  19. package/dist/src/agent-browser-tool.js +1 -1
  20. package/dist/src/agent-device-client.js +2 -2
  21. package/dist/src/alert-runtime.js +1 -1
  22. package/dist/src/alert.js +1 -0
  23. package/dist/src/android-input-ownership.js +1 -1
  24. package/dist/src/app-launch.js +2 -2
  25. package/dist/src/app-lifecycle.js +1 -1
  26. package/dist/src/app-resolution.js +2 -2
  27. package/dist/src/apple-runner-platform.js +1 -1
  28. package/dist/src/archive.js +2 -2
  29. package/dist/src/browser-launch.js +1 -1
  30. package/dist/src/cache.js +1 -1
  31. package/dist/src/cli-config.js +1 -1
  32. package/dist/src/cli-help.js +287 -301
  33. package/dist/src/cli-runner.js +1 -1
  34. package/dist/src/cli.js +1 -1
  35. package/dist/src/client-metro-companion.js +1 -1
  36. package/dist/src/client-metro.js +1 -1
  37. package/dist/src/client-types.d.ts +14 -2
  38. package/dist/src/{scroll-command.d.ts → cloud-artifacts.d.ts} +242 -238
  39. package/dist/src/command-schema.js +3 -3
  40. package/dist/src/command-tools.js +2 -2
  41. package/dist/src/command.js +1 -1
  42. package/dist/src/config.js +1 -1
  43. package/dist/src/connection-runtime.js +1 -1
  44. package/dist/src/daemon-client-lifecycle.js +1 -1
  45. package/dist/src/daemon-client-transport.js +1 -1
  46. package/dist/src/daemon-registration.js +1 -1
  47. package/dist/src/debug-symbols-facade.js +3 -3
  48. package/dist/src/device-rotation.js +1 -1
  49. package/dist/src/devicectl.js +1 -1
  50. package/dist/src/display-inventory.js +1 -1
  51. package/dist/src/exec.js +1 -1
  52. package/dist/src/hdc.js +1 -1
  53. package/dist/src/helper.js +2 -2
  54. package/dist/src/host.js +1 -1
  55. package/dist/src/index.d.ts +1 -1
  56. package/dist/src/interactor.js +5 -5
  57. package/dist/src/interactor2.js +1 -1
  58. package/dist/src/internal/bin.js +1 -1
  59. package/dist/src/internal/daemon.js +2 -2
  60. package/dist/src/launch-confirmation.js +1 -0
  61. package/dist/src/limrun-runtime-dependencies.js +1 -1
  62. package/dist/src/limrun.d.ts +50 -42
  63. package/dist/src/mechanics.js +16 -16
  64. package/dist/src/owner-identity.js +1 -1
  65. package/dist/src/perf-facade.js +1 -1
  66. package/dist/src/perf-target.js +1 -1
  67. package/dist/src/physical-device-control.js +1 -1
  68. package/dist/src/platform-runtime-android-adb-host.js +1 -1
  69. package/dist/src/platform-runtime-app-log-process.js +1 -1
  70. package/dist/src/platform-runtime-host.js +1 -1
  71. package/dist/src/platform-runtime-operation-host.js +2 -2
  72. package/dist/src/platform-runtime-runtime-hints.js +1 -1
  73. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  74. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  75. package/dist/src/provider-session-ownership.js +1 -1
  76. package/dist/src/provider-webdriver.js +1 -1
  77. package/dist/src/registry.js +20 -4
  78. package/dist/src/result-serialization.js +1 -1
  79. package/dist/src/runner-cache-metadata.js +3 -3
  80. package/dist/src/runner-client.js +1 -1
  81. package/dist/src/runner-dev-tools-security.js +1 -1
  82. package/dist/src/runner-device-readiness.js +1 -1
  83. package/dist/src/runner-disposal.js +1 -1
  84. package/dist/src/runner-error-classification.js +1 -1
  85. package/dist/src/runner-exchange.js +1 -1
  86. package/dist/src/runner-operations-facade.js +1 -1
  87. package/dist/src/runner-session-types.js +1 -1
  88. package/dist/src/runner-start-budget.js +1 -1
  89. package/dist/src/runner-startup-transport.js +1 -1
  90. package/dist/src/runner-xctestrun.js +1 -1
  91. package/dist/src/runtime.js +1 -1
  92. package/dist/src/runtime10.js +1 -1
  93. package/dist/src/runtime2.js +1 -1
  94. package/dist/src/runtime4.js +5 -5
  95. package/dist/src/screenshot-result.js +1 -1
  96. package/dist/src/screenshot-runtime.js +1 -1
  97. package/dist/src/screenshot3.js +1 -1
  98. package/dist/src/sdk-contracts.d.ts +2 -0
  99. package/dist/src/sdk-contracts.js +2 -2
  100. package/dist/src/sdk-selectors.d.ts +4 -4
  101. package/dist/src/session2.js +1 -1
  102. package/dist/src/simulator-boot.js +1 -1
  103. package/dist/src/simulator.js +1 -1
  104. package/dist/src/snapshot-runtime.js +1 -1
  105. package/dist/src/tool-provider.js +3 -3
  106. package/dist/src/tool-provider2.js +1 -1
  107. package/dist/src/tool-provider3.js +1 -1
  108. package/dist/src/toolchain-probe.js +1 -1
  109. package/dist/src/update-check.js +1 -1
  110. package/dist/src/video.js +1 -1
  111. package/package.json +1 -1
  112. package/server.json +2 -2
  113. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.19.apk.sha256 +0 -1
  114. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.19.apk.sha256 +0 -1
@@ -1 +1 @@
1
- import{E as e,_ as t,v as n,y as r}from"./sdk-batch-runner.js";import{n as i}from"./success-text.js";function a(e){return{...typeof e.path==`string`?{path:e.path}:{},...typeof e.width==`number`?{width:e.width}:{},...typeof e.height==`number`?{height:e.height}:{},...typeof e.logicalWidth==`number`?{logicalWidth:e.logicalWidth}:{},...typeof e.logicalHeight==`number`?{logicalHeight:e.logicalHeight}:{},...typeof e.pixelDensity==`number`?{pixelDensity:e.pixelDensity}:{},...e.overlayRefs?{overlayRefs:e.overlayRefs}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function o(t,n){let r=s(t);return{path:e(t,`path`),width:r?.width,height:r?.height,logicalWidth:r?.logicalWidth,logicalHeight:r?.logicalHeight,pixelDensity:r?.pixelDensity,overlayRefs:r?.overlayRefs,...r?.warnings?{warnings:r.warnings}:{},identifiers:{session:n}}}function s(e){if(!t(e))return;let n=d(e);return a({path:l(e,`path`),width:c(e,`width`),height:c(e,`height`),logicalWidth:c(e,`logicalWidth`),logicalHeight:c(e,`logicalHeight`),pixelDensity:c(e,`pixelDensity`),overlayRefs:u(e.overlayRefs),...n===void 0?{}:{warnings:n}})}function c(e,t){let n=e[t];return typeof n==`number`?n:void 0}function l(e,t){let n=e[t];return typeof n==`string`?n:void 0}function u(e){if(Array.isArray(e))return e.filter(h).flatMap(e=>{let t=f(e);return t?[t]:[]})}function d(e){if(Array.isArray(e.warnings))return i(e).filter(e=>e.length>0)}function f(e){if(typeof e.ref!=`string`||e.ref.length===0)return;let t=p(e);if(t)return{ref:e.ref,...m(e),...t}}function p(e){let t=r(e.rect);if(!t)return;let i=r(e.overlayRect);if(!i)return;let a=n(e.center);return a?{rect:t,overlayRect:i,center:a}:void 0}function m(e){return typeof e.label==`string`&&e.label.length>0?{label:e.label}:{}}function h(e){return t(e)}export{a as n,o as t};
1
+ import{E as e,_ as t,v as n,y as r}from"./sdk-batch-runner.js";import{n as i}from"./success-text.js";import"./device.js";import{d as a}from"./device-rotation.js";function o(e){return{...typeof e.path==`string`?{path:e.path}:{},...typeof e.width==`number`?{width:e.width}:{},...typeof e.height==`number`?{height:e.height}:{},...typeof e.logicalWidth==`number`?{logicalWidth:e.logicalWidth}:{},...typeof e.logicalHeight==`number`?{logicalHeight:e.logicalHeight}:{},...typeof e.pixelDensity==`number`?{pixelDensity:e.pixelDensity}:{},...a(e.displayRotation)?{displayRotation:e.displayRotation}:{},...e.overlayRefs?{overlayRefs:e.overlayRefs}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function s(t,n){let r=c(t);return{path:e(t,`path`),width:r?.width,height:r?.height,logicalWidth:r?.logicalWidth,logicalHeight:r?.logicalHeight,pixelDensity:r?.pixelDensity,...r?.displayRotation?{displayRotation:r.displayRotation}:{},overlayRefs:r?.overlayRefs,...r?.warnings?{warnings:r.warnings}:{},identifiers:{session:n}}}function c(e){if(!t(e))return;let n=f(e);return o({path:u(e,`path`),width:l(e,`width`),height:l(e,`height`),logicalWidth:l(e,`logicalWidth`),logicalHeight:l(e,`logicalHeight`),pixelDensity:l(e,`pixelDensity`),displayRotation:a(e.displayRotation)?e.displayRotation:void 0,overlayRefs:d(e.overlayRefs),...n===void 0?{}:{warnings:n}})}function l(e,t){let n=e[t];return typeof n==`number`?n:void 0}function u(e,t){let n=e[t];return typeof n==`string`?n:void 0}function d(e){if(Array.isArray(e))return e.filter(g).flatMap(e=>{let t=p(e);return t?[t]:[]})}function f(e){if(Array.isArray(e.warnings))return i(e).filter(e=>e.length>0)}function p(e){if(typeof e.ref!=`string`||e.ref.length===0)return;let t=m(e);if(t)return{ref:e.ref,...h(e),...t}}function m(e){let t=r(e.rect);if(!t)return;let i=r(e.overlayRect);if(!i)return;let a=n(e.center);return a?{rect:t,overlayRect:i,center:a}:void 0}function h(e){return typeof e.label==`string`&&e.label.length>0?{label:e.label}:{}}function g(e){return t(e)}export{o as n,s as t};
@@ -1 +1 @@
1
- import{N as e,o as t,y as n}from"./sdk-contracts.js";import{f as r,l as i,r as a,u as o}from"./capture.js";import{C as s,D as c,p as l}from"./sdk-device.js";import{$r as u,Ir as d,It as f,Lr as p,Qr as m,S as h,Yr as g,b as _,f as ee,hn as te,jr as v,l as y,zr as b}from"./sdk-batch.js";import{t as ne}from"./session-store.js";import{T as re,d as ie}from"./runtime.js";import{r as ae}from"./session.js";import{t as oe}from"./overlay.js";import{t as x}from"./snapshot-state.js";import{c as S,f as C,i as se,o as ce,u as le}from"./session-snapshot.js";import{t as w}from"./selector-pipeline-policy.js";import{i as T,o as E,r as ue}from"./png-worker-client.js";import{t as de}from"./png-size.js";import{r as fe,t as pe}from"./screenshot-density.js";import{a as D,c as me,o as O,s as k,t as he}from"./screenshot-overlay-draw.js";import{a as ge,i as _e,n as ve,t as ye}from"./session-runtime-admission.js";import A from"node:path";import{promises as j}from"node:fs";import M from"node:os";const N=y(ee),P=Ie(N);function be(e){return I(e)?.route??`generic`}function F(e){return I(e)?.sessionKind}function xe(e){return I(e)?.leaseAdmissionExempt===!0}function Se(e){return I(e)?.selectorValidationExempt!==!0}function Ce(e){return I(e)?.sessionExecutionLockExempt!==!0}function we(e){return I(e)?.replayScopedAction===!0}function Te(e){return I(e)?.allowInvalidRecording!==!0}function Ee(e){return I(e)?.saveScriptFlagOwner===!0}function De(){return N.filter(e=>e.saveScriptFlagOwner===!0).map(e=>e.command).sort()}function Oe(e){return I(e)?.lockPolicySelectorOverride===!0}function ke(e){return I(e)?.androidBlockingDialogGuard===!0}function Ae(e){if(e.command===`human_control`||e.command===`lease_heartbeat`)return!1;let t=h(e);return t===void 0?F(e.command)!==`observability`&&_(e.command)!==`observe`:t!==`observes-app`}function je(e){return I(e.command)?.preferExplicitDeviceOverExistingSession===!0}function Me(e){let t=I(e.command)?.allowSessionlessDefaultDevice;return typeof t==`function`&&t(e)}function Ne(e){return I(e.command)?.sessionlessLeaseAdmissionExemption?.(e)}function Pe(e){let t=I(e.command)?.refFrameEffect;return typeof t==`function`?t(e):t}function Fe(e,t){return t.hasExistingSession?je(e)&&t.hasExplicitDeviceIdentity?`explicit-device`:`existing-session`:Le(e)?`skip`:t.hasDeviceSelectionInput?`explicit-device`:Me(e)?`sessionless-default-device`:`skip`}function I(e){return P.descriptorsByCommand.get(e)}function Ie(e){let t=new Map;for(let n of e){if(t.has(n.command))throw Error(`Duplicate daemon command descriptor: ${n.command}`);t.set(n.command,n)}return{descriptorsByCommand:t}}function Le(e){let t=I(e.command);if(t?.route===`lease`)return!0;let n=t?.skipSessionlessProviderDevice;return typeof n==`function`&&n(e)}const L=a.pendingPixelIdentityEvidence,Re=[{target:`ios-simulator`,status:`accepted`},{target:`android-emulator`,status:`accepted`},{target:`android-device`,status:`rejected`,rejectionReason:L},{target:`macos-app-window`,status:`rejected`,rejectionReason:L},{target:`ios-physical`,status:`rejected`,rejectionReason:L},{target:`macos-helper`,status:`rejected`,rejectionReason:L},{target:`web`,status:`rejected`,rejectionReason:L},{target:`linux`,status:`rejected`,rejectionReason:L},{target:`tvos`,status:`rejected`,rejectionReason:L},{target:`harmonyos`,status:`rejected`,rejectionReason:L},{target:`vega`,status:`rejected`,rejectionReason:L}];function ze(e,t){switch(e.platform){case`apple`:return Be(e,t);case`android`:return e.kind===`device`?`android-device`:`android-emulator`;case`harmonyos`:return`harmonyos`;case`vega`:return`vega`;case`linux`:return`linux`;case`web`:return`web`}}function Be(e,t){let n=c(e);switch(n){case`ios`:case`ipados`:return e.kind===`device`?`ios-physical`:`ios-simulator`;case`tvos`:return`tvos`;case`macos`:return Ve(t);case`watchos`:case`visionos`:throw R(n)}}function Ve(e){return ae(e)===`macos-helper`?`macos-helper`:`macos-app-window`}function R(t,n){return new e(`UNSUPPORTED_OPERATION`,`screenshot --crop-on is not accepted on ${t} targets`,{reason:a.targetNotAccepted,...n?{rejectionReason:n}:{}})}function He(t){if(t.overlayRefs||t.fullscreen)throw new e(`INVALID_ARGS`,`--crop-on cannot be combined with --overlay-refs or --fullscreen: both move the captured frame away from the snapshot viewport the crop is measured against`,{reason:a.frameMismatch});try{te(t.cropOn)}catch{throw new e(`INVALID_ARGS`,`screenshot --crop-on requires a valid selector expression`,{reason:a.selectorInvalid})}let n=ze(t.device,t.surface),r=Re.find(e=>e.target===n);if(!r||r.status===`rejected`)throw R(n,r?.status===`rejected`?r.rejectionReason:void 0)}async function Ue(t,n){if(!We(n))throw new e(`INVALID_ARGS`,`Screenshot crop box must be positive integer pixel offsets`);let r=await ue(await j.readFile(t),n,`screenshot`);r!==null&&await j.writeFile(t,r)}function We(e){return Number.isInteger(e.x)&&e.x>=0&&Number.isInteger(e.y)&&e.y>=0&&Number.isInteger(e.width)&&e.width>0&&Number.isInteger(e.height)&&e.height>0}function Ge(t){switch(t){case`android`:return`device-pixels`;case`xctest`:case`macos-helper`:return`viewport-points`;default:throw new e(`UNSUPPORTED_OPERATION`,`screenshot --crop-on does not accept snapshot backend "${t??`unknown`}"`,{reason:a.targetNotAccepted})}}function z(e,t,n,r,i){if(e===`device-pixels`||t===null)return Ye(n);let a=r/t.width,o=i/t.height;return{x:Math.round((n.x-t.x)*a),y:Math.round((n.y-t.y)*o),width:Math.round(n.width*a),height:Math.round(n.height*o)}}function Ke(e,t,n){let r=Math.max(e.x,0),i=Math.max(e.y,0),a=Math.min(e.x+e.width,t),o=Math.min(e.y+e.height,n);return a<=r||o<=i?null:{x:r,y:i,width:a-r,height:o-i}}function B(e){let t=null;for(let n of e)!v(n)||!g(n.rect)||(!t||m(n.rect)>m(t))&&(t=n.rect);return t||qe(e.filter(e=>g(e.rect)&&!Je(e)))}function qe(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)g(a.rect)&&(t=Math.min(t,a.rect.x),n=Math.min(n,a.rect.y),r=Math.max(r,a.rect.x+a.rect.width),i=Math.max(i,a.rect.y+a.rect.height));return!Number.isFinite(t)||!Number.isFinite(n)||r<=t||i<=n?null:{x:t,y:n,width:r-t,height:i-n}}function Je(e){return p(e.type??``)===`image`&&!d(e.label)}function Ye(e){return{x:Math.round(e.x),y:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height)}}const Xe=`${a.partialIntersection}: the selector frame extends past the captured image; the crop was clipped to the image frame`;function Ze(e){return e?.partialIntersection?[Xe]:[]}async function Qe(t){let{device:n,session:r,surface:i,cropOn:o,screenshotPath:s,logPath:c,dispatchContext:l}=t,u={snapshotInteractiveOnly:!1},d=await S({device:n,session:r,flags:u,logPath:c,snapshotScope:void 0,captureData:async()=>await t.captureSnapshot({options:{appBundleId:l.appBundleId,interactiveOnly:!1,includeRects:!0,surface:i},execution:C(l)})}),f=x(d,u);if(f.snapshotQuality?.state===`sparse`)throw new e(`COMMAND_FAILED`,`the snapshot taken for --crop-on was sparse and cannot be read as the screen`,{reason:a.captureUnreadable});let p=await V(f.nodes,o,f.truncated,n),m=await de(s),h=z(Ge(f.backend),B(f.nodes),p.rect,m.width,m.height),g=Ke(h,m.width,m.height);if(g===null)throw new e(`COMMAND_FAILED`,`the frame resolved by --crop-on occupies no pixel of the capture`,{reason:a.emptyIntersection});let _=g.x!==h.x||g.y!==h.y||g.width<h.width||g.height<h.height;return await Ue(s,g),{partialIntersection:_}}async function V(t,n,r,i){let o=await ie(w.cropTarget,t,n,{platform:s(i)});if(o.kind===`ambiguous`)throw new e(`COMMAND_FAILED`,`--crop-on matched ${o.matchedNodes.length} nodes and must resolve to one`,{reason:a.targetAmbiguous,candidates:o.matchedNodes.map(e=>e.label??e.ref),matches:o.matchedNodes.length});if(o.kind===`none`)throw r?new e(`COMMAND_FAILED`,`the snapshot taken for --crop-on was truncated, so a missing match is not proven`,{reason:a.captureIncomplete}):new e(`COMMAND_FAILED`,`--crop-on matched no node: ${n}`,{reason:a.targetNotFound,hint:`find ${n} list`});return o.node}const $e=[`scroll`,`list`,`recyclerview`,`edittext`,`textfield`];function et(e,t,n){if(e.backend!==`android`||!n.hittable||!O(n.rect)||v(n))return!1;let r=p(n.type??``);return!($e.some(e=>r.includes(e))||t&&k(n.rect)>k(t)*.25)}function tt(e,t,n,r){return!e.rect||e.hittable!==!0||n(e)||r(e)?null:nt(e,t,r)}function nt(e,t,n){let r=e.rect,i=rt(e,t,n);if(!i)return null;let a=i.y-r.y,o=r.y+r.height-(i.y+i.height);if(a<0||o<0||Math.abs(o-a)<16)return null;let s=Math.min(a,o),c=Math.round(i.y-s),l=Math.round(i.height+s*2);return l<=0||l>=r.height?null:{x:r.x,y:c,width:r.width,height:l}}function rt(e,t,n){let r=e.rect,i=new Map(t.map(e=>[e.index,e])),a=t.filter(t=>t.ref!==e.ref&&at(t,e,i)&&it(t,n)&&O(t.rect)&&u(r,t.rect)).map(e=>e.rect);return a.length<2?null:me(a)}function it(e,t){let n=p(e.type??``);return n.includes(`text`)||n.includes(`image`)&&t(e)}function at(e,t,n){let r=e;for(;r.parentIndex!==void 0;){let e=n.get(r.parentIndex);if(!e)return!1;if(e.ref===t.ref)return!0;r=e}return!1}const ot=[`button`,`link`,`menu`,`tab`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];async function H(e){let t=await j.readFile(e.screenshotPath),n=await T(t,`screenshot`),r=st(e.snapshot,n.width,n.height,{maxRefs:e.maxRefs});for(let e of r)he(n,e);return await j.writeFile(e.screenshotPath,await E(n)),r}function st(e,t,r,i={}){let a=B(e.nodes),o=new Map;for(let n of e.nodes){if(!ut(e,a,n))continue;let i=dt(e.nodes,n);if(!i?.rect||!O(i.rect))continue;let s=ft(n,i,e.nodes),c=pt(n,i,s),l=U(e,a,lt(e,i,e.nodes),t,r);if(!O(l))continue;let u=o.get(i.ref);(!u||c>u.score)&&o.set(i.ref,{ref:i.ref,label:s,rect:i.rect,overlayRect:l,score:c})}return ct(e,a,o,t,r),mt([...o.values()]).sort(wt).slice(0,i.maxRefs??24).sort(Y).map(e=>({ref:e.ref,label:e.label,rect:e.rect,overlayRect:e.overlayRect,center:n(e.overlayRect)}))}function ct(e,t,n,r,i){let a=oe(e.nodes).primaryAction;if(!a?.ref||!a.rect||!O(a.rect))return;let o=U(e,t,a.rect,r,i);if(!O(o))return;let s={ref:a.ref,label:a.label,rect:a.rect,overlayRect:o,score:100},c=n.get(a.ref);n.set(a.ref,c?{...c,score:Math.max(c.score,s.score)}:s)}function lt(e,t,n){return e.backend===`android`?tt(t,n,W,e=>!!J(e))??t.rect:t.rect}function ut(e,t,n){let r=[n.label,n.value].some(K)||q(n.identifier);return et(e,t,n)?!0:W(n)?r:r&&ht(n)}function dt(e,t){return[G(t)?t:null,b(e,t,G),t.hittable?t:null,b(e,t,e=>e.hittable===!0)].find(gt)??null}function ft(e,t,n){let r=J(e);return e.ref!==t.ref&&r?r:_t(t,n)||J(t)}function pt(e,t,n){let r=0;return e.ref===t.ref&&(r+=4),t.hittable&&(r+=3),W(t)&&(r+=3),W(e)&&(r+=2),n&&(r+=2),q(t.identifier)&&(r+=1),d(t.value)&&(r+=1),r}function mt(e){let t=[];for(let n of e.sort((e,t)=>k(e.overlayRect)-k(t.overlayRect))){let e=t.findIndex(e=>e.label!==void 0&&e.label===n.label&&(u(e.overlayRect,n.overlayRect)||u(n.overlayRect,e.overlayRect)));if(e===-1){t.push(n);continue}k(n.overlayRect)<k(t[e].overlayRect)&&(t[e]=n)}return t}function U(e,t,n,r,i){return Ct(z(e.backend===`android`?`device-pixels`:`viewport-points`,t,n,r,i),r,i)}function W(e){let t=[e.type,e.role,e.subrole].map(e=>p(e??``)).join(` `);return ot.some(e=>t.includes(e))}function G(e){return W(e)&&!v(e)}function ht(e){let t=p(e.type??``);return t.includes(`statictext`)||t.includes(`image`)||t.includes(`text`)||t.includes(`other`)}function gt(e){return!!(e?.rect&&O(e.rect)&&!v(e))}function K(e){return d(e)?!bt(e):!1}function q(e){return typeof e!=`string`||!K(e)?!1:!xt(e)}function J(e){let t=[e.label,e.value].find(K);if(t)return t.trim();if(q(e.identifier))return e.identifier.trim()}function _t(e,t){let n=null;for(let r of t){if(r.ref===e.ref||!vt(r,e,t))continue;let i=J(r);if(!i)continue;let a=yt(r);(!n||a>n.score)&&(n={label:i,score:a})}return n?.label}function vt(e,t,n){let r=e;for(;r.parentIndex!==void 0;){let e=n[r.parentIndex];if(!e)return!1;if(e.ref===t.ref)return!0;r=e}return!1}function yt(e){let t=0;return p(e.type??``).includes(`text`)&&(t+=2),K(e.label)&&(t+=2),K(e.value)&&(t+=1),t}function bt(e){let t=e?.trim().toLowerCase();return t===`toolbar`||t===`window`||t===`application`||t?.startsWith(`vertical scroll bar`)===!0}function xt(e){return/^[a-z0-9_.]+:id\/[a-z0-9_.-]+$/i.test(e.trim())}function St(e,t){return Number.parseInt(e.replace(/^\D+/,``),10)-Number.parseInt(t.replace(/^\D+/,``),10)}function Ct(e,t,n){let r=D(e.x,0,Math.max(0,t-1)),i=D(e.y,0,Math.max(0,n-1)),a=Math.max(1,t-r),o=Math.max(1,n-i);return{x:r,y:i,width:D(e.width,1,a),height:D(e.height,1,o)}}function Y(e,t){let n=e.overlayRect.y-t.overlayRect.y;if(n!==0)return n;let r=e.overlayRect.x-t.overlayRect.x;return r===0?St(e.ref,t.ref):r}function wt(e,t){return t.score===e.score?Y(e,t):t.score-e.score}async function X(e){let t=f({overlayRefs:e.overlayRefs,cropOn:e.cropOn!==void 0}),n=await ye({device:e.device,plan:t,inspectFacts:e.inspectFacts});return n.admitted?{ok:!0,runtime:await Tt(e.bindDevice,n)}:{ok:!1,response:Dt(t.kind,n.operation,n.fact)}}async function Tt(e,t){let n=ve(e),{device:r,plan:i}=ge(t);switch(i.kind){case`capture`:{let e=await n(r,i.use);return Object.freeze({captureScreenshot:Z(e)})}case`capture-with-overlay-refs`:case`capture-with-crop-on`:{let e=await n(r,i.use);return Object.freeze({captureScreenshot:Z(e),captureSnapshot:Et(e)})}}}function Z(e){return async t=>await e.operations.captureScreenshot(t)}function Et(e){return async t=>await e.operations.captureSnapshot(t)}function Dt(e,n,r){return n===`captureScreenshot`?_e(`screenshot`,r):e===`capture-with-crop-on`?t(`UNSUPPORTED_OPERATION`,`--crop-on crops the capture to a selector frame using a snapshot taken on the same screen, which this target cannot capture.`,{reason:r.available?void 0:r.reason},{hint:(r.available?void 0:r.hint)??`Re-run screenshot without --crop-on.`}):t(`UNSUPPORTED_OPERATION`,`--overlay-refs annotates a capture with the refs of a snapshot taken on the same screen, which this target cannot capture.`,{reason:r.available?void 0:r.reason},{hint:(r.available?void 0:r.hint)??`Re-run screenshot without --overlay-refs.`})}async function Ot(t){let{req:n,session:r}=t,a=i(`screenshot`,n.flags);if(a)throw new e(`INVALID_ARGS`,a);pe(r.device,n.flags?.screenshotPixelDensity);let o=Nt(n),s=typeof n.flags?.screenshotCropOn==`string`&&n.flags.screenshotCropOn.length>0?n.flags.screenshotCropOn:void 0;s!==void 0&&He({device:r.device,surface:r.surface,cropOn:s,overlayRefs:n.flags?.overlayRefs===!0,fullscreen:n.flags?.screenshotFullscreen===!0});let c=await X({device:r.device,overlayRefs:n.flags?.overlayRefs===!0,cropOn:s,inspectFacts:t.inspectFacts,bindDevice:t.bindDevice});if(!c.ok)return c;let l=c.runtime,u={warnings:[]};return{ok:!0,recorded:o.recorded,execute:async e=>await kt({session:e.session,sessionName:e.sessionName,logPath:e.logPath,dispatchContext:e.dispatchContext,flags:e.request.flags,outPath:o.outPath,runtime:l,cropOn:s,cropRun:u})}}async function Q(e){let{session:t,sessionName:n,outPath:i,dispatchContext:a}=e;return await le({backend:Pt(e),artifacts:Ft(),sessions:ce({sessionName:n,getSession:()=>t,recordOptions:{includeSnapshot:!1},setRecord:()=>{}}),policy:re()}).capture.screenshot({session:n,requestId:a.requestId,appBundleId:t.appBundleId,...r(a),surface:t.surface,...i?{out:{kind:`path`,path:i}}:{}})}function $(e){return C(e)}async function kt(e){let{session:t,runtime:n,flags:r}=e,i=At({cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,cropRun:e.cropRun,logPath:e.logPath}),a=await Q({session:t,sessionName:e.sessionName,outPath:e.outPath,dispatchContext:e.dispatchContext,captureScreenshot:n.captureScreenshot,...i?{crop:i}:{}}),o=[...a.warnings??[],...i?.run?.warnings??[]];return{...a,...o.length>0?{warnings:o}:{},...await jt({session:t,cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,screenshotPath:a.path,logPath:e.logPath,dispatchContext:e.dispatchContext}),...await fe({device:t.device,path:a.path,requestedPixelDensity:r?.screenshotPixelDensity,scale:r?.screenshotScale})}}function At(e){let{cropOn:t,captureSnapshot:n,cropRun:r}=e;if(t!==void 0&&n!==void 0&&r!==void 0)return{cropOn:t,captureSnapshot:n,run:r,logPath:e.logPath}}async function jt(e){let{session:t,cropOn:n,captureSnapshot:r}=e;return n!==void 0||r===void 0?{}:{overlayRefs:await Mt({session:t,logPath:e.logPath,screenshotPath:e.screenshotPath,dispatchContext:e.dispatchContext,captureSnapshot:r})}}async function Mt(e){let{session:t,dispatchContext:n}=e,r={snapshotInteractiveOnly:!0},i=await S({device:t.device,session:t,flags:r,logPath:e.logPath,snapshotScope:void 0,captureData:async()=>await e.captureSnapshot({options:{appBundleId:t.appBundleId,interactiveOnly:!0,surface:t.surface},execution:$(n)})}),a=x(i,r);return se(t,a),await H({screenshotPath:e.screenshotPath,snapshot:a})}function Nt(e){let t=e.positionals??[],n=e.flags??{},r=t=>t===void 0?void 0:ne.expandHome(t,e.meta?.cwd),i=r(t[0]),a=r(n.out);return{outPath:i??a,recorded:{positionals:i?[i,...t.slice(1)]:t,flags:a?{...n,out:a}:n}}}function Pt(e){let{session:t,dispatchContext:n,captureScreenshot:i,crop:a}=e;return{platform:s(t.device),captureScreenshot:async(e,s,c)=>{let u=r({...n,...o(c)});if(await i({outPath:s,options:{appBundleId:n.appBundleId,pixelDensity:u.pixelDensity,fullscreen:u.fullscreen,normalizeStatusBar:u.normalizeStatusBar,stabilize:u.stabilize,surface:c?.surface,skipIosSimulatorBootCheck:n.skipIosSimulatorBootCheck??(l(t.device)&&t.device.kind===`simulator`),captureBackend:n.screenshotCaptureBackend},execution:$(n)}),a){let e=await Qe({device:t.device,session:t,surface:t.surface,cropOn:a.cropOn,screenshotPath:s,logPath:a.logPath,dispatchContext:n,captureSnapshot:a.captureSnapshot});a.run.warnings.push(...Ze(e))}}}}function Ft(){return{resolveInput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`screenshot does not resolve input artifacts`)},reserveOutput:async e=>{let t,n;return e?.kind===`path`?n=e.path:(t=await j.mkdtemp(A.join(M.tmpdir(),`agent-device-screenshot-`)),n=A.join(t,`screenshot.png`)),await j.mkdir(A.dirname(n),{recursive:!0}),{path:n,visibility:`client-visible`,publish:async()=>void 0,...t?{cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}:{}}},createTempFile:async e=>{let t=await j.mkdtemp(A.join(M.tmpdir(),`${e.prefix}-`));return{path:A.join(t,`file${e.ext}`),visibility:`internal`,cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}}}}export{Te as _,H as a,Se as b,be as c,xe as d,De as f,Ne as g,Pe as h,X as i,F as l,Fe as m,Ot as n,Oe as o,Ee as p,$ as r,we as s,Q as t,Ae as u,ke as v,Ce as y};
1
+ import{N as e,o as t,y as n}from"./sdk-contracts.js";import{f as r,l as i,r as a,u as o}from"./capture.js";import{C as s,D as c,p as l}from"./sdk-device.js";import{$r as u,Ir as d,It as f,Lr as p,Qr as m,S as h,Yr as g,b as _,f as ee,hn as te,jr as v,l as y,zr as b}from"./sdk-batch.js";import{t as ne}from"./session-store.js";import{T as re,d as ie}from"./runtime.js";import{r as ae}from"./session.js";import{t as oe}from"./overlay.js";import{t as x}from"./snapshot-state.js";import{c as S,f as C,i as se,o as ce,u as le}from"./session-snapshot.js";import{t as w}from"./selector-pipeline-policy.js";import{i as T,o as E,r as ue}from"./png-worker-client.js";import{t as de}from"./png-size.js";import{r as fe,t as pe}from"./screenshot-density.js";import{a as D,c as me,o as O,s as k,t as he}from"./screenshot-overlay-draw.js";import{a as ge,i as _e,n as ve,t as ye}from"./session-runtime-admission.js";import A from"node:path";import{promises as j}from"node:fs";import M from"node:os";const N=y(ee),P=Ie(N);function be(e){return I(e)?.route??`generic`}function F(e){return I(e)?.sessionKind}function xe(e){return I(e)?.leaseAdmissionExempt===!0}function Se(e){return I(e)?.selectorValidationExempt!==!0}function Ce(e){return I(e)?.sessionExecutionLockExempt!==!0}function we(e){return I(e)?.replayScopedAction===!0}function Te(e){return I(e)?.allowInvalidRecording!==!0}function Ee(e){return I(e)?.saveScriptFlagOwner===!0}function De(){return N.filter(e=>e.saveScriptFlagOwner===!0).map(e=>e.command).sort()}function Oe(e){return I(e)?.lockPolicySelectorOverride===!0}function ke(e){return I(e)?.androidBlockingDialogGuard===!0}function Ae(e){if(e.command===`human_control`||e.command===`lease_heartbeat`)return!1;let t=h(e);return t===void 0?F(e.command)!==`observability`&&_(e.command)!==`observe`:t!==`observes-app`}function je(e){return I(e.command)?.preferExplicitDeviceOverExistingSession===!0}function Me(e){let t=I(e.command)?.allowSessionlessDefaultDevice;return typeof t==`function`&&t(e)}function Ne(e){return I(e.command)?.sessionlessLeaseAdmissionExemption?.(e)}function Pe(e){let t=I(e.command)?.refFrameEffect;return typeof t==`function`?t(e):t}function Fe(e,t){return t.hasExistingSession?je(e)&&t.hasExplicitDeviceIdentity?`explicit-device`:`existing-session`:Le(e)?`skip`:t.hasDeviceSelectionInput?`explicit-device`:Me(e)?`sessionless-default-device`:`skip`}function I(e){return P.descriptorsByCommand.get(e)}function Ie(e){let t=new Map;for(let n of e){if(t.has(n.command))throw Error(`Duplicate daemon command descriptor: ${n.command}`);t.set(n.command,n)}return{descriptorsByCommand:t}}function Le(e){let t=I(e.command);if(t?.route===`lease`)return!0;let n=t?.skipSessionlessProviderDevice;return typeof n==`function`&&n(e)}const L=a.pendingPixelIdentityEvidence,Re=[{target:`ios-simulator`,status:`accepted`},{target:`android-emulator`,status:`accepted`},{target:`android-device`,status:`rejected`,rejectionReason:L},{target:`macos-app-window`,status:`rejected`,rejectionReason:L},{target:`ios-physical`,status:`rejected`,rejectionReason:L},{target:`macos-helper`,status:`rejected`,rejectionReason:L},{target:`web`,status:`rejected`,rejectionReason:L},{target:`linux`,status:`rejected`,rejectionReason:L},{target:`tvos`,status:`rejected`,rejectionReason:L},{target:`harmonyos`,status:`rejected`,rejectionReason:L},{target:`vega`,status:`rejected`,rejectionReason:L}];function ze(e,t){switch(e.platform){case`apple`:return Be(e,t);case`android`:return e.kind===`device`?`android-device`:`android-emulator`;case`harmonyos`:return`harmonyos`;case`vega`:return`vega`;case`linux`:return`linux`;case`web`:return`web`}}function Be(e,t){let n=c(e);switch(n){case`ios`:case`ipados`:return e.kind===`device`?`ios-physical`:`ios-simulator`;case`tvos`:return`tvos`;case`macos`:return Ve(t);case`watchos`:case`visionos`:throw R(n)}}function Ve(e){return ae(e)===`macos-helper`?`macos-helper`:`macos-app-window`}function R(t,n){return new e(`UNSUPPORTED_OPERATION`,`screenshot --crop-on is not accepted on ${t} targets`,{reason:a.targetNotAccepted,...n?{rejectionReason:n}:{}})}function He(t){if(t.overlayRefs||t.fullscreen)throw new e(`INVALID_ARGS`,`--crop-on cannot be combined with --overlay-refs or --fullscreen: both move the captured frame away from the snapshot viewport the crop is measured against`,{reason:a.frameMismatch});try{te(t.cropOn)}catch{throw new e(`INVALID_ARGS`,`screenshot --crop-on requires a valid selector expression`,{reason:a.selectorInvalid})}let n=ze(t.device,t.surface),r=Re.find(e=>e.target===n);if(!r||r.status===`rejected`)throw R(n,r?.status===`rejected`?r.rejectionReason:void 0)}async function Ue(t,n){if(!We(n))throw new e(`INVALID_ARGS`,`Screenshot crop box must be positive integer pixel offsets`);let r=await ue(await j.readFile(t),n,`screenshot`);r!==null&&await j.writeFile(t,r)}function We(e){return Number.isInteger(e.x)&&e.x>=0&&Number.isInteger(e.y)&&e.y>=0&&Number.isInteger(e.width)&&e.width>0&&Number.isInteger(e.height)&&e.height>0}function Ge(t){switch(t){case`android`:return`device-pixels`;case`xctest`:case`macos-helper`:return`viewport-points`;default:throw new e(`UNSUPPORTED_OPERATION`,`screenshot --crop-on does not accept snapshot backend "${t??`unknown`}"`,{reason:a.targetNotAccepted})}}function z(e,t,n,r,i){if(e===`device-pixels`||t===null)return Ye(n);let a=r/t.width,o=i/t.height;return{x:Math.round((n.x-t.x)*a),y:Math.round((n.y-t.y)*o),width:Math.round(n.width*a),height:Math.round(n.height*o)}}function Ke(e,t,n){let r=Math.max(e.x,0),i=Math.max(e.y,0),a=Math.min(e.x+e.width,t),o=Math.min(e.y+e.height,n);return a<=r||o<=i?null:{x:r,y:i,width:a-r,height:o-i}}function B(e){let t=null;for(let n of e)!v(n)||!g(n.rect)||(!t||m(n.rect)>m(t))&&(t=n.rect);return t||qe(e.filter(e=>g(e.rect)&&!Je(e)))}function qe(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)g(a.rect)&&(t=Math.min(t,a.rect.x),n=Math.min(n,a.rect.y),r=Math.max(r,a.rect.x+a.rect.width),i=Math.max(i,a.rect.y+a.rect.height));return!Number.isFinite(t)||!Number.isFinite(n)||r<=t||i<=n?null:{x:t,y:n,width:r-t,height:i-n}}function Je(e){return p(e.type??``)===`image`&&!d(e.label)}function Ye(e){return{x:Math.round(e.x),y:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height)}}const Xe=`${a.partialIntersection}: the selector frame extends past the captured image; the crop was clipped to the image frame`;function Ze(e){return e?.partialIntersection?[Xe]:[]}async function Qe(t){let{device:n,session:r,surface:i,cropOn:o,screenshotPath:s,logPath:c,dispatchContext:l}=t,u={snapshotInteractiveOnly:!1},d=await S({device:n,session:r,flags:u,logPath:c,snapshotScope:void 0,captureData:async()=>await t.captureSnapshot({options:{appBundleId:l.appBundleId,interactiveOnly:!1,includeRects:!0,surface:i},execution:C(l)})}),f=x(d,u);if(f.snapshotQuality?.state===`sparse`)throw new e(`COMMAND_FAILED`,`the snapshot taken for --crop-on was sparse and cannot be read as the screen`,{reason:a.captureUnreadable});let p=await V(f.nodes,o,f.truncated,n),m=await de(s),h=z(Ge(f.backend),B(f.nodes),p.rect,m.width,m.height),g=Ke(h,m.width,m.height);if(g===null)throw new e(`COMMAND_FAILED`,`the frame resolved by --crop-on occupies no pixel of the capture`,{reason:a.emptyIntersection});let _=g.x!==h.x||g.y!==h.y||g.width<h.width||g.height<h.height;return await Ue(s,g),{partialIntersection:_}}async function V(t,n,r,i){let o=await ie(w.cropTarget,t,n,{platform:s(i)});if(o.kind===`ambiguous`)throw new e(`COMMAND_FAILED`,`--crop-on matched ${o.matchedNodes.length} nodes and must resolve to one`,{reason:a.targetAmbiguous,candidates:o.matchedNodes.map(e=>e.label??e.ref),matches:o.matchedNodes.length});if(o.kind===`none`)throw r?new e(`COMMAND_FAILED`,`the snapshot taken for --crop-on was truncated, so a missing match is not proven`,{reason:a.captureIncomplete}):new e(`COMMAND_FAILED`,`--crop-on matched no node: ${n}`,{reason:a.targetNotFound,hint:`find ${n} list`});return o.node}const $e=[`scroll`,`list`,`recyclerview`,`edittext`,`textfield`];function et(e,t,n){if(e.backend!==`android`||!n.hittable||!O(n.rect)||v(n))return!1;let r=p(n.type??``);return!($e.some(e=>r.includes(e))||t&&k(n.rect)>k(t)*.25)}function tt(e,t,n,r){return!e.rect||e.hittable!==!0||n(e)||r(e)?null:nt(e,t,r)}function nt(e,t,n){let r=e.rect,i=rt(e,t,n);if(!i)return null;let a=i.y-r.y,o=r.y+r.height-(i.y+i.height);if(a<0||o<0||Math.abs(o-a)<16)return null;let s=Math.min(a,o),c=Math.round(i.y-s),l=Math.round(i.height+s*2);return l<=0||l>=r.height?null:{x:r.x,y:c,width:r.width,height:l}}function rt(e,t,n){let r=e.rect,i=new Map(t.map(e=>[e.index,e])),a=t.filter(t=>t.ref!==e.ref&&at(t,e,i)&&it(t,n)&&O(t.rect)&&u(r,t.rect)).map(e=>e.rect);return a.length<2?null:me(a)}function it(e,t){let n=p(e.type??``);return n.includes(`text`)||n.includes(`image`)&&t(e)}function at(e,t,n){let r=e;for(;r.parentIndex!==void 0;){let e=n.get(r.parentIndex);if(!e)return!1;if(e.ref===t.ref)return!0;r=e}return!1}const ot=[`button`,`link`,`menu`,`tab`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];async function H(e){let t=await j.readFile(e.screenshotPath),n=await T(t,`screenshot`),r=st(e.snapshot,n.width,n.height,{maxRefs:e.maxRefs});for(let e of r)he(n,e);return await j.writeFile(e.screenshotPath,await E(n)),r}function st(e,t,r,i={}){let a=B(e.nodes),o=new Map;for(let n of e.nodes){if(!ut(e,a,n))continue;let i=dt(e.nodes,n);if(!i?.rect||!O(i.rect))continue;let s=ft(n,i,e.nodes),c=pt(n,i,s),l=U(e,a,lt(e,i,e.nodes),t,r);if(!O(l))continue;let u=o.get(i.ref);(!u||c>u.score)&&o.set(i.ref,{ref:i.ref,label:s,rect:i.rect,overlayRect:l,score:c})}return ct(e,a,o,t,r),mt([...o.values()]).sort(wt).slice(0,i.maxRefs??24).sort(Y).map(e=>({ref:e.ref,label:e.label,rect:e.rect,overlayRect:e.overlayRect,center:n(e.overlayRect)}))}function ct(e,t,n,r,i){let a=oe(e.nodes).primaryAction;if(!a?.ref||!a.rect||!O(a.rect))return;let o=U(e,t,a.rect,r,i);if(!O(o))return;let s={ref:a.ref,label:a.label,rect:a.rect,overlayRect:o,score:100},c=n.get(a.ref);n.set(a.ref,c?{...c,score:Math.max(c.score,s.score)}:s)}function lt(e,t,n){return e.backend===`android`?tt(t,n,W,e=>!!J(e))??t.rect:t.rect}function ut(e,t,n){let r=[n.label,n.value].some(K)||q(n.identifier);return et(e,t,n)?!0:W(n)?r:r&&ht(n)}function dt(e,t){return[G(t)?t:null,b(e,t,G),t.hittable?t:null,b(e,t,e=>e.hittable===!0)].find(gt)??null}function ft(e,t,n){let r=J(e);return e.ref!==t.ref&&r?r:_t(t,n)||J(t)}function pt(e,t,n){let r=0;return e.ref===t.ref&&(r+=4),t.hittable&&(r+=3),W(t)&&(r+=3),W(e)&&(r+=2),n&&(r+=2),q(t.identifier)&&(r+=1),d(t.value)&&(r+=1),r}function mt(e){let t=[];for(let n of e.sort((e,t)=>k(e.overlayRect)-k(t.overlayRect))){let e=t.findIndex(e=>e.label!==void 0&&e.label===n.label&&(u(e.overlayRect,n.overlayRect)||u(n.overlayRect,e.overlayRect)));if(e===-1){t.push(n);continue}k(n.overlayRect)<k(t[e].overlayRect)&&(t[e]=n)}return t}function U(e,t,n,r,i){return Ct(z(e.backend===`android`?`device-pixels`:`viewport-points`,t,n,r,i),r,i)}function W(e){let t=[e.type,e.role,e.subrole].map(e=>p(e??``)).join(` `);return ot.some(e=>t.includes(e))}function G(e){return W(e)&&!v(e)}function ht(e){let t=p(e.type??``);return t.includes(`statictext`)||t.includes(`image`)||t.includes(`text`)||t.includes(`other`)}function gt(e){return!!(e?.rect&&O(e.rect)&&!v(e))}function K(e){return d(e)?!bt(e):!1}function q(e){return typeof e!=`string`||!K(e)?!1:!xt(e)}function J(e){let t=[e.label,e.value].find(K);if(t)return t.trim();if(q(e.identifier))return e.identifier.trim()}function _t(e,t){let n=null;for(let r of t){if(r.ref===e.ref||!vt(r,e,t))continue;let i=J(r);if(!i)continue;let a=yt(r);(!n||a>n.score)&&(n={label:i,score:a})}return n?.label}function vt(e,t,n){let r=e;for(;r.parentIndex!==void 0;){let e=n[r.parentIndex];if(!e)return!1;if(e.ref===t.ref)return!0;r=e}return!1}function yt(e){let t=0;return p(e.type??``).includes(`text`)&&(t+=2),K(e.label)&&(t+=2),K(e.value)&&(t+=1),t}function bt(e){let t=e?.trim().toLowerCase();return t===`toolbar`||t===`window`||t===`application`||t?.startsWith(`vertical scroll bar`)===!0}function xt(e){return/^[a-z0-9_.]+:id\/[a-z0-9_.-]+$/i.test(e.trim())}function St(e,t){return Number.parseInt(e.replace(/^\D+/,``),10)-Number.parseInt(t.replace(/^\D+/,``),10)}function Ct(e,t,n){let r=D(e.x,0,Math.max(0,t-1)),i=D(e.y,0,Math.max(0,n-1)),a=Math.max(1,t-r),o=Math.max(1,n-i);return{x:r,y:i,width:D(e.width,1,a),height:D(e.height,1,o)}}function Y(e,t){let n=e.overlayRect.y-t.overlayRect.y;if(n!==0)return n;let r=e.overlayRect.x-t.overlayRect.x;return r===0?St(e.ref,t.ref):r}function wt(e,t){return t.score===e.score?Y(e,t):t.score-e.score}async function X(e){let t=f({overlayRefs:e.overlayRefs,cropOn:e.cropOn!==void 0}),n=await ye({device:e.device,plan:t,inspectFacts:e.inspectFacts});return n.admitted?{ok:!0,runtime:await Tt(e.bindDevice,n)}:{ok:!1,response:Dt(t.kind,n.operation,n.fact)}}async function Tt(e,t){let n=ve(e),{device:r,plan:i}=ge(t);switch(i.kind){case`capture`:{let e=await n(r,i.use);return Object.freeze({captureScreenshot:Z(e)})}case`capture-with-overlay-refs`:case`capture-with-crop-on`:{let e=await n(r,i.use);return Object.freeze({captureScreenshot:Z(e),captureSnapshot:Et(e)})}}}function Z(e){return async t=>await e.operations.captureScreenshot(t)}function Et(e){return async t=>await e.operations.captureSnapshot(t)}function Dt(e,n,r){return n===`captureScreenshot`?_e(`screenshot`,r):e===`capture-with-crop-on`?t(`UNSUPPORTED_OPERATION`,`--crop-on crops the capture to a selector frame using a snapshot taken on the same screen, which this target cannot capture.`,{reason:r.available?void 0:r.reason},{hint:(r.available?void 0:r.hint)??`Re-run screenshot without --crop-on.`}):t(`UNSUPPORTED_OPERATION`,`--overlay-refs annotates a capture with the refs of a snapshot taken on the same screen, which this target cannot capture.`,{reason:r.available?void 0:r.reason},{hint:(r.available?void 0:r.hint)??`Re-run screenshot without --overlay-refs.`})}async function Ot(t){let{req:n,session:r}=t,a=i(`screenshot`,n.flags);if(a)throw new e(`INVALID_ARGS`,a);pe(r.device,n.flags?.screenshotPixelDensity);let o=Nt(n),s=typeof n.flags?.screenshotCropOn==`string`&&n.flags.screenshotCropOn.length>0?n.flags.screenshotCropOn:void 0;s!==void 0&&He({device:r.device,surface:r.surface,cropOn:s,overlayRefs:n.flags?.overlayRefs===!0,fullscreen:n.flags?.screenshotFullscreen===!0});let c=await X({device:r.device,overlayRefs:n.flags?.overlayRefs===!0,cropOn:s,inspectFacts:t.inspectFacts,bindDevice:t.bindDevice});if(!c.ok)return c;let l=c.runtime,u={warnings:[]};return{ok:!0,recorded:o.recorded,execute:async e=>await kt({session:e.session,sessionName:e.sessionName,logPath:e.logPath,dispatchContext:e.dispatchContext,flags:e.request.flags,outPath:o.outPath,runtime:l,cropOn:s,cropRun:u})}}async function Q(e){let{session:t,sessionName:n,outPath:i,dispatchContext:a}=e;return await le({backend:Pt(e),artifacts:Ft(),sessions:ce({sessionName:n,getSession:()=>t,recordOptions:{includeSnapshot:!1},setRecord:()=>{}}),policy:re()}).capture.screenshot({session:n,requestId:a.requestId,appBundleId:t.appBundleId,...r(a),surface:t.surface,...i?{out:{kind:`path`,path:i}}:{}})}function $(e){return C(e)}async function kt(e){let{session:t,runtime:n,flags:r}=e,i=At({cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,cropRun:e.cropRun,logPath:e.logPath}),a=await Q({session:t,sessionName:e.sessionName,outPath:e.outPath,dispatchContext:e.dispatchContext,captureScreenshot:n.captureScreenshot,...i?{crop:i}:{}}),o=[...a.warnings??[],...i?.run?.warnings??[]];return{...a,...o.length>0?{warnings:o}:{},...await jt({session:t,cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,screenshotPath:a.path,logPath:e.logPath,dispatchContext:e.dispatchContext}),...await fe({device:t.device,path:a.path,requestedPixelDensity:r?.screenshotPixelDensity,scale:r?.screenshotScale})}}function At(e){let{cropOn:t,captureSnapshot:n,cropRun:r}=e;if(t!==void 0&&n!==void 0&&r!==void 0)return{cropOn:t,captureSnapshot:n,run:r,logPath:e.logPath}}async function jt(e){let{session:t,cropOn:n,captureSnapshot:r}=e;return n!==void 0||r===void 0?{}:{overlayRefs:await Mt({session:t,logPath:e.logPath,screenshotPath:e.screenshotPath,dispatchContext:e.dispatchContext,captureSnapshot:r})}}async function Mt(e){let{session:t,dispatchContext:n}=e,r={snapshotInteractiveOnly:!0},i=await S({device:t.device,session:t,flags:r,logPath:e.logPath,snapshotScope:void 0,captureData:async()=>await e.captureSnapshot({options:{appBundleId:t.appBundleId,interactiveOnly:!0,surface:t.surface},execution:$(n)})}),a=x(i,r);return se(t,a),await H({screenshotPath:e.screenshotPath,snapshot:a})}function Nt(e){let t=e.positionals??[],n=e.flags??{},r=t=>t===void 0?void 0:ne.expandHome(t,e.meta?.cwd),i=r(t[0]),a=r(n.out);return{outPath:i??a,recorded:{positionals:i?[i,...t.slice(1)]:t,flags:a?{...n,out:a}:n}}}function Pt(e){let{session:t,dispatchContext:n,captureScreenshot:i,crop:a}=e;return{platform:s(t.device),captureScreenshot:async(e,s,c)=>{let u=r({...n,...o(c)}),d=await i({outPath:s,options:{appBundleId:n.appBundleId,pixelDensity:u.pixelDensity,fullscreen:u.fullscreen,normalizeStatusBar:u.normalizeStatusBar,stabilize:u.stabilize,surface:c?.surface,skipIosSimulatorBootCheck:n.skipIosSimulatorBootCheck??(l(t.device)&&t.device.kind===`simulator`),captureBackend:n.screenshotCaptureBackend},execution:$(n)});if(a){let e=await Qe({device:t.device,session:t,surface:t.surface,cropOn:a.cropOn,screenshotPath:s,logPath:a.logPath,dispatchContext:n,captureSnapshot:a.captureSnapshot});a.run.warnings.push(...Ze(e))}return d.displayRotation?{displayRotation:d.displayRotation}:void 0}}}function Ft(){return{resolveInput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`screenshot does not resolve input artifacts`)},reserveOutput:async e=>{let t,n;return e?.kind===`path`?n=e.path:(t=await j.mkdtemp(A.join(M.tmpdir(),`agent-device-screenshot-`)),n=A.join(t,`screenshot.png`)),await j.mkdir(A.dirname(n),{recursive:!0}),{path:n,visibility:`client-visible`,publish:async()=>void 0,...t?{cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}:{}}},createTempFile:async e=>{let t=await j.mkdtemp(A.join(M.tmpdir(),`${e.prefix}-`));return{path:A.join(t,`file${e.ext}`),visibility:`internal`,cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}}}}export{Te as _,H as a,Se as b,be as c,xe as d,De as f,Ne as g,Pe as h,X as i,F as l,Fe as m,Ot as n,Oe as o,Ee as p,$ as r,we as s,Q as t,Ae as u,ke as v,Ce as y};
@@ -1,4 +1,4 @@
1
- import{N as e,s as t}from"./sdk-contracts.js";import{y as n}from"./registry.js";import{n as r}from"./path-resolution.js";import"./file.js";import{n as i}from"./screenshot-result.js";import{t as a}from"./shared.js";import{t as o}from"./cli-runner.js";import{n as s,t as c}from"./color.js";import l from"node:path";function u(e){let t=e.baselineInitialized===!0,r=e.summary??{},i=v(r.additions),a=v(r.removals),o=v(r.unchanged),l=s(),u=n(e),d=u.length>0?`${u.join(`
1
+ import{N as e,s as t}from"./sdk-contracts.js";import{b as n}from"./registry.js";import{n as r}from"./path-resolution.js";import"./file.js";import{n as i}from"./screenshot-result.js";import{t as a}from"./shared.js";import{t as o}from"./cli-runner.js";import{n as s,t as c}from"./color.js";import l from"node:path";function u(e){let t=e.baselineInitialized===!0,r=e.summary??{},i=v(r.additions),a=v(r.removals),o=v(r.unchanged),l=s(),u=n(e),d=u.length>0?`${u.join(`
2
2
  `)}\n`:``;if(t)return`${d}Baseline initialized (${o} lines).\n`;let f=y(Array.isArray(e.lines)?e.lines:[],1).map(e=>{let t=typeof e.text==`string`?e.text:``;if(e.kind===`added`){let e=t.startsWith(` `)?`+${t}`:`+ ${t}`;return l?c(e,`green`):e}if(e.kind===`removed`){let e=t.startsWith(` `)?`-${t}`:`- ${t}`;return l?c(e,`red`):e}return l?c(t,`dim`):t}),p=f.length>0?`${f.join(`
3
3
  `)}\n`:``;return l?`${d}${p}${[`${c(String(i),`green`)} additions`,`${c(String(a),`red`)} removals`,`${c(String(o),`dim`)} unchanged`].join(`, `)}\n`:`${d}${p}${i} additions, ${a} removals, ${o} unchanged\n`}function d(e){let t=s(),n=e.match===!0,r=e.dimensionMismatch,i=[];return i.push(...f(e,t)),i.push(...p(e,n,t)),!n&&!r&&(i.push(...m(e,t)),i.push(...h(e,t))),`${i.join(`
4
4
  `)}\n`}function f(e,t){if(e.match===!0)return[`${t?c(`✓`,`green`):`✓`} Screenshots match.`];let n=e.dimensionMismatch,r=t?c(`✗`,`red`):`✗`;if(n){let e=n.expected,t=n.actual;return[`${r} Screenshots have different dimensions: expected ${e?.width}x${e?.height}, got ${t?.width}x${t?.height}`]}let i=v(e.differentPixels),a=v(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?c(o,`red`):o}`]}function p(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=_(e.diffPath),i=n?c(`Diff image:`,`dim`):`Diff image:`,a=n?c(t,`green`):t;r.push(` ${i} ${a}`)}if(e.currentOverlayPath){let t=_(e.currentOverlayPath),i=n?c(`Current overlay:`,`dim`):`Current overlay:`,a=n?c(t,`green`):t,o=v(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function m(e,t){let n=v(e.differentPixels),r=v(e.totalPixels);return[` ${t?c(String(n),`red`):String(n)} different / ${r} total pixels`]}function h(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${b(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...g(e));return r}function g(e){let t=e.shareOfDiffPercentage===0&&e.differentPixels>0?`<0.01`:String(e.shareOfDiffPercentage),n=e.rect,r=[` ${e.index}. x=${n.x} y=${n.y} ${n.width}x${n.height}, ${t}% of diff`],i=e.currentOverlayMatches?.[0];if(i){let e=i.label?` "${i.label}"`:``;r.push(` overlaps @${i.ref}${e}, ${i.regionCoveragePercentage}% of region`)}return r}function _(e){let t=process.cwd(),n=l.relative(t,e);return n===``||!n.startsWith(`..`)&&!l.isAbsolute(n)?n===``?`.`:`.${l.sep}${n}`:e}function v(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function y(e,t){if(e.length===0)return e;let n=e.map((e,t)=>({index:t,kind:e.kind})).filter(e=>e.kind===`added`||e.kind===`removed`).map(e=>e.index);if(n.length===0)return e;let r=Array(e.length).fill(!1);for(let i of n){let n=Math.max(0,i-t),a=Math.min(e.length-1,i+t);for(let e=n;e<=a;e+=1)r[e]=!0}return e.filter((e,t)=>r[t])}function b(e,t){return t?c(e,`dim`):e}const x=async({positionals:e,flags:n,client:r})=>{let s=await o({client:r,command:`screenshot`,positionals:e,flags:n});if(t(n.responseLevel))return await a(n,s,()=>JSON.stringify(s,null,2)),!0;let c=i(s);return await a(n,c,()=>{let e=s.overlayRefs?`Annotated ${s.overlayRefs.length} refs onto ${s.path}`:w(s),t=s.warnings??[];return t.length>0?[e,...t].join(`
@@ -626,6 +626,8 @@ type DaemonRequestMeta = {
626
626
  includeCost?: boolean;
627
627
  responseLevel?: ResponseLevel;
628
628
  cwd?: string;
629
+ /** The client's `DEVELOPER_DIR`, applied to the commands a local daemon spawns for this request. */
630
+ developerDir?: string;
629
631
  sessionExplicit?: boolean;
630
632
  tenantId?: string;
631
633
  runId?: string;
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime.js";const t=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,n=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,r=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,i=/https?:\/\/[^\s"'<>]+/gi;function a(e){return s(e,new WeakSet)}function o(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.message==`string`&&t.message.length!==0)return a({message:t.message,...typeof t.code==`string`&&t.code.length>0?{code:t.code}:{}})}function s(e,n,r){if(e==null)return e;if(typeof e==`string`)return c(e,r);if(typeof e!=`object`)return e;if(n.has(e))return`[Circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>s(e,n));let i={};for(let[r,a]of Object.entries(e)){if(t.test(r)){i[r]=`[REDACTED]`;continue}i[r]=s(a,n,r)}return i}function c(e,i){let a=e.trim();if(!a)return l(e);if(i&&t.test(i))return`[REDACTED]`;let o=u(a);return o=o.replace(n,`[REDACTED]`),o=o.replace(r,(e,t,n,r,i,a)=>f({key:t,separator:n,rawValue:r,offset:i,input:a})||d(r)?e:`${t}${n}[REDACTED]`),l(o)}function l(e){return e.length<=400?e:`${e.slice(0,386)}...<truncated>`}function u(e){return e.replace(i,e=>ee(e)??e)}function d(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function f(e){if(e.key.toLowerCase()!==`token`||!e.separator.includes(`:`))return!1;try{return new URL(e.rawValue).pathname.replace(/\/+$/,``)===`/api-keys`&&/(?:^|\b)(?:service\/)?api\s+$/i.test(e.input.slice(0,e.offset))}catch{return!1}}function ee(e){try{let t=new URL(e);return t.search&&=`?REDACTED`,(t.username||t.password)&&(t.username=`REDACTED`,t.password=`REDACTED`),t.toString()}catch{return null}}var p=e({AppError:()=>y,KNOWN_APP_ERROR_CODES:()=>m,asAppError:()=>D,createRequestCanceledError:()=>C,defaultHintForCode:()=>P,detailsAfterDispatchedSteps:()=>I,discloseDispatch:()=>F,discloseDispatchAfterSteps:()=>L,discloseUnclassifiedDispatch:()=>R,errorMessage:()=>E,isAgentDeviceError:()=>O,isRequestCanceledDetails:()=>w,isRequestCanceledError:()=>T,normalizeAgentDeviceError:()=>k,normalizeError:()=>A,readDiagnosticsRecordRef:()=>M,readElementMatchCandidateRefs:()=>_,readErrorCandidateViews:()=>g,retriableForErrorCode:()=>N,summarizeCommandAttemptFailures:()=>ne,throwDaemonError:()=>b,toAppErrorCode:()=>h});const m=[`INVALID_ARGS`,`DEVICE_NOT_FOUND`,`DEVICE_IN_USE`,`TOOL_MISSING`,`APP_NOT_INSTALLED`,`UNSUPPORTED_PLATFORM`,`UNSUPPORTED_OPERATION`,`NOT_IMPLEMENTED`,`COMMAND_FAILED`,`SESSION_NOT_FOUND`,`UNAUTHORIZED`,`AMBIGUOUS_MATCH`,`REPLAY_DIVERGENCE`,`REPAIR_SESSION_EXPIRED`,`REPAIR_COMMIT_FAILED`,`UNKNOWN`];function h(e,t=`COMMAND_FAILED`){return typeof e==`string`&&e.length>0?e:t}function g(e){let t=v(e?.candidates),n=[];if(t.length>0){let r=typeof e?.matches==`number`?e.matches:t.length,i=typeof e?.refsGeneration==`number`?e.refsGeneration:void 0;n.push({kind:`element-match`,candidates:t,matches:r,...i===void 0?{}:{refsGeneration:i}})}let r=te(e?.devices);return r.length>0&&n.push({kind:`device`,devices:r}),n}function _(e){return v(e?.candidates).flatMap(e=>{let t=/^@(e\d+)(?:~s\d+)?(?:\s|$)/.exec(e);return t?.[1]?[t[1]]:[]})}function v(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function te(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.name==`string`):[]}var y=class extends Error{code;details;cause;constructor(e,t,n,r){super(t),this.code=e,this.details=n,this.cause=r}};function b(e){throw new y(h(e.code),e.message,{...e.details??{},hint:e.hint,diagnosticId:e.diagnosticId,logPath:e.logPath,logPathUnavailable:e.logPathUnavailable,diagnosticsRecord:e.diagnosticsRecord,retriable:e.retriable,supportedOn:e.supportedOn},e.cause)}const x=`request_canceled`,S=`request canceled`;function C(e,t){return new y(`COMMAND_FAILED`,S,{hint:`The request was canceled intentionally (explicit cancel or client disconnect) — no retry is needed unless the cancellation was unintended.`,...e,reason:x},t)}function w(e){return e?.reason===x}function T(e){return!(e instanceof y)||e.code!==`COMMAND_FAILED`?!1:w(e.details)?!0:e.message===S}function E(e){return e instanceof Error?e.message:String(e)}function ne(e){return e.map(e=>({args:e.args.join(` `),exitCode:e.exitCode,stderr:e.stderr.slice(0,400)}))}function D(e,t=`UNKNOWN`){return e instanceof y?e:e instanceof Error?new y(t,e.message,void 0,e):new y(t,`Unknown error`,{err:e})}function O(e){return e instanceof y}function k(e,t={}){return A(e,t)}function A(e,t={}){let n=D(e),r=n.details?a(n.details):void 0,i=j(r,`diagnosticId`)??t.diagnosticId,s=j(r,`logPath`)??t.logPath,c=j(r,`logPathUnavailable`),l=M(r?.diagnosticsRecord)??t.diagnosticsRecord,u=j(r,`hint`)??P(n.code),d=ce(r,`retriable`)??N(n.code),f=j(r,`supportedOn`),ee=ue(r),p=ie(n.code,n.message,r),m=o(n.cause);return{code:n.code,message:p,...m===void 0?{}:{cause:m},hint:u,diagnosticId:i,logPath:s,...c===void 0?{}:{logPathUnavailable:c},...l===void 0?{}:{diagnosticsRecord:l},...d===void 0?{}:{retriable:d},...f===void 0?{}:{supportedOn:f},details:ee}}const re=/^\S+ exited with code -?\d+$/;function ie(e,t,n){if(e!==`COMMAND_FAILED`||n?.processExitError!==!0)return t;let r=se(typeof n?.stderr==`string`?n.stderr:``);return r?re.test(t)?r:t.includes(r)?t:`${t}: ${r}`:t}const ae=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i],oe=/^(?:(?:adb|xcrun|simctl):\s*)?(?:error:\s*)?/i;function se(e){for(let t of e.split(`
2
- `)){let e=t.trim();if(!e||ae.some(t=>t.test(e)))continue;let n=e.replace(oe,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function j(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function M(e){if(!e||typeof e!=`object`)return;let{session:t,requestId:n}=e;if(typeof t==`string`&&typeof n==`string`&&t.length!==0&&n.length!==0)return{session:t,requestId:n}}function ce(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}const le=[`startupRuleMatched`,`startupHostDeadlineHit`];function ue(e){if(!e)return;let t={...e};for(let e of le)delete t[e];return delete t.hint,delete t.diagnosticId,delete t.logPath,delete t.logPathUnavailable,delete t.diagnosticsRecord,delete t.retriable,delete t.supportedOn,Object.keys(t).length>0?t:void 0}const de={DEVICE_IN_USE:!0};function fe(e){return m.includes(e)}function N(e){return fe(e)?de[e]:void 0}function P(e){switch(e){case`INVALID_ARGS`:return`Check command arguments and run --help for usage examples.`;case`SESSION_NOT_FOUND`:return`Run open first or pass an explicit device selector.`;case`TOOL_MISSING`:return`Install required platform tooling and ensure it is available in PATH.`;case`DEVICE_NOT_FOUND`:return`Verify the target device is booted/connected and selectors match.`;case`APP_NOT_INSTALLED`:return`Run apps to discover the exact installed package or bundle id, or install the app before open.`;case`UNSUPPORTED_OPERATION`:return`This command is not available for the selected platform/device.`;case`UNSUPPORTED_PLATFORM`:return`This platform is not supported for the requested operation; run devices to inspect available targets.`;case`AMBIGUOUS_MATCH`:return`Multiple candidates matched. Narrow the query or pass an exact identifier.`;case`DEVICE_IN_USE`:return`The device is busy with another agent-device request; retry once it frees up.`;case`REPLAY_DIVERGENCE`:return`Read details.divergence (screen/suggestions) for repair context, or rerun with --json for the full report.`;case`REPAIR_SESSION_EXPIRED`:return`The --save-script repair session was reaped before it was finalized; re-run replay <script> --save-script from the start.`;case`REPAIR_COMMIT_FAILED`:return`The repair transaction completed, but committing its healed script failed at teardown (no-clobber refusal or a filesystem error); inspect the target path/permissions, then re-run replay <script> --save-script to retry.`;case`NOT_IMPLEMENTED`:return`This command is part of the planned API but is not implemented yet.`;case`COMMAND_FAILED`:return`Retry with --debug and inspect diagnostics log for details.`;case`UNAUTHORIZED`:return`Refresh daemon metadata and retry the command.`;case`UNKNOWN`:return`Unexpected internal error. Retry with --debug and report the diagnostics log if it persists.`;default:return`Retry with --debug and inspect diagnostics log for details.`}}function F(e,t,n={}){return e.details={...e.details,...n,dispatched:t},e}function I(e,t){if(t===0)return e;let n=e?.dispatchedSteps;return{...e,dispatchedSteps:t+(typeof n==`number`?n:0),dispatched:`unknown`}}function L(e,t){return e instanceof y&&(e.details=I(e.details,t)),e}function R(e,t){return e.details?.dispatched===void 0?F(e,t):e}const z={interactiveOnly:`snapshotInteractiveOnly`,depth:`snapshotDepth`,scope:`snapshotScope`,raw:`snapshotRaw`,customActions:`snapshotCustomActions`,forceFull:`snapshotForceFull`,includeHiddenContentHints:`snapshotIncludeHiddenContentHints`,preferredBackend:`snapshotPreferredBackend`},pe=[`interactiveOnly`,`depth`,`scope`,`raw`,`customActions`,`forceFull`],me=[`interactiveOnly`,`preferredBackend`,`depth`,`scope`,`raw`,`customActions`,`includeHiddenContentHints`],he=[`depth`,`interactiveOnly`,`raw`,`scope`,`customActions`];function B(e,t){return Object.fromEntries(t.map(t=>[t,e?.[z[t]]]))}function ge(e,t){return Object.fromEntries(t.flatMap(t=>{let n=e?.[t];return n===void 0?[]:[[z[t],n]]}))}const V={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,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`,heading:`heading`,activityindicator:`activity-indicator`,progressindicator:`progress-indicator`,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 _e(e){return Object.prototype.hasOwnProperty.call(V,e)?V[e]:void 0}function H(e){let t=e,n=e.replaceAll(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.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))),n===`textview`?r?`text`:`text-view`:_e(n)||n||`element`}function ve(e){if(e===void 0||e.backend===void 0)return{};switch(e.backend){case`xctest`:return{backend:e.backend,producer:e.producer};case`android`:return{backend:e.backend,producer:e.producer};case`harmonyos-arkui`:return{backend:e.backend,producer:e.producer};case`macos-helper`:return{backend:e.backend,producer:e.producer};case`linux-atspi`:return{backend:e.backend,producer:e.producer};case`web`:return{backend:e.backend,producer:e.producer}}}function ye(e){return e===`xctest`||e===`android`||e===`harmonyos-arkui`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function be(e){return e===void 0||e===`xctest`||e===`android`||e===`harmonyos-arkui`}const xe=[`bundle_changed`,`stale_target`,`missing_after_wait`,`interaction_foreground_guard`];function Se(e){return typeof e==`string`&&xe.includes(e)}const U=[`unknown`,`notRunning`,`runningBackgroundSuspended`,`runningBackground`,`runningForeground`];Object.freeze(U.filter(e=>e!==`runningForeground`));function Ce(e){return typeof e==`string`&&U.includes(e)}function we(e,t){return t.postGestureOutcome??=e.postGestureOutcome,t}function Te(e){return e.map((e,t)=>({...e,ref:e.ref??`e${t+1}`,kind:H(e.type??`Element`)}))}const Ee=/^~s(\d+)$/,De=`Refs look like @e12, optionally pinned to the snapshot generation that minted them: @e12~s3 (the ref, then "~s" and the refsGeneration reported by the issuing snapshot/find response).`;function W(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=Ee.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function Oe(e){let t=W(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function ke(e,t){return e.find(e=>e.ref===t)??null}function Ae(e){return JSON.stringify({interactiveOnly:e?.interactiveOnly===!0,depth:typeof e?.depth==`number`?e.depth:null,scope:e?.scope?.trim()||null,raw:e?.raw===!0,customActions:e?.customActions===!0})}function je(e){if(e)return B(e,he)}function Me(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const G=[`ios`,`android`,`harmonyos`];function Ne(e){return G.some(t=>t===e)}const K={ios:`ios-instance`,android:`android-instance`,harmonyos:`harmonyos-instance`};function Pe(e){return e===void 0?void 0:K[e]}const Fe=new Map(Object.entries(K).flatMap(([e,t])=>t===void 0?[]:[[t,e]]));function Ie(e){return Fe.get(e)}const Le=[`summary`,`headers`,`body`,`all`],Re=[`digest`,`default`,`full`];function ze(e){return e!==void 0&&e!=="default"}function q(e,t,n,r){return{ok:!1,error:{code:e,message:t,...r?.hint?{hint:r.hint}:{},...r?.retriable===void 0?{}:{retriable:r.retriable},...n?{details:n}:{}}}}const J=`No active session. Run open first.`;function Be(){return q(`SESSION_NOT_FOUND`,J)}function Y(e){return{parse(t){return e(t,`$`)}}}function X(e,t){throw Error(`${e}: ${t}`)}function Z(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&X(t,`Expected an object`),e}function Ve(e,t){return typeof e!=`string`&&X(t,`Expected a string`),e}function He(e,t){return Number.isInteger(e)||X(t,`Expected an integer`),e}function Ue(e,t){return Array.isArray(e)||X(t,`Expected an array`),e}function Q(e,t,n){let r=e[t];return r===void 0?void 0:Ve(r,`${n}.${t}`)}function We(e,t,n){let r=e[t];if(r!==void 0)return Ue(r,`${n}.${t}`).map((e,r)=>Ve(e,`${n}.${t}[${String(r)}]`))}function Ge(e,t,n){let r=e[t];return r===void 0?void 0:He(r,`${n}.${t}`)}function $(e,t,n){let r=e[t];return r===void 0?void 0:Z(r,`${n}.${t}`)}function Ke(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&X(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const qe=Y((e,t)=>{let n=Z(e,t);return{platform:Ke(n,`platform`,G,t),metroHost:Q(n,`metroHost`,t),metroPort:Ge(n,`metroPort`,t),bundleUrl:Q(n,`bundleUrl`,t),launchUrl:Q(n,`launchUrl`,t)}});function Je(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&X(`${t}.id`,`Expected a string, number, or null`),n}const Ye=Y((e,t)=>{let n=Z(e,t);return{jsonrpc:Q(n,`jsonrpc`,t),id:Je(n,t),method:Q(n,`method`,t),params:n.params}}),Xe=Y((e,t)=>{let n=Z(e,t);return{token:Q(n,`token`,t),session:Q(n,`session`,t),command:Q(n,`command`,t),positionals:We(n,`positionals`,t),input:$(n,`input`,t),flags:$(n,`flags`,t),runtime:$(n,`runtime`,t),meta:$(n,`meta`,t)}});export{b as $,ve as A,R as B,Ce as C,ge as D,Oe as E,C as F,T as G,p as H,P as I,M as J,k as K,I as L,be as M,y as N,B as O,D as P,ne as Q,F as R,we as S,ye as T,O as U,E as V,w as W,g as X,_ as Y,N as Z,Te as _,qe as a,ke as b,Ne as c,Be as d,h as et,Ie as f,pe as g,me as h,Xe as i,W as j,je as k,Ye as l,De as m,J as n,o as nt,q as o,U as p,A as q,Re as r,ze as s,Le as t,a as tt,Pe as u,Ae as v,Se as w,H as x,Me as y,L as z};
1
+ import{r as e}from"./rolldown-runtime.js";const t=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,n=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,r=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,i=/https?:\/\/[^\s"'<>]+/gi,a=8192,o=`...<truncated>`;function s(e){return l(e,new WeakSet)}function c(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.message==`string`&&t.message.length!==0)return s({message:t.message,...typeof t.code==`string`&&t.code.length>0?{code:t.code}:{}})}function l(e,n,r){if(e==null)return e;if(typeof e==`string`)return u(e,r);if(typeof e!=`object`)return e;if(n.has(e))return`[Circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>l(e,n));let i={};for(let[r,a]of Object.entries(e)){if(t.test(r)){i[r]=`[REDACTED]`;continue}i[r]=l(a,n,r)}return i}function u(e,i){let a=e.trim();if(!a)return d(e,i);if(i&&t.test(i))return`[REDACTED]`;let o=f(a);return o=o.replace(n,`[REDACTED]`),o=o.replace(r,(e,t,n,r,i,a)=>ee({key:t,separator:n,rawValue:r,offset:i,input:a})||p(r)?e:`${t}${n}[REDACTED]`),d(o,i)}function d(e,t){if(t===`stderr`){if(e.length<=a)return e;let t=`\n${o}\n`,n=a-t.length,r=Math.ceil(n/2);return`${e.slice(0,r)}${t}${e.slice(-(n-r))}`}return e.length<=400?e:`${e.slice(0,386)}${o}`}function f(e){return e.replace(i,e=>m(e)??e)}function p(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function ee(e){if(e.key.toLowerCase()!==`token`||!e.separator.includes(`:`))return!1;try{return new URL(e.rawValue).pathname.replace(/\/+$/,``)===`/api-keys`&&/(?:^|\b)(?:service\/)?api\s+$/i.test(e.input.slice(0,e.offset))}catch{return!1}}function m(e){try{let t=new URL(e);return t.search&&=`?REDACTED`,(t.username||t.password)&&(t.username=`REDACTED`,t.password=`REDACTED`),t.toString()}catch{return null}}var te=e({AppError:()=>b,KNOWN_APP_ERROR_CODES:()=>h,asAppError:()=>E,createRequestCanceledError:()=>re,defaultHintForCode:()=>N,detailsAfterDispatchedSteps:()=>F,discloseDispatch:()=>P,discloseDispatchAfterSteps:()=>I,discloseUnclassifiedDispatch:()=>L,errorMessage:()=>ae,isAgentDeviceError:()=>D,isRequestCanceledDetails:()=>w,isRequestCanceledError:()=>ie,normalizeAgentDeviceError:()=>O,normalizeError:()=>k,readDiagnosticsRecordRef:()=>j,readElementMatchCandidateRefs:()=>v,readErrorCandidateViews:()=>_,retriableForErrorCode:()=>M,summarizeCommandAttemptFailures:()=>T,throwDaemonError:()=>x,toAppErrorCode:()=>g});const h=[`INVALID_ARGS`,`DEVICE_NOT_FOUND`,`DEVICE_IN_USE`,`TOOL_MISSING`,`APP_NOT_INSTALLED`,`UNSUPPORTED_PLATFORM`,`UNSUPPORTED_OPERATION`,`NOT_IMPLEMENTED`,`COMMAND_FAILED`,`SESSION_NOT_FOUND`,`UNAUTHORIZED`,`AMBIGUOUS_MATCH`,`REPLAY_DIVERGENCE`,`REPAIR_SESSION_EXPIRED`,`REPAIR_COMMIT_FAILED`,`UNKNOWN`];function g(e,t=`COMMAND_FAILED`){return typeof e==`string`&&e.length>0?e:t}function _(e){let t=y(e?.candidates),n=[];if(t.length>0){let r=typeof e?.matches==`number`?e.matches:t.length,i=typeof e?.refsGeneration==`number`?e.refsGeneration:void 0;n.push({kind:`element-match`,candidates:t,matches:r,...i===void 0?{}:{refsGeneration:i}})}let r=ne(e?.devices);return r.length>0&&n.push({kind:`device`,devices:r}),n}function v(e){return y(e?.candidates).flatMap(e=>{let t=/^@(e\d+)(?:~s\d+)?(?:\s|$)/.exec(e);return t?.[1]?[t[1]]:[]})}function y(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function ne(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.name==`string`):[]}var b=class extends Error{code;details;cause;constructor(e,t,n,r){super(t),this.code=e,this.details=n,this.cause=r}};function x(e){throw new b(g(e.code),e.message,{...e.details??{},hint:e.hint,diagnosticId:e.diagnosticId,logPath:e.logPath,logPathUnavailable:e.logPathUnavailable,diagnosticsRecord:e.diagnosticsRecord,retriable:e.retriable,supportedOn:e.supportedOn},e.cause)}const S=`request_canceled`,C=`request canceled`;function re(e,t){return new b(`COMMAND_FAILED`,C,{hint:`The request was canceled intentionally (explicit cancel or client disconnect) — no retry is needed unless the cancellation was unintended.`,...e,reason:S},t)}function w(e){return e?.reason===S}function ie(e){return!(e instanceof b)||e.code!==`COMMAND_FAILED`?!1:w(e.details)?!0:e.message===C}function ae(e){return e instanceof Error?e.message:String(e)}function T(e){return e.map(e=>({args:e.args.join(` `),exitCode:e.exitCode,stderr:e.stderr.slice(0,400)}))}function E(e,t=`UNKNOWN`){return e instanceof b?e:e instanceof Error?new b(t,e.message,void 0,e):new b(t,`Unknown error`,{err:e})}function D(e){return e instanceof b}function O(e,t={}){return k(e,t)}function k(e,t={}){let n=E(e),r=n.details?s(n.details):void 0,i=A(r,`diagnosticId`)??t.diagnosticId,a=A(r,`logPath`)??t.logPath,o=A(r,`logPathUnavailable`),l=j(r?.diagnosticsRecord)??t.diagnosticsRecord,u=A(r,`hint`)??N(n.code),d=de(r,`retriable`)??M(n.code),f=A(r,`supportedOn`),p=pe(r),ee=se(n.code,n.message,r),m=c(n.cause);return{code:n.code,message:ee,...m===void 0?{}:{cause:m},hint:u,diagnosticId:i,logPath:a,...o===void 0?{}:{logPathUnavailable:o},...l===void 0?{}:{diagnosticsRecord:l},...d===void 0?{}:{retriable:d},...f===void 0?{}:{supportedOn:f},details:p}}const oe=/^\S+ exited with code -?\d+$/;function se(e,t,n){if(e!==`COMMAND_FAILED`||n?.processExitError!==!0)return t;let r=ue(typeof n?.stderr==`string`?n.stderr:``);return r?oe.test(t)?r:t.includes(r)?t:`${t}: ${r}`:t}const ce=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i],le=/^(?:(?:adb|xcrun|simctl):\s*)?(?:error:\s*)?/i;function ue(e){for(let t of e.split(`
2
+ `)){let e=t.trim();if(!e||ce.some(t=>t.test(e)))continue;let n=e.replace(le,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function A(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function j(e){if(!e||typeof e!=`object`)return;let{session:t,requestId:n}=e;if(typeof t==`string`&&typeof n==`string`&&t.length!==0&&n.length!==0)return{session:t,requestId:n}}function de(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}const fe=[`startupRuleMatched`,`startupHostDeadlineHit`];function pe(e){if(!e)return;let t={...e};for(let e of fe)delete t[e];return delete t.hint,delete t.diagnosticId,delete t.logPath,delete t.logPathUnavailable,delete t.diagnosticsRecord,delete t.retriable,delete t.supportedOn,Object.keys(t).length>0?t:void 0}const me={DEVICE_IN_USE:!0};function he(e){return h.includes(e)}function M(e){return he(e)?me[e]:void 0}function N(e){switch(e){case`INVALID_ARGS`:return`Check command arguments and run --help for usage examples.`;case`SESSION_NOT_FOUND`:return`Run open first or pass an explicit device selector.`;case`TOOL_MISSING`:return`Install required platform tooling and ensure it is available in PATH.`;case`DEVICE_NOT_FOUND`:return`Verify the target device is booted/connected and selectors match.`;case`APP_NOT_INSTALLED`:return`Run apps to discover the exact installed package or bundle id, or install the app before open.`;case`UNSUPPORTED_OPERATION`:return`This command is not available for the selected platform/device.`;case`UNSUPPORTED_PLATFORM`:return`This platform is not supported for the requested operation; run devices to inspect available targets.`;case`AMBIGUOUS_MATCH`:return`Multiple candidates matched. Narrow the query or pass an exact identifier.`;case`DEVICE_IN_USE`:return`The device is busy with another agent-device request; retry once it frees up.`;case`REPLAY_DIVERGENCE`:return`Read details.divergence (screen/suggestions) for repair context, or rerun with --json for the full report.`;case`REPAIR_SESSION_EXPIRED`:return`The --save-script repair session was reaped before it was finalized; re-run replay <script> --save-script from the start.`;case`REPAIR_COMMIT_FAILED`:return`The repair transaction completed, but committing its healed script failed at teardown (no-clobber refusal or a filesystem error); inspect the target path/permissions, then re-run replay <script> --save-script to retry.`;case`NOT_IMPLEMENTED`:return`This command is part of the planned API but is not implemented yet.`;case`COMMAND_FAILED`:return`Retry with --debug and inspect diagnostics log for details.`;case`UNAUTHORIZED`:return`Refresh daemon metadata and retry the command.`;case`UNKNOWN`:return`Unexpected internal error. Retry with --debug and report the diagnostics log if it persists.`;default:return`Retry with --debug and inspect diagnostics log for details.`}}function P(e,t,n={}){return e.details={...e.details,...n,dispatched:t},e}function F(e,t){if(t===0)return e;let n=e?.dispatchedSteps;return{...e,dispatchedSteps:t+(typeof n==`number`?n:0),dispatched:`unknown`}}function I(e,t){return e instanceof b&&(e.details=F(e.details,t)),e}function L(e,t){return e.details?.dispatched===void 0?P(e,t):e}const R={interactiveOnly:`snapshotInteractiveOnly`,depth:`snapshotDepth`,scope:`snapshotScope`,raw:`snapshotRaw`,customActions:`snapshotCustomActions`,forceFull:`snapshotForceFull`,includeHiddenContentHints:`snapshotIncludeHiddenContentHints`,preferredBackend:`snapshotPreferredBackend`},ge=[`interactiveOnly`,`depth`,`scope`,`raw`,`customActions`,`forceFull`],_e=[`interactiveOnly`,`preferredBackend`,`depth`,`scope`,`raw`,`customActions`,`includeHiddenContentHints`],ve=[`depth`,`interactiveOnly`,`raw`,`scope`,`customActions`];function z(e,t){return Object.fromEntries(t.map(t=>[t,e?.[R[t]]]))}function ye(e,t){return Object.fromEntries(t.flatMap(t=>{let n=e?.[t];return n===void 0?[]:[[R[t],n]]}))}const B={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,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`,heading:`heading`,activityindicator:`activity-indicator`,progressindicator:`progress-indicator`,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 be(e){return Object.prototype.hasOwnProperty.call(B,e)?B[e]:void 0}function V(e){let t=e,n=e.replaceAll(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.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))),n===`textview`?r?`text`:`text-view`:be(n)||n||`element`}function xe(e){if(e===void 0||e.backend===void 0)return{};switch(e.backend){case`xctest`:return{backend:e.backend,producer:e.producer};case`android`:return{backend:e.backend,producer:e.producer};case`harmonyos-arkui`:return{backend:e.backend,producer:e.producer};case`macos-helper`:return{backend:e.backend,producer:e.producer};case`linux-atspi`:return{backend:e.backend,producer:e.producer};case`web`:return{backend:e.backend,producer:e.producer}}}function Se(e){return e===`xctest`||e===`android`||e===`harmonyos-arkui`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function Ce(e){return e===void 0||e===`xctest`||e===`android`||e===`harmonyos-arkui`}const we=[`bundle_changed`,`stale_target`,`missing_after_wait`,`interaction_foreground_guard`];function Te(e){return typeof e==`string`&&we.includes(e)}const H=[`unknown`,`notRunning`,`runningBackgroundSuspended`,`runningBackground`,`runningForeground`];Object.freeze(H.filter(e=>e!==`runningForeground`));function Ee(e){return typeof e==`string`&&H.includes(e)}function De(e,t){return t.postGestureOutcome??=e.postGestureOutcome,t}function Oe(e){return e.map((e,t)=>({...e,ref:e.ref??`e${t+1}`,kind:V(e.type??`Element`)}))}const ke=/^~s(\d+)$/,Ae=`Refs look like @e12, optionally pinned to the snapshot generation that minted them: @e12~s3 (the ref, then "~s" and the refsGeneration reported by the issuing snapshot/find response).`;function U(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=ke.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function je(e){let t=U(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function Me(e,t){return e.find(e=>e.ref===t)??null}function Ne(e){return JSON.stringify({interactiveOnly:e?.interactiveOnly===!0,depth:typeof e?.depth==`number`?e.depth:null,scope:e?.scope?.trim()||null,raw:e?.raw===!0,customActions:e?.customActions===!0})}function Pe(e){if(e)return z(e,ve)}function Fe(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const W=[`ios`,`android`,`harmonyos`];function Ie(e){return W.some(t=>t===e)}const G={ios:`ios-instance`,android:`android-instance`,harmonyos:`harmonyos-instance`};function Le(e){return e===void 0?void 0:G[e]}const Re=new Map(Object.entries(G).flatMap(([e,t])=>t===void 0?[]:[[t,e]]));function ze(e){return Re.get(e)}const Be=[`summary`,`headers`,`body`,`all`],Ve=[`digest`,`default`,`full`];function He(e){return e!==void 0&&e!=="default"}function K(e,t,n,r){return{ok:!1,error:{code:e,message:t,...r?.hint?{hint:r.hint}:{},...r?.retriable===void 0?{}:{retriable:r.retriable},...n?{details:n}:{}}}}const q=`No active session. Run open first.`;function Ue(){return K(`SESSION_NOT_FOUND`,q)}function J(e){return{parse(t){return e(t,`$`)}}}function Y(e,t){throw Error(`${e}: ${t}`)}function X(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&Y(t,`Expected an object`),e}function Z(e,t){return typeof e!=`string`&&Y(t,`Expected a string`),e}function We(e,t){return Number.isInteger(e)||Y(t,`Expected an integer`),e}function Ge(e,t){return Array.isArray(e)||Y(t,`Expected an array`),e}function Q(e,t,n){let r=e[t];return r===void 0?void 0:Z(r,`${n}.${t}`)}function Ke(e,t,n){let r=e[t];if(r!==void 0)return Ge(r,`${n}.${t}`).map((e,r)=>Z(e,`${n}.${t}[${String(r)}]`))}function qe(e,t,n){let r=e[t];return r===void 0?void 0:We(r,`${n}.${t}`)}function $(e,t,n){let r=e[t];return r===void 0?void 0:X(r,`${n}.${t}`)}function Je(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&Y(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const Ye=J((e,t)=>{let n=X(e,t);return{platform:Je(n,`platform`,W,t),metroHost:Q(n,`metroHost`,t),metroPort:qe(n,`metroPort`,t),bundleUrl:Q(n,`bundleUrl`,t),launchUrl:Q(n,`launchUrl`,t)}});function Xe(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&Y(`${t}.id`,`Expected a string, number, or null`),n}const Ze=J((e,t)=>{let n=X(e,t);return{jsonrpc:Q(n,`jsonrpc`,t),id:Xe(n,t),method:Q(n,`method`,t),params:n.params}}),Qe=J((e,t)=>{let n=X(e,t);return{token:Q(n,`token`,t),session:Q(n,`session`,t),command:Q(n,`command`,t),positionals:Ke(n,`positionals`,t),input:$(n,`input`,t),flags:$(n,`flags`,t),runtime:$(n,`runtime`,t),meta:$(n,`meta`,t)}});export{x as $,xe as A,L as B,Ee as C,ye as D,je as E,re as F,ie as G,te as H,N as I,j as J,O as K,F as L,Ce as M,b as N,z as O,E as P,T as Q,P as R,De as S,Se as T,D as U,ae as V,w as W,_ as X,v as Y,M as Z,Oe as _,Ye as a,Me as b,Ie as c,Ue as d,g as et,ze as f,ge as g,_e as h,Qe as i,U as j,Pe as k,Ze as l,Ae as m,q as n,c as nt,K as o,H as p,k as q,Ve as r,He as s,Be as t,s as tt,Le as u,Ne as v,Te as w,V as x,Fe as y,I as z};
@@ -1,8 +1,4 @@
1
1
  import { A as Rect, C as Platform, P as SnapshotNode, R as SnapshotState, T as PublicPlatform, h as ResponseCost } from "./sdk-contracts.js";
2
- //#region packages/contracts/src/click-button.d.ts
3
- declare const CLICK_BUTTONS: readonly ['primary', 'secondary', 'middle'];
4
- type ClickButton = (typeof CLICK_BUTTONS)[number];
5
- //#endregion
6
2
  //#region packages/contracts/src/fill-evidence.d.ts
7
3
  /**
8
4
  * The evidence a `fill` carries when it changed a field but could not confirm the text it sent.
@@ -31,6 +27,10 @@ type FillUnconfirmedVerification = {
31
27
  target: FillVerificationTarget;
32
28
  };
33
29
  //#endregion
30
+ //#region packages/contracts/src/click-button.d.ts
31
+ declare const CLICK_BUTTONS: readonly ['primary', 'secondary', 'middle'];
32
+ type ClickButton = (typeof CLICK_BUTTONS)[number];
33
+ //#endregion
34
34
  //#region packages/contracts/src/interaction.d.ts
35
35
  /** The decisive criterion separating a resolveSelectorChain winner from its strongest runner-up (ADR 0012). */
36
36
  type DisambiguationTiebreak = 'visible' | 'deepest' | 'smallest-area' | 'structural-equivalence';