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 • 2.06 kB
import{n as e}from"./replay-divergence.js";import{d as t}from"./request.js";import{r as n}from"./dispatch-resolve.js";import{n as r,t as i}from"./script-source.js";import{n as a}from"./replay-script-selection.js";import{a as o,d as s,f as c,i as l,l as u,m as d,n as f,o as p,p as m,s as h,t as g}from"./session-replay-vars.js";async function _(n){let{req:r,sessionStore:i,observationStore:a,logPath:f,captureAction:g}=n,_=t(r.meta?.requestId),v=o(n.error),y=[...n.redactions],b=e(y),x={...v,message:b(v.message),...v.hint?{hint:b(v.hint)}:{}},S=a.get(),C=S?await u({session:S,observationStore:a,logPath:f,action:g,signal:_}):{state:`unavailable`,reason:`no-session`,hint:`The session closed before a post-failure screen could be captured.`},w=S&&C.state===`available`&&!n.isControl?c(n.suggestNodes({createdAt:Date.now(),nodes:C.nodes}).map(({node:e,basis:t})=>({node:e,nodeIndex:e.index,basis:t}))).map(({node:e,basis:t})=>h({node:e,nodes:C.nodes,session:S,action:g,basis:t,sanitize:b})):[],T={version:1,kind:`action-failure`,step:{index:n.stepIndex,source:{path:b(n.source.path??n.replayPath),line:n.source.line}},action:b(n.actionLabel),cause:{code:x.code,message:x.message,...x.hint?{hint:x.hint}:{}},screen:p(C,b),suggestions:w.slice(0,5),suggestionCount:w.length,resume:n.resume,repairHint:d({kind:`action-failure`,targetEvidence:void 0,capture:s(C)})},E=m({sessionStore:i,observationStore:a,divergence:T,responseLevel:r.meta?.responseLevel,evidence:C.state===`available`?C.evidence:void 0,..._?{signal:_}:{}});return l({error:x,actionLabel:n.actionLabel,action:n.action,positionals:[...g.positionals],step:n.stepIndex,replayPath:n.replayPath,artifactPaths:[...n.artifactPaths],snapshotDiagnostics:n.snapshotDiagnostics,divergence:E,scrubVars:y,warnings:n.warnings})}function v(){return{appendTraceEvent:f,buildBuiltinVars:e=>g({...e,metadata:{}}),readScriptSourceFile:r,scriptSourceRequiredMessage:i,requestSignal:t,resolveTargetDevice:async(e,t,r)=>await n(e,a(t.appTarget,t.platform,r)),buildActionFailureResponse:_}}export{v as createReplayBackendHost};