UNPKG

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 • 19.9 kB
import{r as e}from"./rolldown-runtime.js";import{Ei as t,Ii as n}from"./sdk-batch.js";import{Q as r,Y as i,c as a,g as o,l as s,v as c}from"./sdk-contracts.js";import{n as l}from"./snapshot-capture-annotations.js";import{A as u,C as d,D as f,E as p,O as m,S as h,T as g,_,b as v,g as y,h as b,m as x,v as S,w as C,x as w,y as T}from"./sdk-batch-runner.js";import{n as ee}from"./snapshot-diagnostics.js";import"./capture.js";import{h as te,xt as ne}from"./sdk-io.js";import"./diagnostics.js";import{A as E,k as re,v as ie,y as ae}from"./sdk-device.js";import{n as D}from"./success-text.js";import{E as oe,m as se,x as ce}from"./lease-scope.js";import{t as O}from"./catalog.js";import{B as le,t as ue}from"./src3.js";import{S as k}from"./device.js";import{r as de}from"./daemon-client-transport.js";import{h as fe}from"./daemon-resolution.js";import{t as pe}from"./src4.js";import{a as me,i as he,l as ge,n as _e,r as ve,t as ye}from"./src5.js";function A(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function j(e,t,n){return{deviceId:t,deviceName:n,...E(e)?{serial:t}:e===`ios`?{udid:t}:{}}}function M(e,t){let n=h(e,`bundleId`),r=h(e,`package`);return{app:f(e,`app`),appPath:f(e,`appPath`),platform:p(e,`platform`),appId:n??r,bundleId:n,package:r,identifiers:A({session:t,bundleId:n,packageName:r})}}function N(e,t){let n=h(e,`bundleId`),r=h(e,`packageName`),i=n??r??h(e,`appId`),a=h(e,`launchTarget`)??r??n??i;if(!a)throw new c(`COMMAND_FAILED`,`Daemon response is missing "launchTarget".`,{response:e});return{appName:h(e,`appName`),appId:i,bundleId:n,packageName:r,launchTarget:a,installablePath:h(e,`installablePath`),archivePath:h(e,`archivePath`),materializationId:h(e,`materializationId`),materializationExpiresAt:h(e,`materializationExpiresAt`),identifiers:A({session:t,bundleId:n,packageName:r,appId:i})}}function P(e){return{released:e.released===!0,materializationId:f(e,`materializationId`),identifiers:{}}}function F(e){let{record:t,platform:n,id:r,name:i,target:a}=R(e,`name`),o=L(t);return{platform:n,target:a,kind:C(t,`kind`),id:r,name:i,booted:typeof t.booted==`boolean`?t.booted:void 0,...ae(n)&&o?{appleOs:o}:{},...I(t),identifiers:j(n,r,i),...be(t),...z(n,r)}}function I(e){let t=h(e,`model`),n=h(e,`osVersion`);return{...t?{model:t}:{},...n?{osVersion:n}:{}}}function be(e){let t=e.claimedBy;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n=t,r=n.session,i=n.workspace;return typeof r!=`string`||typeof i!=`string`?{}:{claimedBy:{session:r,workspace:i}}}function xe(e){let{record:t,platform:n,id:r,name:i,target:a}=R(e,`name`),o=f(t,`device`),s=L(t),c=w(t,`kind`),l={session:i,...j(n,r,o)};return{name:i,address:h(t,`address`),createdAt:g(t,`createdAt`),sessionStateDir:h(t,`sessionStateDir`),runnerLogPath:h(t,`runnerLogPath`),device:{platform:n,target:a,id:r,name:o,...s?{appleOs:s}:{},...I(t),...c?{kind:c}:{},identifiers:l,...z(n,r,{simulatorSetPath:v(t,`ios_simulator_device_set`)})},identifiers:l}}function L(e){let t=e.appleOs;return ie(t)?t:void 0}function R(e,t){let n=b(e);return{record:n,platform:p(n,`platform`),id:f(n,`id`),name:f(n,t),target:T(n,`target`)}}function z(e,t,n={}){if(e===`ios`)return{ios:{udid:t,...n.simulatorSetPath===void 0?{}:{simulatorSetPath:n.simulatorSetPath}}};if(!E(e))return{};let r=n.serial??t;return e===`android`?{android:{serial:r}}:e===`harmonyos`?{harmonyos:{serial:r}}:{vega:{serial:r}}}function Se(e){if(!y(e))return;let t=e.platform,n=h(e,`metroHost`),r=typeof e.metroPort==`number`?e.metroPort:void 0,i=h(e,`bundleUrl`),a=h(e,`launchUrl`);return{platform:s(t)?t:void 0,metroHost:n,metroPort:r,bundleUrl:i,launchUrl:a}}function Ce(e){let t=e.platform,n=h(e,`id`),r=h(e,`device`);if(!re(t)||!n||!r)return;let i=T(e,`target`),a=w(e,`kind`),o=E(t)?h(e,`serial`)??n:void 0,s={...j(t,n,r),...o?{serial:o}:{}};return{platform:t,target:i,id:n,name:r,...I(e),...a?{kind:a}:{},identifiers:s,...z(t,t===`ios`?h(e,`device_udid`)??n:n,{simulatorSetPath:v(e,`ios_simulator_device_set`),serial:o})}}const we=[`explicit-selector`,`existing-session`,`single-booted-local`,`single-bootable-local`,`single-app-installed-local`,`newest-bootable-local`,`preferred-local`,`single-provider-device`],Te=[`session`,`local`,`provider`];function Ee(e){if(!y(e))return;let{reason:t,source:n,candidateCount:r,bootOccurred:i}=e;if(!(!we.includes(t)||!Te.includes(n)||typeof r!=`number`||!Number.isInteger(r)||r<0||typeof i!=`boolean`))return{reason:t,source:n,candidateCount:r,bootOccurred:i}}function De(e){if(y(e)&&typeof e.durationMs==`number`&&typeof e.measuredAt==`string`&&typeof e.method==`string`)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:h(e,`appTarget`),appBundleId:h(e,`appBundleId`)}}function B(e){if(!y(e)||typeof e.success!=`boolean`||typeof e.exitCode!=`number`||typeof e.stdout!=`string`||typeof e.stderr!=`string`)return;let t=V(e.error);return{success:e.success,exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr,...t?{error:t}:{}}}const Oe=[`hint`,`diagnosticId`,`logPath`,`supportedOn`];function V(e){if(!y(e)||typeof e.code!=`string`||typeof e.message!=`string`)return;let t={code:e.code,message:e.message};Object.assign(t,ke(e.cause));for(let n of Oe){let r=e[n];typeof r==`string`&&(t[n]=r)}return y(e.details)&&(t.details=e.details),typeof e.retriable==`boolean`&&(t.retriable=e.retriable),t}function ke(e){let t=r(e);return t?{cause:t}:void 0}function Ae(e){let t=V(e.initialSnapshotError);return{...e.snapshot&&typeof e.snapshot==`object`?{snapshot:e.snapshot}:{},...t?{initialSnapshotError:t}:{}}}function je(e){let t=Me(e.launchConfirmation);if(t===`accepted`)return{launchConfirmation:`accepted`};if(t===`unanswered`){let t=H(e.launchConfirmationReason);return t?{launchConfirmation:`unanswered`,launchConfirmationReason:t}:{launchConfirmation:`unanswered`}}let n=Ne(e.launchConfirmationProbeFailure);return n?{launchConfirmationProbeFailure:n}:{}}function Me(e){switch(e){case`accepted`:case`unanswered`:return e;default:return}}function H(e){switch(e){case`alert-unrecognized`:case`url-owner-unresolved`:return e;default:return}}function Ne(e){switch(e){case`alert-read`:case`alert-accept`:case`runner`:return e;default:return}}function Pe(e){return Array.isArray(e)?e:[]}function Fe(e){let t=se(e);return u({requestId:e.requestId,cwd:e.cwd,sessionExplicit:e.session!==void 0,debug:e.debug,includeCost:e.cost,responseLevel:e.responseLevel,lockPolicy:e.lockPolicy,lockPlatform:e.lockPlatform,...ce(t),sessionIsolation:e.sessionIsolation,installSource:e.installSource,retainMaterializedPaths:e.retainMaterializedPaths,materializedPathRetentionMs:e.materializedPathRetentionMs,materializationId:e.materializationId})}function U(e){return e??`default`}function W(e){let t=D(e),n=o(e);return{...t.length>0?{warnings:t}:{},...n===void 0?{}:{scriptDeliveryFailure:n}}}function Ie(e){let t=async(t,n)=>await e(O.humanControl,t,n);return{allocate:async t=>{let n=await e(O.leaseAllocate,[],{...t,leaseId:t.leaseId});return{...K(n),...typeof n.reused==`boolean`?{created:!n.reused}:{}}},heartbeat:async t=>K(await e(O.leaseHeartbeat,[],t)),release:async t=>{let n=await e(O.leaseRelease,[],t);return{released:n.released===!0,provider:y(n.provider)?n.provider:void 0}},humanControl:{list:async e=>{let n=await t([`list`],e);if(!Array.isArray(n.holds))throw new c(`COMMAND_FAILED`,`Daemon did not return human-control holds.`);return n.holds.map(G)},put:async(e,n={},r)=>G((await t([`put`,e,JSON.stringify(n)],r)).hold),remove:async(e,n)=>(await t([`remove`,e],n)).released===!0}}}function G(e){if(!y(e)||!y(e.scope)||e.state!==`active`&&e.state!==`activating`||typeof e.createdAt!=`number`||typeof e.updatedAt!=`number`)throw new c(`COMMAND_FAILED`,`Daemon returned an invalid human-control hold.`);return{id:f(e,`id`),scope:{backend:f(e.scope,`backend`),leaseProvider:h(e.scope,`leaseProvider`),deviceKey:f(e.scope,`deviceKey`)},state:e.state,reason:h(e,`reason`),createdAt:e.createdAt,updatedAt:e.updatedAt,...typeof e.expiresAt==`number`?{expiresAt:e.expiresAt}:{}}}function K(e){let t=e.lease,n=y(t)?h(t,`leaseId`):void 0,r=y(t)?h(t,`tenantId`):void 0,i=y(t)?h(t,`runId`):void 0,a=y(t)?h(t,`backend`):void 0;if(!y(t)||!n||!r||!i||!a)throw new c(`COMMAND_FAILED`,`Invalid lease response from daemon`,{reason:`INVALID_LEASE_RESPONSE`,response:e});return{leaseId:n,tenantId:r,runId:i,backend:a,leaseProvider:h(t,`leaseProvider`),clientId:h(t,`clientId`),deviceKey:h(t,`deviceKey`),...Le(oe(t.device)),...t.retainOnClose===!0?{retainOnClose:!0}:{},createdAt:typeof t.createdAt==`number`?t.createdAt:void 0,heartbeatAt:typeof t.heartbeatAt==`number`?t.heartbeatAt:void 0,expiresAt:typeof t.expiresAt==`number`?t.expiresAt:void 0}}function Le(e){return e?{device:e}:{}}function q(e){return{...typeof e.path==`string`?{path:e.path}:{},...typeof e.width==`number`?{width:e.width}:{},...typeof e.height==`number`?{height:e.height}:{},...typeof e.logicalWidth==`number`?{logicalWidth:e.logicalWidth}:{},...typeof e.logicalHeight==`number`?{logicalHeight:e.logicalHeight}:{},...typeof e.pixelDensity==`number`?{pixelDensity:e.pixelDensity}:{},...k(e.displayRotation)?{displayRotation:e.displayRotation}:{},...e.overlayRefs?{overlayRefs:e.overlayRefs}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function Re(e,t){let n=ze(e),{scriptDeliveryFailure:r}=W(e);return{path:f(e,`path`),width:n?.width,height:n?.height,logicalWidth:n?.logicalWidth,logicalHeight:n?.logicalHeight,pixelDensity:n?.pixelDensity,...n?.displayRotation?{displayRotation:n.displayRotation}:{},overlayRefs:n?.overlayRefs,...n?.warnings?{warnings:n.warnings}:{},...r?{scriptDeliveryFailure:r}:{},identifiers:{session:t}}}function ze(e){if(!y(e))return;let t=He(e);return q({path:Be(e,`path`),width:J(e,`width`),height:J(e,`height`),logicalWidth:J(e,`logicalWidth`),logicalHeight:J(e,`logicalHeight`),pixelDensity:J(e,`pixelDensity`),displayRotation:k(e.displayRotation)?e.displayRotation:void 0,overlayRefs:Ve(e.overlayRefs),...t===void 0?{}:{warnings:t}})}function J(e,t){let n=e[t];return typeof n==`number`?n:void 0}function Be(e,t){let n=e[t];return typeof n==`string`?n:void 0}function Ve(e){if(Array.isArray(e))return e.filter(Ke).flatMap(e=>{let t=Ue(e);return t?[t]:[]})}function He(e){if(Array.isArray(e.warnings))return D(e).filter(e=>e.length>0)}function Ue(e){if(typeof e.ref!=`string`||e.ref.length===0)return;let t=We(e);if(t)return{ref:e.ref,...Ge(e),...t}}function We(e){let t=S(e.rect);if(!t)return;let n=S(e.overlayRect);if(!n)return;let r=_(e.center);return r?{rect:t,overlayRect:n,center:r}:void 0}function Ge(e){return typeof e.label==`string`&&e.label.length>0?{label:e.label}:{}}function Ke(e){return y(e)}var qe=e({createAgentDeviceClient:()=>Y});function Y(e={},t={}){let n=t.host??te(process),r=t.transport??pe(n);Ze(e.daemonLifecycle);let o=Qe(e.daemonBinding),s=e=>_e(e,n),{reloadMetro:l}=ge,u=e=>({...e,host:n}),p=e=>ye(u(e)),m=(e,t)=>me(u(e),t),g=(e,t)=>he(u(e),t),_=e=>ve(u(e)),v=t=>a(t.responseLevel??e.responseLevel),y=async(n,a=[],s={},c,l)=>{let u=$(e,s),d=u.requestId??ne(),f=de({signal:u.signal,requestId:d});f.refuseIfAborted();let p={session:U(u.session),command:n,positionals:a,...l?{input:l}:{},flags:le(u,c),runtime:u.runtime,meta:{...Fe(u),requestId:d,...t.devicePin?{devicePin:t.devicePin}:{}}};if(t.devicePin){let{assertRequestHonorsDevicePin:e,effectiveDevicePinSelector:n}=await import(`./device-selection-resolver.js`).then(e=>e.t);e(t.devicePin,p),Object.assign(p.flags,n(t.devicePin,p.flags))}let m=await f.guard(async()=>await r(p,{authToken:u.daemonAuthToken,signal:u.signal,daemonLifecycle:u.daemonLifecycle,...o?{daemonBinding:o}:{}}));return m.ok||i(m.error),m.data??{}},b=async(e={})=>{let t=await y(O.sessionList,[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(xe)},S=async(e,t={})=>{let r=await ue(e,t,n);return await y(r.command,r.positionals,r.options,r.metadataFlags,r.input)},C=(t={})=>U($(e,t).session);return{command:{wait:async e=>await S(`wait`,e),alert:async(e={})=>await S(`alert`,e),appState:async(e={})=>await S(`appstate`,e),back:async(e={})=>await S(`back`,e),home:async(e={})=>await S(`home`,e),orientation:async e=>await S(`orientation`,e),fold:async e=>await S(`fold`,e),appSwitcher:async(e={})=>await S(`app-switcher`,e),actionButton:async(e={})=>await S(`action-button`,e),keyboard:async(e={})=>await S(`keyboard`,e),clipboard:async e=>await S(`clipboard`,e),tvRemote:async e=>await S(`tv-remote`,e),hardwareButton:async e=>await S(`hardware-button`,e),telephony:async e=>await S(`telephony`,e),reactNative:async e=>await S(`react-native`,e),doctor:async(e={})=>await S(`doctor`,e),prepare:async e=>await S(`prepare`,e),viewport:async e=>await S(`viewport`,e)},devices:{list:async(e={})=>{let t=await S(`devices`,e);return(Array.isArray(t.devices)?t.devices:[]).map(F)},capabilities:async(e={})=>{let t=await S(`capabilities`,e),n=Array.isArray(t.availableCommands)?t.availableCommands.filter(e=>typeof e==`string`):[];return{device:F(t.device),availableCommands:n,...x(t.targetReadiness)?.press===`bounded-geometry`?{targetReadiness:{press:`bounded-geometry`}}:{}}},boot:async(e={})=>await S(`boot`,e),shutdown:async(e={})=>await S(`shutdown`,e)},sessions:{list:async(e={})=>await b(e),stateDir:async(t={})=>{let r=$(e,t);return fe(r.stateDir??n.env.AGENT_DEVICE_STATE_DIR,{env:n.env,cwd:n.cwd}).baseDir},close:async(t={})=>{let n=C(t);try{let e=await S(`close`,t);return{session:n,shutdown:B(e.shutdown),provider:x(e.provider),savedScript:h(e,`savedScript`),...W(e),identifiers:{session:n}}}finally{await p({...$(e,t),session:n})}},saveScript:async(e={})=>{let t=await y(O.sessionSaveScript,e.path===void 0?[]:[e.path],e,{force:e.force}),n=t.actionCount;if(typeof n!=`number`||!Number.isInteger(n)||n<0)throw new c(`COMMAND_FAILED`,`Daemon returned an invalid saved-script action count.`);let r=f(t,`session`);return{session:r,savedScript:f(t,`savedScript`),actionCount:n,identifiers:{session:r}}},artifacts:async(e={})=>await S(`artifacts`,e)},apps:{install:async e=>M(await S(`install`,e),C(e)),reinstall:async e=>M(await S(`reinstall`,e),C(e)),uninstall:async e=>await S(`uninstall`,e),installFromSource:async e=>N(await S(`install-from-source`,e),C(e)),list:async(e={})=>{let t=await S(`apps`,e);return Array.isArray(t.apps)?t.apps.filter(e=>typeof e==`string`):[]},open:async t=>{let n=C(t),r=await S(`open`,t);await g({...$(e,t),session:n},{explicitRuntime:t.runtime!==void 0,runtime:$(e,t).runtime,sessionReused:r.sessionReused===!0});let i=Ce(r),a=h(r,`appBundleId`),o=a;return{session:n,...W(r),sessionStateDir:h(r,`sessionStateDir`),runnerLogPath:h(r,`runnerLogPath`),requestLogPath:h(r,`requestLogPath`),eventLogPath:h(r,`eventLogPath`),appName:h(r,`appName`),appBundleId:a,appId:o,selection:Ee(r.selection),startup:De(r.startup),runtime:Se(r.runtime),device:i,...je(r),...Ae(r),identifiers:{session:n,deviceId:i?.id,deviceName:i?.name,udid:i?.ios?.udid,serial:i?.android?.serial,appId:o,appBundleId:a}}},close:async(e={})=>{let t=C(e),n=await S(`close`,e);return{session:t,closedApp:e.app,shutdown:B(n.shutdown),savedScript:h(n,`savedScript`),...W(n),identifiers:{session:t}}},push:async e=>await S(`push`,e),triggerEvent:async e=>await S(`trigger-app-event`,e)},materializations:{release:async e=>P(await y(O.releaseMaterializedPaths,[],{...e,materializationId:e.materializationId}))},leases:Ie(y),metro:{prepare:async t=>{let n=await s({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,bridgeScope:t.bridgeScope,launchUrl:t.launchUrl,companionProfileKey:t.companionProfileKey,companionConsumerKey:t.companionConsumerKey,metroPort:t.port,listenHost:t.listenHost,statusHost:t.statusHost,startupTimeoutMs:t.startupTimeoutMs,probeTimeoutMs:t.probeTimeoutMs,reuseExisting:t.reuseExisting,installDependenciesIfNeeded:t.installDependenciesIfNeeded,runtimeFilePath:t.runtimeFilePath,logPath:t.logPath});return await m({...e,session:U(e.session)},n),n},reload:async(t={})=>await l({...t,runtime:await _({...e,session:U(e.session)})??e.runtime})},capture:{snapshot:async(e={})=>{let t=C(e),n=await S(`snapshot`,e);if(v(e)){let e=d(n);return e===void 0?n:{...n,presentedSurface:e}}return Ye(n,t)},screenshot:async(e={})=>{let t=C(e),n=await S(`screenshot`,e);return v(e)?n:Re(n,t)},diff:async e=>await S(`diff`,e),audit:async e=>await S(`audit`,e??{})},interactions:{gesture:async e=>await S(`gesture`,e),click:async e=>await S(`click`,e),press:async e=>await S(`press`,e),longPress:async e=>await S(`longpress`,e),hover:async e=>await S(`hover`,e),swipe:async e=>await S(`swipe`,e),pan:async e=>await S(`gesture`,X(`pan`,e)),drag:async e=>await S(`gesture`,{...e,kind:`drag`}),fling:async e=>await S(`gesture`,Je(e)),swipeGesture:async e=>await S(`gesture`,{...e,kind:`swipe`}),focus:async e=>await S(`focus`,e),type:async e=>await S(`type`,e),fill:async e=>await S(`fill`,e),scroll:async e=>await S(`scroll`,e),pinch:async e=>await S(`gesture`,Z(`pinch`,e)),rotateGesture:async e=>await S(`gesture`,Z(`rotate`,e)),transformGesture:async e=>await S(`gesture`,X(`transform`,e)),tapGesture:async e=>await S(`gesture`,{...e,kind:`tap`}),get:async e=>await S(`get`,e),is:async e=>await S(`is`,e),find:async e=>await S(`find`,e)},replay:{run:async e=>await S(`replay`,e),test:async e=>await S(`test`,e)},batch:{run:async e=>await S(`batch`,e)},observability:{perf:async e=>await S(`perf`,e),logs:async(e={})=>await S(`logs`,e),events:async(e={})=>await S(`events`,e),network:async(e={})=>await S(`network`,e),audio:async(e={})=>await S(`audio`,e)},debug:{symbols:async t=>{let{symbolicateCrashArtifact:r}=await import(`./debug-symbols-facade.js`);return r({...t,cwd:t.cwd??e.cwd??n.cwd})}},recording:{record:async e=>await S(`record`,e),trace:async e=>await S(`trace`,e)},settings:{update:async e=>await S(`settings`,e)}}}function X(e,t){let{x:n,y:r,dx:i,dy:a,...o}=t;return{...o,kind:e,origin:{x:n,y:r},delta:{x:i,y:a}}}function Je(e){let{x:t,y:n,...r}=e;return{...r,kind:`fling`,origin:{x:t,y:n}}}function Z(e,t){let{x:n,y:r,...i}=t;if(n===void 0!=(r===void 0))throw new c(`INVALID_ARGS`,`gesture ${e} center requires both x and y`);return{...i,kind:e,...n===void 0&&r===void 0?{}:{origin:{x:n,y:r}}}}function Ye(e,t){let n=h(e,`appBundleId`);return{nodes:Pe(e.nodes),...typeof e.truncated==`boolean`?{truncated:e.truncated}:{},appName:h(e,`appName`),appBundleId:n,...Xe(e),identifiers:{session:t,appId:n,appBundleId:n}}}function Xe(e){let r=x(e.visibility),i=x(e.unchanged),a=m(e.keyboard),o=t(e.viewport),s=ee(e.snapshotDiagnostics),c=d(e),u=n(e.postGestureOutcome),{scriptDeliveryFailure:f}=W(e);return{...a?{keyboard:a}:{},...o?{viewport:o}:{},...c?{presentedSurface:c}:{},...u?{postGestureOutcome:u}:{},...r?{visibility:r}:{},...l(e),...i?{unchanged:i}:{},...s?{snapshotDiagnostics:s}:{},...f===void 0?{}:{scriptDeliveryFailure:f},...typeof e.fallbackScreenshotPath==`string`?{fallbackScreenshotPath:e.fallbackScreenshotPath}:{},...typeof e.refsGeneration==`number`?{refsGeneration:e.refsGeneration}:{}}}function Ze(e){if(e===void 0||e===`attach`||e===`managed`)return e;throw new c(`INVALID_ARGS`,`daemonLifecycle must be 'attach' or 'managed'.`,{daemonLifecycle:e})}function Qe(e){if(e===void 0)return;let t=typeof e==`object`&&e?e:void 0,n=t?.token;if(typeof n!=`string`||n.length===0)throw Q(`token`);let r=t?.pid;if(typeof r!=`number`||!Number.isSafeInteger(r)||r<=0)throw Q(`pid`);let i=t?.processStartTime;if(typeof i!=`string`||i.trim().length===0)throw Q(`processStartTime`);return{token:n,pid:r,processStartTime:i}}function Q(e){return new c(`INVALID_ARGS`,`daemonBinding is missing or invalid: ${e}.`,{daemonBindingField:e,hint:"Use the `clientConfig.daemonBinding` a host returned; a pin built by hand needs the daemon token and the pid and process start time its record published."})}function $(e,t){return{...e,...t}}export{qe as n,q as r,Y as t};