UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 6.62 kB
import{t as asNonArrayRecord}from"./record-coerce-BTbqdJ3-.mjs";import{C as isOneShotRunSessionKey}from"./session-key-BPgKfU2m.mjs";import{r as addSafeTimeoutDelayGraceMs}from"./timeouts-Dzxxy4Mb.mjs";import{n as isRequestedExecTargetAllowed,o as resolveRequestedExecTarget}from"./bash-tools.exec-target-CnAB4few.mjs";import{t as createCachedToolSchema}from"./cached-schema-CmCgkbgz.mjs";import{t as optionalStringEnum}from"./string-enum-BHQI27hJ.mjs";import{r as executionTitleSchema}from"./typebox-pxCMyoM2.mjs";import{Type}from"typebox"; //!src/agents/bash-tools.schemas.ts const EXEC_TOOL_HOST_VALUES=[`auto`,`sandbox`,`gateway`,`node`];const PROCESS_TOOL_ACTIONS=[`list`,`poll`,`log`,`write`,`send-keys`,`submit`,`paste`,`kill`,`clear`,`remove`];const execSchema=Type.Object({title:executionTitleSchema(),command:Type.String({description:`Shell command.`}),workdir:Type.Optional(Type.String({description:`Omit/empty string: default; whitespace-only invalid.`})),env:Type.Optional(Type.Record(Type.String(),Type.String(),{description:`Literal overrides; no expansion. Omit to inherit.`})),yieldMs:Type.Optional(Type.Number({description:`Milliseconds before returning an ordinary-command handle; default 10000, max 120000.`})),awaitResults:Type.Optional(Type.Boolean({description:`Result required to finish the task; wait for terminal collection. Not for detached servers.`})),background:Type.Optional(Type.Boolean({description:`Start an independent service now. It keeps running after this call, the turn, request Stop and a one-shot CLI exit; session reset, new, delete or archive stops it, and a subagent's services stop when the subagent ends; stop it earlier with process kill. Use yieldMs for ordinary work. No built-in timeout; timeoutSeconds or a configured default applies.`})),durable:Type.Optional(Type.Boolean({description:`Survive Gateway restart using Linux systemd user services or macOS launchd jobs; requires background or yieldMs. No interactive input or proxy-backed secrets.`})),timeoutSeconds:Type.Optional(Type.Number({description:`Process lifetime in seconds; 0 disables.`})),pty:Type.Optional(Type.Boolean({description:`PTY for TTY-required CLIs/coding agents.`})),elevated:Type.Optional(Type.Boolean({description:`Host elevation if allowed.`})),host:optionalStringEnum(EXEC_TOOL_HOST_VALUES,{description:`Omit: named node or configured host. auto: configured host.`}),ask:Type.Optional(Type.String({description:`Requests stricter approvals under tools.exec.mode and host policy; channel-origin calls cannot override host ask=off.`})),node:Type.Optional(Type.String({description:`Node id/name; implies host=node if host is omitted. Other hosts conflict.`}))});function createExecSchema(e){return execSchemas(e).standard}function createExecCompletionSchema(e){return execSchemas(e).completion}const execSchemas=createCachedToolSchema({key:e=>`${e?.sandboxRequired?`sandbox`:e?.host??`auto`}:${Boolean(e?.sandbox)}`,build:buildExecSchemas});function buildExecSchemas(e){const t=Boolean(e?.sandbox);const n=e?.sandboxRequired?`sandbox`:e?.host??`auto`;const r=EXEC_TOOL_HOST_VALUES.filter(e=>e===`auto`||(e!==`sandbox`||t)&&isRequestedExecTargetAllowed({configuredTarget:n,requestedTarget:e,sandboxAvailable:t}));const i=Type.Object({...execSchema.properties,host:optionalStringEnum(r,{description:`Omit: named node or configured host (${n===`auto`?t?`sandbox`:`gateway`:n}). auto: configured host.`})});return{standard:i,completion:Type.Omit(i,[`yieldMs`,`background`,`durable`])}}const nodeExecSchema=Type.Object({title:execSchema.properties.title,command:execSchema.properties.command,workdir:execSchema.properties.workdir,env:execSchema.properties.env,timeoutSeconds:execSchema.properties.timeoutSeconds,host:optionalStringEnum([`node`],{description:`Exec target. Only node is available on this tool surface.`}),node:execSchema.properties.node});const PROCESS_OBSERVATION_REPEATABLE={actions:[`list`,`poll`,`log`]};function isProcessObservationAction(e){const t=asNonArrayRecord(e).action;return typeof t===`string`&&PROCESS_OBSERVATION_REPEATABLE.actions.some(e=>e===t)}const processSchema=Type.Object({action:Type.String({enum:[...PROCESS_TOOL_ACTIONS],description:`Process action (list|poll|log|write|send-keys|submit|paste|kill|clear|remove)`}),sessionId:Type.Optional(Type.String({description:`Required for every action except list.`})),data:Type.Optional(Type.String({description:`Data to write for write`})),keys:Type.Optional(Type.Array(Type.String(),{description:`Key tokens to send for send-keys`})),hex:Type.Optional(Type.Array(Type.String(),{description:`Hex bytes to send for send-keys`})),literal:Type.Optional(Type.String({description:`Literal string for send-keys`})),text:Type.Optional(Type.String({description:`Text to paste for paste`})),bracketed:Type.Optional(Type.Boolean({description:`Wrap paste in bracketed mode`})),eof:Type.Optional(Type.Boolean({description:`Close stdin after write`})),offset:Type.Optional(Type.Number({description:`Log offset`})),limit:Type.Optional(Type.Number({description:`Log length`})),timeout:Type.Optional(Type.Number({description:`For poll: wait up to this many milliseconds before returning; max 30000 ms, higher values are clamped to 30000`,minimum:0}))}); //!src/agents/exec-tool-timeout.ts function resolveExecDefaultTimeoutSec(e){return e&&e>0?e:1800}function resolveExecTimeoutDefaults(e){const t=e?.timeoutSec;const n=resolveExecDefaultTimeoutSec(t);const r=e?.notifySessionKey??e?.runSessionKey??e?.sessionKey;const i=isOneShotRunSessionKey(r);return[n,r=>(r||i)&&e?.sessionsYieldAvailabilityRef?.value===true?n:t&&t>0?t:null]}function resolveNodeExecTimeouts(e,t){const n=typeof e===`number`&&Number.isFinite(e)?e:t;const r=Number.isFinite(n)&&n>0?n:t;const i=!Number.isFinite(r)||r<=0?1e4:Math.max(1e4,addSafeTimeoutDelayGraceMs(r*1e3,5e3));return{runTimeoutMs:Number.isFinite(n)&&n>0?addSafeTimeoutDelayGraceMs(n*1e3,0,{minMs:0}):0,invokeDeadlineMs:i,invokeWaitMs:addSafeTimeoutDelayGraceMs(i,5e3)}}function createExecToolExecutionTimeoutResolver(e){const t=resolveExecDefaultTimeoutSec(e?.timeoutSec);const n=e?.host;return e=>{const r=asNonArrayRecord(e);const i=resolveRequestedExecTarget(r);if((i&&i!==`auto`?i:n)!==`node`)return;return resolveNodeExecTimeouts(typeof r.timeoutSeconds===`number`?r.timeoutSeconds:void 0,t).invokeWaitMs}}export{createExecCompletionSchema as a,isProcessObservationAction as c,PROCESS_OBSERVATION_REPEATABLE as i,nodeExecSchema as l,resolveExecTimeoutDefaults as n,createExecSchema as o,resolveNodeExecTimeouts as r,execSchema as s,createExecToolExecutionTimeoutResolver as t,processSchema as u};