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 • 2.01 kB
import{v as e}from"./sdk-contracts.js";import{f as t,g as n,m as r}from"./lease-registry-scope.js";const i=`/admin/human-control/holds`;function a(t){let n=s(t,`Human-control request body`),r=n.reason;if(r!==void 0&&(typeof r!=`string`||r.trim().length>512))throw new e(`INVALID_ARGS`,`Human-control reason must be at most 512 characters.`);let i=n.ttlMs;if(i!==void 0&&(typeof i!=`number`||!Number.isInteger(i)||i<1e3||i>864e5))throw new e(`INVALID_ARGS`,`Human-control ttlMs must be between 1000 and 86400000.`);return{...n.scope===void 0?{}:{scope:o(n.scope)},...typeof r==`string`&&r.trim()?{reason:r.trim()}:{},...typeof i==`number`?{ttlMs:i}:{}}}function o(i){let a=s(i,`Host human-control scope`);if(typeof a.backend!=`string`||!a.backend.trim()||typeof a.deviceKey!=`string`)throw new e(`INVALID_ARGS`,`Host human control requires scope.backend and scope.deviceKey.`);if(a.leaseProvider!==void 0&&typeof a.leaseProvider!=`string`)throw new e(`INVALID_ARGS`,`scope.leaseProvider must be a string.`);let o=n(a.leaseProvider);return{backend:r(a.backend),deviceKey:t(a.deviceKey),...o?{leaseProvider:o}:{}}}function s(t,n){if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`${n} must be an object.`);return t}function c(t){let n=typeof t==`string`?t.trim():``;if(!/^[a-zA-Z0-9._-]{1,128}$/.test(n))throw new e(`INVALID_ARGS`,`Invalid human-control hold id. Use 1-128 chars: letters, numbers, dot, underscore, hyphen.`);return n}function l(e){return{...e,scope:{...e.scope}}}function u(t){return new e(`DEVICE_IN_USE`,`A human is interacting with this simulator or device; agent interactions are temporarily disabled.`,{reason:`human_control_active`,blockedBy:`human_control`,holdId:t.id,deviceKey:t.scope.deviceKey,pausedAt:new Date(t.createdAt).toISOString(),...t.expiresAt===void 0?{}:{expiresAt:new Date(t.expiresAt).toISOString()},...t.reason?{humanReason:t.reason}:{},hint:`Wait until the human-control hold is released before retrying.`})}export{a,c as i,l as n,u as r,i as t};