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 • 1.42 kB
JavaScript
import{S as e}from"./sdk-batch.js";import{v as t}from"./sdk-contracts.js";import{t as n}from"./src.js";import{i as r,n as i,r as a,t as o}from"./command-tools.js";const s=[`session`,...r];async function c(r){let{jsonSchema:c,tool:f}=await l(),{session:p,platform:m,set:h=`core`,approval:g}=r,_=n({session:p,...m?{lockPlatform:m}:{}}),v=o({structuredContent:`always`}),y=new Set(s);m&&y.add(`platform`);let b={};for(let n of i({outputSchemas:!0})){let r=e(n.name);(h!==`core`||r===`core`||r===`loop`)&&(b[n.name]=f({description:n.description,inputSchema:c(u(n.inputSchema,y)),...n.outputSchema?{outputSchema:c(n.outputSchema)}:{},execute:async(e,{abortSignal:r})=>{let i={...d(e,y),session:p,...m?{platform:m}:{}},o=await v.execute(n.name,i,{signal:r});if(o.isError){let e=o.structuredContent,n=a(e);throw new t(e.code,n,e.details)}return o.structuredContent??{}}}))}return{tools:b,client:_,...g?{toolApproval:g}:{}}}async function l(){try{return await import(`ai`)}catch(e){throw new t(`MISSING_PEER_DEPENDENCY`,"createAgentDeviceTools() requires the optional peer dependency 'ai'. Install it with `pnpm add ai` (or npm/yarn equivalent).",void 0,e)}}function u(e,t){if(!e.properties)return e;let n=e.required?.filter(e=>!t.has(e));return{...e,properties:d(e.properties,t),...n?{required:n}:{}}}function d(e,t){let n={};for(let[r,i]of Object.entries(e))t.has(r)||(n[r]=i);return n}export{c as createAgentDeviceTools};