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 • 7.52 kB
JavaScript
import{An as e,Mn as t,jn as n,wn as r}from"./sdk-batch.js";import{v as i}from"./sdk-contracts.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{i as s,t as c}from"./touch-runtime.js";import{r as l}from"./gesture-admission.js";import{C as u,D as d,F as ee,M as te,N as f,O as p,R as m,T as ne,V as h,W as g,_,j as v,l as re,o as ie,p as y,r as b,v as x,x as S,z as C}from"./tv-remote-runtime.js";import{n as w}from"./audio-probe-runtime.js";import{n as T}from"./perf-runtime.js";import{a as E,i as D,n as O}from"./screenshot-runtime2.js";import{t as k}from"./viewport-runtime.js";import{r as A,u as j}from"./application-lifecycle-interaction.js";import{n as M,r as N,t as P}from"./screen-recording-transport.js";async function F(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(I(e),await P({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>N(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>M(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function I(e){if(e.recordOnlySession)throw new i(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!e.outputPath.toLowerCase().endsWith(`.webm`))throw new i(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}const L=r(`web`),R=Object.freeze({available:!0}),z=n(`unsupported-platform-leaf`,`Web targets read element text from the captured tree only.`),B=n(`unsupported-platform-leaf`),V=n(`owner-capability-missing`,`record is not supported by this web provider`),H=n(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),U=n(`unsupported-platform-leaf`),W=n(`unsupported-platform-leaf`,`apps is not supported on web targets.`),G=n(`unsupported-platform-leaf`),K=n(`unsupported-platform-leaf`),q=n(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),J=n(`owner-capability-missing`),Y=n(`unsupported-platform-leaf`,`A web click is one immediate pointer press; the browser backend has no timed hold.`),ae=n(`unsupported-platform-leaf`,`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`);function X(e,t){return typeof e==`function`?t:J}function Z(e,t){return e?R:t}const oe=n(`unsupported-platform-leaf`),se=n(`unsupported-platform-leaf`,l),Q=n(`unsupported-device-kind`,`open is supported only for web browser devices.`),ce=n(`unsupported-device-kind`,`close is supported only for web browser devices.`),le=n(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`);function ue(e){let t=de(e),n=fe(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:U,clearRuntimeHints:U,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:q,configureProviderPortReverse:le})}function de(e){return e.kind===`device`?R:Q}function fe(e){return e.kind===`device`?R:ce}function pe(t){return Object.freeze({owner:L,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await F({host:t,device:e,owner:L,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async n=>{if(n.intent.kind===`exact-owner`&&!e(n.intent.owner,L))throw new i(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(n.device.platform!==`web`)throw new i(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${n.device.platform}`);let r=await t.networkTransports.resolve(n.device),a=await F({host:t,device:n.device,owner:L,signal:n.scope.signal}),o=n.device.kind===`device`?await t.localInteractors.resolve(n.device,{signal:n.scope.signal}):void 0;return me(t,n.device,n.scope.signal,r,a,$(n.device,r,a.available,o))},shutdown:async()=>void 0})}function me(e,n,r,o,s,l){let u=o.dump,d={...u?{networkDump:async e=>{let t=await u({maxEntries:e.maxEntries,include:e.include},r);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...l.operations.captureSnapshot.available?p({device:n,signal:r,resolveInteractor:e.localInteractors.resolve}):{},...l.operations.captureScreenshot.available?O({device:n,signal:r,resolveInteractor:e.localInteractors.resolve,captureCapabilities:D(`a web target captures through its browser`)}):{},...l.operations.focusPoint.available?C({device:n,signal:r,resolveInteractor:e.localInteractors.resolve}):{},...l.operations.typeText.available?ne({device:n,signal:r,resolveInteractor:e.localInteractors.resolve}):{},...t(l.operations.tapPoint,()=>c({device:n,signal:r,resolveInteractor:e.localInteractors.resolve,facts:l.operations,pause:async t=>await e.clock.sleep(t,r)})),...l.operations.scrollDirection.available?f({device:n,signal:r,resolveInteractor:e.localInteractors.resolve}):{},...l.operations.setViewport.available?{setViewport:async t=>{r.throwIfAborted();let a=await e.localInteractors.resolve(n,{signal:r});if(!a.setViewport)throw new i(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await a.setViewport(t.width,t.height),r.throwIfAborted()}}:{},...t(l.operations.audioProbeQuery,()=>({audioProbeQuery:async t=>{let r=await e.audioProbe.web.resolve(n);if(r===void 0)throw new i(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await r.probe(t)}})),...a(A({owner:`web`,openTargetIdentity:`app-name`,host:e.localInteractors,device:n,signal:r}),l.operations)};return Object.freeze({device:n,owner:L,facts:l,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,r,i){let a=n(`owner-capability-missing`,`network is not supported by this web provider`),o=Z(e.kind===`device`,Q);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:B,appLogDoctor:B,appLogStart:B,appLogReattach:B,appLogCleanup:B,appState:G,networkDump:Z(!!t.dump,a),screenRecordingStart:Z(r,V),screenRecordingReattach:Z(r,V),screenRecordingCleanup:Z(r,V),...v({capture:o,customActions:H,withoutActiveApp:o}),...te({findText:Q,querySelector:Q}),...E({capture:o}),...h({focus:o}),...d({type:o}),...s({unsupported:U,tap:o,tapRef:X(i?.tapRef,o),longPress:Y,hover:X(i?.hover,o),hoverRef:X(i?.hoverRef,o),fill:o,fillRef:X(i?.fillRef,o)}),...ee({scroll:o}),...m({unsupported:oe,targetAuthoredDrag:se}),...k({setViewport:o}),...g({readTextAtPoint:z}),...u({back:K}),...ie({orientation:K}),...b({tvRemote:K}),...re({unsupported:K}),...y({unsupported:K}),...w({capture:ae,query:R}),...T({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),..._({unsupported:K}),setFoldPose:K,sendTelephonyEvent:K,...x({triggerAppEvent:K}),...j({target:K,unsupported:K,write:{}}),...S({read:K,wait:K,accept:K,dismiss:K}),ensureReady:U,bootTarget:U,bootTargetHeadless:U,listApps:W,deployApp:U,materializeAppSource:U,deployMaterializedApp:U,sendPushNotification:U,uninstallApp:U,shutdownTarget:U,...ue(e)}})}export{pe as createWebPlatformRuntime};