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.
2 lines • 2.5 kB
JavaScript
import{B as e,H as t,W as n,v as r}from"./sdk-contracts.js";import{n as i}from"./success-text.js";import{t as a}from"./output-common.js";import{r as o}from"./replay-divergence.js";const s={no:`Not dispatched.`,unknown:`May have reached the device.`};function c(t,i={}){let a=t instanceof r?e(t):t,o=n(a.details),s=a.code===`AMBIGUOUS_MATCH`?m(o):void 0,c=i.reader===`model`,{summary:u,truncated:d}=l(a,s,i.synopsis,c);return{summary:u,body:f(a,{fullMessage:d,candidateViews:s?[]:o,showDetails:i.showDetails})}}function l(e,n,r,i){let a=t(e.details),o=g(e.message),c=o.length>300?`${o.slice(0,300)}…`:o,l=u(e,a,n,r),f=i?d(e):void 0;return{summary:[`Error (${f?`${e.code}, ${f}`:e.code}): ${_(c)}`,...a?[s[a]]:[],...l?[`Next: ${l}`]:[]].join(` `),truncated:c!==o}}function u(e,t,n,r){let i=e.hint?g(e.hint):void 0,a=[...t===`unknown`?[`Run snapshot to check the screen before you retry.`]:[],...n?[`Act on one ref with a command that takes refs, such as press: ${n.join(`; `)}`]:i?[i]:[],...r&&e.code===`INVALID_ARGS`?[`Usage: ${r}`]:[]];return a.length>0?a.join(` `):void 0}function d(e){let t=e.details?.reason;if(typeof t!=`string`)return;let n=g(t);if(n.length!==0)return n.length>80?`${n.slice(0,80)}…`:n}function f(e,t){let n=[];if(t.fullMessage&&n.push(`Message: ${e.message}`),e.cause){let t=e.cause.code?`${e.cause.code} `:``;n.push(`Cause: ${t}${e.cause.message}`)}for(let t of i(e.details))n.push(`Warning: ${a(t)}`);let r=v(t.candidateViews);r.length>0&&n.push(r.join(`
`));let s=p(e);s&&n.push(s);let c=o(e.details);return c&&n.push(c),t.showDetails&&e.details&&n.push(JSON.stringify(e.details,null,2)),n}function p(e){if(e.logPath)return`Log: ${e.logPath}`;if(e.logPathUnavailable)return`Log: unavailable (${e.logPathUnavailable})`}function m(e){let[t,...n]=e;if(!t||n.length>0||t.kind!==`element-match`||t.matches<2||t.matches>3||t.candidates.length!==t.matches)return;let r=t.candidates.map(e=>g(y(e,t.refsGeneration)));return new Set(r.map(e=>e.replace(h,``))).size===r.length?r:void 0}const h=/^@e\d+(?:~s\d+)?\s*/;function g(e){return e.replaceAll(/\s+/g,` `).trim()}function _(e){return/[.!?…]$/.test(e)?e:`${e}.`}function v(e){return e.flatMap(e=>{if(e.kind===`element-match`){let t=e.matches-e.candidates.length;return[`Candidates:`,...e.candidates.map(t=>` ${y(t,e.refsGeneration)}`),...t>0?[` +${t} more`]:[]]}return[`Devices:`,...e.devices.map(e=>` ${e.id} ${e.name}`)]})}function y(e,t){return t===void 0?e:e.replace(/^@(e\d+)(?=\s|$)/,`@$1~s${t}`)}export{c as t};