agent-device 0.21.7 → 0.21.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.7.apk → agent-device-android-ime-helper-0.21.9.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.9.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.7.manifest.json → agent-device-android-ime-helper-0.21.9.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.7.apk → agent-device-android-snapshot-helper-0.21.9.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.9.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.7.manifest.json → agent-device-android-snapshot-helper-0.21.9.manifest.json} +6 -6
- package/apple/macos-helper/Package.swift +16 -1
- package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubPose.swift +47 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubWindowInventory.swift +65 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubPose.swift +225 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubSidebar.swift +57 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubWindowDiscovery.swift +108 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +66 -13
- package/apple/macos-helper/Sources/AgentDeviceMacOSInput/MouseClickDelivery.swift +116 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSInput/MouseClickSchedule.swift +61 -0
- package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubPoseTests.swift +30 -0
- package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubWindowInventoryTests.swift +65 -0
- package/apple/macos-helper/Tests/AgentDeviceMacOSInputTests/MouseClickScheduleTests.swift +58 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +1 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAppScreenCapture.swift +175 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +10 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +42 -15
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +8 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +45 -22
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +39 -734
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +20 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +63 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +13 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +25 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +5 -562
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +566 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +5 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +594 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +35 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +160 -0
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +3 -0
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-frames.swift +203 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotCoordinateSpace.swift +5 -0
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apple-runner-platform.js +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/artifact-paths.js +1 -0
- package/dist/src/back-mode.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +15 -11
- package/dist/src/cli.js +4 -4
- package/dist/src/client-types.d.ts +51 -1
- package/dist/src/command-tools.js +3 -3
- package/dist/src/config.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/device.js +1 -1
- package/dist/src/device2.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/fold-runtime.js +1 -0
- package/dist/src/gesture-admission.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.js +1 -0
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -0
- package/dist/src/interactor-operation-catalog.js +1 -1
- package/dist/src/interactor.js +4 -5
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/internal/png-worker.d.ts +5 -0
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/macos-facade.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +17 -16
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/mp4-duration.js +1 -0
- package/dist/src/multitouch-support.js +1 -1
- package/dist/src/owner-identity.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +2 -2
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +2 -2
- package/dist/src/platform-runtime-runtime-hints.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-crop-bytes.js +1 -1
- package/dist/src/png-encode.js +1 -0
- package/dist/src/png-size.js +1 -0
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/recording-export-quality.js +1 -1
- package/dist/src/recording-scope.js +1 -0
- package/dist/src/recording.js +3 -0
- package/dist/src/registry.js +35 -35
- package/dist/src/replay.js +1 -1
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/result-serialization.js +1 -1
- package/dist/src/runner-cache-metadata.js +2 -2
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-contract.js +3 -0
- package/dist/src/runner-dev-tools-security.js +1 -0
- package/dist/src/runner-device-readiness.js +1 -0
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-presentation.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/runtime10.js +2 -1
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime4.js +5 -5
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image.js +1 -0
- package/dist/src/screenshot-overlay-draw.js +1 -0
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-gesture.js +1 -1
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +7 -5
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-selectors.d.ts +58 -6
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/semantic-index.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session2.js +3 -3
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator-facade.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/src8.js +1 -1
- package/dist/src/stop-sequence.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/video.js +2 -2
- package/dist/src/web2.js +1 -1
- package/package.json +3 -1
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.7.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.7.apk.sha256 +0 -1
- package/dist/src/png-transcode.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,L as t,S as n,p as r}from"./sdk-contracts.js";import"./capture.js";import{r as i}from"./snapshot-capture-annotations.js";import{i as a}from"./snapshot-diagnostics.js";import{f as o}from"./android-input-ownership.js";import{
|
|
1
|
+
import{D as e,L as t,S as n,p as r}from"./sdk-contracts.js";import"./capture.js";import{r as i}from"./snapshot-capture-annotations.js";import{i as a}from"./snapshot-diagnostics.js";import{f as o}from"./android-input-ownership.js";import{b as s}from"./sdk-device.js";import{s as c}from"./session-store.js";import{a as l,f as u,j as d,k as f,o as p,s as m}from"./session-snapshot.js";import{n as h}from"./success-text.js";import{r as g}from"./diagnostics.js";import"./diagnostics2.js";import{i as _,s as v}from"./android-system-chrome.js";import{r as y}from"./request-cancel.js";import"./request.js";import{a as b,i as x,r as S,t as C}from"./screenshot-runtime.js";import{a as w}from"./session-routing.js";import{s as T,t as E}from"./quality-warnings.js";import{i as D,r as O}from"./capture-disclosure.js";import{n as k,o as A,r as j}from"./snapshot-runtime-binding.js";import M from"node:path";import{promises as N}from"node:fs";import P from"node:os";function F(e){return{captureFailed:!0,error:e}}function I(e){return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`unavailable`}}function L(e,t){let n={path:e,overlayRefsRequested:!0,overlayRefSource:`session-snapshot`};return R(t)?{...n,overlayRefsAnnotated:!0,overlayRefs:t}:{...n,overlayRefsAnnotated:!1,overlayRefs:[]}}function R(e){return e.length>0}function z(e,t){return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`session-snapshot`,overlayAnnotationError:t}}function B(e){return`captureFailed`in e?{overlayRefCount:void 0,overlayRefsAnnotated:void 0}:{overlayRefCount:`overlayRefs`in e?e.overlayRefs.length:0,overlayRefsAnnotated:e.overlayRefsAnnotated}}function ee(e){return v(e)===`accessibility-timeout`}async function V(e){if(e.command!==`snapshot`||e.device.platform!==`android`)return;let n=t(e.error);if(ee(n))return{ok:!1,error:{...n,details:{...n.details??{},androidSnapshotTimeoutScreenshot:await H(e)}}}}async function H(n){try{let t=await x({device:n.device,overlayRefs:!1,inspectFacts:n.inspectFacts,bindDevice:n.bindDevice});if(!t.ok)throw new e(`UNSUPPORTED_OPERATION`,`The target does not support screenshot capture, so no timeout evidence was taken.`);let r=await N.mkdtemp(M.join(P.tmpdir(),`agent-device-android-snapshot-timeout-`)),i=M.join(r,`snapshot-timeout-overlay-refs.png`);await t.runtime.captureScreenshot({outPath:i,options:{appBundleId:n.session?.appBundleId,stabilize:!1,surface:n.session?.surface},execution:S(f(n.logPath,{screenshotNoStabilize:!0},n.session?.appBundleId,n.session?.trace?.outPath))}),await N.access(i);let a=await U(i,n.session);return g({level:`warn`,phase:`android_snapshot_timeout_screenshot_captured`,data:{path:i,...B(a)}}),a}catch(e){let n=t(e);return g({level:`warn`,phase:`android_snapshot_timeout_screenshot_failed`,data:{error:n.message}}),F(n.message)}}async function U(e,n){if(!n?.snapshot)return I(e);try{return L(e,await b({screenshotPath:e,snapshot:n.snapshot}))}catch(n){let r=t(n);return g({level:`warn`,phase:`android_snapshot_timeout_screenshot_overlay_failed`,data:{path:e,error:r.message}}),z(e,r.message)}}function W(e){let{verdict:t,appBundleId:n,latch:r}=e;return!t||t.backend===`android-helper`?{latch:r}:t.state===`healthy`?{latch:void 0}:t.state!==`recovered`||t.reasonCode===`requested-backend`?{latch:r}:t.reasonCode===`deferred`?r!==void 0&&r.appBundleId===n?{latch:r}:{warning:E(t.backend),latch:{appBundleId:n}}:{latch:{appBundleId:n}}}function G(e){let{session:t,data:n,verdict:r,internalObservation:i}=e;if(i||!t)return n;let a=W({verdict:r,appBundleId:t.appBundleId,latch:t.recoveredSnapshotWarningLatch});return t.recoveredSnapshotWarningLatch=a.latch,a.warning?{...n,warnings:[a.warning,...h(n)]}:n}async function K(e){let t=await k(e,e.command);if(!t.ok)return t.response;let{session:n,device:r,snapshotScope:i}=t;return await A(n,r,async()=>{let{req:a,sessionName:s,logPath:c,sessionStore:l}=e,u={},d=q({req:a,sessionName:s,logPath:c,sessionStore:l,session:n,device:r,snapshotScope:i,capturedQuality:u,captureSnapshotData:t.captureSnapshot,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice}),f;try{f=await e.execute({runtime:d,sessionName:s,req:a,snapshotScope:i})}catch(t){let i=await V({error:t,command:e.command,logPath:c,session:n,device:r,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});if(!i)throw t;return i}te({req:a,sessionName:s,sessionStore:l,result:f.record});let p=G({session:l.get(s),data:f.data,verdict:u.value,internalObservation:a.internal?.observationOnly===!0});return{ok:!0,data:o(f.data,p)}},e.platformResourceCleanup)}function q(e){let{req:t,sessionName:n,logPath:r,sessionStore:i,session:a,device:o,snapshotScope:s}=e;return u({backend:$({req:t,logPath:r,session:a,device:o,snapshotScope:s,capturedQuality:e.capturedQuality,captureSnapshotData:e.captureSnapshotData,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice}),...D(`snapshot`),signal:y(t.meta?.requestId),sessions:p({sessionName:n,getSession:()=>i.get(n),recordOptions:{includeSnapshot:!0},setRecord:e=>{let r=ne(e),a=i.get(n);i.set(n,J({current:a,sessionName:n,sessionScope:w(t),device:o,record:r,refScopedSnapshot:Y(t),issuesRefsToClient:t.command===`snapshot`&&t.internal?.observationOnly!==!0}))}})})}function J(e){let{current:t,sessionName:n,sessionScope:r,device:i,record:a,refScopedSnapshot:o}=e,s=X(t,a,o),c=s?t.snapshot:a.snapshot,u=j({session:t,sessionName:n,sessionScope:r,device:i,snapshot:c,appBundleId:a.appBundleId});return l(u,{scopeSource:Q({current:t,keepCurrentSnapshot:s,refScopedSnapshot:o}),keptCurrentSnapshot:s,previousGeneration:t?.snapshotGeneration}),Z(u,s,e.issuesRefsToClient),a.appName&&(u.appName=a.appName),u}function Y(e){return e.flags?.snapshotScope?.trim().startsWith(`@`)===!0}function X(e,t,n){return n&&t.snapshot?.nodes.length===0&&e?.snapshot!==void 0}function Z(e,t,n){!t&&n&&d(e)}function Q(e){let{current:t,keepCurrentSnapshot:n,refScopedSnapshot:r}=e;if(r)return n?t?.snapshotScopeSource:t?.snapshotScopeSource??t?.snapshot}function $(e){let{req:t,logPath:n,session:r,device:o,snapshotScope:c}=e;return{platform:s(o),captureSnapshot:async(s,l)=>{let u=await m({device:o,session:r,flags:t.flags,outPath:l?.outPath??t.flags?.out,logPath:n,snapshotScope:c,signal:s.signal,captureData:e.captureSnapshotData,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice}),d=i(u);e.capturedQuality.value=d.quality;let f=a(r);return{snapshot:u.snapshot,...d,...f?{snapshotDiagnostics:f}:{},appName:r?.appBundleId?r.appName??r.appBundleId:void 0,appBundleId:r?.appBundleId}}}}function te(e){let t=e.sessionStore.get(e.sessionName);t&&e.sessionStore.recordAction(t,{command:e.req.command,positionals:e.req.positionals??[],flags:e.req.flags??{},result:re(e.result),interactiveObservation:c(e.req)})}function ne(t){if(!t.snapshot)throw new e(`UNKNOWN`,`snapshot runtime did not produce session state`);return t}function re(e){return e.kind===`snapshot`?{nodes:e.nodes,truncated:e.truncated}:{mode:e.mode,baselineInitialized:e.baselineInitialized,summary:e.summary}}async function ie(e){let t=e.session;if(!t||!T(e.verdict)||e.req.internal?.observationOnly===!0)return;let n=await ae({...e,session:t});if(n!==void 0)return{path:n,artifact:{field:`fallbackScreenshotPath`,artifactType:`screenshot`,path:n,fileName:`snapshot-fallback.png`}}}async function ae(e){let{req:t,session:n}=e;try{let r=await x({device:n.device,overlayRefs:!1,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});return r.ok?(await C({session:n,sessionName:e.sessionName,captureScreenshot:r.runtime.captureScreenshot,dispatchContext:f(e.logPath,t.flags,n.appBundleId,n.trace?.outPath,t.meta?.requestId,t.meta)})).path:void 0}catch{return}}async function oe(e){let t={},i=await K({...e,command:`snapshot`,execute:async({runtime:i,sessionName:a,req:s,snapshotScope:c})=>{let l=await i.capture.snapshot({session:a,...n(s.flags,r),scope:c});l.targetActivation&&!t.state&&(t.state={targetActivation:l.targetActivation});let u=se(s,e.sessionStore.get(a)),d=_(l.nodes),f=o(l,d===l.nodes?l:{...l,nodes:d}),p=await ie({req:s,session:e.sessionStore.get(a),sessionName:a,logPath:e.logPath,verdict:l.snapshotQuality,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice}),m=o(f,p?{...f,fallbackScreenshotPath:p.path,artifacts:[p.artifact]}:f);return{data:u===void 0?m:o(m,{...m,refsGeneration:u}),record:{kind:`snapshot`,nodes:l.nodes.length,truncated:l.truncated}}}});return O(i,t.state)}function se(e,t){return e.internal?.observationOnly===!0?void 0:t?.snapshotGeneration}export{K as n,oe as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{C as t,h as n,m as r,w as i}from"./sdk-contracts.js";import"./capture.js";import{r as a}from"./snapshot-capture-annotations.js";import{c as o,m as s,n as c,s as l}from"./android-input-ownership.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{C as t,h as n,m as r,w as i}from"./sdk-contracts.js";import"./capture.js";import{r as a}from"./snapshot-capture-annotations.js";import{c as o,m as s,n as c,s as l}from"./android-input-ownership.js";import{Ir as u,Mr as d,Pr as f,Ur as p,Vr as m}from"./sdk-batch.js";import{t as h}from"./snapshot-desktop-projection.js";import{a as g}from"./ios-snapshot-planning.js";function _(e,t,n){if(n?.(e.length+t.length)===!1)return;let r=v(t);if(r.length===0)return 0;let i=1/0,a=-1/0;for(let e of r)i=Math.min(i,e.x),a=Math.max(a,e.endX);let o=v(e).filter(e=>e.x<a&&e.endX>i);if(o.length===0)return 0;let s=[...r.flatMap(e=>[e.x,e.endX]),...o.flatMap(e=>[Math.max(e.x,i),Math.min(e.endX,a)])];if(n?.(r.length+o.length+s.length)===!1)return;r.sort(y),o.sort(y);let c=[...new Set(s)].sort((e,t)=>e-t),l=[],u=[],d=0,f=0,p=0,m=0;for(let e=0;e<c.length-1;e+=1){let t=c[e],i=c[e+1];for(l=l.filter(e=>e.endX>t),u=u.filter(e=>e.endX>t);d<r.length&&r[d].x<=t;)l.push(r[d]),d+=1;for(;f<o.length&&o[f].x<=t;)u.push(o[f]),f+=1;if(n?.(1+l.length+u.length)===!1)return;let a=b(l),s=b(u),h=i-t;p+=h*x(a),m+=h*S(a,s)}return p<=0?0:m/p}function v(e){return e.filter(p).map(e=>({...e,endX:e.x+e.width}))}function y(e,t){return e.x-t.x||e.endX-t.endX}function b(e){let t=e.map(e=>({start:e.y,end:e.y+e.height})).sort((e,t)=>e.start-t.start||e.end-t.end),n=[];for(let e of t){let t=n.at(-1);!t||e.start>t.end?n.push({...e}):t.end=Math.max(t.end,e.end)}return n}function x(e){return e.reduce((e,t)=>e+t.end-t.start,0)}function S(e,t){let n=0,r=0,i=0;for(;r<e.length&&i<t.length;){let a=e[r],o=t[i];n+=Math.max(0,Math.min(a.end,o.end)-Math.max(a.start,o.start)),a.end<=o.end?r+=1:i+=1}return n}function C(e,t=new Map){if(t.size===0)return new Set;let n=D(e),r=O(e,n),i={remaining:Math.max(1024,e.length*128),exhausted:!1},a=w(n,{footprints:r,siblingOrders:t,budget:i});return i.exhausted?new Set:L(a,n)}function w(e,t){let n=new Set;for(let r of e.values())for(let e of r)if(T(e,r,t)&&n.add(e.index),t.budget.exhausted)return n;return n}function T(e,t,n){let r=n.siblingOrders.get(e.index),i=n.footprints.get(e.index);if(!r||!i)return!1;for(let e of t){if(!F(n.budget))return!1;if(E(r,i,e,n))return!0}return!1}function E(e,t,n,r){let i=r.siblingOrders.get(n.index),a=r.footprints.get(n.index);if(!i||!a?.hasAction||i.group!==e.group||i.order<=e.order)return!1;let o=P(a,`paint`,r.budget),s=P(t,`show`,r.budget);if(r.budget.exhausted)return!1;let c=_(o,s,e=>I(r.budget,e));return c!==void 0&&c>=.9}function D(e){let t=new Map;for(let n of e){if(typeof n.parentIndex!=`number`)continue;let e=t.get(n.parentIndex)??[];e.push(n),t.set(n.parentIndex,e)}return t}function O(e,t){let n=new Map;for(let r=e.length-1;r>=0;--r){let i=e[r],a=t.get(i.index)??[],o=a.flatMap(e=>n.get(e.index)??[]);n.set(i.index,k(i,a.length,o))}return n}function k(e,t,n){let r=j(e,t),i=r??M(e);return{...i?{showRect:i}:{},showChildren:r?[]:n,...r?{paintRect:r}:{},paintChildren:r?[]:n,hasAction:e.hittable===!0||n.some(A)}}function A(e){return e.hasAction}function j(e,t){if(p(e.rect))return e.hittable===!0||m(e.type)||t===0&&N(e)?e.rect:void 0}function M(e){return p(e.rect)&&N(e)?e.rect:void 0}function N(e){return!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim())}function P(e,t,n){let r=[],i=[e];for(;i.length>0;){if(!F(n))return r;let e=i.pop(),a=t===`paint`?e.paintRect:e.showRect;a&&r.push(a),i.push(...t===`paint`?e.paintChildren:e.showChildren)}return r}function F(e){return I(e,1)}function I(e,t){return t>e.remaining?(e.exhausted=!0,!1):(e.remaining-=t,!0)}function L(e,t){let n=new Set,r=[...e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of t.get(e)??[])r.push(n.index)}}return n}function R(e){let t=new Map;for(let[n,r]of e.entries())t.set(r.index,n);let n=[],r=[];for(let[i,a]of e.entries()){let e=Math.max(0,a.depth??0);for(;r.length>0&&e<=r.at(-1).depth;)r.pop();let o=i,s=typeof a.parentIndex==`number`?t.get(a.parentIndex):void 0,c=typeof s==`number`&&s<o?s:r.at(-1)?.index;n.push({...a,index:o,depth:e,parentIndex:c}),r.push({depth:e,index:o})}return n}function z(e){let t=[],n=[];for(let r of e){let e=r.depth??0;for(;t.length>0&&e<=t.at(-1);)t.pop();let i=u(r.type??``),a=f(d(r));if((i===`group`||i===`ioscontentgroup`)&&!a){t.push(e);continue}let o=Math.max(0,e-t.length);n.push({...r,depth:o})}return n}var B=e({buildSnapshotState:()=>V});function V(e,o){let s=e?.nodes??[],c=o?.snapshotRaw,u=H(e,s,c===!0),d=R(c?u:z(u)),f=o?.snapshotScope&&G(e?.backend)?h(d,o.snapshotScope):d,p=a(e).quality;return{nodes:r(c?f:l(f,U(e?.backend))),truncated:e?.truncated,createdAt:Date.now(),...i(e),...p?{snapshotQuality:p}:{},...e.comparisonIdentity?{comparisonKey:g(e.comparisonIdentity)}:{},...e.systemSurface?{iosSystemSurfaceBundleId:e.systemSurface.bundleId}:{},...e.targetActivation?{targetActivation:e.targetActivation}:{},...e.keyboard?{keyboard:e.keyboard}:{},presentationKey:n(t(o)),comparisonSafe:K(e?.backend,o)}}function H(e,t,n){return e.backend===`android`&&!n?W(e,t):t}function U(e){return e===`android`?{isAdditionalOverlayNode:c}:{}}function W(e,t){let n=s(e),r=C(n?.nodes??t,n?.androidSiblingOrderByNodeIndex);return o(t,e=>{let t=n?.sourceIndexByNodeIndex.get(e.index)??e.index;return r.has(t)})}function G(e){return e===void 0||e===`linux-atspi`||e===`harmonyos-arkui`||e===`web`}function K(e,t){return e===`android`&&t?.snapshotInteractiveOnly!==!0&&typeof t?.snapshotDepth!=`number`&&!t?.snapshotScope}export{B as n,V as t};
|
package/dist/src/snapshot4.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,o as t}from"./sdk-contracts.js";import{d as n}from"./sdk-device.js";import{$ as r,Nr as i,et as a,in as o,nt as s,rn as c,tt as l,ur as u,zt as d}from"./sdk-batch.js";import"./session-store.js";import{M as f,g as p,k as m,m as h,p as g,r as _,s as v}from"./session-snapshot.js";import{k as y}from"./runtime.js";import{i as b,r as x}from"./success-text.js";import"./alert-contract.js";import{d as S,s as C,t as w,u as T}from"./location-coordinates.js";import{a as E,t as ee}from"./absence-observation-errors.js";import{r as te}from"./diagnostics.js";import"./diagnostics2.js";import{h as ne}from"./screenshot-runtime.js";import{n as re,t as ie}from"./capture-disclosure.js";import{n as ae,t as oe}from"./snapshot-runtime.js";import{a as D,i as O,o as k}from"./snapshot-runtime-binding.js";import{a as A,c as j,f as M,g as N,h as P,m as F,o as I,p as L,s as R,t as z}from"./selector-runtime.js";async function B(e){let{device:t,action:n,inspectFacts:i,bindDevice:o}=e,c={command:`alert`,device:t,inspectFacts:i,bindDevice:o,...e.session?{}:{readiness:{}}};if(n===`wait`){let e=await p({...c,use:s});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>H(t,e)}}if(n===`accept`){let e=await p({...c,use:r});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>U(t,e)}}if(n===`dismiss`){let e=await p({...c,use:a});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>W(t,e)}}let u=await p({...c,use:l});if(u.type===`response`)return{ok:!1,response:u.response};let d=u.runtime;return{ok:!0,execute:e=>V(d,e)}}async function V(e,t){return await e.operations.readAlert(t)}async function H(e,t){return await e.operations.awaitAlert(t)}async function U(e,t){return await e.operations.acceptAlert(t)}async function W(e,t){return await e.operations.dismissAlert(t)}async function G(e){let{req:t,logPath:n,sessionStore:r,session:i,device:a,inspectFacts:s,bindDevice:c}=e,l=await B({device:a,action:q(t.positionals?.[0]),session:i,inspectFacts:s,bindDevice:c});if(!l.ok)return l.response;i&&ne(t)===`may-invalidate`&&f(i);let u=m(n,t.flags,i?.appBundleId,i?.trace?.outPath),d=await l.execute({timeoutMs:o(t.positionals?.[1])??1e4,...K(i),execution:h(u)});return O(r,i,t,d),{ok:!0,data:d}}function K(e){return{...e?.appBundleId===void 0?{}:{appBundleId:e.appBundleId},...e?.surface===void 0?{}:{surface:e.surface}}}function q(e){return e===`accept`||e===`dismiss`||e===`wait`?e:`get`}function se(e){let n=e.positionals?.[0]?.toLowerCase(),r=e.positionals?.[1]?.toLowerCase(),i=e.positionals?.[2]?.toLowerCase();return n===`clear-app-state`?{ok:!0,parsed:{setting:n,state:`clear`,appBundleId:r===`clear`?e.positionals?.[2]:e.positionals?.[1]}}:!n||!r||n===`permission`&&!i||n===`location`&&r===`set`&&(!e.positionals?.[2]||!e.positionals?.[3])||n===`reset-keychain`&&e.positionals?.[2]!==void 0?t(`INVALID_ARGS`,C):{ok:!0,parsed:{setting:n,state:r,permissionTarget:i,permissionMode:e.positionals?.[3],latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}}function ce(e){if(e.setting===`permission`)return{permissionTarget:e.permissionTarget,permissionMode:e.permissionMode};if(e.setting===`location`&&e.state===`set`)return{latitude:w(e.latitude,`latitude`),longitude:w(e.longitude,`longitude`)}}function le(e,t,n){let{setting:r,state:i}=e;return r===`clear-app-state`?{setting:`clear-app-state`,state:`clear`,appBundleId:t,platform:n}:r===`location`&&i===`set`?{setting:r,state:i,latitude:e.latitude,longitude:e.longitude,platform:n}:r===`permission`?{setting:r,state:i,permissionTarget:e.permissionTarget,permissionMode:e.permissionMode,platform:n}:{setting:r,state:i,appBundleId:t,platform:n}}function ue(e){return typeof e.message==`string`&&e.message.length>0?e.message:void 0}async function de(e,t,n){let{setting:r,state:i}=t,a=await e.operations.setSetting(t);return a&&typeof a==`object`?b({setting:r,state:i,...a},ue(a)??n):{setting:r,state:i,...x(n)}}async function fe(e){let{req:r,logPath:i,sessionStore:a,session:o,device:s,parsed:c,inspectFacts:l,bindDevice:u}=e,{setting:g,state:_}=c,v=await p({command:`settings`,device:s,use:d,inspectFacts:l,bindDevice:u,...o?{}:{readiness:{}}});if(v.type===`response`)return v.response;if(n(s)&&!S(g))return t(`INVALID_ARGS`,T(g));let y=c.appBundleId??o?.appBundleId;if(g===`clear-app-state`&&!y)return t(`INVALID_ARGS`,`settings clear-app-state requires an app id when no app is bound to the session`);o&&f(o),te({level:`debug`,phase:`settings_apply`,data:le(c,y,s.platform)});let b=ce(c),x=m(i,r.flags,y,o?.trace?.outPath),C=await de(v.runtime,{setting:g,state:_,...y===void 0?{}:{appBundleId:y},...b===void 0?{}:{options:b},execution:h(x)},g===`clear-app-state`?`Cleared user data for ${y}`:`Updated setting: ${g}`);return O(a,o,r,C),{ok:!0,data:C}}async function pe(e){return await ae({...e,command:`diff`,execute:async({runtime:e,sessionName:t,req:n,snapshotScope:r})=>{let i=await e.capture.diffSnapshot({session:t,interactiveOnly:n.flags?.snapshotInteractiveOnly,depth:n.flags?.snapshotDepth,scope:r,raw:n.flags?.snapshotRaw});return{data:i,record:{kind:`diff`,mode:`snapshot`,baselineInitialized:i.baselineInitialized,summary:i.summary}}}})}function me(e){return e!==`sleep`}const he=[`application`,`window`,`tabbar`,`scrollbar`,`image`],ge=new Set([`tab bar`]);async function _e(e,n){if(n.ok||!ve(n.error.details?.reason)||n.error.details?.captureStalled===!0||n.error.details?.captureTruncated===!0)return n;let r=await ye(e).catch(()=>null);return r?t(n.error.code,`${n.error.message}. Current surface: ${r.summary}.`,{...n.error.details??{},currentSurface:r.details}):n}function ve(e){return e===y.targetAbsent||e===y.stableTimeout}async function ye(e){let t={...e.req.flags,snapshotInteractiveOnly:!0},n=await v({device:e.device,session:e.session,flags:t,logPath:e.logPath??``,captureData:async()=>await e.capture(g({flags:t,logPath:e.logPath??``,meta:e.req.meta,session:e.session,snapshotScope:void 0}))});ie(e.activationProof,n.snapshot);let r=[...n.snapshot.nodes].sort(be),i=J(r,6,{includeIdentifiers:!0});if(i.length===0)return null;let a=J(r.filter(e=>!Z(e)),4,{includeIdentifiers:!1}),o=J(r.filter(Se),4,{includeIdentifiers:!0});return{summary:(a.length>0?a:i.slice(0,4)).join(`, `),details:{labels:i,...o.length>0?{buttons:o}:{}}}}function J(e,t,n){let r=new Set,i=[];for(let a of e){let e=X(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function be(e,t){return Y(e)-Y(t)||xe(e,t)}function Y(e){let t=!!X(e,{includeIdentifiers:!1});return(Z(e)?2:0)+ +!t}function xe(e,t){return e.rect&&t.rect?e.rect.y-t.rect.y||e.rect.x-t.rect.x:e.rect?-1:t.rect?1:(e.depth??0)-(t.depth??0)||e.index-t.index}function X(e,t){let n=(t.includeIdentifiers?[e.label,e.value,e.identifier]:[e.label,e.value]).map(e=>typeof e==`string`?e.trim():``).find(e=>e.length>0);return n?n.replaceAll(/\s+/g,` `).slice(0,80):``}function Z(e){let t=i(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return he.some(e=>t.includes(e))||ge.has(n)||n.endsWith(`.fill`)}function Se(e){let t=`${e.type??``} ${e.role??``} ${e.subrole??``}`;return i(t).includes(`button`)}async function Ce(e){let{req:t,sessionName:n,sessionStore:r}=e,i=we(t);if(`ok`in i)return i;let a=i,{session:o,device:s}=await D(r,n,t.flags),c=await Q(e,a,o,s);if(c&&`ok`in c)return c;let l=c,u=t.internal?.replayLandmarkGuard,d=Te(a,o);if(`ok`in d)return d;let{waitParsed:f,staleRefsWarning:p}=d;return e.consumedSnapshot??={},e.activationProof??={},a.kind===`sleep`?await $(e,f,o,s,l,p,u):re({response:await k(o,s,()=>$(e,f,o,s,l,p,u),e.platformResourceCleanup),consumedTree:z(e),activationProof:e.activationProof})}function we(e){let n=c(e.positionals??[]);if(!n)return t(`INVALID_ARGS`,`wait requires a duration or text`);if(n.kind===`invalid`)return t(`INVALID_ARGS`,n.message);if(n.kind!==`absent`)return n;let r=E({depth:e.flags?.snapshotDepth,scope:e.flags?.snapshotScope});if(!r)return n;let i=ee(r,`wait`);return t(i.code,i.message,i.details)}async function Q(e,t,n,r){if(!me(t.kind))return;let i=await M({command:`wait`,device:r,session:n,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});return i.ok?i.operations:i.response}function Te(e,t){if(e.kind!==`ref`)return{waitParsed:e};let n=N(e.rawRef);return n.ok?{waitParsed:{...e,rawRef:n.ref},staleRefsWarning:_({session:t,ref:n.ref,mintedGeneration:n.generation})}:n.response}async function $(e,t,n,r,i,a,o){let{req:s,sessionName:c,sessionStore:l}=e,u=j({...e,session:n,device:r,bound:i}),d=await R(async()=>{let e=await u.selectors.wait({session:c,requestId:s.meta?.requestId,target:Ee(t,n,o)}),r=I(e);L(l,c,s,F(e),r,`landmark`);let i=P(e);return a?{...i,warning:a}:i}),f=i?await _e({req:s,logPath:e.logPath,session:n,device:r,capture:i.capture,activationProof:e.activationProof},d):d;return await A(e,f,`wait`)}function Ee(e,t,n){switch(e.kind){case`sleep`:return{kind:`sleep`,durationMs:e.durationMs};case`selector`:return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...n?{recordedLandmark:n}:{}};case`absent`:return{kind:`absent`,selector:e.selectorExpression,timeoutMs:e.timeoutMs};case`ref`:return Oe(e,t);case`stable`:return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};case`text`:return ke(e);default:return De(e)}}function De(e){throw Error(`Unsupported wait positional target: ${String(e)}`)}function Oe(t,n){if(!n?.snapshot)throw new e(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:t.rawRef,timeoutMs:t.timeoutMs}}function ke(t){let n=u(t.text);if(!n.ok)throw new e(n.code,n.message);return{kind:`text`,text:n.text,timeoutMs:t.timeoutMs}}const Ae={snapshot:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>await oe({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o}),diff:async({req:e,sessionName:n,logPath:r,sessionStore:i,inspectFacts:a,bindDevice:o,platformResourceCleanup:s})=>e.positionals?.[0]===`snapshot`?await pe({req:e,sessionName:n,logPath:r,sessionStore:i,inspectFacts:a,bindDevice:o,platformResourceCleanup:s}):t(`INVALID_ARGS`,`diff currently supports only: diff snapshot`),wait:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>await Ce({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o}),alert:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>{let{session:s,device:c}=await D(r,t,e.flags);return await k(s,c,async()=>await G({req:e,logPath:n,sessionStore:r,session:s,device:c,inspectFacts:i,bindDevice:a}),o)},settings:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>{let s=se(e);if(!s.ok)return s;let{session:c,device:l}=await D(r,t,e.flags);return await k(c,l,async()=>await fe({req:e,logPath:n,sessionStore:r,session:c,device:l,parsed:s.parsed,inspectFacts:i,bindDevice:a}),o)}};async function je(e){let t=e.req.command,n=Ae[t];return n?await n(e):null}export{je as handleSnapshotCommands};
|
|
1
|
+
import{D as e,o as t}from"./sdk-contracts.js";import{f as n,l as r,u as i,w as a}from"./sdk-device.js";import{$ as o,Ht as s,Ir as c,Rt as l,Vt as u,et as d,nt as f,on as p,pr as m,sn as h,tt as g}from"./sdk-batch.js";import"./session-store.js";import{M as _,g as v,k as y,m as b,p as x,r as S,s as C}from"./session-snapshot.js";import{k as w}from"./runtime.js";import{i as ee,r as T}from"./success-text.js";import"./alert-contract.js";import{b as te,c as ne,f as re,g as E,h as ie,m as ae,p as oe,r as D,t as O}from"./location-coordinates.js";import{a as se,t as k}from"./absence-observation-errors.js";import{r as A}from"./diagnostics.js";import"./diagnostics2.js";import{h as j}from"./screenshot-runtime.js";import{n as M,t as N}from"./capture-disclosure.js";import{n as P,t as F}from"./snapshot-runtime.js";import{a as I,i as L,o as R}from"./snapshot-runtime-binding.js";import{a as z,c as B,f as V,g as H,h as U,m as W,o as G,p as K,s as ce,t as le}from"./selector-runtime.js";async function ue(e){let{device:t,action:n,inspectFacts:r,bindDevice:i}=e,a={command:`alert`,device:t,inspectFacts:r,bindDevice:i,...e.session?{}:{readiness:{}}};if(n===`wait`){let e=await v({...a,use:f});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>fe(t,e)}}if(n===`accept`){let e=await v({...a,use:o});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>pe(t,e)}}if(n===`dismiss`){let e=await v({...a,use:d});if(e.type===`response`)return{ok:!1,response:e.response};let t=e.runtime;return{ok:!0,execute:e=>me(t,e)}}let s=await v({...a,use:g});if(s.type===`response`)return{ok:!1,response:s.response};let c=s.runtime;return{ok:!0,execute:e=>de(c,e)}}async function de(e,t){return await e.operations.readAlert(t)}async function fe(e,t){return await e.operations.awaitAlert(t)}async function pe(e,t){return await e.operations.acceptAlert(t)}async function me(e,t){return await e.operations.dismissAlert(t)}async function he(e){let{req:t,logPath:n,sessionStore:r,session:i,device:a,inspectFacts:o,bindDevice:s}=e,c=await ue({device:a,action:_e(t.positionals?.[0]),session:i,inspectFacts:o,bindDevice:s});if(!c.ok)return c.response;i&&j(t)===`may-invalidate`&&_(i);let l=y(n,t.flags,i?.appBundleId,i?.trace?.outPath),u=await c.execute({timeoutMs:h(t.positionals?.[1])??1e4,...ge(i),execution:b(l)});return L(r,i,t,u),{ok:!0,data:u}}function ge(e){return{...e?.appBundleId===void 0?{}:{appBundleId:e.appBundleId},...e?.surface===void 0?{}:{surface:e.surface}}}function _e(e){return e===`accept`||e===`dismiss`||e===`wait`?e:`get`}function ve(e){let n=e.positionals?.[0]?.toLowerCase(),r=e.positionals?.[1]?.toLowerCase(),i=e.positionals?.[2]?.toLowerCase();if(n===`clear-app-state`)return{ok:!0,parsed:{leg:`write`,args:{setting:n,state:`clear`,appBundleId:r===`clear`?e.positionals?.[2]:e.positionals?.[1]}}};let a=l(e.positionals);if(a.kind===`read`)return{ok:!0,parsed:{leg:`read`,setting:a.setting}};if(!n||!r||n===`permission`&&!i||n===`location`&&r===`set`&&(!e.positionals?.[2]||!e.positionals?.[3])||n===`reset-keychain`&&e.positionals?.[2]!==void 0)return t(`INVALID_ARGS`,ne);let o=r;if(n===`text-size`){let e=te(r);if(e===void 0)return t(`INVALID_ARGS`,ie(r));o=e}return{ok:!0,parsed:{leg:`write`,args:{setting:n,state:o,permissionTarget:i,permissionMode:e.positionals?.[3],latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}}}function q(e){if(e.setting===`permission`)return{permissionTarget:e.permissionTarget,permissionMode:e.permissionMode};if(e.setting===`location`&&e.state===`set`)return{latitude:O(e.latitude,`latitude`),longitude:O(e.longitude,`longitude`)}}function ye(e,t,n){let{setting:r,state:i}=e;return r===`clear-app-state`?{setting:`clear-app-state`,state:`clear`,appBundleId:t,platform:n}:r===`location`&&i===`set`?{setting:r,state:i,latitude:e.latitude,longitude:e.longitude,platform:n}:r===`permission`?{setting:r,state:i,permissionTarget:e.permissionTarget,permissionMode:e.permissionMode,platform:n}:{setting:r,state:i,appBundleId:t,platform:n}}function be(e){return typeof e.message==`string`&&e.message.length>0?e.message:void 0}async function xe(e,t,n){let{setting:r,state:i}=t,a=await e.operations.setSetting(t);return a&&typeof a==`object`?ee({setting:r,state:i,...a},be(a)??n):{setting:r,state:i,...T(n)}}async function Se(e){return e.parsed.leg===`read`?await Ce(e,e.parsed.setting):await we(e,e.parsed.args)}async function Ce(e,t){let{req:n,logPath:r,sessionStore:i,session:a,device:o,inspectFacts:s,bindDevice:c}=e,l=J(o,t);if(l!==void 0)return l;let d=await v({command:`settings ${t}`,device:o,use:u,inspectFacts:s,bindDevice:c,...a?{}:{readiness:{}}});if(d.type===`response`)return d.response;A({level:`debug`,phase:`settings_read`,data:{setting:t,platform:o.platform}});let f=y(r,n.flags,a?.appBundleId,a?.trace?.outPath),p=await d.runtime.operations.readSetting({setting:t,execution:b(f)}),m={...p,...T(re(p))};return L(i,a,n,m),{ok:!0,data:m}}async function we(e,t){let{req:n,logPath:r,sessionStore:i,session:a,device:o,inspectFacts:c,bindDevice:l}=e,{setting:u,state:d}=t,f=J(o,u);if(f!==void 0)return f;let p=await v({command:`settings`,device:o,use:s,inspectFacts:c,bindDevice:l,...a?{}:{readiness:{}}}),m=Te(n,t,a);if(p.type===`response`)return p.response;let h=Ee(t,m);if(h!==void 0)return h;a&&_(a),A({level:`debug`,phase:`settings_apply`,data:ye(t,m,o.platform)});let g=await xe(p.runtime,De(t,m,y(r,n.flags,m,a?.trace?.outPath)),oe(u,d,m));return L(i,a,n,g),{ok:!0,data:g}}function J(e,o){if(n(e)&&!E(o))return t(`INVALID_ARGS`,ae(o));if(o===`text-size`&&r(e.platform)&&!i(e))return t(`UNSUPPORTED_OPERATION`,D.message,{deviceKind:e.kind,appleOs:a(e),reason:D.reason},{hint:D.hint})}function Te(e,t,n){return t.appBundleId??e.internal?.settingsAppBundleId??n?.appBundleId}function Ee(e,n){if(e.setting===`clear-app-state`&&!n)return t(`INVALID_ARGS`,`settings clear-app-state requires an app id when no app is bound to the session`)}function De(e,t,n){let r=q(e);return{setting:e.setting,state:e.state,...t===void 0?{}:{appBundleId:t},...r===void 0?{}:{options:r},execution:b(n)}}async function Oe(e){return await P({...e,command:`diff`,execute:async({runtime:e,sessionName:t,req:n,snapshotScope:r})=>{let i=await e.capture.diffSnapshot({session:t,interactiveOnly:n.flags?.snapshotInteractiveOnly,depth:n.flags?.snapshotDepth,scope:r,raw:n.flags?.snapshotRaw});return{data:i,record:{kind:`diff`,mode:`snapshot`,baselineInitialized:i.baselineInitialized,summary:i.summary}}}})}function ke(e){return e!==`sleep`}const Ae=[`application`,`window`,`tabbar`,`scrollbar`,`image`],je=new Set([`tab bar`]);async function Me(e,n){if(n.ok||!Ne(n.error.details?.reason)||n.error.details?.captureStalled===!0||n.error.details?.captureTruncated===!0)return n;let r=await Pe(e).catch(()=>null);return r?t(n.error.code,`${n.error.message}. Current surface: ${r.summary}.`,{...n.error.details??{},currentSurface:r.details}):n}function Ne(e){return e===w.targetAbsent||e===w.stableTimeout}async function Pe(e){let t={...e.req.flags,snapshotInteractiveOnly:!0},n=await C({device:e.device,session:e.session,flags:t,logPath:e.logPath??``,captureData:async()=>await e.capture(x({flags:t,logPath:e.logPath??``,meta:e.req.meta,session:e.session,snapshotScope:void 0}))});N(e.activationProof,n.snapshot);let r=[...n.snapshot.nodes].sort(Fe),i=Y(r,6,{includeIdentifiers:!0});if(i.length===0)return null;let a=Y(r.filter(e=>!Q(e)),4,{includeIdentifiers:!1}),o=Y(r.filter(Le),4,{includeIdentifiers:!0});return{summary:(a.length>0?a:i.slice(0,4)).join(`, `),details:{labels:i,...o.length>0?{buttons:o}:{}}}}function Y(e,t,n){let r=new Set,i=[];for(let a of e){let e=Z(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function Fe(e,t){return X(e)-X(t)||Ie(e,t)}function X(e){let t=!!Z(e,{includeIdentifiers:!1});return(Q(e)?2:0)+ +!t}function Ie(e,t){return e.rect&&t.rect?e.rect.y-t.rect.y||e.rect.x-t.rect.x:e.rect?-1:t.rect?1:(e.depth??0)-(t.depth??0)||e.index-t.index}function Z(e,t){let n=(t.includeIdentifiers?[e.label,e.value,e.identifier]:[e.label,e.value]).map(e=>typeof e==`string`?e.trim():``).find(e=>e.length>0);return n?n.replaceAll(/\s+/g,` `).slice(0,80):``}function Q(e){let t=c(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return Ae.some(e=>t.includes(e))||je.has(n)||n.endsWith(`.fill`)}function Le(e){let t=`${e.type??``} ${e.role??``} ${e.subrole??``}`;return c(t).includes(`button`)}async function Re(e){let{req:t,sessionName:n,sessionStore:r}=e,i=ze(t);if(`ok`in i)return i;let a=i,{session:o,device:s}=await I(r,n,t.flags),c=await Be(e,a,o,s);if(c&&`ok`in c)return c;let l=c,u=t.internal?.replayLandmarkGuard,d=Ve(a,o);if(`ok`in d)return d;let{waitParsed:f,staleRefsWarning:p}=d;return e.consumedSnapshot??={},e.activationProof??={},a.kind===`sleep`?await $(e,f,o,s,l,p,u):M({response:await R(o,s,()=>$(e,f,o,s,l,p,u),e.platformResourceCleanup),consumedTree:le(e),activationProof:e.activationProof})}function ze(e){let n=p(e.positionals??[]);if(!n)return t(`INVALID_ARGS`,`wait requires a duration or text`);if(n.kind===`invalid`)return t(`INVALID_ARGS`,n.message);if(n.kind!==`absent`)return n;let r=se({depth:e.flags?.snapshotDepth,scope:e.flags?.snapshotScope});if(!r)return n;let i=k(r,`wait`);return t(i.code,i.message,i.details)}async function Be(e,t,n,r){if(!ke(t.kind))return;let i=await V({command:`wait`,device:r,session:n,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});return i.ok?i.operations:i.response}function Ve(e,t){if(e.kind!==`ref`)return{waitParsed:e};let n=H(e.rawRef);return n.ok?{waitParsed:{...e,rawRef:n.ref},staleRefsWarning:S({session:t,ref:n.ref,mintedGeneration:n.generation})}:n.response}async function $(e,t,n,r,i,a,o){let{req:s,sessionName:c,sessionStore:l}=e,u=B({...e,session:n,device:r,bound:i}),d=await ce(async()=>{let e=await u.selectors.wait({session:c,requestId:s.meta?.requestId,target:He(t,n,o)}),r=G(e);K(l,c,s,W(e),r,`landmark`);let i=U(e);return a?{...i,warning:a}:i}),f=i?await Me({req:s,logPath:e.logPath,session:n,device:r,capture:i.capture,activationProof:e.activationProof},d):d;return await z(e,f,`wait`)}function He(e,t,n){switch(e.kind){case`sleep`:return{kind:`sleep`,durationMs:e.durationMs};case`selector`:return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...n?{recordedLandmark:n}:{}};case`absent`:return{kind:`absent`,selector:e.selectorExpression,timeoutMs:e.timeoutMs};case`ref`:return We(e,t);case`stable`:return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};case`text`:return Ge(e);default:return Ue(e)}}function Ue(e){throw Error(`Unsupported wait positional target: ${String(e)}`)}function We(t,n){if(!n?.snapshot)throw new e(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:t.rawRef,timeoutMs:t.timeoutMs}}function Ge(t){let n=m(t.text);if(!n.ok)throw new e(n.code,n.message);return{kind:`text`,text:n.text,timeoutMs:t.timeoutMs}}const Ke={snapshot:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>await F({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o}),diff:async({req:e,sessionName:n,logPath:r,sessionStore:i,inspectFacts:a,bindDevice:o,platformResourceCleanup:s})=>e.positionals?.[0]===`snapshot`?await Oe({req:e,sessionName:n,logPath:r,sessionStore:i,inspectFacts:a,bindDevice:o,platformResourceCleanup:s}):t(`INVALID_ARGS`,`diff currently supports only: diff snapshot`),wait:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>await Re({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o}),alert:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>{let{session:s,device:c}=await I(r,t,e.flags);return await R(s,c,async()=>await he({req:e,logPath:n,sessionStore:r,session:s,device:c,inspectFacts:i,bindDevice:a}),o)},settings:async({req:e,sessionName:t,logPath:n,sessionStore:r,inspectFacts:i,bindDevice:a,platformResourceCleanup:o})=>{let s=ve(e);if(!s.ok)return s;let{session:c,device:l}=await I(r,t,e.flags);return await R(c,l,async()=>await Se({req:e,logPath:n,sessionStore:r,session:c,device:l,parsed:s.parsed,inspectFacts:i,bindDevice:a}),o)}};async function qe(e){let t=e.req.command,n=Ke[t];return n?await n(e):null}export{qe as handleSnapshotCommands};
|
package/dist/src/src.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{D as t}from"./sdk-contracts.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{D as t}from"./sdk-contracts.js";import{Qt as n}from"./sdk-batch.js";import{c as r,i,s as a}from"./request-cancellation.js";import{t as o}from"./api.js";import{a as s,i as c,l,n as u,o as d,s as f,t as p}from"./device-session.js";import{scryptSync as m}from"node:crypto";const h=`agent-device-cli`;function g(e){return{apiKey:e.apiKey,defaultHeaders:{"x-agent-device-client":h,"x-agent-device-version":e.clientVersion}}}function _(e){if(e.runtimeInstance!==void 0){let t=e.runtimeInstance.trim();if(!t)throw TypeError(`Limrun runtimeInstance must be a non-empty string`);return t}let t=JSON.stringify({provider:`limrun`,region:e.region?.trim().toLowerCase()||`default`,apiKey:e.apiKey});return`principal-${m(t,`agent-device:limrun-runtime-owner:v1`,32,{N:16384,r:8,p:1,maxmem:67108864}).toString(`hex`)}`}function v(e,t,r){let a=new y(e,t);if(!r?.includePlatformModule)return a;let o=n(i,_(e));if(o.kind!==`provider-runtime`)throw TypeError(`Invalid Limrun runtime owner`);return Object.freeze({runtime:a,platformModule:Object.freeze({owner:o,loadRuntime:async e=>await b(a,o.instance,e)})})}var y=class{limrun;sessions=new Map;appAliases=new Map;options;dependencies;provider=i;leaseLifecycle={allocate:async(e,t)=>await this.allocate(e,t),release:async e=>await this.release(e)};appCatalog=async(e,t)=>{let{assertLimrunUploadedAppAccess:n,listLimrunAppAssets:r}=await import(`./app-catalog.js`);return n(e.publicNetworkOnly),(await r(this.limrun,e.platform,t)).map(e=>e.name)};recoverExpiredLease=async e=>{if(e.leaseProvider!==this.provider||!r(e.backend))throw new t(`UNSUPPORTED_OPERATION`,`Limrun cannot recover this expired lease.`,{leaseId:e.leaseId,leaseProvider:e.leaseProvider,leaseBackend:e.backend});await this.release(e)};deviceInventoryProvider=async e=>{if(e.leaseProvider!==this.provider||!e.leaseId)return null;let t=this.sessions.get(e.leaseId);return t?e.platform&&e.platform!==t.platform?[]:[t.device]:null};constructor(e,t){this.options=e,this.dependencies=t,this.limrun=new o(g({apiKey:e.apiKey,clientVersion:t.clientVersion}))}ownsDevice(e){return a(e.id)!==void 0}hasLiveSession(e){return this.getSessionForDevice(e)!==void 0}getInteractor(e,t){let n=this.getSessionForDevice(e);if(n)return n.platform===`ios`?u(n):f(n)}getDeviceSession(e){let t=this.getSessionForDevice(e);return t?p(t):void 0}async installApp(e,t,n,r,i,a){return await this.installInstallablePath(e,n,{...r,appIdentifierHint:r?.appIdentifierHint??t,packageNameHint:r?.packageNameHint??t},i,a)}async installInstallablePath(e,t,n,r,i){let a=this.getSessionForDevice(e);if(a)return a.platform===`ios`?await c(this.limrun,a,t,n,r,i):await l(this.limrun,a,t,n,r,i)}async configurePortReverse(e){let t=this.requireAndroidPortReverseSession(e.leaseId);if(t)return await d(t,e),x(e)}async shutdown(){let e=[...this.sessions.values()];await Promise.allSettled(e.map(async e=>await this.terminateSession(e))),this.sessions.clear(),this.appAliases.clear()}async allocate(e,t){if(e.leaseProvider!==this.provider)return;let n=r(e.backend);if(!n)return;let i=this.sessions.get(e.leaseId);if(i)return{limrunInstanceId:i.instanceId,device:i.device};let{allocateLimrunAndroidSession:a,allocateLimrunIosSession:o,resolvePreinstalledAppId:s,resolveRequestedLimrunAppAsset:c}=await import(`./session-allocation.js`),l=await c(this.limrun,n,t),u=n===`ios`?await o(this.sessionAllocationParams(e,l)):await a(this.sessionAllocationParams(e,l));if(l)try{let t=await s(u,l);this.appAliases.set(e.leaseId,{assetName:l.name,installedAppId:t})}catch(e){throw await this.terminateSession(u),e}return this.sessions.set(e.leaseId,u),{limrunInstanceId:u.instanceId,device:u.device}}sessionAllocationParams(e,t){return{limrun:this.limrun,lease:e,metadata:this.buildInstanceMetadata(e),region:this.options.region,app:t,dependencies:this.dependencies}}buildInstanceMetadata(e){return{displayName:`agent-device-${e.tenantId}-${e.runId}`,labels:{tenantId:e.tenantId,runId:e.runId,leaseId:e.leaseId,provider:e.leaseProvider??`limrun`,source:h}}}async release(e){let t=this.sessions.get(e.leaseId);return t?(await this.terminateSession(t),this.sessions.delete(e.leaseId),this.appAliases.delete(e.leaseId),{limrunInstanceId:t.instanceId}):await this.releaseRecoveredSession(e)}async releaseRecoveredSession(e){let t=r(e.backend);if(!t)return;let n=`provider=${i},leaseId=${e.leaseId}`,a=(t===`ios`?await this.limrun.iosInstances.list({labelSelector:n}):await this.limrun.androidInstances.list({labelSelector:n})).getPaginatedItems().map(e=>e.metadata.id);for(let e of a)t===`ios`?await this.limrun.iosInstances.delete(e):await this.limrun.androidInstances.delete(e);if(a.length!==0)return{limrunInstanceId:a[0],limrunInstanceCount:a.length}}async terminateSession(e){if(e.client.disconnect(),e.platform===`ios`){await this.limrun.iosInstances.delete(e.instanceId);return}await s(e),await this.limrun.androidInstances.delete(e.instanceId)}getSessionForDevice(e){let t=a(e.id);if(!t)return;let n=this.sessions.get(t.leaseId);return n?.platform===t.platform?n:void 0}resolveAppReference(e,t){let n=a(e.id);if(!n)return t;let r=this.appAliases.get(n.leaseId);return r?.assetName===t?r.installedAppId:t}currentAppLogReader(e){let t=this.getSessionForDevice(e);if(!t)return;let n=p(t);return{platform:t.platform,leaseId:t.lease.leaseId,instanceId:t.instanceId,readLogs:async(e,t)=>n.platform===`ios`?await n.readLogs(e,t):await n.readLogs(t),[Symbol.asyncDispose]:async()=>void 0}}async reconnectAppLogReader(e,t){let{reconnectLimrunAppLogReader:n}=await import(`./app-log-reconnect.js`);return await n({limrun:this.limrun,descriptor:e,dependencies:this.dependencies,signal:t})}requireAndroidPortReverseSession(e){let t=this.sessions.get(e);if(!t||t.platform===`android`)return t;throw S(`port reverse`,`Direct Limrun iOS sessions cannot reach local host ports; use a bridge public URL.`)}};async function b(e,n,r){let{createLimrunPlatformRuntimeOwner:i}=await import(`./app-log-runtime2.js`);return i({host:r,runtimeInstance:n,ownsDevice:t=>e.ownsDevice(t),hasLiveSession:t=>e.hasLiveSession(t),getInteractor:(t,n)=>e.getInteractor(t,n),getDeviceSession:t=>e.getDeviceSession(t),resolveAppReference:(t,n)=>e.resolveAppReference(t,n),openCurrent:async t=>e.currentAppLogReader(t),reconnect:async(t,n)=>await e.reconnectAppLogReader(t,n),listApps:async(n,r,i)=>{i.throwIfAborted();let a=e.getDeviceSession(n);if(!a)throw new t(`DEVICE_NOT_FOUND`,`Limrun app inventory session is unavailable`,{deviceId:n.id});return(await a.listApps(r)).map(e=>({id:e.id,name:e.name??e.id}))},getAppState:async(n,r)=>{r.throwIfAborted();let i=e.getDeviceSession(n);if(i?.platform!==`android`)throw new t(`UNSUPPORTED_OPERATION`,`Limrun Android appstate requires an active provider session`);let a=await i.getForegroundApp(r);return r.throwIfAborted(),{package:a?.appId,activity:a?.activity}},deployApp:async(t,n,r,i)=>await e.installApp(t,n.app,n.appPath,{relaunch:n.replaceExisting,appIdentifierHint:n.app,packageNameHint:n.app},r,i),deployMaterializedApp:async(t,n,r,i)=>await e.installInstallablePath(t,n.artifact.installablePath,{appIdentifierHint:n.artifact.bundleId,packageNameHint:n.artifact.packageName},r,i),configurePortReverse:async t=>await e.configurePortReverse(t)})}function x(e){return{leaseId:e.leaseId,devicePort:e.devicePort,hostPort:e.hostPort,name:e.name}}function S(e,n){throw new t(`UNSUPPORTED_OPERATION`,n,{command:e})}async function C(e){let n=new o({...g(e),timeout:15e3,maxRetries:0}),r={limit:1,...e.region?{region:e.region}:{}};try{e.platform===`android`?await n.androidInstances.list(r):await n.iosInstances.list(r)}catch(e){let n=w(e);throw n===401||n===403?new t(`UNAUTHORIZED`,`Limrun rejected connection verification.`,{status:n,hint:`Check LIMRUN_API_KEY and its organization access.`}):new t(`COMMAND_FAILED`,`Limrun connection verification failed.`,{hint:`Check Limrun service access, LIMRUN_REGION, and network connectivity, then retry.`},e)}let i=e.platform===`android`?`Android`:`iOS`,a=e.platform===`android`?`emulator`:`simulator`;return{provider:`limrun`,service:`Limrun`,verificationMessage:`Credentials and ${i} instance access verified.`,device:{status:`deferred`,name:`Provider-selected ${i} ${a}`,platform:e.platform},app:{status:`missing`,message:`Run apps to choose an uploaded asset before allocation.`}}}function w(e){if(!e||typeof e!=`object`)return;let t=e.status;return typeof t==`number`?t:void 0}var T=e({LIMRUN_PROVIDER:()=>i,createLimrunRuntime:()=>v,verifyLimrunConnection:()=>C});export{C as n,v as r,T as t};
|
package/dist/src/src7.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{T as t}from"./sdk-device.js";import{Kt as n,Zt as r}from"./sdk-batch.js";import{t as i}from"./audio-probe-runtime.js";import{a,n as o,t as s}from"./durable-resource.js";import{n as c}from"./async-lifecycle.js";import{n as l,t as u}from"./audio-probe-result.js";import d from"node:fs/promises";function f(e,t){if(e.resourceKind!==t.resourceKind)return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Durable resource kind ${e.resourceKind} does not match ${t.resourceKind}`};if(e.descriptor.version!==t.version)return{status:`unreattachable`,reason:`descriptor-version-unsupported`,message:`Unsupported ${t.resourceKind} descriptor version: ${e.descriptor.version}`,version:e.descriptor.version};try{let n=t.decode(e.descriptor.body);return n.status===`decoded`?n:{status:`unreattachable`,reason:`descriptor-invalid`,message:n.message}}catch(e){return{status:`unreattachable`,reason:`descriptor-invalid`,message:e instanceof Error?e.message:`Descriptor codec rejected the body`}}}function p(e,t){return Object.freeze({pendingHandle:new c(e),envelope:t})}function m(e){return Object.freeze({appLogReattach:async({envelope:t})=>{let n=f(t,e.codec);return n.status===`unreattachable`?n:await e.reattach(n.descriptor,h(t))},appLogCleanup:async({envelope:t})=>{let n=f(t,e.codec);return n.status===`decoded`?await e.cleanup(n.descriptor,h(t)):{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message}}})}function h(e){return Object.freeze({sessionId:e.sessionId,fence:e.fence})}function g(e){if(typeof e!=`object`||!e||Array.isArray(e))return{status:`invalid`,message:`App-log process marker must be an object`};let t=e;return!Number.isInteger(t.pid)||Number(t.pid)<=0?{status:`invalid`,message:`App-log process marker pid must be a positive integer`}:typeof t.startTime!=`string`||t.startTime.trim().length===0?{status:`invalid`,message:`App-log process marker startTime must be a non-empty string`}:typeof t.command!=`string`||t.command.trim().length===0?{status:`invalid`,message:`App-log process marker command must be a non-empty string`}:{status:`decoded`,marker:Object.freeze({pid:Number(t.pid),startTime:t.startTime,command:t.command})}}function _(e){let t,n,r,i=()=>n??=e.forceCleanup();return Object.freeze({inspect:()=>e.inspect(),finish:()=>t??=e.finish(),forceCleanup:i,[Symbol.asyncDispose]:async()=>{r??=i().then(ee),await r}})}function v(e){return _({inspect:e.inspect,finish:e.finish,forceCleanup:async()=>{let t=await e.finish();return t.status===`completed`?{status:`cleaned`}:{status:`cleanup-pending`,reason:t.reason,message:t.message}}})}function ee(t){if(!s(t))throw new e(`COMMAND_FAILED`,t.message??`Durable resource cleanup could not be confirmed`,{reason:t.reason,retriable:t.reason!==`ownership-fence-lost`,hint:t.reason===`ownership-fence-lost`?`Use the current resource owner or recovery record before retrying cleanup.`:`Keep the recovery record and retry cleanup through the exact runtime owner.`})}const te=e=>b(e.backend)&&(e.source===`system-audio`||e.source===`media-elements`)&&x(e.sourceCount,0)&&re(e.notes)&&b(e.statusPath)&&x(e.startedAt,1)&&x(e.durationMs,1)&&x(e.bucketMs,1),y=Object.freeze({resourceKind:i,version:1,encode:e=>({...e,notes:[...e.notes],marker:{...e.marker}}),decode:e=>{let t=te(e)?ne(e.marker):`invalid`;if(t===`invalid`)return{status:`invalid`,message:`Audio probe descriptor body is invalid`};let n=e;return{status:`decoded`,descriptor:Object.freeze({backend:n.backend,source:n.source,sourceCount:n.sourceCount,notes:Object.freeze([...n.notes]),statusPath:n.statusPath,startedAt:n.startedAt,durationMs:n.durationMs,bucketMs:n.bucketMs,marker:t})}}});function ne(e){if(typeof e!=`object`||!e)return`invalid`;let t=e;return!x(t.pid,1)||!b(t.startTime)||!b(t.command)?`invalid`:Object.freeze({pid:t.pid,startTime:t.startTime,command:t.command})}function b(e){return typeof e==`string`&&e.length>0}function x(e,t){return typeof e==`number`&&Number.isInteger(e)&&e>=t}function re(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}async function S(e){try{let t=await d.readFile(e.statusPath,`utf8`);return l(JSON.parse(t),{source:e.source,backend:e.backend,durationMs:e.durationMs,elapsedMs:Date.now()-e.startedAt,bucketMs:e.bucketMs,activeFallback:!0,sourceCount:e.sourceCount,notes:[...e.notes]})}catch(e){if(e.code===`ENOENT`)return;throw e}}function C(e,t,n){let r=Math.min(e.durationMs,Math.max(0,Date.now()-e.startedAt));return{...t??u({source:e.source,backend:e.backend,durationMs:e.durationMs,bucketMs:e.bucketMs,sourceCount:e.sourceCount,notes:[...e.notes]}),state:`stopped`,active:!1,elapsedMs:r,stoppedAt:new Date().toISOString(),reason:n}}function ie(e){let{host:t}=e;return Object.freeze({audioProbeReattach:async e=>{let n=f(e.envelope,y);if(n.status!==`decoded`)return n;let r=n.descriptor,i=await t.inspectProcess(r.marker);if(i===`owned-alive`)return{status:`unreattachable`,reason:`transport-not-reattachable`};if(i===`ownership-lost`)return{status:`unreattachable`,reason:`ownership-fence-lost`};let a=await S(r);return a===void 0||a.state!==`stopped`?{status:`missing`}:{status:`completed`,result:C(r,a,`daemon-recovery`)}},audioProbeCleanup:async e=>{let n=f(e.envelope,y);if(n.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message};let r=n.descriptor,i=await t.inspectProcess(r.marker);if(i===`ownership-lost`)return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(i===`missing`)return{status:`already-missing`};let a=await t.terminateProcess(r.marker);return a===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:{status:a===`terminated`?`cleaned`:`already-missing`}}})}async function ae(n){let{host:r,device:s,owner:l,input:u}=n,f=Date.now(),p=r.info,m=Object.freeze([...p.notes(s)]),h=Object.freeze({source:p.source,backend:p.backend,sourceCount:p.sourceCount,notes:m,statusPath:u.statusPath,startedAt:f,durationMs:u.durationMs,bucketMs:u.bucketMs});await d.rm(u.statusPath,{force:!0});let g=await r.start({durationMs:u.durationMs,bucketMs:u.bucketMs,statusPath:u.statusPath});g.wait.catch(()=>{});let _=g.marker;try{if(_===void 0)throw new e(`COMMAND_FAILED`,`failed to start host audio probe: the helper process exposed no exact identity, so the capture could not be recovered after daemon loss and was terminated`);await ue(h,g)}catch(e){throw await g.terminate().catch(()=>{}),e}return Object.freeze({pendingHandle:new c(oe(h,g)),envelope:o({resourceKind:i,sessionId:u.sessionId,device:t(s),owner:l,fence:u.fence,lifecycle:`open`,descriptor:a(y,{backend:p.backend,source:p.source,sourceCount:p.sourceCount,notes:m,statusPath:u.statusPath,startedAt:f,durationMs:u.durationMs,bucketMs:u.bucketMs,marker:_})})})}function oe(e,t){let n,r,i,a;t.wait.then(e=>{a={message:se(e)}},e=>{a={message:e instanceof Error?e.message:`audio probe helper wait failed`}});let o=()=>n??=(async()=>{let n=await S(e);if(n?.state!==`stopped`&&a)throw w(a);return await t.terminate().catch(()=>{}),await t.wait.catch(()=>{}),{status:`completed`,result:C(e,n,`stopped`)}})(),s=()=>r??=n?n.then(async()=>({status:`cleaned`}),async()=>await T(t)):T(t);return Object.freeze({inspect:()=>e,status:async()=>{let t=await S(e);if(t?.state===`stopped`)return t;if(a)throw w(a);return t??C(e,void 0,`not-started`)},finish:o,forceCleanup:s,[Symbol.asyncDispose]:async()=>{i??=s().then(ce),await i}})}function se(e){return e.stderr?.trim()||e.stdout?.trim()||`audio probe helper exited with code ${e.exitCode??1}`}function w(t){return new e(`COMMAND_FAILED`,`host audio probe helper exited before completing the capture: ${t.message}`,{hint:`Keep audio-probe.resource.json; stop resolves the record through descriptor cleanup.`})}async function T(e){try{return await e.terminate(),await e.wait.catch(()=>{}),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`cleanup-unconfirmed`,message:e instanceof Error?e.message:`Audio probe termination failed`}}}function ce(t){if(!s(t))throw new e(`COMMAND_FAILED`,t.message??`Audio probe cleanup could not be confirmed`,{reason:t.reason,retriable:t.reason!==`ownership-fence-lost`,hint:`Keep audio-probe.resource.json and retry stop through its exact runtime owner.`})}function le(e){let{host:t,device:n,owner:r}=e,i=ie({host:t});return Object.freeze({audioProbeStart:async e=>await ae({host:t,device:n,owner:r,input:e}),audioProbeReattach:i.audioProbeReattach,audioProbeCleanup:i.audioProbeCleanup})}async function ue(t,n){let r=Date.now()+5e3;for(;Date.now()<r;){if(await S(t))return;let r=await Promise.race([n.wait.then(e=>e,e=>e),de(100).then(()=>void 0)]);if(r instanceof Error)throw r;if(r){let t=r,n=t.stderr?.trim()||t.stdout?.trim()||`host audio probe helper exited with code ${t.exitCode??1}`;throw new e(`COMMAND_FAILED`,`failed to start host audio probe: ${n}`)}}throw new e(`COMMAND_FAILED`,`failed to start host audio probe`)}function de(e){return new Promise(t=>setTimeout(t,e))}async function E(e,t){let n=await O(e,t);if(n.status===`missing`)return{status:`missing`};if(n.status===`invalid`)return{status:`unreattachable`,reason:`ownership-fence-lost`,message:n.message};let r=await e.processes.inspect(n.marker);return r===`missing`?(t&&await e.processes.clearMarker(t),{status:`missing`}):r===`ownership-lost`?{status:`unreattachable`,reason:`ownership-fence-lost`}:{status:`unreattachable`,reason:`transport-not-reattachable`}}async function D(e,t){if(!t)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`App-log process marker path is missing`};let n=await O(e,t);if(n.status===`missing`)return{status:`already-missing`};if(n.status===`invalid`)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message};let r=await e.processes.inspect(n.marker);if(r===`ownership-lost`)return k();if(r===`missing`)return await e.processes.clearMarker(t),{status:`already-missing`};let i=await e.processes.terminate(n.marker);return i===`ownership-lost`?k():(await e.processes.clearMarker(t),{status:i===`terminated`?`cleaned`:`already-missing`})}async function O(e,t){return t?await e.processes.readMarker(t):{status:`invalid`,message:`App-log process marker path is missing`}}function k(){return{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function fe(e){let t=e.initialProcess;for(;!e.stopped();){if(t){await pe(e,t),t=void 0,await be(e);continue}let n=await xe(e);if(n.status===`stopped`)return;n.status!==`waiting`&&(t=n.process)}}async function pe(e,t){let{process:n}=t;e.setActive(n);try{e.setState(`active`),await me(e,t)}finally{await A(e,n)}}async function me(e,t){let n=he(t.process);try{await ge(e,t,n),await ve(e,t.process,n),await ye(n.outcome)}finally{n.controller.abort()}}function he(e){let t=new AbortController,n=!1,r=()=>{n=!0,t.abort()};return{controller:t,outcome:e.wait.then(()=>(r(),{status:`exited`}),e=>(r(),{status:`failed`,error:e})),settled:()=>n}}async function ge(e,t,n){for(;!e.stopped()&&!n.settled();){if(!await _e(e,n))return;let r=await e.resolvePid();if(e.stopped())return;if(r!==t.pid){await t.process.terminate();return}}}async function _e(e,t){try{await e.sleep(500,t.controller.signal)}catch(e){if(!t.settled())throw e}return!t.settled()}async function ve(e,t,n){e.stopped()&&!n.settled()&&await t.terminate()}async function ye(e){let t=await e;if(t.status===`failed`)throw t.error}async function be(e){e.stopped()||(e.setState(`recovering`),await e.sleep(500))}async function xe(e){let t=await e.resolvePid();if(e.stopped())return{status:`stopped`};if(!t)return e.setState(`recovering`),await e.sleep(1e3),{status:`waiting`};let n=await e.startProcess(t);return e.setActive(n),e.stopped()?(await Se(e,n),{status:`stopped`}):{status:`started`,process:{pid:t,process:n}}}async function Se(e,t){try{await t.terminate(),await t.wait}finally{await A(e,t)}}async function A(e,t){try{await t[Symbol.asyncDispose]()}finally{e.setActive(void 0)}}async function Ce(e){let t=await e.resolvePid(e.setupSignal);e.setupSignal.throwIfAborted();let n=await e.host.outputs.openAppend(e.outputPath),r=`recovering`,i=!1,a;try{if(e.setupSignal.throwIfAborted(),t){e.setupSignal.throwIfAborted();let i=new AbortController,o=()=>i.abort(e.setupSignal.reason);e.setupSignal.addEventListener(`abort`,o,{once:!0});try{a=await e.processStart({command:e.command(t),output:n,markerPath:e.pidPath},i.signal)}finally{e.setupSignal.removeEventListener(`abort`,o)}e.setupSignal.throwIfAborted(),r=`active`}}catch(e){throw await j([async()=>await a?.terminate(),async()=>{await a?.wait},async()=>await a?.[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()]),e}let o=fe({initialProcess:a&&t?{pid:t,process:a}:void 0,stopped:()=>i,setActive:e=>{a=e},setState:e=>{r=e},resolvePid:async()=>await e.resolvePid(),startProcess:async t=>await e.processStart({command:e.command(t),output:n,markerPath:e.pidPath}),sleep:async(t,n)=>await e.host.clock.sleep(t,n)}).catch(()=>{r=`failed`}),s,c=async()=>s??=we({options:e,monitor:o,active:()=>a,stop:()=>{i=!0},setState:e=>{r=e},output:n}),l=e.host.clock.now();return v({inspect:()=>({backend:e.backend,state:r,startedAt:l}),finish:c})}async function we(e){return e.stop(),(await j([async()=>await e.active()?.terminate(),async()=>await e.monitor,async()=>await e.output[Symbol.asyncDispose]()])).length>0?(e.setState(`failed`),{status:`cleanup-pending`,reason:`transport-failed`,message:e.options.cleanupFailureMessage}):(e.setState(`ended`),{status:`completed`,result:{backend:e.options.backend,outputPath:e.options.outputPath,completedAt:e.options.host.clock.now()}})}async function j(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}function M(e,t,n){let r=e.artifacts.resolveSession(t);return n.outputPath===r.outputPath&&(n.pidPath===void 0||n.pidPath===r.pidPath)}function N(t,n){if(!M(t,n.sessionId,n))throw new e(`INVALID_ARGS`,`App-log paths do not match the owning session`)}const P=Object.freeze({available:!0});async function Te(e,t,n){let r=(await e.commands.run(t,n)).stdout.trim().split(/\s+/)[0]??``;return/^\d+$/.test(r)?r:``}function Ee(t,i){let a=n(i.family);return Object.freeze({owner:a,ownsDevice:e=>e.platform===i.family,inspectFacts:async e=>F(e,await t.processTransports.resolve(e),i),bind:async n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,a))throw new e(`UNSUPPORTED_OPERATION`,`${i.label} app-log owner identity does not match`);if(n.device.platform!==i.family)throw new e(`UNSUPPORTED_PLATFORM`,`${i.label} app-log owner cannot bind ${n.device.platform}`);let o=await t.processTransports.resolve(n.device);return De(t,n.device,n.scope.signal,o,a,i)},shutdown:async()=>void 0})}function De(e,t,n,r,i,a){let o=m({codec:a.codec,reattach:async(t,n)=>M(e,n.sessionId,t)?await E(e,t.pidPath):{status:`unreattachable`,reason:`descriptor-invalid`,message:`${a.label} app-log descriptor paths do not match the owning session`},cleanup:async(t,n)=>M(e,n.sessionId,t)?await D(e,t.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`${a.label} app-log descriptor paths do not match the owning session`}}),s=Object.freeze({appLogInspect:async()=>({backend:a.backend}),appLogDoctor:async({appBundleId:r})=>await a.doctor({host:e,device:t,signal:n},r),...r.start?{appLogStart:async o=>await Oe(e,t,n,r,i,o,a)}:{},...o});return Object.freeze({device:t,owner:i,facts:F(t,r,a),operations:s,[Symbol.asyncDispose]:async()=>void 0})}function F(e,t,n){let r=t.start?P:{available:!1,reason:`owner-capability-missing`,hint:n.startUnavailableHint};return Object.freeze({device:{family:n.family,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:P,appLogDoctor:P,appLogStart:r,appLogReattach:P,appLogCleanup:P}})}async function Oe(t,n,r,i,a,o,s){if(!i.start)throw new e(`UNSUPPORTED_OPERATION`,s.startUnavailableHint);N(t,o);let c=t.artifacts.resolveSession(o.sessionId),l={host:t,device:n,signal:r,input:o,artifacts:c,transport:i};s.validateStart?.(l),r.throwIfAborted();let u=await s.process(l);r.throwIfAborted();let d=await Ce({host:t,backend:s.backend,outputPath:c.outputPath,pidPath:c.pidPath,processStart:i.start,setupSignal:r,resolvePid:u.resolvePid,command:u.command,cleanupFailureMessage:s.cleanupFailureMessage}),f=s.descriptor({artifacts:c,transport:i});return p(d,s.envelope({input:o,device:n,owner:a,descriptor:f}))}function I(e){for(let t of[/\bstatus(?:Code)?["'=: ]+([1-5]\d{2})\b/i,/\bresponse(?:\s+code)?["'=: ]+([1-5]\d{2})\b/i,/\bHTTP\/[0-9.]+\s+([1-5]\d{2})\b/i]){let n=t.exec(e);if(!n)continue;let r=Number.parseInt(n[1]??``,10);if(Number.isInteger(r))return r}return null}function L(e){return/\b\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z)?\b/.exec(e)?.[0]??/\b\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+\b/.exec(e)?.[0]}function ke(e){let t=e.indexOf(`{`),n=e.lastIndexOf(`}`);if(t<0||n<=t)return null;try{let r=JSON.parse(e.slice(t,n+1));return r&&typeof r==`object`&&!Array.isArray(r)?r:null}catch{return null}}function R(e,t){for(let n of t){let t=e?.[n];if(typeof t==`string`&&t.trim())return t.trim()}}function Ae(e,t){for(let n of t){let t=e?.[n];if(typeof t==`number`&&Number.isInteger(t))return t;if(typeof t==`string`&&/^\d{3}$/.test(t.trim()))return Number.parseInt(t,10)}return null}function je(e,t){let n=t?.headers??t?.requestHeaders??t?.responseHeaders;return n===void 0?/\bheaders?["'=: ]+(\{.*\})/i.exec(e)?.[1]?.trim():B(n)}function z(e,t,n){for(let r of n){if(t?.[r]!==void 0)return B(t[r]);let n=r.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),i=RegExp(`\\b${n}["'=: ]+(.+)$`,`i`).exec(e);if(i?.[1])return i[1].trim()}}function B(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Me(e,t,n){let r=U(t,n,5),i=e.packetId??r.map(V).find(e=>typeof e==`string`&&e.length>0);i&&(e.packetId=i);let a=i?U(t,n,12).filter(e=>V(e)===i):r;e.timestamp??=a.map(L).find(e=>typeof e==`string`&&e.length>0),e.status??=a.map(I).find(e=>typeof e==`number`)??void 0,e.durationMs??=a.map(H).find(e=>typeof e==`number`)??void 0}function V(e){return/\bpacket id (\d+)\b/i.exec(e)?.[1]??null}function H(e){let t=/\b(?:duration|elapsed request\/response time, ms)[:= ]+(\d+)\b/i.exec(e);return t?Number.parseInt(t[1]??``,10):null}function U(e,t,n){return e.slice(Math.max(0,t-n),Math.min(e.length,t+n+1)).map(e=>e.trim()).filter(Boolean)}const Ne=RegExp(`\\b(${[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`,`HEAD`,`OPTIONS`].join(`|`)})\\b\\s+https?:\\/\\/`,`i`),Pe=/https?:\/\/[^\s"'<>\])]+/i,Fe=/\[C(\d+)\b[^\]]*?\burl:\s*([^\s,\]]+)/,W=/\bsummary for task (?:success|failure)\s*\{([^}]*)\}/,Ie=/\bTask\s+<([0-9A-Fa-f-]+)>\.<(\d+)>/,G=/(?:^|\s)(\S+)\[(\d+):[0-9a-f]+\]/,Le=/\burl:\s*(https?:\/\/[^\s,\]]+)/i;function Re(e,t,n=e.dump.limits.maxEntries){let r=[...e.dump.entries],i=new Set(r.map(K));for(let e of t.dump.entries){let t=K(e);if(!i.has(t)&&(i.add(t),r.push(e),r.length>=n))break}let a=new Set([...e.dump.entries,...t.dump.entries].map(e=>e.packetId).filter(e=>e!==void 0)),o=[...new Set([...e.unnamedRequestIds,...t.unnamedRequestIds])].filter(e=>!a.has(e));return Object.freeze({dump:Object.freeze({...e.dump,matchedLines:r.length,entries:Object.freeze(r),unnamedRequests:o.length}),unnamedRequestIds:Object.freeze(o)})}function ze(e,t){let n=J(t.maxEntries,25,1,200),r=t.include??`summary`,i=J(t.maxPayloadChars,2048,64,16384),a=J(t.maxScanLines,4e3,100,2e4),o=Ve(t.lineNumberOffset);if(!t.exists)return Object.freeze({dump:Object.freeze({path:t.path,exists:!1,scannedLines:0,matchedLines:0,entries:Object.freeze([]),unnamedRequests:0,include:r,limits:Object.freeze({maxEntries:n,maxPayloadChars:i,maxScanLines:a})}),unnamedRequestIds:Object.freeze([])});let s=e.split(`
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{E as t}from"./sdk-device.js";import{Yt as n,en as r}from"./sdk-batch.js";import{t as i}from"./audio-probe-runtime.js";import{a,n as o,t as s}from"./durable-resource.js";import{n as c}from"./async-lifecycle.js";import{n as l,t as u}from"./audio-probe-result.js";import d from"node:fs/promises";function f(e,t){if(e.resourceKind!==t.resourceKind)return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Durable resource kind ${e.resourceKind} does not match ${t.resourceKind}`};if(e.descriptor.version!==t.version)return{status:`unreattachable`,reason:`descriptor-version-unsupported`,message:`Unsupported ${t.resourceKind} descriptor version: ${e.descriptor.version}`,version:e.descriptor.version};try{let n=t.decode(e.descriptor.body);return n.status===`decoded`?n:{status:`unreattachable`,reason:`descriptor-invalid`,message:n.message}}catch(e){return{status:`unreattachable`,reason:`descriptor-invalid`,message:e instanceof Error?e.message:`Descriptor codec rejected the body`}}}function p(e,t){return Object.freeze({pendingHandle:new c(e),envelope:t})}function m(e){return Object.freeze({appLogReattach:async({envelope:t})=>{let n=f(t,e.codec);return n.status===`unreattachable`?n:await e.reattach(n.descriptor,h(t))},appLogCleanup:async({envelope:t})=>{let n=f(t,e.codec);return n.status===`decoded`?await e.cleanup(n.descriptor,h(t)):{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message}}})}function h(e){return Object.freeze({sessionId:e.sessionId,fence:e.fence})}function g(e){if(typeof e!=`object`||!e||Array.isArray(e))return{status:`invalid`,message:`App-log process marker must be an object`};let t=e;return!Number.isInteger(t.pid)||Number(t.pid)<=0?{status:`invalid`,message:`App-log process marker pid must be a positive integer`}:typeof t.startTime!=`string`||t.startTime.trim().length===0?{status:`invalid`,message:`App-log process marker startTime must be a non-empty string`}:typeof t.command!=`string`||t.command.trim().length===0?{status:`invalid`,message:`App-log process marker command must be a non-empty string`}:{status:`decoded`,marker:Object.freeze({pid:Number(t.pid),startTime:t.startTime,command:t.command})}}function _(e){let t,n,r,i=()=>n??=e.forceCleanup();return Object.freeze({inspect:()=>e.inspect(),finish:()=>t??=e.finish(),forceCleanup:i,[Symbol.asyncDispose]:async()=>{r??=i().then(ee),await r}})}function v(e){return _({inspect:e.inspect,finish:e.finish,forceCleanup:async()=>{let t=await e.finish();return t.status===`completed`?{status:`cleaned`}:{status:`cleanup-pending`,reason:t.reason,message:t.message}}})}function ee(t){if(!s(t))throw new e(`COMMAND_FAILED`,t.message??`Durable resource cleanup could not be confirmed`,{reason:t.reason,retriable:t.reason!==`ownership-fence-lost`,hint:t.reason===`ownership-fence-lost`?`Use the current resource owner or recovery record before retrying cleanup.`:`Keep the recovery record and retry cleanup through the exact runtime owner.`})}const te=e=>b(e.backend)&&(e.source===`system-audio`||e.source===`media-elements`)&&x(e.sourceCount,0)&&re(e.notes)&&b(e.statusPath)&&x(e.startedAt,1)&&x(e.durationMs,1)&&x(e.bucketMs,1),y=Object.freeze({resourceKind:i,version:1,encode:e=>({...e,notes:[...e.notes],marker:{...e.marker}}),decode:e=>{let t=te(e)?ne(e.marker):`invalid`;if(t===`invalid`)return{status:`invalid`,message:`Audio probe descriptor body is invalid`};let n=e;return{status:`decoded`,descriptor:Object.freeze({backend:n.backend,source:n.source,sourceCount:n.sourceCount,notes:Object.freeze([...n.notes]),statusPath:n.statusPath,startedAt:n.startedAt,durationMs:n.durationMs,bucketMs:n.bucketMs,marker:t})}}});function ne(e){if(typeof e!=`object`||!e)return`invalid`;let t=e;return!x(t.pid,1)||!b(t.startTime)||!b(t.command)?`invalid`:Object.freeze({pid:t.pid,startTime:t.startTime,command:t.command})}function b(e){return typeof e==`string`&&e.length>0}function x(e,t){return typeof e==`number`&&Number.isInteger(e)&&e>=t}function re(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}async function S(e){try{let t=await d.readFile(e.statusPath,`utf8`);return l(JSON.parse(t),{source:e.source,backend:e.backend,durationMs:e.durationMs,elapsedMs:Date.now()-e.startedAt,bucketMs:e.bucketMs,activeFallback:!0,sourceCount:e.sourceCount,notes:[...e.notes]})}catch(e){if(e.code===`ENOENT`)return;throw e}}function C(e,t,n){let r=Math.min(e.durationMs,Math.max(0,Date.now()-e.startedAt));return{...t??u({source:e.source,backend:e.backend,durationMs:e.durationMs,bucketMs:e.bucketMs,sourceCount:e.sourceCount,notes:[...e.notes]}),state:`stopped`,active:!1,elapsedMs:r,stoppedAt:new Date().toISOString(),reason:n}}function ie(e){let{host:t}=e;return Object.freeze({audioProbeReattach:async e=>{let n=f(e.envelope,y);if(n.status!==`decoded`)return n;let r=n.descriptor,i=await t.inspectProcess(r.marker);if(i===`owned-alive`)return{status:`unreattachable`,reason:`transport-not-reattachable`};if(i===`ownership-lost`)return{status:`unreattachable`,reason:`ownership-fence-lost`};let a=await S(r);return a===void 0||a.state!==`stopped`?{status:`missing`}:{status:`completed`,result:C(r,a,`daemon-recovery`)}},audioProbeCleanup:async e=>{let n=f(e.envelope,y);if(n.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message};let r=n.descriptor,i=await t.inspectProcess(r.marker);if(i===`ownership-lost`)return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(i===`missing`)return{status:`already-missing`};let a=await t.terminateProcess(r.marker);return a===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:{status:a===`terminated`?`cleaned`:`already-missing`}}})}async function ae(n){let{host:r,device:s,owner:l,input:u}=n,f=Date.now(),p=r.info,m=Object.freeze([...p.notes(s)]),h=Object.freeze({source:p.source,backend:p.backend,sourceCount:p.sourceCount,notes:m,statusPath:u.statusPath,startedAt:f,durationMs:u.durationMs,bucketMs:u.bucketMs});await d.rm(u.statusPath,{force:!0});let g=await r.start({durationMs:u.durationMs,bucketMs:u.bucketMs,statusPath:u.statusPath});g.wait.catch(()=>{});let _=g.marker;try{if(_===void 0)throw new e(`COMMAND_FAILED`,`failed to start host audio probe: the helper process exposed no exact identity, so the capture could not be recovered after daemon loss and was terminated`);await ue(h,g)}catch(e){throw await g.terminate().catch(()=>{}),e}return Object.freeze({pendingHandle:new c(oe(h,g)),envelope:o({resourceKind:i,sessionId:u.sessionId,device:t(s),owner:l,fence:u.fence,lifecycle:`open`,descriptor:a(y,{backend:p.backend,source:p.source,sourceCount:p.sourceCount,notes:m,statusPath:u.statusPath,startedAt:f,durationMs:u.durationMs,bucketMs:u.bucketMs,marker:_})})})}function oe(e,t){let n,r,i,a;t.wait.then(e=>{a={message:se(e)}},e=>{a={message:e instanceof Error?e.message:`audio probe helper wait failed`}});let o=()=>n??=(async()=>{let n=await S(e);if(n?.state!==`stopped`&&a)throw w(a);return await t.terminate().catch(()=>{}),await t.wait.catch(()=>{}),{status:`completed`,result:C(e,n,`stopped`)}})(),s=()=>r??=n?n.then(async()=>({status:`cleaned`}),async()=>await T(t)):T(t);return Object.freeze({inspect:()=>e,status:async()=>{let t=await S(e);if(t?.state===`stopped`)return t;if(a)throw w(a);return t??C(e,void 0,`not-started`)},finish:o,forceCleanup:s,[Symbol.asyncDispose]:async()=>{i??=s().then(ce),await i}})}function se(e){return e.stderr?.trim()||e.stdout?.trim()||`audio probe helper exited with code ${e.exitCode??1}`}function w(t){return new e(`COMMAND_FAILED`,`host audio probe helper exited before completing the capture: ${t.message}`,{hint:`Keep audio-probe.resource.json; stop resolves the record through descriptor cleanup.`})}async function T(e){try{return await e.terminate(),await e.wait.catch(()=>{}),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`cleanup-unconfirmed`,message:e instanceof Error?e.message:`Audio probe termination failed`}}}function ce(t){if(!s(t))throw new e(`COMMAND_FAILED`,t.message??`Audio probe cleanup could not be confirmed`,{reason:t.reason,retriable:t.reason!==`ownership-fence-lost`,hint:`Keep audio-probe.resource.json and retry stop through its exact runtime owner.`})}function le(e){let{host:t,device:n,owner:r}=e,i=ie({host:t});return Object.freeze({audioProbeStart:async e=>await ae({host:t,device:n,owner:r,input:e}),audioProbeReattach:i.audioProbeReattach,audioProbeCleanup:i.audioProbeCleanup})}async function ue(t,n){let r=Date.now()+5e3;for(;Date.now()<r;){if(await S(t))return;let r=await Promise.race([n.wait.then(e=>e,e=>e),de(100).then(()=>void 0)]);if(r instanceof Error)throw r;if(r){let t=r,n=t.stderr?.trim()||t.stdout?.trim()||`host audio probe helper exited with code ${t.exitCode??1}`;throw new e(`COMMAND_FAILED`,`failed to start host audio probe: ${n}`)}}throw new e(`COMMAND_FAILED`,`failed to start host audio probe`)}function de(e){return new Promise(t=>setTimeout(t,e))}async function E(e,t){let n=await O(e,t);if(n.status===`missing`)return{status:`missing`};if(n.status===`invalid`)return{status:`unreattachable`,reason:`ownership-fence-lost`,message:n.message};let r=await e.processes.inspect(n.marker);return r===`missing`?(t&&await e.processes.clearMarker(t),{status:`missing`}):r===`ownership-lost`?{status:`unreattachable`,reason:`ownership-fence-lost`}:{status:`unreattachable`,reason:`transport-not-reattachable`}}async function D(e,t){if(!t)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`App-log process marker path is missing`};let n=await O(e,t);if(n.status===`missing`)return{status:`already-missing`};if(n.status===`invalid`)return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:n.message};let r=await e.processes.inspect(n.marker);if(r===`ownership-lost`)return k();if(r===`missing`)return await e.processes.clearMarker(t),{status:`already-missing`};let i=await e.processes.terminate(n.marker);return i===`ownership-lost`?k():(await e.processes.clearMarker(t),{status:i===`terminated`?`cleaned`:`already-missing`})}async function O(e,t){return t?await e.processes.readMarker(t):{status:`invalid`,message:`App-log process marker path is missing`}}function k(){return{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function fe(e){let t=e.initialProcess;for(;!e.stopped();){if(t){await pe(e,t),t=void 0,await be(e);continue}let n=await xe(e);if(n.status===`stopped`)return;n.status!==`waiting`&&(t=n.process)}}async function pe(e,t){let{process:n}=t;e.setActive(n);try{e.setState(`active`),await me(e,t)}finally{await A(e,n)}}async function me(e,t){let n=he(t.process);try{await ge(e,t,n),await ve(e,t.process,n),await ye(n.outcome)}finally{n.controller.abort()}}function he(e){let t=new AbortController,n=!1,r=()=>{n=!0,t.abort()};return{controller:t,outcome:e.wait.then(()=>(r(),{status:`exited`}),e=>(r(),{status:`failed`,error:e})),settled:()=>n}}async function ge(e,t,n){for(;!e.stopped()&&!n.settled();){if(!await _e(e,n))return;let r=await e.resolvePid();if(e.stopped())return;if(r!==t.pid){await t.process.terminate();return}}}async function _e(e,t){try{await e.sleep(500,t.controller.signal)}catch(e){if(!t.settled())throw e}return!t.settled()}async function ve(e,t,n){e.stopped()&&!n.settled()&&await t.terminate()}async function ye(e){let t=await e;if(t.status===`failed`)throw t.error}async function be(e){e.stopped()||(e.setState(`recovering`),await e.sleep(500))}async function xe(e){let t=await e.resolvePid();if(e.stopped())return{status:`stopped`};if(!t)return e.setState(`recovering`),await e.sleep(1e3),{status:`waiting`};let n=await e.startProcess(t);return e.setActive(n),e.stopped()?(await Se(e,n),{status:`stopped`}):{status:`started`,process:{pid:t,process:n}}}async function Se(e,t){try{await t.terminate(),await t.wait}finally{await A(e,t)}}async function A(e,t){try{await t[Symbol.asyncDispose]()}finally{e.setActive(void 0)}}async function Ce(e){let t=await e.resolvePid(e.setupSignal);e.setupSignal.throwIfAborted();let n=await e.host.outputs.openAppend(e.outputPath),r=`recovering`,i=!1,a;try{if(e.setupSignal.throwIfAborted(),t){e.setupSignal.throwIfAborted();let i=new AbortController,o=()=>i.abort(e.setupSignal.reason);e.setupSignal.addEventListener(`abort`,o,{once:!0});try{a=await e.processStart({command:e.command(t),output:n,markerPath:e.pidPath},i.signal)}finally{e.setupSignal.removeEventListener(`abort`,o)}e.setupSignal.throwIfAborted(),r=`active`}}catch(e){throw await j([async()=>await a?.terminate(),async()=>{await a?.wait},async()=>await a?.[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()]),e}let o=fe({initialProcess:a&&t?{pid:t,process:a}:void 0,stopped:()=>i,setActive:e=>{a=e},setState:e=>{r=e},resolvePid:async()=>await e.resolvePid(),startProcess:async t=>await e.processStart({command:e.command(t),output:n,markerPath:e.pidPath}),sleep:async(t,n)=>await e.host.clock.sleep(t,n)}).catch(()=>{r=`failed`}),s,c=async()=>s??=we({options:e,monitor:o,active:()=>a,stop:()=>{i=!0},setState:e=>{r=e},output:n}),l=e.host.clock.now();return v({inspect:()=>({backend:e.backend,state:r,startedAt:l}),finish:c})}async function we(e){return e.stop(),(await j([async()=>await e.active()?.terminate(),async()=>await e.monitor,async()=>await e.output[Symbol.asyncDispose]()])).length>0?(e.setState(`failed`),{status:`cleanup-pending`,reason:`transport-failed`,message:e.options.cleanupFailureMessage}):(e.setState(`ended`),{status:`completed`,result:{backend:e.options.backend,outputPath:e.options.outputPath,completedAt:e.options.host.clock.now()}})}async function j(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}function M(e,t,n){let r=e.artifacts.resolveSession(t);return n.outputPath===r.outputPath&&(n.pidPath===void 0||n.pidPath===r.pidPath)}function N(t,n){if(!M(t,n.sessionId,n))throw new e(`INVALID_ARGS`,`App-log paths do not match the owning session`)}const P=Object.freeze({available:!0});async function Te(e,t,n){let r=(await e.commands.run(t,n)).stdout.trim().split(/\s+/)[0]??``;return/^\d+$/.test(r)?r:``}function Ee(t,i){let a=n(i.family);return Object.freeze({owner:a,ownsDevice:e=>e.platform===i.family,inspectFacts:async e=>F(e,await t.processTransports.resolve(e),i),bind:async n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,a))throw new e(`UNSUPPORTED_OPERATION`,`${i.label} app-log owner identity does not match`);if(n.device.platform!==i.family)throw new e(`UNSUPPORTED_PLATFORM`,`${i.label} app-log owner cannot bind ${n.device.platform}`);let o=await t.processTransports.resolve(n.device);return De(t,n.device,n.scope.signal,o,a,i)},shutdown:async()=>void 0})}function De(e,t,n,r,i,a){let o=m({codec:a.codec,reattach:async(t,n)=>M(e,n.sessionId,t)?await E(e,t.pidPath):{status:`unreattachable`,reason:`descriptor-invalid`,message:`${a.label} app-log descriptor paths do not match the owning session`},cleanup:async(t,n)=>M(e,n.sessionId,t)?await D(e,t.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`${a.label} app-log descriptor paths do not match the owning session`}}),s=Object.freeze({appLogInspect:async()=>({backend:a.backend}),appLogDoctor:async({appBundleId:r})=>await a.doctor({host:e,device:t,signal:n},r),...r.start?{appLogStart:async o=>await Oe(e,t,n,r,i,o,a)}:{},...o});return Object.freeze({device:t,owner:i,facts:F(t,r,a),operations:s,[Symbol.asyncDispose]:async()=>void 0})}function F(e,t,n){let r=t.start?P:{available:!1,reason:`owner-capability-missing`,hint:n.startUnavailableHint};return Object.freeze({device:{family:n.family,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:P,appLogDoctor:P,appLogStart:r,appLogReattach:P,appLogCleanup:P}})}async function Oe(t,n,r,i,a,o,s){if(!i.start)throw new e(`UNSUPPORTED_OPERATION`,s.startUnavailableHint);N(t,o);let c=t.artifacts.resolveSession(o.sessionId),l={host:t,device:n,signal:r,input:o,artifacts:c,transport:i};s.validateStart?.(l),r.throwIfAborted();let u=await s.process(l);r.throwIfAborted();let d=await Ce({host:t,backend:s.backend,outputPath:c.outputPath,pidPath:c.pidPath,processStart:i.start,setupSignal:r,resolvePid:u.resolvePid,command:u.command,cleanupFailureMessage:s.cleanupFailureMessage}),f=s.descriptor({artifacts:c,transport:i});return p(d,s.envelope({input:o,device:n,owner:a,descriptor:f}))}function I(e){for(let t of[/\bstatus(?:Code)?["'=: ]+([1-5]\d{2})\b/i,/\bresponse(?:\s+code)?["'=: ]+([1-5]\d{2})\b/i,/\bHTTP\/[0-9.]+\s+([1-5]\d{2})\b/i]){let n=t.exec(e);if(!n)continue;let r=Number.parseInt(n[1]??``,10);if(Number.isInteger(r))return r}return null}function L(e){return/\b\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z)?\b/.exec(e)?.[0]??/\b\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+\b/.exec(e)?.[0]}function ke(e){let t=e.indexOf(`{`),n=e.lastIndexOf(`}`);if(t<0||n<=t)return null;try{let r=JSON.parse(e.slice(t,n+1));return r&&typeof r==`object`&&!Array.isArray(r)?r:null}catch{return null}}function R(e,t){for(let n of t){let t=e?.[n];if(typeof t==`string`&&t.trim())return t.trim()}}function Ae(e,t){for(let n of t){let t=e?.[n];if(typeof t==`number`&&Number.isInteger(t))return t;if(typeof t==`string`&&/^\d{3}$/.test(t.trim()))return Number.parseInt(t,10)}return null}function je(e,t){let n=t?.headers??t?.requestHeaders??t?.responseHeaders;return n===void 0?/\bheaders?["'=: ]+(\{.*\})/i.exec(e)?.[1]?.trim():B(n)}function z(e,t,n){for(let r of n){if(t?.[r]!==void 0)return B(t[r]);let n=r.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),i=RegExp(`\\b${n}["'=: ]+(.+)$`,`i`).exec(e);if(i?.[1])return i[1].trim()}}function B(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Me(e,t,n){let r=U(t,n,5),i=e.packetId??r.map(V).find(e=>typeof e==`string`&&e.length>0);i&&(e.packetId=i);let a=i?U(t,n,12).filter(e=>V(e)===i):r;e.timestamp??=a.map(L).find(e=>typeof e==`string`&&e.length>0),e.status??=a.map(I).find(e=>typeof e==`number`)??void 0,e.durationMs??=a.map(H).find(e=>typeof e==`number`)??void 0}function V(e){return/\bpacket id (\d+)\b/i.exec(e)?.[1]??null}function H(e){let t=/\b(?:duration|elapsed request\/response time, ms)[:= ]+(\d+)\b/i.exec(e);return t?Number.parseInt(t[1]??``,10):null}function U(e,t,n){return e.slice(Math.max(0,t-n),Math.min(e.length,t+n+1)).map(e=>e.trim()).filter(Boolean)}const Ne=RegExp(`\\b(${[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`,`HEAD`,`OPTIONS`].join(`|`)})\\b\\s+https?:\\/\\/`,`i`),Pe=/https?:\/\/[^\s"'<>\])]+/i,Fe=/\[C(\d+)\b[^\]]*?\burl:\s*([^\s,\]]+)/,W=/\bsummary for task (?:success|failure)\s*\{([^}]*)\}/,Ie=/\bTask\s+<([0-9A-Fa-f-]+)>\.<(\d+)>/,G=/(?:^|\s)(\S+)\[(\d+):[0-9a-f]+\]/,Le=/\burl:\s*(https?:\/\/[^\s,\]]+)/i;function Re(e,t,n=e.dump.limits.maxEntries){let r=[...e.dump.entries],i=new Set(r.map(K));for(let e of t.dump.entries){let t=K(e);if(!i.has(t)&&(i.add(t),r.push(e),r.length>=n))break}let a=new Set([...e.dump.entries,...t.dump.entries].map(e=>e.packetId).filter(e=>e!==void 0)),o=[...new Set([...e.unnamedRequestIds,...t.unnamedRequestIds])].filter(e=>!a.has(e));return Object.freeze({dump:Object.freeze({...e.dump,matchedLines:r.length,entries:Object.freeze(r),unnamedRequests:o.length}),unnamedRequestIds:Object.freeze(o)})}function ze(e,t){let n=J(t.maxEntries,25,1,200),r=t.include??`summary`,i=J(t.maxPayloadChars,2048,64,16384),a=J(t.maxScanLines,4e3,100,2e4),o=Ve(t.lineNumberOffset);if(!t.exists)return Object.freeze({dump:Object.freeze({path:t.path,exists:!1,scannedLines:0,matchedLines:0,entries:Object.freeze([]),unnamedRequests:0,include:r,limits:Object.freeze({maxEntries:n,maxPayloadChars:i,maxScanLines:a})}),unnamedRequestIds:Object.freeze([])});let s=e.split(`
|
|
2
2
|
`),c=Math.max(0,s.length-a),l=s.slice(c),u=[],d=Be(t.backend)?Qe(l):void 0,f=d?et(l,d):[];for(let e=l.length-1;e>=0&&u.length<n;--e){if(!l[e]?.trim())continue;let n=He(l,e,o+c+e+1,t.backend,r,i,d);n&&u.push(n)}return Object.freeze({dump:Object.freeze({path:t.path,exists:!0,scannedLines:l.length,matchedLines:u.length,entries:Object.freeze(u),unnamedRequests:f.length,include:r,limits:Object.freeze({maxEntries:n,maxPayloadChars:i,maxScanLines:a})}),unnamedRequestIds:Object.freeze(f)})}function Be(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function Ve(e){if(e===void 0)return 0;if(!Number.isInteger(e)||e<0)throw TypeError(`Network line number offset must be a non-negative integer`);return e}function He(e,t,n,r,i,a,o){let s=e[t]?.trim();if(!s)return null;let c=ke(s),l=Ue(s,c)??(o?$e(s,o,t):null);if(!l)return null;let u=Je(s,n,l,a);return r===`android`&&Me(u,e,t),Ye(u,s,c,i,a),u}function Ue(e,t){let n=We(e,t),r=Ge(e,t);if(!r)return null;let i=Ke(e,t);return qe(e,n.explicit,i)?{method:n.value,url:r,status:i}:null}function We(e,t){let n=R(t,[`method`,`httpMethod`]),r=/\bmethod["'=: ]+([A-Z]+)\b/i.exec(e)?.[1],i=Ne.exec(e)?.[1],a=n??r??i;return{value:a?.toUpperCase(),explicit:!!a}}function Ge(e,t){return R(t,[`url`,`requestUrl`])||(Le.exec(e)?.[1]??Pe.exec(e)?.[0])}function Ke(e,t){return Ae(t,[`status`,`statusCode`,`responseCode`])??I(e)??void 0}function qe(e,t,n){return t||n!==void 0||/\bURL["'=: ]+https?:\/\//i.test(e)||/\bheaders?["'=: ]+/i.test(e)||/\b(?:requestBody|responseBody|payload|request|response)["'=: ]+/i.test(e)}function Je(e,t,n,r){return{...n,timestamp:L(e),packetId:n.packetId??V(e)??void 0,durationMs:n.durationMs??H(e)??void 0,raw:q(e,r),line:t}}function Ye(e,t,n,r,i){if(Xe(r)){let r=je(t,n);r&&(e.headers=q(r,i))}if(Ze(r)){let r=z(t,n,[`requestBody`,`body`,`payload`,`request`]),a=z(t,n,[`responseBody`,`response`]);r&&(e.requestBody=q(r,i)),a&&(e.responseBody=q(a,i))}}function Xe(e){return e===`headers`||e===`all`}function Ze(e){return e===`body`||e===`all`}function K(e){return`${e.timestamp??``}|${e.method??``}|${e.url}|${e.status??``}|${e.raw}`}function q(e,t){return e.length<=t?e:`${e.slice(0,t)}...<truncated>`}function J(e,t,n,r){return e===void 0||!Number.isInteger(e)?t:Math.max(n,Math.min(r,e))}function Qe(e){let t=new Map;for(let[n,r]of e.entries()){let e=Fe.exec(r);if(!e)continue;let i=Y(r,e[1]),a=i===void 0?void 0:nt(e[2]);if(!a||i===void 0)continue;let o=t.get(i);o?o.push({lineIndex:n,origin:a}):t.set(i,[{lineIndex:n,origin:a}])}return t}function Y(e,t){let n=G.exec(e);if(n)return`${n[1]}[${n[2]}]#${t}`}function $e(e,t,n){let r=W.exec(e);if(!r)return null;let i=Q(r[1]);if(i.get(`reused`)!==`1`)return null;let a=i.get(`connection`),o=a===void 0?void 0:Y(e,a),s=o===void 0?void 0:Z(t,o,n);return s?{url:s,status:rt(i.get(`response_status`)),durationMs:$(i.get(`transaction_duration_ms`)),pathUnavailable:!0,packetId:X(e)}:null}function et(e,t){let n=new Set;for(let[r,i]of e.entries()){let e=tt(i,t,r);e!==void 0&&n.add(e)}return[...n]}function tt(e,t,n){if(!e.includes(`summary for task`))return;let r=W.exec(e);if(!r)return;let i=Q(r[1]);if(i.get(`reused`)!==`1`)return;let a=i.get(`connection`),o=a===void 0?void 0:Y(e,a);if(!(o!==void 0&&Z(t,o,n)))return X(e)}function X(e){let t=Ie.exec(e);if(!t)return;let n=G.exec(e);return`${n?`${n[1]}[${n[2]}]`:``}#${t[1]}.${t[2]}`}function Z(e,t,n){let r=e.get(t);if(!r)return;let i;for(let e of r){if(e.lineIndex>n)break;i=e.origin}return i}function Q(e){let t=new Map;for(let n of e.split(`,`)){let e=n.indexOf(`=`);e!==-1&&t.set(n.slice(0,e).trim(),n.slice(e+1).trim())}return t}function nt(e){try{return new URL(e).origin}catch{return}}function rt(e){let t=$(e);return t!==void 0&&t>0?t:void 0}function $(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}export{M as a,E as c,m as d,p as f,Te as i,le as l,f as m,ze as n,N as o,g as p,Ee as r,D as s,Re as t,v as u};
|
package/dist/src/src8.js
CHANGED
|
@@ -112,4 +112,4 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
|
|
|
112
112
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
113
113
|
`,e)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(this.onKeyLine=!1,t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){u(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let n=!this.onKeyLine&&this.indent===e.indent,r=n&&(t.sep||t.explicitKey)&&this.type!==`seq-item-ind`,i=[];if(r&&t.sep&&!t.value){let n=[];for(let r=0;r<t.sep.length;++r){let i=t.sep[r];switch(i.type){case`newline`:n.push(r);break;case`space`:break;case`comment`:i.indent>e.indent&&(n.length=0);break;default:n.length=0}}n.length>=2&&(i=t.sep.splice(n[1]))}switch(this.type){case`anchor`:case`tag`:r||t.value?(i.push(this.sourceToken),e.items.push({start:i}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`explicit-key-ind`:!t.sep&&!t.explicitKey?(t.start.push(this.sourceToken),t.explicitKey=!0):r||t.value?(i.push(this.sourceToken),e.items.push({start:i,explicitKey:!0})):this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case`map-value-ind`:if(t.explicitKey){if(!t.sep){if(a(t.start,`newline`))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let e=l(t.start);this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:null,sep:[this.sourceToken]}]})}}else if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(a(t.sep,`map-value-ind`))this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]});else if(s(t.key)&&!a(t.sep,`newline`)){let e=l(t.start),n=t.key,r=t.sep;r.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:n,sep:r}]})}else i.length>0?t.sep=t.sep.concat(i,this.sourceToken):t.sep.push(this.sourceToken)}else t.sep?t.value||r?e.items.push({start:i,key:null,sep:[this.sourceToken]}):a(t.sep,`map-value-ind`)?this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);r||t.value?(e.items.push({start:i,key:n,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(n):(Object.assign(t,{key:n,sep:[]}),this.onKeyLine=!0);return}default:{let r=this.startBlockValue(e);if(r){if(r.type===`block-seq`){if(!t.explicitKey&&t.sep&&!a(t.sep,`newline`)){yield*this.pop({type:`error`,offset:this.offset,message:`Unexpected block-seq-ind on same line with key`,source:this.source});return}}else n&&e.items.push({start:i});this.stack.push(r);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){u(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case`anchor`:case`tag`:if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case`seq-item-ind`:if(this.indent!==e.indent)break;t.value||a(t.start,`seq-item-ind`)?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return}if(this.indent>e.indent){let t=this.startBlockValue(e);if(t){this.stack.push(t);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type===`flow-error-end`){let e;do yield*this.pop(),e=this.peek(1);while(e?.type===`flow-collection`)}else if(e.end.length===0){switch(this.type){case`comma`:case`explicit-key-ind`:!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return;case`map-value-ind`:!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return;case`space`:case`comment`:case`newline`:case`anchor`:case`tag`:!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);!t||t.value?e.items.push({start:[],key:n,sep:[]}):t.sep?this.stack.push(n):Object.assign(t,{key:n,sep:[]});return}case`flow-map-end`:case`flow-seq-end`:e.end.push(this.sourceToken);return}let n=this.startBlockValue(e);n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=l(c(t));d(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
|
|
114
114
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
115
|
-
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=l(c(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=l(c(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Xe=n((e=>{var t=He(),n=Ee(),r=De(),i=re(),a=m(),o=Je(),s=Ye();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Ze=n((e=>{var t=He(),n=Ee(),r=we(),i=De(),a=x(),o=m(),s=D(),c=S(),l=O(),u=A();Ke();var d=qe(),f=Je(),p=Ye(),g=Xe(),_=h();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=g.parse,e.parseAllDocuments=g.parseAllDocuments,e.parseDocument=g.parseDocument,e.stringify=g.stringify,e.visit=_.visit,e.visitAsync=_.visitAsync})),P=Ze();function F(e,t){return Qe(e?.range?.[0],t)}function Qe(e,t){let n=t.lineCounter.linePos(e!==void 0&&e>=0?e:0).line;return t.sourcePath===void 0?{line:n}:{path:t.sourcePath,line:n}}function $e(e){return`${e.path===void 0?``:`${e.path}:`}line ${e.line}`}function I(e,t,n){throw new r(`INVALID_ARGS`,`${e} (${$e(F(t,n))})`)}function L(e,t,n){(0,P.isMap)(e)||I(`Maestro ${t} expects a map.`,e,n);let r=[];for(let i of e.items){let e=i.key;(0,P.isScalar)(e)||I(`Maestro ${t} map keys must be strings.`,void 0,n);let a=e.value;typeof a!=`string`&&typeof a!=`number`&&typeof a!=`boolean`&&I(`Maestro ${t} map keys must be strings.`,e,n),i.value!==null&&!(0,P.isNode)(i.value)&&I(`Maestro ${t} values must be YAML nodes.`,e,n),r.push({key:String(a),keyNode:e,value:i.value})}return r}function et(e,t,n){return(0,P.isSeq)(e)||I(`Maestro ${t} expects a list.`,e,n),e.items}function tt(e,t,n){return et(e,t,n).map((e,r)=>G(e,`${t}[${r}]`,n))}function R(e,t,n,r){let i=new Set(n),a=new Set;for(let n of e)a.has(n.key)&&I(`Maestro ${t} contains duplicate field "${n.key}".`,n.keyNode,r),a.add(n.key),i.has(n.key)||I(`Maestro ${t} field "${n.key}" is not supported.`,n.keyNode,r)}function z(e,t){return e.some(e=>e.key===t)}function B(e,t){return e.find(e=>e.key===t)?.value}function V(e,t,n){return z(e,t)?n(B(e,t)):void 0}function H(e,t,n){return o({optional:V(e,`optional`,e=>q(e,`${t}.optional`,n))})}function U(e){return e===null||(0,P.isScalar)(e)&&e.value===null}function W(e,t,n){if(e==null)return null;(0,P.isScalar)(e)||I(`Maestro ${t} expects a scalar value.`,e,n);let r=e.value;if(r===null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`)return r;I(`Maestro ${t} contains an unsupported scalar value.`,e,n)}function G(e,t,n){let r=W(e,t,n);return typeof r!=`string`&&I(`Maestro ${t} expects a string.`,e,n),r}function K(e,t,n){let r=W(e,t,n);if(r!==null)return typeof r!=`string`&&I(`Maestro ${t} expects a string.`,e,n),r}function q(e,t,n){let r=W(e,t,n);if(r!==null)return typeof r!=`boolean`&&I(`Maestro ${t} expects a boolean.`,e,n),r}const nt=/^\$\{[A-Za-z_][A-Za-z0-9_.]*\}$/,rt=/^-?\d+(\.\d+)?$/,it=/^-?\d+$/,at={"tapOn.index":{integer:!0,nonNegative:!0},"tapOn.repeat":{integer:!0,positive:!0},"tapOn.delay":{integer:!0,nonNegative:!0},"doubleTapOn.delay":{integer:!0,nonNegative:!0},eraseText:{integer:!0,positive:!0},"eraseText.charactersToErase":{integer:!0,positive:!0},"extendedWaitUntil.timeout":{nonNegative:!0},"scrollUntilVisible.timeout":{nonNegative:!0},waitForAnimationToEnd:{nonNegative:!0},"waitForAnimationToEnd.timeout":{nonNegative:!0},"swipe.duration":{nonNegative:!0},"repeat.times":{integer:!0,nonNegative:!0},"retry.maxRetries":{integer:!0,nonNegative:!0}};function ot(e){return e.positive&&e.integer?`a positive integer`:e.positive?`a positive number`:e.nonNegative&&e.integer?`a non-negative integer`:e.nonNegative?`a non-negative finite number`:e.integer?`an integer`:`a finite number`}function st(e,t,n,r,i){let a=`Maestro ${t} expects ${ot(i)} or a variable expression.`;Number.isFinite(e)||I(a,n,r),Math.abs(e)>2**53-1&&I(a,n,r),i.integer&&!Number.isSafeInteger(e)&&I(a,n,r),i.nonNegative&&e<0&&I(a,n,r),i.positive&&e<=0&&I(a,n,r)}function ct(e,t,n,r,i){if(typeof e==`number`)return st(e,t,n,r,i),e;if(typeof e==`string`){if(nt.test(e))return e;if((i.integer?it:rt).test(e)){let a=Number(e);return st(a,t,n,r,i),a}}I(`Maestro ${t} expects ${ot(i)} or a variable expression.`,n,r)}function J(e,t,n,r=at[t]??{}){let i=W(e,t,n);if(i!==null)return ct(i,t,e,n,r)}function lt(e,t,n){let r=at[t]??{},i=W(e,t,n);return i===null&&I(`Maestro ${t} expects ${ot(r)} or a variable expression.`,e,n),ct(i,t,e,n,r)}function ut(e,t,n){let r=W(e,t,n);return r===null&&I(`Maestro ${t} requires a condition.`,e,n),typeof r==`string`&&r.includes("${")&&!nt.test(r)&&I(`Maestro ${t} only supports a literal value or a bare \${VAR} lookup; JavaScript expressions are not supported — compute it in a runScript and reference \${output.x}.`,e,n),r}function dt(e,t,n){let r=L(e,t,n),i={};for(let e of r){let r=W(e.value,`${t}.${e.key}`,n);r===null&&I(`Maestro ${t}.${e.key} expects a string, number, or boolean.`,e.value,n),i[e.key]=r}return i}function Y(e,t,n){return V(e,`label`,e=>K(e,`${t}.label`,n))}const X=[`id`,`text`,`enabled`,`selected`,`index`,`childOf`,`below`,`above`,`leftOf`,`rightOf`,`containsChild`,`containsDescendants`],ft={textKeys:[`id`,`text`],booleanKeys:[`enabled`,`selected`],textAliases:{label:`text`}},pt={id:(e,t,n,r)=>_t(e,`id`,t,n,r),text:(e,t,n,r)=>_t(e,`text`,t,n,r),enabled:(e,t,n,r)=>vt(e,`enabled`,t,n,r),selected:(e,t,n,r)=>vt(e,`selected`,t,n,r),index:(e,t,n,r)=>{e.index=J(t.value,`${n}.index`,r,{integer:!0,nonNegative:!0})},childOf:(e,t,n,r)=>{e.childOf=Z(t.value,`${n}.childOf`,r)},below:(e,t,n,r)=>{e.below=Z(t.value,`${n}.below`,r)},above:(e,t,n,r)=>{e.above=Z(t.value,`${n}.above`,r)},leftOf:(e,t,n,r)=>{e.leftOf=Z(t.value,`${n}.leftOf`,r)},rightOf:(e,t,n,r)=>{e.rightOf=Z(t.value,`${n}.rightOf`,r)},containsChild:(e,t,n,r)=>{e.containsChild=Z(t.value,`${n}.containsChild`,r)},containsDescendants:(e,t,n,r)=>{e.containsDescendants=et(t.value,`${n}.containsDescendants`,r).map(e=>Z(e,`${n}.containsDescendants`,r))},optional:(e,t,n,r)=>vt(e,`optional`,t,n,r)};function Z(e,t,n,r=X){if((0,P.isScalar)(e))return{text:G(e,t,n)};let i=L(e,t,n);return R(i,t,r,n),mt(i,t,n)}function mt(e,t,n){e.length===0&&I(`Maestro ${t} selector is empty.`,void 0,n);let r={};for(let i of e){let e=pt[i.key];e||I(`Maestro ${t} selector field "${i.key}" is not supported.`,i.keyNode,n),e(r,i,t,n)}return Object.keys(r).filter(e=>e!==`optional`).length===0&&I(`Maestro ${t} selector must contain a selector value.`,e[0]?.keyNode,n),r}function ht(e,t,n,r){let i=F(t,n);if((0,P.isScalar)(e))return{source:i,entries:[],target:bt(Z(e,r.name,n,r.selectorKeys))};let a=L(e,r.name,n),o=z(a,`point`);if(R(a,r.name,o?r.pointAllowedKeys:r.selectorAllowedKeys,n),o){let e=r.pointConflictingSelectorKeys??r.selectorKeys;return a.some(t=>yt(t.key,e))&&I(`Maestro ${r.name}.point cannot be combined with a selector.`,t,n),{source:i,entries:a,target:r.parsePoint(B(a,`point`),`${r.name}.point`,n)}}return{source:i,entries:a,target:bt(mt(a.filter(e=>yt(e.key,r.selectorKeys)),r.name,n))}}function Q(e,t,n){let r=G(e,t,n),i=/^\s*(\d+)\s*,\s*(\d+)\s*$/.exec(r);if(i)return{space:`absolute`,x:Number(i[1]),y:Number(i[2])};let a=/^\s*(\d+)%\s*,\s*(\d+)%\s*$/.exec(r);if(a){let r=Number(a[1]),i=Number(a[2]);return(r>100||i>100)&&I(`Maestro ${t} percentage coordinates must be between 0% and 100%.`,e,n),{space:`percent`,x:r,y:i}}/^\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%\s*$/.test(r)&&I(`Maestro ${t} percentage coordinates must be whole numbers.`,e,n),I(`Maestro ${t} expects absolute or percentage coordinates.`,e,n)}function gt(e,t,n){let r=Q(e,t,n);return r.space!==`absolute`&&I(`Maestro ${t} only supports absolute coordinates.`,e,n),r}function _t(e,t,n,r,i){let a=K(n.value,`${r}.${t}`,i);a!==void 0&&(e[t]=a)}function vt(e,t,n,r,i){let a=q(n.value,`${r}.${t}`,i);a!==void 0&&(e[t]=a)}function yt(e,t){return t.includes(e)}function bt(e){return{space:`target`,selector:e}}function xt(e,t,n){let r=ht(e,t,n,{name:`tapOn`,selectorKeys:X,pointConflictingSelectorKeys:X,pointAllowedKeys:[`point`,`retryTapIfNoChange`,`repeat`,`delay`,`optional`,`label`],selectorAllowedKeys:[...X,`retryTapIfNoChange`,`repeat`,`delay`,`optional`,`label`],parsePoint:Q});if(r.entries.length===0)return{kind:`tapOn`,source:r.source,target:r.target};if(r.target.space!==`target`)return{kind:`tapOn`,source:r.source,target:r.target,...Ot(r.entries,n)};let i=Ot(r.entries,n);return o({kind:`tapOn`,source:r.source,target:r.target,...i})}function St(e,t,n){let r=ht(e,t,n,{name:`doubleTapOn`,selectorKeys:X,pointAllowedKeys:[`point`,`delay`,`optional`,`label`],selectorAllowedKeys:[...X,`delay`,`optional`,`label`],parsePoint:gt}),i=H(r.entries,`doubleTapOn`,n),a=z(r.entries,`delay`)?J(B(r.entries,`delay`),`doubleTapOn.delay`,n):void 0,s=Y(r.entries,`doubleTapOn`,n);return o({kind:`doubleTapOn`,source:r.source,target:r.target,...i,delay:a,label:s})}function Ct(e,t,n){let r=ht(e,t,n,{name:`longPressOn`,selectorKeys:X,pointAllowedKeys:[`point`,`optional`,`label`],selectorAllowedKeys:[...X,`optional`,`label`],parsePoint:gt});return o({kind:`longPressOn`,source:r.source,target:r.target,...H(r.entries,`longPressOn`,n),label:Y(r.entries,`longPressOn`,n)})}function wt(e,t,n){let r=F(t,n),i=L(e,`swipe`,n);R(i,`swipe`,[`start`,`end`,`direction`,`duration`,`from`,`label`,`optional`],n);let a=H(i,`swipe`,n),o=Y(i,`swipe`,n),s=z(i,`duration`)?J(B(i,`duration`),`swipe.duration`,n):void 0;if(z(i,`start`)||z(i,`end`))return{...Tt(i,r,s,t,n),...a,label:o};let c=z(i,`direction`)?kt(B(i,`direction`),`swipe.direction`,n):void 0;return z(i,`from`)?{...Et(i,r,c,s,t,n),...a,label:o}:{...Dt(r,c,s,t,n),...a,label:o}}function Tt(e,t,n,r,i){z(e,`direction`)&&I(`Maestro swipe cannot combine direction with start/end coordinates.`,r,i),(!z(e,`start`)||!z(e,`end`))&&I(`Maestro swipe requires both start and end coordinates.`,r,i);let a=Q(B(e,`start`),`swipe.start`,i),s=Q(B(e,`end`),`swipe.end`,i);return a.space!==s.space&&I(`Maestro swipe start/end must use the same coordinate space.`,r,i),{kind:`swipe`,source:t,gesture:o({kind:`coordinates`,start:a,end:s,duration:n})}}function Et(e,t,n,r,i,a){return n===void 0&&I(`Maestro target swipe requires direction.`,i,a),{kind:`swipe`,source:t,gesture:o({kind:`target`,from:Z(B(e,`from`),`swipe.from`,a),direction:n,duration:r})}}function Dt(e,t,n,r,i){return t===void 0&&I(`Maestro swipe requires direction, target, or start/end coordinates.`,r,i),{kind:`swipe`,source:e,gesture:o({kind:`screen`,direction:t,duration:n})}}function Ot(e,t){let n=V(e,`retryTapIfNoChange`,e=>q(e,`tapOn.retryTapIfNoChange`,t)),r=V(e,`repeat`,e=>lt(e,`tapOn.repeat`,t)),i=V(e,`delay`,e=>J(e,`tapOn.delay`,t)),a=H(e,`tapOn`,t).optional;return o({retryTapIfNoChange:n,repeat:r,delay:i,optional:a,label:Y(e,`tapOn`,t)})}function kt(e,t,n){let r=G(e,t,n).toLowerCase();if(r===`up`||r===`down`||r===`left`||r===`right`)return r;I(`Maestro ${t} must be UP, DOWN, LEFT, or RIGHT.`,e,n)}function At(e,t,n,r){let i=F(n,r);if((0,P.isScalar)(t))return{kind:e,source:i,target:Z(t,e,r)};let a=L(t,e,r);R(a,e,[...X,`optional`,`label`],r);let s=H(a,e,r),c=Y(a,e,r);return o({kind:e,source:i,target:mt(a.filter(e=>e.key!==`optional`&&e.key!==`label`),e,r),...s,label:c})}const jt=[...X,`optional`];function Mt(e,t,n,r){if(!z(e,t))return;let{optional:i,...a}=Z(B(e,t),n,r,jt);return{selector:a,optional:i}}function Nt(e,t,n){let r=Mt(e,`visible`,`extendedWaitUntil.visible`,n),i=Mt(e,`notVisible`,`extendedWaitUntil.notVisible`,n);return r&&i&&I(`Maestro extendedWaitUntil cannot specify both visible and notVisible.`,t,n),!r&&!i&&I(`Maestro extendedWaitUntil requires visible or notVisible.`,t,n),r?{key:`visible`,selector:r.selector,optional:r.optional}:{key:`notVisible`,selector:i.selector,optional:i.optional}}function Pt(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`runScript`,source:r,file:G(e,`runScript`,n)};let i=L(e,`runScript`,n);return R(i,`runScript`,[`file`,`env`],n),z(i,`file`)||I(`Maestro runScript requires a file.`,t,n),o({kind:`runScript`,source:r,file:G(B(i,`file`),`runScript.file`,n),env:z(i,`env`)?dt(B(i,`env`),`runScript.env`,n):void 0})}function Ft(e,t,n,r){let i=F(t,n);if((0,P.isScalar)(e))return{kind:`runFlow`,source:i,include:{kind:`file`,path:G(e,`runFlow`,n)}};let a=L(e,`runFlow`,n);R(a,`runFlow`,[`file`,`commands`,`env`,`when`,`label`],n);let s=z(a,`file`);return s===z(a,`commands`)&&I(`Maestro runFlow requires exactly one of file or commands.`,t,n),o({kind:`runFlow`,source:i,include:s?{kind:`file`,path:G(B(a,`file`),`runFlow.file`,n)}:{kind:`commands`,commands:r(B(a,`commands`),`runFlow.commands`,n)},env:z(a,`env`)?dt(B(a,`env`),`runFlow.env`,n):void 0,when:z(a,`when`)?Rt(B(a,`when`),n):void 0,label:Y(a,`runFlow`,n)})}function It(e,t,n,r){let i=F(t,n),a=L(e,`repeat`,n);return R(a,`repeat`,[`times`,`commands`,`while`],n),z(a,`while`)&&I(`Maestro repeat.while is not supported; use repeat.times.`,B(a,`while`),n),z(a,`times`)||I(`Maestro repeat requires times.`,t,n),z(a,`commands`)||I(`Maestro repeat requires commands.`,t,n),{kind:`repeat`,source:i,times:lt(B(a,`times`),`repeat.times`,n),commands:r(B(a,`commands`),`repeat.commands`,n)}}function Lt(e,t,n,r){let i=F(t,n),a=L(e,`retry`,n);R(a,`retry`,[`maxRetries`,`commands`],n),z(a,`commands`)||I(`Maestro retry requires commands.`,t,n);let s=z(a,`maxRetries`)?lt(B(a,`maxRetries`),`retry.maxRetries`,n):void 0;return o({kind:`retry`,source:i,commands:r(B(a,`commands`),`retry.commands`,n),maxRetries:s})}function Rt(e,t){let n=L(e,`runFlow.when`,t);return R(n,`runFlow.when`,[`platform`,`visible`,`notVisible`,`true`],t),n.length===0&&I(`Maestro runFlow.when cannot be empty.`,e,t),o({platform:V(n,`platform`,e=>Bt(e,t)),visible:V(n,`visible`,e=>Z(e,`runFlow.when.visible`,t)),notVisible:V(n,`notVisible`,e=>Z(e,`runFlow.when.notVisible`,t)),true:V(n,`true`,e=>zt(e,t))})}function zt(e,t){let n=W(e,`runFlow.when.true`,t);if(typeof n==`boolean`||typeof n==`string`)return n;I(`Maestro runFlow.when.true expects a boolean or expression string.`,e,t)}function Bt(e,t){let n=G(e,`runFlow.when.platform`,t).toLowerCase();if(n===`android`||n===`ios`||n===`web`)return n;I(`Maestro runFlow.when.platform expects Android, iOS, or Web.`,e,t)}function $(e,t,n){return et(e,t,n).map(e=>Vt(e,n))}function Vt(e,t){if((0,P.isScalar)(e))return typeof e.value!=`string`&&I(`Maestro command names must be strings.`,e,t),Ht(e.value,e,t);(0,P.isMap)(e)||I(`Maestro commands must be a scalar or one-key map.`,e,t);let n=L(e,`command`,t);n.length!==1&&I(`Maestro command maps must contain exactly one command.`,e,t);let r=n[0];return Wt(r.key,r.value,e,t)}function Ht(e,t,n){return Wt(e,null,t,n)}const Ut={launchApp:Gt,tapOn:xt,doubleTapOn:St,longPressOn:Ct,inputText:Kt,eraseText:qt,openLink:Jt,assertVisible:(e,t,n)=>At(`assertVisible`,e,t,n),assertNotVisible:(e,t,n)=>At(`assertNotVisible`,e,t,n),assertTrue:Yt,extendedWaitUntil:Xt,takeScreenshot:Zt,scroll:Qt,scrollUntilVisible:$t,swipe:wt,hideKeyboard:en,pressKey:tn,back:nn,waitForAnimationToEnd:rn,stopApp:an,clearState:on,runScript:Pt,evalScript:sn,runFlow:(e,t,n)=>Ft(e,t,n,$),repeat:(e,t,n)=>It(e,t,n,$),retry:(e,t,n)=>Lt(e,t,n,$)};Object.keys(Ut);function Wt(e,t,n,r){let i=Ut[e];return i||I(`Maestro command "${e}" is not supported.`,n,r),i(t,n,r)}function Gt(e,t,n){let r=F(t,n);if(U(e))return{kind:`launchApp`,source:r};if((0,P.isScalar)(e))return{kind:`launchApp`,source:r,appId:G(e,`launchApp`,n)};let i=L(e,`launchApp`,n);return R(i,`launchApp`,[`appId`,`stopApp`,`clearState`,`arguments`,`launchArguments`],n),o({kind:`launchApp`,source:r,appId:V(i,`appId`,e=>K(e,`launchApp.appId`,n)),stopApp:V(i,`stopApp`,e=>q(e,`launchApp.stopApp`,n)),clearState:V(i,`clearState`,e=>q(e,`launchApp.clearState`,n)),arguments:V(i,`arguments`,e=>cn(e,`launchApp.arguments`,n)),launchArguments:V(i,`launchArguments`,e=>cn(e,`launchApp.launchArguments`,n))})}function Kt(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`inputText`,source:r,text:G(e,`inputText`,n)};let i=L(e,`inputText`,n);return R(i,`inputText`,[`text`,`label`],n),z(i,`text`)||I(`Maestro inputText requires text.`,t,n),o({kind:`inputText`,source:r,text:G(B(i,`text`),`inputText.text`,n),label:Y(i,`inputText`,n)})}function qt(e,t,n){let r=F(t,n);if(U(e))return{kind:`eraseText`,source:r};if((0,P.isScalar)(e))return{kind:`eraseText`,source:r,charactersToErase:lt(e,`eraseText`,n)};let i=L(e,`eraseText`,n);return R(i,`eraseText`,[`charactersToErase`],n),o({kind:`eraseText`,source:r,charactersToErase:z(i,`charactersToErase`)?J(B(i,`charactersToErase`),`eraseText.charactersToErase`,n):void 0})}function Jt(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`openLink`,source:r,link:G(e,`openLink`,n)};let i=L(e,`openLink`,n);return R(i,`openLink`,[`link`],n),{kind:`openLink`,source:r,link:G(B(i,`link`),`openLink.link`,n)}}function Yt(e,t,n){let r=F(t,n);if(U(e)&&I(`Maestro assertTrue requires condition.`,t,n),(0,P.isScalar)(e))return{kind:`assertTrue`,source:r,condition:ut(e,`assertTrue`,n)};let i=L(e,`assertTrue`,n);R(i,`assertTrue`,[`condition`,`optional`,`label`],n),z(i,`condition`)||I(`Maestro assertTrue requires condition.`,t,n);let a=ut(B(i,`condition`),`assertTrue.condition`,n),s=H(i,`assertTrue`,n),c=Y(i,`assertTrue`,n);return o({kind:`assertTrue`,source:r,condition:a,...s,label:c})}function Xt(e,t,n){let r=L(e,`extendedWaitUntil`,n);R(r,`extendedWaitUntil`,[`visible`,`notVisible`,`timeout`,`optional`,`label`],n);let i=H(r,`extendedWaitUntil`,n),a=Y(r,`extendedWaitUntil`,n),s=Nt(r,t,n),c=z(r,`timeout`)?J(B(r,`timeout`),`extendedWaitUntil.timeout`,n):void 0,l=i.optional===!0||s.optional===!0||void 0,u={kind:`extendedWaitUntil`,source:F(t,n),timeout:c,optional:l,label:a};return u[s.key]=s.selector,o(u)}function Zt(e,t,n){return{kind:`takeScreenshot`,source:F(t,n),path:G(e,`takeScreenshot`,n)}}function Qt(e,t,n){return U(e)||I(`Maestro scroll does not accept options yet.`,t,n),{kind:`scroll`,source:F(t,n)}}function $t(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`scrollUntilVisible`,source:r,element:Z(e,`scrollUntilVisible.element`,n)};let i=L(e,`scrollUntilVisible`,n);R(i,`scrollUntilVisible`,[`element`,`direction`,`timeout`,`optional`,`label`],n);let a=H(i,`scrollUntilVisible`,n),s=Y(i,`scrollUntilVisible`,n),c=Mt(i,`element`,`scrollUntilVisible.element`,n);c||I(`Maestro scrollUntilVisible requires element.`,t,n);let l=z(i,`direction`)?kt(B(i,`direction`),`scrollUntilVisible.direction`,n):void 0,u=z(i,`timeout`)?J(B(i,`timeout`),`scrollUntilVisible.timeout`,n):void 0,d=a.optional===!0||c.optional===!0||void 0;return o({kind:`scrollUntilVisible`,source:r,element:c.selector,direction:l,timeout:u,optional:d,label:s})}function en(e,t,n){return U(e)||I(`Maestro hideKeyboard does not accept options.`,t,n),{kind:`hideKeyboard`,source:F(t,n)}}function tn(e,t,n){let r=G(e,`pressKey`,n).toLowerCase();return r!==`back`&&r!==`enter`&&r!==`return`&&r!==`home`&&I(`Maestro pressKey "${r}" is not supported.`,e,n),{kind:`pressKey`,source:F(t,n),key:r}}function nn(e,t,n){return U(e)||I(`Maestro back does not accept options.`,t,n),{kind:`back`,source:F(t,n)}}function rn(e,t,n){let r=F(t,n);if(U(e))return{kind:`waitForAnimationToEnd`,source:r};if((0,P.isScalar)(e))return o({kind:`waitForAnimationToEnd`,source:r,timeout:J(e,`waitForAnimationToEnd`,n)});let i=L(e,`waitForAnimationToEnd`,n);return R(i,`waitForAnimationToEnd`,[`timeout`],n),o({kind:`waitForAnimationToEnd`,source:r,timeout:z(i,`timeout`)?J(B(i,`timeout`),`waitForAnimationToEnd.timeout`,n):void 0})}function an(e,t,n){let r=F(t,n);return U(e)?{kind:`stopApp`,source:r}:{kind:`stopApp`,source:r,appId:G(e,`stopApp`,n)}}function on(e,t,n){let r=F(t,n);return U(e)?{kind:`clearState`,source:r}:{kind:`clearState`,source:r,appId:G(e,`clearState`,n)}}function sn(e,t,n){return{kind:`evalScript`,source:F(t,n),script:G(e,`evalScript`,n)}}function cn(e,t,n){if((0,P.isSeq)(e))return{kind:`list`,values:et(e,t,n).map((e,r)=>{let i=W(e,`${t}[${r}]`,n);return i===null&&I(`${t}[${r}] expects a scalar value.`,e,n),i})};if((0,P.isMap)(e))return{kind:`map`,values:dt(e,t,n)};let r=W(e,t,n);return r===null&&I(`${t} expects a scalar, list, or map.`,e,n),{kind:`scalar`,value:r}}function ln(e,t={}){let n=new P.LineCounter,i=o({lineCounter:n,sourcePath:t.sourcePath}),a=(0,P.parseAllDocuments)(e,{lineCounter:n});for(let e of a)if(e.errors.length>0){let t=e.errors[0],n=t?.message??`Invalid Maestro YAML flow.`,a=Qe(t?.pos[0],i);throw new r(`INVALID_ARGS`,`Invalid Maestro YAML flow: ${n} (${$e(a)})`)}let s=a.map(e=>e.contents).filter(e=>e!==null);s.length===0&&I(`Maestro flow is empty.`,void 0,i);let c,l;s.length===1&&(0,P.isSeq)(s[0])?l=s[0]:s.length===2&&(0,P.isMap)(s[0])&&(0,P.isSeq)(s[1])?(c=s[0],l=s[1]):I(`Maestro flow must contain a command list, optionally preceded by one config document.`,s[0],i);let u=c?un(c,i):{};return{kind:`program`,source:F(c??l,i),config:u,commands:$(l,`commands`,i)}}function un(e,t){let n=L(e,`flow config`,t);return R(n,`flow config`,[`name`,`appId`,`tags`,`env`,`onFlowStart`,`onFlowComplete`],t),o({name:V(n,`name`,e=>K(e,`name`,t)),appId:V(n,`appId`,e=>K(e,`appId`,t)),tags:V(n,`tags`,e=>tt(e,`tags`,t)),env:V(n,`env`,e=>dt(e,`env`,t)),onFlowStart:V(n,`onFlowStart`,e=>$(e,`onFlowStart`,t)),onFlowComplete:V(n,`onFlowComplete`,e=>$(e,`onFlowComplete`,t))})}function dn(e,t){let n=new Map;return async(r,a,o)=>{if(o?.aborted)throw i();let s=fn(r,a,e),c=n.get(s);if(c)return c;let l=ln(t(s),{sourcePath:s});return n.set(s,l),l}}function fn(e,t,n){let r=t?a.dirname(t):n;return a.resolve(r,e)}function pn(e){let t={[e.entryPath]:e.entrySource},n=mn(e.entrySource,e.entryPath);return n&&hn({program:n,sourcePath:e.entryPath,context:l({},{...e.env}),files:t,readSource:e.readSource}),t}function mn(e,t){try{return ln(e,{sourcePath:t})}catch{return}}function hn(e){let t=e.context.enter(e.program.config.env??{});try{gn([...e.program.config.onFlowStart??[],...e.program.commands,...e.program.config.onFlowComplete??[]],e)}finally{t()}}function gn(e,t){for(let n of e){if(n.kind===`repeat`||n.kind===`retry`){gn(n.commands,t);continue}if(n.kind!==`runFlow`)continue;let e=t.context.enter(n.env??{});try{if(n.include.kind===`commands`){gn(n.include.commands,t);continue}_n(n.include.path,t)}finally{e()}}}function _n(e,t){let n=t.context.resolveDeferred(e);if(n.includes("${"))return;let r=fn(n,t.sourcePath,t.sourcePath);if(t.files[r]!==void 0)return;let i=t.readSource(r);if(i===void 0)return;t.files[r]=i;let a=mn(i,r);a&&hn({...t,program:a,sourcePath:r})}var vn=t({MAESTRO_COMPATIBILITY_ADR_URL:()=>MAESTRO_COMPATIBILITY_ADR_URL,MAESTRO_COMPATIBILITY_ISSUE_URL:()=>MAESTRO_COMPATIBILITY_ISSUE_URL,collectMaestroFlowSources:()=>pn});export{at as a,l as c,o as d,ft as i,c as l,dn as n,ot as o,ln as r,Ze as s,vn as t,s as u};
|
|
115
|
+
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=l(c(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=l(c(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Xe=n((e=>{var t=He(),n=Ee(),r=De(),i=re(),a=m(),o=Je(),s=Ye();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Ze=n((e=>{var t=He(),n=Ee(),r=we(),i=De(),a=x(),o=m(),s=D(),c=S(),l=O(),u=A();Ke();var d=qe(),f=Je(),p=Ye(),g=Xe(),_=h();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=g.parse,e.parseAllDocuments=g.parseAllDocuments,e.parseDocument=g.parseDocument,e.stringify=g.stringify,e.visit=_.visit,e.visitAsync=_.visitAsync})),P=Ze();function F(e,t){return Qe(e?.range?.[0],t)}function Qe(e,t){let n=t.lineCounter.linePos(e!==void 0&&e>=0?e:0).line;return t.sourcePath===void 0?{line:n}:{path:t.sourcePath,line:n}}function $e(e){return`${e.path===void 0?``:`${e.path}:`}line ${e.line}`}function I(e,t,n){throw new r(`INVALID_ARGS`,`${e} (${$e(F(t,n))})`)}function L(e,t,n){(0,P.isMap)(e)||I(`Maestro ${t} expects a map.`,e,n);let r=[];for(let i of e.items){let e=i.key;(0,P.isScalar)(e)||I(`Maestro ${t} map keys must be strings.`,void 0,n);let a=e.value;typeof a!=`string`&&typeof a!=`number`&&typeof a!=`boolean`&&I(`Maestro ${t} map keys must be strings.`,e,n),i.value!==null&&!(0,P.isNode)(i.value)&&I(`Maestro ${t} values must be YAML nodes.`,e,n),r.push({key:String(a),keyNode:e,value:i.value})}return r}function R(e,t,n){return(0,P.isSeq)(e)||I(`Maestro ${t} expects a list.`,e,n),e.items}function et(e,t,n){return R(e,t,n).map((e,r)=>K(e,`${t}[${r}]`,n))}function z(e,t,n,r){let i=new Set(n),a=new Set;for(let n of e)a.has(n.key)&&I(`Maestro ${t} contains duplicate field "${n.key}".`,n.keyNode,r),a.add(n.key),i.has(n.key)||I(`Maestro ${t} field "${n.key}" is not supported.`,n.keyNode,r)}function B(e,t){return e.some(e=>e.key===t)}function V(e,t){return e.find(e=>e.key===t)?.value}function H(e,t,n){return B(e,t)?n(V(e,t)):void 0}function U(e,t,n){return o({optional:H(e,`optional`,e=>J(e,`${t}.optional`,n))})}function W(e){return e===null||(0,P.isScalar)(e)&&e.value===null}function G(e,t,n){if(e==null)return null;(0,P.isScalar)(e)||I(`Maestro ${t} expects a scalar value.`,e,n);let r=e.value;if(r===null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`)return r;I(`Maestro ${t} contains an unsupported scalar value.`,e,n)}function K(e,t,n){let r=G(e,t,n);return typeof r!=`string`&&I(`Maestro ${t} expects a string.`,e,n),r}function q(e,t,n){let r=G(e,t,n);if(r!==null)return typeof r!=`string`&&I(`Maestro ${t} expects a string.`,e,n),r}function J(e,t,n){let r=G(e,t,n);if(r!==null)return typeof r!=`boolean`&&I(`Maestro ${t} expects a boolean.`,e,n),r}const tt=/^\$\{[A-Za-z_][A-Za-z0-9_.]*\}$/,nt=new Set([`allow`,`deny`,`unset`,`always`,`inuse`,`never`,`limited`]),rt=/^-?\d+(\.\d+)?$/,it=/^-?\d+$/,at={"tapOn.index":{integer:!0,nonNegative:!0},"tapOn.repeat":{integer:!0,positive:!0},"tapOn.delay":{integer:!0,nonNegative:!0},"doubleTapOn.delay":{integer:!0,nonNegative:!0},eraseText:{integer:!0,positive:!0},"eraseText.charactersToErase":{integer:!0,positive:!0},"extendedWaitUntil.timeout":{nonNegative:!0},"scrollUntilVisible.timeout":{nonNegative:!0},waitForAnimationToEnd:{nonNegative:!0},"waitForAnimationToEnd.timeout":{nonNegative:!0},"swipe.duration":{nonNegative:!0},"repeat.times":{integer:!0,nonNegative:!0},"retry.maxRetries":{integer:!0,nonNegative:!0}};function ot(e){return e.positive&&e.integer?`a positive integer`:e.positive?`a positive number`:e.nonNegative&&e.integer?`a non-negative integer`:e.nonNegative?`a non-negative finite number`:e.integer?`an integer`:`a finite number`}function st(e,t,n,r,i){let a=`Maestro ${t} expects ${ot(i)} or a variable expression.`;Number.isFinite(e)||I(a,n,r),Math.abs(e)>2**53-1&&I(a,n,r),i.integer&&!Number.isSafeInteger(e)&&I(a,n,r),i.nonNegative&&e<0&&I(a,n,r),i.positive&&e<=0&&I(a,n,r)}function ct(e,t,n,r,i){if(typeof e==`number`)return st(e,t,n,r,i),e;if(typeof e==`string`){if(tt.test(e))return e;if((i.integer?it:rt).test(e)){let a=Number(e);return st(a,t,n,r,i),a}}I(`Maestro ${t} expects ${ot(i)} or a variable expression.`,n,r)}function Y(e,t,n,r=at[t]??{}){let i=G(e,t,n);if(i!==null)return ct(i,t,e,n,r)}function lt(e,t,n){let r=at[t]??{},i=G(e,t,n);return i===null&&I(`Maestro ${t} expects ${ot(r)} or a variable expression.`,e,n),ct(i,t,e,n,r)}function ut(e,t,n){let r=G(e,t,n);return r===null&&I(`Maestro ${t} requires a condition.`,e,n),typeof r==`string`&&r.includes("${")&&!tt.test(r)&&I(`Maestro ${t} only supports a literal value or a bare \${VAR} lookup; JavaScript expressions are not supported — compute it in a runScript and reference \${output.x}.`,e,n),r}function dt(e,t,n){let r=L(e,t,n),i={};for(let e of r){let r=G(e.value,`${t}.${e.key}`,n);r===null&&I(`Maestro ${t}.${e.key} expects a string, number, or boolean.`,e.value,n),i[e.key]=r}return i}function X(e,t,n){return H(e,`label`,e=>q(e,`${t}.label`,n))}const Z=[`id`,`text`,`enabled`,`selected`,`index`,`childOf`,`below`,`above`,`leftOf`,`rightOf`,`containsChild`,`containsDescendants`],ft={textKeys:[`id`,`text`],booleanKeys:[`enabled`,`selected`],textAliases:{label:`text`}},pt={id:(e,t,n,r)=>vt(e,`id`,t,n,r),text:(e,t,n,r)=>vt(e,`text`,t,n,r),enabled:(e,t,n,r)=>yt(e,`enabled`,t,n,r),selected:(e,t,n,r)=>yt(e,`selected`,t,n,r),index:(e,t,n,r)=>{e.index=Y(t.value,`${n}.index`,r,{integer:!0,nonNegative:!0})},childOf:(e,t,n,r)=>{e.childOf=Q(t.value,`${n}.childOf`,r)},below:(e,t,n,r)=>{e.below=Q(t.value,`${n}.below`,r)},above:(e,t,n,r)=>{e.above=Q(t.value,`${n}.above`,r)},leftOf:(e,t,n,r)=>{e.leftOf=Q(t.value,`${n}.leftOf`,r)},rightOf:(e,t,n,r)=>{e.rightOf=Q(t.value,`${n}.rightOf`,r)},containsChild:(e,t,n,r)=>{e.containsChild=Q(t.value,`${n}.containsChild`,r)},containsDescendants:(e,t,n,r)=>{e.containsDescendants=R(t.value,`${n}.containsDescendants`,r).map(e=>Q(e,`${n}.containsDescendants`,r))},optional:(e,t,n,r)=>yt(e,`optional`,t,n,r)};function Q(e,t,n,r=Z){if((0,P.isScalar)(e))return{text:K(e,t,n)};let i=L(e,t,n);return z(i,t,r,n),mt(i,t,n)}function mt(e,t,n){e.length===0&&I(`Maestro ${t} selector is empty.`,void 0,n);let r={};for(let i of e){let e=pt[i.key];e||I(`Maestro ${t} selector field "${i.key}" is not supported.`,i.keyNode,n),e(r,i,t,n)}return Object.keys(r).filter(e=>e!==`optional`).length===0&&I(`Maestro ${t} selector must contain a selector value.`,e[0]?.keyNode,n),r}function ht(e,t,n,r){let i=F(t,n);if((0,P.isScalar)(e))return{source:i,entries:[],target:xt(Q(e,r.name,n,r.selectorKeys))};let a=L(e,r.name,n),o=B(a,`point`);if(z(a,r.name,o?r.pointAllowedKeys:r.selectorAllowedKeys,n),o){let e=r.pointConflictingSelectorKeys??r.selectorKeys;return a.some(t=>bt(t.key,e))&&I(`Maestro ${r.name}.point cannot be combined with a selector.`,t,n),{source:i,entries:a,target:r.parsePoint(V(a,`point`),`${r.name}.point`,n)}}return{source:i,entries:a,target:xt(mt(a.filter(e=>bt(e.key,r.selectorKeys)),r.name,n))}}function gt(e,t,n){let r=K(e,t,n),i=/^\s*(\d+)\s*,\s*(\d+)\s*$/.exec(r);if(i)return{space:`absolute`,x:Number(i[1]),y:Number(i[2])};let a=/^\s*(\d+)%\s*,\s*(\d+)%\s*$/.exec(r);if(a){let r=Number(a[1]),i=Number(a[2]);return(r>100||i>100)&&I(`Maestro ${t} percentage coordinates must be between 0% and 100%.`,e,n),{space:`percent`,x:r,y:i}}/^\s*\d+(?:\.\d+)?%\s*,\s*\d+(?:\.\d+)?%\s*$/.test(r)&&I(`Maestro ${t} percentage coordinates must be whole numbers.`,e,n),I(`Maestro ${t} expects absolute or percentage coordinates.`,e,n)}function _t(e,t,n){let r=gt(e,t,n);return r.space!==`absolute`&&I(`Maestro ${t} only supports absolute coordinates.`,e,n),r}function vt(e,t,n,r,i){let a=q(n.value,`${r}.${t}`,i);a!==void 0&&(e[t]=a)}function yt(e,t,n,r,i){let a=J(n.value,`${r}.${t}`,i);a!==void 0&&(e[t]=a)}function bt(e,t){return t.includes(e)}function xt(e){return{space:`target`,selector:e}}function St(e,t,n){let r=ht(e,t,n,{name:`tapOn`,selectorKeys:Z,pointConflictingSelectorKeys:Z,pointAllowedKeys:[`point`,`retryTapIfNoChange`,`repeat`,`delay`,`optional`,`label`],selectorAllowedKeys:[...Z,`retryTapIfNoChange`,`repeat`,`delay`,`optional`,`label`],parsePoint:gt});if(r.entries.length===0)return{kind:`tapOn`,source:r.source,target:r.target};if(r.target.space!==`target`)return{kind:`tapOn`,source:r.source,target:r.target,...kt(r.entries,n)};let i=kt(r.entries,n);return o({kind:`tapOn`,source:r.source,target:r.target,...i})}function Ct(e,t,n){let r=ht(e,t,n,{name:`doubleTapOn`,selectorKeys:Z,pointAllowedKeys:[`point`,`delay`,`optional`,`label`],selectorAllowedKeys:[...Z,`delay`,`optional`,`label`],parsePoint:_t}),i=U(r.entries,`doubleTapOn`,n),a=B(r.entries,`delay`)?Y(V(r.entries,`delay`),`doubleTapOn.delay`,n):void 0,s=X(r.entries,`doubleTapOn`,n);return o({kind:`doubleTapOn`,source:r.source,target:r.target,...i,delay:a,label:s})}function wt(e,t,n){let r=ht(e,t,n,{name:`longPressOn`,selectorKeys:Z,pointAllowedKeys:[`point`,`optional`,`label`],selectorAllowedKeys:[...Z,`optional`,`label`],parsePoint:_t});return o({kind:`longPressOn`,source:r.source,target:r.target,...U(r.entries,`longPressOn`,n),label:X(r.entries,`longPressOn`,n)})}function Tt(e,t,n){let r=F(t,n),i=L(e,`swipe`,n);z(i,`swipe`,[`start`,`end`,`direction`,`duration`,`from`,`label`,`optional`],n);let a=U(i,`swipe`,n),o=X(i,`swipe`,n),s=B(i,`duration`)?Y(V(i,`duration`),`swipe.duration`,n):void 0;if(B(i,`start`)||B(i,`end`))return{...Et(i,r,s,t,n),...a,label:o};let c=B(i,`direction`)?At(V(i,`direction`),`swipe.direction`,n):void 0;return B(i,`from`)?{...Dt(i,r,c,s,t,n),...a,label:o}:{...Ot(r,c,s,t,n),...a,label:o}}function Et(e,t,n,r,i){B(e,`direction`)&&I(`Maestro swipe cannot combine direction with start/end coordinates.`,r,i),(!B(e,`start`)||!B(e,`end`))&&I(`Maestro swipe requires both start and end coordinates.`,r,i);let a=gt(V(e,`start`),`swipe.start`,i),s=gt(V(e,`end`),`swipe.end`,i);return a.space!==s.space&&I(`Maestro swipe start/end must use the same coordinate space.`,r,i),{kind:`swipe`,source:t,gesture:o({kind:`coordinates`,start:a,end:s,duration:n})}}function Dt(e,t,n,r,i,a){return n===void 0&&I(`Maestro target swipe requires direction.`,i,a),{kind:`swipe`,source:t,gesture:o({kind:`target`,from:Q(V(e,`from`),`swipe.from`,a),direction:n,duration:r})}}function Ot(e,t,n,r,i){return t===void 0&&I(`Maestro swipe requires direction, target, or start/end coordinates.`,r,i),{kind:`swipe`,source:e,gesture:o({kind:`screen`,direction:t,duration:n})}}function kt(e,t){let n=H(e,`retryTapIfNoChange`,e=>J(e,`tapOn.retryTapIfNoChange`,t)),r=H(e,`repeat`,e=>lt(e,`tapOn.repeat`,t)),i=H(e,`delay`,e=>Y(e,`tapOn.delay`,t)),a=U(e,`tapOn`,t).optional;return o({retryTapIfNoChange:n,repeat:r,delay:i,optional:a,label:X(e,`tapOn`,t)})}function At(e,t,n){let r=K(e,t,n).toLowerCase();if(r===`up`||r===`down`||r===`left`||r===`right`)return r;I(`Maestro ${t} must be UP, DOWN, LEFT, or RIGHT.`,e,n)}function jt(e,t,n,r){let i=F(n,r);if((0,P.isScalar)(t))return{kind:e,source:i,target:Q(t,e,r)};let a=L(t,e,r);z(a,e,[...Z,`optional`,`label`],r);let s=U(a,e,r),c=X(a,e,r);return o({kind:e,source:i,target:mt(a.filter(e=>e.key!==`optional`&&e.key!==`label`),e,r),...s,label:c})}const Mt=[...Z,`optional`];function Nt(e,t,n,r){if(!B(e,t))return;let{optional:i,...a}=Q(V(e,t),n,r,Mt);return{selector:a,optional:i}}function Pt(e,t,n){let r=Nt(e,`visible`,`extendedWaitUntil.visible`,n),i=Nt(e,`notVisible`,`extendedWaitUntil.notVisible`,n);return r&&i&&I(`Maestro extendedWaitUntil cannot specify both visible and notVisible.`,t,n),!r&&!i&&I(`Maestro extendedWaitUntil requires visible or notVisible.`,t,n),r?{key:`visible`,selector:r.selector,optional:r.optional}:{key:`notVisible`,selector:i.selector,optional:i.optional}}function Ft(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`runScript`,source:r,file:K(e,`runScript`,n)};let i=L(e,`runScript`,n);return z(i,`runScript`,[`file`,`env`],n),B(i,`file`)||I(`Maestro runScript requires a file.`,t,n),o({kind:`runScript`,source:r,file:K(V(i,`file`),`runScript.file`,n),env:B(i,`env`)?dt(V(i,`env`),`runScript.env`,n):void 0})}function It(e,t,n,r){let i=F(t,n);if((0,P.isScalar)(e))return{kind:`runFlow`,source:i,include:{kind:`file`,path:K(e,`runFlow`,n)}};let a=L(e,`runFlow`,n);z(a,`runFlow`,[`file`,`commands`,`env`,`when`,`label`],n);let s=B(a,`file`);return s===B(a,`commands`)&&I(`Maestro runFlow requires exactly one of file or commands.`,t,n),o({kind:`runFlow`,source:i,include:s?{kind:`file`,path:K(V(a,`file`),`runFlow.file`,n)}:{kind:`commands`,commands:r(V(a,`commands`),`runFlow.commands`,n)},env:B(a,`env`)?dt(V(a,`env`),`runFlow.env`,n):void 0,when:B(a,`when`)?zt(V(a,`when`),n):void 0,label:X(a,`runFlow`,n)})}function Lt(e,t,n,r){let i=F(t,n),a=L(e,`repeat`,n);return z(a,`repeat`,[`times`,`commands`,`while`],n),B(a,`while`)&&I(`Maestro repeat.while is not supported; use repeat.times.`,V(a,`while`),n),B(a,`times`)||I(`Maestro repeat requires times.`,t,n),B(a,`commands`)||I(`Maestro repeat requires commands.`,t,n),{kind:`repeat`,source:i,times:lt(V(a,`times`),`repeat.times`,n),commands:r(V(a,`commands`),`repeat.commands`,n)}}function Rt(e,t,n,r){let i=F(t,n),a=L(e,`retry`,n);z(a,`retry`,[`maxRetries`,`commands`],n),B(a,`commands`)||I(`Maestro retry requires commands.`,t,n);let s=B(a,`maxRetries`)?lt(V(a,`maxRetries`),`retry.maxRetries`,n):void 0;return o({kind:`retry`,source:i,commands:r(V(a,`commands`),`retry.commands`,n),maxRetries:s})}function zt(e,t){let n=L(e,`runFlow.when`,t);return z(n,`runFlow.when`,[`platform`,`visible`,`notVisible`,`true`],t),n.length===0&&I(`Maestro runFlow.when cannot be empty.`,e,t),o({platform:H(n,`platform`,e=>Vt(e,t)),visible:H(n,`visible`,e=>Q(e,`runFlow.when.visible`,t)),notVisible:H(n,`notVisible`,e=>Q(e,`runFlow.when.notVisible`,t)),true:H(n,`true`,e=>Bt(e,t))})}function Bt(e,t){let n=G(e,`runFlow.when.true`,t);if(typeof n==`boolean`||typeof n==`string`)return n;I(`Maestro runFlow.when.true expects a boolean or expression string.`,e,t)}function Vt(e,t){let n=K(e,`runFlow.when.platform`,t).toLowerCase();if(n===`android`||n===`ios`||n===`web`)return n;I(`Maestro runFlow.when.platform expects Android, iOS, or Web.`,e,t)}function $(e,t,n){return R(e,t,n).map(e=>Ht(e,n))}function Ht(e,t){if((0,P.isScalar)(e))return typeof e.value!=`string`&&I(`Maestro command names must be strings.`,e,t),Ut(e.value,e,t);(0,P.isMap)(e)||I(`Maestro commands must be a scalar or one-key map.`,e,t);let n=L(e,`command`,t);n.length!==1&&I(`Maestro command maps must contain exactly one command.`,e,t);let r=n[0];return Gt(r.key,r.value,e,t)}function Ut(e,t,n){return Gt(e,null,t,n)}const Wt={launchApp:Kt,tapOn:St,doubleTapOn:Ct,longPressOn:wt,inputText:qt,eraseText:Jt,openLink:Yt,assertVisible:(e,t,n)=>jt(`assertVisible`,e,t,n),assertNotVisible:(e,t,n)=>jt(`assertNotVisible`,e,t,n),assertTrue:Xt,extendedWaitUntil:Zt,takeScreenshot:Qt,scroll:$t,scrollUntilVisible:en,swipe:Tt,hideKeyboard:tn,pressKey:nn,back:rn,waitForAnimationToEnd:an,stopApp:on,setPermissions:sn,clearState:un,runScript:Ft,evalScript:dn,runFlow:(e,t,n)=>It(e,t,n,$),repeat:(e,t,n)=>Lt(e,t,n,$),retry:(e,t,n)=>Rt(e,t,n,$)};Object.keys(Wt);function Gt(e,t,n,r){let i=Wt[e];return i||I(`Maestro command "${e}" is not supported.`,n,r),i(t,n,r)}function Kt(e,t,n){let r=F(t,n);if(W(e))return{kind:`launchApp`,source:r};if((0,P.isScalar)(e))return{kind:`launchApp`,source:r,appId:K(e,`launchApp`,n)};let i=L(e,`launchApp`,n);return z(i,`launchApp`,[`appId`,`stopApp`,`clearState`,`permissions`,`arguments`,`launchArguments`],n),o({kind:`launchApp`,source:r,appId:H(i,`appId`,e=>q(e,`launchApp.appId`,n)),stopApp:H(i,`stopApp`,e=>J(e,`launchApp.stopApp`,n)),clearState:H(i,`clearState`,e=>J(e,`launchApp.clearState`,n)),permissions:H(i,`permissions`,e=>cn(e,n,`launchApp`)),arguments:H(i,`arguments`,e=>fn(e,`launchApp.arguments`,n)),launchArguments:H(i,`launchArguments`,e=>fn(e,`launchApp.launchArguments`,n))})}function qt(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`inputText`,source:r,text:K(e,`inputText`,n)};let i=L(e,`inputText`,n);return z(i,`inputText`,[`text`,`label`],n),B(i,`text`)||I(`Maestro inputText requires text.`,t,n),o({kind:`inputText`,source:r,text:K(V(i,`text`),`inputText.text`,n),label:X(i,`inputText`,n)})}function Jt(e,t,n){let r=F(t,n);if(W(e))return{kind:`eraseText`,source:r};if((0,P.isScalar)(e))return{kind:`eraseText`,source:r,charactersToErase:lt(e,`eraseText`,n)};let i=L(e,`eraseText`,n);return z(i,`eraseText`,[`charactersToErase`],n),o({kind:`eraseText`,source:r,charactersToErase:B(i,`charactersToErase`)?Y(V(i,`charactersToErase`),`eraseText.charactersToErase`,n):void 0})}function Yt(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`openLink`,source:r,link:K(e,`openLink`,n)};let i=L(e,`openLink`,n);return z(i,`openLink`,[`link`],n),{kind:`openLink`,source:r,link:K(V(i,`link`),`openLink.link`,n)}}function Xt(e,t,n){let r=F(t,n);if(W(e)&&I(`Maestro assertTrue requires condition.`,t,n),(0,P.isScalar)(e))return{kind:`assertTrue`,source:r,condition:ut(e,`assertTrue`,n)};let i=L(e,`assertTrue`,n);z(i,`assertTrue`,[`condition`,`optional`,`label`],n),B(i,`condition`)||I(`Maestro assertTrue requires condition.`,t,n);let a=ut(V(i,`condition`),`assertTrue.condition`,n),s=U(i,`assertTrue`,n),c=X(i,`assertTrue`,n);return o({kind:`assertTrue`,source:r,condition:a,...s,label:c})}function Zt(e,t,n){let r=L(e,`extendedWaitUntil`,n);z(r,`extendedWaitUntil`,[`visible`,`notVisible`,`timeout`,`optional`,`label`],n);let i=U(r,`extendedWaitUntil`,n),a=X(r,`extendedWaitUntil`,n),s=Pt(r,t,n),c=B(r,`timeout`)?Y(V(r,`timeout`),`extendedWaitUntil.timeout`,n):void 0,l=i.optional===!0||s.optional===!0||void 0,u={kind:`extendedWaitUntil`,source:F(t,n),timeout:c,optional:l,label:a};return u[s.key]=s.selector,o(u)}function Qt(e,t,n){return{kind:`takeScreenshot`,source:F(t,n),path:K(e,`takeScreenshot`,n)}}function $t(e,t,n){return W(e)||I(`Maestro scroll does not accept options yet.`,t,n),{kind:`scroll`,source:F(t,n)}}function en(e,t,n){let r=F(t,n);if((0,P.isScalar)(e))return{kind:`scrollUntilVisible`,source:r,element:Q(e,`scrollUntilVisible.element`,n)};let i=L(e,`scrollUntilVisible`,n);z(i,`scrollUntilVisible`,[`element`,`direction`,`timeout`,`optional`,`label`],n);let a=U(i,`scrollUntilVisible`,n),s=X(i,`scrollUntilVisible`,n),c=Nt(i,`element`,`scrollUntilVisible.element`,n);c||I(`Maestro scrollUntilVisible requires element.`,t,n);let l=B(i,`direction`)?At(V(i,`direction`),`scrollUntilVisible.direction`,n):void 0,u=B(i,`timeout`)?Y(V(i,`timeout`),`scrollUntilVisible.timeout`,n):void 0,d=a.optional===!0||c.optional===!0||void 0;return o({kind:`scrollUntilVisible`,source:r,element:c.selector,direction:l,timeout:u,optional:d,label:s})}function tn(e,t,n){return W(e)||I(`Maestro hideKeyboard does not accept options.`,t,n),{kind:`hideKeyboard`,source:F(t,n)}}function nn(e,t,n){let r=K(e,`pressKey`,n).toLowerCase();return r!==`back`&&r!==`enter`&&r!==`return`&&r!==`home`&&I(`Maestro pressKey "${r}" is not supported.`,e,n),{kind:`pressKey`,source:F(t,n),key:r}}function rn(e,t,n){return W(e)||I(`Maestro back does not accept options.`,t,n),{kind:`back`,source:F(t,n)}}function an(e,t,n){let r=F(t,n);if(W(e))return{kind:`waitForAnimationToEnd`,source:r};if((0,P.isScalar)(e))return o({kind:`waitForAnimationToEnd`,source:r,timeout:Y(e,`waitForAnimationToEnd`,n)});let i=L(e,`waitForAnimationToEnd`,n);return z(i,`waitForAnimationToEnd`,[`timeout`],n),o({kind:`waitForAnimationToEnd`,source:r,timeout:B(i,`timeout`)?Y(V(i,`timeout`),`waitForAnimationToEnd.timeout`,n):void 0})}function on(e,t,n){let r=F(t,n);return W(e)?{kind:`stopApp`,source:r}:{kind:`stopApp`,source:r,appId:K(e,`stopApp`,n)}}function sn(e,t,n){let r=F(t,n),i=L(e,`setPermissions`,n);z(i,`setPermissions`,[`appId`,`permissions`,`optional`,`label`],n),B(i,`permissions`)||I(`Maestro setPermissions requires permissions.`,t,n);let a=H(i,`appId`,e=>q(e,`setPermissions.appId`,n)),s=cn(V(i,`permissions`),n),c=U(i,`setPermissions`,n),l=X(i,`setPermissions`,n);return o({kind:`setPermissions`,source:r,appId:a,permissions:s,...c,label:l})}function cn(e,t,n=`setPermissions`){let r=L(e,`${n}.permissions`,t);r.length===0&&I(`Maestro ${n}.permissions requires at least one permission.`,e,t);let i={};for(let e of r)i[e.key]=ln(e,t,n);return i}function ln(e,t,n=`setPermissions`){let r=`${n}.permissions.${e.key}`,i=G(e.value,r,t);typeof i!=`string`&&I(`Maestro ${r} expects a string.`,e.value,t);let a=i.toLowerCase();if(nt.has(a))return a;if(tt.test(i))return i;i.includes("${")&&I(`Maestro ${r} only supports allow|deny|unset (plus always|inuse|never|limited for location/photos) or a bare \${VAR} lookup; JavaScript expressions are not supported.`,e.value,t),I(`Maestro ${r} expects allow|deny|unset (plus always|inuse|never|limited for location/photos) or a bare \${VAR} lookup.`,e.value,t)}function un(e,t,n){let r=F(t,n);return W(e)?{kind:`clearState`,source:r}:{kind:`clearState`,source:r,appId:K(e,`clearState`,n)}}function dn(e,t,n){return{kind:`evalScript`,source:F(t,n),script:K(e,`evalScript`,n)}}function fn(e,t,n){if((0,P.isSeq)(e))return{kind:`list`,values:R(e,t,n).map((e,r)=>{let i=G(e,`${t}[${r}]`,n);return i===null&&I(`${t}[${r}] expects a scalar value.`,e,n),i})};if((0,P.isMap)(e))return{kind:`map`,values:dt(e,t,n)};let r=G(e,t,n);return r===null&&I(`${t} expects a scalar, list, or map.`,e,n),{kind:`scalar`,value:r}}function pn(e,t={}){let n=new P.LineCounter,i=o({lineCounter:n,sourcePath:t.sourcePath}),a=(0,P.parseAllDocuments)(e,{lineCounter:n});for(let e of a)if(e.errors.length>0){let t=e.errors[0],n=t?.message??`Invalid Maestro YAML flow.`,a=Qe(t?.pos[0],i);throw new r(`INVALID_ARGS`,`Invalid Maestro YAML flow: ${n} (${$e(a)})`)}let s=a.map(e=>e.contents).filter(e=>e!==null);s.length===0&&I(`Maestro flow is empty.`,void 0,i);let c,l;s.length===1&&(0,P.isSeq)(s[0])?l=s[0]:s.length===2&&(0,P.isMap)(s[0])&&(0,P.isSeq)(s[1])?(c=s[0],l=s[1]):I(`Maestro flow must contain a command list, optionally preceded by one config document.`,s[0],i);let u=c?mn(c,i):{};return{kind:`program`,source:F(c??l,i),config:u,commands:$(l,`commands`,i)}}function mn(e,t){let n=L(e,`flow config`,t);return z(n,`flow config`,[`name`,`appId`,`tags`,`env`,`onFlowStart`,`onFlowComplete`],t),o({name:H(n,`name`,e=>q(e,`name`,t)),appId:H(n,`appId`,e=>q(e,`appId`,t)),tags:H(n,`tags`,e=>et(e,`tags`,t)),env:H(n,`env`,e=>dt(e,`env`,t)),onFlowStart:H(n,`onFlowStart`,e=>$(e,`onFlowStart`,t)),onFlowComplete:H(n,`onFlowComplete`,e=>$(e,`onFlowComplete`,t))})}function hn(e,t){let n=new Map;return async(r,a,o)=>{if(o?.aborted)throw i();let s=gn(r,a,e),c=n.get(s);if(c)return c;let l=pn(t(s),{sourcePath:s});return n.set(s,l),l}}function gn(e,t,n){let r=t?a.dirname(t):n;return a.resolve(r,e)}function _n(e){let t={[e.entryPath]:e.entrySource},n=vn(e.entrySource,e.entryPath);return n&&yn({program:n,sourcePath:e.entryPath,context:l({},{...e.env}),files:t,readSource:e.readSource}),t}function vn(e,t){try{return pn(e,{sourcePath:t})}catch{return}}function yn(e){let t=e.context.enter(e.program.config.env??{});try{bn([...e.program.config.onFlowStart??[],...e.program.commands,...e.program.config.onFlowComplete??[]],e)}finally{t()}}function bn(e,t){for(let n of e){if(n.kind===`repeat`||n.kind===`retry`){bn(n.commands,t);continue}if(n.kind!==`runFlow`)continue;let e=t.context.enter(n.env??{});try{if(n.include.kind===`commands`){bn(n.include.commands,t);continue}xn(n.include.path,t)}finally{e()}}}function xn(e,t){let n=t.context.resolveDeferred(e);if(n.includes("${"))return;let r=gn(n,t.sourcePath,t.sourcePath);if(t.files[r]!==void 0)return;let i=t.readSource(r);if(i===void 0)return;t.files[r]=i;let a=vn(i,r);a&&yn({...t,program:a,sourcePath:r})}var Sn=t({MAESTRO_COMPATIBILITY_ADR_URL:()=>MAESTRO_COMPATIBILITY_ADR_URL,MAESTRO_COMPATIBILITY_ISSUE_URL:()=>MAESTRO_COMPATIBILITY_ISSUE_URL,collectMaestroFlowSources:()=>_n});export{at as a,l as c,o as d,ft as i,c as l,hn as n,ot as o,pn as r,Ze as s,Sn as t,s as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as
|
|
1
|
+
import{g as e}from"./sdk-batch-runner.js";import{d as t,f as n}from"./sdk-device.js";import{r}from"./recording-export-quality.js";import{n as i}from"./recording-scope.js";import{i as a,n as o}from"./recording-stop-observation.js";import{t as s}from"./screen-recording-completion.js";import{t as c}from"./artifact-paths.js";async function l(e,t){try{return await e()}catch{if(t?.aborted)throw t.reason;return!1}}function u(e){return e.exitCode===0}function d(e){return process.platform===`darwin`&&(n(e)||t(e)&&e.kind===`simulator`||e.platform===`android`&&e.kind===`emulator`)}const f=[`scope`,`showTouches`,`recordOnlySession`,`activeSessionApp`,`exportQuality`];function p(e){return i(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`&&(e.exportQuality===void 0||r(e.exportQuality))&&m(e.activeSessionApp)}function m(t){return t===void 0?!0:!e(t)||!h(t.bundleId)?!1:t.name===void 0||h(t.name)}function h(e){return typeof e==`string`&&e.length>0}function g(e){return e.exportPath===void 0?e.observation===void 0||e.observation.recorder===`unconfirmed`:!1}const _=`stopObservation`,v=`stoppedAtMs`,y=`stopRecorderWarning`,b=`collectedPath`,x=`exportPath`,S=`stopFinalization`,C=Symbol(`unreadable`),w={telemetryPath:j(),warning:j(),overlayWarning:j(),nativePathDisposition:{encode:e=>e,read:e=>e===void 0?void 0:a(e)?e:C},chunks:{encode:e=>e.map(M),read:e=>e===void 0?void 0:N(e)??C},capturedDurationMs:{encode:e=>e,read:e=>e===void 0?void 0:F(e)?e:C}};function T(e){return{...e.observation===void 0?{}:{[_]:D(e.observation)},...e.stoppedAtMs===void 0?{}:{[v]:e.stoppedAtMs},...e.recorderWarning===void 0?{}:{[y]:e.recorderWarning},...e.collectedPath===void 0?{}:{[b]:e.collectedPath},...e.exportPath===void 0?{}:{[x]:e.exportPath},...e.finalization===void 0?{}:{[S]:O(e.finalization)}}}function E(e){let t=e?.[_],n=e?.[v],r=I(e?.[y]),i=I(e?.[b]),a=I(e?.[x]),s=k(e?.[S]);return{...o(t)?{observation:t}:{},...F(n)?{stoppedAtMs:n}:{},...r===void 0?{}:{recorderWarning:r},...i===void 0?{}:{collectedPath:i},...a===void 0?{}:{exportPath:a},...s===void 0?{}:{finalization:s}}}function D(e){return e.recorder===`confirmed`?{recorder:e.recorder}:{recorder:e.recorder,why:e.why}}function O(e){let t={};for(let n of A()){let r=e[n];r!==void 0&&(t[n]=w[n].encode(r))}return t}function k(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n={};for(let e of A()){let r=w[e].read(t[e]);if(r===C)return;r!==void 0&&(n[e]=r)}return Object.keys(n).length===0?void 0:n}function A(){return Object.keys(w)}function j(){return{encode:e=>e,read:I}}function M(e){return{index:e.index,path:e.path,...e.clientOutPath===void 0?{}:{clientOutPath:e.clientOutPath}}}function N(e){if(!Array.isArray(e))return;let t=e.map(P);return t.every(e=>e!==void 0)?t:void 0}function P(e){if(typeof e!=`object`||!e)return;let{index:t,path:n,clientOutPath:r}=e,i=I(n),a=I(r);if(!(!Number.isInteger(t)||t<1||i===void 0)&&(r===void 0||a!==void 0))return{index:t,path:i,...a===void 0?{}:{clientOutPath:a}}}function F(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function I(e){return typeof e==`string`&&e.length>0?e:void 0}async function L(e){let{steps:t,snapshot:n,progress:r,now:i=Date.now}=e,a=E(r?.learned),o=a.observation,l=a.recorderWarning,u=a.stoppedAtMs;if(g(a)){u=i();let e=await t.stop();o=e.observation,l=e.warning,r?.record(T({observation:o,stoppedAtMs:u,recorderWarning:e.warning}))}if(o===void 0)throw Error(`record stop reached collection without an observation of its recorder and a committed export`);let d=a.collectedPath??c(n.outPath);a.collectedPath===void 0&&(await t.collect(d),r?.record(T({collectedPath:d})));let f=a.finalization??await t.finalize({collectedPath:d,exportPath:n.outPath,stoppedAtMs:u??i()});r?.record(T({exportPath:n.outPath,finalization:f})),await t.discard(d);let{nativePathDisposition:p,warning:m,...h}=f,_=[m,l].filter(e=>e!==void 0&&e.length>0);return s(n,{...h,..._.length===0?{}:{warning:_.join(` `)}},{stopObservation:o,...p===void 0?{}:{nativePathDisposition:p}})}export{d as a,p as i,E as n,u as o,f as r,l as s,L as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{Hr as t,Kr as n,Ur as r}from"./sdk-batch.js";import{n as i,r as a}from"./snapshot.js";function o(t,n,r,i){return new e(`COMMAND_FAILED`,`fill tapped (${t}, ${n}) but ${r}`,{reason:`text_entry_focus_not_observed`,x:t,y:n,...i,hint:`The tap most likely missed the field. Re-check the target with snapshot -i and fill the element it reports, rather than retrying the same coordinates.`})}function s(e){let t=[];for(let n of p(e)){let e=a(n);r(e)&&t.push({node:n,identity:m(n),rect:e})}return t}function c(e){let t=new Map;for(let n of e)t.set(n.identity,(t.get(n.identity)??0)+1);return t}function l(e){let t=s(e),r=c(t),i=null,a=1/0;for(let e of t){if(!e.node.traits?.includes(`IsEditing`))continue;let t=n(e.rect);t>=a||(i=r.get(e.identity)===1?{identity:e.identity,rect:e.rect}:{rect:e.rect},a=t)}return i}function u(e,n,r){let i=s(e),a=c(i),o=new Set;for(let e of i)a.get(e.identity)===1&&t(e.rect,n,r)&&o.add(e.identity);return o}async function d(e){let t=Date.now()+(e.timeoutMs??3e3),n=0,r=!1;for(;;){let i=await e.readFocus();if(n+=1,i&&(r=!0,f(i,e.targetsAtPoint,e.x,e.y)))return`focused-element`;if(Date.now()>=t)break;await e.sleep(150)}throw o(e.x,e.y,`nothing there took text-entry focus, so the text was not sent`,{samples:n,editingElementObserved:r})}function f(e,n,r,i){return t(e.rect,r,i)?!0:e.identity!==void 0&&n.has(e.identity)}function p(e){let t=[],n=e=>{t.push(e);for(let t of i(e))n(t)};for(let t of Array.isArray(e)?e:[e])n(t);return t}function m(e){return[e.pid??``,e.type??e.elementType??``,e.AXUniqueId??e.identifier??``,e.AXLabel??e.label??``].join(`\0`)}export{d as awaitLimrunTextEntryFocus,l as readLimrunTextEntryFocus,u as readLimrunUnambiguousTapTargets};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{n as t,r as n}from"./interactor-operation-binding.js";function r(e){let t=t=>t??e.unsupported;return Object.freeze({tapPoint:e.tap,tapRef:t(e.tapRef),longPressPoint:e.longPress,hoverPoint:i(t(e.hover)),hoverRef:i(t(e.hoverRef)),fillPoint:e.fill,fillRef:t(e.fillRef),tapElementSelector:t(e.tapElementSelector)})}function i(e){return e.available?e:Object.freeze({...e,hint:e.hint??`hover raises pointer hover state and is available on web targets only. On touch platforms use longpress for hold gestures.`})}function a(e,t){return{...e.execution,appBundleId:e.appBundleId,signal:t}}function o(t,n,r,i){let o=async e=>(t.throwIfAborted(),await n(a(e,t))),l=async e=>{let t=await o(e);return e.options.button!==`primary`&&t.alternateClick?await t.alternateClick(e.point,e.options.button):t.pressPoint?await t.pressPoint(e.point,e.options):await c(t,e.point,e.options,i)},u=async t=>{let n=await o(t);if(!n.hover)throw new e(`UNSUPPORTED_OPERATION`,`Bound runtime advertised hover without an interactor.`);return await n.hover(t.point.x,t.point.y)},d=async e=>await(await o(e)).fill(e.point.x,e.point.y,e.text,e.delayMs,{allowNonHittableCoordinateFallback:e.allowNonHittableCoordinateFallback});return Object.freeze({...r.tapPoint.available?{tapPoint:l}:{},...r.tapRef.available?{tapRef:async e=>{let t=await o(e);return t.tapRef?await t.tapRef(e.ref):s(`tapRef`)}}:{},...r.longPressPoint.available?{longPressPoint:async e=>await(await o(e)).longPress(e.point.x,e.point.y,e.durationMs)}:{},...r.hoverPoint.available?{hoverPoint:u}:{},...r.hoverRef.available?{hoverRef:async e=>{let t=await o(e);return t.hoverRef?await t.hoverRef(e.ref):s(`hoverRef`)}}:{},...r.fillPoint.available?{fillPoint:d}:{},...r.fillRef.available?{fillRef:async e=>{let t=await o(e);return t.fillRef?await t.fillRef(e.ref,e.text,e.delayMs):s(`fillRef`)}}:{},...r.tapElementSelector.available?{tapElementSelector:async e=>{let t=await o(e);return t.tapElementSelector?await t.tapElementSelector(e.selector):s(`tapElementSelector`)}}:{}})}function s(t){throw new e(`UNSUPPORTED_OPERATION`,`Bound runtime advertised ${t} without an interactor.`)}async function c(t,n,r,i){if(r.button!==`primary`)throw new e(`UNSUPPORTED_OPERATION`,`Bound runtime does not implement ${r.button} click.`);let a;for(let e=0;e<r.count;e+=1){let[o,s]=u(e,r.jitterPx),c=r.doubleTap?await t.doubleTap(n.x+o,n.y+s):r.holdMs>0?await t.longPress(n.x+o,n.y+s,r.holdMs):await t.tap(n.x+o,n.y+s);a??=c,e<r.count-1&&r.intervalMs>0&&await i(r.intervalMs)}return a}const l=[[0,0],[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]];function u(e,t){if(t<=0)return[0,0];let[n,r]=l[e%l.length];return[n*t,r*t]}function d(e){return o(e.signal,t(e),e.facts,e.pause)}function f(e){return o(e.signal,n({...e,operation:`touch`}),e.facts,e.pause)}export{r as i,f as n,u as r,d as t};
|
package/dist/src/tree.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Ir as e}from"./sdk-batch.js";function t(e){let t=new Map;for(let n of e){if(typeof n.parentIndex!=`number`)continue;let e=t.get(n.parentIndex)??[];e.push(n),t.set(n.parentIndex,e)}return t}const n=new WeakMap;function r(e,t){if(!e[t])return[];let n=o(e)[t]??t+1;return e.slice(t+1,n)}function i(e,t,n){let r=o(e)[t]??t+1;for(let i=t+1;i<r;i+=1){let t=e[i];if(t&&n(t))return t}}function a(e,t,n){let r=o(e)[t]??t+1;for(let i=t+1;i<r;i+=1){let t=e[i];t&&n(t)}}function o(e){let t=n.get(e);if(t)return t;let r=Array(e.length),i=[];for(let[t,n]of e.entries()){let e=n?.depth??0;for(;i.length>0&&e<=i.at(-1).depth;){let e=i.pop();r[e.position]=t}i.push({depth:e,position:t})}for(let t of i)r[t.position]=e.length;return n.set(e,r),r}function s(e,t){let n=[],r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);)i.add(r.index),n.push(r),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0;return n}function c(e,t,n){for(let r of s(e,t))if(n(r))return r;return null}function l(e,t,n={}){return(n.includeSelf===!0&&p(e.type)?e:null)??c(e,t,e=>p(e.type))}function u(t,n){let r=e(t.type??``),i=t.label?.trim();return!!(f(t)||r===`other`&&!i&&!t.value||(r===`other`||r===`statictext`)&&i&&n.includes(i)||r===`image`)}function d(t){let n=e(t.type??``);return n===`button`||n===`link`||n===`switch`||n===`searchfield`||n===`textfield`}function f(t){return e(t.type??``)===`button`&&t.label?.trim()===`chevron`&&t.enabled===!1}function p(t){let n=e(t??``);return n===`collectionview`||n===`table`||n===`scrollview`||n===`scrollarea`}function m(t,n){let r=t.label?.trim();if(!r||r!==n)return!1;let i=e(t.type??``);return i===`other`||i===`statictext`||i===`link`}function h(e,t,n){e.set(t.index,_(v(e,t),n))}function g(e,t,n){let r=v(e,t);e.set(t.index,_(r,n(r)))}function _(e,t){let n={...e,...t};for(let[e,r]of Object.entries(t))r===void 0&&delete n[e];return n}function v(e,t){return e.get(t.index)??t}function y(t){let n;for(let r of t){let t=e(r.type??``);(t===`application`||t===`window`)&&x(r.rect,n)&&(n=r.rect)}return n}function b(e,t,n=.8){let r=S(e),i=S(t);return r>0&&i>0&&r/i>=n}function x(e,t){return!!(e&&(!t||S(e)>S(t)))}function S(e){return e?e.width*e.height:0}function C(e,t,n){let r=new Map(n.map(e=>[e.index,e])),i=new Map;for(let[t,n]of e.entries())i.set(n.index,t);return e.map((e,n)=>{let a=typeof e.parentIndex==`number`?i.get(e.parentIndex):void 0;return a===void 0&&typeof e.parentIndex==`number`&&(a=w(e.parentIndex,t,r,i)),{...e,index:n,parentIndex:a}})}function w(e,t,n,r){let i=e,a=new Set;for(;typeof i==`number`&&!a.has(i);){if(a.add(i),!t.has(i))return r.get(i);i=n.get(i)?.parentIndex}}export{c as a,f as c,p as d,d as f,g,u as h,y as i,b as l,C as m,r as n,l as o,h as p,i as r,a as s,t,m as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{Kt as t}from"./sdk-batch.js";import{g as n,m as r}from"./session-snapshot.js";import{x as i}from"./runtime.js";import{r as a}from"./success-text.js";function o(e){let t=e?.trim().split(/\s+/,1)[0];if(!t||!t.startsWith(`@`)||t.length<3)return null;let n=t.slice(1);return/^[A-Za-z_-]*\d[\w-]*$/i.test(n)||/^(?:ref|node|element|el)[\w-]*$/i.test(n)?t:null}async function s(e){let r=await n({command:`type`,device:e.device,use:t,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});if(r.type===`response`)return{ok:!1,response:r.response};let i=r.runtime;return{ok:!0,typeText:async(e,t)=>await c(i,e,t)}}async function c(t,n,r){let s=o(n[0]);if(s)throw new e(`INVALID_ARGS`,`type does not accept a target ref like "${s}"`,{hint:`Use fill ${s} "text" to target that field, or press ${s} then type "text" to append.`});let c=n.join(` `);if(!c)throw new e(`INVALID_ARGS`,`type requires text`);let u=i(r.delayMs??0,`delay-ms`,0,1e4),d=(await t.operations.typeText(l(c,u,r)))?.textEntryRoute;return{...d===void 0?{}:{textEntryRoute:d},text:c,delayMs:u,...a(`Typed ${Array.from(c).length} chars`)}}function l(e,t,n){return{text:e,delayMs:t,...n.appBundleId===void 0?{}:{options:{appBundleId:n.appBundleId}},execution:r(n)}}export{s as n,c as t};
|
package/dist/src/video.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{or as t}from"./sdk-batch.js";import{x as n}from"./owner-identity.js";import{c as r}from"./exec.js";import{t as i}from"./timeouts.js";import{n as a,t as o}from"./file.js";import"./command.js";import"./retry.js";import"./process.js";import s from"node:path";import c from"node:fs";import{createHash as l}from"node:crypto";import u from"node:os";import{fileURLToPath as d}from"node:url";const f=`apple/runner/AgentDeviceRunner/RecordingScripts`;function p(e,t,n,r){let i=`${f}/${e}`,a=`dist/${i}`;return[s.resolve(t,e),s.resolve(n,i),s.resolve(t,`../${i}`),s.resolve(t,`../../${i}`),s.resolve(t,`../../../${i}`),s.resolve(n,a),s.resolve(r,i)]}function m(t,n,r=s.dirname(d(import.meta.url)),i=process.cwd()){let a=p(t,r,n,i);for(let e of a)if(c.existsSync(e))return e;throw new e(`COMMAND_FAILED`,`Missing recording helper script: ${t}`,{hint:`Ensure ${f} is present in this checkout or bundled under dist/${f} in the package.`,scriptName:t,searchedPaths:a})}function h(e=process.env){let t=v(),n=s.join(t,`home`),r=s.join(t,`module-cache`);return c.mkdirSync(n,{recursive:!0}),c.mkdirSync(r,{recursive:!0}),{...e,HOME:n,CLANG_MODULE_CACHE_PATH:r}}async function g(e){let t=[e.sourcePath,...e.extraSourcePaths??[]],n=t.map(e=>({sourcePath:e,stat:c.statSync(e),source:c.readFileSync(e)})),r=S(e.cacheName??s.basename(e.sourcePath,s.extname(e.sourcePath))),i=C([`2`,process.platform,process.arch,...n.flatMap(({sourcePath:e,stat:t,source:n})=>[s.resolve(e),t.size,n])]),a=s.join(v(),`bin`,`${r}-${i}`);return await y({sourcePaths:t,executablePath:a,timeoutMs:e.timeoutMs}),a}async function _(e){let t=S(e.cacheName),n=C([`2`,process.platform,process.arch,e.source]),r=s.join(v(),`sources`,`${t}-${n}.swift`),i=s.join(v(),`bin`,`${t}-${n}`);return await y({sourcePaths:[r],executablePath:i,sourceText:e.source,timeoutMs:e.timeoutMs}),i}function v(){let e=process.env.AGENT_DEVICE_SWIFT_CACHE_DIR?.trim();return e?s.resolve(e):s.join(u.tmpdir(),`agent-device-swift-cache`)}async function y(e){if(x(e.executablePath))return;let t=s.dirname(e.executablePath);c.mkdirSync(t,{recursive:!0});let n=e.timeoutMs??12e4;await a({acquire:()=>b(`${e.executablePath}.lock`,n),task:async()=>{if(x(e.executablePath))return;let i=c.mkdtempSync(s.join(t,`.${s.basename(e.executablePath)}.${process.pid}.`)),a=s.join(i,s.basename(e.executablePath));try{let[t]=e.sourcePaths;e.sourceText!==void 0&&t&&!c.existsSync(t)&&(c.mkdirSync(s.dirname(t),{recursive:!0}),c.writeFileSync(t,e.sourceText)),await r(`xcrun`,[`swiftc`,...e.sourcePaths,`-o`,a],{timeoutMs:n,env:h()}),c.renameSync(a,e.executablePath)}finally{c.rmSync(i,{recursive:!0,force:!0})}}})}async function b(t,r){try{return await o({lockDirPath:t,owner:{pid:process.pid,startTime:n(process.pid),acquiredAtMs:Date.now()},timeoutMs:r,pollMs:25,ownerGraceMs:r,description:`Swift cache lock: ${t} (${r}ms)`})}catch(n){throw n instanceof e&&n.message.startsWith(`Timed out waiting for Swift cache lock:`)?new e(`COMMAND_FAILED`,n.message,{...n.details,lockDir:t,timeoutMs:r,hint:`Another agent-device process may still be compiling this Swift helper. Retry shortly; if no agent-device process is active, remove "${t}" and retry.`}):n}}function x(e){try{return c.accessSync(e,c.constants.X_OK),c.statSync(e).isFile()}catch{return!1}}function S(e){return t(e.replaceAll(/[^A-Za-z0-9._-]/g,`-`))||`swift-helper`}function C(e){let t=l(`sha256`);for(let n of e)t.update(Buffer.isBuffer(n)?n:String(n)),t.update(`\0`);return t.digest(`hex`).slice(0,16)}const w={block:161,blockGroup:160,cluster:524531317,codecId:134,documentType:17026,ebml:440786851,segment:408125543,simpleBlock:163,trackEntry:174,trackNumber:215,tracks:374648427,trackType:131};function T(e){let t=E(e);if(!t)return!1;let{bytes:n,fileSize:r}=t,i=L(n,0,n.length,r);if(!i||i.id!==w.ebml||!i.complete||i.unknownSize||!D(n,i))return!1;let a=L(n,i.nextOffset,n.length,r);return!a||a.id!==w.segment||!V(a,r)?!1:O(n,a,r)}function E(e){try{let t=c.openSync(e,`r`);try{let e=c.fstatSync(t).size;if(e<=0)return;let n=Buffer.alloc(Math.min(e,1048576));return c.readSync(t,n,0,n.length,0)===n.length?{bytes:n,fileSize:e}:void 0}finally{c.closeSync(t)}}catch{return}}function D(e,t){let n=I(e,t)?.find(e=>e.id===w.documentType);return n!==void 0&&e.toString(`ascii`,n.dataStart,n.dataEnd)===`webm`}function O(e,t,n){let r=new Set,i=new Set;for(let a=t.dataStart;a<t.dataEnd;){let o=L(e,a,t.dataEnd,n);if(!o||!V(o,n))return!1;if(o.id===w.tracks&&k(e,o,r),o.id===w.cluster&&j(e,o,n,i),H(r,i))return!0;if(!o.complete||o.unknownSize)return!1;a=o.nextOffset}return!1}function k(e,t,n){let r=I(e,t);if(r){for(let t of r)if(t.id===w.trackEntry){let r=A(e,t);r!==void 0&&n.add(r)}}}function A(e,t){let n=I(e,t),r=F(e,n,w.trackNumber),i=F(e,n,w.trackType),a=n?.find(e=>e.id===w.codecId),o=a?e.toString(`ascii`,a.dataStart,a.dataEnd):void 0;return i===1&&o?.startsWith(`V_`)?r:void 0}function j(e,t,n,r){for(let i=t.dataStart;i<t.dataEnd;){let a=L(e,i,t.dataEnd,n);if(!a||!V(a,n)||(a.id===w.simpleBlock&&N(e,a,r),a.id===w.blockGroup&&M(e,a,r),!a.complete||a.unknownSize))return;i=a.nextOffset}}function M(e,t,n){let r=I(e,t)?.find(e=>e.id===w.block);r&&N(e,r,n)}function N(e,t,n){if(!t.complete||t.unknownSize)return;let r=z(e,t.dataStart);!r||r.unknown||t.dataEnd-t.dataStart<r.length+4||n.add(r.value)}function P(e,t){let n=t.dataEnd-t.dataStart;if(n<1||n>6)return;let r=0;for(let n=t.dataStart;n<t.dataEnd;n+=1)r=r*256+e[n];return Number.isSafeInteger(r)?r:void 0}function F(e,t,n){let r=t?.find(e=>e.id===n);return r?P(e,r):void 0}function I(e,t){if(!t.complete||t.unknownSize)return;let n=[];for(let r=t.dataStart;r<t.dataEnd;){let i=L(e,r,t.dataEnd,e.length);if(!i||!i.complete||i.unknownSize)return;n.push(i),r=i.nextOffset}return n}function L(e,t,n,r){let i=R(e,t);if(!i)return;let a=z(e,t+i.length);if(!a)return;let o=t+i.length+a.length;if(o>n)return;let s=a.unknown?r:o+a.value;if(!(!Number.isSafeInteger(s)||s<o))return{id:i.value,dataStart:o,dataEnd:Math.min(s,n),nextOffset:s,complete:s<=n,unknownSize:a.unknown}}function R(e,t){let n=B(e,t,4);if(!n)return;let r=0;for(let i=0;i<n;i+=1)r=r*256+e[t+i];return{length:n,value:r}}function z(e,t){let n=B(e,t,8);if(!n)return;let r=e[t],i=128>>n-1;if((r&i-1)==i-1&&e.subarray(t+1,t+n).every(e=>e===255))return{length:n,value:0,unknown:!0};let a=r&i-1;for(let r=1;r<n;r+=1)a=a*256+e[t+r];return Number.isSafeInteger(a)?{length:n,value:a,unknown:!1}:void 0}function B(e,t,n){let r=e[t];if(r===void 0||r===0)return;let i=128,a=1;for(;(r&i)===0;)i>>=1,a+=1;return a<=n&&t+a<=e.length?a:void 0}function V(e,t){return e.unknownSize||e.nextOffset<=t}function H(e,t){for(let n of e)if(t.has(n))return!0;return!1}let U;async function W(e,t={}){let n=t.pollMs??150,r=t.attempts??12,a,o=0;for(let t=0;t<r;t+=1){let t=0;try{t=c.statSync(e).size}catch{t=0}if(t>0&&t===a){if(o+=1,o>=2)return}else o=0;a=t,await i(n)}}async function G(e){let t=await Z(e);if(!t)return!1;if(t===`webm`)return!0;try{let t=await K(),n=await r(t,[e],{allowFailure:!0,timeoutMs:1e4,env:h()});return n.exitCode===0||Y(n.stderr,n.stdout)}catch(e){if(q(e))return!0;throw e}}async function K(){U??=_({source:`import Foundation
|
|
2
2
|
import AVFoundation
|
|
3
3
|
|
|
4
4
|
let url = URL(fileURLWithPath: CommandLine.arguments[1])
|
|
@@ -20,4 +20,4 @@ Task {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
semaphore.wait()
|
|
23
|
-
exit(exitCode)`,cacheName:`video-validator`,timeoutMs:3e4});try{return await
|
|
23
|
+
exit(exitCode)`,cacheName:`video-validator`,timeoutMs:3e4});try{return await U}catch(e){throw U=void 0,e}}function q(t){return t instanceof e?t.code===`TOOL_MISSING`||Y(String(t.details?.stderr??``),String(t.details?.stdout??``)):!1}async function J(e,t={}){let n=t.pollMs??150,r=t.attempts??12;for(let t=0;t<r;t+=1){if(await G(e))return;await i(n)}}function Y(e,t){let n=`${e}\n${t}`;return/\b(no such module ['"]AVFoundation['"]|unable to find utility ["']swiftc?["']|xcrun: error: unable to find utility ["']swiftc?["'])\b/i.test(n)}async function X(e){return await Z(e)!==void 0}async function Z(e){try{let t=c.statSync(e);if(!t.isFile()||t.size<=0)return}catch{return}return e.toLowerCase().endsWith(`.webm`)?T(e)?`webm`:void 0:await Q(e)?`mp4`:void 0}async function Q(e){let{findMp4Atom:t}=await import(`./mp4-atoms.js`).then(e=>e.n);return t(e,[`ftyp`])!==void 0&&t(e,[`moov`])!==void 0}export{W as a,m as c,J as i,G as n,h as o,Z as r,g as s,X as t};
|
package/dist/src/web2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{r as t}from"./interaction-positionals.js";import{c as n}from"./diagnostics.js";import"./diagnostics2.js";import{n as r}from"./src6.js";function i(t){let n=async n=>{throw new e(`UNSUPPORTED_OPERATION`,`${n} is not supported on ${t}`)};return{open:()=>n(`open`),openDevice:()=>n(`openDevice`),close:()=>n(`close`),tap:()=>n(`tap`),doubleTap:()=>n(`doubleTap`),longPress:()=>n(`longPress`),focus:()=>n(`focus`),type:()=>n(`type`),fill:()=>n(`fill`),scroll:()=>n(`scroll`),screenshot:()=>n(`screenshot`),snapshot:()=>n(`snapshot`),back:()=>n(`back`),home:()=>n(`home`),setOrientation:()=>n(`setOrientation`),appSwitcher:()=>n(`appSwitcher`),
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{r as t}from"./interaction-positionals.js";import{c as n}from"./diagnostics.js";import"./diagnostics2.js";import{n as r}from"./src6.js";function i(t){let n=async n=>{throw new e(`UNSUPPORTED_OPERATION`,`${n} is not supported on ${t}`)};return{open:()=>n(`open`),openDevice:()=>n(`openDevice`),close:()=>n(`close`),tap:()=>n(`tap`),doubleTap:()=>n(`doubleTap`),longPress:()=>n(`longPress`),focus:()=>n(`focus`),type:()=>n(`type`),fill:()=>n(`fill`),scroll:()=>n(`scroll`),screenshot:()=>n(`screenshot`),snapshot:()=>n(`snapshot`),back:()=>n(`back`),home:()=>n(`home`),setOrientation:()=>n(`setOrientation`),appSwitcher:()=>n(`appSwitcher`),tvRemote:()=>n(`tvRemote`),readClipboard:()=>n(`readClipboard`),writeClipboard:()=>n(`writeClipboard`),setSetting:()=>n(`setSetting`),readAlert:()=>n(`readAlert`),awaitAlert:()=>n(`awaitAlert`),acceptAlert:()=>n(`acceptAlert`),dismissAlert:()=>n(`dismissAlert`)}}async function a(a){let o=a??await r(),s=o.clickRef,c=o.hover,l=o.hoverRef,u=o.fillRef;return{...i(`web`),open:(e,t)=>o.open(t?.url??e,{url:t?.url}),openDevice:()=>o.open(`about:blank`),close:e=>o.close(e),tap:(e,t)=>o.click(e,t),...s?{tapRef:async e=>(await s(e),{ref:t(e)})}:{},...c?{hover:async(e,t)=>await c(e,t)}:{},...l?{hoverRef:async e=>(await l(e),{ref:t(e)})}:{},focus:(e,t)=>o.click(e,t),type:(e,t)=>o.typeText(e,{delayMs:t}),fill:(e,t,n,r)=>o.fill(e,t,n,{delayMs:r}),...u?{fillRef:async(e,n,r)=>(await u(e,n,{delayMs:r}),{ref:t(e),text:n,delayMs:r??0})}:{},scroll:(e,t)=>o.scroll(e,t),screenshot:(e,t)=>o.screenshot(e,t),setViewport:(e,t)=>o.setViewport(e,t),snapshot:async e=>{let t=await n(`snapshot_capture`,async()=>await o.snapshot(e),{backend:`web`});return{nodes:t.nodes,truncated:t.truncated??!1,backend:`web`,producer:`agent-browser`}},setOrientation:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`orientation is not supported on web`)}}}export{a as createWebInteractor};
|