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 • 623 B
const e=new Set;function t(t={}){let r=new Map,i=t.now??(()=>Date.now()),a=e=>{e?.timer&&clearTimeout(e.timer)},o={get(e){let t=r.get(e);if(t){if(t.expiresAt!==void 0&&t.expiresAt<=i()){o.delete(e);return}return t.value}},set(e,o){a(r.get(e));let s=n(t.ttlMs,i),c={value:o,expiresAt:s};t.scheduleExpiry&&s!==void 0&&(c.timer=setTimeout(()=>{r.delete(e)},Math.max(0,s-i())),c.timer.unref?.()),r.set(e,c)},delete(e){let t=r.get(e);return t?(a(t),r.delete(e)):!1},clear(){for(let e of r.values())a(e);r.clear()}};return e.add(o.clear),o}function n(e,t){if(!(e===void 0||!Number.isFinite(e)))return t()+Math.max(0,e)}export{t};