agent-device 0.20.7 → 0.20.8
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.20.7.apk → agent-device-android-ime-helper-0.20.8.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.8.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.7.manifest.json → agent-device-android-ime-helper-0.20.8.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.7.apk → agent-device-android-snapshot-helper-0.20.8.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.8.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.7.manifest.json → agent-device-android-snapshot-helper-0.20.8.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +5 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift +4 -0
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +7 -7
- package/dist/src/app-lifecycle2.js +1 -1
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apps.js +5 -5
- package/dist/src/auth-session.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +1 -1
- package/dist/src/cli.js +4 -4
- package/dist/src/client-metro.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/debug-symbols.js +3 -3
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/device-ready.js +1 -0
- package/dist/src/dispatch.js +1 -0
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/handler-utils.js +1 -0
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/hdc.js +1 -0
- package/dist/src/helper.js +1 -1
- package/dist/src/host-process.js +3 -2
- package/dist/src/ime-lifecycle.js +5 -5
- package/dist/src/index.d.ts +21 -21
- package/dist/src/input-actions.js +4 -4
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-artifact.js +1 -1
- package/dist/src/interaction-runtime.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction-touch-reference-frame.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +1 -1
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +7 -29
- package/dist/src/inventory2.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/output-path.js +1 -0
- package/dist/src/owner-identity.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-network-web-transport.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-screen-recording-android-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -0
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-output-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-web-host.js +1 -0
- package/dist/src/platform-runtime-toolchain-host.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/prepare-kind.js +13 -13
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -0
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-telemetry.js +1 -0
- package/dist/src/registry.js +4 -4
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay.js +2 -2
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +3 -3
- package/dist/src/runtime3.js +3 -3
- package/dist/src/runtime4.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/screenshot-result.js +4 -4
- package/dist/src/sdk-android-adb.js +4 -4
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +5 -1
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +2 -2
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session.js +10 -10
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-session.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +2 -2
- package/dist/src/src3.js +1 -1
- package/dist/src/text-surface.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/video.js +23 -0
- package/dist/src/web.js +1 -1
- package/package.json +2 -4
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.7.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.7.apk.sha256 +0 -1
- package/dist/src/context.js +0 -1
- package/dist/src/provider.js +0 -1
- package/dist/src/runner-client.js +0 -1
- package/dist/src/runner-provider.js +0 -1
- package/skills/agent-device/SKILL.md +0 -20
- package/skills/dogfood/SKILL.md +0 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,_ as t,h as n,l as r,m as i,s as a,v as o}from"./sdk-contracts.js";import{x as s}from"./version.js";import{Jt as c,Kt as l,X as u,Yt as d,Zt as f,dt as p,it as m,jn as h,ln as ee,qt as te,sn as ne}from"./sdk-batch-runner.js";import{_ as re,c as ie,l as ae,s as oe}from"./sdk-device.js";import{J as se,X as ce,c as g,it as le,z as _}from"./prepare-kind.js";import{j as ue}from"./screenshot-result.js";import{i as de}from"./session-target-evidence.js";import{i as fe}from"./text-surface.js";import{a as pe,t as me}from"./runtime.js";import{A as v}from"./sdk-android-adb.js";import{r as he}from"./app-lifecycle.js";import{h as y}from"./ime-lifecycle.js";import{N as ge}from"./runner-disposal.js";import{D as _e,_ as ve,c as ye,l as be,n as xe,s as b,t as Se}from"./context.js";import{a as x}from"./runner-client.js";import{Gt as S,Ht as Ce,Kt as C,O as we,Wt as Te,en as w,in as T,sn as Ee,x as De}from"./internal/daemon.js";import{a as Oe,i as ke,r as Ae}from"./snapshot-session.js";const je=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function Me(e,t){let n=Ne(t);return n.length===0?null:b(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}function Ne(e){if(!e)return[];let t=[];for(let[n,r]of je)e[n]!==void 0&&t.push(r);return t}function Pe(e,t){if(!t||t.settle===!0)return null;let n=[];return t.settleQuietMs!==void 0&&n.push(`--settle-quiet`),n.length===0?null:b(`INVALID_ARGS`,`${e}: ${n.join(`, `)} require${n.length===1?`s`:``} --settle.`)}function Fe(e){if(e?.settle===!0)return{...e.settleQuietMs===void 0?{}:{quietMs:e.settleQuietMs},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}}function E(e){if(e.length<2)return null;let t=Number(e[0]),n=Number(e[1]);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function D(e){let t=n(e);return t?{ok:!0,ref:t.base,generation:t.generation}:{ok:!1,response:b(`INVALID_ARGS`,`Invalid ref "${e}" — malformed generation suffix.`,{hint:a})}}function O(e,t){let n=E(e);if(n)return{ok:!0,target:{kind:`point`,x:n.x,y:n.y}};let r=e[0]??``;if(r.startsWith(`@`)){let t=D(r);return t.ok?{ok:!0,target:{kind:`ref`,ref:t.ref,fallbackLabel:e.slice(1).join(` `).trim()},refGeneration:t.generation}:{ok:!1,response:t.response}}let i=e.join(` `).trim();return i?{ok:!0,target:{kind:`selector`,selector:i}}:{ok:!1,response:b(`INVALID_ARGS`,`${t} requires @ref, selector expression, or x y coordinates`)}}function Ie(e){let t=E(e);if(t)return{ok:!0,target:{kind:`point`,x:t.x,y:t.y},...Ue(e[2])};let n=He(e),r=O(n.targetPositionals,`longpress`);return r.ok?{ok:!0,target:r.target,refGeneration:r.refGeneration,...n.duration}:r}function Le(e){let t=e[0]??``;if(t.startsWith(`@`)){let n=D(t);if(!n.ok)return{ok:!1,response:n.response};let r=g(e).text;return r?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:Ve(e)},refGeneration:n.generation,text:r}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after ref`)}}let n=E(e);if(n){let t=e.slice(2).join(` `);return t?{ok:!0,target:{kind:`point`,x:n.x,y:n.y},text:t}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after coordinates`)}}let r=Re(e);return!r||r.kind!==`selector`?{ok:!1,response:b(`INVALID_ARGS`,`fill requires x y text, @ref text, or selector text`)}:r.text.trim()?{ok:!0,target:{kind:`selector`,selector:r.target.selector},text:r.text}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after selector`)}}function Re(e){try{return g(e)}catch{return null}}function ze(e){let t=`evidence`in e?e.evidence:void 0,n=e.settle;return e.kind===`ref`?{ref:k(e.target?.kind===`ref`?e.target.ref:void 0),refLabel:e.refLabel,selectorChain:e.selectorChain,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:e.kind===`selector`?{selector:e.target?.kind===`selector`?e.target.selector:void 0,selectorChain:e.selectorChain,refLabel:e.refLabel,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:{evidence:t,settle:n}}function Be(e,t){return e.kind===`point`?`coordinate tap`:t.kind===`ref`&&t.target?.kind===`ref`?t.target.ref:t.kind===`selector`&&t.target?.kind===`selector`?t.target.selector:`target`}function k(e){return e?.startsWith(`@`)?e.slice(1):e}function Ve(e){return e.length>=3&&e[1]?.trim()||``}function He(e){let t=e.at(-1);return e.length>1&&We(t)?{targetPositionals:e.slice(0,-1),duration:{durationMs:Number(t)}}:{targetPositionals:e,duration:{}}}function Ue(e){return e===void 0?{}:{durationMs:Number(e)}}function We(e){return e===void 0||e.trim()===``?!1:Number.isFinite(Number(e))}function A(e,t){return!(!e||!ie(e.device)||_e(e.device)||t.skipPendingPostGestureStabilization&&T(e))}function j(e){let{session:t,selectorExpression:n}=e;return A(t,{skipPendingPostGestureStabilization:!0})?p(n):null}function Ge(e){let t=e.identifier?.trim();if(t)return{key:`id`,value:t};let n=e.label?.trim();return n?{key:`label`,value:n}:null}function M(e,t={}){let n=o(e);if(n.code===`ELEMENT_NOT_FOUND`)return t.delegateSemanticFailures===!0||t.allowElementNotFound===!0;if(n.code===`AMBIGUOUS_MATCH`)return t.delegateSemanticFailures===!0;if(n.code===`ELEMENT_OFFSCREEN`)return t.delegateSemanticFailures!==!1;if(n.code!==`COMMAND_FAILED`)return!1;let r=n.message.toLowerCase();return r.includes(`fetch failed`)||r.includes(`timed out`)||r.includes(`timeout`)||r.includes(`runner did not accept connection`)||r.includes(`invalid runner response`)}async function Ke(e,n){let r=await N(e);if(r){if(y(r.foregroundPackage))return`press ${n} opened an Android permission dialog (${r.foregroundPackage}) over ${r.expectedPackage}. ${r.hint}`;throw new t(`COMMAND_FAILED`,`press ${n} left ${e.appBundleId} and foregrounded ${r.foregroundPackage}. The tap likely escaped the app.`,r)}}async function N(e){if(e.device.platform!==`android`||!e.appBundleId)return null;let t=await he(e.device),n=t.package?.trim();return!n||n===e.appBundleId||!Xe(n)?null:{expectedPackage:e.appBundleId,foregroundPackage:n,activity:t.activity,hint:Ye(n)}}function qe(e){return y(e.foregroundPackage)?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Je(e){return e.code===`COMMAND_FAILED`&&typeof e.details?.expectedPackage==`string`&&typeof e.details?.foregroundPackage==`string`}function Ye(e){return y(e)?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function Xe(e){return e===`com.android.settings`||e===`com.android.systemui`||y(e)||e.includes(`launcher`)}function Ze(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function Qe(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:u(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:u(e.node)}}function P(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=tt(e),i=r?.kind===`ref`?z(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:et(s)}}function F(e){let{target:t}=e;return{...t.kind===`ref`?{ref:z(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:u(e.node)}}function I(e){let{node:t,preActionNodes:n,...r}=e;return r}function $e(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function L(e){let{selectorChain:t,...n}=e;return n}function R(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=o.recordSession&&i?de(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:ue(n),...s?{targetEvidence:s}:{}})}function et(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function tt(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function z(e){return e.startsWith(`@`)?e.slice(1):e}const nt=[`application`,`window`,`tabbar`,`scrollbar`,`image`],rt=new Set([`tab bar`]);async function B(e,t){if(t.ok||!it(t.error.details?.reason)||t.error.details?.captureStalled===!0||t.error.details?.captureTruncated===!0)return t;let n=await at(e).catch(()=>null);return n?b(t.error.code,`${t.error.message}. Current surface: ${n.summary}.`,{...t.error.details??{},currentSurface:n.details}):t}function it(e){return e===s.targetAbsent||e===s.stableTimeout}async function at(e){let t=[...(await w({device:e.device,session:e.session,flags:{...e.req.flags,snapshotInteractiveOnly:!0},logPath:e.logPath??``})).snapshot.nodes].sort(ot),n=V(t,6,{includeIdentifiers:!0});if(n.length===0)return null;let r=V(t.filter(e=>!U(e)),4,{includeIdentifiers:!1}),i=V(t.filter(lt),4,{includeIdentifiers:!0});return{summary:(r.length>0?r:n.slice(0,4)).join(`, `),details:{labels:n,...i.length>0?{buttons:i}:{}}}}function V(e,t,n){let r=new Set,i=[];for(let a of e){let e=ct(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function ot(e,t){return H(e)-H(t)||st(e,t)}function H(e){let t=!!ct(e,{includeIdentifiers:!1});return(U(e)?2:0)+ +!t}function st(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 ct(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.replace(/\s+/g,` `).slice(0,80):``}function U(e){let t=h(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return nt.some(e=>t.includes(e))||rt.has(n)||n.endsWith(`.fill`)}function lt(e){return h(`${e.type??``} ${e.role??``} ${e.subrole??``}`).includes(`button`)}function W(e,t){let n=pe(t);if(!n)return e;if(e.ok){let t=G(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:G(r.hint,n)}}}}function G(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function ut(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:o,contextFromFlags:s}=e,c=se(n),l=le(n.rect);if(!l||ie(t)&&c&&!fe(n.type??``))return c;try{let e=await xe(t,`read`,[String(l.x),String(l.y)],void 0,{...s(r,i,a),surface:o}),u=e&&typeof e==`object`?e:void 0,d=typeof u?.text==`string`?u.text:``;return d.trim()?d:(v({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`empty_backend_text`,nodeRef:n.ref,surface:o,platform:t.platform}}),c)}catch(e){return v({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`backend_read_failed`,nodeRef:n.ref,surface:o,platform:t.platform,error:e instanceof Error?e.message:String(e)}}),c}}function K(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=yt(c,e.req.flags?.out),d=mt({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=ht({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await dt({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return xt({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function dt(e){let{params:t,request:n}=e,r=await q(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&St(r)?await ft({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&_(r.snapshotQuality)?await pt({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function ft(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await q(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await q(t,n,r.query,!1)}}async function pt(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await q(t,n,r.query,!1)}catch{return i}}async function q(e,t,n,r=t.flags?.snapshotInteractiveOnly){return(await w({device:e.device,session:e.session,flags:{...t.flags,snapshotInteractiveOnly:r},outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal})).snapshot}function mt(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!Ee(a)&&!J(a,o))return r}function ht(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&>(t,r)&&_t(i,n)&&i.presentationKey===vt(r))return i}function gt(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||Ee(e)||J(e,t))}function _t(e,t){return t-e.createdAt<750}function J(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&T(e)}function vt(e){return r(i(bt(e)))}function yt(e,t){return JSON.stringify({presentationKey:vt(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function bt(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function xt(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||_(i.snapshotQuality)||(C(t,i),n.set(r,t))}function St(e){return e.snapshotQuality||e.backend!==`xctest`||e.nodes.length!==1?!1:e.nodes[0]?.type===`Application`}function Ct(e){return me({backend:wt(e),...Oe(`selector commands`,{plural:!0}),sessions:Ce({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(C(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??ge(e.req.meta?.requestId)})}async function Y(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);if(!n&&t.requireSession)return{ok:!1,response:ye()};let r=n?.device??await ve(e.req.flags??{});n||await we(r);let i=be(t.capability,r);return i?{ok:!1,response:i}:{ok:!0,runtime:Ct({...e,session:n,device:r})}}function wt(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,s=K({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i});return{platform:re(r),captureSnapshot:async(e,n)=>{let i={...t.flags,...Tt(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,c=t.command===`wait`||t.command===`find`||a&&r.platform===`web`;return await s.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:c,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})},readText:async(a,o)=>({text:await ut({device:r,node:o,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:e.contextFromFlags??((e,t,n)=>Se(i??``,e,t,n))})}),findText:async(t,n)=>({found:await Et(e,n,t.signal)})}}function Tt(e){let{interactiveOnly:t,scope:n,depth:r,raw:i,includeHiddenContentHints:a}=e??{},o={};return t!==void 0&&(o.snapshotInteractiveOnly=t),n!==void 0&&(o.snapshotScope=n),r!==void 0&&(o.snapshotDepth=r),i!==void 0&&(o.snapshotRaw=i),a!==void 0&&(o.snapshotIncludeHiddenContentHints=a),o}async function Et(e,t,n){let r=await Dt(e,t,n);return r===null?await Ot(e,t,n)===!0?!0:await jt(e,t,n):r}async function Dt(e,t,n){return!ae(e.device)||!e.session?.surface||e.session.surface===`app`?null:await jt(e,t,n)}async function Ot(e,t,n){let r=kt(e);return r?(await x(r.device,{command:`findText`,text:t,appBundleId:r.appBundleId},{...At(e,r),signal:n}))?.found===!0:null}function kt(e){return!oe(e.device.platform)||_e(e.device)||!e.session?.appBundleId?null:{device:e.device,appBundleId:e.session.appBundleId,traceLogPath:e.session.trace?.outPath}}function At(e,t){return De({req:e.req,logPath:e.logPath,traceLogPath:t.traceLogPath})}async function jt(e,t,n){return!!ce((await Mt(e,n)).nodes,t)}async function Mt(e,t){let{snapshot:n}=await K({device:e.device,session:e.session,sessionStore:e.sessionStore,sessionName:e.sessionName,req:e.req,logPath:e.logPath,consumedSnapshot:e.consumedSnapshot}).capture({flags:{...e.req.flags,snapshotInteractiveOnly:!1,snapshotIncludeHiddenContentHints:!1},signal:t,cache:{forceFresh:!0,bypassForPostGestureStabilization:!0}});return n}async function Nt(e){let{req:t}=e;if(t.command!==`find`)return null;let n=ne(t.positionals??[],t.flags);if(!n.ok)return b(n.code,n.message);let r=n.parsed,i=r.action;if(!ee(i))return null;let a=await Y(e,{requireSession:!1,capability:`find`});return a.ok?W(await $(async()=>{let n=await a.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:r.locator,query:r.query,action:i,timeoutMs:r.timeoutMs});R(e.sessionStore,e.sessionName,t,Ze(n,i));let o=Qe(n),s=typeof o.ref==`string`?[o.ref]:Array.isArray(o.matches)?o.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(Te(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...o,refsGeneration:t.snapshotGeneration}}return o}),X(e)):a.response}function X(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function Pt(e){let{req:t}=e;if(t.command!==`get`)return null;let n=te(t.positionals?.[0]);if(!n.ok)return b(n.code,n.message);let r=n.format,i=qt(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=Me(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard;if(i.target.kind===`selector`&&!a){let t=await zt(e,r,i.target.selector);if(t)return t}let o=await Y(e,{requireSession:!0,capability:`get`});if(!o.ok)return o.response;let s=i.target.kind===`ref`?S({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return W(await $(async()=>{let n=await o.runtime.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});R(e.sessionStore,e.sessionName,t,P(n,r),{node:n.node,preActionNodes:n.preActionNodes});let c=F(n);return s?{...c,warning:s}:c}),X(e))}async function Ft(e){let{req:t}=e;if(t.command!==`is`)return null;let n=c(t.positionals??[]);if(!n.ok)return b(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,expectedText:i}=n,a={selectorExpression:n.selectorExpression},o=t.internal?.replayTargetGuard,s=e.sessionStore.get(e.sessionName)?.recordSession===!0;if(!o&&!s){let t=await Bt(e,r,a.selectorExpression,i);if(t)return t}let l=await Y(e,{requireSession:!0,capability:`is`});return l.ok?W(await Yt(e,await $(async()=>{let n=await l.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:a.selectorExpression,expectedText:i,expectedResolvedTarget:o}),s=Lt(n),c=I(n);return R(e.sessionStore,e.sessionName,t,c,s),L(c)}),`is ${r}`),X(e)):l.response}async function It(e){let{req:t,sessionName:n,sessionStore:r}=e,i=m(t.positionals??[]);if(!i)return b(`INVALID_ARGS`,`wait requires a duration or text`);let{session:a,device:o}=await Ae(r,n,t.flags);if(i.kind!==`sleep`){let e=be(`wait`,o);if(e)return e}let s=t.internal?.replayLandmarkGuard;if(i.kind===`selector`&&!s&&!a?.recordSession){let t=await Vt({...e,session:a,device:o,selectorExpression:i.selectorExpression,timeoutMs:i.timeoutMs});if(t)return t}let c=i,l;if(i.kind===`ref`){let e=D(i.rawRef);if(!e.ok)return e.response;c={...i,rawRef:e.ref},l=S({session:a,ref:e.ref,mintedGeneration:e.generation})}e.consumedSnapshot??={};let u=async()=>{let i=Ct({...e,session:a,device:o}),u=await $(async()=>{let e=await i.selectors.wait({session:n,requestId:t.meta?.requestId,target:Jt(c,a,s)}),o=Lt(e);R(r,n,t,I(e),o,`landmark`);let u=$e(e);return l?{...u,warning:l}:u});return await Yt(e,await B({req:t,logPath:e.logPath,session:a,device:o},u),`wait`)};return i.kind===`sleep`?await u():W(await ke(a,o,u),X(e))}function Lt(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function Rt(e,t,n){if(!e||e.recordSession)return null;let r=j({session:e,selectorExpression:n});return t===`text`&&r?.key!==`id`?null:r}async function zt(e,t,n){let r=e.sessionStore.get(e.sessionName),i=Rt(r,t,n);if(!r||!i)return null;let a=await Z(e,r,i);if(Q(a))return a.response;if(!a)return null;let o=Wt(t,i.raw,a);return o?(R(e.sessionStore,e.sessionName,e.req,P(o,t)),{ok:!0,data:F(o)}):null}async function Bt(e,t,n,r){if(t===`hidden`)return null;let i=await Ht(e,n);if(Q(i))return i.response;if(!i?.result.found||!i.result.node)return null;let a=t===`exists`?{predicate:t,pass:!0,selector:i.selector.raw,matches:1,selectorChain:[i.selector.raw]}:Gt(t,r,i.selector.raw,i.session,i.result.node);return a?(R(e.sessionStore,e.sessionName,e.req,a),{ok:!0,data:L(a)}):null}async function Vt(e){let t=j({session:e.session,selectorExpression:e.selectorExpression});if(!e.session||!t)return null;let n=Date.now(),r=await Z(e,e.session,t);if(Q(r))return r.response;if(!r?.found)return null;let i={kind:`selector`,selector:t.raw,waitedMs:Date.now()-n,selectorChain:[t.raw]};R(e.sessionStore,e.sessionName,e.req,i);let a={ok:!0,data:L(i)};return await B({req:e.req,logPath:e.logPath,session:e.session,device:e.device},a)}async function Ht(e,t){let n=e.sessionStore.get(e.sessionName),r=j({session:n,selectorExpression:t});if(!n||!r)return null;let i=await Z(e,n,r);return Q(i)?i:i?{session:n,selector:r,result:i}:null}async function Ut(e,t,n){let r=await x(e.device,{command:`querySelector`,selectorKey:t.key,selectorValue:t.value,appBundleId:e.appBundleId},n),i=r.found===!0,a=Kt(r);return{found:i,...typeof r.text==`string`?{text:r.text}:{},...a?{node:a}:{}}}async function Z(t,n,r){try{return await Ut(n,r,De({req:t.req,logPath:t.logPath,traceLogPath:n.trace?.outPath}))}catch(t){return M(t,{allowElementNotFound:!0})?null:{kind:`error`,response:{ok:!1,error:e(t)}}}}function Q(e){return e!==null&&`kind`in e&&e.kind===`error`}function Wt(e,t,n){if(!n.found||!n.node)return null;let r={target:{kind:`selector`,selector:t},node:n.node,selectorChain:[t]};return e===`attrs`?{kind:`attrs`,...r}:typeof n.text==`string`?{kind:`text`,...r,text:n.text}:null}function Gt(e,t,n,r,i){let a=f({predicate:e,node:i,nodes:[i],expectedText:t,platform:r.device.platform});return{predicate:e,pass:a.pass,selector:n,...e===`text`?{text:a.actualText}:{},selectorChain:[n]}}function Kt(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!(!n||typeof n!=`object`))return n}function qt(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=D(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=l(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:b(n.code,n.message)}}function Jt(e,n,r){if(e.kind===`sleep`)return{kind:`sleep`,durationMs:e.durationMs};if(e.kind===`selector`)return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...r?{recordedLandmark:r}:{}};if(e.kind===`ref`){if(!n?.snapshot)throw new t(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:e.rawRef,timeoutMs:e.timeoutMs}}if(e.kind===`stable`)return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};let i=d(e.text);if(!i.ok)throw new t(i.code,i.message);return{kind:`text`,text:i.text,timeoutMs:e.timeoutMs}}async function $(e){try{return{ok:!0,data:await e()}}catch(e){let t=o(e);return b(t.code,t.message,t.details)}}async function Yt(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{i=await N(r)}catch{return t}return i?b(t.error.code,`${n} failed because ${qe(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{Pe as S,Ie as _,Ut as a,Fe as b,Ke as c,M as d,A as f,Le as g,ze as h,It as i,Je as l,Be as m,Pt as n,K as o,j as p,Ft as r,W as s,Nt as t,Ge as u,O as v,Me as x,k as y};
|
|
1
|
+
import{S as e,_ as t,h as n,l as r,m as i,s as a,v as o}from"./sdk-contracts.js";import{x as s}from"./version.js";import{Jt as c,Kt as l,Mn as u,Yt as d,Zt as f,cn as p,ct as m,et as h,mt as ee,qt as te,un as ne}from"./sdk-batch-runner.js";import{_ as re,c as g,l as ie,s as ae}from"./sdk-device.js";import{J as oe,X as se,c as ce,it as le,z as ue}from"./prepare-kind.js";import{X as _,j as de}from"./screenshot-result.js";import{i as fe}from"./session-target-evidence.js";import{i as pe}from"./text-surface.js";import{a as me,t as he}from"./runtime.js";import{j as ge}from"./sdk-android-adb.js";import{r as _e}from"./app-lifecycle.js";import{h as v}from"./ime-lifecycle.js";import{N as ve}from"./runner-disposal.js";import{E as y,c as b,g as ye,o as x,s as be,t as xe}from"./dispatch.js";import{Xt as S,Yt as Se,Zt as C,an as w,ct as T,fn as Ce,ln as E,pn as D,qt as we}from"./internal/daemon.js";import{a as O,i as Te,l as Ee,r as De}from"./snapshot-session.js";import{t as Oe}from"./device-ready.js";const ke=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function k(e,t){let n=Ae(t);return n.length===0?null:x(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}function Ae(e){if(!e)return[];let t=[];for(let[n,r]of ke)e[n]!==void 0&&t.push(r);return t}function je(e,t){if(!t||t.settle===!0)return null;let n=[];return t.settleQuietMs!==void 0&&n.push(`--settle-quiet`),n.length===0?null:x(`INVALID_ARGS`,`${e}: ${n.join(`, `)} require${n.length===1?`s`:``} --settle.`)}function Me(e){if(e?.settle===!0)return{...e.settleQuietMs===void 0?{}:{quietMs:e.settleQuietMs},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}}function A(e){if(e.length<2)return null;let t=Number(e[0]),n=Number(e[1]);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function j(e){let t=n(e);return t?{ok:!0,ref:t.base,generation:t.generation}:{ok:!1,response:x(`INVALID_ARGS`,`Invalid ref "${e}" — malformed generation suffix.`,{hint:a})}}function M(e,t){let n=A(e);if(n)return{ok:!0,target:{kind:`point`,x:n.x,y:n.y}};let r=e[0]??``;if(r.startsWith(`@`)){let t=j(r);return t.ok?{ok:!0,target:{kind:`ref`,ref:t.ref,fallbackLabel:e.slice(1).join(` `).trim()},refGeneration:t.generation}:{ok:!1,response:t.response}}let i=e.join(` `).trim();return i?{ok:!0,target:{kind:`selector`,selector:i}}:{ok:!1,response:x(`INVALID_ARGS`,`${t} requires @ref, selector expression, or x y coordinates`)}}function Ne(e){let t=A(e);if(t)return{ok:!0,target:{kind:`point`,x:t.x,y:t.y},...Be(e[2])};let n=ze(e),r=M(n.targetPositionals,`longpress`);return r.ok?{ok:!0,target:r.target,refGeneration:r.refGeneration,...n.duration}:r}function Pe(e){let t=e[0]??``;if(t.startsWith(`@`)){let n=j(t);if(!n.ok)return{ok:!1,response:n.response};let r=ce(e).text;return r?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:Re(e)},refGeneration:n.generation,text:r}:{ok:!1,response:x(`INVALID_ARGS`,`fill requires text after ref`)}}let n=A(e);if(n){let t=e.slice(2).join(` `);return t?{ok:!0,target:{kind:`point`,x:n.x,y:n.y},text:t}:{ok:!1,response:x(`INVALID_ARGS`,`fill requires text after coordinates`)}}let r=Fe(e);return!r||r.kind!==`selector`?{ok:!1,response:x(`INVALID_ARGS`,`fill requires x y text, @ref text, or selector text`)}:r.text.trim()?{ok:!0,target:{kind:`selector`,selector:r.target.selector},text:r.text}:{ok:!1,response:x(`INVALID_ARGS`,`fill requires text after selector`)}}function Fe(e){try{return ce(e)}catch{return null}}function Ie(e){let t=`evidence`in e?e.evidence:void 0,n=e.settle;return e.kind===`ref`?{ref:N(e.target?.kind===`ref`?e.target.ref:void 0),refLabel:e.refLabel,selectorChain:e.selectorChain,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:e.kind===`selector`?{selector:e.target?.kind===`selector`?e.target.selector:void 0,selectorChain:e.selectorChain,refLabel:e.refLabel,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:{evidence:t,settle:n}}function Le(e,t){return e.kind===`point`?`coordinate tap`:t.kind===`ref`&&t.target?.kind===`ref`?t.target.ref:t.kind===`selector`&&t.target?.kind===`selector`?t.target.selector:`target`}function N(e){return e?.startsWith(`@`)?e.slice(1):e}function Re(e){return e.length>=3&&e[1]?.trim()||``}function ze(e){let t=e.at(-1);return e.length>1&&Ve(t)?{targetPositionals:e.slice(0,-1),duration:{durationMs:Number(t)}}:{targetPositionals:e,duration:{}}}function Be(e){return e===void 0?{}:{durationMs:Number(e)}}function Ve(e){return e===void 0||e.trim()===``?!1:Number.isFinite(Number(e))}function P(e,t){return!(!e||!g(e.device)||y(e.device)||t.skipPendingPostGestureStabilization&&E(e))}function F(e){let{session:t,selectorExpression:n}=e;return P(t,{skipPendingPostGestureStabilization:!0})?ee(n):null}function He(e){let t=e.identifier?.trim();if(t)return{key:`id`,value:t};let n=e.label?.trim();return n?{key:`label`,value:n}:null}function I(e,t={}){let n=o(e);if(n.code===`ELEMENT_NOT_FOUND`)return t.delegateSemanticFailures===!0||t.allowElementNotFound===!0;if(n.code===`AMBIGUOUS_MATCH`)return t.delegateSemanticFailures===!0;if(n.code===`ELEMENT_OFFSCREEN`)return t.delegateSemanticFailures!==!1;if(n.code!==`COMMAND_FAILED`)return!1;let r=n.message.toLowerCase();return r.includes(`fetch failed`)||r.includes(`timed out`)||r.includes(`timeout`)||r.includes(`runner did not accept connection`)||r.includes(`invalid runner response`)}async function Ue(e,n){let r=await L(e);if(r){if(v(r.foregroundPackage))return`press ${n} opened an Android permission dialog (${r.foregroundPackage}) over ${r.expectedPackage}. ${r.hint}`;throw new t(`COMMAND_FAILED`,`press ${n} left ${e.appBundleId} and foregrounded ${r.foregroundPackage}. The tap likely escaped the app.`,r)}}async function L(e){if(e.device.platform!==`android`||!e.appBundleId)return null;let t=await _e(e.device),n=t.package?.trim();return!n||n===e.appBundleId||!qe(n)?null:{expectedPackage:e.appBundleId,foregroundPackage:n,activity:t.activity,hint:Ke(n)}}function We(e){return v(e.foregroundPackage)?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Ge(e){return e.code===`COMMAND_FAILED`&&typeof e.details?.expectedPackage==`string`&&typeof e.details?.foregroundPackage==`string`}function Ke(e){return v(e)?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function qe(e){return e===`com.android.settings`||e===`com.android.systemui`||v(e)||e.includes(`launcher`)}function Je(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function Ye(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:h(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:h(e.node)}}function Xe(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=$e(e),i=r?.kind===`ref`?H(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:Qe(s)}}function R(e){let{target:t}=e;return{...t.kind===`ref`?{ref:H(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:h(e.node)}}function z(e){let{node:t,preActionNodes:n,...r}=e;return r}function Ze(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function B(e){let{selectorChain:t,...n}=e;return n}function V(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=_(o)&&i?fe(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:de(n),...s?{targetEvidence:s}:{}})}function Qe(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function $e(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function H(e){return e.startsWith(`@`)?e.slice(1):e}const et=[`application`,`window`,`tabbar`,`scrollbar`,`image`],tt=new Set([`tab bar`]);async function U(e,t){if(t.ok||!nt(t.error.details?.reason)||t.error.details?.captureStalled===!0||t.error.details?.captureTruncated===!0)return t;let n=await rt(e).catch(()=>null);return n?x(t.error.code,`${t.error.message}. Current surface: ${n.summary}.`,{...t.error.details??{},currentSurface:n.details}):t}function nt(e){return e===s.targetAbsent||e===s.stableTimeout}async function rt(e){let t=[...(await w({device:e.device,session:e.session,flags:{...e.req.flags,snapshotInteractiveOnly:!0},logPath:e.logPath??``})).snapshot.nodes].sort(it),n=W(t,6,{includeIdentifiers:!0});if(n.length===0)return null;let r=W(t.filter(e=>!ct(e)),4,{includeIdentifiers:!1}),i=W(t.filter(lt),4,{includeIdentifiers:!0});return{summary:(r.length>0?r:n.slice(0,4)).join(`, `),details:{labels:n,...i.length>0?{buttons:i}:{}}}}function W(e,t,n){let r=new Set,i=[];for(let a of e){let e=st(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function it(e,t){return at(e)-at(t)||ot(e,t)}function at(e){let t=!!st(e,{includeIdentifiers:!1});return(ct(e)?2:0)+ +!t}function ot(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 st(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.replace(/\s+/g,` `).slice(0,80):``}function ct(e){let t=u(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return et.some(e=>t.includes(e))||tt.has(n)||n.endsWith(`.fill`)}function lt(e){return u(`${e.type??``} ${e.role??``} ${e.subrole??``}`).includes(`button`)}function G(e,t){let n=me(t);if(!n)return e;if(e.ok){let t=ut(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:ut(r.hint,n)}}}}function ut(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function dt(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:o,contextFromFlags:s}=e,c=oe(n),l=le(n.rect);if(!l||g(t)&&c&&!pe(n.type??``))return c;try{let e=await xe(t,`read`,[String(l.x),String(l.y)],void 0,{...s(r,i,a),surface:o}),u=e&&typeof e==`object`?e:void 0,d=typeof u?.text==`string`?u.text:``;return d.trim()?d:(ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`empty_backend_text`,nodeRef:n.ref,surface:o,platform:t.platform}}),c)}catch(e){return ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`backend_read_failed`,nodeRef:n.ref,surface:o,platform:t.platform,error:e instanceof Error?e.message:String(e)}}),c}}function K(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=xt(c,e.req.flags?.out),d=ht({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=gt({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await ft({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return Ct({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function ft(e){let{params:t,request:n}=e,r=await q(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&wt(r)?await pt({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&ue(r.snapshotQuality)?await mt({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function pt(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await q(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await q(t,n,r.query,!1)}}async function mt(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await q(t,n,r.query,!1)}catch{return i}}async function q(e,t,n,r=t.flags?.snapshotInteractiveOnly){return(await w({device:e.device,session:e.session,flags:{...t.flags,snapshotInteractiveOnly:r},outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal})).snapshot}function ht(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!D(a)&&!yt(a,o))return r}function gt(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&&_t(t,r)&&vt(i,n)&&i.presentationKey===bt(r))return i}function _t(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||D(e)||yt(e,t))}function vt(e,t){return t-e.createdAt<750}function yt(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&E(e)}function bt(e){return r(i(St(e)))}function xt(e,t){return JSON.stringify({presentationKey:bt(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function St(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function Ct(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||ue(i.snapshotQuality)||(C(t,i),n.set(r,t))}function wt(e){return e.snapshotQuality||e.backend!==`xctest`||e.nodes.length!==1?!1:e.nodes[0]?.type===`Application`}function Tt(e){return he({backend:Et(e),...Ee(`selector commands`,{plural:!0}),sessions:we({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(C(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??ve(e.req.meta?.requestId)})}async function J(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);if(!n&&t.requireSession)return{ok:!1,response:be()};let r=n?.device??await ye(e.req.flags??{});n||await Oe(r);let i=b(t.capability,r);return i?{ok:!1,response:i}:{ok:!0,runtime:Tt({...e,session:n,device:r})}}function Et(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,s=K({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i});return{platform:re(r),captureSnapshot:async(e,n)=>{let i={...t.flags,...Dt(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,c=t.command===`wait`||t.command===`find`||a&&r.platform===`web`;return await s.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:c,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})},readText:async(a,o)=>({text:await dt({device:r,node:o,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:e.contextFromFlags??((e,t,n)=>Ce(i??``,e,t,n))})}),findText:async(t,n)=>({found:await Ot(e,n,t.signal)})}}function Dt(e){let{interactiveOnly:t,scope:n,depth:r,raw:i,includeHiddenContentHints:a}=e??{},o={};return t!==void 0&&(o.snapshotInteractiveOnly=t),n!==void 0&&(o.snapshotScope=n),r!==void 0&&(o.snapshotDepth=r),i!==void 0&&(o.snapshotRaw=i),a!==void 0&&(o.snapshotIncludeHiddenContentHints=a),o}async function Ot(e,t,n){let r=await kt(e,t,n);return r===null?await At(e,t,n)===!0?!0:await Nt(e,t,n):r}async function kt(e,t,n){return!ie(e.device)||!e.session?.surface||e.session.surface===`app`?null:await Nt(e,t,n)}async function At(e,t,n){let r=jt(e);return r?(await T(r.device,{command:`findText`,text:t,appBundleId:r.appBundleId},{...Mt(e,r),signal:n}))?.found===!0:null}function jt(e){return!ae(e.device.platform)||y(e.device)||!e.session?.appBundleId?null:{device:e.device,appBundleId:e.session.appBundleId,traceLogPath:e.session.trace?.outPath}}function Mt(e,t){return O({req:e.req,logPath:e.logPath,traceLogPath:t.traceLogPath})}async function Nt(e,t,n){return!!se((await Pt(e,n)).nodes,t)}async function Pt(e,t){let{snapshot:n}=await K({device:e.device,session:e.session,sessionStore:e.sessionStore,sessionName:e.sessionName,req:e.req,logPath:e.logPath,consumedSnapshot:e.consumedSnapshot}).capture({flags:{...e.req.flags,snapshotInteractiveOnly:!1,snapshotIncludeHiddenContentHints:!1},signal:t,cache:{forceFresh:!0,bypassForPostGestureStabilization:!0}});return n}async function Ft(e){let{req:t}=e;if(t.command!==`find`)return null;let n=p(t.positionals??[],t.flags);if(!n.ok)return x(n.code,n.message);let r=n.parsed,i=r.action;if(!ne(i))return null;let a=await J(e,{requireSession:!1,capability:`find`});return a.ok?G(await Q(async()=>{let n=await a.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:r.locator,query:r.query,action:i,timeoutMs:r.timeoutMs});V(e.sessionStore,e.sessionName,t,Je(n,i));let o=Ye(n),s=typeof o.ref==`string`?[o.ref]:Array.isArray(o.matches)?o.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(Se(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...o,refsGeneration:t.snapshotGeneration}}return o}),Y(e)):a.response}function Y(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function It(e){let{req:t}=e;if(t.command!==`get`)return null;let n=te(t.positionals?.[0]);if(!n.ok)return x(n.code,n.message);let r=n.format,i=Yt(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=k(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard;if(i.target.kind===`selector`&&!a){let t=await Vt(e,r,i.target.selector);if(t)return t}let o=await J(e,{requireSession:!0,capability:`get`});if(!o.ok)return o.response;let s=i.target.kind===`ref`?S({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return G(await Q(async()=>{let n=await o.runtime.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});V(e.sessionStore,e.sessionName,t,Xe(n,r),{node:n.node,preActionNodes:n.preActionNodes});let c=R(n);return s?{...c,warning:s}:c}),Y(e))}async function Lt(e){let{req:t}=e;if(t.command!==`is`)return null;let n=c(t.positionals??[]);if(!n.ok)return x(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,expectedText:i}=n,a={selectorExpression:n.selectorExpression},o=t.internal?.replayTargetGuard,s=_(e.sessionStore.get(e.sessionName));if(!o&&!s){let t=await Ht(e,r,a.selectorExpression,i);if(t)return t}let l=await J(e,{requireSession:!0,capability:`is`});return l.ok?G(await $(e,await Q(async()=>{let n=await l.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:a.selectorExpression,expectedText:i,expectedResolvedTarget:o}),s=zt(n),c=z(n);return V(e.sessionStore,e.sessionName,t,c,s),B(c)}),`is ${r}`),Y(e)):l.response}async function Rt(e){let{req:t,sessionName:n,sessionStore:r}=e,i=m(t.positionals??[]);if(!i)return x(`INVALID_ARGS`,`wait requires a duration or text`);let{session:a,device:o}=await De(r,n,t.flags);if(i.kind!==`sleep`){let e=b(`wait`,o);if(e)return e}let s=t.internal?.replayLandmarkGuard;if(i.kind===`selector`&&!s&&!_(a)){let t=await Ut({...e,session:a,device:o,selectorExpression:i.selectorExpression,timeoutMs:i.timeoutMs});if(t)return t}let c=i,l;if(i.kind===`ref`){let e=j(i.rawRef);if(!e.ok)return e.response;c={...i,rawRef:e.ref},l=S({session:a,ref:e.ref,mintedGeneration:e.generation})}e.consumedSnapshot??={};let u=async()=>{let i=Tt({...e,session:a,device:o}),u=await Q(async()=>{let e=await i.selectors.wait({session:n,requestId:t.meta?.requestId,target:Xt(c,a,s)}),o=zt(e);V(r,n,t,z(e),o,`landmark`);let u=Ze(e);return l?{...u,warning:l}:u});return await $(e,await U({req:t,logPath:e.logPath,session:a,device:o},u),`wait`)};return i.kind===`sleep`?await u():G(await Te(a,o,u),Y(e))}function zt(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function Bt(e,t,n){if(!e||_(e))return null;let r=F({session:e,selectorExpression:n});return t===`text`&&r?.key!==`id`?null:r}async function Vt(e,t,n){let r=e.sessionStore.get(e.sessionName),i=Bt(r,t,n);if(!r||!i)return null;let a=await X(e,r,i);if(Z(a))return a.response;if(!a)return null;let o=Kt(t,i.raw,a);return o?(V(e.sessionStore,e.sessionName,e.req,Xe(o,t)),{ok:!0,data:R(o)}):null}async function Ht(e,t,n,r){if(t===`hidden`)return null;let i=await Wt(e,n);if(Z(i))return i.response;if(!i?.result.found||!i.result.node)return null;let a=t===`exists`?{predicate:t,pass:!0,selector:i.selector.raw,matches:1,selectorChain:[i.selector.raw]}:qt(t,r,i.selector.raw,i.session,i.result.node);return a?(V(e.sessionStore,e.sessionName,e.req,a),{ok:!0,data:B(a)}):null}async function Ut(e){let t=F({session:e.session,selectorExpression:e.selectorExpression});if(!e.session||!t)return null;let n=Date.now(),r=await X(e,e.session,t);if(Z(r))return r.response;if(!r?.found)return null;let i={kind:`selector`,selector:t.raw,waitedMs:Date.now()-n,selectorChain:[t.raw]};V(e.sessionStore,e.sessionName,e.req,i);let a={ok:!0,data:B(i)};return await U({req:e.req,logPath:e.logPath,session:e.session,device:e.device},a)}async function Wt(e,t){let n=e.sessionStore.get(e.sessionName),r=F({session:n,selectorExpression:t});if(!n||!r)return null;let i=await X(e,n,r);return Z(i)?i:i?{session:n,selector:r,result:i}:null}async function Gt(e,t,n){let r=await T(e.device,{command:`querySelector`,selectorKey:t.key,selectorValue:t.value,appBundleId:e.appBundleId},n),i=r.found===!0,a=Jt(r);return{found:i,...typeof r.text==`string`?{text:r.text}:{},...a?{node:a}:{}}}async function X(t,n,r){try{return await Gt(n,r,O({req:t.req,logPath:t.logPath,traceLogPath:n.trace?.outPath}))}catch(t){return I(t,{allowElementNotFound:!0})?null:{kind:`error`,response:{ok:!1,error:e(t)}}}}function Z(e){return e!==null&&`kind`in e&&e.kind===`error`}function Kt(e,t,n){if(!n.found||!n.node)return null;let r={target:{kind:`selector`,selector:t},node:n.node,selectorChain:[t]};return e===`attrs`?{kind:`attrs`,...r}:typeof n.text==`string`?{kind:`text`,...r,text:n.text}:null}function qt(e,t,n,r,i){let a=f({predicate:e,node:i,nodes:[i],expectedText:t,platform:r.device.platform});return{predicate:e,pass:a.pass,selector:n,...e===`text`?{text:a.actualText}:{},selectorChain:[n]}}function Jt(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!(!n||typeof n!=`object`))return n}function Yt(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=j(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=l(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:x(n.code,n.message)}}function Xt(e,n,r){if(e.kind===`sleep`)return{kind:`sleep`,durationMs:e.durationMs};if(e.kind===`selector`)return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...r?{recordedLandmark:r}:{}};if(e.kind===`ref`){if(!n?.snapshot)throw new t(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:e.rawRef,timeoutMs:e.timeoutMs}}if(e.kind===`stable`)return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};let i=d(e.text);if(!i.ok)throw new t(i.code,i.message);return{kind:`text`,text:i.text,timeoutMs:e.timeoutMs}}async function Q(e){try{return{ok:!0,data:await e()}}catch(e){let t=o(e);return x(t.code,t.message,t.details)}}async function $(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{i=await L(r)}catch{return t}return i?x(t.error.code,`${n} failed because ${We(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{je as S,Ne as _,Gt as a,Me as b,Ue as c,I as d,P as f,Pe as g,Ie as h,Rt as i,Ge as l,Le as m,It as n,K as o,F as p,Lt as r,G as s,Ft as t,He as u,M as v,k as x,N as y};
|
package/dist/src/selectors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Sn as e,_n as t,bn as n,rn as r,tn as i,vn as a,xn as o}from"./sdk-batch-runner.js";import{t as s}from"./sdk-selectors.js";export{i as findSelectorChainMatch,s as formatSelectorFailure,o as isNodeEditable,e as isNodeVisible,t as isSelectorToken,a as parseSelectorChain,r as resolveSelectorChain,n as tryParseSelectorChain};
|
package/dist/src/server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{S as e,_ as t,n,o as r}from"./sdk-contracts.js";import{n as i}from"./version.js";import{Hn as a,S as o,g as s,h as c}from"./sdk-batch-runner.js";import{i as l,t as u}from"./sdk-device.js";import{Et as ee,Ot as te,kt as ne,qt as re,un as ie}from"./prepare-kind.js";import{_ as d,g as f,h as ae,s as oe,v as p}from"./registry.js";import{i as se,n as ce,t as le}from"./command-metadata.js";import{n as ue,r as de,t as fe}from"./cli-config.js";import{t as pe}from"./cli-output.js";const m=[`simulator`,`emulator`,`device`];function h(e){return{type:`number`,...e?{description:e}:{}}}function g(e,t){return{type:`string`,enum:e,...t?{description:t}:{}}}function _(e){return{type:`string`,const:e}}function v(e){return{type:[`string`,`null`],...e?{description:e}:{}}}function y(e,t=[],n){return{type:`object`,...n?{description:n}:{},properties:e,...t.length>0?{required:t}:{}}}const b={type:`array`,items:{type:`string`}},x=y({wallClockMs:h(`Total wall-clock time for the request in milliseconds.`),runnerRoundTrips:h(`Number of real runner round-trips made while serving the request.`),nodeCount:h(`Number of nodes in the original node tree when the response carries one.`)},[`wallClockMs`,`runnerRoundTrips`]),S=y({field:p(),artifactType:p(),path:p(),localPath:p(),fileName:p()},[`field`]);function C(e={}){let t=e.properties??{},n=e.required??[];return y({targetKind:g([`point`,`ref`,`selector`],`Resolved interaction target kind.`),x:h(`Resolved interaction x coordinate when available.`),y:h(`Resolved interaction y coordinate when available.`),referenceWidth:h(`Reference frame width for visualizing the interaction point.`),referenceHeight:h(`Reference frame height for visualizing the interaction point.`),ref:p(`Snapshot ref without the @ prefix when the target was an @ref.`),selector:p(`Selector expression when the target was a selector.`),selectorChain:b,refLabel:p(),targetHittable:f(),hint:p(),warning:p(),message:p(),evidence:T,resolution:me,cost:x,maestroNonHittableCoordinateFallbackAllowed:f(`Whether the direct iOS Maestro coordinate fallback was allowed for this selector.`),maestroNonHittableCoordinateFallbackUsed:f(`Whether the direct iOS Maestro coordinate fallback was actually used.`),maestroFallbackReason:_(`non-hittable-coordinate`),...t},[`targetKind`,...n])}const w=y({diagnosticRef:p(`Opaque non-@ diagnostic token. Never a snapshot ref: not issued via refsGeneration and cannot be pinned or reused as an @ref target. UTF-8 truncated to 256 bytes.`),role:p(`UTF-8 truncated to 256 bytes.`),label:p(`UTF-8 truncated to 256 bytes.`)},[`diagnosticRef`]),me={type:`object`,description:`Pre-action disclosure of how the acting path resolved its target. Absent when resolutionDisclosure is inapplicable for the path.`,oneOf:[y({source:_(`runtime`),phase:_(`pre-action`),kind:_(`unique`)},[`source`,`phase`,`kind`]),y({source:_(`runtime`),phase:_(`pre-action`),kind:_(`disambiguated`),matchCount:h(`Total matches resolveSelectorChain found before disambiguation.`),winnerDiagnostic:w,tiebreak:g([`visible`,`deepest`,`smallest-area`,`structural-equivalence`],`The comparison that decided the winner.`),alternatives:{type:`array`,description:`At most 5 losing candidates, document order. Present at default/full response levels and omitted in digest. The winner is never included.`,items:w}},[`source`,`phase`,`kind`,`matchCount`,`winnerDiagnostic`,`tiebreak`]),y({source:_(`ref`),phase:_(`pre-action`),kind:_(`exact`)},[`source`,`phase`,`kind`]),y({source:_(`ref`),phase:_(`pre-action`),kind:_(`label-fallback`)},[`source`,`phase`,`kind`]),y({source:_(`direct-ios`),kind:_(`not-observed`)},[`source`,`kind`])]},T=y({foregroundApp:p(`Foreground app bundle id or name, when the capture carries it.`),nodeCount:h(`Node count in the post-action interactive-only capture.`),interactiveNodeCount:h(`Subset of nodeCount the platform reports as hittable.`),digest:p(`Order-independent digest of the post-action node multiset.`),changedFromBefore:f(`Whether the post-action digest differs from the pre-action capture digest. false is evidence, not failure.`)},[`nodeCount`,`interactiveNodeCount`,`digest`,`changedFromBefore`]),E=y({settled:f(`Whether the UI held the quiet window before the deadline. false is advisory, not failure.`),waitedMs:h(),captures:h(),quietMs:h(),timeoutMs:h(),refsGeneration:h(`Snapshot generation of the stored settled tree; refs on added diff lines were minted from it.`),refs:{type:`array`,items:y({ref:p(`Plain ref body (e12) minted from the stored settled tree.`)},[`ref`])},diff:y({summary:y({additions:h(),removals:h(),unchanged:h()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:y({kind:g([`added`,`removed`]),text:p(),ref:p(`Plain ref body (e12) for added lines.`)},[`kind`,`text`])},truncated:f(`Lines were capped to the response bound.`)},[`summary`,`lines`],`Settled diff vs the pre-action tree (changed lines only).`),tail:{type:`array`,description:`Unchanged interactive refs tail: still-present, actionable elements from the settled tree, attached only when diff carries zero added-line refs (a modal-dismiss/toast-only diff).`,items:y({ref:p(`Plain ref body (e12) minted from the stored settled tree.`),role:p(),label:p()},[`ref`,`role`])},tailTruncated:f(`Present (true) when tail candidates exceeded the response cap.`),hint:p()},[`settled`,`waitedMs`,`captures`,`quietMs`,`timeoutMs`]),D={platform:g(l),target:g(u),device:p(`Human-readable device name.`),id:p(`Stable device id.`),kind:g(m)},O=[`platform`,`target`,`device`,`id`,`kind`],he=y({success:f(),exitCode:h(),stdout:p(),stderr:p(),error:d(`Normalized error detail when shutdown failed.`)},[`success`,`exitCode`,`stdout`,`stderr`]);function ge(e){return{...e,properties:{...e.properties??{},settle:E}}}const _e=C({properties:{evidence:T,settle:E,button:g([`secondary`,`middle`]),count:h(`Number of press/click repetitions.`),intervalMs:h(`Delay between repeated press/click actions.`),holdMs:h(`Hold duration for each action.`),jitterPx:h(`Randomization radius in pixels.`),doubleTap:f(`Whether the command requested a double-tap action.`)}}),k={text:p(`Text submitted to the field.`),delayMs:h(`Delay between typed characters in milliseconds.`),evidence:T,settle:E},ve=y({resourceId:v(`Android resource id of the exact field that changed.`),className:v(`Android class name of the exact field that changed.`),packageName:v(`Android package name that owns the exact field.`),rect:y({x:h(),y:h(),width:h(),height:h()},[`x`,`y`,`width`,`height`],`Screen-space rectangle of the exact field that changed.`)},[`resourceId`,`className`,`packageName`,`rect`],`Target identity captured before fill and matched after fill.`),ye={press:_e,click:_e,fill:{type:`object`,description:`Fill response. Android may return target-bound unconfirmed evidence when the exact app-owned field changed but formatting prevented raw equality.`,oneOf:[{...C({properties:k,required:[`text`]}),not:y({},[`verification`])},C({properties:{...k,verification:_(`unconfirmed`),requested:p(`Literal text requested by the fill command.`),before:v(`Raw target text captured before the fill.`),after:v(`Raw target text captured after the fill.`),target:ve},required:[`text`,`verification`,`requested`,`before`,`after`,`target`]})]},longpress:C({properties:{durationMs:h(),settle:E,gesture:_(`longpress`)}}),find:y({ref:p(`Snapshot ref without the @ prefix when the find action returns one.`),refsGeneration:h(`ADR 0014 ref frame epoch for read-only find actions.`),found:f(`Whether a wait/exists/read-only find satisfied its condition.`),waitedMs:h(`Milliseconds waited for a read-only find condition.`),text:p(`Text value returned by find get_text.`),node:d(`Snapshot node for find get_attrs/get_text.`),matches:{type:`array`,description:`Every match for the read-only find list action (#1625): { ref, node } each.`,items:d(`One listed match with its snapshot ref and node.`)},locator:p(`Locator kind used for the find action.`),query:p(`Query argument used for the find action.`),x:h(`Resolved x coordinate for mutating find actions.`),y:h(`Resolved y coordinate for mutating find actions.`),message:p(`Diagnostic message for mutating find actions.`),settle:E,cost:x},[],`Daemon response data for the find command.`),boot:y({...D,booted:{type:`boolean`,const:!0}},[...O,`booted`]),shutdown:y({...D,shutdown:he},[...O,`shutdown`]),viewport:y({width:h(),height:h(),message:p()},[`width`,`height`,`message`]),...oe,back:ge(oe.back),wait:y({waitedMs:h(),kind:_(`selector`),text:p(),selector:p(),captures:h(),nodeCount:h(),hint:p(),warning:p()},[`waitedMs`]),prepare:y({action:_(`ios-runner`),platform:g(l),deviceId:p(),deviceName:p(),kind:g(m),durationMs:h(),runner:y({},[]),cache:g([`exact`,`restore-key`,`miss`,`external`]),artifact:g([`valid`,`rebuilt`]),buildMs:h(),connectMs:h(),healthCheckMs:h(),xctestrunPath:p(),recoveryReason:p(),failureReason:p(),timing:y({totalMs:h(),additiveParts:y({buildMs:h(),connectAfterBuildMs:h(),healthCheckMs:h()},[`connectAfterBuildMs`,`healthCheckMs`]),containment:y({connectMs:{type:`array`,items:_(`buildMs`)},healthCheckMs:{type:`array`,items:p()}},[`healthCheckMs`]),note:p()},[`totalMs`,`additiveParts`,`containment`,`note`]),message:p()},[`action`,`platform`,`deviceId`,`deviceName`,`kind`,`durationMs`,`runner`,`connectMs`,`healthCheckMs`,`timing`,`message`]),push:{type:`object`,oneOf:[y({platform:_(`ios`),bundleId:p(),message:p()},[`platform`,`bundleId`,`message`]),y({platform:_(`android`),package:p(),action:p(),extrasCount:h(),message:p()},[`platform`,`package`,`action`,`extrasCount`,`message`])]},"trigger-app-event":y({event:p(),eventUrl:p(),transport:_(`deep-link`),message:p()},[`event`,`eventUrl`,`transport`,`message`]),clipboard:{type:`object`,oneOf:[y({action:_(`read`),text:p()},[`action`,`text`]),y({action:_(`write`),textLength:h(),message:p()},[`action`,`textLength`,`message`])]},appstate:{type:`object`,oneOf:[y({platform:g([`ios`,`macos`]),appName:p(),appBundleId:p(),source:_(`session`),surface:g(re),device_udid:p(`iOS only — the session device UDID.`),ios_simulator_device_set:{type:[`string`,`null`],description:`iOS only — the simulator set path, or null when unknown.`}},[`platform`,`appName`,`source`,`surface`]),y({platform:_(`android`),package:p(),activity:p()},[`platform`,`package`,`activity`])]},keyboard:y({platform:g([`android`,`ios`]),action:g([`status`,`dismiss`,`enter`]),visible:f(),wasVisible:f(),dismissed:f(),attempts:h(),inputType:p(),type:g([`text`,`number`,`email`,`phone`,`password`,`datetime`,`unknown`]),inputMethodPackage:p(),focusedPackage:p(),focusedResourceId:p(),inputOwner:g([`app`,`ime`,`unknown`]),message:p()},[`platform`,`action`]),doctor:y({status:g([`pass`,`warn`,`fail`,`info`]),summary:p(),kind:g([`auto`,`react-native`,`expo`,`repack`]),platform:p(),target:g(u),targetApp:p(),metro:y({host:p(),port:h()},[`host`,`port`]),checks:{type:`array`,items:y({id:p(),status:g([`pass`,`warn`,`fail`,`info`]),summary:p(),hint:p(),command:p(),evidence:d()},[`id`,`status`,`summary`])}},[`status`,`summary`,`kind`,`checks`]),diff:y({mode:_(`snapshot`),baselineInitialized:f(),summary:y({additions:h(),removals:h(),unchanged:h()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:y({kind:g([`added`,`removed`]),text:p(),ref:p()},[`kind`,`text`])},warnings:b},[`mode`,`baselineInitialized`,`summary`,`lines`]),replay:y({replayed:h(),healed:h(),session:p(),sessionActive:f(`True iff the session is still active — the script had no terminal close.`),artifactPaths:b,snapshotDiagnostics:d(),message:p()},[`replayed`,`healed`,`session`,`sessionActive`,`artifactPaths`,`message`]),test:y({total:h(),executed:h(),passed:h(),failed:h(),skipped:h(),notRun:h(),durationMs:h(),failures:{type:`array`,items:d()},tests:{type:`array`,items:d()},snapshotDiagnostics:d()},[`total`,`executed`,`passed`,`failed`,`skipped`,`notRun`,`durationMs`,`failures`,`tests`]),record:{type:`object`,oneOf:[y({recording:_(`started`),outPath:p(),sessionStateDir:p(),recordingBackend:p(),recordingScope:p(),recordOnlySession:f(),activeSessionApp:d(),showTouches:f()},[`recording`,`outPath`,`sessionStateDir`,`showTouches`]),y({recording:_(`stopped`),outPath:p(),telemetryPath:p(),artifacts:{type:`array`,items:S},recordingBackend:p(),recordingScope:p(),recordOnlySession:f(),activeSessionApp:d(),durationMs:h(),showTouches:f(),warning:p(),overlayWarning:p(),chunks:{type:`array`,items:d()}},[`recording`,`outPath`,`artifacts`,`durationMs`,`showTouches`])]},trace:{type:`object`,oneOf:[y({trace:_(`started`),outPath:p()},[`trace`,`outPath`]),y({trace:_(`stopped`),outPath:p(),artifacts:{type:`array`,items:S}},[`trace`,`outPath`,`artifacts`])]}},be={devices:{type:`object`,properties:{devices:{type:`array`,items:{type:`object`,properties:{platform:{type:`string`,enum:l},target:{type:`string`,enum:u},kind:{type:`string`,enum:m},id:{type:`string`},name:{type:`string`}},required:[`platform`,`target`,`kind`,`id`,`name`]}}},required:[`devices`]},apps:{type:`object`,properties:{apps:{type:`array`,items:{type:`string`}}},required:[`apps`]}},A={...ye,...be};function xe(t){return e(t)}function Se(e){let t=[`Error (${e.code}): ${e.message}`];e.hint&&t.push(`Hint: ${e.hint}`),t.push(...te(e.details)),e.supportedOn&&t.push(`Supported on: ${e.supportedOn}`);let n=ee(e.details);return n&&t.push(n),t.join(`
|
|
2
|
-
`)}function Ce(e,t,n){let r=fe({command:e,cwd:process.cwd(),cliFlags:t}),i={};for(let[t,a]of Object.entries(r))Object.hasOwn(n,t)&&ue(t,e)&&(i[t]=a);return de(i,t)}const we={devices:e=>({devices:e.map(ie)}),apps:e=>({apps:e})};function Te(e,t){let n=we[e];return n?n(t):t}function Ee(){let e=new Map;return{pinInput:(t,n,r)=>Be(t,n,je(e,r,n.session)),mergeCommandResult:(t,n,r,i)=>Me(e,t,n,r,i),mergeErrorDetails:(t,n,r)=>{let i=j(n,r);De(e,i,t),Re(e,i,t)}}}function De(e,t,n){let r=n?.refsGeneration;typeof r==`number`&&M(e,t,ne(n),r)}const Oe=new Set([`snapshot`,`find`]),ke=new Set(c.map(e=>e.name).filter(ce).filter(e=>s(e))),Ae=new Set([`press`,`click`,`fill`,`longpress`,`get`]);function je(e,t,n){return e.get(j(t,n))}function j(e,t){let n=typeof t==`string`&&t.length>0?t:`default`;return`${e??``}\u0000${n}`}function Me(e,t,n,r,i){let a=j(r,i);if(ke.has(t)){Fe(e,a,Ie(n));return}Oe.has(t)&&(t===`find`?Pe(e,a,n):Ne(e,a,n))}function Ne(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`){e.delete(t);return}let i=[];for(let{ref:e}of n.refs??[])i.push(e);for(let e of n.nodes??[])i.push(e.ref);M(e,t,i,r)}function Pe(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`)return;let i=[];typeof n.ref==`string`&&n.ref.startsWith(`@`)&&i.push(n.ref.slice(1));for(let e of n.matches??[])typeof e.ref==`string`&&e.ref.length>0&&i.push(e.ref.startsWith(`@`)?e.ref.slice(1):e.ref);M(e,t,i,r)}function Fe(e,t,n){n?.refsGeneration!==void 0&&M(e,t,[...n.diff?.lines??[],...n.refs??[],...n.tail??[]].map(e=>e.ref).filter(e=>typeof e==`string`),n.refsGeneration)}function Ie(e){let t=e.settle;return typeof t==`object`&&t?t:void 0}function M(e,t,n,r){if(n.length===0)return;let i=e.get(t)??new Map;e.set(t,i),Le(i,n,r)}function Le(e,t,n){for(let r of t)e.delete(r),e.set(r,n);for(;e.size>1e3;)e.delete(e.keys().next().value)}function Re(e,t,n){let r=a(a(n?.divergence)?.screen);if(r?.state!==`available`)return;let i=r.refsGeneration;if(typeof i!=`number`)return;let o=[];ze(r.refs,o),M(e,t,o,i)}function ze(e,t){if(Array.isArray(e))for(let n of e){let e=a(n)?.ref;typeof e==`string`&&e.length>0&&t.push(e)}}function Be(e,t,n){return n===void 0||n.size===0?t:e===`wait`?Ve(t,n)??t:Ae.has(e)?He(t,n)??t:t}function Ve(e,t){if(typeof e.ref!=`string`)return;let n=N(e.ref,t);return n===e.ref?void 0:{...e,ref:n}}function He(e,t){let n=a(e.target);if(n?.kind!==`ref`||typeof n.ref!=`string`)return;let r=N(n.ref,t);return r===n.ref?void 0:{...e,target:{...n,ref:r}}}function N(e,t){if(!e.startsWith(`@`)||e.includes(`~`))return e;let n=t.get(e.slice(1));return n===void 0?e:`${e}~s${n}`}function Ue(){return se().map(e=>{let t=e.name in A?A[e.name]:void 0;return{name:e.name,description:ae(e),inputSchema:P(e.name,e.inputSchema),...t?{outputSchema:t}:{}}})}function We(e={}){let n=Ee();return{execute:async(r,i)=>{if(!ce(r))throw new t(`INVALID_ARGS`,`Unknown command tool: ${r}`);let a=P(r,le(r).inputSchema).properties,o=Ce(r,i,a),s=Ye(o),c=$e(o),l=n.pinInput(r,c,s.client.stateDir),u=await qe(e,s.client);try{let t=await(e.runCommand??Je)(u,r,l);return n.mergeCommandResult(r,t,s.client.stateDir,c.session),{isError:!1,structuredContent:Te(r,t),content:[{type:`text`,text:et({name:r,input:c,result:t,outputFormat:s.outputFormat,responseLevel:s.client.responseLevel})}]}}catch(e){return Ge(e,n,s.client.stateDir,c.session)}}}}function Ge(e,t,n,r){let i=xe(e);return t.mergeErrorDetails(i.details,n,r),{isError:!0,structuredContent:i,content:[{type:`text`,text:Se(i)}]}}const Ke=We();async function qe(e,t){if(e.createClient)return await e.createClient(t);let{createAgentDeviceClient:n}=await import(`./agent-device-client.js`).then(e=>e.t);return n(t)}async function Je(e,t,n){return await(await import(`./command-surface.js`).then(e=>e.t)).runCommand(e,t,n)}function Ye(e){return{client:Xe(e),outputFormat:Qe(e.mcpOutputFormat)}}function Xe(e){let n=e.stateDir,r=e.includeCost,i=e.responseLevel,a={};if(n!==void 0){if(typeof n!=`string`||n.length===0)throw new t(`INVALID_ARGS`,`Expected stateDir to be a non-empty string.`);a.stateDir=n}if(r!==void 0){if(typeof r!=`boolean`)throw new t(`INVALID_ARGS`,`Expected includeCost to be a boolean.`);r&&(a.cost=!0)}let o=Ze(i);return o!==void 0&&(a.responseLevel=o),a}function Ze(e){if(e===void 0)return;let r=n.find(t=>t===e);if(r===void 0)throw new t(`INVALID_ARGS`,`Expected responseLevel to be one of 'digest', 'default', or 'full'.`);return r}function Qe(e){if(e===void 0)return`optimized`;if(e!==`optimized`&&e!==`json`)throw new t(`INVALID_ARGS`,`Expected mcpOutputFormat to be "optimized" or "json".`);return e}function $e(e){let{stateDir:t,mcpOutputFormat:n,includeCost:r,responseLevel:i,...a}=e;return a}function P(e,t){let n=o(e);return{...t,properties:{...t.properties,...n&&!t.properties?.noRecord?{noRecord:{type:`boolean`,description:`Do not record this action.`}}:{},stateDir:{type:`string`,description:`Agent-device state directory.`},mcpOutputFormat:{type:`string`,enum:[`optimized`,`json`],description:`MCP text content format. Defaults to optimized agent-friendly text; use json for JSON text. Structured content is always returned separately.`},includeCost:{type:`boolean`,description:`Include per-command agent-cost (cost.wallClockMs, …) in structuredContent. Defaults to off; the default response shape is unchanged.`},responseLevel:{type:`string`,enum:[`digest`,`default`,`full`],description:`Response verbosity: token-cheap digest / default (today) / full. Defaults to default; the default response shape is unchanged.`}}}}function et(e){if(e.outputFormat===`json`||e.responseLevel!==void 0&&e.responseLevel!=="default")return F(e.result);let t=pe({name:e.name,input:e.input,result:e.result});return typeof t?.text==`string`?t.text:F(t?.data??e.result)}function F(e){return typeof e==`string`?e:JSON.stringify(e,null,2)}const I=`2026-07-28`,L=[I],R=[`2025-11-25`,`2025-06-18`],z=[...L,...R],B=`server/discover`,tt=new Set([`initialize`,`ping`]),V=`io.modelcontextprotocol/protocolVersion`,H=`io.modelcontextprotocol/clientCapabilities`,U=`io.modelcontextprotocol/clientInfo`,W=36e5;var G=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${z.join(`, `)}.`),this.requested=e}get data(){return{supported:z,requested:this.requested}}};function nt(e,n){let r=X(X(n)._meta),i=ut(r,V);if(i===void 0){if(e===B)throw new t(`INVALID_ARGS`,`Expected _meta["${V}"] on ${B}.`);return`legacy`}if(!z.includes(i))throw new G(i);if(!q(r[H]))throw new t(`INVALID_ARGS`,`Expected _meta["${H}"] to be an object.`);let a=r[U];if(a!==void 0&&!st(a))throw new t(`INVALID_ARGS`,`Expected _meta["${U}"] to be a valid Implementation.`);if(!L.includes(i)){if(e===B)throw new G(i);return`legacy`}return`modern`}function rt(e){let t=ut(X(e),`protocolVersion`);return t!==void 0&&R.includes(t)?t:`2025-11-25`}function it(e,t){return t===`modern`&&tt.has(e)}function K(){return{name:`agent-device`,version:i()}}function at(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":K()}}}function ot(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function q(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function st(e){return!q(e)||!Y(e.name)||!Y(e.version)?!1:J(e.title,Y)&&J(e.description,Y)&&J(e.websiteUrl,Y)&&J(e.icons,e=>Array.isArray(e)&&e.every(ct))}function ct(e){return!q(e)||!Y(e.src)?!1:J(e.mimeType,Y)&&J(e.sizes,lt)&&J(e.theme,e=>e===`light`||e===`dark`)}function J(e,t){return e===void 0||t(e)}function Y(e){return typeof e==`string`}function lt(e){return Array.isArray(e)&&e.every(Y)}function X(e){return q(e)?e:{}}function ut(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function dt(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return Z(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=nt(e.method,e.params),n=await ft(e.method,e.params,t);return ht(e.id,at(n,t))}catch(t){return t instanceof G?Z(e.id,-32022,t.message,t.data):t instanceof Q?Z(e.id,-32601,t.message):Z(e.id,-32602,t instanceof Error?t.message:String(t))}}async function ft(e,t,n){if(it(e,n))throw new Q(`${e} was removed in MCP ${I}.`);switch(e){case`server/discover`:return{supportedVersions:z,capabilities:{tools:{}},instructions:`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web targets. Each tool mirrors the CLI command of the same name; tool descriptions carry the per-command contract.`,ttlMs:W,cacheScope:`public`};case`initialize`:return{protocolVersion:rt(t),capabilities:{tools:{}},serverInfo:K()};case`ping`:return{};case`tools/list`:return{tools:Ue(),...ot(n,W)};case`tools/call`:return await pt(t);default:throw new Q(`Unsupported MCP method: ${e}`)}}async function pt(e){let t=gt(e),n=vt(t,`name`);try{return await Ke.execute(n,_t(t.arguments))}catch(e){return mt(Se(xe(e)),!0)}}function mt(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function ht(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function Z(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function gt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`Expected object parameters.`);return e}function _t(e){return e===void 0?{}:gt(e)}function vt(e,n){let r=e[n];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var Q=class extends Error{};async function yt(){let e=bt(),t=new Et(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){Ot({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function bt(e={}){let t=e.handlePayload??xt,n=e.write??Ot,r=Promise.resolve();return{push:e=>{let i=Tt(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function xt(e){return Array.isArray(e)?St(e):Ct(e)}async function St(e){let t=[];for(let n of e)t.push(...Dt(await Ct(n)));return t.length>0?t:null}async function Ct(e){let t;try{t=r.parse(e)}catch{return wt($(e))}return dt(t)}function wt(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function Tt(e){return Array.isArray(e)?e.length===1?$(e[0]):null:$(e)}function $(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var Et=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
|
|
1
|
+
import{S as e,_ as t,n,o as r}from"./sdk-contracts.js";import{n as i}from"./version.js";import{S as a,Un as o,g as s,h as c}from"./sdk-batch-runner.js";import{i as l,t as u}from"./sdk-device.js";import{Et as ee,Ot as te,kt as ne,qt as re,un as ie}from"./prepare-kind.js";import{_ as d,g as f,h as ae,s as oe,v as p}from"./registry.js";import{i as se,n as ce,t as le}from"./command-metadata.js";import{n as ue,r as de,t as fe}from"./cli-config.js";import{t as pe}from"./cli-output.js";const m=[`simulator`,`emulator`,`device`];function h(e){return{type:`number`,...e?{description:e}:{}}}function g(e,t){return{type:`string`,enum:e,...t?{description:t}:{}}}function _(e){return{type:`string`,const:e}}function v(e){return{type:[`string`,`null`],...e?{description:e}:{}}}function y(e,t=[],n){return{type:`object`,...n?{description:n}:{},properties:e,...t.length>0?{required:t}:{}}}const b={type:`array`,items:{type:`string`}},x=y({wallClockMs:h(`Total wall-clock time for the request in milliseconds.`),runnerRoundTrips:h(`Number of real runner round-trips made while serving the request.`),nodeCount:h(`Number of nodes in the original node tree when the response carries one.`)},[`wallClockMs`,`runnerRoundTrips`]),S=y({field:p(),artifactType:p(),path:p(),localPath:p(),fileName:p()},[`field`]);function C(e={}){let t=e.properties??{},n=e.required??[];return y({targetKind:g([`point`,`ref`,`selector`],`Resolved interaction target kind.`),x:h(`Resolved interaction x coordinate when available.`),y:h(`Resolved interaction y coordinate when available.`),referenceWidth:h(`Reference frame width for visualizing the interaction point.`),referenceHeight:h(`Reference frame height for visualizing the interaction point.`),ref:p(`Snapshot ref without the @ prefix when the target was an @ref.`),selector:p(`Selector expression when the target was a selector.`),selectorChain:b,refLabel:p(),targetHittable:f(),hint:p(),warning:p(),message:p(),evidence:T,resolution:me,cost:x,maestroNonHittableCoordinateFallbackAllowed:f(`Whether the direct iOS Maestro coordinate fallback was allowed for this selector.`),maestroNonHittableCoordinateFallbackUsed:f(`Whether the direct iOS Maestro coordinate fallback was actually used.`),maestroFallbackReason:_(`non-hittable-coordinate`),...t},[`targetKind`,...n])}const w=y({diagnosticRef:p(`Opaque non-@ diagnostic token. Never a snapshot ref: not issued via refsGeneration and cannot be pinned or reused as an @ref target. UTF-8 truncated to 256 bytes.`),role:p(`UTF-8 truncated to 256 bytes.`),label:p(`UTF-8 truncated to 256 bytes.`)},[`diagnosticRef`]),me={type:`object`,description:`Pre-action disclosure of how the acting path resolved its target. Absent when resolutionDisclosure is inapplicable for the path.`,oneOf:[y({source:_(`runtime`),phase:_(`pre-action`),kind:_(`unique`)},[`source`,`phase`,`kind`]),y({source:_(`runtime`),phase:_(`pre-action`),kind:_(`disambiguated`),matchCount:h(`Total matches resolveSelectorChain found before disambiguation.`),winnerDiagnostic:w,tiebreak:g([`visible`,`deepest`,`smallest-area`,`structural-equivalence`],`The comparison that decided the winner.`),alternatives:{type:`array`,description:`At most 5 losing candidates, document order. Present at default/full response levels and omitted in digest. The winner is never included.`,items:w}},[`source`,`phase`,`kind`,`matchCount`,`winnerDiagnostic`,`tiebreak`]),y({source:_(`ref`),phase:_(`pre-action`),kind:_(`exact`)},[`source`,`phase`,`kind`]),y({source:_(`ref`),phase:_(`pre-action`),kind:_(`label-fallback`)},[`source`,`phase`,`kind`]),y({source:_(`direct-ios`),kind:_(`not-observed`)},[`source`,`kind`])]},T=y({foregroundApp:p(`Foreground app bundle id or name, when the capture carries it.`),nodeCount:h(`Node count in the post-action interactive-only capture.`),interactiveNodeCount:h(`Subset of nodeCount the platform reports as hittable.`),digest:p(`Order-independent digest of the post-action node multiset.`),changedFromBefore:f(`Whether the post-action digest differs from the pre-action capture digest. false is evidence, not failure.`)},[`nodeCount`,`interactiveNodeCount`,`digest`,`changedFromBefore`]),E=y({settled:f(`Whether the UI held the quiet window before the deadline. false is advisory, not failure.`),waitedMs:h(),captures:h(),quietMs:h(),timeoutMs:h(),refsGeneration:h(`Snapshot generation of the stored settled tree; refs on added diff lines were minted from it.`),refs:{type:`array`,items:y({ref:p(`Plain ref body (e12) minted from the stored settled tree.`)},[`ref`])},diff:y({summary:y({additions:h(),removals:h(),unchanged:h()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:y({kind:g([`added`,`removed`]),text:p(),ref:p(`Plain ref body (e12) for added lines.`)},[`kind`,`text`])},truncated:f(`Lines were capped to the response bound.`)},[`summary`,`lines`],`Settled diff vs the pre-action tree (changed lines only).`),tail:{type:`array`,description:`Unchanged interactive refs tail: still-present, actionable elements from the settled tree, attached only when diff carries zero added-line refs (a modal-dismiss/toast-only diff).`,items:y({ref:p(`Plain ref body (e12) minted from the stored settled tree.`),role:p(),label:p()},[`ref`,`role`])},tailTruncated:f(`Present (true) when tail candidates exceeded the response cap.`),hint:p()},[`settled`,`waitedMs`,`captures`,`quietMs`,`timeoutMs`]),D={platform:g(l),target:g(u),device:p(`Human-readable device name.`),id:p(`Stable device id.`),kind:g(m)},O=[`platform`,`target`,`device`,`id`,`kind`],he=y({success:f(),exitCode:h(),stdout:p(),stderr:p(),error:d(`Normalized error detail when shutdown failed.`)},[`success`,`exitCode`,`stdout`,`stderr`]);function ge(e){return{...e,properties:{...e.properties??{},settle:E}}}const _e=C({properties:{evidence:T,settle:E,button:g([`secondary`,`middle`]),count:h(`Number of press/click repetitions.`),intervalMs:h(`Delay between repeated press/click actions.`),holdMs:h(`Hold duration for each action.`),jitterPx:h(`Randomization radius in pixels.`),doubleTap:f(`Whether the command requested a double-tap action.`)}}),k={text:p(`Text submitted to the field.`),delayMs:h(`Delay between typed characters in milliseconds.`),evidence:T,settle:E},ve=y({resourceId:v(`Android resource id of the exact field that changed.`),className:v(`Android class name of the exact field that changed.`),packageName:v(`Android package name that owns the exact field.`),rect:y({x:h(),y:h(),width:h(),height:h()},[`x`,`y`,`width`,`height`],`Screen-space rectangle of the exact field that changed.`)},[`resourceId`,`className`,`packageName`,`rect`],`Target identity captured before fill and matched after fill.`),ye={press:_e,click:_e,fill:{type:`object`,description:`Fill response. Android may return target-bound unconfirmed evidence when the exact app-owned field changed but formatting prevented raw equality.`,oneOf:[{...C({properties:k,required:[`text`]}),not:y({},[`verification`])},C({properties:{...k,verification:_(`unconfirmed`),requested:p(`Literal text requested by the fill command.`),before:v(`Raw target text captured before the fill.`),after:v(`Raw target text captured after the fill.`),target:ve},required:[`text`,`verification`,`requested`,`before`,`after`,`target`]})]},longpress:C({properties:{durationMs:h(),settle:E,gesture:_(`longpress`)}}),find:y({ref:p(`Snapshot ref without the @ prefix when the find action returns one.`),refsGeneration:h(`ADR 0014 ref frame epoch for read-only find actions.`),found:f(`Whether a wait/exists/read-only find satisfied its condition.`),waitedMs:h(`Milliseconds waited for a read-only find condition.`),text:p(`Text value returned by find get_text.`),node:d(`Snapshot node for find get_attrs/get_text.`),matches:{type:`array`,description:`Every match for the read-only find list action (#1625): { ref, node } each.`,items:d(`One listed match with its snapshot ref and node.`)},locator:p(`Locator kind used for the find action.`),query:p(`Query argument used for the find action.`),x:h(`Resolved x coordinate for mutating find actions.`),y:h(`Resolved y coordinate for mutating find actions.`),message:p(`Diagnostic message for mutating find actions.`),settle:E,cost:x},[],`Daemon response data for the find command.`),boot:y({...D,booted:{type:`boolean`,const:!0}},[...O,`booted`]),shutdown:y({...D,shutdown:he},[...O,`shutdown`]),viewport:y({width:h(),height:h(),message:p()},[`width`,`height`,`message`]),...oe,back:ge(oe.back),wait:y({waitedMs:h(),kind:_(`selector`),text:p(),selector:p(),captures:h(),nodeCount:h(),hint:p(),warning:p()},[`waitedMs`]),prepare:y({action:_(`ios-runner`),platform:g(l),deviceId:p(),deviceName:p(),kind:g(m),durationMs:h(),runner:y({},[]),cache:g([`exact`,`restore-key`,`miss`,`external`]),artifact:g([`valid`,`rebuilt`]),buildMs:h(),connectMs:h(),healthCheckMs:h(),xctestrunPath:p(),recoveryReason:p(),failureReason:p(),timing:y({totalMs:h(),additiveParts:y({buildMs:h(),connectAfterBuildMs:h(),healthCheckMs:h()},[`connectAfterBuildMs`,`healthCheckMs`]),containment:y({connectMs:{type:`array`,items:_(`buildMs`)},healthCheckMs:{type:`array`,items:p()}},[`healthCheckMs`]),note:p()},[`totalMs`,`additiveParts`,`containment`,`note`]),message:p()},[`action`,`platform`,`deviceId`,`deviceName`,`kind`,`durationMs`,`runner`,`connectMs`,`healthCheckMs`,`timing`,`message`]),push:{type:`object`,oneOf:[y({platform:_(`ios`),bundleId:p(),message:p()},[`platform`,`bundleId`,`message`]),y({platform:_(`android`),package:p(),action:p(),extrasCount:h(),message:p()},[`platform`,`package`,`action`,`extrasCount`,`message`])]},"trigger-app-event":y({event:p(),eventUrl:p(),transport:_(`deep-link`),message:p()},[`event`,`eventUrl`,`transport`,`message`]),clipboard:{type:`object`,oneOf:[y({action:_(`read`),text:p()},[`action`,`text`]),y({action:_(`write`),textLength:h(),message:p()},[`action`,`textLength`,`message`])]},appstate:{type:`object`,oneOf:[y({platform:g([`ios`,`macos`]),appName:p(),appBundleId:p(),source:_(`session`),surface:g(re),device_udid:p(`iOS only — the session device UDID.`),ios_simulator_device_set:{type:[`string`,`null`],description:`iOS only — the simulator set path, or null when unknown.`}},[`platform`,`appName`,`source`,`surface`]),y({platform:_(`android`),package:p(),activity:p()},[`platform`,`package`,`activity`])]},keyboard:y({platform:g([`android`,`ios`]),action:g([`status`,`dismiss`,`enter`]),visible:f(),wasVisible:f(),dismissed:f(),attempts:h(),inputType:p(),type:g([`text`,`number`,`email`,`phone`,`password`,`datetime`,`unknown`]),inputMethodPackage:p(),focusedPackage:p(),focusedResourceId:p(),inputOwner:g([`app`,`ime`,`unknown`]),message:p()},[`platform`,`action`]),doctor:y({status:g([`pass`,`warn`,`fail`,`info`]),summary:p(),kind:g([`auto`,`react-native`,`expo`,`repack`]),platform:p(),target:g(u),targetApp:p(),metro:y({host:p(),port:h()},[`host`,`port`]),checks:{type:`array`,items:y({id:p(),status:g([`pass`,`warn`,`fail`,`info`]),summary:p(),hint:p(),command:p(),evidence:d()},[`id`,`status`,`summary`])}},[`status`,`summary`,`kind`,`checks`]),diff:y({mode:_(`snapshot`),baselineInitialized:f(),summary:y({additions:h(),removals:h(),unchanged:h()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:y({kind:g([`added`,`removed`]),text:p(),ref:p()},[`kind`,`text`])},warnings:b},[`mode`,`baselineInitialized`,`summary`,`lines`]),replay:y({replayed:h(),healed:h(),session:p(),sessionActive:f(`True iff the session is still active — the script had no terminal close.`),artifactPaths:b,snapshotDiagnostics:d(),message:p()},[`replayed`,`healed`,`session`,`sessionActive`,`artifactPaths`,`message`]),test:y({total:h(),executed:h(),passed:h(),failed:h(),skipped:h(),notRun:h(),durationMs:h(),failures:{type:`array`,items:d()},tests:{type:`array`,items:d()},snapshotDiagnostics:d()},[`total`,`executed`,`passed`,`failed`,`skipped`,`notRun`,`durationMs`,`failures`,`tests`]),record:{type:`object`,oneOf:[y({recording:_(`started`),outPath:p(),sessionStateDir:p(),recordingBackend:p(),recordingScope:p(),recordOnlySession:f(),activeSessionApp:d(),showTouches:f()},[`recording`,`outPath`,`sessionStateDir`,`showTouches`]),y({recording:_(`stopped`),outPath:p(),telemetryPath:p(),artifacts:{type:`array`,items:S},recordingBackend:p(),recordingScope:p(),recordOnlySession:f(),activeSessionApp:d(),durationMs:h(),showTouches:f(),warning:p(),overlayWarning:p(),chunks:{type:`array`,items:d()}},[`recording`,`outPath`,`artifacts`,`durationMs`,`showTouches`])]},trace:{type:`object`,oneOf:[y({trace:_(`started`),outPath:p()},[`trace`,`outPath`]),y({trace:_(`stopped`),outPath:p(),artifacts:{type:`array`,items:S}},[`trace`,`outPath`,`artifacts`])]}},be={devices:{type:`object`,properties:{devices:{type:`array`,items:{type:`object`,properties:{platform:{type:`string`,enum:l},target:{type:`string`,enum:u},kind:{type:`string`,enum:m},id:{type:`string`},name:{type:`string`}},required:[`platform`,`target`,`kind`,`id`,`name`]}}},required:[`devices`]},apps:{type:`object`,properties:{apps:{type:`array`,items:{type:`string`}}},required:[`apps`]}},A={...ye,...be};function xe(t){return e(t)}function Se(e){let t=[`Error (${e.code}): ${e.message}`];e.hint&&t.push(`Hint: ${e.hint}`),t.push(...te(e.details)),e.supportedOn&&t.push(`Supported on: ${e.supportedOn}`);let n=ee(e.details);return n&&t.push(n),t.join(`
|
|
2
|
+
`)}function Ce(e,t,n){let r=fe({command:e,cwd:process.cwd(),cliFlags:t}),i={};for(let[t,a]of Object.entries(r))Object.hasOwn(n,t)&&ue(t,e)&&(i[t]=a);return de(i,t)}const we={devices:e=>({devices:e.map(ie)}),apps:e=>({apps:e})};function Te(e,t){let n=we[e];return n?n(t):t}function Ee(){let e=new Map;return{pinInput:(t,n,r)=>Be(t,n,je(e,r,n.session)),mergeCommandResult:(t,n,r,i)=>Me(e,t,n,r,i),mergeErrorDetails:(t,n,r)=>{let i=j(n,r);De(e,i,t),Re(e,i,t)}}}function De(e,t,n){let r=n?.refsGeneration;typeof r==`number`&&M(e,t,ne(n),r)}const Oe=new Set([`snapshot`,`find`]),ke=new Set(c.map(e=>e.name).filter(ce).filter(e=>s(e))),Ae=new Set([`press`,`click`,`fill`,`longpress`,`get`]);function je(e,t,n){return e.get(j(t,n))}function j(e,t){let n=typeof t==`string`&&t.length>0?t:`default`;return`${e??``}\u0000${n}`}function Me(e,t,n,r,i){let a=j(r,i);if(ke.has(t)){Fe(e,a,Ie(n));return}Oe.has(t)&&(t===`find`?Pe(e,a,n):Ne(e,a,n))}function Ne(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`){e.delete(t);return}let i=[];for(let{ref:e}of n.refs??[])i.push(e);for(let e of n.nodes??[])i.push(e.ref);M(e,t,i,r)}function Pe(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`)return;let i=[];typeof n.ref==`string`&&n.ref.startsWith(`@`)&&i.push(n.ref.slice(1));for(let e of n.matches??[])typeof e.ref==`string`&&e.ref.length>0&&i.push(e.ref.startsWith(`@`)?e.ref.slice(1):e.ref);M(e,t,i,r)}function Fe(e,t,n){n?.refsGeneration!==void 0&&M(e,t,[...n.diff?.lines??[],...n.refs??[],...n.tail??[]].map(e=>e.ref).filter(e=>typeof e==`string`),n.refsGeneration)}function Ie(e){let t=e.settle;return typeof t==`object`&&t?t:void 0}function M(e,t,n,r){if(n.length===0)return;let i=e.get(t)??new Map;e.set(t,i),Le(i,n,r)}function Le(e,t,n){for(let r of t)e.delete(r),e.set(r,n);for(;e.size>1e3;)e.delete(e.keys().next().value)}function Re(e,t,n){let r=o(o(n?.divergence)?.screen);if(r?.state!==`available`)return;let i=r.refsGeneration;if(typeof i!=`number`)return;let a=[];ze(r.refs,a),M(e,t,a,i)}function ze(e,t){if(Array.isArray(e))for(let n of e){let e=o(n)?.ref;typeof e==`string`&&e.length>0&&t.push(e)}}function Be(e,t,n){return n===void 0||n.size===0?t:e===`wait`?Ve(t,n)??t:Ae.has(e)?He(t,n)??t:t}function Ve(e,t){if(typeof e.ref!=`string`)return;let n=N(e.ref,t);return n===e.ref?void 0:{...e,ref:n}}function He(e,t){let n=o(e.target);if(n?.kind!==`ref`||typeof n.ref!=`string`)return;let r=N(n.ref,t);return r===n.ref?void 0:{...e,target:{...n,ref:r}}}function N(e,t){if(!e.startsWith(`@`)||e.includes(`~`))return e;let n=t.get(e.slice(1));return n===void 0?e:`${e}~s${n}`}function Ue(){return se().map(e=>{let t=e.name in A?A[e.name]:void 0;return{name:e.name,description:ae(e),inputSchema:P(e.name,e.inputSchema),...t?{outputSchema:t}:{}}})}function We(e={}){let n=Ee();return{execute:async(r,i)=>{if(!ce(r))throw new t(`INVALID_ARGS`,`Unknown command tool: ${r}`);let a=P(r,le(r).inputSchema).properties,o=Ce(r,i,a),s=Ye(o),c=$e(o),l=n.pinInput(r,c,s.client.stateDir),u=await qe(e,s.client);try{let t=await(e.runCommand??Je)(u,r,l);return n.mergeCommandResult(r,t,s.client.stateDir,c.session),{isError:!1,structuredContent:Te(r,t),content:[{type:`text`,text:et({name:r,input:c,result:t,outputFormat:s.outputFormat,responseLevel:s.client.responseLevel})}]}}catch(e){return Ge(e,n,s.client.stateDir,c.session)}}}}function Ge(e,t,n,r){let i=xe(e);return t.mergeErrorDetails(i.details,n,r),{isError:!0,structuredContent:i,content:[{type:`text`,text:Se(i)}]}}const Ke=We();async function qe(e,t){if(e.createClient)return await e.createClient(t);let{createAgentDeviceClient:n}=await import(`./agent-device-client.js`).then(e=>e.t);return n(t)}async function Je(e,t,n){return await(await import(`./command-surface.js`).then(e=>e.t)).runCommand(e,t,n)}function Ye(e){return{client:Xe(e),outputFormat:Qe(e.mcpOutputFormat)}}function Xe(e){let n=e.stateDir,r=e.includeCost,i=e.responseLevel,a={};if(n!==void 0){if(typeof n!=`string`||n.length===0)throw new t(`INVALID_ARGS`,`Expected stateDir to be a non-empty string.`);a.stateDir=n}if(r!==void 0){if(typeof r!=`boolean`)throw new t(`INVALID_ARGS`,`Expected includeCost to be a boolean.`);r&&(a.cost=!0)}let o=Ze(i);return o!==void 0&&(a.responseLevel=o),a}function Ze(e){if(e===void 0)return;let r=n.find(t=>t===e);if(r===void 0)throw new t(`INVALID_ARGS`,`Expected responseLevel to be one of 'digest', 'default', or 'full'.`);return r}function Qe(e){if(e===void 0)return`optimized`;if(e!==`optimized`&&e!==`json`)throw new t(`INVALID_ARGS`,`Expected mcpOutputFormat to be "optimized" or "json".`);return e}function $e(e){let{stateDir:t,mcpOutputFormat:n,includeCost:r,responseLevel:i,...a}=e;return a}function P(e,t){let n=a(e);return{...t,properties:{...t.properties,...n&&!t.properties?.noRecord?{noRecord:{type:`boolean`,description:`Do not record this action.`}}:{},stateDir:{type:`string`,description:`Agent-device state directory.`},mcpOutputFormat:{type:`string`,enum:[`optimized`,`json`],description:`MCP text content format. Defaults to optimized agent-friendly text; use json for JSON text. Structured content is always returned separately.`},includeCost:{type:`boolean`,description:`Include per-command agent-cost (cost.wallClockMs, …) in structuredContent. Defaults to off; the default response shape is unchanged.`},responseLevel:{type:`string`,enum:[`digest`,`default`,`full`],description:`Response verbosity: token-cheap digest / default (today) / full. Defaults to default; the default response shape is unchanged.`}}}}function et(e){if(e.outputFormat===`json`||e.responseLevel!==void 0&&e.responseLevel!=="default")return F(e.result);let t=pe({name:e.name,input:e.input,result:e.result});return typeof t?.text==`string`?t.text:F(t?.data??e.result)}function F(e){return typeof e==`string`?e:JSON.stringify(e,null,2)}const I=`2026-07-28`,L=[I],R=[`2025-11-25`,`2025-06-18`],z=[...L,...R],B=`server/discover`,tt=new Set([`initialize`,`ping`]),V=`io.modelcontextprotocol/protocolVersion`,H=`io.modelcontextprotocol/clientCapabilities`,U=`io.modelcontextprotocol/clientInfo`,W=36e5;var G=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${z.join(`, `)}.`),this.requested=e}get data(){return{supported:z,requested:this.requested}}};function nt(e,n){let r=X(X(n)._meta),i=ut(r,V);if(i===void 0){if(e===B)throw new t(`INVALID_ARGS`,`Expected _meta["${V}"] on ${B}.`);return`legacy`}if(!z.includes(i))throw new G(i);if(!q(r[H]))throw new t(`INVALID_ARGS`,`Expected _meta["${H}"] to be an object.`);let a=r[U];if(a!==void 0&&!st(a))throw new t(`INVALID_ARGS`,`Expected _meta["${U}"] to be a valid Implementation.`);if(!L.includes(i)){if(e===B)throw new G(i);return`legacy`}return`modern`}function rt(e){let t=ut(X(e),`protocolVersion`);return t!==void 0&&R.includes(t)?t:`2025-11-25`}function it(e,t){return t===`modern`&&tt.has(e)}function K(){return{name:`agent-device`,version:i()}}function at(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":K()}}}function ot(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function q(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function st(e){return!q(e)||!Y(e.name)||!Y(e.version)?!1:J(e.title,Y)&&J(e.description,Y)&&J(e.websiteUrl,Y)&&J(e.icons,e=>Array.isArray(e)&&e.every(ct))}function ct(e){return!q(e)||!Y(e.src)?!1:J(e.mimeType,Y)&&J(e.sizes,lt)&&J(e.theme,e=>e===`light`||e===`dark`)}function J(e,t){return e===void 0||t(e)}function Y(e){return typeof e==`string`}function lt(e){return Array.isArray(e)&&e.every(Y)}function X(e){return q(e)?e:{}}function ut(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function dt(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return Z(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=nt(e.method,e.params),n=await ft(e.method,e.params,t);return ht(e.id,at(n,t))}catch(t){return t instanceof G?Z(e.id,-32022,t.message,t.data):t instanceof Q?Z(e.id,-32601,t.message):Z(e.id,-32602,t instanceof Error?t.message:String(t))}}async function ft(e,t,n){if(it(e,n))throw new Q(`${e} was removed in MCP ${I}.`);switch(e){case`server/discover`:return{supportedVersions:z,capabilities:{tools:{}},instructions:`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web targets. Each tool mirrors the CLI command of the same name; tool descriptions carry the per-command contract.`,ttlMs:W,cacheScope:`public`};case`initialize`:return{protocolVersion:rt(t),capabilities:{tools:{}},serverInfo:K()};case`ping`:return{};case`tools/list`:return{tools:Ue(),...ot(n,W)};case`tools/call`:return await pt(t);default:throw new Q(`Unsupported MCP method: ${e}`)}}async function pt(e){let t=gt(e),n=vt(t,`name`);try{return await Ke.execute(n,_t(t.arguments))}catch(e){return mt(Se(xe(e)),!0)}}function mt(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function ht(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function Z(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function gt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`Expected object parameters.`);return e}function _t(e){return e===void 0?{}:gt(e)}function vt(e,n){let r=e[n];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var Q=class extends Error{};async function yt(){let e=bt(),t=new Et(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){Ot({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function bt(e={}){let t=e.handlePayload??xt,n=e.write??Ot,r=Promise.resolve();return{push:e=>{let i=Tt(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function xt(e){return Array.isArray(e)?St(e):Ct(e)}async function St(e){let t=[];for(let n of e)t.push(...Dt(await Ct(n)));return t.length>0?t:null}async function Ct(e){let t;try{t=r.parse(e)}catch{return wt($(e))}return dt(t)}function wt(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function Tt(e){return Array.isArray(e)?e.length===1?$(e[0]):null:$(e)}function $(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var Et=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
|
|
3
3
|
`);if(e===-1)return;let t=this.buffer.slice(0,e).trim();return this.buffer=this.buffer.slice(e+1),t.length>0?t:void 0}emit(e){this.sink(JSON.parse(e))}};function Dt(e){return e?[e]:[]}function Ot(e){process.stdout.write(`${JSON.stringify(e)}\n`)}export{yt as runAgentDeviceMcpServer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{At as e,Bt as t,Ft as n,Nt as r,Tt as i,Vt as a,jt as o}from"./sdk-batch-runner.js";import{$ as s,et as c,it as l,tt as u}from"./prepare-kind.js";import{
|
|
1
|
+
import{At as e,Bt as t,Ft as n,Nt as r,Tt as i,Vt as a,jt as o}from"./sdk-batch-runner.js";import{$ as s,et as c,it as l,tt as u}from"./prepare-kind.js";import{cn as d}from"./internal/daemon.js";function f(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}function p(e,t={}){let n=t.mode??`action`,{node:r,preActionNodes:a}=e;if(typeof r.index!=`number`)return;let o=c(a),l=i(_(r),a);if(n===`landmark`&&l.id===void 0&&l.label===void 0)return;let u=s(r,o,8),d=u.chain,f=v(a,r),p=y(r,o),b=x(r),C=+(d.length>0),w=e=>{let t=d.slice(0,e),n=S({nodes:a,byIndex:o,node:r,identity:l,ancestry:t,sibling:f,scrollRegion:p});return{candidate:{...l,ancestry:t,sibling:f,viewportOrder:n.viewportOrder,...p?{scrollRegion:p}:{},...b?{rect:b}:{},verification:`verified`},domain:n}};for(let e=d.length;e>=C;--e){let{candidate:t,domain:i}=w(e);if(h(t))return t.verification=m({node:r,domain:i,mode:n,brokenWalk:u.broken}),t;if(e===C)return g(t)}}function m(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:w({node:e.node,domain:e.domain})}function h(e){return a(t({...e,verification:`unverifiable`}))<=n}function g(e){return e.verification=`unverifiable`,a(t(e))>4096&&delete e.rect,e}const _=o;function v(e,t){return r(e,t)}function y(e,t){let n=d(e,t);if(!n)return;let r=_(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function b(t,n){return!t&&!n?!0:!t||!n?!1:e(t,n)}function x(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function S(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:s}=e,c=u(t,n,i,a),l=c.filter(e=>v(t,e)===o),d=c.length>0?c.filter(e=>b(y(e,n),s)):void 0,f=d?C(d):[];return{identitySet:c,siblingMatches:l,regionMembers:d,orderedRegion:f,viewportOrder:Math.max(f.findIndex(e=>e.index===r.index),0)}}function C(e){return e.map((e,t)=>({node:e,documentOrder:t,center:l(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function w(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return f({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}export{C as a,p as i,y as n,b as o,v as r,f as s,_ as t};
|