agent-device
Version:
Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.
1 lines • 3.63 kB
JavaScript
import{A as e,B as t,L as n,R as r,b as i,y as a}from"./sdk-batch.js";import{v as o}from"./sdk-contracts.js";import{a as s,n as c}from"./recording-scope.js";import{n as l,t as u}from"./perf-runtime-plan.js";import{n as d}from"./device-claim-reconciliation.js";import{t as f}from"./device-claim-recovery.js";import{n as p}from"./provider-device-admission.js";import{n as m,r as h}from"./lease-context.js";function g(e){return e?[...e.screenRecording?[`screen-recording`]:[],...e.appLog?[`app-log`]:[],...e.audioProbe?[`audio-probe`]:[],...e.perfCapture?[`perf-capture`]:[],...e.trace?[`trace-log`]:[]]:[]}function _(e,t,n){let r=[...g(t),...n?[`provider-lease`]:[]];r.length>0&&h(e,`session-resource-disposal:${r.join(`,`)}`)}async function v(e){let{req:t,session:n}=e;if(m(t))switch(a(t.command)){case`none`:return await b(t,e.claimRecovery);case`session-lifecycle`:return await y(e);case`nested-test`:await D(t);return;case`operation`:C(t,n);return;default:h(t,`${t.command}:unclassified`)}}async function y(e){let{req:t,session:n}=e;(t.command!==`close`||t.internal?.closeAppOnly!==!0)&&(t.command===`open`&&n&&await e.validateSessionReopen(n),t.command===`close`&&_(t,n,await e.closeWouldReleaseProviderLease()),await b(t,e.claimRecovery))}async function b(e,t){let n=i(e.command);if(n!==`acquire-session`&&n!==`transient-exclusive`||e.command===`open`&&t.currentSessionExists)return;let r=await t.resolveDevice();if(e.command===`open`&&t.hasInMemorySessionOwner(r)||p(r))return;let a=await f({device:r,command:e.command,session:t.session,workspace:t.workspace,stateDir:t.stateDir,env:t.env,coveredClaimIsOwnedByRequest:t.coveredClaimIsOwnedByRequest,inspectRecovery:t=>x(e,t),...n===`acquire-session`?{observeDeviceBoot:t.observeDeviceBoot}:{}});if(a.status===`refused`)throw t.claimConflictError(r,a.conflict)}function x(e,t){if(e.command===`batch`||e.command===`replay`||!m(e))return;let n=d(t);return n.status===`inspectable`&&n.ownedResources.length>0&&h(e,`session-resource-recovery:${n.ownedResources[0].resourceKind}`),n}function S(e){return t=>x(e,t)}function C(t,n){switch(t.command){case`perf`:return w(t);case`record`:{let r=e({action:t.positionals?.[0],scope:t.flags?.recordingScope,hasLiveHandle:n?.screenRecording!==void 0});h(t,`record:${r.kind}`);return}case`logs`:return T(t,n);case`audio`:return E(t,n);case`trace`:{let e=s(t.positionals);if(!e)throw new o(`INVALID_ARGS`,c);h(t,`trace:${e}`)}return;default:h(t,`${t.command}:unclassified-operation`)}}function w(e){let t=u({positionals:e.positionals,kind:e.flags?.kind,outPath:e.flags?.out}),n=l(t);h(e,`perf:${n.kind}`)}function T(e,n){let r=t({action:e.positionals?.[0],restart:e.flags?.restart,marker:e.positionals?.slice(1).join(` `)});if([`start`,`stop`,`clear-restart`].includes(r.kind)){h(e,`logs:${r.kind}`);return}if(n&&!p(n.device)){n.device.platform===`android`&&h(e,`logs:${r.kind}`);return}h(e,`logs:${r.kind}:unverified-owner`)}function E(e,t){let i=n(e.positionals);if(!t||p(t.device)){h(e,`audio:unverified-owner`);return}let a=t.device.platform===`web`?`query`:`capture`,o=r({probeAction:i.probeAction,mode:a});h(e,`audio:${o.kind}`)}async function D(e){e.flags?.timeoutMs!==void 0&&h(e,`test:attempt-timeout`),e.flags?.recordVideo===!0&&h(e,`test:record-video`);let t=e.flags?.replayScriptSources;if(t===void 0)return;let{buildReplayTestSourceDiscovery:n}=await import(`./session-test-source-discovery.js`).then(e=>e.n);(await n(t,e.flags?.replayBackend))().some(e=>e.manifest.attemptDefaults?.timeoutMs!==void 0)&&h(e,`test:attempt-timeout`)}export{v as admitBoundedCompositeResourceRequest,S as createBoundedClaimRecoveryBeforeGateway};