UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.66 kB
import{m as readNonBlankString}from"./string-coerce-CpTFcSwY.mjs";import{t as isPlainObject}from"./plain-object-CHrMoU5Q.mjs";import{t as mergeDeep}from"./deep-merge-BcazJ3mu.mjs";import{n as formatConfigIssueLines}from"./issue-format-CeCSO2Ku.mjs";import{t as readByteStreamWithLimit}from"./read-byte-stream-with-limit-Ockoa332.mjs";import{createReadStream,existsSync}from"node:fs";import path from"node:path";import{TextDecoder}from"node:util"; //!src/commands/agent-exec-input.ts const AGENT_EXEC_MESSAGE_MAX_BYTES=4194304;const UTF8_DECODER=new TextDecoder(`utf-8`,{fatal:true});async function resolveAgentExecPrompt(e,t){const n=readNonBlankString(t);if(e!==void 0&&n)throw new Error(`Use either the prompt argument or --message-file, not both.`);if(t!==void 0&&!n)throw new Error(`--message-file must not be empty.`);if(n){const e=n===`-`?process.stdin:createReadStream(n);try{const t=n===`-`?`stdin`:`Message file ${n}`;const r=await readByteStreamWithLimit(e,{maxBytes:AGENT_EXEC_MESSAGE_MAX_BYTES,onOverflow:()=>/* @__PURE__ */ new Error(`${t} exceeds ${String(AGENT_EXEC_MESSAGE_MAX_BYTES)} bytes`)});let i;try{i=UTF8_DECODER.decode(r).replace(/^\uFEFF/,``)}catch{throw new Error(`${t} must be valid UTF-8`)}if(!i.trim())throw new Error(`${t} is empty`);return i}catch(e){if(n===`-`||!(e instanceof Error)||!(`code`in e))throw e;if(e.code===`ENOENT`)throw new Error(`Message file not found: ${n}`,{cause:e});throw e}}if(!e?.trim())throw new Error(`Missing prompt. Pass text or use --message-file <path>.`);return e}function buildExecConfigDefaults(){return{env:{shellEnv:{enabled:false}},agents:{defaults:{sandbox:{mode:`off`}}},tools:{profile:`coding`,fs:{workspaceOnly:true},exec:{mode:`full`}}}}async function resolveExecBaseConfig(e){if(e.configOverride?.length&&e.authEnvOnly===true)throw new Error(`--config-override cannot be combined with --auth-env-only.`);if(e.config&&(e.isolated||e.authEnvOnly===true)){const t=e.isolated?`--isolated`:`--auth-env-only`;throw new Error(`--config cannot be combined with ${t}.`)}if(e.isolated||e.authEnvOnly===true){const{applyImplicitAgentRosterDefaults:e}=await import(`./implicit-agent-roster-rw3rmRZt.mjs`);const{coerceConfig:t}=await import(`./io.read-helpers-Dy7TdS1M.mjs`);return t(e({}))}const{createConfigIO:t,getRuntimeConfigSnapshot:n}=await import(`./io-Daz-kTPd.mjs`);const r=!e.config&&n();if(r)return r;const i=t({...e.config?{configPath:path.resolve(e.config)}:{},observe:false});if(e.config&&!existsSync(i.configPath))throw new Error(`--config file not found: ${i.configPath}`);const{config:a,sourceConfig:o,configDiagnostics:s}=await i.readBestEffortConfigSnapshot();if(s){const{createInvalidConfigError:e,formatInvalidConfigDetails:t}=await import(`./io.invalid-config-Cw04snJA.mjs`);throw e(s.path,t(s.issues))}const{captureRuntimeConfigWithSource:c}=await import(`./runtime-config-capture-state-FXjuWUho.mjs`);const{applyConfigOverrides:l}=await import(`./runtime-overrides-DlnVZ-Ac.mjs`);return c(a,l(o))}async function applyExecConfigOverrides(e,t=[]){if(t.length===0)return e;const n=t.map(e=>{let t;try{t=JSON.parse(e)}catch{throw new Error(`--config-override must contain valid JSON.`)}if(!isPlainObject(t))throw new Error(`--config-override must be a JSON object.`);return t});const r=n.reduce((e,t)=>mergeDeep(e,t),e);const{validateConfigObjectWithPlugins:i}=await import(`./validation-DA9hNnzv.mjs`);const a=i(r);if(!a.ok)throw new Error(`Invalid --config-override: ${formatConfigIssueLines(a.issues,``,{normalizeRoot:true}).join(`; `)}`);const{captureRuntimeConfigWithSource:o}=await import(`./runtime-config-capture-state-FXjuWUho.mjs`);const{projectConfigOntoRuntimeSourceSnapshot:s}=await import(`./runtime-source-projection-CGuBxAdR.mjs`);const{coerceConfig:c}=await import(`./io.read-helpers-Dy7TdS1M.mjs`);const l=n.reduce((e,t)=>mergeDeep(e,t),s(e));return o(a.config,c(l))}function buildExecRunConfig(e){const t=e.opts??{};const{base:n,cwd:r}=e;const{session:i,...a}=n;const{store:o,...s}=i??{};const c=i?{...a,session:s}:n;const l=c.agents?.entries;const u=l?{...c,agents:{...c.agents,entries:Object.fromEntries(Object.entries(l).map(([e,t])=>{const{agentDir:n,runtime:i,...a}=t;if(i?.type!==`acp`||i.acp?.cwd===void 0)return[e,{...a,workspace:r,...i?{runtime:i}:{}}];const{cwd:o,...s}=i.acp;return[e,{...a,workspace:r,runtime:{...i,acp:s}}]}))}}:c;return mergeDeep(mergeDeep(buildExecConfigDefaults(),u),{agents:{defaults:{workspace:e.cwd,skipBootstrap:true,...t.localModelLean?{experimental:{localModelLean:true}}:{}}},skills:{load:{watch:false}}})}export{resolveExecBaseConfig as i,buildExecRunConfig as n,resolveAgentExecPrompt as r,applyExecConfigOverrides as t};