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 • 3.56 kB
import{j as e}from"./sdk-batch-runner.js";const t={ios:!0,macos:!0,android:!0,harmonyos:!0,vega:!0,linux:!0,web:!0},n=1500;function r(e,t){e&&(e.snapshotDiagnostics??={samples:[]}).samples.push({...t,durationMs:Math.max(0,Math.round(t.durationMs))})}function i(e){let t=e?.snapshotDiagnostics?.samples;if(!(!t||t.length===0))return a(t)}function a(e){if(e.length===0)return;let t=e.slice(1),r=t.length>=3?c(t):void 0,i=t.filter(e=>e.durationMs>=n).length,a=r!==void 0&&r.p95Ms>=n&&i>=2;return{stats:c(e),...a&&r?{warning:p(r)}:{}}}function o(e){let t=e.filter(e=>e!==void 0),n=t.flatMap(e=>x(e.stats));if(n.length===0)return;let r={...S(n),...l(t)},i=t.filter(e=>e.warning);return{stats:r,...i.length>0?{warning:m({warnedCount:i.length,totalCount:t.length,worst:i.reduce((e,t)=>Math.max(e,t.stats.p95Ms),0),platform:r.platform})}:{}}}function s(t){if(!e(t))return;let n=h(t.stats);if(!n)return;let r=typeof t.warning==`string`?t.warning:void 0;return{stats:n,...r?{warning:r}:{}}}function c(e){let t=e.map(e=>e.durationMs).sort((e,t)=>e-t);return{count:t.length,p50Ms:u(t,50),p95Ms:u(t,95),maxMs:t.at(-1)??0,slowThresholdMs:n,...d(e),...f(e)}}function l(e){let t={};for(let[n,r]of e.flatMap(e=>Object.entries(e.stats.backends??{})))t[n]=(t[n]??0)+r;return Object.keys(t).length>0?{backends:t}:{}}function u(e,t){if(e.length===0)return 0;let n=Math.max(0,Math.ceil(t/100*e.length)-1);return e[Math.min(n,e.length-1)]??0}function d(e){let t=e.map(e=>e.platform).filter(e=>!!e);return new Set(t).size===1?{platform:t[0]}:{}}function f(e){let t={};for(let n of e){let e=n.producer??n.backend;e&&(t[e]=(t[e]??0)+1)}return Object.keys(t).length>0?{backends:t}:{}}function p(e){return`Warning: ${e.platform?`${e.platform} `:``}snapshots are slow in this run: p95 ${e.p95Ms}ms over ${e.count} captures. Possible causes: device load, app or dev server stuck, helper fallback, or stale daemon.`}function m(e){return`Warning: ${e.platform?`${e.platform} `:``}snapshots were slow in ${e.warnedCount} of ${e.totalCount} runs (worst run p95 ${e.worst}ms). Possible causes: device load, app or dev server stuck, helper fallback, or stale daemon.`}function h(t){if(!e(t))return;let n=g(t);if(n)return{...n,...v(t)}}function g(e){let t={count:e.count,p50Ms:e.p50Ms,p95Ms:e.p95Ms,maxMs:e.maxMs,slowThresholdMs:e.slowThresholdMs};if(!Number.isSafeInteger(t.count)||t.count<0)return;let n=[t.p50Ms,t.p95Ms,t.maxMs,t.slowThresholdMs];if(!n.every(b))return;let[r,i,a]=n;if(!(r>i||i>a))return t}function _(e){let t=Object.entries(e).filter(e=>Number.isSafeInteger(e[1])&&e[1]>=0);return t.length>0?Object.fromEntries(t):void 0}function v(t){let n=y(t.platform)?t.platform:void 0,r=e(t.backends)?_(t.backends):void 0;return{...n?{platform:n}:{},...r?{backends:r}:{}}}function y(e){return typeof e==`string`&&Object.hasOwn(t,e)}function b(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function x(e){let{count:t,platform:n}=e;return t<=0?[]:t===1?[{durationMs:e.maxMs,weight:1,platform:n}]:t===2?[{durationMs:e.p50Ms,weight:1,platform:n},{durationMs:e.maxMs,weight:1,platform:n}]:[{durationMs:e.p50Ms,weight:t-2,platform:n},{durationMs:e.p95Ms,weight:1,platform:n},{durationMs:e.maxMs,weight:1,platform:n}]}function S(e){let t=[...e].sort((e,t)=>e.durationMs-t.durationMs),r=t.reduce((e,t)=>e+t.weight,0);return{count:r,p50Ms:C(t,r,50),p95Ms:C(t,r,95),maxMs:t.at(-1)?.durationMs??0,slowThresholdMs:n,...d(t)}}function C(e,t,n){let r=Math.max(1,Math.ceil(n/100*t)),i=0;for(let t of e)if(i+=t.weight,i>=r)return t.durationMs;return e.at(-1)?.durationMs??0}export{a,i,s as n,r,o as t};