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 • 2.5 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{B as t,v as n}from"./sdk-contracts.js";import"./file.js";import{a as r,i,o as a}from"./verified-file.js";import{t as o}from"./app-log-durable-resource.js";import{r as s}from"./session-capture-binding.js";import{t as c}from"./app-log-files.js";import l from"node:fs";import u from"node:path";function d(e){let t=r(e);if(t===void 0)return{exists:!1,sizeBytes:0};try{let e=l.fstatSync(t);return{exists:!0,sizeBytes:e.size,modifiedAt:e.mtime.toISOString()}}finally{l.closeSync(t)}}function f(e,t,n){c(e,n);let r=`[agent-device][mark][${new Date().toISOString()}] ${t.trim()||`marker`}\n`,a=i(e);try{l.writeFileSync(a,r,`utf8`)}finally{l.closeSync(a)}}function p(e){let t=u.dirname(e),n=u.basename(e);l.existsSync(t)||l.mkdirSync(t,{recursive:!0});let r=a(e);try{l.fsyncSync(r)}finally{l.closeSync(r)}let i=0;for(let e of l.readdirSync(t)){if(!e.startsWith(`${n}.`))continue;let r=e.slice(n.length+1);if(/^\d+$/.test(r))try{l.unlinkSync(u.join(t,e)),i+=1}catch{}}return{path:e,cleared:!0,removedRotatedFiles:i}}var m=e({adoptStartedSessionAppLog:()=>g,bindSessionAppLog:()=>b,clearStoppedSessionAppLog:()=>x,finishSessionAppLog:()=>_,forceCleanupSessionAppLog:()=>v,inspectSessionAppLog:()=>h,recordSessionAppLogFailure:()=>y});function h(e){if(e.appLog){let t=e.appLog.handle.inspect();return{active:t.state===`active`||t.state===`recovering`,...t}}return e.appLogFailure?{active:!1,state:`failed`,backend:e.appLogFailure.backend,failureCode:e.appLogFailure.code,failureMessage:e.appLogFailure.message,hint:e.appLogFailure.hint}:{active:!1,state:`inactive`}}function g(e){return o.adoptStarted({...e,binding:b(e.sessionStore,e.ref)})}function _(e){return o.finishLive({binding:b(e.sessionStore,e.ref),intent:e.intent})}function v(e){return o.forceCleanupLive({binding:b(e.sessionStore,e.ref)})}function y(e){let n=t(e.error),r=e.sessionStore.resolveCurrent(e.ref);return!r||r.appLog||e.sessionStore.update(e.ref,{appLog:void 0,appLogFailure:{backend:e.backend,code:n.code,message:n.message,hint:n.hint}}),n}function b(e,t){return s(e,t,{read:e=>e.appLog,write:n=>{e.update(t,{appLog:n,appLogFailure:void 0})}})}function x(e){if(e.sessionStore.requireCurrent(e.ref).appLog)throw new n(`INVALID_ARGS`,`logs clear requires logs to be stopped first; run logs stop`);let t=p(e.sessionStore.resolveAppLogPath(e.ref.address));return e.sessionStore.update(e.ref,{appLogFailure:void 0}),t}export{_ as a,f as c,x as i,d as l,m as n,h as o,b as r,y as s,g as t};