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.

3 lines • 2.2 kB
import{v as e}from"./sdk-contracts.js";import{Tt as t}from"./sdk-io.js";import"./diagnostics.js";import{c as n,r,x as i}from"./src3.js";import{t as a}from"./src7.js";const o=n();function s(e,t,n){let r=o[e];if(!r)throw Error(`Missing CLI reader for command: ${e}`);return{...r(t,n),...i(e,n)}}const c=65536;async function l(t){if(t.isTTY)throw new e(`INVALID_ARGS`,`fill --text-stdin reads piped input, but stdin is a terminal.`,{reason:`fill_text_stdin_tty`,hint:`Pipe the text in, for example: printf %s "$PASSWORD" | agent-device fill @e3 --text-stdin`});let n=[],r=0,i=``;for await(let a of t){let t=f(i,a);if(i=t.held,r+=p(t.piece),r>65536)throw new e(`INVALID_ARGS`,`fill --text-stdin accepts at most ${c} bytes of input.`,{reason:`fill_text_stdin_too_large`,maxBytes:c});n.push(m(t.piece))}if(i)throw g();let a=_(h(Buffer.concat(n)));if(a===``)throw new e(`INVALID_ARGS`,`fill --text-stdin received no text.`,{reason:`fill_text_stdin_empty`,hint:`Check that the piped value is set. To clear a field, pass an empty text argument instead: fill @e3 ""`});return a}const u=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/,d=/[\uD800-\uDBFF]$/;function f(e,t){if(typeof t!=`string`){if(e)throw g();return{piece:t,held:``}}let n=e+t;return d.test(n)?{piece:n.slice(0,-1),held:n.slice(-1)}:{piece:n,held:``}}function p(e){return typeof e==`string`?Buffer.byteLength(e,`utf8`):e.byteLength}function m(e){if(typeof e!=`string`)return e;if(u.test(e))throw g();return Buffer.from(e,`utf8`)}function h(e){try{return new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e)}catch{throw g()}}function g(){return new e(`INVALID_ARGS`,`fill --text-stdin input is not valid UTF-8.`,{reason:`fill_text_stdin_invalid_utf8`})}function _(e){return e.endsWith(`\r `)?e.slice(0,-2):e.endsWith(` `)?e.slice(0,-1):e}async function v(e){return(await y(e)).result}async function y(e){let n=s(e.command,e.positionals,e.flags);if(e.flags.textStdin){let e=await l(process.stdin);t(e),n.text=e}let i=await r(e.client,e.command,n);return{result:i,cliOutput:await a({name:e.command,input:n,result:i,progress:e.commandProgress,env:e.env,stderrIsTTY:!!process.stderr.isTTY})}}export{y as n,v as t};