openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.85 kB
JavaScript
import{o as writeRuntimeJson,r as defaultRuntime}from"../runtime-DIcLIHcp.mjs";import{t as _usingCtx}from"../usingCtx-CUVyQ_FT.mjs";import{a as isPersistentSystemAgentOperation,s as parseSystemAgentOperation}from"../operations-parse-Cg7QWEil.mjs";import{t as executeSystemAgentOperation}from"../operations-H7jZftg1.mjs";import{r as withProgress}from"../progress-BcNIavn6.mjs";import{n as requireSystemAgentPersistentApplyInference,r as SystemAgentInferenceUnavailableError,t as requireSystemAgentInferenceRoute}from"../inference-guard-u0LFXoxk.mjs";import{i as loadSystemAgentOverview,n as formatSystemAgentOverview}from"../overview-Cu_HscGr.mjs";import{r as hasCurrentSystemAgentOwnerPluginArtifacts}from"../verified-inference-C2wCwCrh.mjs";import{c as resolveSystemAgentOperation}from"../dialogue-DuFogy1g.mjs";import{stdin,stdout}from"node:process";
//!src/system-agent/system-agent.ts
async function runOneShot(e,t,n){if(e.kind===`none`&&e.message===``)return;await requireSystemAgentInferenceRoute(n.verifiedInference,`conversation`);const r=n.yes===true||!isPersistentSystemAgentOperation(e);if(r&&isPersistentSystemAgentOperation(e))await requireSystemAgentPersistentApplyInference({binding:n.verifiedInference,runtime:t},e=>{if(e[0]instanceof SystemAgentInferenceUnavailableError)throw e[0];throw new SystemAgentInferenceUnavailableError(`conversation`,e,`route-changed`)});await executeSystemAgentOperation(e,t,{approved:r})}async function runSystemAgent(e,t=defaultRuntime){try{var n=_usingCtx();const r=e?.verifiedInference;if(!r)throw new SystemAgentInferenceUnavailableError(`conversation`);const i={...e,verifiedInference:r};const run=()=>runBoundSystemAgent(i,t);const a=r.execution;if(a.runner!==`embedded`||a.agentHarnessRuntimeOverride===`openclaw`)return await run();const{resolveAgentWorkspaceDir:o}=await import(`../agent-scope-FEZ3WYd3.mjs`);const{loadAgentRuntimePluginRegistryHandle:s}=await import(`../runtime-plugins-BdbkeGCz.mjs`);const{withPluginLifecycleLeaseAsync:c}=await import(`../plugin-lifecycle-lease-DXYQ3mrW.mjs`);const{createPluginCache:l,withPluginCache:u}=await import(`../plugin-cache-Blu0DQOb.mjs`);const{withPluginRuntimeRegistryScope:d}=await import(`../gateway-request-scope-BS6Ldhu6.mjs`);const f=n.a(l());const{readConfigFileSnapshot:p}=await import(`../config/config.js`);await d(await c({},async e=>{const t=await p();if(!await hasCurrentSystemAgentOwnerPluginArtifacts(r,t))throw new SystemAgentInferenceUnavailableError(`conversation`,[],`route-changed`);const n=t.runtimeConfig??t.config;const i=o(n,a.agentId);await e.assertOwned();return u(f,()=>s({basePluginIds:[],config:n,workspaceDir:i,selections:[{provider:a.provider,modelId:a.model,runtime:a.agentHarnessRuntimeOverride,agentId:a.agentId}]}))}),run)}catch(e){n.e=e}finally{await n.d()}}async function runBoundSystemAgent(e,t){await requireSystemAgentInferenceRoute(e.verifiedInference,`conversation`);if(e.json){const e=await loadSystemAgentOverview();writeRuntimeJson(t,e);return}if(e.message?.trim()){const n=parseSystemAgentOperation(e.message);if(n.kind===`overview`){await runOneShot(n,t,e);return}const r=await withProgress({label:`Loading OpenClaw overview…`,indeterminate:true,delayMs:0,fallback:`none`},async()=>await loadSystemAgentOverview());t.log(formatSystemAgentOverview(r));t.log(``);await runOneShot(await resolveSystemAgentOperation(e.message,t,{...e,loadOverview:async()=>r}),t,e);return}if(e.interactive===false){const e=await loadSystemAgentOverview();t.log(formatSystemAgentOverview(e));return}const n=e.input??stdin;const r=e.output??stdout;const i=n.isTTY===true;const a=r.isTTY===true;if(!i||!a){t.error(`OpenClaw needs an interactive TTY. Use --message for one command.`);t.exit(1);return}const{runSystemAgentTui:o}=await import(`../tui-backend-CqpkzAKp.mjs`);e.onReady?.();await o(e,t)}export{runSystemAgent};