agent-device 0.21.37 → 0.21.38

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 (485) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.apk → agent-device-android-ime-helper-0.21.38.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.38.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.manifest.json → agent-device-android-ime-helper-0.21.38.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.apk → agent-device-android-snapshot-helper-0.21.38.apk} +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.38.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.manifest.json → agent-device-android-snapshot-helper-0.21.38.manifest.json} +7 -7
  7. package/apple/fold-helper/Fold.m +8 -4
  8. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardReturnKey.swift +53 -0
  9. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +42 -4
  10. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +26 -18
  11. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +42 -11
  12. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +123 -22
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +7 -0
  14. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +570 -53
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +41 -0
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +7 -0
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +17 -1
  18. package/dist/src/THIRD_PARTY_NOTICES.txt +2 -2
  19. package/dist/src/absence-observation-errors.js +1 -1
  20. package/dist/src/absence-observation.js +1 -1
  21. package/dist/src/adapter.js +1 -1
  22. package/dist/src/adb-executor.js +1 -1
  23. package/dist/src/adb-failure.js +2 -2
  24. package/dist/src/adb-transport.js +1 -1
  25. package/dist/src/agent-browser-lifecycle.js +1 -1
  26. package/dist/src/agent-browser-process-record.js +1 -1
  27. package/dist/src/agent-browser-provider.js +1 -1
  28. package/dist/src/agent-browser-tool.js +1 -1
  29. package/dist/src/ai-sdk.d.ts +1 -1
  30. package/dist/src/ai-sdk.js +1 -1
  31. package/dist/src/alert-contract.js +1 -1
  32. package/dist/src/alert-tree-driver.js +1 -1
  33. package/dist/src/alert.js +1 -1
  34. package/dist/src/android-adb.d.ts +1 -1
  35. package/dist/src/android.js +1 -1
  36. package/dist/src/android2.js +1 -1
  37. package/dist/src/app-backend.js +1 -1
  38. package/dist/src/app-catalog.js +1 -1
  39. package/dist/src/app-deployment-resolution.js +1 -1
  40. package/dist/src/app-inventory.js +1 -1
  41. package/dist/src/app-launch.js +1 -1
  42. package/dist/src/app-lifecycle.js +4 -4
  43. package/dist/src/app-lifecycle2.js +2 -2
  44. package/dist/src/app-log-files.js +1 -1
  45. package/dist/src/app-log-runtime2.js +2 -2
  46. package/dist/src/app-log-session-resource.js +1 -1
  47. package/dist/src/app-resolution.js +1 -1
  48. package/dist/src/app-state-read.js +1 -1
  49. package/dist/src/app-state-runtime.d.ts +1 -1
  50. package/dist/src/application-lifecycle-interaction.js +1 -1
  51. package/dist/src/archive.js +1 -1
  52. package/dist/src/args.js +1 -1
  53. package/dist/src/artifact-download.js +1 -1
  54. package/dist/src/artifact-tracking.js +1 -1
  55. package/dist/src/auth-session.js +1 -1
  56. package/dist/src/auth.js +1 -1
  57. package/dist/src/automation-helper-artifact.js +1 -1
  58. package/dist/src/automation-helper.js +1 -1
  59. package/dist/src/await-with-signal.js +1 -1
  60. package/dist/src/backend-snapshot-options.js +1 -1
  61. package/dist/src/boot-diagnostics.js +1 -1
  62. package/dist/src/bridge-source.js +1 -1
  63. package/dist/src/browser-launch.js +1 -1
  64. package/dist/src/browserstack-device-features.js +1 -1
  65. package/dist/src/browserstack.js +1 -1
  66. package/dist/src/cache.js +1 -1
  67. package/dist/src/capture-disclosure.js +1 -1
  68. package/dist/src/capture-lifecycle.js +1 -1
  69. package/dist/src/cli-config.js +1 -1
  70. package/dist/src/cli-help.js +19 -16
  71. package/dist/src/cli-output.js +11 -11
  72. package/dist/src/cli-runner.js +1 -1
  73. package/dist/src/cli.js +2 -2
  74. package/dist/src/click-button.js +1 -1
  75. package/dist/src/client-metro-companion.js +1 -1
  76. package/dist/src/client-metro.js +1 -1
  77. package/dist/src/client-options.js +1 -1
  78. package/dist/src/client-port.d.ts +246 -208
  79. package/dist/src/clipboard-shell-response.js +1 -1
  80. package/dist/src/cloud-artifacts.d.ts +7 -2
  81. package/dist/src/code-signature-cache.js +1 -1
  82. package/dist/src/command-schema.js +6 -4
  83. package/dist/src/command-tools.js +3 -3
  84. package/dist/src/command.js +1 -1
  85. package/dist/src/composed-inventory-gateways.js +1 -1
  86. package/dist/src/composite-resource-admission.js +1 -1
  87. package/dist/src/config.js +1 -1
  88. package/dist/src/connection-lease-transaction.js +1 -1
  89. package/dist/src/connection-metro-runtime.js +1 -1
  90. package/dist/src/connection-runtime.js +1 -1
  91. package/dist/src/connection-verification.js +1 -1
  92. package/dist/src/connection.js +3 -3
  93. package/dist/src/context.js +1 -1
  94. package/dist/src/contract.d.ts +2 -1
  95. package/dist/src/contracts.d.ts +1 -1
  96. package/dist/src/contracts.js +1 -1
  97. package/dist/src/daemon-client-attach.js +1 -1
  98. package/dist/src/daemon-client-dispatch-disclosure.js +1 -1
  99. package/dist/src/daemon-client-ensure.js +1 -1
  100. package/dist/src/daemon-client-ensuring.js +1 -1
  101. package/dist/src/daemon-client-lease-beat.js +1 -1
  102. package/dist/src/daemon-client-lifecycle.js +1 -1
  103. package/dist/src/daemon-client-liveness-probe.js +1 -1
  104. package/dist/src/daemon-client-remote-health-cache.js +1 -0
  105. package/dist/src/daemon-client-remote-health-recovery.js +1 -0
  106. package/dist/src/daemon-client-transport.js +1 -1
  107. package/dist/src/daemon-command-registry.js +1 -1
  108. package/dist/src/daemon-composition.js +1 -1
  109. package/dist/src/daemon-diagnostics-scope.js +1 -1
  110. package/dist/src/daemon-http.js +1 -1
  111. package/dist/src/daemon-launch-spec.js +1 -1
  112. package/dist/src/daemon-lifecycle-errors.js +1 -1
  113. package/dist/src/daemon-policy-file.js +1 -1
  114. package/dist/src/daemon-registration-owner.js +3 -3
  115. package/dist/src/daemon-registration.js +1 -1
  116. package/dist/src/daemon-resolution.js +1 -1
  117. package/dist/src/daemon-startup-diagnostics.js +1 -1
  118. package/dist/src/daemon-stop.js +1 -1
  119. package/dist/src/daemon.js +1 -1
  120. package/dist/src/debug-symbols-facade.js +3 -3
  121. package/dist/src/device-claim-admission.js +1 -0
  122. package/dist/src/device-claim-reconciliation.js +1 -0
  123. package/dist/src/device-claim-recovery.js +1 -1
  124. package/dist/src/device-claim-rule.js +1 -1
  125. package/dist/src/device-claims.js +1 -1
  126. package/dist/src/device-input-state.d.ts +1 -1
  127. package/dist/src/device-inventory-context.js +1 -1
  128. package/dist/src/device-selection-resolver.js +1 -1
  129. package/dist/src/device-session.js +1 -1
  130. package/dist/src/device-shell.js +1 -1
  131. package/dist/src/device.js +1 -1
  132. package/dist/src/device3.js +3 -3
  133. package/dist/src/devicectl.js +1 -1
  134. package/dist/src/diagnostics.js +1 -1
  135. package/dist/src/discovery.js +1 -1
  136. package/dist/src/dispatch-resolve.js +1 -1
  137. package/dist/src/display-inventory.js +1 -1
  138. package/dist/src/doctor-facade.js +1 -1
  139. package/dist/src/doctor2.js +1 -1
  140. package/dist/src/durable-capture-resource.js +1 -1
  141. package/dist/src/durable-capture.js +1 -1
  142. package/dist/src/durable-resource.js +1 -1
  143. package/dist/src/ended-lease.js +1 -1
  144. package/dist/src/engine-eval-script.js +1 -1
  145. package/dist/src/error.js +2 -2
  146. package/dist/src/errors.js +1 -1
  147. package/dist/src/explicit-session-resolution.js +1 -1
  148. package/dist/src/expo-dev-client-launch.js +1 -1
  149. package/dist/src/failure-output.js +1 -1
  150. package/dist/src/file.js +1 -1
  151. package/dist/src/find.js +1 -1
  152. package/dist/src/finders.js +1 -1
  153. package/dist/src/flag-registry.js +1 -1
  154. package/dist/src/focus-runtime.js +1 -1
  155. package/dist/src/fold-helper.js +1 -1
  156. package/dist/src/generic-settle.js +1 -1
  157. package/dist/src/generic.js +1 -1
  158. package/dist/src/gesture-admission.js +1 -1
  159. package/dist/src/gesture-plan-types.d.ts +1 -1
  160. package/dist/src/gesture-plan.js +1 -1
  161. package/dist/src/gesture-runtime.js +1 -1
  162. package/dist/src/hdc.js +1 -1
  163. package/dist/src/helper-artifacts.js +1 -1
  164. package/dist/src/helper.js +2 -2
  165. package/dist/src/host-file.js +1 -1
  166. package/dist/src/host.js +1 -1
  167. package/dist/src/host2.js +1 -1
  168. package/dist/src/host3.js +1 -1
  169. package/dist/src/host4.js +1 -1
  170. package/dist/src/host5.js +1 -1
  171. package/dist/src/host6.js +1 -1
  172. package/dist/src/human-control-contract.js +1 -1
  173. package/dist/src/human-control.js +1 -1
  174. package/dist/src/ime-rebind.js +1 -1
  175. package/dist/src/ime-settings-record.js +1 -1
  176. package/dist/src/ime-state.js +1 -1
  177. package/dist/src/index.d.ts +3 -3
  178. package/dist/src/index.js +1 -1
  179. package/dist/src/input-actions.js +1 -1
  180. package/dist/src/input-actions2.js +1 -1
  181. package/dist/src/install-artifact-facade.js +1 -1
  182. package/dist/src/install-source-network-transport.js +1 -1
  183. package/dist/src/install-source2.js +1 -1
  184. package/dist/src/interaction-error.js +1 -1
  185. package/dist/src/interaction-positionals.js +1 -1
  186. package/dist/src/interaction-ref-policy.js +1 -1
  187. package/dist/src/interaction2.js +1 -1
  188. package/dist/src/interactor-operation-binding.js +1 -1
  189. package/dist/src/interactor.js +5 -5
  190. package/dist/src/interactor2.js +1 -1
  191. package/dist/src/interactor3.js +1 -1
  192. package/dist/src/interactor4.js +1 -1
  193. package/dist/src/interactor5.js +1 -1
  194. package/dist/src/interactors.js +1 -1
  195. package/dist/src/internal/bin.js +1 -1
  196. package/dist/src/internal/companion-tunnel.js +1 -1
  197. package/dist/src/internal/daemon.js +1 -1
  198. package/dist/src/internal/png-worker.js +1 -1
  199. package/dist/src/internal/run-script-child.js +1 -1
  200. package/dist/src/inventory.js +1 -1
  201. package/dist/src/inventory2.js +1 -1
  202. package/dist/src/inventory3.js +1 -1
  203. package/dist/src/inventory5.js +1 -1
  204. package/dist/src/ios-node-interpretation.js +1 -1
  205. package/dist/src/ios-simulator-accessibility.js +1 -1
  206. package/dist/src/ios-snapshot-acquisition.js +1 -1
  207. package/dist/src/ios-snapshot-engine.js +1 -1
  208. package/dist/src/ios-snapshot-runtime.js +1 -1
  209. package/dist/src/launch-confirmation.js +1 -1
  210. package/dist/src/launch-services-registration.js +1 -1
  211. package/dist/src/lease-context.js +1 -1
  212. package/dist/src/lease-registry-scope.js +1 -1
  213. package/dist/src/lease-release2.js +1 -1
  214. package/dist/src/lease-scope.js +1 -1
  215. package/dist/src/lease.js +1 -1
  216. package/dist/src/leased-recording-retention.js +1 -1
  217. package/dist/src/legacy.js +1 -1
  218. package/dist/src/limrun-download-file.js +1 -1
  219. package/dist/src/limrun-ios-files.js +1 -1
  220. package/dist/src/limrun-ios-runner.js +2 -2
  221. package/dist/src/limrun-runtime-dependencies.js +1 -1
  222. package/dist/src/limrun.d.ts +1 -1
  223. package/dist/src/local-interactor-operation-set.js +1 -1
  224. package/dist/src/local-simulator-apps.js +1 -1
  225. package/dist/src/local-simulator-files.js +1 -1
  226. package/dist/src/location-coordinates.js +1 -1
  227. package/dist/src/manifest.js +1 -1
  228. package/dist/src/mechanics.js +12 -12
  229. package/dist/src/merge-flags.js +1 -1
  230. package/dist/src/metro-reload-endpoints.js +1 -1
  231. package/dist/src/metro-session-hints.js +1 -1
  232. package/dist/src/metro.d.ts +1 -1
  233. package/dist/src/mobile-snapshot-semantics.js +1 -1
  234. package/dist/src/network-traffic.js +1 -1
  235. package/dist/src/node-http.js +1 -1
  236. package/dist/src/node-touch-point.js +1 -1
  237. package/dist/src/observation.js +1 -1
  238. package/dist/src/open-script.js +1 -1
  239. package/dist/src/open-target-device-resolution.js +1 -1
  240. package/dist/src/orientation.js +1 -1
  241. package/dist/src/parameterized-recorded-fill.js +1 -1
  242. package/dist/src/perf-facade.js +1 -1
  243. package/dist/src/perf-runtime-operation-builder.js +1 -1
  244. package/dist/src/perf-runtime-plan.js +1 -1
  245. package/dist/src/perf-target.js +2 -2
  246. package/dist/src/perf.js +1 -1
  247. package/dist/src/physical-device-control.js +1 -1
  248. package/dist/src/platform-runtime-android-adb-host.js +1 -1
  249. package/dist/src/platform-runtime-app-log-process.js +1 -1
  250. package/dist/src/platform-runtime-apple-application-tools.js +1 -1
  251. package/dist/src/platform-runtime-claim-recovery.js +1 -1
  252. package/dist/src/platform-runtime-host.js +1 -1
  253. package/dist/src/platform-runtime-open-target.js +1 -1
  254. package/dist/src/platform-runtime-operation-host.js +3 -3
  255. package/dist/src/platform-runtime-runtime-hints.js +1 -1
  256. package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
  257. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  258. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  259. package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
  260. package/dist/src/platform-runtime-shutdown-error.js +1 -1
  261. package/dist/src/platform-runtime-unavailable.js +1 -1
  262. package/dist/src/platform-runtime.js +1 -1
  263. package/dist/src/platform-runtime2.js +1 -1
  264. package/dist/src/plist.js +1 -1
  265. package/dist/src/plugins2.js +1 -1
  266. package/dist/src/png-crop-bytes.js +1 -1
  267. package/dist/src/png-resize.js +1 -1
  268. package/dist/src/png-size.js +1 -1
  269. package/dist/src/png-worker-client.js +1 -1
  270. package/dist/src/png.js +1 -1
  271. package/dist/src/post-gesture-stability.js +1 -1
  272. package/dist/src/process-executable-path.js +1 -0
  273. package/dist/src/process-exit.js +1 -1
  274. package/dist/src/provider-device-runtime.d.ts +2 -2
  275. package/dist/src/provider-limrun-credentials.js +1 -1
  276. package/dist/src/provider-plugin.d.ts +1 -1
  277. package/dist/src/provider-profile-fields.js +1 -1
  278. package/dist/src/provider-webdriver.js +1 -1
  279. package/dist/src/provider.js +1 -1
  280. package/dist/src/proxy.js +2 -2
  281. package/dist/src/react-devtools-connection.js +1 -1
  282. package/dist/src/react-devtools-inspect-command.js +1 -1
  283. package/dist/src/react-native-overlay2.js +2 -2
  284. package/dist/src/react-native.js +1 -1
  285. package/dist/src/react-profile-command.js +1 -1
  286. package/dist/src/record-runtime.js +1 -1
  287. package/dist/src/record-trace.js +1 -1
  288. package/dist/src/recording-gestures.js +1 -1
  289. package/dist/src/recording.js +1 -1
  290. package/dist/src/rect-center.js +1 -1
  291. package/dist/src/register-builtins.js +1 -1
  292. package/dist/src/registry.js +1 -1
  293. package/dist/src/remote-config-core.js +1 -1
  294. package/dist/src/remote-config-flags.js +1 -1
  295. package/dist/src/remote-connection-state.js +1 -1
  296. package/dist/src/replay-backend-host.js +1 -1
  297. package/dist/src/replay-divergence.js +1 -1
  298. package/dist/src/replay-maestro-backend.js +2 -2
  299. package/dist/src/replay.d.ts +1 -1
  300. package/dist/src/replay2.js +1 -1
  301. package/dist/src/reporting.js +1 -1
  302. package/dist/src/request-dispatch-disclosure.js +1 -1
  303. package/dist/src/request-ended-leases.js +1 -1
  304. package/dist/src/request-providers.js +1 -1
  305. package/dist/src/request-runtime-binding.js +1 -1
  306. package/dist/src/request.js +1 -1
  307. package/dist/src/result-serialization.js +2 -2
  308. package/dist/src/retry.js +1 -1
  309. package/dist/src/run-script-execution.js +6 -8
  310. package/dist/src/run-script-http.js +1 -1
  311. package/dist/src/runner-cache-metadata.js +1 -1
  312. package/dist/src/runner-cache-retention.js +1 -1
  313. package/dist/src/runner-client.js +1 -1
  314. package/dist/src/runner-contract.js +1 -1
  315. package/dist/src/runner-dev-tools-security.js +1 -1
  316. package/dist/src/runner-device-readiness.js +1 -1
  317. package/dist/src/runner-device-set.js +1 -1
  318. package/dist/src/runner-disposal.js +1 -1
  319. package/dist/src/runner-error-classification.js +2 -2
  320. package/dist/src/runner-exchange.js +1 -1
  321. package/dist/src/runner-io.js +1 -1
  322. package/dist/src/runner-launched-session.js +1 -1
  323. package/dist/src/runner-lease.js +1 -1
  324. package/dist/src/runner-lifecycle.js +1 -1
  325. package/dist/src/runner-operations-facade.js +1 -1
  326. package/dist/src/runner-panel.js +1 -1
  327. package/dist/src/runner-retention.js +1 -1
  328. package/dist/src/runner-runtime.js +1 -1
  329. package/dist/src/runner-selector-query.js +1 -1
  330. package/dist/src/runner-sequence.js +1 -1
  331. package/dist/src/runner-start-budget.js +1 -1
  332. package/dist/src/runner-startup-transport.js +1 -1
  333. package/dist/src/runner-toolchain-identity.js +1 -1
  334. package/dist/src/runtime-admission.js +1 -1
  335. package/dist/src/runtime-deployment.js +1 -1
  336. package/dist/src/runtime-factory.js +1 -1
  337. package/dist/src/runtime-session.js +1 -1
  338. package/dist/src/runtime-transport-hints.js +1 -1
  339. package/dist/src/runtime.js +2 -2
  340. package/dist/src/runtime10.js +1 -1
  341. package/dist/src/runtime11.js +1 -1
  342. package/dist/src/runtime12.js +1 -1
  343. package/dist/src/runtime13.js +2 -2
  344. package/dist/src/runtime2.js +2 -2
  345. package/dist/src/runtime4.js +3 -3
  346. package/dist/src/runtime5.js +1 -1
  347. package/dist/src/runtime6.js +1 -1
  348. package/dist/src/runtime7.js +2 -2
  349. package/dist/src/runtime8.js +1 -1
  350. package/dist/src/runtime9.js +1 -1
  351. package/dist/src/screen-recording-admission-ledger.js +1 -0
  352. package/dist/src/screen-recording-completion.js +1 -1
  353. package/dist/src/screen-recording-options.js +1 -1
  354. package/dist/src/screen-recording-resource-recovery.js +1 -1
  355. package/dist/src/screen-recording-stop-recovery.js +1 -1
  356. package/dist/src/screen-recording-transport.js +1 -1
  357. package/dist/src/screenshot-density.js +1 -1
  358. package/dist/src/screenshot-image-size.js +1 -1
  359. package/dist/src/screenshot-image.js +1 -1
  360. package/dist/src/screenshot-runtime.js +1 -1
  361. package/dist/src/screenshot-runtime2.js +1 -1
  362. package/dist/src/screenshot.js +1 -1
  363. package/dist/src/screenshot2.js +1 -1
  364. package/dist/src/screenshot4.js +1 -1
  365. package/dist/src/script-source.js +1 -1
  366. package/dist/src/script.js +1 -1
  367. package/dist/src/scroll-command.js +1 -1
  368. package/dist/src/scroll-gesture.js +1 -1
  369. package/dist/src/sdk-batch-runner.d.ts +1 -1
  370. package/dist/src/sdk-batch-runner.js +2 -2
  371. package/dist/src/sdk-batch.js +2 -2
  372. package/dist/src/sdk-contracts.d.ts +26 -2
  373. package/dist/src/sdk-contracts.js +2 -2
  374. package/dist/src/sdk-device.js +1 -1
  375. package/dist/src/sdk-finders.d.ts +1 -1
  376. package/dist/src/sdk-finders.js +1 -1
  377. package/dist/src/sdk-io.js +5 -5
  378. package/dist/src/sdk-remote-config.d.ts +1 -1
  379. package/dist/src/sdk-remote-config.js +1 -1
  380. package/dist/src/sdk-selectors.d.ts +9 -6
  381. package/dist/src/sdk-selectors.js +1 -1
  382. package/dist/src/selection.js +0 -0
  383. package/dist/src/selector-pipeline-policy.js +1 -1
  384. package/dist/src/selector-runtime.js +1 -1
  385. package/dist/src/selectors.js +1 -1
  386. package/dist/src/server-shutdown.js +1 -1
  387. package/dist/src/server-startup.js +2 -2
  388. package/dist/src/server.js +4 -4
  389. package/dist/src/session-allocation.js +1 -1
  390. package/dist/src/session-artifact-paths.js +1 -1
  391. package/dist/src/session-capture-binding.js +1 -1
  392. package/dist/src/session-device-resolution.js +1 -1
  393. package/dist/src/session-event-action.js +1 -1
  394. package/dist/src/session-open.js +1 -1
  395. package/dist/src/session-repair-tombstone.js +1 -1
  396. package/dist/src/session-replay-vars.js +1 -1
  397. package/dist/src/session-routing.js +1 -1
  398. package/dist/src/session-runtime-admission.js +1 -1
  399. package/dist/src/session-runtime.js +1 -1
  400. package/dist/src/session-script-destination.js +1 -0
  401. package/dist/src/session-selector.js +1 -1
  402. package/dist/src/session-store.js +3 -3
  403. package/dist/src/session-teardown.js +1 -1
  404. package/dist/src/session-tenant-scope.js +1 -1
  405. package/dist/src/session2.js +5 -5
  406. package/dist/src/settings-bluetooth.js +1 -1
  407. package/dist/src/settings-global-toggle.js +1 -1
  408. package/dist/src/settings.js +1 -1
  409. package/dist/src/settings2.js +1 -1
  410. package/dist/src/settle-observation-capture.js +1 -1
  411. package/dist/src/simctl-execution.js +1 -1
  412. package/dist/src/simctl-facade.js +1 -1
  413. package/dist/src/simctl.js +1 -1
  414. package/dist/src/simulator-app-budget.js +1 -1
  415. package/dist/src/simulator-boot.js +1 -1
  416. package/dist/src/simulator-facade.js +1 -1
  417. package/dist/src/simulator-state.js +1 -1
  418. package/dist/src/simulator.js +1 -1
  419. package/dist/src/snapshot-baseline.js +1 -1
  420. package/dist/src/snapshot-chrome.js +1 -1
  421. package/dist/src/snapshot-desktop-projection.js +1 -1
  422. package/dist/src/snapshot-diagnostics.js +1 -1
  423. package/dist/src/snapshot-helper-install.js +3 -3
  424. package/dist/src/snapshot-helper-session.js +1 -1
  425. package/dist/src/snapshot-lines.js +1 -1
  426. package/dist/src/snapshot-node-lookup.js +1 -1
  427. package/dist/src/snapshot-occlusion.js +1 -1
  428. package/dist/src/snapshot-private-evidence.js +1 -1
  429. package/dist/src/snapshot-runtime-binding.js +1 -1
  430. package/dist/src/snapshot-runtime-capture-input.js +1 -1
  431. package/dist/src/snapshot-runtime.js +1 -1
  432. package/dist/src/snapshot-state.js +1 -1
  433. package/dist/src/snapshot.js +1 -1
  434. package/dist/src/snapshot2.js +1 -1
  435. package/dist/src/snapshot3.js +2 -2
  436. package/dist/src/snapshot4.js +1 -1
  437. package/dist/src/source-channel.js +1 -1
  438. package/dist/src/src.js +1 -1
  439. package/dist/src/src10.js +1 -1
  440. package/dist/src/src11.js +1 -1
  441. package/dist/src/src2.js +1 -1
  442. package/dist/src/src3.js +5 -5
  443. package/dist/src/src4.js +2 -2
  444. package/dist/src/src5.js +1 -1
  445. package/dist/src/src6.js +1 -1
  446. package/dist/src/src8.js +1 -1
  447. package/dist/src/store-legacy.js +1 -1
  448. package/dist/src/store.js +1 -1
  449. package/dist/src/string-enum.js +1 -1
  450. package/dist/src/surface-snapshot.js +1 -1
  451. package/dist/src/surface-snapshot2.js +1 -1
  452. package/dist/src/sync-cache.js +1 -1
  453. package/dist/src/system-surface-foreground.js +2 -2
  454. package/dist/src/takeover.js +1 -1
  455. package/dist/src/tap-keyboard-occlusion.js +1 -1
  456. package/dist/src/target-evidence-tree.js +1 -1
  457. package/dist/src/target-evidence.js +1 -1
  458. package/dist/src/telephony-runtime.js +1 -1
  459. package/dist/src/tool-provider-facade.js +1 -1
  460. package/dist/src/tool-provider.js +3 -3
  461. package/dist/src/tool-provider2.js +1 -1
  462. package/dist/src/tool-provider3.js +1 -1
  463. package/dist/src/toolchain-probe.js +1 -1
  464. package/dist/src/touch-runtime.js +1 -1
  465. package/dist/src/touch-runtime2.js +1 -1
  466. package/dist/src/transport.js +2 -2
  467. package/dist/src/tree.js +1 -1
  468. package/dist/src/tv-remote-runtime.js +1 -1
  469. package/dist/src/tv-remote.js +1 -1
  470. package/dist/src/type-text-runtime.js +1 -1
  471. package/dist/src/unsupported-interactor.js +1 -1
  472. package/dist/src/update-check.js +1 -1
  473. package/dist/src/validation.js +1 -1
  474. package/dist/src/vars.js +1 -1
  475. package/dist/src/vega-executable.js +1 -1
  476. package/dist/src/verified-file.js +1 -1
  477. package/dist/src/video.js +2 -2
  478. package/dist/src/viewport.js +1 -1
  479. package/dist/src/web.js +1 -1
  480. package/dist/src/webdriver-source.js +1 -1
  481. package/package.json +2 -2
  482. package/server.json +2 -2
  483. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.37.apk.sha256 +0 -1
  484. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.37.apk.sha256 +0 -1
  485. package/dist/src/capture-output-ownership.js +0 -1
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{n as t,t as n}from"./durable-resource.js";function r(e,t){let r=i(e),o,s=!1,c=()=>s,l=e=>(s=!0,o??=t.finish(r,e).catch(e=>{throw o=void 0,e}),o),u=()=>o?o.then(async e=>e.status===`completed`?{status:`cleaned`}:await t.forceCleanup(r),async()=>await t.forceCleanup(r)):t.forceCleanup(r);return Object.freeze({inspect:()=>r,appendGestureEvents:e=>{e.length===0||c()||(r=i({...r,gestureEvents:[...r.gestureEvents,...e]}))},setTouchReferenceFrame:e=>{c()||(r=i({...r,...e?{touchReferenceFrame:e}:{}}))},setRunnerSessionId:e=>{c()||e.trim().length===0||(r=i({...r,runnerSessionId:e}))},invalidate:e=>{c()||r.invalidatedReason||(r=i({...r,invalidatedReason:e}))},finish:l,...n(()=>(s=!0,u()),a)})}function i(e){return Object.freeze({...e,gestureEvents:Object.freeze([...e.gestureEvents])})}function a(n,r){if(!t(n))throw new e(`COMMAND_FAILED`,n.message??`Screen recording cleanup could not be confirmed`,{reason:n.reason,retriable:n.reason!==`ownership-fence-lost`,hint:n.reason===`ownership-fence-lost`?`Use the current recording owner or recovery record before retrying cleanup.`:`Keep the recovery record and retry cleanup through the exact runtime owner.`},r)}function o(e,t,n){let{stopObservation:r,nativePathDisposition:i,showTouches:a=e.showTouches}=n;return Object.freeze({status:`completed`,result:Object.freeze({backend:e.backend,outPath:e.outPath,...e.clientOutPath===void 0?{}:{clientOutPath:e.clientOutPath},startedAt:e.startedAt,completedAt:Date.now(),stopObservation:r,...i===void 0?{}:{nativePathDisposition:i},scope:e.scope,showTouches:a,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...t})})}export{r as n,o as t};
1
+ import{_ as e}from"./sdk-contracts.js";import{n as t,t as n}from"./durable-resource.js";function r(e,t){let r=i(e),o,s=!1,c=()=>s,l=e=>(s=!0,o??=t.finish(r,e).catch(e=>{throw o=void 0,e}),o),u=()=>o?o.then(async e=>e.status===`completed`?{status:`cleaned`}:await t.forceCleanup(r),async()=>await t.forceCleanup(r)):t.forceCleanup(r);return Object.freeze({inspect:()=>r,appendGestureEvents:e=>{e.length===0||c()||(r=i({...r,gestureEvents:[...r.gestureEvents,...e]}))},setTouchReferenceFrame:e=>{c()||(r=i({...r,...e?{touchReferenceFrame:e}:{}}))},setRunnerSessionId:e=>{c()||e.trim().length===0||(r=i({...r,runnerSessionId:e}))},invalidate:e=>{c()||r.invalidatedReason||(r=i({...r,invalidatedReason:e}))},finish:l,...n(()=>(s=!0,u()),a)})}function i(e){return Object.freeze({...e,gestureEvents:Object.freeze([...e.gestureEvents])})}function a(n,r){if(!t(n))throw new e(`COMMAND_FAILED`,n.message??`Screen recording cleanup could not be confirmed`,{reason:n.reason,retriable:n.reason!==`ownership-fence-lost`,hint:n.reason===`ownership-fence-lost`?`Use the current recording owner or recovery record before retrying cleanup.`:`Keep the recovery record and retry cleanup through the exact runtime owner.`},r)}function o(e,t,n){let{stopObservation:r,nativePathDisposition:i,showTouches:a=e.showTouches}=n;return Object.freeze({status:`completed`,result:Object.freeze({backend:e.backend,outPath:e.outPath,...e.clientOutPath===void 0?{}:{clientOutPath:e.clientOutPath},startedAt:e.startedAt,completedAt:Date.now(),stopObservation:r,...i===void 0?{}:{nativePathDisposition:i},scope:e.scope,showTouches:a,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...t})})}export{r as n,o as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";function t(t,r,i){let a=n(t,r);if(a.length>0)throw new e(`INVALID_ARGS`,i(a))}function n(e,t){return Object.freeze([...t.scopes.includes(e.scope)?[]:[`--scope`],...t.fps||e.fps===void 0?[]:[`--fps`],...t.exportQuality||e.exportQuality===void 0?[]:[`--quality`],...t.hideTouches||!e.hideTouchesRequested?[]:[`--hide-touches`]])}export{t};
1
+ import{_ as e}from"./sdk-contracts.js";function t(t,r,i){let a=n(t,r);if(a.length>0)throw new e(`INVALID_ARGS`,i(a))}function n(e,t){return Object.freeze([...t.scopes.includes(e.scope)?[]:[`--scope`],...t.fps||e.fps===void 0?[]:[`--fps`],...t.exportQuality||e.exportQuality===void 0?[]:[`--quality`],...t.hideTouches||!e.hideTouchesRequested?[]:[`--hide-touches`]])}export{t};
@@ -1 +1 @@
1
- import{N as e,Sn as t}from"./sdk-batch.js";import{i as n}from"./screen-recording-session-resource.js";async function r(e){let t;try{return t=await e.gateway.bind({device:i(e.envelope),intent:{kind:`exact-owner`,owner:e.envelope.owner,fence:e.envelope.fence},scope:e.scope}),e.scope.signal.throwIfAborted(),e.create(t)}catch(e){throw t&&await t[Symbol.asyncDispose](),e}}function i(e){return{platform:e.device.family,id:e.device.id,name:e.device.id,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.appleOs===void 0?{}:{appleOs:e.device.appleOs},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}}}function a(e){return n.recoverOne({sessionsDir:e.sessionsDir,scope:e.scope,acquisitionDeadlineMs:e.acquisitionDeadlineMs,onDiagnostic:e.onDiagnostic,acquireControl:async(t,n)=>await o(e.gateway,t,n)},e.resourcePath)}async function o(n,i,a){return await r({gateway:n,envelope:i,scope:a,create:n=>s({runtime:t(n,e),dispose:async()=>await n[Symbol.asyncDispose]()})})}function s(e){return Object.freeze({reattach:async t=>await e.runtime.operations.screenRecordingReattach({envelope:t}),cleanup:async t=>await e.runtime.operations.screenRecordingCleanup({envelope:t}),[Symbol.asyncDispose]:e.dispose})}export{a as n,r,s as t};
1
+ import{N as e,Tn as t}from"./sdk-batch.js";import{i as n}from"./screen-recording-session-resource.js";async function r(e){let t;try{return t=await e.gateway.bind({device:i(e.envelope),intent:{kind:`exact-owner`,owner:e.envelope.owner,fence:e.envelope.fence},scope:e.scope}),e.scope.signal.throwIfAborted(),e.create(t)}catch(e){throw t&&await t[Symbol.asyncDispose](),e}}function i(e){return{platform:e.device.family,id:e.device.id,name:e.device.id,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.appleOs===void 0?{}:{appleOs:e.device.appleOs},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}}}function a(e){return n.recoverOne({sessionsDir:e.sessionsDir,scope:e.scope,acquisitionDeadlineMs:e.acquisitionDeadlineMs,onDiagnostic:e.onDiagnostic,acquireControl:async(t,n)=>await o(e.gateway,t,n)},e.resourcePath)}async function o(n,i,a){return await r({gateway:n,envelope:i,scope:a,create:n=>s({runtime:t(n,e),dispose:async()=>await n[Symbol.asyncDispose]()})})}function s(e){return Object.freeze({reattach:async t=>await e.runtime.operations.screenRecordingReattach({envelope:t}),cleanup:async t=>await e.runtime.operations.screenRecordingCleanup({envelope:t}),[Symbol.asyncDispose]:e.dispose})}export{a as n,r,s as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime.js";import{P as t}from"./sdk-contracts.js";import{y as n}from"./sdk-batch-runner.js";import{yt as r}from"./sdk-io.js";import"./diagnostics.js";import{X as i,q as a}from"./sdk-device.js";import{r as o}from"./recording-scope.js";import{i as s,n as c}from"./recording-stop-observation.js";import{n as l,t as u}from"./screen-recording-resource-store.js";import d from"node:fs";var f=e({readReplayableStoredCompletion:()=>y,resolveScreenRecordingStopRecovery:()=>m,screenRecordingManifestDevice:()=>g,screenRecordingManifestIsTerminal:()=>h});const p=[`clientOutPath`,`telemetryPath`,`warning`,`overlayWarning`];function m(e){let{resourcePath:t,record:n}=_(e);if(n.status!==`decoded`)return{kind:`none`};if(v(e,n.envelope),n.envelope.lifecycle!==`completed`)return{kind:`open`,resourcePath:t};let i=y(n.envelope.metadata);return i===void 0?(r({level:`warn`,phase:`screen_recording_completed_manifest_unreplayable`,data:{resourcePath:t}}),{kind:`none`}):{kind:`completed`,completion:i}}function h(e){let{record:t}=_(e);return t.status===`decoded`&&t.envelope.lifecycle===`completed`}function g(e){let{record:t}=_(e);return t.status===`decoded`?t.envelope.device:void 0}function _(e){let t=l.resolvePath(e.sessionStore.resolveSessionDir(e.sessionName));return{resourcePath:t,record:l.read(t)}}function v(e,n){if(n.sessionId!==e.sessionName)throw new t(`COMMAND_FAILED`,`Screen recording recovery record does not belong to the requested session`,{reason:`runtime-contract-invalid`});if(!i(n.device,a(e.device)))throw new t(`COMMAND_FAILED`,`Screen recording recovery device does not match the selected device`,{reason:`runtime-contract-invalid`})}function y(e){let t=e?.[u];if(!n(t)||!b(t)||!x(t)||!S(t))return;let r=t;return d.existsSync(r.outPath)?r:void 0}function b(e){return C(e.outPath)&&C(e.backend)&&T(e.startedAt)&&T(e.completedAt)&&(e.capturedDurationMs===void 0||T(e.capturedDurationMs))&&o(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function x(e){return p.every(t=>w(e[t]))&&D(e.activeSessionApp)&&k(e.chunks)}function S(e){return(e.stopObservation===void 0||c(e.stopObservation))&&(e.nativePathDisposition===void 0||s(e.nativePathDisposition))}function C(e){return typeof e==`string`&&e.length>0}function w(e){return e===void 0||C(e)}function T(e){return typeof e==`number`&&Number.isFinite(e)}function E(e){return!n(e)||!C(e.bundleId)?!1:w(e.name)}function D(e){return e===void 0||E(e)}function O(e){return Array.isArray(e)&&e.every(e=>n(e)&&Number.isFinite(e.index)&&C(e.path)&&w(e.clientOutPath))}function k(e){return e===void 0||O(e)}export{f as i,g as n,h as r,m as t};
1
+ import{r as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{y as n}from"./sdk-batch-runner.js";import{St as r}from"./sdk-io.js";import"./diagnostics.js";import{J as i,Z as a}from"./sdk-device.js";import{r as o}from"./recording-scope.js";import{i as s,n as c}from"./recording-stop-observation.js";import{n as l,t as u}from"./screen-recording-resource-store.js";import d from"node:fs";var f=e({readReplayableStoredCompletion:()=>y,resolveScreenRecordingStopRecovery:()=>m,screenRecordingManifestDevice:()=>g,screenRecordingManifestIsTerminal:()=>h});const p=[`clientOutPath`,`telemetryPath`,`warning`,`overlayWarning`];function m(e){let{resourcePath:t,record:n}=_(e);if(n.status!==`decoded`)return{kind:`none`};if(v(e,n.envelope),n.envelope.lifecycle!==`completed`)return{kind:`open`,resourcePath:t};let i=y(n.envelope.metadata);return i===void 0?(r({level:`warn`,phase:`screen_recording_completed_manifest_unreplayable`,data:{resourcePath:t}}),{kind:`none`}):{kind:`completed`,completion:i}}function h(e){let{record:t}=_(e);return t.status===`decoded`&&t.envelope.lifecycle===`completed`}function g(e){let{record:t}=_(e);return t.status===`decoded`?t.envelope.device:void 0}function _(e){let t=l.resolvePath(e.sessionStore.resolveSessionDir(e.sessionName));return{resourcePath:t,record:l.read(t)}}function v(e,n){if(n.sessionId!==e.sessionName)throw new t(`COMMAND_FAILED`,`Screen recording recovery record does not belong to the requested session`,{reason:`runtime-contract-invalid`});if(!a(n.device,i(e.device)))throw new t(`COMMAND_FAILED`,`Screen recording recovery device does not match the selected device`,{reason:`runtime-contract-invalid`})}function y(e){let t=e?.[u];if(!n(t)||!b(t)||!x(t)||!S(t))return;let r=t;return d.existsSync(r.outPath)?r:void 0}function b(e){return C(e.outPath)&&C(e.backend)&&T(e.startedAt)&&T(e.completedAt)&&(e.capturedDurationMs===void 0||T(e.capturedDurationMs))&&o(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function x(e){return p.every(t=>w(e[t]))&&D(e.activeSessionApp)&&k(e.chunks)}function S(e){return(e.stopObservation===void 0||c(e.stopObservation))&&(e.nativePathDisposition===void 0||s(e.nativePathDisposition))}function C(e){return typeof e==`string`&&e.length>0}function w(e){return e===void 0||C(e)}function T(e){return typeof e==`number`&&Number.isFinite(e)}function E(e){return!n(e)||!C(e.bundleId)?!1:w(e.name)}function D(e){return e===void 0||E(e)}function O(e){return Array.isArray(e)&&e.every(e=>n(e)&&Number.isFinite(e.index)&&C(e.path)&&w(e.clientOutPath))}function k(e){return e===void 0||O(e)}export{f as i,g as n,h as r,m as t};
@@ -1 +1 @@
1
- import{q as e}from"./sdk-device.js";import{a as t,r as n}from"./durable-resource.js";import{n as r}from"./screen-recording-runtime.js";import{n as i}from"./async-lifecycle.js";import{n as a,t as o}from"./screen-recording-completion.js";import{t as s}from"./screen-recording-options.js";function c(e){return Object.freeze({resourceKind:r,version:1,encode:e=>({...e}),decode:t=>t.backend===e&&typeof t.outputPath==`string`?{status:`decoded`,descriptor:Object.freeze({backend:e,outputPath:t.outputPath})}:{status:`invalid`,message:`Invalid ${e} screen-recording descriptor`}})}function l(e){return{status:`unreattachable`,reason:`transport-not-reattachable`,message:e}}function u(e){return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:e}}async function d(l){let{host:u,device:d,owner:m,input:h,signal:g,transport:_}=l;s(h,l.support,l.unsupported),g.throwIfAborted(),await u.screenRecording.outputs.prepare(h.outputPath);let v=f(_),y=!1;try{await _.start(g),y=!0,g.throwIfAborted()}catch(e){throw y&&await v().catch(()=>{}),g.throwIfAborted(),e}let b=a(p(_.backend,h),{finish:async e=>{let t=await v();_.collect&&await _.collect(t,e.outPath);let n=await u.screenRecording.finalize.complete({outputPath:e.outPath,showTouches:!1,gestureEvents:e.gestureEvents,...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},targetLabel:_.targetLabel});return o(e,n,{stopObservation:{recorder:`confirmed`},showTouches:!1})},forceCleanup:async()=>{try{return await v(),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`${_.backend} recording cleanup failed`}}}});return Object.freeze({pendingHandle:new i(b),envelope:n({resourceKind:r,sessionId:h.sessionId,device:e(d),owner:m,fence:h.fence,lifecycle:`open`,descriptor:t(c(_.backend),{backend:_.backend,outputPath:h.outputPath})})})}function f(e){let t;return()=>t??=e.stop().catch(e=>{throw t=void 0,e})}function p(e,t){return Object.freeze({backend:e,outPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutPath:t.clientOutputPath},startedAt:Date.now(),scope:t.scope,showTouches:!1,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},gestureEvents:[]})}export{u as n,l as r,d as t};
1
+ import{J as e}from"./sdk-device.js";import{a as t,r as n}from"./durable-resource.js";import{n as r}from"./screen-recording-runtime.js";import{n as i}from"./async-lifecycle.js";import{n as a,t as o}from"./screen-recording-completion.js";import{t as s}from"./screen-recording-options.js";function c(e){return Object.freeze({resourceKind:r,version:1,encode:e=>({...e}),decode:t=>t.backend===e&&typeof t.outputPath==`string`?{status:`decoded`,descriptor:Object.freeze({backend:e,outputPath:t.outputPath})}:{status:`invalid`,message:`Invalid ${e} screen-recording descriptor`}})}function l(e){return{status:`unreattachable`,reason:`transport-not-reattachable`,message:e}}function u(e){return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:e}}async function d(l){let{host:u,device:d,owner:m,input:h,signal:g,transport:_}=l;s(h,l.support,l.unsupported),g.throwIfAborted(),await u.screenRecording.outputs.prepare(h.outputPath);let v=f(_),y=!1;try{await _.start(g),y=!0,g.throwIfAborted()}catch(e){throw y&&await v().catch(()=>{}),g.throwIfAborted(),e}let b=a(p(_.backend,h),{finish:async e=>{let t=await v();_.collect&&await _.collect(t,e.outPath);let n=await u.screenRecording.finalize.complete({outputPath:e.outPath,showTouches:!1,gestureEvents:e.gestureEvents,...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},targetLabel:_.targetLabel});return o(e,n,{stopObservation:{recorder:`confirmed`},showTouches:!1})},forceCleanup:async()=>{try{return await v(),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`${_.backend} recording cleanup failed`}}}});return Object.freeze({pendingHandle:new i(b),envelope:n({resourceKind:r,sessionId:h.sessionId,device:e(d),owner:m,fence:h.fence,lifecycle:`open`,descriptor:t(c(_.backend),{backend:_.backend,outputPath:h.outputPath})})})}function f(e){let t;return()=>t??=e.stop().catch(e=>{throw t=void 0,e})}function p(e,t){return Object.freeze({backend:e,outPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutPath:t.clientOutputPath},startedAt:Date.now(),scope:t.scope,showTouches:!1,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},gestureEvents:[]})}export{u as n,l as r,d as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{t as n}from"./png-size.js";function r(t,n){if(!(n===void 0||s(t)))throw new e(`UNSUPPORTED_OPERATION`,`--pixel-density is currently supported only on iOS-family simulators`)}function i(e,t,n){let r=o(n);if(t!==r)return{width:Math.max(1,Math.round(e.width/t*r)),height:Math.max(1,Math.round(e.height/t*r))}}async function a(e){let t=s(e.device),r;try{r=await n(e.path)}catch(e){if(t)throw e;return{}}let i={width:r.width,height:r.height};if(!t||e.scale!==void 0&&e.scale!==1)return i;let a=o(e.requestedPixelDensity);return{...i,logicalWidth:Math.round(r.width/a),logicalHeight:Math.round(r.height/a),pixelDensity:a}}function o(e){return e??1}function s(e){return t(e)&&e.kind===`simulator`}export{i as n,a as r,r as t};
1
+ import{_ as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{t as n}from"./png-size.js";function r(t,n){if(!(n===void 0||s(t)))throw new e(`UNSUPPORTED_OPERATION`,`--pixel-density is currently supported only on iOS-family simulators`)}function i(e,t,n){let r=o(n);if(t!==r)return{width:Math.max(1,Math.round(e.width/t*r)),height:Math.max(1,Math.round(e.height/t*r))}}async function a(e){let t=s(e.device),r;try{r=await n(e.path)}catch(e){if(t)throw e;return{}}let i={width:r.width,height:r.height};if(!t||e.scale!==void 0&&e.scale!==1)return i;let a=o(e.requestedPixelDensity);return{...i,logicalWidth:Math.round(r.width/a),logicalHeight:Math.round(r.height/a),pixelDensity:a}}function o(e){return e??1}function s(e){return t(e)&&e.kind===`simulator`}export{i as n,a as r,r as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{n as t}from"./png.js";function n(e,n,a){a==null||a<=0||(t(e)?r(e,n,a):e[0]===255&&e[1]===216&&i(e,n,a))}function r(e,t,n){let r=8;for(;r+16<=e.length;){let i=e.readUInt32BE(r),a=e.toString(`ascii`,r+4,r+8);if(a===`IHDR`&&i>=8&&o(e.readUInt32BE(r+8),e.readUInt32BE(r+12),t,n),a===`IEND`)return;r+=i+12}}function i(e,t,n){for(let{marker:r,offset:i,length:s}of a(e))[192,193,194].includes(r)&&s>=8&&o(e.readUInt16BE(i+5),e.readUInt16BE(i+3),t,n)}function*a(e){let t=2;for(;t+3<e.length&&e[t]===255;){for(;e[t]===255;)t+=1;let n=e[t++];if(n===218||n===217||t+2>e.length)return;let r=e.readUInt16BE(t);if(r<2||t+r>e.length)return;yield{marker:n,offset:t,length:r},t+=r}}function o(t,n,r,i){let a=t*n;if(!Number.isSafeInteger(a)||a<1||i!=null&&i>0&&a>i)throw new e(`INVALID_ARGS`,`${r} is ${a} pixels, which exceeds the configured maxImagePixels limit of ${i}`)}export{n as validateScreenshotImagePixels,o as validateScreenshotPixels};
1
+ import{_ as e}from"./sdk-contracts.js";import{n as t}from"./png.js";function n(e,n,a){a==null||a<=0||(t(e)?r(e,n,a):e[0]===255&&e[1]===216&&i(e,n,a))}function r(e,t,n){let r=8;for(;r+16<=e.length;){let i=e.readUInt32BE(r),a=e.toString(`ascii`,r+4,r+8);if(a===`IHDR`&&i>=8&&o(e.readUInt32BE(r+8),e.readUInt32BE(r+12),t,n),a===`IEND`)return;r+=i+12}}function i(e,t,n){for(let{marker:r,offset:i,length:s}of a(e))[192,193,194].includes(r)&&s>=8&&o(e.readUInt16BE(i+5),e.readUInt16BE(i+3),t,n)}function*a(e){let t=2;for(;t+3<e.length&&e[t]===255;){for(;e[t]===255;)t+=1;let n=e[t++];if(n===218||n===217||t+2>e.length)return;let r=e.readUInt16BE(t);if(r<2||t+r>e.length)return;yield{marker:n,offset:t,length:r},t+=r}}function o(t,n,r,i){let a=t*n;if(!Number.isSafeInteger(a)||a<1||i!=null&&i>0&&a>i)throw new e(`INVALID_ARGS`,`${r} is ${a} pixels, which exceeds the configured maxImagePixels limit of ${i}`)}export{n as validateScreenshotImagePixels,o as validateScreenshotPixels};
@@ -1 +1 @@
1
- import{t as e}from"./rolldown-runtime.js";import{P as t}from"./sdk-contracts.js";import{n,r,t as i}from"./png.js";import{validateScreenshotImagePixels as a}from"./screenshot-image-size.js";var o=e(((e,t)=>{function n(e){var n=Math.floor,r=Array(64),i=Array(64),a=Array(64),o=Array(64),s,c,l,u,d=Array(65535),f=Array(65535),p=Array(64),m=Array(64),h=[],g=0,_=7,v=Array(64),y=Array(64),b=Array(64),x=Array(256),S=Array(2048),C,w=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],T=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],E=[0,1,2,3,4,5,6,7,8,9,10,11],D=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],O=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],k=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],A=[0,1,2,3,4,5,6,7,8,9,10,11],j=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],M=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function N(e){for(var t=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],s=0;s<64;s++){var c=n((t[s]*e+50)/100);c<1?c=1:c>255&&(c=255),r[w[s]]=c}for(var l=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],u=0;u<64;u++){var d=n((l[u]*e+50)/100);d<1?d=1:d>255&&(d=255),i[w[u]]=d}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],p=0,m=0;m<8;m++)for(var h=0;h<8;h++)a[p]=1/(r[w[p]]*f[m]*f[h]*8),o[p]=1/(i[w[p]]*f[m]*f[h]*8),p++}function P(e,t){for(var n=0,r=0,i=[],a=1;a<=16;a++){for(var o=1;o<=e[a];o++)i[t[r]]=[],i[t[r]][0]=n,i[t[r]][1]=a,r++,n++;n*=2}return i}function F(){s=P(T,E),c=P(k,A),l=P(D,O),u=P(j,M)}function I(){for(var e=1,t=2,n=1;n<=15;n++){for(var r=e;r<t;r++)f[32767+r]=n,d[32767+r]=[],d[32767+r][1]=n,d[32767+r][0]=r;for(var i=-(t-1);i<=-e;i++)f[32767+i]=n,d[32767+i]=[],d[32767+i][1]=n,d[32767+i][0]=t-1+i;e<<=1,t<<=1}}function L(){for(var e=0;e<256;e++)S[e]=19595*e,S[e+256>>0]=38470*e,S[e+512>>0]=7471*e+32768,S[e+768>>0]=-11059*e,S[e+1024>>0]=-21709*e,S[e+1280>>0]=32768*e+8421375,S[e+1536>>0]=-27439*e,S[e+1792>>0]=-5329*e}function R(e){for(var t=e[0],n=e[1]-1;n>=0;)t&1<<n&&(g|=1<<_),n--,_--,_<0&&(g==255?(z(255),z(0)):z(g),_=7,g=0)}function z(e){h.push(e)}function B(e){z(e>>8&255),z(e&255)}function V(e,t){var n,r,i,a,o,s,c,l,u=0,d,f=8,m=64;for(d=0;d<f;++d){n=e[u],r=e[u+1],i=e[u+2],a=e[u+3],o=e[u+4],s=e[u+5],c=e[u+6],l=e[u+7];var h=n+l,g=n-l,_=r+c,v=r-c,y=i+s,b=i-s,x=a+o,S=a-o,C=h+x,w=h-x,T=_+y,E=_-y;e[u]=C+T,e[u+4]=C-T;var D=(E+w)*.707106781;e[u+2]=w+D,e[u+6]=w-D,C=S+b,T=b+v,E=v+g;var O=(C-E)*.382683433,k=.5411961*C+O,A=1.306562965*E+O,j=T*.707106781,M=g+j,N=g-j;e[u+5]=N+k,e[u+3]=N-k,e[u+1]=M+A,e[u+7]=M-A,u+=8}for(u=0,d=0;d<f;++d){n=e[u],r=e[u+8],i=e[u+16],a=e[u+24],o=e[u+32],s=e[u+40],c=e[u+48],l=e[u+56];var P=n+l,F=n-l,I=r+c,L=r-c,R=i+s,z=i-s,B=a+o,V=a-o,H=P+B,U=P-B,W=I+R,G=I-R;e[u]=H+W,e[u+32]=H-W;var K=(G+U)*.707106781;e[u+16]=U+K,e[u+48]=U-K,H=V+z,W=z+L,G=L+F;var q=(H-G)*.382683433,J=.5411961*H+q,Y=1.306562965*G+q,X=W*.707106781,Z=F+X,Q=F-X;e[u+40]=Q+J,e[u+24]=Q-J,e[u+8]=Z+Y,e[u+56]=Z-Y,u++}var $;for(d=0;d<m;++d)$=e[d]*t[d],p[d]=$>0?$+.5|0:$-.5|0;return p}function H(){B(65504),B(16),z(74),z(70),z(73),z(70),z(0),z(1),z(1),z(0),B(1),B(1),z(0),z(0)}function U(e){if(e){B(65505),e[0]===69&&e[1]===120&&e[2]===105&&e[3]===102?B(e.length+2):(B(e.length+5+2),z(69),z(120),z(105),z(102),z(0));for(var t=0;t<e.length;t++)z(e[t])}}function W(e,t){B(65472),B(17),z(8),B(t),B(e),z(3),z(1),z(17),z(0),z(2),z(17),z(1),z(3),z(17),z(1)}function G(){B(65499),B(132),z(0);for(var e=0;e<64;e++)z(r[e]);z(1);for(var t=0;t<64;t++)z(i[t])}function K(){B(65476),B(418),z(0);for(var e=0;e<16;e++)z(T[e+1]);for(var t=0;t<=11;t++)z(E[t]);z(16);for(var n=0;n<16;n++)z(D[n+1]);for(var r=0;r<=161;r++)z(O[r]);z(1);for(var i=0;i<16;i++)z(k[i+1]);for(var a=0;a<=11;a++)z(A[a]);z(17);for(var o=0;o<16;o++)z(j[o+1]);for(var s=0;s<=161;s++)z(M[s])}function q(e){e!==void 0&&e.constructor===Array&&e.forEach(e=>{if(typeof e==`string`){B(65534);var t=e.length;B(t+2);var n;for(n=0;n<t;n++)z(e.charCodeAt(n))}})}function J(){B(65498),B(12),z(3),z(1),z(0),z(2),z(17),z(3),z(17),z(0),z(63),z(0)}function Y(e,t,n,r,i){for(var a=i[0],o=i[240],s,c=16,l=63,u=64,p=V(e,t),h=0;h<u;++h)m[w[h]]=p[h];var g=m[0]-n;n=m[0],g==0?R(r[0]):(s=32767+g,R(r[f[s]]),R(d[s]));for(var _=63;_>0&&m[_]==0;_--);if(_==0)return R(a),n;for(var v=1,y;v<=_;){for(var b=v;m[v]==0&&v<=_;++v);var x=v-b;if(x>=c){y=x>>4;for(var S=1;S<=y;++S)R(o);x&=15}s=32767+m[v],R(i[(x<<4)+f[s]]),R(d[s]),v++}return _!=l&&R(a),n}function X(){for(var e=String.fromCharCode,t=0;t<256;t++)x[t]=e(t)}this.encode=function(e,n){new Date().getTime(),n&&Z(n),h=[],g=0,_=7,B(65496),H(),q(e.comments),U(e.exifBuffer),G(),W(e.width,e.height),K(),J();var r=0,i=0,d=0;g=0,_=7,this.encode.displayName=`_encode_`;var f=e.data,p=e.width,m=e.height,x=p*4;p*3;for(var C,w=0,T,E,D,O,k,A,j,M;w<m;){for(C=0;C<x;){for(O=x*w+C,k=O,A=-1,j=0,M=0;M<64;M++)j=M>>3,A=(M&7)*4,k=O+j*x+A,w+j>=m&&(k-=x*(w+1+j-m)),C+A>=x&&(k-=C+A-x+4),T=f[k++],E=f[k++],D=f[k++],v[M]=(S[T]+S[E+256>>0]+S[D+512>>0]>>16)-128,y[M]=(S[T+768>>0]+S[E+1024>>0]+S[D+1280>>0]>>16)-128,b[M]=(S[T+1280>>0]+S[E+1536>>0]+S[D+1792>>0]>>16)-128;r=Y(v,a,r,s,l),i=Y(y,o,i,c,u),d=Y(b,o,d,c,u),C+=32}w+=8}if(_>=0){var N=[];N[1]=_+1,N[0]=(1<<_+1)-1,R(N)}return B(65497),t===void 0?new Uint8Array(h):Buffer.from(h)};function Z(e){if(e<=0&&(e=1),e>100&&(e=100),C!=e){var t=0;t=Math.floor(e<50?5e3/e:200-e*2),N(t),C=e}}function Q(){var t=new Date().getTime();e||=50,X(),F(),I(),L(),Z(e),new Date().getTime()-t}Q()}t===void 0?typeof window<`u`&&(window[`jpeg-js`]=window[`jpeg-js`]||{},window[`jpeg-js`].encode=r):t.exports=r;function r(e,t){return t===void 0&&(t=50),{data:new n(t).encode(e,t),width:e.width,height:e.height}}})),s=e(((e,t)=>{var n=(function(){var e=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),t=4017,n=799,r=3406,i=2276,a=1567,o=3784,s=5793,c=2896;function l(){}function u(e,t){for(var n=0,r=[],i,a,o=16;o>0&&!e[o-1];)o--;r.push({children:[],index:0});var s=r[0],c;for(i=0;i<o;i++){for(a=0;a<e[i];a++){for(s=r.pop(),s.children[s.index]=t[n];s.index>0;){if(r.length===0)throw Error(`Could not recreate Huffman Table`);s=r.pop()}for(s.index++,r.push(s);r.length<=i;)r.push(c={children:[],index:0}),s.children[s.index]=c.children,s=c;n++}i+1<o&&(r.push(c={children:[],index:0}),s.children[s.index]=c.children,s=c)}return r[0].children}function d(t,n,r,i,a,o,s,c,l,u){r.precision,r.samplesPerLine,r.scanLines;var d=r.mcusPerLine,f=r.progressive;r.maxH,r.maxV;var p=n,m=0,h=0;function g(){if(h>0)return h--,m>>h&1;if(m=t[n++],m==255){var e=t[n++];if(e)throw Error(`unexpected marker: `+(m<<8|e).toString(16))}return h=7,m>>>7}function _(e){for(var t=e,n;(n=g())!==null;){if(t=t[n],typeof t==`number`)return t;if(typeof t!=`object`)throw Error(`invalid huffman sequence`)}return null}function v(e){for(var t=0;e>0;){var n=g();if(n===null)return;t=t<<1|n,e--}return t}function y(e){var t=v(e);return t>=1<<e-1?t:t+(-1<<e)+1}function b(t,n){var r=_(t.huffmanTableDC),i=r===0?0:y(r);n[0]=t.pred+=i;for(var a=1;a<64;){var o=_(t.huffmanTableAC),s=o&15,c=o>>4;if(s===0){if(c<15)break;a+=16;continue}a+=c;var l=e[a];n[l]=y(s),a++}}function x(e,t){var n=_(e.huffmanTableDC),r=n===0?0:y(n)<<l;t[0]=e.pred+=r}function S(e,t){t[0]|=g()<<l}var C=0;function w(t,n){if(C>0){C--;return}for(var r=o,i=s;r<=i;){var a=_(t.huffmanTableAC),c=a&15,u=a>>4;if(c===0){if(u<15){C=v(u)+(1<<u)-1;break}r+=16;continue}r+=u;var d=e[r];n[d]=y(c)*(1<<l),r++}}var T=0,E;function D(t,n){for(var r=o,i=s,a=0;r<=i;){var c=e[r],u=n[c]<0?-1:1;switch(T){case 0:var d=_(t.huffmanTableAC),f=d&15,a=d>>4;if(f===0)a<15?(C=v(a)+(1<<a),T=4):(a=16,T=1);else{if(f!==1)throw Error(`invalid ACn encoding`);E=y(f),T=a?2:3}continue;case 1:case 2:n[c]?n[c]+=(g()<<l)*u:(a--,a===0&&(T=T==2?3:0));break;case 3:n[c]?n[c]+=(g()<<l)*u:(n[c]=E<<l,T=0);break;case 4:n[c]&&(n[c]+=(g()<<l)*u)}r++}T===4&&(C--,C===0&&(T=0))}function O(e,t,n,r,i){var a=n/d|0,o=n%d,s=a*e.v+r,c=o*e.h+i;e.blocks[s]===void 0&&u.tolerantDecoding||t(e,e.blocks[s][c])}function k(e,t,n){var r=n/e.blocksPerLine|0,i=n%e.blocksPerLine;e.blocks[r]===void 0&&u.tolerantDecoding||t(e,e.blocks[r][i])}var A=i.length,j,M,N,P,F,I=f?o===0?c===0?x:S:c===0?w:D:b,L=0,R,z=A==1?i[0].blocksPerLine*i[0].blocksPerColumn:d*r.mcusPerColumn;a||=z;for(var B,V;L<z;){for(M=0;M<A;M++)i[M].pred=0;if(C=0,A==1)for(j=i[0],F=0;F<a;F++)k(j,I,L),L++;else for(F=0;F<a;F++){for(M=0;M<A;M++)for(j=i[M],B=j.h,V=j.v,N=0;N<V;N++)for(P=0;P<B;P++)O(j,I,L,N,P);if(L++,L===z)break}if(L===z)do{if(t[n]===255&&t[n+1]!==0)break;n+=1}while(n<t.length-2);if(h=0,R=t[n]<<8|t[n+1],R<65280)throw Error(`marker was not found`);if(R>=65488&&R<=65495)n+=2;else break}return n-p}function f(e,l){var u=[],d=l.blocksPerLine,f=l.blocksPerColumn,p=d<<3,m=new Int32Array(64),h=new Uint8Array(64);function _(e,u,d){var f=l.quantizationTable,p,m,h,g,_,v,y,b,x,S=d,C;for(C=0;C<64;C++)S[C]=e[C]*f[C];for(C=0;C<8;++C){var w=8*C;if(S[1+w]==0&&S[2+w]==0&&S[3+w]==0&&S[4+w]==0&&S[5+w]==0&&S[6+w]==0&&S[7+w]==0){x=s*S[0+w]+512>>10,S[0+w]=x,S[1+w]=x,S[2+w]=x,S[3+w]=x,S[4+w]=x,S[5+w]=x,S[6+w]=x,S[7+w]=x;continue}p=s*S[0+w]+128>>8,m=s*S[4+w]+128>>8,h=S[2+w],g=S[6+w],_=c*(S[1+w]-S[7+w])+128>>8,b=c*(S[1+w]+S[7+w])+128>>8,v=S[3+w]<<4,y=S[5+w]<<4,x=p-m+1>>1,p=p+m+1>>1,m=x,x=h*o+g*a+128>>8,h=h*a-g*o+128>>8,g=x,x=_-y+1>>1,_=_+y+1>>1,y=x,x=b+v+1>>1,v=b-v+1>>1,b=x,x=p-g+1>>1,p=p+g+1>>1,g=x,x=m-h+1>>1,m=m+h+1>>1,h=x,x=_*i+b*r+2048>>12,_=_*r-b*i+2048>>12,b=x,x=v*n+y*t+2048>>12,v=v*t-y*n+2048>>12,y=x,S[0+w]=p+b,S[7+w]=p-b,S[1+w]=m+y,S[6+w]=m-y,S[2+w]=h+v,S[5+w]=h-v,S[3+w]=g+_,S[4+w]=g-_}for(C=0;C<8;++C){var T=C;if(S[8+T]==0&&S[16+T]==0&&S[24+T]==0&&S[32+T]==0&&S[40+T]==0&&S[48+T]==0&&S[56+T]==0){x=s*d[C+0]+8192>>14,S[0+T]=x,S[8+T]=x,S[16+T]=x,S[24+T]=x,S[32+T]=x,S[40+T]=x,S[48+T]=x,S[56+T]=x;continue}p=s*S[0+T]+2048>>12,m=s*S[32+T]+2048>>12,h=S[16+T],g=S[48+T],_=c*(S[8+T]-S[56+T])+2048>>12,b=c*(S[8+T]+S[56+T])+2048>>12,v=S[24+T],y=S[40+T],x=p-m+1>>1,p=p+m+1>>1,m=x,x=h*o+g*a+2048>>12,h=h*a-g*o+2048>>12,g=x,x=_-y+1>>1,_=_+y+1>>1,y=x,x=b+v+1>>1,v=b-v+1>>1,b=x,x=p-g+1>>1,p=p+g+1>>1,g=x,x=m-h+1>>1,m=m+h+1>>1,h=x,x=_*i+b*r+2048>>12,_=_*r-b*i+2048>>12,b=x,x=v*n+y*t+2048>>12,v=v*t-y*n+2048>>12,y=x,S[0+T]=p+b,S[56+T]=p-b,S[8+T]=m+y,S[48+T]=m-y,S[16+T]=h+v,S[40+T]=h-v,S[24+T]=g+_,S[32+T]=g-_}for(C=0;C<64;++C){var E=128+(S[C]+8>>4);u[C]=E<0?0:E>255?255:E}}g(p*f*8);for(var v,y,b=0;b<f;b++){var x=b<<3;for(v=0;v<8;v++)u.push(new Uint8Array(p));for(var S=0;S<d;S++){_(l.blocks[b][S],h,m);var C=0,w=S<<3;for(y=0;y<8;y++){var T=u[x+y];for(v=0;v<8;v++)T[w+v]=h[C++]}}}return u}function p(e){return e<0?0:e>255?255:e}l.prototype={load:function(e){var t=new XMLHttpRequest;t.open(`GET`,e,!0),t.responseType=`arraybuffer`,t.onload=(function(){var e=new Uint8Array(t.response||t.mozResponseArrayBuffer);this.parse(e),this.onload&&this.onload()}).bind(this),t.send(null)},parse:function(t){var n=this.opts.maxResolutionInMP*1e3*1e3,r=0;t.length;function i(){var e=t[r]<<8|t[r+1];return r+=2,e}function a(){var e=i(),n=t.subarray(r,r+e-2);return r+=n.length,n}function o(e){var t=1,n=1,r,i;for(i in e.components)e.components.hasOwnProperty(i)&&(r=e.components[i],t<r.h&&(t=r.h),n<r.v&&(n=r.v));var a=Math.ceil(e.samplesPerLine/8/t),o=Math.ceil(e.scanLines/8/n);for(i in e.components)if(e.components.hasOwnProperty(i)){r=e.components[i];var s=Math.ceil(Math.ceil(e.samplesPerLine/8)*r.h/t),c=Math.ceil(Math.ceil(e.scanLines/8)*r.v/n),l=a*r.h,u=o*r.v,d=u*l,f=[];g(d*256);for(var p=0;p<u;p++){for(var m=[],h=0;h<l;h++)m.push(new Int32Array(64));f.push(m)}r.blocksPerLine=s,r.blocksPerColumn=c,r.blocks=f}e.maxH=t,e.maxV=n,e.mcusPerLine=a,e.mcusPerColumn=o}var s=null,c=null,l,p,m=[],h=[],_=[],v=[],y=i(),b=-1;if(this.comments=[],y!=65496)throw Error(`SOI not found`);for(y=i();y!=65497;){var x,S;switch(y){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var C=a();if(y===65534){var w=String.fromCharCode.apply(null,C);this.comments.push(w)}y===65504&&C[0]===74&&C[1]===70&&C[2]===73&&C[3]===70&&C[4]===0&&(s={version:{major:C[5],minor:C[6]},densityUnits:C[7],xDensity:C[8]<<8|C[9],yDensity:C[10]<<8|C[11],thumbWidth:C[12],thumbHeight:C[13],thumbData:C.subarray(14,14+3*C[12]*C[13])}),y===65505&&C[0]===69&&C[1]===120&&C[2]===105&&C[3]===102&&C[4]===0&&(this.exifBuffer=C.subarray(5,C.length)),y===65518&&C[0]===65&&C[1]===100&&C[2]===111&&C[3]===98&&C[4]===101&&C[5]===0&&(c={version:C[6],flags0:C[7]<<8|C[8],flags1:C[9]<<8|C[10],transformCode:C[11]});break;case 65499:for(var T=i()+r-2;r<T;){var E=t[r++];g(256);var D=new Int32Array(64);if(!(E>>4))for(S=0;S<64;S++){var O=e[S];D[O]=t[r++]}else if(E>>4==1)for(S=0;S<64;S++){var O=e[S];D[O]=i()}else throw Error(`DQT: invalid table spec`);m[E&15]=D}break;case 65472:case 65473:case 65474:i(),l={},l.extended=y===65473,l.progressive=y===65474,l.precision=t[r++],l.scanLines=i(),l.samplesPerLine=i(),l.components={},l.componentsOrder=[];var k=l.scanLines*l.samplesPerLine;if(k>n){var A=Math.ceil((k-n)/1e6);throw Error(`maxResolutionInMP limit exceeded by ${A}MP`)}var j=t[r++],M;for(x=0;x<j;x++){M=t[r];var N=t[r+1]>>4,P=t[r+1]&15,F=t[r+2];if(N<=0||P<=0)throw Error(`Invalid sampling factor, expected values above 0`);l.componentsOrder.push(M),l.components[M]={h:N,v:P,quantizationIdx:F},r+=3}o(l),h.push(l);break;case 65476:var I=i();for(x=2;x<I;){var L=t[r++],R=new Uint8Array(16),z=0;for(S=0;S<16;S++,r++)z+=R[S]=t[r];g(16+z);var B=new Uint8Array(z);for(S=0;S<z;S++,r++)B[S]=t[r];x+=17+z,(L>>4?_:v)[L&15]=u(R,B)}break;case 65501:i(),p=i();break;case 65500:i(),i();break;case 65498:i();var V=t[r++],H=[],U;for(x=0;x<V;x++){U=l.components[t[r++]];var W=t[r++];U.huffmanTableDC=v[W>>4],U.huffmanTableAC=_[W&15],H.push(U)}var G=t[r++],K=t[r++],q=t[r++],J=d(t,r,l,H,p,G,K,q>>4,q&15,this.opts);r+=J;break;case 65535:t[r]!==255&&r--;break;default:if(t[r-3]==255&&t[r-2]>=192&&t[r-2]<=254){r-=3;break}if(y===224||y==225){if(b!==-1)throw Error(`first unknown JPEG marker at offset ${b.toString(16)}, second unknown JPEG marker ${y.toString(16)} at offset ${(r-1).toString(16)}`);b=r-1;let e=i();if(t[r+e-2]===255){r+=e-2;break}}throw Error(`unknown JPEG marker `+y.toString(16))}y=i()}if(h.length!=1)throw Error(`only single frame JPEGs supported`);for(var x=0;x<h.length;x++){var Y=h[x].components;for(var S in Y)Y[S].quantizationTable=m[Y[S].quantizationIdx],delete Y[S].quantizationIdx}this.width=l.samplesPerLine,this.height=l.scanLines,this.jfif=s,this.adobe=c,this.components=[];for(var x=0;x<l.componentsOrder.length;x++){var U=l.components[l.componentsOrder[x]];this.components.push({lines:f(l,U),scaleX:U.h/l.maxH,scaleY:U.v/l.maxV})}},getData:function(e,t){var n=this.width/e,r=this.height/t,i,a,o,s,c,l,u,d,f,m,h=0,_,v,y,b,x,S,C,w,T,E,D,O=e*t*this.components.length;g(O);var k=new Uint8Array(O);switch(this.components.length){case 1:for(i=this.components[0],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],f=0;f<e;f++)_=c[0|f*i.scaleX*n],k[h++]=_;break;case 2:for(i=this.components[0],a=this.components[1],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],f=0;f<e;f++)_=c[0|f*i.scaleX*n],k[h++]=_,_=l[0|f*a.scaleX*n],k[h++]=_;break;case 3:for(D=!0,this.adobe&&this.adobe.transformCode?D=!0:this.opts.colorTransform!==void 0&&(D=!!this.opts.colorTransform),i=this.components[0],a=this.components[1],o=this.components[2],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],u=o.lines[0|m*o.scaleY*r],f=0;f<e;f++)D?(_=c[0|f*i.scaleX*n],v=l[0|f*a.scaleX*n],y=u[0|f*o.scaleX*n],w=p(_+1.402*(y-128)),T=p(_-.3441363*(v-128)-.71413636*(y-128)),E=p(_+1.772*(v-128))):(w=c[0|f*i.scaleX*n],T=l[0|f*a.scaleX*n],E=u[0|f*o.scaleX*n]),k[h++]=w,k[h++]=T,k[h++]=E;break;case 4:if(!this.adobe)throw Error(`Unsupported color mode (4 components)`);for(D=!1,this.adobe&&this.adobe.transformCode?D=!0:this.opts.colorTransform!==void 0&&(D=!!this.opts.colorTransform),i=this.components[0],a=this.components[1],o=this.components[2],s=this.components[3],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],u=o.lines[0|m*o.scaleY*r],d=s.lines[0|m*s.scaleY*r],f=0;f<e;f++)D?(_=c[0|f*i.scaleX*n],v=l[0|f*a.scaleX*n],y=u[0|f*o.scaleX*n],b=d[0|f*s.scaleX*n],x=255-p(_+1.402*(y-128)),S=255-p(_-.3441363*(v-128)-.71413636*(y-128)),C=255-p(_+1.772*(v-128))):(x=c[0|f*i.scaleX*n],S=l[0|f*a.scaleX*n],C=u[0|f*o.scaleX*n],b=d[0|f*s.scaleX*n]),k[h++]=255-x,k[h++]=255-S,k[h++]=255-C,k[h++]=255-b;break;default:throw Error(`Unsupported color mode`)}return k},copyToImageData:function(e,t){var n=e.width,r=e.height,i=e.data,a=this.getData(n,r),o=0,s=0,c,l,u,d,f,m,h,g,_;switch(this.components.length){case 1:for(l=0;l<r;l++)for(c=0;c<n;c++)u=a[o++],i[s++]=u,i[s++]=u,i[s++]=u,t&&(i[s++]=255);break;case 3:for(l=0;l<r;l++)for(c=0;c<n;c++)h=a[o++],g=a[o++],_=a[o++],i[s++]=h,i[s++]=g,i[s++]=_,t&&(i[s++]=255);break;case 4:for(l=0;l<r;l++)for(c=0;c<n;c++)f=a[o++],m=a[o++],u=a[o++],d=a[o++],h=255-p(f*(1-d/255)+d),g=255-p(m*(1-d/255)+d),_=255-p(u*(1-d/255)+d),i[s++]=h,i[s++]=g,i[s++]=_,t&&(i[s++]=255);break;default:throw Error(`Unsupported color mode`)}}};var m=0,h=0;function g(e=0){var t=m+e;if(t>h){var n=Math.ceil((t-h)/1024/1024);throw Error(`maxMemoryUsageInMB limit exceeded by at least ${n}MB`)}m=t}return l.resetMaxMemoryUsage=function(e){m=0,h=e},l.getBytesAllocated=function(){return m},l.requestMemoryAllocation=g,l})();t===void 0?typeof window<`u`&&(window[`jpeg-js`]=window[`jpeg-js`]||{},window[`jpeg-js`].decode=r):t.exports=r;function r(e,t={}){var r={colorTransform:void 0,useTArray:!1,formatAsRGBA:!0,tolerantDecoding:!0,maxResolutionInMP:100,maxMemoryUsageInMB:512,...t},i=new Uint8Array(e),a=new n;a.opts=r,n.resetMaxMemoryUsage(r.maxMemoryUsageInMB*1024*1024),a.parse(i);var o=r.formatAsRGBA?4:3,s=a.width*a.height*o;try{n.requestMemoryAllocation(s);var c={width:a.width,height:a.height,exifBuffer:a.exifBuffer,data:r.useTArray?new Uint8Array(s):Buffer.alloc(s)};a.comments.length>0&&(c.comments=a.comments)}catch(e){throw e instanceof RangeError?Error(`Could not allocate enough memory for the image. Required: `+s):e instanceof ReferenceError&&e.message===`Buffer is not defined`?Error(`Buffer is not globally defined in this environment. Consider setting useTArray to true`):e}return a.copyToImageData(c,r.formatAsRGBA),c}})),c=e(((e,t)=>{t.exports={encode:o(),decode:s()}}))();const l=Buffer.from([255,216,255]);function u(e){if(n(e))return`png`;if(e.subarray(0,l.length).equals(l))return`jpeg`}function d(e,t,n){a(e,t,n);let r=u(e);if(r===`png`)return i(e,t);if(r===`jpeg`)return f(e,t,n);throw p(t,e)}function f(e,n,i){try{let t=(0,c.decode)(e,{useTArray:!0,formatAsRGBA:!0,...i!=null&&i>0?{maxResolutionInMP:(Math.floor(i)+.5)/1e6}:{}}),n=new r.PNG({width:t.width,height:t.height});return n.data=Buffer.from(t.data.buffer,t.data.byteOffset,t.data.byteLength),n}catch(e){throw new t(`COMMAND_FAILED`,`Failed to decode ${n} as JPEG`,{label:n,reason:e instanceof Error?e.message:String(e)})}}function p(e,n){return new t(`COMMAND_FAILED`,`${e} is neither PNG nor JPEG`,{label:e,leadingBytes:n.subarray(0,4).toString(`hex`)})}export{d as decodeScreenshotImage};
1
+ import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{n,r,t as i}from"./png.js";import{validateScreenshotImagePixels as a}from"./screenshot-image-size.js";var o=e(((e,t)=>{function n(e){var n=Math.floor,r=Array(64),i=Array(64),a=Array(64),o=Array(64),s,c,l,u,d=Array(65535),f=Array(65535),p=Array(64),m=Array(64),h=[],g=0,_=7,v=Array(64),y=Array(64),b=Array(64),x=Array(256),S=Array(2048),C,w=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],T=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],E=[0,1,2,3,4,5,6,7,8,9,10,11],D=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],O=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],k=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],A=[0,1,2,3,4,5,6,7,8,9,10,11],j=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],M=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function N(e){for(var t=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],s=0;s<64;s++){var c=n((t[s]*e+50)/100);c<1?c=1:c>255&&(c=255),r[w[s]]=c}for(var l=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],u=0;u<64;u++){var d=n((l[u]*e+50)/100);d<1?d=1:d>255&&(d=255),i[w[u]]=d}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],p=0,m=0;m<8;m++)for(var h=0;h<8;h++)a[p]=1/(r[w[p]]*f[m]*f[h]*8),o[p]=1/(i[w[p]]*f[m]*f[h]*8),p++}function P(e,t){for(var n=0,r=0,i=[],a=1;a<=16;a++){for(var o=1;o<=e[a];o++)i[t[r]]=[],i[t[r]][0]=n,i[t[r]][1]=a,r++,n++;n*=2}return i}function F(){s=P(T,E),c=P(k,A),l=P(D,O),u=P(j,M)}function I(){for(var e=1,t=2,n=1;n<=15;n++){for(var r=e;r<t;r++)f[32767+r]=n,d[32767+r]=[],d[32767+r][1]=n,d[32767+r][0]=r;for(var i=-(t-1);i<=-e;i++)f[32767+i]=n,d[32767+i]=[],d[32767+i][1]=n,d[32767+i][0]=t-1+i;e<<=1,t<<=1}}function L(){for(var e=0;e<256;e++)S[e]=19595*e,S[e+256>>0]=38470*e,S[e+512>>0]=7471*e+32768,S[e+768>>0]=-11059*e,S[e+1024>>0]=-21709*e,S[e+1280>>0]=32768*e+8421375,S[e+1536>>0]=-27439*e,S[e+1792>>0]=-5329*e}function R(e){for(var t=e[0],n=e[1]-1;n>=0;)t&1<<n&&(g|=1<<_),n--,_--,_<0&&(g==255?(z(255),z(0)):z(g),_=7,g=0)}function z(e){h.push(e)}function B(e){z(e>>8&255),z(e&255)}function V(e,t){var n,r,i,a,o,s,c,l,u=0,d,f=8,m=64;for(d=0;d<f;++d){n=e[u],r=e[u+1],i=e[u+2],a=e[u+3],o=e[u+4],s=e[u+5],c=e[u+6],l=e[u+7];var h=n+l,g=n-l,_=r+c,v=r-c,y=i+s,b=i-s,x=a+o,S=a-o,C=h+x,w=h-x,T=_+y,E=_-y;e[u]=C+T,e[u+4]=C-T;var D=(E+w)*.707106781;e[u+2]=w+D,e[u+6]=w-D,C=S+b,T=b+v,E=v+g;var O=(C-E)*.382683433,k=.5411961*C+O,A=1.306562965*E+O,j=T*.707106781,M=g+j,N=g-j;e[u+5]=N+k,e[u+3]=N-k,e[u+1]=M+A,e[u+7]=M-A,u+=8}for(u=0,d=0;d<f;++d){n=e[u],r=e[u+8],i=e[u+16],a=e[u+24],o=e[u+32],s=e[u+40],c=e[u+48],l=e[u+56];var P=n+l,F=n-l,I=r+c,L=r-c,R=i+s,z=i-s,B=a+o,V=a-o,H=P+B,U=P-B,W=I+R,G=I-R;e[u]=H+W,e[u+32]=H-W;var K=(G+U)*.707106781;e[u+16]=U+K,e[u+48]=U-K,H=V+z,W=z+L,G=L+F;var q=(H-G)*.382683433,J=.5411961*H+q,Y=1.306562965*G+q,X=W*.707106781,Z=F+X,Q=F-X;e[u+40]=Q+J,e[u+24]=Q-J,e[u+8]=Z+Y,e[u+56]=Z-Y,u++}var $;for(d=0;d<m;++d)$=e[d]*t[d],p[d]=$>0?$+.5|0:$-.5|0;return p}function H(){B(65504),B(16),z(74),z(70),z(73),z(70),z(0),z(1),z(1),z(0),B(1),B(1),z(0),z(0)}function U(e){if(e){B(65505),e[0]===69&&e[1]===120&&e[2]===105&&e[3]===102?B(e.length+2):(B(e.length+5+2),z(69),z(120),z(105),z(102),z(0));for(var t=0;t<e.length;t++)z(e[t])}}function W(e,t){B(65472),B(17),z(8),B(t),B(e),z(3),z(1),z(17),z(0),z(2),z(17),z(1),z(3),z(17),z(1)}function G(){B(65499),B(132),z(0);for(var e=0;e<64;e++)z(r[e]);z(1);for(var t=0;t<64;t++)z(i[t])}function K(){B(65476),B(418),z(0);for(var e=0;e<16;e++)z(T[e+1]);for(var t=0;t<=11;t++)z(E[t]);z(16);for(var n=0;n<16;n++)z(D[n+1]);for(var r=0;r<=161;r++)z(O[r]);z(1);for(var i=0;i<16;i++)z(k[i+1]);for(var a=0;a<=11;a++)z(A[a]);z(17);for(var o=0;o<16;o++)z(j[o+1]);for(var s=0;s<=161;s++)z(M[s])}function q(e){e!==void 0&&e.constructor===Array&&e.forEach(e=>{if(typeof e==`string`){B(65534);var t=e.length;B(t+2);var n;for(n=0;n<t;n++)z(e.charCodeAt(n))}})}function J(){B(65498),B(12),z(3),z(1),z(0),z(2),z(17),z(3),z(17),z(0),z(63),z(0)}function Y(e,t,n,r,i){for(var a=i[0],o=i[240],s,c=16,l=63,u=64,p=V(e,t),h=0;h<u;++h)m[w[h]]=p[h];var g=m[0]-n;n=m[0],g==0?R(r[0]):(s=32767+g,R(r[f[s]]),R(d[s]));for(var _=63;_>0&&m[_]==0;_--);if(_==0)return R(a),n;for(var v=1,y;v<=_;){for(var b=v;m[v]==0&&v<=_;++v);var x=v-b;if(x>=c){y=x>>4;for(var S=1;S<=y;++S)R(o);x&=15}s=32767+m[v],R(i[(x<<4)+f[s]]),R(d[s]),v++}return _!=l&&R(a),n}function X(){for(var e=String.fromCharCode,t=0;t<256;t++)x[t]=e(t)}this.encode=function(e,n){new Date().getTime(),n&&Z(n),h=[],g=0,_=7,B(65496),H(),q(e.comments),U(e.exifBuffer),G(),W(e.width,e.height),K(),J();var r=0,i=0,d=0;g=0,_=7,this.encode.displayName=`_encode_`;var f=e.data,p=e.width,m=e.height,x=p*4;p*3;for(var C,w=0,T,E,D,O,k,A,j,M;w<m;){for(C=0;C<x;){for(O=x*w+C,k=O,A=-1,j=0,M=0;M<64;M++)j=M>>3,A=(M&7)*4,k=O+j*x+A,w+j>=m&&(k-=x*(w+1+j-m)),C+A>=x&&(k-=C+A-x+4),T=f[k++],E=f[k++],D=f[k++],v[M]=(S[T]+S[E+256>>0]+S[D+512>>0]>>16)-128,y[M]=(S[T+768>>0]+S[E+1024>>0]+S[D+1280>>0]>>16)-128,b[M]=(S[T+1280>>0]+S[E+1536>>0]+S[D+1792>>0]>>16)-128;r=Y(v,a,r,s,l),i=Y(y,o,i,c,u),d=Y(b,o,d,c,u),C+=32}w+=8}if(_>=0){var N=[];N[1]=_+1,N[0]=(1<<_+1)-1,R(N)}return B(65497),t===void 0?new Uint8Array(h):Buffer.from(h)};function Z(e){if(e<=0&&(e=1),e>100&&(e=100),C!=e){var t=0;t=Math.floor(e<50?5e3/e:200-e*2),N(t),C=e}}function Q(){var t=new Date().getTime();e||=50,X(),F(),I(),L(),Z(e),new Date().getTime()-t}Q()}t===void 0?typeof window<`u`&&(window[`jpeg-js`]=window[`jpeg-js`]||{},window[`jpeg-js`].encode=r):t.exports=r;function r(e,t){return t===void 0&&(t=50),{data:new n(t).encode(e,t),width:e.width,height:e.height}}})),s=e(((e,t)=>{var n=(function(){var e=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),t=4017,n=799,r=3406,i=2276,a=1567,o=3784,s=5793,c=2896;function l(){}function u(e,t){for(var n=0,r=[],i,a,o=16;o>0&&!e[o-1];)o--;r.push({children:[],index:0});var s=r[0],c;for(i=0;i<o;i++){for(a=0;a<e[i];a++){for(s=r.pop(),s.children[s.index]=t[n];s.index>0;){if(r.length===0)throw Error(`Could not recreate Huffman Table`);s=r.pop()}for(s.index++,r.push(s);r.length<=i;)r.push(c={children:[],index:0}),s.children[s.index]=c.children,s=c;n++}i+1<o&&(r.push(c={children:[],index:0}),s.children[s.index]=c.children,s=c)}return r[0].children}function d(t,n,r,i,a,o,s,c,l,u){r.precision,r.samplesPerLine,r.scanLines;var d=r.mcusPerLine,f=r.progressive;r.maxH,r.maxV;var p=n,m=0,h=0;function g(){if(h>0)return h--,m>>h&1;if(m=t[n++],m==255){var e=t[n++];if(e)throw Error(`unexpected marker: `+(m<<8|e).toString(16))}return h=7,m>>>7}function _(e){for(var t=e,n;(n=g())!==null;){if(t=t[n],typeof t==`number`)return t;if(typeof t!=`object`)throw Error(`invalid huffman sequence`)}return null}function v(e){for(var t=0;e>0;){var n=g();if(n===null)return;t=t<<1|n,e--}return t}function y(e){var t=v(e);return t>=1<<e-1?t:t+(-1<<e)+1}function b(t,n){var r=_(t.huffmanTableDC),i=r===0?0:y(r);n[0]=t.pred+=i;for(var a=1;a<64;){var o=_(t.huffmanTableAC),s=o&15,c=o>>4;if(s===0){if(c<15)break;a+=16;continue}a+=c;var l=e[a];n[l]=y(s),a++}}function x(e,t){var n=_(e.huffmanTableDC),r=n===0?0:y(n)<<l;t[0]=e.pred+=r}function S(e,t){t[0]|=g()<<l}var C=0;function w(t,n){if(C>0){C--;return}for(var r=o,i=s;r<=i;){var a=_(t.huffmanTableAC),c=a&15,u=a>>4;if(c===0){if(u<15){C=v(u)+(1<<u)-1;break}r+=16;continue}r+=u;var d=e[r];n[d]=y(c)*(1<<l),r++}}var T=0,E;function D(t,n){for(var r=o,i=s,a=0;r<=i;){var c=e[r],u=n[c]<0?-1:1;switch(T){case 0:var d=_(t.huffmanTableAC),f=d&15,a=d>>4;if(f===0)a<15?(C=v(a)+(1<<a),T=4):(a=16,T=1);else{if(f!==1)throw Error(`invalid ACn encoding`);E=y(f),T=a?2:3}continue;case 1:case 2:n[c]?n[c]+=(g()<<l)*u:(a--,a===0&&(T=T==2?3:0));break;case 3:n[c]?n[c]+=(g()<<l)*u:(n[c]=E<<l,T=0);break;case 4:n[c]&&(n[c]+=(g()<<l)*u)}r++}T===4&&(C--,C===0&&(T=0))}function O(e,t,n,r,i){var a=n/d|0,o=n%d,s=a*e.v+r,c=o*e.h+i;e.blocks[s]===void 0&&u.tolerantDecoding||t(e,e.blocks[s][c])}function k(e,t,n){var r=n/e.blocksPerLine|0,i=n%e.blocksPerLine;e.blocks[r]===void 0&&u.tolerantDecoding||t(e,e.blocks[r][i])}var A=i.length,j,M,N,P,F,I=f?o===0?c===0?x:S:c===0?w:D:b,L=0,R,z=A==1?i[0].blocksPerLine*i[0].blocksPerColumn:d*r.mcusPerColumn;a||=z;for(var B,V;L<z;){for(M=0;M<A;M++)i[M].pred=0;if(C=0,A==1)for(j=i[0],F=0;F<a;F++)k(j,I,L),L++;else for(F=0;F<a;F++){for(M=0;M<A;M++)for(j=i[M],B=j.h,V=j.v,N=0;N<V;N++)for(P=0;P<B;P++)O(j,I,L,N,P);if(L++,L===z)break}if(L===z)do{if(t[n]===255&&t[n+1]!==0)break;n+=1}while(n<t.length-2);if(h=0,R=t[n]<<8|t[n+1],R<65280)throw Error(`marker was not found`);if(R>=65488&&R<=65495)n+=2;else break}return n-p}function f(e,l){var u=[],d=l.blocksPerLine,f=l.blocksPerColumn,p=d<<3,m=new Int32Array(64),h=new Uint8Array(64);function _(e,u,d){var f=l.quantizationTable,p,m,h,g,_,v,y,b,x,S=d,C;for(C=0;C<64;C++)S[C]=e[C]*f[C];for(C=0;C<8;++C){var w=8*C;if(S[1+w]==0&&S[2+w]==0&&S[3+w]==0&&S[4+w]==0&&S[5+w]==0&&S[6+w]==0&&S[7+w]==0){x=s*S[0+w]+512>>10,S[0+w]=x,S[1+w]=x,S[2+w]=x,S[3+w]=x,S[4+w]=x,S[5+w]=x,S[6+w]=x,S[7+w]=x;continue}p=s*S[0+w]+128>>8,m=s*S[4+w]+128>>8,h=S[2+w],g=S[6+w],_=c*(S[1+w]-S[7+w])+128>>8,b=c*(S[1+w]+S[7+w])+128>>8,v=S[3+w]<<4,y=S[5+w]<<4,x=p-m+1>>1,p=p+m+1>>1,m=x,x=h*o+g*a+128>>8,h=h*a-g*o+128>>8,g=x,x=_-y+1>>1,_=_+y+1>>1,y=x,x=b+v+1>>1,v=b-v+1>>1,b=x,x=p-g+1>>1,p=p+g+1>>1,g=x,x=m-h+1>>1,m=m+h+1>>1,h=x,x=_*i+b*r+2048>>12,_=_*r-b*i+2048>>12,b=x,x=v*n+y*t+2048>>12,v=v*t-y*n+2048>>12,y=x,S[0+w]=p+b,S[7+w]=p-b,S[1+w]=m+y,S[6+w]=m-y,S[2+w]=h+v,S[5+w]=h-v,S[3+w]=g+_,S[4+w]=g-_}for(C=0;C<8;++C){var T=C;if(S[8+T]==0&&S[16+T]==0&&S[24+T]==0&&S[32+T]==0&&S[40+T]==0&&S[48+T]==0&&S[56+T]==0){x=s*d[C+0]+8192>>14,S[0+T]=x,S[8+T]=x,S[16+T]=x,S[24+T]=x,S[32+T]=x,S[40+T]=x,S[48+T]=x,S[56+T]=x;continue}p=s*S[0+T]+2048>>12,m=s*S[32+T]+2048>>12,h=S[16+T],g=S[48+T],_=c*(S[8+T]-S[56+T])+2048>>12,b=c*(S[8+T]+S[56+T])+2048>>12,v=S[24+T],y=S[40+T],x=p-m+1>>1,p=p+m+1>>1,m=x,x=h*o+g*a+2048>>12,h=h*a-g*o+2048>>12,g=x,x=_-y+1>>1,_=_+y+1>>1,y=x,x=b+v+1>>1,v=b-v+1>>1,b=x,x=p-g+1>>1,p=p+g+1>>1,g=x,x=m-h+1>>1,m=m+h+1>>1,h=x,x=_*i+b*r+2048>>12,_=_*r-b*i+2048>>12,b=x,x=v*n+y*t+2048>>12,v=v*t-y*n+2048>>12,y=x,S[0+T]=p+b,S[56+T]=p-b,S[8+T]=m+y,S[48+T]=m-y,S[16+T]=h+v,S[40+T]=h-v,S[24+T]=g+_,S[32+T]=g-_}for(C=0;C<64;++C){var E=128+(S[C]+8>>4);u[C]=E<0?0:E>255?255:E}}g(p*f*8);for(var v,y,b=0;b<f;b++){var x=b<<3;for(v=0;v<8;v++)u.push(new Uint8Array(p));for(var S=0;S<d;S++){_(l.blocks[b][S],h,m);var C=0,w=S<<3;for(y=0;y<8;y++){var T=u[x+y];for(v=0;v<8;v++)T[w+v]=h[C++]}}}return u}function p(e){return e<0?0:e>255?255:e}l.prototype={load:function(e){var t=new XMLHttpRequest;t.open(`GET`,e,!0),t.responseType=`arraybuffer`,t.onload=(function(){var e=new Uint8Array(t.response||t.mozResponseArrayBuffer);this.parse(e),this.onload&&this.onload()}).bind(this),t.send(null)},parse:function(t){var n=this.opts.maxResolutionInMP*1e3*1e3,r=0;t.length;function i(){var e=t[r]<<8|t[r+1];return r+=2,e}function a(){var e=i(),n=t.subarray(r,r+e-2);return r+=n.length,n}function o(e){var t=1,n=1,r,i;for(i in e.components)e.components.hasOwnProperty(i)&&(r=e.components[i],t<r.h&&(t=r.h),n<r.v&&(n=r.v));var a=Math.ceil(e.samplesPerLine/8/t),o=Math.ceil(e.scanLines/8/n);for(i in e.components)if(e.components.hasOwnProperty(i)){r=e.components[i];var s=Math.ceil(Math.ceil(e.samplesPerLine/8)*r.h/t),c=Math.ceil(Math.ceil(e.scanLines/8)*r.v/n),l=a*r.h,u=o*r.v,d=u*l,f=[];g(d*256);for(var p=0;p<u;p++){for(var m=[],h=0;h<l;h++)m.push(new Int32Array(64));f.push(m)}r.blocksPerLine=s,r.blocksPerColumn=c,r.blocks=f}e.maxH=t,e.maxV=n,e.mcusPerLine=a,e.mcusPerColumn=o}var s=null,c=null,l,p,m=[],h=[],_=[],v=[],y=i(),b=-1;if(this.comments=[],y!=65496)throw Error(`SOI not found`);for(y=i();y!=65497;){var x,S;switch(y){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var C=a();if(y===65534){var w=String.fromCharCode.apply(null,C);this.comments.push(w)}y===65504&&C[0]===74&&C[1]===70&&C[2]===73&&C[3]===70&&C[4]===0&&(s={version:{major:C[5],minor:C[6]},densityUnits:C[7],xDensity:C[8]<<8|C[9],yDensity:C[10]<<8|C[11],thumbWidth:C[12],thumbHeight:C[13],thumbData:C.subarray(14,14+3*C[12]*C[13])}),y===65505&&C[0]===69&&C[1]===120&&C[2]===105&&C[3]===102&&C[4]===0&&(this.exifBuffer=C.subarray(5,C.length)),y===65518&&C[0]===65&&C[1]===100&&C[2]===111&&C[3]===98&&C[4]===101&&C[5]===0&&(c={version:C[6],flags0:C[7]<<8|C[8],flags1:C[9]<<8|C[10],transformCode:C[11]});break;case 65499:for(var T=i()+r-2;r<T;){var E=t[r++];g(256);var D=new Int32Array(64);if(!(E>>4))for(S=0;S<64;S++){var O=e[S];D[O]=t[r++]}else if(E>>4==1)for(S=0;S<64;S++){var O=e[S];D[O]=i()}else throw Error(`DQT: invalid table spec`);m[E&15]=D}break;case 65472:case 65473:case 65474:i(),l={},l.extended=y===65473,l.progressive=y===65474,l.precision=t[r++],l.scanLines=i(),l.samplesPerLine=i(),l.components={},l.componentsOrder=[];var k=l.scanLines*l.samplesPerLine;if(k>n){var A=Math.ceil((k-n)/1e6);throw Error(`maxResolutionInMP limit exceeded by ${A}MP`)}var j=t[r++],M;for(x=0;x<j;x++){M=t[r];var N=t[r+1]>>4,P=t[r+1]&15,F=t[r+2];if(N<=0||P<=0)throw Error(`Invalid sampling factor, expected values above 0`);l.componentsOrder.push(M),l.components[M]={h:N,v:P,quantizationIdx:F},r+=3}o(l),h.push(l);break;case 65476:var I=i();for(x=2;x<I;){var L=t[r++],R=new Uint8Array(16),z=0;for(S=0;S<16;S++,r++)z+=R[S]=t[r];g(16+z);var B=new Uint8Array(z);for(S=0;S<z;S++,r++)B[S]=t[r];x+=17+z,(L>>4?_:v)[L&15]=u(R,B)}break;case 65501:i(),p=i();break;case 65500:i(),i();break;case 65498:i();var V=t[r++],H=[],U;for(x=0;x<V;x++){U=l.components[t[r++]];var W=t[r++];U.huffmanTableDC=v[W>>4],U.huffmanTableAC=_[W&15],H.push(U)}var G=t[r++],K=t[r++],q=t[r++],J=d(t,r,l,H,p,G,K,q>>4,q&15,this.opts);r+=J;break;case 65535:t[r]!==255&&r--;break;default:if(t[r-3]==255&&t[r-2]>=192&&t[r-2]<=254){r-=3;break}if(y===224||y==225){if(b!==-1)throw Error(`first unknown JPEG marker at offset ${b.toString(16)}, second unknown JPEG marker ${y.toString(16)} at offset ${(r-1).toString(16)}`);b=r-1;let e=i();if(t[r+e-2]===255){r+=e-2;break}}throw Error(`unknown JPEG marker `+y.toString(16))}y=i()}if(h.length!=1)throw Error(`only single frame JPEGs supported`);for(var x=0;x<h.length;x++){var Y=h[x].components;for(var S in Y)Y[S].quantizationTable=m[Y[S].quantizationIdx],delete Y[S].quantizationIdx}this.width=l.samplesPerLine,this.height=l.scanLines,this.jfif=s,this.adobe=c,this.components=[];for(var x=0;x<l.componentsOrder.length;x++){var U=l.components[l.componentsOrder[x]];this.components.push({lines:f(l,U),scaleX:U.h/l.maxH,scaleY:U.v/l.maxV})}},getData:function(e,t){var n=this.width/e,r=this.height/t,i,a,o,s,c,l,u,d,f,m,h=0,_,v,y,b,x,S,C,w,T,E,D,O=e*t*this.components.length;g(O);var k=new Uint8Array(O);switch(this.components.length){case 1:for(i=this.components[0],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],f=0;f<e;f++)_=c[0|f*i.scaleX*n],k[h++]=_;break;case 2:for(i=this.components[0],a=this.components[1],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],f=0;f<e;f++)_=c[0|f*i.scaleX*n],k[h++]=_,_=l[0|f*a.scaleX*n],k[h++]=_;break;case 3:for(D=!0,this.adobe&&this.adobe.transformCode?D=!0:this.opts.colorTransform!==void 0&&(D=!!this.opts.colorTransform),i=this.components[0],a=this.components[1],o=this.components[2],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],u=o.lines[0|m*o.scaleY*r],f=0;f<e;f++)D?(_=c[0|f*i.scaleX*n],v=l[0|f*a.scaleX*n],y=u[0|f*o.scaleX*n],w=p(_+1.402*(y-128)),T=p(_-.3441363*(v-128)-.71413636*(y-128)),E=p(_+1.772*(v-128))):(w=c[0|f*i.scaleX*n],T=l[0|f*a.scaleX*n],E=u[0|f*o.scaleX*n]),k[h++]=w,k[h++]=T,k[h++]=E;break;case 4:if(!this.adobe)throw Error(`Unsupported color mode (4 components)`);for(D=!1,this.adobe&&this.adobe.transformCode?D=!0:this.opts.colorTransform!==void 0&&(D=!!this.opts.colorTransform),i=this.components[0],a=this.components[1],o=this.components[2],s=this.components[3],m=0;m<t;m++)for(c=i.lines[0|m*i.scaleY*r],l=a.lines[0|m*a.scaleY*r],u=o.lines[0|m*o.scaleY*r],d=s.lines[0|m*s.scaleY*r],f=0;f<e;f++)D?(_=c[0|f*i.scaleX*n],v=l[0|f*a.scaleX*n],y=u[0|f*o.scaleX*n],b=d[0|f*s.scaleX*n],x=255-p(_+1.402*(y-128)),S=255-p(_-.3441363*(v-128)-.71413636*(y-128)),C=255-p(_+1.772*(v-128))):(x=c[0|f*i.scaleX*n],S=l[0|f*a.scaleX*n],C=u[0|f*o.scaleX*n],b=d[0|f*s.scaleX*n]),k[h++]=255-x,k[h++]=255-S,k[h++]=255-C,k[h++]=255-b;break;default:throw Error(`Unsupported color mode`)}return k},copyToImageData:function(e,t){var n=e.width,r=e.height,i=e.data,a=this.getData(n,r),o=0,s=0,c,l,u,d,f,m,h,g,_;switch(this.components.length){case 1:for(l=0;l<r;l++)for(c=0;c<n;c++)u=a[o++],i[s++]=u,i[s++]=u,i[s++]=u,t&&(i[s++]=255);break;case 3:for(l=0;l<r;l++)for(c=0;c<n;c++)h=a[o++],g=a[o++],_=a[o++],i[s++]=h,i[s++]=g,i[s++]=_,t&&(i[s++]=255);break;case 4:for(l=0;l<r;l++)for(c=0;c<n;c++)f=a[o++],m=a[o++],u=a[o++],d=a[o++],h=255-p(f*(1-d/255)+d),g=255-p(m*(1-d/255)+d),_=255-p(u*(1-d/255)+d),i[s++]=h,i[s++]=g,i[s++]=_,t&&(i[s++]=255);break;default:throw Error(`Unsupported color mode`)}}};var m=0,h=0;function g(e=0){var t=m+e;if(t>h){var n=Math.ceil((t-h)/1024/1024);throw Error(`maxMemoryUsageInMB limit exceeded by at least ${n}MB`)}m=t}return l.resetMaxMemoryUsage=function(e){m=0,h=e},l.getBytesAllocated=function(){return m},l.requestMemoryAllocation=g,l})();t===void 0?typeof window<`u`&&(window[`jpeg-js`]=window[`jpeg-js`]||{},window[`jpeg-js`].decode=r):t.exports=r;function r(e,t={}){var r={colorTransform:void 0,useTArray:!1,formatAsRGBA:!0,tolerantDecoding:!0,maxResolutionInMP:100,maxMemoryUsageInMB:512,...t},i=new Uint8Array(e),a=new n;a.opts=r,n.resetMaxMemoryUsage(r.maxMemoryUsageInMB*1024*1024),a.parse(i);var o=r.formatAsRGBA?4:3,s=a.width*a.height*o;try{n.requestMemoryAllocation(s);var c={width:a.width,height:a.height,exifBuffer:a.exifBuffer,data:r.useTArray?new Uint8Array(s):Buffer.alloc(s)};a.comments.length>0&&(c.comments=a.comments)}catch(e){throw e instanceof RangeError?Error(`Could not allocate enough memory for the image. Required: `+s):e instanceof ReferenceError&&e.message===`Buffer is not defined`?Error(`Buffer is not globally defined in this environment. Consider setting useTArray to true`):e}return a.copyToImageData(c,r.formatAsRGBA),c}})),c=e(((e,t)=>{t.exports={encode:o(),decode:s()}}))();const l=Buffer.from([255,216,255]);function u(e){if(n(e))return`png`;if(e.subarray(0,l.length).equals(l))return`jpeg`}function d(e,t,n){a(e,t,n);let r=u(e);if(r===`png`)return i(e,t);if(r===`jpeg`)return f(e,t,n);throw p(t,e)}function f(e,n,i){try{let t=(0,c.decode)(e,{useTArray:!0,formatAsRGBA:!0,...i!=null&&i>0?{maxResolutionInMP:(Math.floor(i)+.5)/1e6}:{}}),n=new r.PNG({width:t.width,height:t.height});return n.data=Buffer.from(t.data.buffer,t.data.byteOffset,t.data.byteLength),n}catch(e){throw new t(`COMMAND_FAILED`,`Failed to decode ${n} as JPEG`,{label:n,reason:e instanceof Error?e.message:String(e)})}}function p(e,n){return new t(`COMMAND_FAILED`,`${e} is neither PNG nor JPEG`,{label:e,leadingBytes:n.subarray(0,4).toString(`hex`)})}export{d as decodeScreenshotImage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime.js";import{C as t,P as n,q as r,s as i}from"./sdk-contracts.js";import{f as a,h as o,i as s,n as c,p as l}from"./screenshot.js";import"./capture.js";import{pt as u,yt as d}from"./sdk-io.js";import"./diagnostics.js";import{B as f,L as p,w as m}from"./sdk-device.js";import{Di as h,Ii as g,In as _,Ni as v,Pi as y,ci as ee,ei as b,ki as x,oi as S,rn as te,si as C,ui as ne}from"./sdk-batch.js";import"./file.js";import{t as w}from"./session-paths.js";import{t as T}from"./snapshot-state.js";import{n as E}from"./snapshot-runtime-capture-input.js";import{n as re}from"./context.js";import{i as ie,t as ae}from"./selector-pipeline-policy.js";import{i as oe,o as se,r as ce}from"./png-worker-client.js";import{t as le}from"./react-native-overlay2.js";import{t as ue}from"./command-policy.js";import{t as de}from"./png-size.js";import{a as D,o as O,s as k,t as fe}from"./screenshot-overlay-draw.js";import{f as pe,i as A,n as me}from"./runtime-session.js";import{a as he,i as ge,n as _e,t as ve}from"./session-runtime-admission.js";import{r as ye,t as be}from"./screenshot-density.js";import{promises as j}from"node:fs";import M from"node:os";import N from"node:path";function xe(e,t){return{resolveInput:async()=>{throw new n(`UNSUPPORTED_OPERATION`,`screenshot does not resolve input artifacts`)},reserveOutput:async r=>{try{let n,i;return r?.kind===`path`?i=r.path:(n=await j.mkdtemp(N.join(M.tmpdir(),`agent-device-screenshot-`)),i=N.join(n,`screenshot.png`)),await j.mkdir(N.dirname(i),{recursive:!0}),e&&r?.kind===`path`?await Se(i,t):{path:i,visibility:`client-visible`,publish:async()=>{e&&t?.throwIfAborted()},...n?{cleanup:async()=>{await j.rm(n,{recursive:!0,force:!0})}}:{}}}catch(e){throw e instanceof n?e:P(e,r?.kind===`path`?r.path:`(temporary screenshot)`)}},createTempFile:async e=>{let t=await j.mkdtemp(N.join(M.tmpdir(),`${e.prefix}-`));return{path:N.join(t,`file${e.ext}`),visibility:`internal`,cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}}}}function P(e,t){return new n(`COMMAND_FAILED`,`Failed to publish screenshot`,{reason:`screenshot_publication_failed`,path:t,...e instanceof Error&&`code`in e?{filesystemCode:e.code}:{},cause:r(e)})}async function Se(e,t){let n=await Ce(e),i=await j.mkdtemp(N.join(M.tmpdir(),`agent-device-crop-`)),a=N.join(i,`screenshot${N.extname(e)||`.png`}`),o=async()=>{await j.rm(i,{recursive:!0,force:!0}).catch(e=>{d({level:`warn`,phase:`screenshot_crop_cleanup_failed`,data:{tempRoot:i,error:r(e)}})})};return{path:a,publishedPath:e,visibility:`client-visible`,publish:async()=>{try{let e=await j.readFile(a);t?.throwIfAborted(),u({destination:n,contents:e,preserveExistingMode:!0})}catch(n){throw t?.aborted?t.reason:P(n,e)}await o()},cleanup:o}}async function Ce(e){let t;try{t=(await j.lstat(e).catch(e=>{if(e.code!==`ENOENT`)throw e}))?.isSymbolicLink()?await j.realpath(e).catch(t=>{throw t.code===`ENOENT`?new n(`INVALID_ARGS`,`Screenshot destination is a dangling symbolic link`,{reason:`screenshot_destination_dangling_symlink`,path:e}):t}):e;let r=await j.stat(t).catch(e=>{if(e.code!==`ENOENT`)throw e});if(r&&!r.isFile())throw new n(`INVALID_ARGS`,`Screenshot destination must be a regular file`,{reason:`screenshot_destination_not_file`,path:e})}catch(t){throw t instanceof n?t:P(t,e)}return t}const F=s.pendingPixelIdentityEvidence,we=[{target:`ios-simulator`,status:`accepted`},{target:`android-emulator`,status:`accepted`},{target:`android-device`,status:`rejected`,rejectionReason:F},{target:`macos-app-window`,status:`rejected`,rejectionReason:F},{target:`ios-physical`,status:`accepted`},{target:`ios-physical-xctest`,status:`rejected`,rejectionReason:F},{target:`ipados-physical`,status:`rejected`,rejectionReason:F},{target:`macos-helper`,status:`rejected`,rejectionReason:F},{target:`web`,status:`rejected`,rejectionReason:F},{target:`linux`,status:`rejected`,rejectionReason:F},{target:`tvos`,status:`rejected`,rejectionReason:F},{target:`harmonyos`,status:`rejected`,rejectionReason:F},{target:`vega`,status:`rejected`,rejectionReason:F}];function I(e,t){switch(e.platform){case`apple`:return Te(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 Te(e,t){let n=f(e);switch(n){case`ios`:return e.kind===`device`?e.iosPhysicalDeviceBackend===`xctest`?`ios-physical-xctest`:`ios-physical`:`ios-simulator`;case`ipados`:return e.kind===`device`?`ipados-physical`:`ios-simulator`;case`tvos`:return`tvos`;case`macos`:return Ee(t);case`watchos`:case`visionos`:throw L(n)}}function Ee(e){return(e??`app`)===`app`?`macos-app-window`:`macos-helper`}function L(e,t){return new n(`UNSUPPORTED_OPERATION`,`screenshot --crop-on is not accepted on ${e} targets`,{reason:s.targetNotAccepted,...t?{rejectionReason:t}:{}})}function De(e){if(e.overlayRefs||e.fullscreen)throw new n(`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:s.frameMismatch});try{_(e.cropOn)}catch{throw new n(`INVALID_ARGS`,`screenshot --crop-on requires a valid selector expression`,{reason:s.selectorInvalid})}let t=I(e.device,e.surface),r=we.find(e=>e.target===t);if(!r||r.status===`rejected`)throw L(t,r?.status===`rejected`?r.rejectionReason:void 0)}function Oe(e,t){if(I(e,void 0)===`ios-physical`&&t.iosPhysicalCaptureBackend!==`coredevice`)throw L(`ios-physical-non-coredevice-capture`,F)}async function ke(e,t){if(!Ae(t))throw new n(`INVALID_ARGS`,`Screenshot crop box must be positive integer pixel offsets`);let r=await ce(await j.readFile(e),t,`screenshot`);r!==null&&await j.writeFile(e,r)}function Ae(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 je(e){switch(e){case`android`:return`device-pixels`;case`xctest`:case`macos-helper`:return`viewport-points`;default:throw new n(`UNSUPPORTED_OPERATION`,`screenshot --crop-on does not accept snapshot backend "${e??`unknown`}"`,{reason:s.targetNotAccepted})}}function R(e,t,n,r,i){if(e===`device-pixels`||t===null)return Fe(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 Me(e,t,n){return h(e,{x:0,y:0,width:t,height:n})??null}function z(e){let t=null;for(let n of e)!b(n)||!x(n.rect)||(!t||v(n.rect)>v(t))&&(t=n.rect);return t||Ne(e.filter(e=>x(e.rect)&&!Pe(e)))}function Ne(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)x(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 Pe(e){return C(e.type??``)===`image`&&!S(e.label)}function Fe(e){return{x:Math.round(e.x),y:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height)}}const Ie=`${s.partialIntersection}: the selector frame extends past the captured image; the crop was clipped to the image frame`;function Le(e){return e?.partialIntersection?[Ie]:[]}async function Re(e){let{device:t,session:r,surface:i,cropOn:a,screenshotPath:o,logPath:c,dispatchContext:l}=e,u={snapshotInteractiveOnly:!1},d=await A({device:t,session:r,flags:u,logPath:c,snapshotScope:void 0,captureData:async()=>await e.captureSnapshot({options:{appBundleId:l.appBundleId,interactiveOnly:!1,includeRects:!0,surface:i},execution:E(l)})}),f=T(d,u);if(f.snapshotQuality?.state===`sparse`)throw new n(`COMMAND_FAILED`,`the snapshot taken for --crop-on was sparse and cannot be read as the screen`,{reason:s.captureUnreadable});let p=await ze(f.nodes,a,f.truncated,t),m=await de(o),h=R(je(f.backend),z(f.nodes),p.rect,m.width,m.height),g=Me(h,m.width,m.height);if(g===null)throw new n(`COMMAND_FAILED`,`the frame resolved by --crop-on occupies no pixel of the capture`,{reason:s.emptyIntersection});let _=g.x!==h.x||g.y!==h.y||g.width<h.width||g.height<h.height;return await ke(o,g),{partialIntersection:_}}async function ze(e,t,r,i){let a=await ie(ae.cropTarget,e,t,{platform:p(i)});if(a.kind===`ambiguous`)throw new n(`COMMAND_FAILED`,`--crop-on matched ${a.matchedNodes.length} nodes and must resolve to one`,{reason:s.targetAmbiguous,candidates:a.matchedNodes.map(e=>e.label??e.ref),matches:a.matchedNodes.length});if(a.kind===`none`)throw r?new n(`COMMAND_FAILED`,`the snapshot taken for --crop-on was truncated, so a missing match is not proven`,{reason:s.captureIncomplete}):new n(`COMMAND_FAILED`,`--crop-on matched no node: ${t}`,{reason:s.targetNotFound,hint:`find ${t} list`});return a.node}const Be=[`scroll`,`list`,`recyclerview`,`edittext`,`textfield`];function Ve(e,t,n){if(e.backend!==`android`||!n.hittable||!O(n.rect)||b(n))return!1;let r=C(n.type??``);return!(Be.some(e=>r.includes(e))||t&&k(n.rect)>k(t)*.25)}function He(e,t,n,r){return!e.rect||e.hittable!==!0||n(e)||r(e)?null:Ue(e,t,r)}function Ue(e,t,n){let r=e.rect,i=We(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 We(e,t,n){let r=e.rect,i=new Map(t.map(e=>[e.index,e])),a=t.filter(t=>t.ref!==e.ref&&B(t,e,i)&&Ge(t,n)&&O(t.rect)&&y(r,t.rect)).map(e=>e.rect);return a.length<2?null:g(a)}function Ge(e,t){let n=C(e.type??``);return n.includes(`text`)||n.includes(`image`)&&t(e)}function B(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 Ke=[`button`,`link`,`menu`,`tab`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];async function V(e){let t=await j.readFile(e.screenshotPath),n=await oe(t,`screenshot`),r=qe(e.snapshot,n.width,n.height,{maxRefs:e.maxRefs});for(let e of r)fe(n,e);return await j.writeFile(e.screenshotPath,await se(n)),r}function qe(e,n,r,i={}){let a=z(e.nodes),o=ee(e.nodes),s=rt(e.nodes,o),c=new Map;for(let t of e.nodes){if(!Xe(e,a,t))continue;let i=Ze(e.nodes,o,t);if(!i?.ref||!i.rect||!O(i.rect))continue;let l=Qe(t,i,s),u=$e(t,i,l),d=H(e,a,Ye(e,i,e.nodes),n,r);if(!O(d))continue;let f=c.get(i.ref);(!f||u>f.score)&&c.set(i.ref,{ref:i.ref,label:l,rect:i.rect,overlayRect:d,score:u})}return Je(e,a,c,n,r),et([...c.values()]).sort(dt).slice(0,i.maxRefs??24).sort(Y).map(e=>({ref:e.ref,label:e.label,rect:e.rect,overlayRect:e.overlayRect,center:t(e.overlayRect)}))}function Je(e,t,n,r,i){let a=le(e.nodes).primaryAction;if(!a?.ref||!a.rect||!O(a.rect))return;let o=H(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 Ye(e,t,n){return e.backend===`android`?He(t,n,U,e=>!!q(e))??t.rect:t.rect}function Xe(e,t,n){let r=[n.label,n.value].some(G)||K(n.identifier);return Ve(e,t,n)?!0:U(n)?r:r&&tt(n)}function Ze(e,t,n){let r=r=>ne(e,n,t,e=>r(e)?e:null);return[W(n)?n:null,r(W),n.hittable?n:null,r(e=>e.hittable===!0)].find(nt)??null}function Qe(e,t,n){let r=q(e);return e.ref!==t.ref&&r?r:(t.ref?n.get(t.ref):void 0)||q(t)}function $e(e,t,n){let r=0;return e.ref===t.ref&&(r+=4),t.hittable&&(r+=3),U(t)&&(r+=3),U(e)&&(r+=2),n&&(r+=2),K(t.identifier)&&(r+=1),S(t.value)&&(r+=1),r}function et(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&&(y(e.overlayRect,n.overlayRect)||y(n.overlayRect,e.overlayRect)));if(e===-1){t.push(n);continue}k(n.overlayRect)<k(t[e].overlayRect)&&(t[e]=n)}return t}function H(e,t,n,r,i){return ut(R(e.backend===`android`?`device-pixels`:`viewport-points`,t,n,r,i),r,i)}function U(e){let t=[e.type,e.role,e.subrole].map(e=>C(e??``)).join(` `);return Ke.some(e=>t.includes(e))}function W(e){return U(e)&&!b(e)}function tt(e){let t=C(e.type??``);return t.includes(`statictext`)||t.includes(`image`)||t.includes(`text`)||t.includes(`other`)}function nt(e){return!!(e?.rect&&O(e.rect)&&!b(e))}function G(e){return S(e)?!st(e):!1}function K(e){return typeof e!=`string`||!G(e)?!1:!ct(e)}function q(e){let t=[e.label,e.value].find(G);if(t)return t.trim();if(K(e.identifier))return e.identifier.trim()}function rt(e,t){let n=it(e,t),r=[],i=new Set,a=n.roots.map(e=>({position:e,expanded:!1}));for(;a.length>0;){let t=a.pop();if(t.expanded){r[t.position]=at(e,n.byParent.get(t.position),r);continue}if(!i.has(t.position)){i.add(t.position),a.push({position:t.position,expanded:!0});for(let e of n.byParent.get(t.position)??[])a.push({position:e,expanded:!1})}}let o=new Map;return e.forEach((e,t)=>{let n=r[t]?.label;e.ref&&n!==void 0&&!o.has(e.ref)&&o.set(e.ref,n)}),o}function it(e,t){let n=new Map(e.map((e,t)=>[e,t])),r=[],i=new Map;return e.forEach((a,o)=>{let{parentIndex:s}=a,c=s===void 0?void 0:t.get(s)??e[s],l=c&&c!==a?n.get(c):void 0;if(l===void 0){r.push(o);return}let u=i.get(l);u?u.push(o):i.set(l,[o])}),{roots:r,byParent:i}}function at(e,t,n){let r;for(let i of t??[]){let t=e[i],a=q(t),o=a?{label:a,score:ot(t),position:i}:void 0;r=J(J(r,o),n[i])}return r}function J(e,t){return!e||!t?e??t:t.score===e.score?t.position<e.position?t:e:t.score>e.score?t:e}function ot(e){let t=0;return C(e.type??``).includes(`text`)&&(t+=2),G(e.label)&&(t+=2),G(e.value)&&(t+=1),t}function st(e){let t=e?.trim().toLowerCase();return t===`toolbar`||t===`window`||t===`application`||t?.startsWith(`vertical scroll bar`)===!0}function ct(e){return/^[a-z0-9_.]+:id\/[a-z0-9_.-]+$/i.test(e.trim())}function lt(e,t){return Number.parseInt(e.replace(/^\D+/,``),10)-Number.parseInt(t.replace(/^\D+/,``),10)}function ut(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?lt(e.ref,t.ref):r}function dt(e,t){return t.score===e.score?Y(e,t):t.score-e.score}async function X(e){let t=te({overlayRefs:e.overlayRefs,cropOn:e.cropOn!==void 0}),n=await ve({device:e.device,plan:t,inspectFacts:e.inspectFacts});return n.admitted?{ok:!0,runtime:await ft(e.bindDevice,n)}:{ok:!1,response:mt(t.kind,n.operation,n.fact)}}async function ft(e,t){let n=_e(e),{device:r,plan:i}=he(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:pt(e)})}}}function Z(e){return async t=>await e.operations.captureScreenshot(t)}function pt(e){return async t=>await e.operations.captureSnapshot(t)}function mt(e,t,n){return t===`captureScreenshot`?ge(`screenshot`,n):e===`capture-with-crop-on`?i(`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:n.available?void 0:n.reason},{hint:(n.available?void 0:n.hint)??`Re-run screenshot without --crop-on.`}):i(`UNSUPPORTED_OPERATION`,`--overlay-refs annotates a capture with the refs of a snapshot taken on the same screen, which this target cannot capture.`,{reason:n.available?void 0:n.reason},{hint:(n.available?void 0:n.hint)??`Re-run screenshot without --overlay-refs.`})}var ht=e({captureScreenshotArtifact:()=>Q,resolveScreenshotGenericExecution:()=>gt,screenshotExecutionFromContext:()=>$});async function gt(e){let{req:t,session:r}=e,i=a(`screenshot`,t.flags);if(i)throw new n(`INVALID_ARGS`,i);be(r.device,t.flags?.screenshotPixelDensity),xt(t.flags);let o=St(t,e.hostCwd),s=typeof t.flags?.screenshotCropOn==`string`&&t.flags.screenshotCropOn.length>0?t.flags.screenshotCropOn:void 0;s!==void 0&&De({device:r.device,surface:r.surface,cropOn:s,overlayRefs:t.flags?.overlayRefs===!0,fullscreen:t.flags?.screenshotFullscreen===!0});let c=await X({device:r.device,overlayRefs:t.flags?.overlayRefs===!0,cropOn:s,inspectFacts:e.inspectFacts,platformServices:e.platformServices,bindDevice:e.bindDevice});if(!c.ok)return c;let l=c.runtime,u={warnings:[]},{createCommandSurface:d}=e;return{ok:!0,recorded:o.recorded,execute:async e=>await _t({createCommandSurface:d,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:r,dispatchContext:i}=e;return await(await e.createCommandSurface({backend:Ct(e),artifacts:xe(e.crop!==void 0,i.signal),sessions:me(n,t),policy:ue()})).capture.screenshot({session:n,requestId:i.requestId,appBundleId:t.appBundleId,...o(i),surface:t.surface,...r?{out:{kind:`path`,path:r}}:{}})}function $(e){return E(e)}async function _t(e){let{session:t,runtime:n,flags:r}=e,i=vt({cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,cropRun:e.cropRun,logPath:e.logPath}),a=await Q({createCommandSurface:e.createCommandSurface,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 yt({session:t,cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,screenshotPath:a.path,logPath:e.logPath,dispatchContext:e.dispatchContext}),...await ye({device:t.device,path:a.path,requestedPixelDensity:r?.screenshotPixelDensity,scale:r?.screenshotScale})}}function vt(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 yt(e){let{session:t,cropOn:n,captureSnapshot:r}=e;return n!==void 0||r===void 0?{}:{overlayRefs:await bt({session:t,logPath:e.logPath,screenshotPath:e.screenshotPath,dispatchContext:e.dispatchContext,captureSnapshot:r})}}async function bt(e){let{session:t,dispatchContext:n}=e,r={snapshotInteractiveOnly:!0},i=await A({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=T(i,r);return pe(t,a),await V({screenshotPath:e.screenshotPath,snapshot:a})}function xt(e){let t=e?.screenshotCaptureBackend;if(t!==void 0){if(!c.includes(t))throw new n(`INVALID_ARGS`,`--capture-backend takes ${c.join(`, `)}`);if(e?.screenshotPixelDensity!==void 0||e?.screenshotNormalizeStatusBar)throw new n(`INVALID_ARGS`,`--pixel-density and --normalize-status-bar cannot be combined with --capture-backend runner: they belong to the simctl capture`)}}function St(e,t){let n=e.positionals??[],r=e.flags??{},i=n=>n===void 0?void 0:w(n,re(e,{cwd:t})),a=i(n[0]),o=i(r.out);return{outPath:a??o,recorded:{positionals:a?[a,...n.slice(1)]:n,flags:o?{...r,out:o}:r}}}function Ct(e){let{session:t,dispatchContext:n,captureScreenshot:r,crop:i}=e;return{platform:p(t.device),captureScreenshot:async(e,a,s)=>{let c=o({...n,...l(s)}),u=await r({outPath:a,options:{appBundleId:n.appBundleId,pixelDensity:c.pixelDensity,screenMask:c.screenMask,fullscreen:c.fullscreen,normalizeStatusBar:c.normalizeStatusBar,stabilize:c.stabilize,surface:s?.surface,skipIosSimulatorBootCheck:n.skipIosSimulatorBootCheck??(m(t.device)&&t.device.kind===`simulator`),captureBackend:c.captureBackend,preferredCaptureBackend:n.preferredScreenshotCaptureBackend},execution:$(n)});if(i){Oe(t.device,u);let e=await Re({device:t.device,session:t,surface:t.surface,cropOn:i.cropOn,screenshotPath:a,logPath:i.logPath,dispatchContext:n,captureSnapshot:i.captureSnapshot});i.run.warnings.push(...Le(e))}return u.displayRotation?{displayRotation:u.displayRotation}:void 0}}}export{V as a,X as i,$ as n,ht as r,Q as t};
1
+ import{r as e}from"./rolldown-runtime.js";import{Ci as t,Si as n,Ti as r,bi as i,di as a,hi as o,ii as s,on as c,pi as l,ui as u,yi as d,zn as f}from"./sdk-batch.js";import{A as p,_ as m,at as h,s as g}from"./sdk-contracts.js";import{f as ee,h as _,i as v,n as y,p as b}from"./screenshot.js";import"./capture.js";import{St as x,gt as S}from"./sdk-io.js";import"./diagnostics.js";import{R as C,V as te,w as ne}from"./sdk-device.js";import"./file.js";import{t as re}from"./session-paths.js";import{t as w}from"./snapshot-state.js";import{n as T}from"./snapshot-runtime-capture-input.js";import{n as ie}from"./context.js";import{i as ae,t as oe}from"./selector-pipeline-policy.js";import{i as se,o as ce,r as le}from"./png-worker-client.js";import{t as ue}from"./react-native-overlay2.js";import{t as de}from"./command-policy.js";import{t as fe}from"./png-size.js";import{a as E,o as D,s as O,t as pe}from"./screenshot-overlay-draw.js";import{f as me,i as k,n as he}from"./runtime-session.js";import{a as ge,i as _e,n as ve,t as ye}from"./session-runtime-admission.js";import{r as be,t as A}from"./screenshot-density.js";import{promises as j}from"node:fs";import M from"node:os";import N from"node:path";function xe(e,t){return{resolveInput:async()=>{throw new m(`UNSUPPORTED_OPERATION`,`screenshot does not resolve input artifacts`)},reserveOutput:async n=>{try{let r,i;return n?.kind===`path`?i=n.path:(r=await j.mkdtemp(N.join(M.tmpdir(),`agent-device-screenshot-`)),i=N.join(r,`screenshot.png`)),await j.mkdir(N.dirname(i),{recursive:!0}),e&&n?.kind===`path`?await Se(i,t):{path:i,visibility:`client-visible`,publish:async()=>{e&&t?.throwIfAborted()},...r?{cleanup:async()=>{await j.rm(r,{recursive:!0,force:!0})}}:{}}}catch(e){throw e instanceof m?e:P(e,n?.kind===`path`?n.path:`(temporary screenshot)`)}},createTempFile:async e=>{let t=await j.mkdtemp(N.join(M.tmpdir(),`${e.prefix}-`));return{path:N.join(t,`file${e.ext}`),visibility:`internal`,cleanup:async()=>{await j.rm(t,{recursive:!0,force:!0})}}}}}function P(e,t){return new m(`COMMAND_FAILED`,`Failed to publish screenshot`,{reason:`screenshot_publication_failed`,path:t,...e instanceof Error&&`code`in e?{filesystemCode:e.code}:{},cause:p(e)})}async function Se(e,t){let n=await Ce(e),r=await j.mkdtemp(N.join(M.tmpdir(),`agent-device-crop-`)),i=N.join(r,`screenshot${N.extname(e)||`.png`}`),a=async()=>{await j.rm(r,{recursive:!0,force:!0}).catch(e=>{x({level:`warn`,phase:`screenshot_crop_cleanup_failed`,data:{tempRoot:r,error:p(e)}})})};return{path:i,publishedPath:e,visibility:`client-visible`,publish:async()=>{try{let e=await j.readFile(i);t?.throwIfAborted(),S({destination:n,contents:e,preserveExistingMode:!0})}catch(n){throw t?.aborted?t.reason:P(n,e)}await a()},cleanup:a}}async function Ce(e){let t;try{t=(await j.lstat(e).catch(e=>{if(e.code!==`ENOENT`)throw e}))?.isSymbolicLink()?await j.realpath(e).catch(t=>{throw t.code===`ENOENT`?new m(`INVALID_ARGS`,`Screenshot destination is a dangling symbolic link`,{reason:`screenshot_destination_dangling_symlink`,path:e}):t}):e;let n=await j.stat(t).catch(e=>{if(e.code!==`ENOENT`)throw e});if(n&&!n.isFile())throw new m(`INVALID_ARGS`,`Screenshot destination must be a regular file`,{reason:`screenshot_destination_not_file`,path:e})}catch(t){throw t instanceof m?t:P(t,e)}return t}const F=v.pendingPixelIdentityEvidence,we=[{target:`ios-simulator`,status:`accepted`},{target:`android-emulator`,status:`accepted`},{target:`android-device`,status:`rejected`,rejectionReason:F},{target:`macos-app-window`,status:`rejected`,rejectionReason:F},{target:`ios-physical`,status:`accepted`},{target:`ios-physical-xctest`,status:`rejected`,rejectionReason:F},{target:`ipados-physical`,status:`rejected`,rejectionReason:F},{target:`macos-helper`,status:`rejected`,rejectionReason:F},{target:`web`,status:`rejected`,rejectionReason:F},{target:`linux`,status:`rejected`,rejectionReason:F},{target:`tvos`,status:`rejected`,rejectionReason:F},{target:`harmonyos`,status:`rejected`,rejectionReason:F},{target:`vega`,status:`rejected`,rejectionReason:F}];function I(e,t){switch(e.platform){case`apple`:return Te(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 Te(e,t){let n=te(e);switch(n){case`ios`:return e.kind===`device`?e.iosPhysicalDeviceBackend===`xctest`?`ios-physical-xctest`:`ios-physical`:`ios-simulator`;case`ipados`:return e.kind===`device`?`ipados-physical`:`ios-simulator`;case`tvos`:return`tvos`;case`macos`:return Ee(t);case`watchos`:case`visionos`:throw L(n)}}function Ee(e){return(e??`app`)===`app`?`macos-app-window`:`macos-helper`}function L(e,t){return new m(`UNSUPPORTED_OPERATION`,`screenshot --crop-on is not accepted on ${e} targets`,{reason:v.targetNotAccepted,...t?{rejectionReason:t}:{}})}function De(e){if(e.overlayRefs||e.fullscreen)throw new m(`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:v.frameMismatch});try{f(e.cropOn)}catch{throw new m(`INVALID_ARGS`,`screenshot --crop-on requires a valid selector expression`,{reason:v.selectorInvalid})}let t=I(e.device,e.surface),n=we.find(e=>e.target===t);if(!n||n.status===`rejected`)throw L(t,n?.status===`rejected`?n.rejectionReason:void 0)}function Oe(e,t){if(I(e,void 0)===`ios-physical`&&t.iosPhysicalCaptureBackend!==`coredevice`)throw L(`ios-physical-non-coredevice-capture`,F)}async function ke(e,t){if(!Ae(t))throw new m(`INVALID_ARGS`,`Screenshot crop box must be positive integer pixel offsets`);let n=await le(await j.readFile(e),t,`screenshot`);n!==null&&await j.writeFile(e,n)}function Ae(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 je(e){switch(e){case`android`:return`device-pixels`;case`xctest`:case`macos-helper`:return`viewport-points`;default:throw new m(`UNSUPPORTED_OPERATION`,`screenshot --crop-on does not accept snapshot backend "${e??`unknown`}"`,{reason:v.targetNotAccepted})}}function R(e,t,n,r,i){if(e===`device-pixels`||t===null)return Fe(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 Me(e,t,n){return l(e,{x:0,y:0,width:t,height:n})??null}function z(e){let t=null;for(let n of e)!s(n)||!o(n.rect)||(!t||d(n.rect)>d(t))&&(t=n.rect);return t||Ne(e.filter(e=>o(e.rect)&&!Pe(e)))}function Ne(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)o(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 Pe(e){return a(e.type??``)===`image`&&!u(e.label)}function Fe(e){return{x:Math.round(e.x),y:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height)}}const Ie=`${v.partialIntersection}: the selector frame extends past the captured image; the crop was clipped to the image frame`;function Le(e){return e?.partialIntersection?[Ie]:[]}async function Re(e){let{device:t,session:n,surface:r,cropOn:i,screenshotPath:a,logPath:o,dispatchContext:s}=e,c={snapshotInteractiveOnly:!1},l=await k({device:t,session:n,flags:c,logPath:o,snapshotScope:void 0,captureData:async()=>await e.captureSnapshot({options:{appBundleId:s.appBundleId,interactiveOnly:!1,includeRects:!0,surface:r},execution:T(s)})}),u=w(l,c);if(u.snapshotQuality?.state===`sparse`)throw new m(`COMMAND_FAILED`,`the snapshot taken for --crop-on was sparse and cannot be read as the screen`,{reason:v.captureUnreadable});let d=await ze(u.nodes,i,u.truncated,t),f=await fe(a),p=R(je(u.backend),z(u.nodes),d.rect,f.width,f.height),h=Me(p,f.width,f.height);if(h===null)throw new m(`COMMAND_FAILED`,`the frame resolved by --crop-on occupies no pixel of the capture`,{reason:v.emptyIntersection});let g=h.x!==p.x||h.y!==p.y||h.width<p.width||h.height<p.height;return await ke(a,h),{partialIntersection:g}}async function ze(e,t,n,r){let i=await ae(oe.cropTarget,e,t,{platform:C(r)});if(i.kind===`ambiguous`)throw new m(`COMMAND_FAILED`,`--crop-on matched ${i.matchedNodes.length} nodes and must resolve to one`,{reason:v.targetAmbiguous,candidates:i.matchedNodes.map(e=>e.label??e.ref),matches:i.matchedNodes.length});if(i.kind===`none`)throw n?new m(`COMMAND_FAILED`,`the snapshot taken for --crop-on was truncated, so a missing match is not proven`,{reason:v.captureIncomplete}):new m(`COMMAND_FAILED`,`--crop-on matched no node: ${t}`,{reason:v.targetNotFound,hint:`find ${t} list`});return i.node}const Be=[`scroll`,`list`,`recyclerview`,`edittext`,`textfield`];function Ve(e,t,n){if(e.backend!==`android`||!n.hittable||!D(n.rect)||s(n))return!1;let r=a(n.type??``);return!(Be.some(e=>r.includes(e))||t&&O(n.rect)>O(t)*.25)}function He(e,t,n,r){return!e.rect||e.hittable!==!0||n(e)||r(e)?null:Ue(e,t,r)}function Ue(e,t,n){let r=e.rect,i=We(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 We(e,t,r){let a=e.rect,o=new Map(t.map(e=>[e.index,e])),s=t.filter(t=>t.ref!==e.ref&&B(t,e,o)&&Ge(t,r)&&D(t.rect)&&i(a,t.rect)).map(e=>e.rect);return s.length<2?null:n(s)}function Ge(e,t){let n=a(e.type??``);return n.includes(`text`)||n.includes(`image`)&&t(e)}function B(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 Ke=[`button`,`link`,`menu`,`tab`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];async function V(e){let t=await j.readFile(e.screenshotPath),n=await se(t,`screenshot`),r=qe(e.snapshot,n.width,n.height,{maxRefs:e.maxRefs});for(let e of r)pe(n,e);return await j.writeFile(e.screenshotPath,await ce(n)),r}function qe(e,n,r,i={}){let a=z(e.nodes),o=t(e.nodes),s=rt(e.nodes,o),c=new Map;for(let t of e.nodes){if(!Xe(e,a,t))continue;let i=Ze(e.nodes,o,t);if(!i?.ref||!i.rect||!D(i.rect))continue;let l=Qe(t,i,s),u=$e(t,i,l),d=H(e,a,Ye(e,i,e.nodes),n,r);if(!D(d))continue;let f=c.get(i.ref);(!f||u>f.score)&&c.set(i.ref,{ref:i.ref,label:l,rect:i.rect,overlayRect:d,score:u})}return Je(e,a,c,n,r),et([...c.values()]).sort(dt).slice(0,i.maxRefs??24).sort(Y).map(e=>({ref:e.ref,label:e.label,rect:e.rect,overlayRect:e.overlayRect,center:h(e.overlayRect)}))}function Je(e,t,n,r,i){let a=ue(e.nodes).primaryAction;if(!a?.ref||!a.rect||!D(a.rect))return;let o=H(e,t,a.rect,r,i);if(!D(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 Ye(e,t,n){return e.backend===`android`?He(t,n,U,e=>!!q(e))??t.rect:t.rect}function Xe(e,t,n){let r=[n.label,n.value].some(G)||K(n.identifier);return Ve(e,t,n)?!0:U(n)?r:r&&tt(n)}function Ze(e,t,n){let i=i=>r(e,n,t,e=>i(e)?e:null);return[W(n)?n:null,i(W),n.hittable?n:null,i(e=>e.hittable===!0)].find(nt)??null}function Qe(e,t,n){let r=q(e);return e.ref!==t.ref&&r?r:(t.ref?n.get(t.ref):void 0)||q(t)}function $e(e,t,n){let r=0;return e.ref===t.ref&&(r+=4),t.hittable&&(r+=3),U(t)&&(r+=3),U(e)&&(r+=2),n&&(r+=2),K(t.identifier)&&(r+=1),u(t.value)&&(r+=1),r}function et(e){let t=[];for(let n of e.sort((e,t)=>O(e.overlayRect)-O(t.overlayRect))){let e=t.findIndex(e=>e.label!==void 0&&e.label===n.label&&(i(e.overlayRect,n.overlayRect)||i(n.overlayRect,e.overlayRect)));if(e===-1){t.push(n);continue}O(n.overlayRect)<O(t[e].overlayRect)&&(t[e]=n)}return t}function H(e,t,n,r,i){return ut(R(e.backend===`android`?`device-pixels`:`viewport-points`,t,n,r,i),r,i)}function U(e){let t=[e.type,e.role,e.subrole].map(e=>a(e??``)).join(` `);return Ke.some(e=>t.includes(e))}function W(e){return U(e)&&!s(e)}function tt(e){let t=a(e.type??``);return t.includes(`statictext`)||t.includes(`image`)||t.includes(`text`)||t.includes(`other`)}function nt(e){return!!(e?.rect&&D(e.rect)&&!s(e))}function G(e){return u(e)?!st(e):!1}function K(e){return typeof e!=`string`||!G(e)?!1:!ct(e)}function q(e){let t=[e.label,e.value].find(G);if(t)return t.trim();if(K(e.identifier))return e.identifier.trim()}function rt(e,t){let n=it(e,t),r=[],i=new Set,a=n.roots.map(e=>({position:e,expanded:!1}));for(;a.length>0;){let t=a.pop();if(t.expanded){r[t.position]=at(e,n.byParent.get(t.position),r);continue}if(!i.has(t.position)){i.add(t.position),a.push({position:t.position,expanded:!0});for(let e of n.byParent.get(t.position)??[])a.push({position:e,expanded:!1})}}let o=new Map;return e.forEach((e,t)=>{let n=r[t]?.label;e.ref&&n!==void 0&&!o.has(e.ref)&&o.set(e.ref,n)}),o}function it(e,t){let n=new Map(e.map((e,t)=>[e,t])),r=[],i=new Map;return e.forEach((a,o)=>{let{parentIndex:s}=a,c=s===void 0?void 0:t.get(s)??e[s],l=c&&c!==a?n.get(c):void 0;if(l===void 0){r.push(o);return}let u=i.get(l);u?u.push(o):i.set(l,[o])}),{roots:r,byParent:i}}function at(e,t,n){let r;for(let i of t??[]){let t=e[i],a=q(t),o=a?{label:a,score:ot(t),position:i}:void 0;r=J(J(r,o),n[i])}return r}function J(e,t){return!e||!t?e??t:t.score===e.score?t.position<e.position?t:e:t.score>e.score?t:e}function ot(e){let t=0;return a(e.type??``).includes(`text`)&&(t+=2),G(e.label)&&(t+=2),G(e.value)&&(t+=1),t}function st(e){let t=e?.trim().toLowerCase();return t===`toolbar`||t===`window`||t===`application`||t?.startsWith(`vertical scroll bar`)===!0}function ct(e){return/^[a-z0-9_.]+:id\/[a-z0-9_.-]+$/i.test(e.trim())}function lt(e,t){return Number.parseInt(e.replace(/^\D+/,``),10)-Number.parseInt(t.replace(/^\D+/,``),10)}function ut(e,t,n){let r=E(e.x,0,Math.max(0,t-1)),i=E(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:E(e.width,1,a),height:E(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?lt(e.ref,t.ref):r}function dt(e,t){return t.score===e.score?Y(e,t):t.score-e.score}async function X(e){let t=c({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 ft(e.bindDevice,n)}:{ok:!1,response:mt(t.kind,n.operation,n.fact)}}async function ft(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:pt(e)})}}}function Z(e){return async t=>await e.operations.captureScreenshot(t)}function pt(e){return async t=>await e.operations.captureSnapshot(t)}function mt(e,t,n){return t===`captureScreenshot`?_e(`screenshot`,n):e===`capture-with-crop-on`?g(`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:n.available?void 0:n.reason},{hint:(n.available?void 0:n.hint)??`Re-run screenshot without --crop-on.`}):g(`UNSUPPORTED_OPERATION`,`--overlay-refs annotates a capture with the refs of a snapshot taken on the same screen, which this target cannot capture.`,{reason:n.available?void 0:n.reason},{hint:(n.available?void 0:n.hint)??`Re-run screenshot without --overlay-refs.`})}var ht=e({captureScreenshotArtifact:()=>Q,resolveScreenshotGenericExecution:()=>gt,screenshotExecutionFromContext:()=>$});async function gt(e){let{req:t,session:n}=e,r=ee(`screenshot`,t.flags);if(r)throw new m(`INVALID_ARGS`,r);A(n.device,t.flags?.screenshotPixelDensity),xt(t.flags);let i=St(t,e.hostCwd),a=typeof t.flags?.screenshotCropOn==`string`&&t.flags.screenshotCropOn.length>0?t.flags.screenshotCropOn:void 0;a!==void 0&&De({device:n.device,surface:n.surface,cropOn:a,overlayRefs:t.flags?.overlayRefs===!0,fullscreen:t.flags?.screenshotFullscreen===!0});let o=await X({device:n.device,overlayRefs:t.flags?.overlayRefs===!0,cropOn:a,inspectFacts:e.inspectFacts,platformServices:e.platformServices,bindDevice:e.bindDevice});if(!o.ok)return o;let s=o.runtime,c={warnings:[]},{createCommandSurface:l}=e;return{ok:!0,recorded:i.recorded,execute:async e=>await _t({createCommandSurface:l,session:e.session,sessionName:e.sessionName,logPath:e.logPath,dispatchContext:e.dispatchContext,flags:e.request.flags,outPath:i.outPath,runtime:s,cropOn:a,cropRun:c})}}async function Q(e){let{session:t,sessionName:n,outPath:r,dispatchContext:i}=e;return await(await e.createCommandSurface({backend:Ct(e),artifacts:xe(e.crop!==void 0,i.signal),sessions:he(n,t),policy:de()})).capture.screenshot({session:n,requestId:i.requestId,appBundleId:t.appBundleId,..._(i),surface:t.surface,...r?{out:{kind:`path`,path:r}}:{}})}function $(e){return T(e)}async function _t(e){let{session:t,runtime:n,flags:r}=e,i=vt({cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,cropRun:e.cropRun,logPath:e.logPath}),a=await Q({createCommandSurface:e.createCommandSurface,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 yt({session:t,cropOn:e.cropOn,captureSnapshot:n.captureSnapshot,screenshotPath:a.path,logPath:e.logPath,dispatchContext:e.dispatchContext}),...await be({device:t.device,path:a.path,requestedPixelDensity:r?.screenshotPixelDensity,scale:r?.screenshotScale})}}function vt(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 yt(e){let{session:t,cropOn:n,captureSnapshot:r}=e;return n!==void 0||r===void 0?{}:{overlayRefs:await bt({session:t,logPath:e.logPath,screenshotPath:e.screenshotPath,dispatchContext:e.dispatchContext,captureSnapshot:r})}}async function bt(e){let{session:t,dispatchContext:n}=e,r={snapshotInteractiveOnly:!0},i=await k({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=w(i,r);return me(t,a),await V({screenshotPath:e.screenshotPath,snapshot:a})}function xt(e){let t=e?.screenshotCaptureBackend;if(t!==void 0){if(!y.includes(t))throw new m(`INVALID_ARGS`,`--capture-backend takes ${y.join(`, `)}`);if(e?.screenshotPixelDensity!==void 0||e?.screenshotNormalizeStatusBar)throw new m(`INVALID_ARGS`,`--pixel-density and --normalize-status-bar cannot be combined with --capture-backend runner: they belong to the simctl capture`)}}function St(e,t){let n=e.positionals??[],r=e.flags??{},i=n=>n===void 0?void 0:re(n,ie(e,{cwd:t})),a=i(n[0]),o=i(r.out);return{outPath:a??o,recorded:{positionals:a?[a,...n.slice(1)]:n,flags:o?{...r,out:o}:r}}}function Ct(e){let{session:t,dispatchContext:n,captureScreenshot:r,crop:i}=e;return{platform:C(t.device),captureScreenshot:async(e,a,o)=>{let s=_({...n,...b(o)}),c=await r({outPath:a,options:{appBundleId:n.appBundleId,pixelDensity:s.pixelDensity,screenMask:s.screenMask,fullscreen:s.fullscreen,normalizeStatusBar:s.normalizeStatusBar,stabilize:s.stabilize,surface:o?.surface,skipIosSimulatorBootCheck:n.skipIosSimulatorBootCheck??(ne(t.device)&&t.device.kind===`simulator`),captureBackend:s.captureBackend,preferredCaptureBackend:n.preferredScreenshotCaptureBackend},execution:$(n)});if(i){Oe(t.device,c);let e=await Re({device:t.device,session:t,surface:t.surface,cropOn:i.cropOn,screenshotPath:a,logPath:i.logPath,dispatchContext:n,captureSnapshot:i.captureSnapshot});i.run.warnings.push(...Le(e))}return c.displayRotation?{displayRotation:c.displayRotation}:void 0}}}export{V as a,X as i,$ as n,ht as r,Q as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{n as t,r as n}from"./interactor-operation-binding.js";function r(e){return()=>({captureBackendRefusal:e})}async function i(t,n={}){let r=t?.captureBackend;if(r!==void 0&&!n.captureBackends?.includes(r))throw new e(`UNSUPPORTED_OPERATION`,`--capture-backend ${r} is not supported: ${n.captureBackendRefusal??`this capture owner declares no such backend`}`,{reason:`screenshot-capture-backend-unsupported`});if(t?.screenMask===void 0)return;let{readScreenshotScreenMask:i}=await import(`./screenshot.js`).then(e=>e.g);if(i(t?.screenMask)!==void 0&&n.screenMask!==!0)throw new e(`UNSUPPORTED_OPERATION`,`--screen-mask requires a handheld iOS simulator simctl capture`,{reason:`screenshot-screen-mask-unsupported`})}function a(e){return Object.freeze({captureScreenshot:e.capture})}function o(e,t){let{captureBackend:n,preferredCaptureBackend:r,...i}=e??{};return n?{...i,captureBackend:n}:r&&t.captureCapabilities(i).captureBackends?.includes(r)?{...i,captureBackend:r}:i}function s(e,t){return Object.freeze({captureScreenshot:async n=>{let r=o(n.options,e);return await i(r,e.captureCapabilities(r)),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e.signal})).screenshot(n.outPath,r)??{}}})}function c(e){return s(e,t(e))}function l(e){return s(e,n({...e,operation:`screenshot`}))}export{a,r as i,c as n,l as r,i as t};
1
+ import{_ as e}from"./sdk-contracts.js";import{n as t,r as n}from"./interactor-operation-binding.js";function r(e){return()=>({captureBackendRefusal:e})}async function i(t,n={}){let r=t?.captureBackend;if(r!==void 0&&!n.captureBackends?.includes(r))throw new e(`UNSUPPORTED_OPERATION`,`--capture-backend ${r} is not supported: ${n.captureBackendRefusal??`this capture owner declares no such backend`}`,{reason:`screenshot-capture-backend-unsupported`});if(t?.screenMask===void 0)return;let{readScreenshotScreenMask:i}=await import(`./screenshot.js`).then(e=>e.g);if(i(t?.screenMask)!==void 0&&n.screenMask!==!0)throw new e(`UNSUPPORTED_OPERATION`,`--screen-mask requires a handheld iOS simulator simctl capture`,{reason:`screenshot-screen-mask-unsupported`})}function a(e){return Object.freeze({captureScreenshot:e.capture})}function o(e,t){let{captureBackend:n,preferredCaptureBackend:r,...i}=e??{};return n?{...i,captureBackend:n}:r&&t.captureCapabilities(i).captureBackends?.includes(r)?{...i,captureBackend:r}:i}function s(e,t){return Object.freeze({captureScreenshot:async n=>{let r=o(n.options,e);return await i(r,e.captureCapabilities(r)),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e.signal})).screenshot(n.outPath,r)??{}}})}function c(e){return s(e,t(e))}function l(e){return s(e,n({...e,operation:`screenshot`}))}export{a,r as i,c as n,l as r,i as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime.js";import{P as t}from"./sdk-contracts.js";var n=e({RETIRED_SCREENSHOT_MAX_SIZE:()=>o,SCREENSHOT_CAPTURE_BACKENDS:()=>d,SCREENSHOT_COMMAND_FLAG_KEYS:()=>f,SCREENSHOT_CROP_REASONS:()=>l,SCREENSHOT_FULLSCREEN_REASONS:()=>u,SCREENSHOT_SCALE_LIMITS:()=>a,SCREENSHOT_SCREEN_MASKS:()=>r,SCREENSHOT_SPECIFIC_FLAG_DEFINITIONS:()=>p,appendScreenshotScriptFlags:()=>S,readScreenshotScreenMask:()=>i,readScreenshotScriptFlag:()=>C,retiredScreenshotMaxSizeFlagError:()=>s,screenshotFlagsFromOptions:()=>y,screenshotFlagsFromPublicOptions:()=>b,screenshotOptionsFromFlags:()=>v,validateNoRetiredScreenshotMaxSize:()=>c,validateScreenshotScale:()=>x});const r=[`black`];function i(e){if(e===void 0||e===`black`)return e;throw new t(`INVALID_ARGS`,`--screen-mask must be black`)}const a={min:.01,max:1},o={flagKey:`screenshotMaxSize`,cliToken:`--max-size`,envVar:`AGENT_DEVICE_SCREENSHOT_MAX_SIZE`,publicOptionKey:`maxSize`,migration:{screenshot:`screenshot --max-size was removed; use --scale <0.01-1> (or AGENT_DEVICE_SCREENSHOT_SCALE) to downscale proportionally`,record:`record --max-size was removed; recordings capture at native resolution`}};function s(e,t){return t&&Object.hasOwn(t,o.flagKey)?o.migration[e]:void 0}function c(e,n){if(Object.hasOwn(n,o.publicOptionKey)||Object.hasOwn(n,o.flagKey))throw new t(`INVALID_ARGS`,o.migration[e])}const l={selectorInvalid:`CROP_SELECTOR_INVALID`,targetNotFound:`CROP_TARGET_NOT_FOUND`,targetAmbiguous:`CROP_TARGET_AMBIGUOUS`,captureUnreadable:`CROP_CAPTURE_UNREADABLE`,captureIncomplete:`CROP_CAPTURE_INCOMPLETE`,emptyIntersection:`CROP_EMPTY_INTERSECTION`,partialIntersection:`CROP_PARTIAL_INTERSECTION`,targetNotAccepted:`CROP_TARGET_NOT_ACCEPTED`,frameMismatch:`CROP_FRAME_MISMATCH`,pendingPixelIdentityEvidence:`PENDING_PIXEL_IDENTITY_EVIDENCE`},u={macOsHelperSurfaceFixedFrame:`SCREENSHOT_FULLSCREEN_MACOS_HELPER_SURFACE_FIXED_FRAME`},d=[`runner`],f=[`out`,`overlayRefs`,`screenshotCropOn`,`screenshotPixelDensity`,`screenshotScreenMask`,`screenshotFullscreen`,`screenshotScale`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`,`screenshotCaptureBackend`],p=[{key:`screenshotCropOn`,names:[`--crop-on`],type:`string`,usageLabel:`--crop-on <selector-expression>`,usageDescription:`Screenshot: crop the capture to the frame of the selector resolved on the same screen`,projectConfig:!1,recorded:!0},{key:`screenshotPixelDensity`,names:[`--pixel-density`],type:`int`,min:1,usageLabel:`--pixel-density <n>`,usageDescription:`Screenshot: output PNG pixel density in pixels per logical point (currently supported on iOS simulators)`,projectConfig:!0,recorded:!0},{key:`screenshotScreenMask`,names:[`--screen-mask`],type:`enum`,enumValues:r,usageLabel:`--screen-mask <black>`,usageDescription:`Screenshot or live screenshot diff: fill the iOS simulator screen outline with black; requires simctl capture`,projectConfig:!1,recorded:!0},{key:`screenshotFullscreen`,names:[`--fullscreen`,`--full`,`-f`],type:`boolean`,usageLabel:`--fullscreen, --full, -f`,usageDescription:`Screenshot: on web capture the full page; on macOS app sessions capture the full desktop instead of the app window`,projectConfig:!0,recorded:!0},{key:`screenshotScale`,names:[`--scale`],type:`number`,min:a.min,max:a.max,usageLabel:`--scale <0.01-1>`,usageDescription:`Screenshot: resize both dimensions by this factor (or use AGENT_DEVICE_SCREENSHOT_SCALE)`,projectConfig:!0,recorded:!0},{key:`screenshotNoStabilize`,names:[`--no-stabilize`],type:`boolean`,usageLabel:`--no-stabilize`,usageDescription:`Screenshot: capture immediately without Android status-bar stabilization (the default)`,projectConfig:!0,recorded:!0},{key:`screenshotNormalizeStatusBar`,names:[`--normalize-status-bar`],type:`boolean`,usageLabel:`--normalize-status-bar`,usageDescription:`Screenshot: temporarily normalize iOS simulator or ADB-backed Android status-bar chrome for deterministic screenshot diffs; ADB-backed Android waits for transient UI to fade`,projectConfig:!0,recorded:!0},{key:`screenshotCaptureBackend`,names:[`--capture-backend`],type:`enum`,enumValues:d,usageLabel:`--capture-backend runner`,usageDescription:`Screenshot: on Apple targets capture through the XCTest runner (XCUIScreen), which leaves out the simulator-drawn Dynamic Island, instead of simctl; refused on other platforms, provider sessions and macOS surfaces the helper captures, and with --pixel-density, --screen-mask and --normalize-status-bar`,projectConfig:!0,recorded:!1}],m=[{tokens:[`--fullscreen`,`--full`,`-f`],key:`screenshotFullscreen`},{tokens:[`--no-stabilize`],key:`screenshotNoStabilize`},{tokens:[`--normalize-status-bar`],key:`screenshotNormalizeStatusBar`}],h=[{token:`--pixel-density`,key:`screenshotPixelDensity`,label:`screenshot --pixel-density`}],g=[{token:`--scale`,key:`screenshotScale`,label:`screenshot --scale`,min:a.min,max:a.max}],_=[{token:`--crop-on`,key:`screenshotCropOn`,label:`screenshot --crop-on`}];function v(e){return w({overlayRefs:e?.overlayRefs,cropOn:e?.screenshotCropOn,pixelDensity:e?.screenshotPixelDensity,screenMask:i(e?.screenshotScreenMask),fullscreen:e?.screenshotFullscreen,scale:e?.screenshotScale,stabilize:e?.screenshotNoStabilize===void 0?void 0:!e.screenshotNoStabilize,normalizeStatusBar:e?.screenshotNormalizeStatusBar,captureBackend:e?.screenshotCaptureBackend})}function y(e={}){return w({overlayRefs:e.overlayRefs,screenshotCropOn:e.screenshotCropOn??e.cropOn,screenshotPixelDensity:e.screenshotPixelDensity??e.pixelDensity,screenshotScreenMask:i(e.screenshotScreenMask??e.screenMask),screenshotFullscreen:e.screenshotFullscreen??e.fullscreen,screenshotScale:e.screenshotScale,screenshotNoStabilize:e.screenshotNoStabilize??(e.stabilize===void 0?void 0:!e.stabilize),screenshotNormalizeStatusBar:e.screenshotNormalizeStatusBar??e.normalizeStatusBar,screenshotCaptureBackend:e.screenshotCaptureBackend??e.captureBackend})}function b(e={}){return y({...e,screenshotScale:e.screenshotScale??e.scale})}function x(e){let{min:n,max:r}=a;if(e.scale!==void 0&&(!Number.isFinite(e.scale)||e.scale<n||e.scale>r))throw new t(`INVALID_ARGS`,`screenshot scale must be between ${n} and ${r}`)}function S(e,t){typeof t?.screenshotPixelDensity==`number`&&e.push(`--pixel-density`,String(t.screenshotPixelDensity)),t?.screenshotScreenMask!==void 0&&e.push(`--screen-mask`,i(t.screenshotScreenMask)),t?.screenshotFullscreen&&e.push(`--fullscreen`),typeof t?.screenshotScale==`number`&&e.push(`--scale`,String(t.screenshotScale)),t?.screenshotNoStabilize&&e.push(`--no-stabilize`),t?.screenshotNoStabilize===!1&&e.push(`--no-stabilize=false`),t?.screenshotNormalizeStatusBar&&e.push(`--normalize-status-bar`)}function C(e){let{args:n,flags:r,index:a}=e,s=n[a];if(s===`--screen-mask`){let e=n[a+1];if(e===void 0)throw new t(`INVALID_ARGS`,`--screen-mask requires black`);return r.screenshotScreenMask=i(e),{handled:!0,nextIndex:a+1}}if(s===o.cliToken)throw new t(`INVALID_ARGS`,o.migration.screenshot);return T(s,r,a)??E({args:n,index:a,flags:r,token:s})??D({args:n,index:a,flags:r,token:s})??O({args:n,index:a,flags:r,token:s})??{handled:!1}}function w(e){return Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))}function T(e,t,n){if(e===`--no-stabilize=false`)return t.screenshotNoStabilize=!1,{handled:!0,nextIndex:n};let r=m.find(t=>t.tokens.some(t=>t===e));if(r)return t[r.key]=!0,{handled:!0,nextIndex:n}}function E(e){let n=h.find(t=>t.token===e.token);if(!n)return;let r=Number(e.args[e.index+1]);if(!Number.isInteger(r)||r<1)throw new t(`INVALID_ARGS`,`${n.label} requires a positive integer`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}function D(e){let n=g.find(t=>t.token===e.token);if(!n)return;let r=Number(e.args[e.index+1]);if(!Number.isFinite(r)||r<n.min||r>n.max)throw new t(`INVALID_ARGS`,`${n.label} requires a number from ${n.min} to ${n.max}`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}function O(e){let n=_.find(t=>t.token===e.token);if(!n)return;let r=e.args[e.index+1];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`${n.label} requires a selector expression`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}export{c as _,u as a,p as c,C as d,s as f,n as g,v as h,l as i,S as l,b as m,d as n,a as o,y as p,f as r,r as s,o as t,i as u,x as v};
1
+ import{r as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";var n=e({RETIRED_SCREENSHOT_MAX_SIZE:()=>o,SCREENSHOT_CAPTURE_BACKENDS:()=>d,SCREENSHOT_COMMAND_FLAG_KEYS:()=>f,SCREENSHOT_CROP_REASONS:()=>l,SCREENSHOT_FULLSCREEN_REASONS:()=>u,SCREENSHOT_SCALE_LIMITS:()=>a,SCREENSHOT_SCREEN_MASKS:()=>r,SCREENSHOT_SPECIFIC_FLAG_DEFINITIONS:()=>p,appendScreenshotScriptFlags:()=>S,readScreenshotScreenMask:()=>i,readScreenshotScriptFlag:()=>C,retiredScreenshotMaxSizeFlagError:()=>s,screenshotFlagsFromOptions:()=>y,screenshotFlagsFromPublicOptions:()=>b,screenshotOptionsFromFlags:()=>v,validateNoRetiredScreenshotMaxSize:()=>c,validateScreenshotScale:()=>x});const r=[`black`];function i(e){if(e===void 0||e===`black`)return e;throw new t(`INVALID_ARGS`,`--screen-mask must be black`)}const a={min:.01,max:1},o={flagKey:`screenshotMaxSize`,cliToken:`--max-size`,envVar:`AGENT_DEVICE_SCREENSHOT_MAX_SIZE`,publicOptionKey:`maxSize`,migration:{screenshot:`screenshot --max-size was removed; use --scale <0.01-1> (or AGENT_DEVICE_SCREENSHOT_SCALE) to downscale proportionally`,record:`record --max-size was removed; recordings capture at native resolution`}};function s(e,t){return t&&Object.hasOwn(t,o.flagKey)?o.migration[e]:void 0}function c(e,n){if(Object.hasOwn(n,o.publicOptionKey)||Object.hasOwn(n,o.flagKey))throw new t(`INVALID_ARGS`,o.migration[e])}const l={selectorInvalid:`CROP_SELECTOR_INVALID`,targetNotFound:`CROP_TARGET_NOT_FOUND`,targetAmbiguous:`CROP_TARGET_AMBIGUOUS`,captureUnreadable:`CROP_CAPTURE_UNREADABLE`,captureIncomplete:`CROP_CAPTURE_INCOMPLETE`,emptyIntersection:`CROP_EMPTY_INTERSECTION`,partialIntersection:`CROP_PARTIAL_INTERSECTION`,targetNotAccepted:`CROP_TARGET_NOT_ACCEPTED`,frameMismatch:`CROP_FRAME_MISMATCH`,pendingPixelIdentityEvidence:`PENDING_PIXEL_IDENTITY_EVIDENCE`},u={macOsHelperSurfaceFixedFrame:`SCREENSHOT_FULLSCREEN_MACOS_HELPER_SURFACE_FIXED_FRAME`},d=[`runner`],f=[`out`,`overlayRefs`,`screenshotCropOn`,`screenshotPixelDensity`,`screenshotScreenMask`,`screenshotFullscreen`,`screenshotScale`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`,`screenshotCaptureBackend`],p=[{key:`screenshotCropOn`,names:[`--crop-on`],type:`string`,usageLabel:`--crop-on <selector-expression>`,usageDescription:`Screenshot: crop the capture to the frame of the selector resolved on the same screen`,projectConfig:!1,recorded:!0},{key:`screenshotPixelDensity`,names:[`--pixel-density`],type:`int`,min:1,usageLabel:`--pixel-density <n>`,usageDescription:`Screenshot: output PNG pixel density in pixels per logical point (currently supported on iOS simulators)`,projectConfig:!0,recorded:!0},{key:`screenshotScreenMask`,names:[`--screen-mask`],type:`enum`,enumValues:r,usageLabel:`--screen-mask <black>`,usageDescription:`Screenshot or live screenshot diff: fill the iOS simulator screen outline with black; requires simctl capture`,projectConfig:!1,recorded:!0},{key:`screenshotFullscreen`,names:[`--fullscreen`,`--full`,`-f`],type:`boolean`,usageLabel:`--fullscreen, --full, -f`,usageDescription:`Screenshot: on web capture the full page; on macOS app sessions capture the full desktop instead of the app window`,projectConfig:!0,recorded:!0},{key:`screenshotScale`,names:[`--scale`],type:`number`,min:a.min,max:a.max,usageLabel:`--scale <0.01-1>`,usageDescription:`Screenshot: resize both dimensions by this factor (or use AGENT_DEVICE_SCREENSHOT_SCALE)`,projectConfig:!0,recorded:!0},{key:`screenshotNoStabilize`,names:[`--no-stabilize`],type:`boolean`,usageLabel:`--no-stabilize`,usageDescription:`Screenshot: capture immediately without Android status-bar stabilization (the default)`,projectConfig:!0,recorded:!0},{key:`screenshotNormalizeStatusBar`,names:[`--normalize-status-bar`],type:`boolean`,usageLabel:`--normalize-status-bar`,usageDescription:`Screenshot: temporarily normalize iOS simulator or ADB-backed Android status-bar chrome for deterministic screenshot diffs; ADB-backed Android waits for transient UI to fade`,projectConfig:!0,recorded:!0},{key:`screenshotCaptureBackend`,names:[`--capture-backend`],type:`enum`,enumValues:d,usageLabel:`--capture-backend runner`,usageDescription:`Screenshot: on Apple targets capture through the XCTest runner (XCUIScreen), which leaves out the simulator-drawn Dynamic Island, instead of simctl; refused on other platforms, provider sessions and macOS surfaces the helper captures, and with --pixel-density, --screen-mask and --normalize-status-bar`,projectConfig:!0,recorded:!1}],m=[{tokens:[`--fullscreen`,`--full`,`-f`],key:`screenshotFullscreen`},{tokens:[`--no-stabilize`],key:`screenshotNoStabilize`},{tokens:[`--normalize-status-bar`],key:`screenshotNormalizeStatusBar`}],h=[{token:`--pixel-density`,key:`screenshotPixelDensity`,label:`screenshot --pixel-density`}],g=[{token:`--scale`,key:`screenshotScale`,label:`screenshot --scale`,min:a.min,max:a.max}],_=[{token:`--crop-on`,key:`screenshotCropOn`,label:`screenshot --crop-on`}];function v(e){return w({overlayRefs:e?.overlayRefs,cropOn:e?.screenshotCropOn,pixelDensity:e?.screenshotPixelDensity,screenMask:i(e?.screenshotScreenMask),fullscreen:e?.screenshotFullscreen,scale:e?.screenshotScale,stabilize:e?.screenshotNoStabilize===void 0?void 0:!e.screenshotNoStabilize,normalizeStatusBar:e?.screenshotNormalizeStatusBar,captureBackend:e?.screenshotCaptureBackend})}function y(e={}){return w({overlayRefs:e.overlayRefs,screenshotCropOn:e.screenshotCropOn??e.cropOn,screenshotPixelDensity:e.screenshotPixelDensity??e.pixelDensity,screenshotScreenMask:i(e.screenshotScreenMask??e.screenMask),screenshotFullscreen:e.screenshotFullscreen??e.fullscreen,screenshotScale:e.screenshotScale,screenshotNoStabilize:e.screenshotNoStabilize??(e.stabilize===void 0?void 0:!e.stabilize),screenshotNormalizeStatusBar:e.screenshotNormalizeStatusBar??e.normalizeStatusBar,screenshotCaptureBackend:e.screenshotCaptureBackend??e.captureBackend})}function b(e={}){return y({...e,screenshotScale:e.screenshotScale??e.scale})}function x(e){let{min:n,max:r}=a;if(e.scale!==void 0&&(!Number.isFinite(e.scale)||e.scale<n||e.scale>r))throw new t(`INVALID_ARGS`,`screenshot scale must be between ${n} and ${r}`)}function S(e,t){typeof t?.screenshotPixelDensity==`number`&&e.push(`--pixel-density`,String(t.screenshotPixelDensity)),t?.screenshotScreenMask!==void 0&&e.push(`--screen-mask`,i(t.screenshotScreenMask)),t?.screenshotFullscreen&&e.push(`--fullscreen`),typeof t?.screenshotScale==`number`&&e.push(`--scale`,String(t.screenshotScale)),t?.screenshotNoStabilize&&e.push(`--no-stabilize`),t?.screenshotNoStabilize===!1&&e.push(`--no-stabilize=false`),t?.screenshotNormalizeStatusBar&&e.push(`--normalize-status-bar`)}function C(e){let{args:n,flags:r,index:a}=e,s=n[a];if(s===`--screen-mask`){let e=n[a+1];if(e===void 0)throw new t(`INVALID_ARGS`,`--screen-mask requires black`);return r.screenshotScreenMask=i(e),{handled:!0,nextIndex:a+1}}if(s===o.cliToken)throw new t(`INVALID_ARGS`,o.migration.screenshot);return T(s,r,a)??E({args:n,index:a,flags:r,token:s})??D({args:n,index:a,flags:r,token:s})??O({args:n,index:a,flags:r,token:s})??{handled:!1}}function w(e){return Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))}function T(e,t,n){if(e===`--no-stabilize=false`)return t.screenshotNoStabilize=!1,{handled:!0,nextIndex:n};let r=m.find(t=>t.tokens.some(t=>t===e));if(r)return t[r.key]=!0,{handled:!0,nextIndex:n}}function E(e){let n=h.find(t=>t.token===e.token);if(!n)return;let r=Number(e.args[e.index+1]);if(!Number.isInteger(r)||r<1)throw new t(`INVALID_ARGS`,`${n.label} requires a positive integer`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}function D(e){let n=g.find(t=>t.token===e.token);if(!n)return;let r=Number(e.args[e.index+1]);if(!Number.isFinite(r)||r<n.min||r>n.max)throw new t(`INVALID_ARGS`,`${n.label} requires a number from ${n.min} to ${n.max}`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}function O(e){let n=_.find(t=>t.token===e.token);if(!n)return;let r=e.args[e.index+1];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`${n.label} requires a selector expression`);return e.flags[n.key]=r,{handled:!0,nextIndex:e.index+1}}export{c as _,u as a,p as c,C as d,s as f,n as g,v as h,l as i,S as l,b as m,d as n,a as o,y as p,f as r,r as s,o as t,i as u,x as v};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{g as t}from"./host-file.js";import{runHarmonyHdc as n,runHarmonyShell as r}from"./hdc.js";import{randomUUID as i}from"node:crypto";async function a(a,o){let s=`/data/local/tmp/agent-device-screen-${i()}.jpeg`;try{await r(a,[`snapshot_display`,`-f`,s],{timeoutMs:15e3}),await n(a,[`file`,`recv`,s,o],{timeoutMs:15e3});let i=await t(o);if(i.length<3||i[0]!==255||i[1]!==216||i[2]!==255)throw new e(`COMMAND_FAILED`,`HarmonyOS screenshot is not a JPEG file`)}finally{await r(a,[`rm`,`-f`,s],{allowFailure:!0}).catch(()=>{})}}export{a as screenshotHarmony};
1
+ import{_ as e}from"./sdk-contracts.js";import{g as t}from"./host-file.js";import{n,r}from"./hdc.js";import{randomUUID as i}from"node:crypto";async function a(a,o){let s=`/data/local/tmp/agent-device-screen-${i()}.jpeg`;try{await r(a,[`snapshot_display`,`-f`,s],{timeoutMs:15e3}),await n(a,[`file`,`recv`,s,o],{timeoutMs:15e3});let i=await t(o);if(i.length<3||i[0]!==255||i[1]!==216||i[2]!==255)throw new e(`COMMAND_FAILED`,`HarmonyOS screenshot is not a JPEG file`)}finally{await r(a,[`rm`,`-f`,s],{allowFailure:!0}).catch(()=>{})}}export{a as screenshotHarmony};
@@ -1,2 +1,2 @@
1
- import{P as e,c as t}from"./sdk-contracts.js";import{r as n}from"./src.js";import{u as r}from"./file.js";import{t as i}from"./cli-runner.js";import{n as a,r as o}from"./src7.js";import{t as s}from"./command-policy.js";import{n as c}from"./shared.js";const l=async({positionals:e,flags:r,client:a,host:o})=>{let s=await i({client:a,command:`screenshot`,positionals:e,flags:r,env:o.env});if(t(r.responseLevel))return await c(r,s,()=>JSON.stringify(s,null,2)),!0;let l=n(s);return await c(r,l,()=>{let e=s.overlayRefs?`Annotated ${s.overlayRefs.length} refs onto ${s.path}`:f(s),t=s.warnings??[];return t.length>0?[e,...t].join(`
1
+ import{_ as e,c as t}from"./sdk-contracts.js";import{r as n}from"./src.js";import{u as r}from"./file.js";import{t as i}from"./cli-runner.js";import{n as a,r as o}from"./src7.js";import{t as s}from"./command-policy.js";import{n as c}from"./shared.js";const l=async({positionals:e,flags:r,client:a,host:o})=>{let s=await i({client:a,command:`screenshot`,positionals:e,flags:r,env:o.env});if(t(r.responseLevel))return await c(r,s,()=>JSON.stringify(s,null,2)),!0;let l={...n(s),...s.scriptDeliveryFailure?{scriptDeliveryFailure:s.scriptDeliveryFailure}:{}};return await c(r,l,()=>{let e=s.overlayRefs?`Annotated ${s.overlayRefs.length} refs onto ${s.path}`:f(s),t=s.warnings??[];return t.length>0?[e,...t].join(`
2
2
  `):e}),!0},u=async({positionals:t,flags:n,client:l,host:u})=>{if(t[0]===`snapshot`){let e=await i({client:l,command:`diff`,positionals:t,flags:n,env:u.env});return await c(n,e,()=>o(e,u.env,process.stdout)),!0}if(t[0]!==`screenshot`)return!1;let f=n.baseline;if(!f||typeof f!=`string`)throw new e(`INVALID_ARGS`,`diff screenshot requires --baseline <path>`);let p=r(f,{cwd:u.cwd}),h=typeof n.out==`string`?r(n.out,{cwd:u.cwd}):void 0,g=t[1];if(t.length>2)throw new e(`INVALID_ARGS`,`diff screenshot accepts at most one current screenshot path`);let[{createCommandSurfaceAgentDevice:_},{createLocalArtifactAdapter:v}]=await Promise.all([import(`./src9.js`),import(`./sdk-io.js`).then(e=>e.n)]),y=await _({backend:d(l,n),artifacts:v({cwd:u.cwd}),sessions:{get:e=>({name:e}),set:()=>{}},policy:s()}).capture.diffScreenshot({session:n.session,baseline:{kind:`path`,path:p},current:g?{kind:`path`,path:r(g,{cwd:u.cwd})}:{kind:`live`},...h?{out:{kind:`path`,path:h}}:{},threshold:m(n.threshold),overlayRefs:n.overlayRefs,normalizeStatusBar:n.screenshotNormalizeStatusBar,screenMask:n.screenshotScreenMask,surface:n.surface});return await c(n,y,()=>a(y,u,process.stdout)),!0};function d(e,t){return{platform:p(t),captureScreenshot:async(t,r,i)=>{let a=await e.capture.screenshot({path:r,session:t.session,overlayRefs:i?.overlayRefs,pixelDensity:i?.pixelDensity,fullscreen:i?.fullscreen,normalizeStatusBar:i?.normalizeStatusBar,screenMask:i?.screenMask,stabilize:i?.stabilize,surface:i?.surface});return n(a)}}}function f(e){if(typeof e.width!=`number`||typeof e.height!=`number`)return e.path;let t=typeof e.pixelDensity==`number`?` @${e.pixelDensity}x`:``;return`${e.path} (${e.width}x${e.height}${t})`}function p(e){switch(e.platform){case`android`:case`linux`:case`macos`:return e.platform;default:return`ios`}}function m(e){if(e!=null&&e!==``)return Number(e)}export{u as diffCommand,l as screenshotCommand};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";const t=`This replay request carries no script sources. Replay scripts are read by the client and sent with the request; upgrade the agent-device client that issued it to a version that sends script sources.`;function n(t,n){let r=t.files[n];if(r===void 0)throw new e(`INVALID_ARGS`,`replay script source is missing ${n}; it was not part of the script sources sent with this request.`,{path:n,entry:t.entry});return r}export{n,t};
1
+ import{_ as e}from"./sdk-contracts.js";const t=`This replay request carries no script sources. Replay scripts are read by the client and sent with the request; upgrade the agent-device client that issued it to a version that sends script sources.`;function n(t,n){let r=t.files[n];if(r===void 0)throw new e(`INVALID_ARGS`,`replay script source is missing ${n}; it was not part of the script sources sent with this request.`,{path:n,entry:t.entry});return r}export{n,t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{d as t,t as n}from"./screenshot.js";import{h as r}from"./sdk-batch-runner.js";import"./capture.js";import{a as i}from"./sdk-device.js";import{Cr as a,wr as o}from"./sdk-batch.js";import{i as s}from"./recording-export-quality.js";import{c,n as l,o as u,s as d}from"./scroll-gesture.js";import{t as f}from"./gesture-plan-types.js";import{_ as p,g as ee,h as m,n as h,p as te,v as g}from"./open-script.js";const _=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`,`tap`,`drag`],ne=[`points`,`holdMs`,`count`,`pauseMs`];function v(t){let n=S(t),i=D(n,`kind`,_);if(i===`tap`)return re(n);if(ae(i,n),i===`pan`)return{kind:i,origin:C(n,`origin`),delta:C(n,`delta`),pointerCount:r(n,`pointerCount`,{min:1,max:2}),durationMs:x(n)};if(i===`drag`)return b(n);if(n.pointerCount!==void 0)throw new e(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`);if(i===`fling`){if(n.durationMs!==void 0)throw new e(`INVALID_ARGS`,`gesture fling does not accept durationMs; use gesture pan for timed movement`);return{kind:i,direction:D(n,`direction`,l),origin:C(n,`origin`),distance:r(n,`distance`,{min:0})}}if(i===`swipe`){if(n.durationMs!==void 0)throw new e(`INVALID_ARGS`,`gesture swipe does not accept durationMs; use gesture pan for timed movement`);return{kind:i,preset:D(n,`preset`,d)}}if(i===`pinch`)return{kind:i,scale:T(n,`scale`),origin:w(n,`origin`)};if(i===`rotate`){if(n.velocity!==void 0)throw new e(`INVALID_ARGS`,`gesture rotate does not accept velocity; rotation pacing derives from degrees`);return{kind:i,degrees:T(n,`degrees`),origin:w(n,`origin`)}}return{kind:i,origin:C(n,`origin`),delta:C(n,`delta`),scale:T(n,`scale`),degrees:T(n,`degrees`),durationMs:x(n)}}function re(t){if(t.pointerCount!==void 0)throw new e(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`,{hint:`gesture tap takes one contact per point.`});if(t.durationMs!==void 0)throw new e(`INVALID_ARGS`,`gesture tap does not accept durationMs; use holdMs`);let n={kind:`tap`,points:y(t),holdMs:r(t,`holdMs`,{min:16,max:f}),count:r(t,`count`,{min:1,max:200}),pauseMs:r(t,`pauseMs`,{min:0,max:u})};return ie(n),n}function y(t){let n=t.points;if(!Array.isArray(n)||n.length<2||n.length>5)throw new e(`INVALID_ARGS`,`gesture tap requires 2 to 5 points`,{hint:`Use press for a single contact.`});return n.map((t,n)=>{if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`Expected points[${n}] to be a point.`);let r=t;return{x:T(r,`x`),y:T(r,`y`)}})}function ie(t){let n=t.count??1,r=t.pauseMs??0,i=t.holdMs??50,a=n*(i+500)+Math.max(0,n-1)*r;if(!(a<=6e4))throw new e(`INVALID_ARGS`,`gesture tap series must fit within ${c}ms.`,{count:n,pauseMs:r,holdMs:i,overheadAllowanceMs:500,scheduledDurationMs:a,hint:`Reduce --count, --pause-ms or --hold-ms.`})}function ae(t,n){let r=ne.find(e=>n[e]!==void 0);if(r!==void 0)throw new e(`INVALID_ARGS`,`${r} is supported only for gesture tap`,{hint:`gesture ${t} does not read ${r}.`})}function b(t){let n=r(t,`sourceHoldMs`,{min:1,max:1e4}),i=r(t,`moveMs`,{min:16,max:1e4}),a=r(t,`destinationHoldMs`,{min:0,max:1e4});if((n??800)+(i??500)+(a??0)>1e4)throw new e(`INVALID_ARGS`,`gesture drag total duration must be at most ${f}`);return{kind:`drag`,source:E(t,`source`),destination:E(t,`destination`),sourceHoldMs:n,moveMs:i,destinationHoldMs:a}}function x(t){let n=r(t,`durationMs`);if(n!==void 0){if(n<16||n>1e4)throw new e(`INVALID_ARGS`,`Expected durationMs to be an integer between 16 and ${f}.`);return n}}function S(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`gesture requires structured object input`);return t}function C(e,t){let n=S(e[t]);return{x:T(n,`x`),y:T(n,`y`)}}function w(e,t){return e[t]===void 0?void 0:C(e,t)}function T(t,n){let r=t[n];if(typeof r!=`number`||!Number.isFinite(r))throw new e(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);return r}function E(t,n){let r=t[n];if(typeof r!=`string`||r.trim().length===0)throw new e(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r.trim()}function D(t,n,r){let i=t[n];if(typeof i!=`string`||!r.includes(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be one of: ${r.join(`, `)}.`);return i}const O={pointerCount:`--pointer-count`,holdMs:`--hold-ms`,count:`--count`,pauseMs:`--pause-ms`,postGestureStabilization:`--no-post-gesture-stabilization`},k={pan:[`pointerCount`],tap:[`holdMs`,`count`,`pauseMs`],fling:[],swipe:[`postGestureStabilization`],pinch:[],rotate:[],transform:[],drag:[]};function A(e,t,n,r){if(e!==`gesture`)return;let i=t[0];if(i===void 0||!Object.hasOwn(k,i))return;let a=k[i],o=Object.keys(O).filter(e=>n[e]!==void 0&&!a.includes(e));if(o.length!==0)return`gesture ${i} does not read ${o.map(e=>O[e]).join(`, `)} (${r}).`}const j={swipe:{max:4,usage:`swipe accepts 4 arguments: x1 y1 x2 y2`,retired:{positional:`durationMs`,migrate:M}},"gesture pan":{max:5,usage:`gesture pan accepts at most 5 arguments: x y dx dy [durationMs]`},"gesture fling":{max:4,usage:`gesture fling accepts at most 4 arguments: direction x y [distance]`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture swipe":{max:1,usage:`gesture swipe accepts 1 argument: preset`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture pinch":{max:3,usage:`gesture pinch accepts at most 3 arguments: scale [x] [y]`},"gesture rotate":{max:3,usage:`gesture rotate accepts at most 3 arguments: degrees [x] [y]`,retired:{positional:`velocity`,migrate:(e,t)=>`use "${t}"; rotation pacing derives from degrees.`}},"gesture transform":{max:7,usage:`gesture transform accepts at most 7 arguments: x y dx dy scale degrees [durationMs]`},"gesture tap":{min:4,max:10,pairs:!0,usage:`gesture tap accepts 4 to 10 arguments: x1 y1 x2 y2 [x3 y3 [x4 y4 [x5 y5]]]`},"gesture drag":{max:5,usage:`gesture drag accepts at most 5 arguments: source destination [sourceHoldMs] [moveMs] [destinationHoldMs]`}};function M(e,t){let[n,r,i,a,o]=e,s=N(n,i),c=N(r,a);return s===void 0||c===void 0?`use "gesture pan x1 y1 dx dy durationMs" for the same timed drag, or "${t}" for a default-duration swipe.`:`use "gesture pan ${n} ${r} ${s} ${c} ${o}" for the same timed drag, or "${t}" for a default-duration swipe.`}function N(e,t){let n=Number(t)-Number(e);return Number.isFinite(n)?n:void 0}function P(e,t){let n=j[e];if(n.min!==void 0&&t.length<n.min||n.pairs&&t.length%2!=0)return{usage:n.usage};if(t.length<=n.max)return;let r=n.retired;if(!r||t.length!==n.max+1||!oe(t[n.max]))return{usage:n.usage};let i=`${e} ${t.slice(0,n.max).join(` `)}`;return{usage:n.usage,migration:`The trailing ${r.positional} positional was removed: ${r.migrate(t,i)}`}}function oe(e){return e===void 0||e.trim().length===0?!1:e.startsWith("${")||Number.isFinite(Number(e))}function se(t){if(!(!t||typeof t!=`object`||Array.isArray(t))&&t.durationMs!==void 0)throw new e(`INVALID_ARGS`,`swipe does not accept durationMs; use gesture pan for timed movement`)}function F(e,t){let n=t?`${e.usage} (${t})`:e.usage;return e.migration?`${n}. ${e.migration}`:`${n}.`}function I(t,n){let r=P(t,n);if(r)throw new e(`INVALID_ARGS`,F(r))}function L(e,t,n){let r=R(e,t);return r?F(r,n):void 0}function R(e,t){if(e===`swipe`)return P(`swipe`,t);if(e!==`gesture`)return;let n=`gesture ${t[0]}`;if(Object.hasOwn(j,n))return P(n,t.slice(1))}function z(e){return{origin:{x:Number(e[0]),y:Number(e[1])},delta:{x:Number(e[2]),y:Number(e[3])}}}function B(e,t={}){let{pointerCount:n}=t,r=e[0],i=e.slice(1);switch(r){case`pan`:{I(`gesture pan`,i);let{origin:e,delta:t}=z(i);return v({kind:r,origin:e,delta:t,pointerCount:n,durationMs:q(i[4])})}case`fling`:return I(`gesture fling`,i),v({kind:r,direction:i[0],origin:{x:Number(i[1]),y:Number(i[2])},distance:q(i[3])});case`swipe`:return I(`gesture swipe`,i),v({kind:r,preset:i[0]});case`pinch`:return I(`gesture pinch`,i),v({kind:r,scale:Number(i[0]),origin:J(i[1],i[2])});case`rotate`:return I(`gesture rotate`,i),v({kind:r,degrees:Number(i[0]),origin:J(i[1],i[2])});case`transform`:{I(`gesture transform`,i);let{origin:e,delta:t}=z(i);return v({kind:r,origin:e,delta:t,scale:Number(i[4]),degrees:Number(i[5]),durationMs:q(i[6])})}case`tap`:return I(`gesture tap`,i),v({kind:r,points:ce(i),holdMs:t.holdMs,count:t.count,pauseMs:t.pauseMs});case`drag`:return I(`gesture drag`,i),v({kind:r,source:i[0],destination:i[1],sourceHoldMs:q(i[2]),moveMs:q(i[3]),destinationHoldMs:q(i[4])});default:return v({kind:r})}}function V(e){if(e[0]!==`drag`)return;let t=B(e);return t.kind===`drag`?t:void 0}function H(e){switch(e.kind){case`pan`:return Y([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.durationMs]);case`fling`:return Y([e.kind,e.direction,e.origin.x,e.origin.y,e.distance]);case`swipe`:return[e.kind,e.preset];case`pinch`:return Y([e.kind,e.scale,e.origin?.x,e.origin?.y]);case`rotate`:return e.origin?Y([e.kind,e.degrees,e.origin.x,e.origin.y]):[e.kind,String(e.degrees)];case`transform`:return Y([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.scale,e.degrees,e.durationMs]);case`tap`:return[e.kind,...e.points.flatMap(e=>[String(e.x),String(e.y)])];case`drag`:return[e.kind,e.source,e.destination,String(e.sourceHoldMs??800),String(e.moveMs??500),String(e.destinationHoldMs??0)]}}function U(e,t={}){return I(`swipe`,e),{from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},...t.count===void 0?{}:{count:t.count},...t.pauseMs===void 0?{}:{pauseMs:t.pauseMs},...t.pattern===void 0?{}:{pattern:t.pattern}}}function W(t){switch(t.kind){case`pan`:return{gesture:{intent:`pan`,origin:t.origin,delta:t.delta,pointerCount:t.pointerCount,durationMs:t.durationMs}};case`fling`:return{gesture:{intent:`fling`,direction:t.direction,origin:t.origin,distance:t.distance}};case`swipe`:return{gesture:{intent:`fling`,preset:t.preset}};case`pinch`:return{gesture:{intent:`pinch`,origin:t.origin,scale:t.scale}};case`rotate`:return{gesture:{intent:`rotate`,origin:t.origin,degrees:t.degrees}};case`transform`:return{gesture:{intent:`transform`,origin:t.origin,delta:t.delta,scale:t.scale,degrees:t.degrees,durationMs:t.durationMs}};case`tap`:return{gesture:{intent:`tap`,points:t.points,holdMs:t.holdMs}};case`drag`:throw new e(`INVALID_ARGS`,`gesture drag targets must be resolved before coordinate normalization`)}}function G(e){return e.kind===`drag`?{intent:`drag`,source:e.source,destination:e.destination,sourceHoldMs:e.sourceHoldMs,moveMs:e.moveMs,destinationHoldMs:e.destinationHoldMs}:W(e).gesture}function K(e){return{gesture:{intent:`fling`,from:e.from,to:e.to}}}function ce(e){let t=[];for(let n=0;n+1<e.length;n+=2)t.push({x:Number(e[n]),y:Number(e[n+1])});return t}function q(e){return e===void 0?void 0:Number(e)}function J(t,n){if(t===void 0!=(n===void 0))throw new e(`INVALID_ARGS`,`gesture origin requires both x and y coordinates`);return t===void 0?void 0:{x:Number(t),y:Number(n)}}function Y(e){return e.filter(e=>e!==void 0).map(String)}const X=/^[A-Z_][A-Z0-9_]*$/,le=new Set(i.filter(e=>e!==`web`)),ue=new Set([`mobile`,`tv`,`desktop`]);function de(t){let n=[],r=[],i=t.split(/\r?\n/),s=!1,c,l=(t,n,r)=>{let i=t.kind===`multiple`?`targets-v1`:`target-v1`;throw new e(`INVALID_ARGS`,`${i} annotation on line ${t.line} must be immediately followed by its action line (line ${n+1} ${r}).`)};for(let[t,u]of i.entries()){let i=u.trim();if(i.length===0){c&&l(c,t,`is blank`);continue}if(i.startsWith(`#`)){let e=a(i);if(e.kind===`v1`){c&&l(c,t,`is another target annotation`),c={kind:`multiple`,evidence:e.evidence,line:t+1};continue}let n=o(i);if(n.kind===`v1`){c&&l(c,t,`is another target annotation`),c={kind:`single`,evidence:n.evidence,line:t+1};continue}c&&l(c,t,`is a comment`);continue}if(Z(i)){if(c&&l(c,t,`is an env directive`),s)throw new e(`INVALID_ARGS`,`env directives must precede all actions (line ${t+1}).`);continue}let d=ge(u);if(!d){c&&l(c,t,`did not parse as an action`);continue}let f=L(d.command,d.positionals??[],`line ${t+1}`);if(f)throw new e(`INVALID_ARGS`,f);let p=A(d.command,d.positionals??[],d.flags??{},`line ${t+1}`);if(p)throw new e(`INVALID_ARGS`,p);c&&=(c.kind===`single`?d.targetEvidence=c.evidence:d.targetEvidences=c.evidence,void 0),n.push(d),r.push(t+1),s=!0}if(c){let t=c.kind===`multiple`?`targets-v1`:`target-v1`;throw new e(`INVALID_ARGS`,`${t} annotation on line ${c.line} must be immediately followed by its action line (end of script reached).`)}return{actions:n,actionLines:r}}function fe(e){let t=e.split(/\r?\n/),n={};for(let[e,r]of t.entries()){let t=r.trim();if(t.length===0||t.startsWith(`#`))continue;if(Z(t)){he(n,t,e+1);continue}if(!t.startsWith(`context `))break;let i=t.match(/(?:^|\s)platform=([^\s]+)/);if(i){let e=i[1];e&&le.has(e)&&Q(n,`platform`,e)}let a=t.match(/(?:^|\s)target=([^\s]+)/);if(a){let e=a[1];e&&ue.has(e)&&Q(n,`target`,e)}let o=t.match(/(?:^|\s)timeout=(\d+)/);if(o){let e=Number(o[1]);Number.isFinite(e)&&e>=1&&Q(n,`timeoutMs`,Math.floor(e))}let s=t.match(/(?:^|\s)retries=(\d+)/);if(s){let e=Number(s[1]);Number.isFinite(e)&&e>=0&&Q(n,`retries`,Math.floor(e))}}return n}function Z(e){return e===`env`||e.startsWith(`env `)||e.startsWith(`env `)}function pe(t,n){let r=t.slice(3).replace(/^[\s]+/,``),i=r.indexOf(`=`);if(i<=0)throw new e(`INVALID_ARGS`,`Invalid env directive on line ${n}: expected "env KEY=VALUE".`);let a=r.slice(0,i);if(!X.test(a))throw new e(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`);if(a.startsWith(`AD_`))throw new e(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: the AD_* namespace is reserved for built-in variables. Rename ${a} to avoid the AD_ prefix.`);return{key:a,value:me(r.slice(i+1),n)}}function me(t,n){if(t.length===0)return``;if(t.startsWith(`"`))try{let e=JSON.parse(t);if(typeof e!=`string`)throw Error(`not a string literal`);return e}catch{throw new e(`INVALID_ARGS`,`Invalid quoted env value on line ${n}.`)}return t}function he(t,n,r){let{key:i,value:a}=pe(n,r),o=t.env??{};if(Object.prototype.hasOwnProperty.call(o,i))throw new e(`INVALID_ARGS`,`Duplicate env directive "${i}" on line ${r}.`);o[i]=a,t.env=o}function Q(t,n,r){let i=t[n];if(i!==void 0){let t=i===r?`Duplicate replay test metadata "${n}" in context header.`:`Conflicting replay test metadata "${n}" in context header: ${String(i)} vs ${String(r)}.`;throw new e(`INVALID_ARGS`,t)}t[n]=r}function ge(r){let i=r.trim();if(i.length===0||i.startsWith(`#`))return null;let[a,...o]=ve(i);if(a===void 0||a===`context`)return null;let c={ts:Date.now(),command:a,positionals:[],flags:{}};if(a===`snapshot`){c.positionals=[];for(let e=0;e<o.length;e+=1){let t=o[e];if(t===`-i`){c.flags.snapshotInteractiveOnly=!0;continue}if(t!==`-c`){if(t===`--raw`){c.flags.snapshotRaw=!0;continue}if(t===`--force-full`){c.flags.snapshotForceFull=!0;continue}if((t===`-d`||t===`--depth`)&&e+1<o.length){let t=Number(o[e+1]);Number.isFinite(t)&&t>=0&&(c.flags.snapshotDepth=Math.floor(t)),e+=1;continue}if((t===`-s`||t===`--scope`)&&e+1<o.length){c.flags.snapshotScope=o[e+1],e+=1;continue}if(t===`--backend`&&e+1<o.length){e+=1;continue}}}return c}if(a===`open`){let e=h(o);return c.positionals=e.positionals,Object.assign(c.flags,e.flags),c.runtime=e.runtime,c}if(a===`runtime`){let e=ee(o);return c.positionals=e.positionals,Object.assign(c.flags,e.flags),c}if(te(a)){let e=p(a,o);Object.assign(c.flags,e.flags);let t=e.positionals[0];if(t===void 0)return c;if(t.startsWith(`@`))return c.positionals=[g(t)],e.positionals[1]&&(c.result={refLabel:e.positionals[1]}),c;let n=e.positionals[0],r=e.positionals[1];return $(n)&&$(r)&&e.positionals.length>=2?(c.positionals=[n,r],c):(c.positionals=[e.positionals.join(` `)],c)}if(a===`fill`){let e=p(a,o);if(Object.assign(c.flags,e.flags),!_e(e.positionals))return c.positionals=e.positionals,c;let[t,n,...r]=e.positionals;if($(t)&&$(n))return c.positionals=[t,n,r.join(` `)],c;let[i,s,...l]=e.positionals;if(i.startsWith(`@`)){let e=g(i);return l.length>0?(c.positionals=[e,l.join(` `)],c.result={refLabel:s},c):(c.positionals=[e,s],c)}return c.positionals=[i,[s,...l].join(` `)],c}if(a===`get`){let e=o[0],t=o[1];return e===void 0||t===void 0?(c.positionals=o,c):t.startsWith(`@`)?(c.positionals=[e,g(t)],o[2]&&(c.result={refLabel:o[2]}),c):(c.positionals=[e,o.slice(1).join(` `)],c)}if(a===`swipe`||a===`type`||a===`gesture`||a===`fold`){let e=p(a,o);return Object.assign(c.flags,e.flags),c.positionals=e.positionals,c}if(a===`record`){let t=[];for(let r=0;r<o.length;r+=1){let i=o[r];if(i===n.cliToken)throw new e(`INVALID_ARGS`,n.migration.record);if(i===`--hide-touches`){c.flags.hideTouches=!0;continue}if(i===`--fps`&&r+1<o.length){let e=Number(o[r+1]);Number.isFinite(e)&&(c.flags.fps=Math.floor(e)),r+=1;continue}if(i===`--quality`&&r+1<o.length){let e=o[r+1],t=s(e);t!==void 0&&(c.flags.quality=t),r+=1;continue}t.push(i)}return c.positionals=t,c}if(a===`screenshot`){let e=[];for(let n=0;n<o.length;n+=1){let r=o[n],i=t({args:o,index:n,flags:c.flags});if(i.handled){n=i.nextIndex;continue}e.push(r)}return c.positionals=e,c}if(a===`scroll`||a===`wait`){let e=m(a,o);return Object.assign(c.flags,e.flags),c.positionals=e.positionals.map(e=>g(e)),c}return c.positionals=a===`longpress`||a===`hover`?o.map(e=>g(e)):o,c}function _e(e){return e.length>=2}function $(e){return e?!Number.isNaN(Number(e)):!1}function ve(e){let t=[],n=0;for(;n<e.length&&(n=ye(e,n),!(n>=e.length));){let r=e[n]===`"`?be(e,n):xe(e,n)??Ee(e,n);t.push(r.value),n=r.nextCursor}return t}function ye(e,t){let n=t;for(;n<e.length&&/\s/.test(e.charAt(n));)n+=1;return n}function be(t,n){let r=n+1,i=!1,a=r;for(;a<t.length;a+=1){let e=t.charAt(a);if(e===`"`&&!i)break;if(i){i=!1;continue}i=e===`\\`}if(a>=t.length)throw new e(`INVALID_ARGS`,`Invalid replay script line: ${t}`);let o=t.slice(n,a+1),s;try{s=JSON.parse(o)}catch{throw new e(`INVALID_ARGS`,`Invalid quoted value ${o} in replay script line: ${t}`,{hint:`Quoted replay values are JSON strings: escape backslashes, quotes, tabs, and newlines (\\\\, \\", \\t, \\n).`})}return{value:s,nextCursor:a+1}}function xe(e,t){if(e[t]!==`'`)return null;let n=Se(e,t+1);return n===-1||!we(e,n+1)?null:{value:Te(e.slice(t+1,n)),nextCursor:n+1}}function Se(e,t){let n=t;for(;n<e.length;){let t=e.indexOf(`'`,n);if(t===-1)return-1;if(!Ce(e,t))return t;n=t+1}return-1}function Ce(e,t){let n=0;for(;t>0&&e.charAt(t-1)===`\\`;)n+=1,--t;return n%2==1}function we(e,t){return t>=e.length||/\s/.test(e.charAt(t))}function Te(e){return e.replaceAll(String.raw`\'`,`'`)}function Ee(e,t){let n=t;for(;n<e.length&&!/\s/.test(e.charAt(n));)n+=1;return{value:e.slice(t,n),nextCursor:n}}export{se as a,B as c,K as d,U as f,k as i,H as l,v as m,de as n,A as o,_ as p,fe as r,V as s,X as t,G as u};
1
+ import{Dr as e,Er as t}from"./sdk-batch.js";import{_ as n}from"./sdk-contracts.js";import{d as r,t as i}from"./screenshot.js";import{h as a}from"./sdk-batch-runner.js";import"./capture.js";import{a as o}from"./sdk-device.js";import{i as s}from"./recording-export-quality.js";import{c,n as l,o as u,s as d}from"./scroll-gesture.js";import{t as f}from"./gesture-plan-types.js";import{_ as p,g as ee,h as m,n as h,p as te,v as g}from"./open-script.js";const _=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`,`tap`,`drag`],ne=[`points`,`holdMs`,`count`,`pauseMs`];function v(e){let t=S(e),r=D(t,`kind`,_);if(r===`tap`)return re(t);if(ae(r,t),r===`pan`)return{kind:r,origin:C(t,`origin`),delta:C(t,`delta`),pointerCount:a(t,`pointerCount`,{min:1,max:2}),durationMs:x(t)};if(r===`drag`)return b(t);if(t.pointerCount!==void 0)throw new n(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`);if(r===`fling`){if(t.durationMs!==void 0)throw new n(`INVALID_ARGS`,`gesture fling does not accept durationMs; use gesture pan for timed movement`);return{kind:r,direction:D(t,`direction`,l),origin:C(t,`origin`),distance:a(t,`distance`,{min:0})}}if(r===`swipe`){if(t.durationMs!==void 0)throw new n(`INVALID_ARGS`,`gesture swipe does not accept durationMs; use gesture pan for timed movement`);return{kind:r,preset:D(t,`preset`,d)}}if(r===`pinch`)return{kind:r,scale:T(t,`scale`),origin:w(t,`origin`)};if(r===`rotate`){if(t.velocity!==void 0)throw new n(`INVALID_ARGS`,`gesture rotate does not accept velocity; rotation pacing derives from degrees`);return{kind:r,degrees:T(t,`degrees`),origin:w(t,`origin`)}}return{kind:r,origin:C(t,`origin`),delta:C(t,`delta`),scale:T(t,`scale`),degrees:T(t,`degrees`),durationMs:x(t)}}function re(e){if(e.pointerCount!==void 0)throw new n(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`,{hint:`gesture tap takes one contact per point.`});if(e.durationMs!==void 0)throw new n(`INVALID_ARGS`,`gesture tap does not accept durationMs; use holdMs`);let t={kind:`tap`,points:y(e),holdMs:a(e,`holdMs`,{min:16,max:f}),count:a(e,`count`,{min:1,max:200}),pauseMs:a(e,`pauseMs`,{min:0,max:u})};return ie(t),t}function y(e){let t=e.points;if(!Array.isArray(t)||t.length<2||t.length>5)throw new n(`INVALID_ARGS`,`gesture tap requires 2 to 5 points`,{hint:`Use press for a single contact.`});return t.map((e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))throw new n(`INVALID_ARGS`,`Expected points[${t}] to be a point.`);let r=e;return{x:T(r,`x`),y:T(r,`y`)}})}function ie(e){let t=e.count??1,r=e.pauseMs??0,i=e.holdMs??50,a=t*(i+500)+Math.max(0,t-1)*r;if(!(a<=6e4))throw new n(`INVALID_ARGS`,`gesture tap series must fit within ${c}ms.`,{count:t,pauseMs:r,holdMs:i,overheadAllowanceMs:500,scheduledDurationMs:a,hint:`Reduce --count, --pause-ms or --hold-ms.`})}function ae(e,t){let r=ne.find(e=>t[e]!==void 0);if(r!==void 0)throw new n(`INVALID_ARGS`,`${r} is supported only for gesture tap`,{hint:`gesture ${e} does not read ${r}.`})}function b(e){let t=a(e,`sourceHoldMs`,{min:1,max:1e4}),r=a(e,`moveMs`,{min:16,max:1e4}),i=a(e,`destinationHoldMs`,{min:0,max:1e4});if((t??800)+(r??500)+(i??0)>1e4)throw new n(`INVALID_ARGS`,`gesture drag total duration must be at most ${f}`);return{kind:`drag`,source:E(e,`source`),destination:E(e,`destination`),sourceHoldMs:t,moveMs:r,destinationHoldMs:i}}function x(e){let t=a(e,`durationMs`);if(t!==void 0){if(t<16||t>1e4)throw new n(`INVALID_ARGS`,`Expected durationMs to be an integer between 16 and ${f}.`);return t}}function S(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new n(`INVALID_ARGS`,`gesture requires structured object input`);return e}function C(e,t){let n=S(e[t]);return{x:T(n,`x`),y:T(n,`y`)}}function w(e,t){return e[t]===void 0?void 0:C(e,t)}function T(e,t){let r=e[t];if(typeof r!=`number`||!Number.isFinite(r))throw new n(`INVALID_ARGS`,`Expected ${t} to be a finite number.`);return r}function E(e,t){let r=e[t];if(typeof r!=`string`||r.trim().length===0)throw new n(`INVALID_ARGS`,`Expected ${t} to be a non-empty string.`);return r.trim()}function D(e,t,r){let i=e[t];if(typeof i!=`string`||!r.includes(i))throw new n(`INVALID_ARGS`,`Expected ${t} to be one of: ${r.join(`, `)}.`);return i}const O={pointerCount:`--pointer-count`,holdMs:`--hold-ms`,count:`--count`,pauseMs:`--pause-ms`,postGestureStabilization:`--no-post-gesture-stabilization`},k={pan:[`pointerCount`],tap:[`holdMs`,`count`,`pauseMs`],fling:[],swipe:[`postGestureStabilization`],pinch:[],rotate:[],transform:[],drag:[]};function A(e,t,n,r){if(e!==`gesture`)return;let i=t[0];if(i===void 0||!Object.hasOwn(k,i))return;let a=k[i],o=Object.keys(O).filter(e=>n[e]!==void 0&&!a.includes(e));if(o.length!==0)return`gesture ${i} does not read ${o.map(e=>O[e]).join(`, `)} (${r}).`}const j={swipe:{max:4,usage:`swipe accepts 4 arguments: x1 y1 x2 y2`,retired:{positional:`durationMs`,migrate:M}},"gesture pan":{max:5,usage:`gesture pan accepts at most 5 arguments: x y dx dy [durationMs]`},"gesture fling":{max:4,usage:`gesture fling accepts at most 4 arguments: direction x y [distance]`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture swipe":{max:1,usage:`gesture swipe accepts 1 argument: preset`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture pinch":{max:3,usage:`gesture pinch accepts at most 3 arguments: scale [x] [y]`},"gesture rotate":{max:3,usage:`gesture rotate accepts at most 3 arguments: degrees [x] [y]`,retired:{positional:`velocity`,migrate:(e,t)=>`use "${t}"; rotation pacing derives from degrees.`}},"gesture transform":{max:7,usage:`gesture transform accepts at most 7 arguments: x y dx dy scale degrees [durationMs]`},"gesture tap":{min:4,max:10,pairs:!0,usage:`gesture tap accepts 4 to 10 arguments: x1 y1 x2 y2 [x3 y3 [x4 y4 [x5 y5]]]`},"gesture drag":{max:5,usage:`gesture drag accepts at most 5 arguments: source destination [sourceHoldMs] [moveMs] [destinationHoldMs]`}};function M(e,t){let[n,r,i,a,o]=e,s=N(n,i),c=N(r,a);return s===void 0||c===void 0?`use "gesture pan x1 y1 dx dy durationMs" for the same timed drag, or "${t}" for a default-duration swipe.`:`use "gesture pan ${n} ${r} ${s} ${c} ${o}" for the same timed drag, or "${t}" for a default-duration swipe.`}function N(e,t){let n=Number(t)-Number(e);return Number.isFinite(n)?n:void 0}function P(e,t){let n=j[e];if(n.min!==void 0&&t.length<n.min||n.pairs&&t.length%2!=0)return{usage:n.usage};if(t.length<=n.max)return;let r=n.retired;if(!r||t.length!==n.max+1||!oe(t[n.max]))return{usage:n.usage};let i=`${e} ${t.slice(0,n.max).join(` `)}`;return{usage:n.usage,migration:`The trailing ${r.positional} positional was removed: ${r.migrate(t,i)}`}}function oe(e){return e===void 0||e.trim().length===0?!1:e.startsWith("${")||Number.isFinite(Number(e))}function se(e){if(!(!e||typeof e!=`object`||Array.isArray(e))&&e.durationMs!==void 0)throw new n(`INVALID_ARGS`,`swipe does not accept durationMs; use gesture pan for timed movement`)}function F(e,t){let n=t?`${e.usage} (${t})`:e.usage;return e.migration?`${n}. ${e.migration}`:`${n}.`}function I(e,t){let r=P(e,t);if(r)throw new n(`INVALID_ARGS`,F(r))}function L(e,t,n){let r=R(e,t);return r?F(r,n):void 0}function R(e,t){if(e===`swipe`)return P(`swipe`,t);if(e!==`gesture`)return;let n=`gesture ${t[0]}`;if(Object.hasOwn(j,n))return P(n,t.slice(1))}function z(e){return{origin:{x:Number(e[0]),y:Number(e[1])},delta:{x:Number(e[2]),y:Number(e[3])}}}function B(e,t={}){let{pointerCount:n}=t,r=e[0],i=e.slice(1);switch(r){case`pan`:{I(`gesture pan`,i);let{origin:e,delta:t}=z(i);return v({kind:r,origin:e,delta:t,pointerCount:n,durationMs:q(i[4])})}case`fling`:return I(`gesture fling`,i),v({kind:r,direction:i[0],origin:{x:Number(i[1]),y:Number(i[2])},distance:q(i[3])});case`swipe`:return I(`gesture swipe`,i),v({kind:r,preset:i[0]});case`pinch`:return I(`gesture pinch`,i),v({kind:r,scale:Number(i[0]),origin:J(i[1],i[2])});case`rotate`:return I(`gesture rotate`,i),v({kind:r,degrees:Number(i[0]),origin:J(i[1],i[2])});case`transform`:{I(`gesture transform`,i);let{origin:e,delta:t}=z(i);return v({kind:r,origin:e,delta:t,scale:Number(i[4]),degrees:Number(i[5]),durationMs:q(i[6])})}case`tap`:return I(`gesture tap`,i),v({kind:r,points:ce(i),holdMs:t.holdMs,count:t.count,pauseMs:t.pauseMs});case`drag`:return I(`gesture drag`,i),v({kind:r,source:i[0],destination:i[1],sourceHoldMs:q(i[2]),moveMs:q(i[3]),destinationHoldMs:q(i[4])});default:return v({kind:r})}}function V(e){if(e[0]!==`drag`)return;let t=B(e);return t.kind===`drag`?t:void 0}function H(e){switch(e.kind){case`pan`:return Y([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.durationMs]);case`fling`:return Y([e.kind,e.direction,e.origin.x,e.origin.y,e.distance]);case`swipe`:return[e.kind,e.preset];case`pinch`:return Y([e.kind,e.scale,e.origin?.x,e.origin?.y]);case`rotate`:return e.origin?Y([e.kind,e.degrees,e.origin.x,e.origin.y]):[e.kind,String(e.degrees)];case`transform`:return Y([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.scale,e.degrees,e.durationMs]);case`tap`:return[e.kind,...e.points.flatMap(e=>[String(e.x),String(e.y)])];case`drag`:return[e.kind,e.source,e.destination,String(e.sourceHoldMs??800),String(e.moveMs??500),String(e.destinationHoldMs??0)]}}function U(e,t={}){return I(`swipe`,e),{from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},...t.count===void 0?{}:{count:t.count},...t.pauseMs===void 0?{}:{pauseMs:t.pauseMs},...t.pattern===void 0?{}:{pattern:t.pattern}}}function W(e){switch(e.kind){case`pan`:return{gesture:{intent:`pan`,origin:e.origin,delta:e.delta,pointerCount:e.pointerCount,durationMs:e.durationMs}};case`fling`:return{gesture:{intent:`fling`,direction:e.direction,origin:e.origin,distance:e.distance}};case`swipe`:return{gesture:{intent:`fling`,preset:e.preset}};case`pinch`:return{gesture:{intent:`pinch`,origin:e.origin,scale:e.scale}};case`rotate`:return{gesture:{intent:`rotate`,origin:e.origin,degrees:e.degrees}};case`transform`:return{gesture:{intent:`transform`,origin:e.origin,delta:e.delta,scale:e.scale,degrees:e.degrees,durationMs:e.durationMs}};case`tap`:return{gesture:{intent:`tap`,points:e.points,holdMs:e.holdMs}};case`drag`:throw new n(`INVALID_ARGS`,`gesture drag targets must be resolved before coordinate normalization`)}}function G(e){return e.kind===`drag`?{intent:`drag`,source:e.source,destination:e.destination,sourceHoldMs:e.sourceHoldMs,moveMs:e.moveMs,destinationHoldMs:e.destinationHoldMs}:W(e).gesture}function K(e){return{gesture:{intent:`fling`,from:e.from,to:e.to}}}function ce(e){let t=[];for(let n=0;n+1<e.length;n+=2)t.push({x:Number(e[n]),y:Number(e[n+1])});return t}function q(e){return e===void 0?void 0:Number(e)}function J(e,t){if(e===void 0!=(t===void 0))throw new n(`INVALID_ARGS`,`gesture origin requires both x and y coordinates`);return e===void 0?void 0:{x:Number(e),y:Number(t)}}function Y(e){return e.filter(e=>e!==void 0).map(String)}const X=/^[A-Z_][A-Z0-9_]*$/,le=new Set(o.filter(e=>e!==`web`)),ue=new Set([`mobile`,`tv`,`desktop`]);function de(r){let i=[],a=[],o=r.split(/\r?\n/),s=!1,c,l=(e,t,r)=>{let i=e.kind===`multiple`?`targets-v1`:`target-v1`;throw new n(`INVALID_ARGS`,`${i} annotation on line ${e.line} must be immediately followed by its action line (line ${t+1} ${r}).`)};for(let[r,u]of o.entries()){let o=u.trim();if(o.length===0){c&&l(c,r,`is blank`);continue}if(o.startsWith(`#`)){let n=t(o);if(n.kind===`v1`){c&&l(c,r,`is another target annotation`),c={kind:`multiple`,evidence:n.evidence,line:r+1};continue}let i=e(o);if(i.kind===`v1`){c&&l(c,r,`is another target annotation`),c={kind:`single`,evidence:i.evidence,line:r+1};continue}c&&l(c,r,`is a comment`);continue}if(Z(o)){if(c&&l(c,r,`is an env directive`),s)throw new n(`INVALID_ARGS`,`env directives must precede all actions (line ${r+1}).`);continue}let d=ge(u);if(!d){c&&l(c,r,`did not parse as an action`);continue}let f=L(d.command,d.positionals??[],`line ${r+1}`);if(f)throw new n(`INVALID_ARGS`,f);let p=A(d.command,d.positionals??[],d.flags??{},`line ${r+1}`);if(p)throw new n(`INVALID_ARGS`,p);c&&=(c.kind===`single`?d.targetEvidence=c.evidence:d.targetEvidences=c.evidence,void 0),i.push(d),a.push(r+1),s=!0}if(c){let e=c.kind===`multiple`?`targets-v1`:`target-v1`;throw new n(`INVALID_ARGS`,`${e} annotation on line ${c.line} must be immediately followed by its action line (end of script reached).`)}return{actions:i,actionLines:a}}function fe(e){let t=e.split(/\r?\n/),n={};for(let[e,r]of t.entries()){let t=r.trim();if(t.length===0||t.startsWith(`#`))continue;if(Z(t)){he(n,t,e+1);continue}if(!t.startsWith(`context `))break;let i=t.match(/(?:^|\s)platform=([^\s]+)/);if(i){let e=i[1];e&&le.has(e)&&Q(n,`platform`,e)}let a=t.match(/(?:^|\s)target=([^\s]+)/);if(a){let e=a[1];e&&ue.has(e)&&Q(n,`target`,e)}let o=t.match(/(?:^|\s)timeout=(\d+)/);if(o){let e=Number(o[1]);Number.isFinite(e)&&e>=1&&Q(n,`timeoutMs`,Math.floor(e))}let s=t.match(/(?:^|\s)retries=(\d+)/);if(s){let e=Number(s[1]);Number.isFinite(e)&&e>=0&&Q(n,`retries`,Math.floor(e))}}return n}function Z(e){return e===`env`||e.startsWith(`env `)||e.startsWith(`env `)}function pe(e,t){let r=e.slice(3).replace(/^[\s]+/,``),i=r.indexOf(`=`);if(i<=0)throw new n(`INVALID_ARGS`,`Invalid env directive on line ${t}: expected "env KEY=VALUE".`);let a=r.slice(0,i);if(!X.test(a))throw new n(`INVALID_ARGS`,`Invalid env key "${a}" on line ${t}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`);if(a.startsWith(`AD_`))throw new n(`INVALID_ARGS`,`Invalid env key "${a}" on line ${t}: the AD_* namespace is reserved for built-in variables. Rename ${a} to avoid the AD_ prefix.`);return{key:a,value:me(r.slice(i+1),t)}}function me(e,t){if(e.length===0)return``;if(e.startsWith(`"`))try{let t=JSON.parse(e);if(typeof t!=`string`)throw Error(`not a string literal`);return t}catch{throw new n(`INVALID_ARGS`,`Invalid quoted env value on line ${t}.`)}return e}function he(e,t,r){let{key:i,value:a}=pe(t,r),o=e.env??{};if(Object.prototype.hasOwnProperty.call(o,i))throw new n(`INVALID_ARGS`,`Duplicate env directive "${i}" on line ${r}.`);o[i]=a,e.env=o}function Q(e,t,r){let i=e[t];if(i!==void 0){let e=i===r?`Duplicate replay test metadata "${t}" in context header.`:`Conflicting replay test metadata "${t}" in context header: ${String(i)} vs ${String(r)}.`;throw new n(`INVALID_ARGS`,e)}e[t]=r}function ge(e){let t=e.trim();if(t.length===0||t.startsWith(`#`))return null;let[a,...o]=ve(t);if(a===void 0||a===`context`)return null;let c={ts:Date.now(),command:a,positionals:[],flags:{}};if(a===`snapshot`){c.positionals=[];for(let e=0;e<o.length;e+=1){let t=o[e];if(t===`-i`){c.flags.snapshotInteractiveOnly=!0;continue}if(t!==`-c`){if(t===`--raw`){c.flags.snapshotRaw=!0;continue}if(t===`--force-full`){c.flags.snapshotForceFull=!0;continue}if((t===`-d`||t===`--depth`)&&e+1<o.length){let t=Number(o[e+1]);Number.isFinite(t)&&t>=0&&(c.flags.snapshotDepth=Math.floor(t)),e+=1;continue}if((t===`-s`||t===`--scope`)&&e+1<o.length){c.flags.snapshotScope=o[e+1],e+=1;continue}if(t===`--backend`&&e+1<o.length){e+=1;continue}}}return c}if(a===`open`){let e=h(o);return c.positionals=e.positionals,Object.assign(c.flags,e.flags),c.runtime=e.runtime,c}if(a===`runtime`){let e=ee(o);return c.positionals=e.positionals,Object.assign(c.flags,e.flags),c}if(te(a)){let e=p(a,o);Object.assign(c.flags,e.flags);let t=e.positionals[0];if(t===void 0)return c;if(t.startsWith(`@`))return c.positionals=[g(t)],e.positionals[1]&&(c.result={refLabel:e.positionals[1]}),c;let n=e.positionals[0],r=e.positionals[1];return $(n)&&$(r)&&e.positionals.length>=2?(c.positionals=[n,r],c):(c.positionals=[e.positionals.join(` `)],c)}if(a===`fill`){let e=p(a,o);if(Object.assign(c.flags,e.flags),!_e(e.positionals))return c.positionals=e.positionals,c;let[t,n,...r]=e.positionals;if($(t)&&$(n))return c.positionals=[t,n,r.join(` `)],c;let[i,s,...l]=e.positionals;if(i.startsWith(`@`)){let e=g(i);return l.length>0?(c.positionals=[e,l.join(` `)],c.result={refLabel:s},c):(c.positionals=[e,s],c)}return c.positionals=[i,[s,...l].join(` `)],c}if(a===`get`){let e=o[0],t=o[1];return e===void 0||t===void 0?(c.positionals=o,c):t.startsWith(`@`)?(c.positionals=[e,g(t)],o[2]&&(c.result={refLabel:o[2]}),c):(c.positionals=[e,o.slice(1).join(` `)],c)}if(a===`swipe`||a===`type`||a===`gesture`||a===`fold`){let e=p(a,o);return Object.assign(c.flags,e.flags),c.positionals=e.positionals,c}if(a===`record`){let e=[];for(let t=0;t<o.length;t+=1){let r=o[t];if(r===i.cliToken)throw new n(`INVALID_ARGS`,i.migration.record);if(r===`--hide-touches`){c.flags.hideTouches=!0;continue}if(r===`--fps`&&t+1<o.length){let e=Number(o[t+1]);Number.isFinite(e)&&(c.flags.fps=Math.floor(e)),t+=1;continue}if(r===`--quality`&&t+1<o.length){let e=o[t+1],n=s(e);n!==void 0&&(c.flags.quality=n),t+=1;continue}e.push(r)}return c.positionals=e,c}if(a===`screenshot`){let e=[];for(let t=0;t<o.length;t+=1){let n=o[t],i=r({args:o,index:t,flags:c.flags});if(i.handled){t=i.nextIndex;continue}e.push(n)}return c.positionals=e,c}if(a===`scroll`||a===`wait`){let e=m(a,o);return Object.assign(c.flags,e.flags),c.positionals=e.positionals.map(e=>g(e)),c}return c.positionals=a===`longpress`||a===`hover`?o.map(e=>g(e)):o,c}function _e(e){return e.length>=2}function $(e){return e?!Number.isNaN(Number(e)):!1}function ve(e){let t=[],n=0;for(;n<e.length&&(n=ye(e,n),!(n>=e.length));){let r=e[n]===`"`?be(e,n):xe(e,n)??Ee(e,n);t.push(r.value),n=r.nextCursor}return t}function ye(e,t){let n=t;for(;n<e.length&&/\s/.test(e.charAt(n));)n+=1;return n}function be(e,t){let r=t+1,i=!1,a=r;for(;a<e.length;a+=1){let t=e.charAt(a);if(t===`"`&&!i)break;if(i){i=!1;continue}i=t===`\\`}if(a>=e.length)throw new n(`INVALID_ARGS`,`Invalid replay script line: ${e}`);let o=e.slice(t,a+1),s;try{s=JSON.parse(o)}catch{throw new n(`INVALID_ARGS`,`Invalid quoted value ${o} in replay script line: ${e}`,{hint:`Quoted replay values are JSON strings: escape backslashes, quotes, tabs, and newlines (\\\\, \\", \\t, \\n).`})}return{value:s,nextCursor:a+1}}function xe(e,t){if(e[t]!==`'`)return null;let n=Se(e,t+1);return n===-1||!we(e,n+1)?null:{value:Te(e.slice(t+1,n)),nextCursor:n+1}}function Se(e,t){let n=t;for(;n<e.length;){let t=e.indexOf(`'`,n);if(t===-1)return-1;if(!Ce(e,t))return t;n=t+1}return-1}function Ce(e,t){let n=0;for(;t>0&&e.charAt(t-1)===`\\`;)n+=1,--t;return n%2==1}function we(e,t){return t>=e.length||/\s/.test(e.charAt(t))}function Te(e){return e.replaceAll(String.raw`\'`,`'`)}function Ee(e,t){let n=t;for(;n<e.length&&!/\s/.test(e.charAt(n));)n+=1;return{value:e.slice(t,n),nextCursor:n}}export{se as a,B as c,K as d,U as f,k as i,H as l,v as m,de as n,A as o,_ as p,fe as r,V as s,X as t,G as u};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";const t=1e4,n=.65;function r(e,t){return{...e,releaseBehavior:t===void 0?`controlled`:`inertial`}}function i(t,n=`scroll accepts either a relative amount or --pixels, not both`){if(t.amount!==void 0&&t.pixels!==void 0)throw new e(`INVALID_ARGS`,n)}function a(t){if(t.maxPasses!==void 0){if(t.until===void 0)throw new e(`INVALID_ARGS`,`scroll maxPasses requires until`,{reason:`scroll_max_passes_requires_until`});if(!Number.isInteger(t.maxPasses)||t.maxPasses<1||t.maxPasses>200)throw new e(`INVALID_ARGS`,`scroll maxPasses must be an integer from 1 to 200`,{reason:`scroll_max_passes_invalid`})}if(t.until!==void 0&&t.edge!==void 0)throw new e(`INVALID_ARGS`,`scroll ${t.edge} already scrolls to the ${t.edge} edge and cannot take --until`,{hint:`Use scroll ${t.edge===`bottom`?`down`:`up`} --until <selector> to stop at the target, or scroll ${t.edge} to reach the edge.`})}function o(t,n={}){if(t===void 0)return;let r=n.field??`scroll durationMs`,i=n.max??1e4,a=n.invalidMessage??`${r} must be a non-negative integer`;if(!Number.isFinite(t)||!Number.isInteger(t)||t<0)throw new e(`INVALID_ARGS`,a);if(t>i)throw new e(`INVALID_ARGS`,`${r} must be a non-negative integer at most ${i}`);return t}export{o as a,a as i,t as n,r as o,i as r,n as t};
1
+ import{_ as e}from"./sdk-contracts.js";const t=1e4,n=.65;function r(e,t){return{...e,releaseBehavior:t===void 0?`controlled`:`inertial`}}function i(t,n=`scroll accepts either a relative amount or --pixels, not both`){if(t.amount!==void 0&&t.pixels!==void 0)throw new e(`INVALID_ARGS`,n)}function a(t){if(t.maxPasses!==void 0){if(t.until===void 0)throw new e(`INVALID_ARGS`,`scroll maxPasses requires until`,{reason:`scroll_max_passes_requires_until`});if(!Number.isInteger(t.maxPasses)||t.maxPasses<1||t.maxPasses>200)throw new e(`INVALID_ARGS`,`scroll maxPasses must be an integer from 1 to 200`,{reason:`scroll_max_passes_invalid`})}if(t.until!==void 0&&t.edge!==void 0)throw new e(`INVALID_ARGS`,`scroll ${t.edge} already scrolls to the ${t.edge} edge and cannot take --until`,{hint:`Use scroll ${t.edge===`bottom`?`down`:`up`} --until <selector> to stop at the target, or scroll ${t.edge} to reach the edge.`})}function o(t,n={}){if(t===void 0)return;let r=n.field??`scroll durationMs`,i=n.max??1e4,a=n.invalidMessage??`${r} must be a non-negative integer`;if(!Number.isFinite(t)||!Number.isInteger(t)||t<0)throw new e(`INVALID_ARGS`,a);if(t>i)throw new e(`INVALID_ARGS`,`${r} must be a non-negative integer at most ${i}`);return t}export{o as a,a as i,t as n,r as o,i as r,n as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{ei as t}from"./sdk-batch.js";import{t as n}from"./string-enum.js";const r=[`up`,`down`,`left`,`right`,`top`,`bottom`],i=[`up`,`down`,`left`,`right`],a=[`left`,`right`,`left-edge`,`right-edge`],o=new Set([`left-edge`,`right-edge`]);function s(e){return o.has(e)}const c=[`one-way`,`ping-pong`],l=1e4,u=6e4,d=n(i,{message:e=>`Unknown direction: ${e}`}),f=.6;function p(e){let t=e.direction,n=t===`up`||t===`down`,r=n?e.referenceHeight:e.referenceWidth,i=n?e.referenceWidth:e.referenceHeight,a=O(e.amount),o=e.pixels===void 0?Math.round(r*a):k(e.pixels),s=h(r),c=Math.max(1,r-s*2),l=Math.max(1,Math.min(o,c)),u=Math.round(l/2),d=Math.round(r/2),f={axisStart:d-u,axisEnd:d+u,cross:Math.round(i/2)},p=h(i),_=e.container?g(f,e.container,n,{axis:{min:s,max:r-s},cross:{min:p,max:i-p},crossFrame:{min:0,max:i}}):f,v=_.axisEnd-_.axisStart,y=v<l;return{direction:t,...m(t,_),referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:y?v:l,...y?{requestedPixels:l}:{}}}function m(e,t){let n=e===`up`||e===`down`,r=n?{x:t.cross,y:t.axisStart}:{x:t.axisStart,y:t.cross},i=n?{x:t.cross,y:t.axisEnd}:{x:t.axisEnd,y:t.cross},[a,o]=e===`up`||e===`left`?[r,i]:[i,r];return{x1:a.x,y1:a.y,x2:o.x,y2:o.y}}function h(e){return Math.max(1,Math.round(e*.1))}function g(e,t,n,r){let i=_(n?t.y:t.x,n?t.height:t.width,r.axis),a=n?t.x:t.y,o=n?t.width:t.height,s=_(a,o,r.cross)??_(a,o,r.crossFrame);if(!i||!s)return e;let c=e.cross>=s.min&&e.cross<=s.max?e.cross:Math.round((s.min+s.max)/2);if(e.axisEnd-e.axisStart>=i.max-i.min)return{axisStart:i.min,axisEnd:i.max,cross:c};let l=e.axisStart<i.min?i.min-e.axisStart:Math.min(0,i.max-e.axisEnd);return{axisStart:e.axisStart+l,axisEnd:e.axisEnd+l,cross:c}}function _(e,t,n){let r=Math.max(n.min,Math.ceil(e)+8),i=Math.min(n.max,Math.floor(e+t)-1-8);return i>r?{min:r,max:i}:void 0}function v(e){O(e.amount),e.pixels!==void 0&&k(e.pixels)}function y(e,t){if(e===`left`||e===`right`){let n=x(e,t);return{preset:e,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,referenceWidth:n.referenceWidth,referenceHeight:n.referenceHeight}}let[n,r]=e===`left-edge`?[99,15]:[1,85],i=w(C(t,n,50),t,8),a=w(C(t,r,50),t,8);return{preset:e,x1:i.x,y1:i.y,x2:a.x,y2:a.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function b(e,t){switch(e){case`up`:return{x:0,y:-t};case`down`:return{x:0,y:t};case`left`:return{x:-t,y:0};case`right`:return{x:t,y:0}}}function x(e,t){let n=e===`left`||e===`up`,r=n?85:15,i=n?15:85,a=e===`up`||e===`down`,o=w(C(t,a?50:r,a?r:50),t,8),s=w(C(t,a?50:i,a?i:50),t,8);return{direction:e,x1:o.x,y1:o.y,x2:s.x,y2:s.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function S(e){let t=E(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function C(e,t,n){let r=Math.trunc(e.referenceWidth*t/100),i=Math.trunc(e.referenceHeight*n/100);return{x:Number.isFinite(r)?r:0,y:Number.isFinite(i)?i:0}}function w(e,t,n){return{x:A(e.x,n,t.referenceWidth),y:A(e.y,n,t.referenceHeight)}}function T(e){return d.parse(e)}function E(e){let n=e.filter(e=>t(e)&&D(e.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(n)return n;let r=e.map(e=>e.rect).filter(D);if(r.length===0)return;let i=Math.max(...r.map(e=>e.x+e.width)),a=Math.max(...r.map(e=>e.y+e.height));if(!(i<=0||a<=0))return{x:0,y:0,width:i,height:a}}function D(e){return!!e&&e.width>0&&e.height>0}function O(t){if(t===void 0)return f;if(!Number.isFinite(t)||t<=0)throw new e(`INVALID_ARGS`,`scroll amount must be a positive number`);return t}function k(t){if(!Number.isFinite(t)||t<=0)throw new e(`INVALID_ARGS`,`scroll pixels must be a positive integer`);return Math.max(1,Math.round(t))}function A(e,t,n){let r=Math.round(t);if(!Number.isFinite(r))return 0;let i=Math.max(r,Math.round(n-t));return!Number.isFinite(i)||!Number.isFinite(e)?r:Math.min(i,Math.max(r,Math.round(e)))}const j=Object.freeze({reason:`scroll_keyboard_occludes_surface`,hint:"The on-screen keyboard covers the surface this scroll would swipe, so it cannot reach it. Run `keyboard dismiss` and retry, accepting that it drops focus (re-tap the field to keep typing), or scroll before focusing the field."});function M(e,t){if(!P(e)||!P(t))return{kind:`unobstructed`};let n=e.x+e.width/2;if(n<t.x||n>=t.x+t.width)return{kind:`unobstructed`};let r=t.y;if(r>=e.y+e.height||t.y+t.height<=e.y)return{kind:`unobstructed`};let i=Math.max(0,r-12-e.y);return i<.15*e.height?{kind:`occluded`,keyboardMinY:r,visibleHeight:i}:{kind:`avoided`,viewport:{...e,height:i},keyboardMinY:r}}function N(t,n){return new e(`COMMAND_FAILED`,`scroll ${t} refused: the keyboard leaves ${n.visibleHeight}px of ${n.viewportHeight}px visible, below the 15% needed for a swipe`,{keyboardMinY:n.keyboardMinY,visibleHeight:n.visibleHeight,viewportHeight:n.viewportHeight,minVisibleFraction:.15,...j})}function P(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}export{T as _,c as a,u as c,p as d,y as f,s as g,S as h,j as i,v as l,b as m,i as n,l as o,M as p,r,a as s,f as t,x as u,N as v};
1
+ import{ii as e}from"./sdk-batch.js";import{_ as t}from"./sdk-contracts.js";import{t as n}from"./string-enum.js";const r=[`up`,`down`,`left`,`right`,`top`,`bottom`],i=[`up`,`down`,`left`,`right`],a=[`left`,`right`,`left-edge`,`right-edge`],o=new Set([`left-edge`,`right-edge`]);function s(e){return o.has(e)}const c=[`one-way`,`ping-pong`],l=1e4,u=6e4,d=n(i,{message:e=>`Unknown direction: ${e}`}),f=.6;function p(e){let t=e.direction,n=t===`up`||t===`down`,r=n?e.referenceHeight:e.referenceWidth,i=n?e.referenceWidth:e.referenceHeight,a=O(e.amount),o=e.pixels===void 0?Math.round(r*a):k(e.pixels),s=h(r),c=Math.max(1,r-s*2),l=Math.max(1,Math.min(o,c)),u=Math.round(l/2),d=Math.round(r/2),f={axisStart:d-u,axisEnd:d+u,cross:Math.round(i/2)},p=h(i),_=e.container?g(f,e.container,n,{axis:{min:s,max:r-s},cross:{min:p,max:i-p},crossFrame:{min:0,max:i}}):f,v=_.axisEnd-_.axisStart,y=v<l;return{direction:t,...m(t,_),referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:y?v:l,...y?{requestedPixels:l}:{}}}function m(e,t){let n=e===`up`||e===`down`,r=n?{x:t.cross,y:t.axisStart}:{x:t.axisStart,y:t.cross},i=n?{x:t.cross,y:t.axisEnd}:{x:t.axisEnd,y:t.cross},[a,o]=e===`up`||e===`left`?[r,i]:[i,r];return{x1:a.x,y1:a.y,x2:o.x,y2:o.y}}function h(e){return Math.max(1,Math.round(e*.1))}function g(e,t,n,r){let i=_(n?t.y:t.x,n?t.height:t.width,r.axis),a=n?t.x:t.y,o=n?t.width:t.height,s=_(a,o,r.cross)??_(a,o,r.crossFrame);if(!i||!s)return e;let c=e.cross>=s.min&&e.cross<=s.max?e.cross:Math.round((s.min+s.max)/2);if(e.axisEnd-e.axisStart>=i.max-i.min)return{axisStart:i.min,axisEnd:i.max,cross:c};let l=e.axisStart<i.min?i.min-e.axisStart:Math.min(0,i.max-e.axisEnd);return{axisStart:e.axisStart+l,axisEnd:e.axisEnd+l,cross:c}}function _(e,t,n){let r=Math.max(n.min,Math.ceil(e)+8),i=Math.min(n.max,Math.floor(e+t)-1-8);return i>r?{min:r,max:i}:void 0}function v(e){O(e.amount),e.pixels!==void 0&&k(e.pixels)}function y(e,t){if(e===`left`||e===`right`){let n=x(e,t);return{preset:e,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,referenceWidth:n.referenceWidth,referenceHeight:n.referenceHeight}}let[n,r]=e===`left-edge`?[99,15]:[1,85],i=w(C(t,n,50),t,8),a=w(C(t,r,50),t,8);return{preset:e,x1:i.x,y1:i.y,x2:a.x,y2:a.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function b(e,t){switch(e){case`up`:return{x:0,y:-t};case`down`:return{x:0,y:t};case`left`:return{x:-t,y:0};case`right`:return{x:t,y:0}}}function x(e,t){let n=e===`left`||e===`up`,r=n?85:15,i=n?15:85,a=e===`up`||e===`down`,o=w(C(t,a?50:r,a?r:50),t,8),s=w(C(t,a?50:i,a?i:50),t,8);return{direction:e,x1:o.x,y1:o.y,x2:s.x,y2:s.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function S(e){let t=E(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function C(e,t,n){let r=Math.trunc(e.referenceWidth*t/100),i=Math.trunc(e.referenceHeight*n/100);return{x:Number.isFinite(r)?r:0,y:Number.isFinite(i)?i:0}}function w(e,t,n){return{x:A(e.x,n,t.referenceWidth),y:A(e.y,n,t.referenceHeight)}}function T(e){return d.parse(e)}function E(t){let n=t.filter(t=>e(t)&&D(t.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(n)return n;let r=t.map(e=>e.rect).filter(D);if(r.length===0)return;let i=Math.max(...r.map(e=>e.x+e.width)),a=Math.max(...r.map(e=>e.y+e.height));if(!(i<=0||a<=0))return{x:0,y:0,width:i,height:a}}function D(e){return!!e&&e.width>0&&e.height>0}function O(e){if(e===void 0)return f;if(!Number.isFinite(e)||e<=0)throw new t(`INVALID_ARGS`,`scroll amount must be a positive number`);return e}function k(e){if(!Number.isFinite(e)||e<=0)throw new t(`INVALID_ARGS`,`scroll pixels must be a positive integer`);return Math.max(1,Math.round(e))}function A(e,t,n){let r=Math.round(t);if(!Number.isFinite(r))return 0;let i=Math.max(r,Math.round(n-t));return!Number.isFinite(i)||!Number.isFinite(e)?r:Math.min(i,Math.max(r,Math.round(e)))}const j=Object.freeze({reason:`scroll_keyboard_occludes_surface`,hint:"The on-screen keyboard covers the surface this scroll would swipe, so it cannot reach it. Run `keyboard dismiss` and retry, accepting that it drops focus (re-tap the field to keep typing), or scroll before focusing the field."});function M(e,t){if(!P(e)||!P(t))return{kind:`unobstructed`};let n=e.x+e.width/2;if(n<t.x||n>=t.x+t.width)return{kind:`unobstructed`};let r=t.y;if(r>=e.y+e.height||t.y+t.height<=e.y)return{kind:`unobstructed`};let i=Math.max(0,r-12-e.y);return i<.15*e.height?{kind:`occluded`,keyboardMinY:r,visibleHeight:i}:{kind:`avoided`,viewport:{...e,height:i},keyboardMinY:r}}function N(e,n){return new t(`COMMAND_FAILED`,`scroll ${e} refused: the keyboard leaves ${n.visibleHeight}px of ${n.viewportHeight}px visible, below the 15% needed for a swipe`,{keyboardMinY:n.keyboardMinY,visibleHeight:n.visibleHeight,viewportHeight:n.viewportHeight,minVisibleFraction:.15,...j})}function P(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}export{T as _,c as a,u as c,p as d,y as f,s as g,S as h,j as i,v as l,b as m,i as n,l as o,M as p,r,a as s,f as t,x as u,N as v};
@@ -1,4 +1,4 @@
1
- import { a as DaemonRequest, o as DaemonResponse, v as SessionRuntimeHints } from "./sdk-contracts.js";
1
+ import { a as DaemonRequest, o as DaemonResponse, y as SessionRuntimeHints } from "./sdk-contracts.js";
2
2
  //#region packages/contracts/src/batch-step.d.ts
3
3
  /**
4
4
  * One step of a daemon batch, as submitted.
@@ -1,2 +1,2 @@
1
- import{P as e,R as t,c as n,f as r,o as i}from"./sdk-contracts.js";import{a,n as o,o as s,r as c,w as l}from"./sdk-batch.js";function u(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function d(t,n,r,i){let a=r(t[n]);if(a===void 0)throw new e(`COMMAND_FAILED`,i,{response:t});return a}function f(e,t,n){return n(e[t])}function p(e,t,n){let r=e[t];return r===null?null:n(r)}function m(e,t){return d(e,t,E,`Daemon response is missing "${t}".`)}function ee(e,t){return f(e,t,E)}function te(e,t){return p(e,t,E)}function h(e,t){return d(e,t,D,`Daemon response is missing numeric "${t}".`)}function g(e,t){return d(e,t,O,`Daemon response has invalid "${t}".`)}function _(e,t){return d(e,t,k,`Daemon response has invalid "${t}".`)}function v(e,t){return f(e,t,A)??`mobile`}function y(e){if(!M(e))return;let t=T(e,`x`),n=T(e,`y`),r=T(e,`width`),i=T(e,`height`);if(t!==void 0&&n!==void 0&&r!==void 0&&i!==void 0)return{x:t,y:n,width:r,height:i}}function ne(e){if(e!==void 0)return M(e)?e.kind===`absent`?{kind:`absent`,...b(e)}:e.kind===`unmeasurable`?typeof e.reason==`string`&&e.reason.trim().length>0?{kind:`unmeasurable`,reason:e.reason}:{kind:`unmeasurable`,reason:`unreported-reason`}:e.kind===`tree-rejected`?x(e):e.kind===`visibility-only`?typeof e.visible==`boolean`?{kind:`visibility-only`,visible:e.visible}:{kind:`unmeasurable`,reason:`invalid-visibility-probe`}:e.kind===`derived`&&e.derivation!==`docked-tree`?{kind:`unmeasurable`,reason:`unrecognized-derivation`}:e.kind===`visible`||e.kind===`derived`?S(e.frame,e.kind,b(e)):{kind:`unmeasurable`,reason:`unrecognized-kind`}:{kind:`unmeasurable`,reason:`malformed-fact`}}function b(e){return e.treeBound===!0?{treeBound:!0}:{}}function x(e){return e.derivation===`docked-tree`?e.visible!==void 0&&typeof e.visible!=`boolean`?{kind:`unmeasurable`,reason:`invalid-visibility-probe`}:{kind:`tree-rejected`,derivation:`docked-tree`,...typeof e.visible==`boolean`?{visible:e.visible}:{}}:{kind:`unmeasurable`,reason:`unrecognized-derivation`}}function S(e,t,n){let r=y(e);return re(r)?t===`derived`?{kind:`derived`,derivation:`docked-tree`,frame:r,...n}:{kind:`visible`,frame:r,...n}:{kind:`unmeasurable`,reason:`invalid-${t}-frame`}}function re(e){if(!e)return!1;let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||!Number.isFinite(t+r)||!Number.isFinite(n+i)||r<=0||i<=0?!1:t!==-Number.MAX_VALUE/2||n!==-Number.MAX_VALUE/2||r!==Number.MAX_VALUE||i!==Number.MAX_VALUE}const C={presented:`presented`,absent:`absent`,unknown:`unknown`},w=`presentedSurface`;function ie(e){if(!Object.hasOwn(e,w))return;let t=e[w];return typeof t==`string`&&Object.hasOwn(C,t)?C[t]:`unknown`}function ae(e){if(!M(e))return;let t=T(e,`x`),n=T(e,`y`);if(t!==void 0&&n!==void 0)return{x:t,y:n}}function T(e,t){let n=e[t];return typeof n==`number`?n:void 0}function E(e){return typeof e==`string`&&e.length>0?e:void 0}function D(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function O(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`harmonyos`||e===`vega`||e===`linux`||e===`web`?e:void 0}function k(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function A(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function j(t){if(!M(t))throw new e(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:t});return t}function M(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function N(e){return M(e)?e:void 0}function P(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function F(e){return e.split(`
2
- `).map(e=>e.trim()).filter(e=>e.length>0)}function I(t,n,r={}){let i=t[n];if(i===void 0)return;if(!Number.isInteger(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be an integer.`);let a=i;if(r.min!==void 0&&a<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&a>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return a}function L(t,n,r={}){let i=t[n];if(i!==void 0){if(typeof i!=`number`||!Number.isFinite(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);if(r.min!==void 0&&i<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&i>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return i}}const R=`android_shell_text_unsupported`;function z(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function B(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}const V=`Each batch step is {"command":"<name>","input":{...}}, where input is that command's own structured input object, keyed by field name. There is no positional step form: args, argv, positionals, and flags are not step fields.`;function H(t,n,r=V){if(!u(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`,{hint:r});return t}function U(t,n,r=V){let i=t.input;if(!u(i))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`,{hint:r});return i}function W(t,n){if(t!==void 0)try{return i.parse(t)}catch(t){throw new e(`INVALID_ARGS`,`Batch step ${n} runtime is invalid: ${t instanceof Error?t.message:String(t)}`)}}function G(e){let t=e.trim();if(!t||/\s/.test(t))return!1;let n=/^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(t);if(!n)return!1;let r=n[1]?.toLowerCase(),i=n[2]??``;return r===`http`||r===`https`||r===`ws`||r===`wss`||r===`ftp`||r===`ftps`?i.startsWith(`//`):!0}function K(e){let t=e.trim().split(`:`)[0]?.toLowerCase();return t===`http`||t===`https`}const q=`com.apple.mobilesafari`;function J(e,t){let n=e?.trim();if(n)return n;if(K(t))return q}const oe=new Set(o);async function se(e,n,r){let i=Q(e.flags),a=i?.batchOnError??`stop`;if(a!==`stop`)return $(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=i?.batchMaxSteps??100;if(!z(o))return $(`INVALID_ARGS`,`Invalid batch max-steps: ${String(i?.batchMaxSteps)}`);try{let t=Y(i?.batchSteps,o),a=Date.now(),s=[];for(let[i,a]of t.entries()){let o=await pe(e,n,a,r,{stepNumber:i+1,totalSteps:t.length,remainingSteps:t.slice(i+1).map(e=>({command:e.command,positionals:e.positionals,flags:e.flags,...e.input===void 0?{}:{input:e.input}}))});if(!o.ok)return ce(o,a,{executedSteps:t.slice(0,i),total:t.length,partialResults:s});s.push(o.result)}return{ok:!0,data:{total:t.length,executed:t.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let n=t(e);return $(n.code,n.message,n.details)}}function ce(e,t,n){let{error:r}=e;return{ok:!1,error:{code:r.code,message:`Batch failed at step ${e.step} (${t.command}): ${r.message}`,hint:r.hint,diagnosticId:r.diagnosticId,logPath:r.logPath,...r.retriable===void 0?{}:{retriable:r.retriable},...r.supportedOn===void 0?{}:{supportedOn:r.supportedOn},details:{...r.details??{},...n.executedSteps.some(le)&&(r.details?.reason!==`bounded_composite_resource_unsupported`||r.details.dispatched!==`no`)?{dispatched:`unknown`}:{},step:e.step,command:t.command,positionals:t.positionals,executed:n.executedSteps.length,total:n.total,partialResults:n.partialResults}}}}function le(e){return l(e)!==`observes-app`}function Y(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);B(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let i=t[n];if(!M(i))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let o=Object.keys(i).filter(e=>!oe.has(e));if(o.length>0){let t=o.map(e=>`"${e}"`).join(`, `);throw new e(`INVALID_ARGS`,`Batch step ${n+1} has unknown field(s): ${t}. Allowed fields: command, positionals, input, flags, runtime.`)}let c=s(i.command);if(!c)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(a(c,n+1),i.positionals!==void 0&&!Array.isArray(i.positionals))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must be an array.`);let l=i.positionals??[];if(l.some(e=>typeof e!=`string`))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must contain only strings.`);if(i.flags!==void 0&&!M(i.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(X(i.flags,n+1),i.input!==void 0&&!M(i.input))throw new e(`INVALID_ARGS`,`Batch step ${n+1} input must be an object.`);r.push({command:c,positionals:l,input:i.input,flags:i.flags??{},runtime:W(i.runtime,n+1)})}return r}function X(t,n){if(t?.textStdin===!0)throw new e(`INVALID_ARGS`,`Batch step ${n}: fill textStdin is not supported because batch steps have no stdin of their own.`,{reason:`fill_text_stdin_in_batch`})}function ue(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return Z(Q(e),a)}function Z(e,t){let n=Q(e)??{},r=t;for(let e of c)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function de(e,t){return n(e)?t?e:`digest`:e}function fe(e,t){let n=e?.responseLevel,r=de(n,t);return r===n?e:{...e,responseLevel:r}}async function pe(e,t,n,i,a){let{stepNumber:o,totalSteps:s}=a,c=o===s,l=Date.now(),u=ue(e.flags,n.flags);u.session===void 0&&r(e)&&(u.session=t);let d=await i({token:e.token,session:t,command:n.command,positionals:n.positionals,input:n.input,flags:u,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:fe(e.meta,c)},a),f=Date.now()-l;return d.ok?{ok:!0,step:o,result:{step:o,command:n.command,ok:!0,data:d.data??{},durationMs:f}}:{ok:!1,step:o,error:d.error}}function Q(e){return e}function $(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{ne as A,te as C,h as D,_ as E,P as M,u as N,g as O,v as S,ie as T,N as _,G as a,ae as b,V as c,W as d,U as f,L as g,I as h,q as i,F as j,m as k,B as l,R as m,se as n,K as o,H as p,Y as r,J as s,Z as t,z as u,j as v,ee as w,y as x,M as y};
1
+ import{a as e,n as t,o as n,r,w as i}from"./sdk-batch.js";import{_ as a,c as o,f as s,o as c,x as l}from"./sdk-contracts.js";function u(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e,t,n,r){let i=n(e[t]);if(i===void 0)throw new a(`COMMAND_FAILED`,r,{response:e});return i}function f(e,t,n){return n(e[t])}function p(e,t,n){let r=e[t];return r===null?null:n(r)}function m(e,t){return d(e,t,D,`Daemon response is missing "${t}".`)}function ee(e,t){return f(e,t,D)}function te(e,t){return p(e,t,D)}function h(e,t){return d(e,t,O,`Daemon response is missing numeric "${t}".`)}function g(e,t){return d(e,t,k,`Daemon response has invalid "${t}".`)}function _(e,t){return d(e,t,A,`Daemon response has invalid "${t}".`)}function v(e,t){return f(e,t,A)}function y(e,t){return f(e,t,j)??`mobile`}function b(e){if(!N(e))return;let t=E(e,`x`),n=E(e,`y`),r=E(e,`width`),i=E(e,`height`);if(t!==void 0&&n!==void 0&&r!==void 0&&i!==void 0)return{x:t,y:n,width:r,height:i}}function ne(e){if(e!==void 0)return N(e)?e.kind===`absent`?{kind:`absent`,...x(e)}:e.kind===`unmeasurable`?typeof e.reason==`string`&&e.reason.trim().length>0?{kind:`unmeasurable`,reason:e.reason}:{kind:`unmeasurable`,reason:`unreported-reason`}:e.kind===`tree-rejected`?S(e):e.kind===`visibility-only`?typeof e.visible==`boolean`?{kind:`visibility-only`,visible:e.visible}:{kind:`unmeasurable`,reason:`invalid-visibility-probe`}:e.kind===`derived`&&e.derivation!==`docked-tree`?{kind:`unmeasurable`,reason:`unrecognized-derivation`}:e.kind===`visible`||e.kind===`derived`?C(e.frame,e.kind,x(e)):{kind:`unmeasurable`,reason:`unrecognized-kind`}:{kind:`unmeasurable`,reason:`malformed-fact`}}function x(e){return e.treeBound===!0?{treeBound:!0}:{}}function S(e){return e.derivation===`docked-tree`?e.visible!==void 0&&typeof e.visible!=`boolean`?{kind:`unmeasurable`,reason:`invalid-visibility-probe`}:{kind:`tree-rejected`,derivation:`docked-tree`,...typeof e.visible==`boolean`?{visible:e.visible}:{}}:{kind:`unmeasurable`,reason:`unrecognized-derivation`}}function C(e,t,n){let r=b(e);return re(r)?t===`derived`?{kind:`derived`,derivation:`docked-tree`,frame:r,...n}:{kind:`visible`,frame:r,...n}:{kind:`unmeasurable`,reason:`invalid-${t}-frame`}}function re(e){if(!e)return!1;let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||!Number.isFinite(t+r)||!Number.isFinite(n+i)||r<=0||i<=0?!1:t!==-Number.MAX_VALUE/2||n!==-Number.MAX_VALUE/2||r!==Number.MAX_VALUE||i!==Number.MAX_VALUE}const w={presented:`presented`,absent:`absent`,unknown:`unknown`},T=`presentedSurface`;function ie(e){if(!Object.hasOwn(e,T))return;let t=e[T];return typeof t==`string`&&Object.hasOwn(w,t)?w[t]:`unknown`}function ae(e){if(!N(e))return;let t=E(e,`x`),n=E(e,`y`);if(t!==void 0&&n!==void 0)return{x:t,y:n}}function E(e,t){let n=e[t];return typeof n==`number`?n:void 0}function D(e){return typeof e==`string`&&e.length>0?e:void 0}function O(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function k(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`harmonyos`||e===`vega`||e===`linux`||e===`web`?e:void 0}function A(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function j(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function M(e){if(!N(e))throw new a(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:e});return e}function N(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function P(e){return N(e)?e:void 0}function F(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function I(e){return e.split(`
2
+ `).map(e=>e.trim()).filter(e=>e.length>0)}function L(e,t,n={}){let r=e[t];if(r===void 0)return;if(!Number.isInteger(r))throw new a(`INVALID_ARGS`,`Expected ${t} to be an integer.`);let i=r;if(n.min!==void 0&&i<n.min)throw new a(`INVALID_ARGS`,`Expected ${t} to be at least ${n.min}.`);if(n.max!==void 0&&i>n.max)throw new a(`INVALID_ARGS`,`Expected ${t} to be at most ${n.max}.`);return i}function R(e,t,n={}){let r=e[t];if(r!==void 0){if(typeof r!=`number`||!Number.isFinite(r))throw new a(`INVALID_ARGS`,`Expected ${t} to be a finite number.`);if(n.min!==void 0&&r<n.min)throw new a(`INVALID_ARGS`,`Expected ${t} to be at least ${n.min}.`);if(n.max!==void 0&&r>n.max)throw new a(`INVALID_ARGS`,`Expected ${t} to be at most ${n.max}.`);return r}}const z=`android_shell_text_unsupported`;function B(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function V(e,t){if(e>t)throw new a(`INVALID_ARGS`,`batch has ${e} steps; max allowed is ${t}.`)}const H=`Each batch step is {"command":"<name>","input":{...}}, where input is that command's own structured input object, keyed by field name. There is no positional step form: args, argv, positionals, and flags are not step fields.`;function U(e,t,n=H){if(!u(e))throw new a(`INVALID_ARGS`,`Invalid batch step ${t}.`,{hint:n});return e}function W(e,t,n=H){let r=e.input;if(!u(r))throw new a(`INVALID_ARGS`,`Batch step ${t} input must be an object.`,{hint:n});return r}function G(e,t){if(e!==void 0)try{return c.parse(e)}catch(e){throw new a(`INVALID_ARGS`,`Batch step ${t} runtime is invalid: ${e instanceof Error?e.message:String(e)}`)}}function K(e){let t=e.trim();if(!t||/\s/.test(t))return!1;let n=/^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(t);if(!n)return!1;let r=n[1]?.toLowerCase(),i=n[2]??``;return r===`http`||r===`https`||r===`ws`||r===`wss`||r===`ftp`||r===`ftps`?i.startsWith(`//`):!0}function q(e){let t=e.trim().split(`:`)[0]?.toLowerCase();return t===`http`||t===`https`}const J=`com.apple.mobilesafari`;function oe(e,t){let n=e?.trim();if(n)return n;if(q(t))return J}const se=new Set(t);async function ce(e,t,n){let r=Q(e.flags),i=r?.batchOnError??`stop`;if(i!==`stop`)return $(`INVALID_ARGS`,`Unsupported batch on-error mode: ${i}.`);let a=r?.batchMaxSteps??100;if(!B(a))return $(`INVALID_ARGS`,`Invalid batch max-steps: ${String(r?.batchMaxSteps)}`);try{let i=X(r?.batchSteps,a),o=Date.now(),s=[];for(let[r,a]of i.entries()){let o=await me(e,t,a,n,{stepNumber:r+1,totalSteps:i.length,remainingSteps:i.slice(r+1).map(e=>({command:e.command,positionals:e.positionals,flags:e.flags,...e.input===void 0?{}:{input:e.input}}))});if(!o.ok)return le(o,a,{executedSteps:i.slice(0,r),total:i.length,partialResults:s});s.push(o.result)}return{ok:!0,data:{total:i.length,executed:i.length,totalDurationMs:Date.now()-o,results:s}}}catch(e){let t=l(e);return $(t.code,t.message,t.details)}}function le(e,t,n){let{error:r}=e;return{ok:!1,error:{code:r.code,message:`Batch failed at step ${e.step} (${t.command}): ${r.message}`,hint:r.hint,diagnosticId:r.diagnosticId,logPath:r.logPath,...r.retriable===void 0?{}:{retriable:r.retriable},...r.supportedOn===void 0?{}:{supportedOn:r.supportedOn},details:{...r.details??{},...n.executedSteps.some(Y)&&(r.details?.reason!==`bounded_composite_resource_unsupported`||r.details.dispatched!==`no`)?{dispatched:`unknown`}:{},step:e.step,command:t.command,positionals:t.positionals,executed:n.executedSteps.length,total:n.total,partialResults:n.partialResults}}}}function Y(e){return i(e)!==`observes-app`}function X(t,r){if(!Array.isArray(t)||t.length===0)throw new a(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);V(t.length,r);let i=[];for(let r=0;r<t.length;r+=1){let o=t[r];if(!N(o))throw new a(`INVALID_ARGS`,`Invalid batch step at index ${r}.`);let s=Object.keys(o).filter(e=>!se.has(e));if(s.length>0){let e=s.map(e=>`"${e}"`).join(`, `);throw new a(`INVALID_ARGS`,`Batch step ${r+1} has unknown field(s): ${e}. Allowed fields: command, positionals, input, flags, runtime.`)}let c=n(o.command);if(!c)throw new a(`INVALID_ARGS`,`Batch step ${r+1} requires command.`);if(e(c,r+1),o.positionals!==void 0&&!Array.isArray(o.positionals))throw new a(`INVALID_ARGS`,`Batch step ${r+1} positionals must be an array.`);let l=o.positionals??[];if(l.some(e=>typeof e!=`string`))throw new a(`INVALID_ARGS`,`Batch step ${r+1} positionals must contain only strings.`);if(o.flags!==void 0&&!N(o.flags))throw new a(`INVALID_ARGS`,`Batch step ${r+1} flags must be an object.`);if(ue(o.flags,r+1),o.input!==void 0&&!N(o.input))throw new a(`INVALID_ARGS`,`Batch step ${r+1} input must be an object.`);i.push({command:c,positionals:l,input:o.input,flags:o.flags??{},runtime:G(o.runtime,r+1)})}return i}function ue(e,t){if(e?.textStdin===!0)throw new a(`INVALID_ARGS`,`Batch step ${t}: fill textStdin is not supported because batch steps have no stdin of their own.`,{reason:`fill_text_stdin_in_batch`})}function de(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return Z(Q(e),a)}function Z(e,t){let n=Q(e)??{},i=t;for(let e of r)i[e]===void 0&&n[e]!==void 0&&(i[e]=n[e]);return t}function fe(e,t){return o(e)?t?e:`digest`:e}function pe(e,t){let n=e?.responseLevel,r=fe(n,t);return r===n?e:{...e,responseLevel:r}}async function me(e,t,n,r,i){let{stepNumber:a,totalSteps:o}=i,c=a===o,l=Date.now(),u=de(e.flags,n.flags);u.session===void 0&&s(e)&&(u.session=t);let d=await r({token:e.token,session:t,command:n.command,positionals:n.positionals,input:n.input,flags:u,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:pe(e.meta,c)},i),f=Date.now()-l;return d.ok?{ok:!0,step:a,result:{step:a,command:n.command,ok:!0,data:d.data??{},durationMs:f}}:{ok:!1,step:a,error:d.error}}function Q(e){return e}function $(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{m as A,te as C,_ as D,ie as E,I as M,F as N,h as O,u as P,y as S,ee as T,P as _,K as a,ae as b,H as c,G as d,W as f,R as g,L as h,J as i,ne as j,g as k,V as l,z as m,ce as n,q as o,U as p,X as r,oe as s,Z as t,B as u,M as v,v as w,b as x,N as y};