UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

115 lines (114 loc) • 4.47 kB
import { o as writeRuntimeJson, r as defaultRuntime } from "../runtime-B-SLYP-m.mjs"; import { t as _usingCtx } from "../usingCtx-rhpPzaNq.mjs"; import { a as isPersistentSystemAgentOperation, o as parseSystemAgentOperation } from "../operations-parse-DoFrSk0v.mjs"; import { t as executeSystemAgentOperation } from "../operations-CBf52_6Y.mjs"; import { r as withProgress } from "../progress-DZHhZ1Fk.mjs"; import { n as requireSystemAgentPersistentApplyInference, r as SystemAgentInferenceUnavailableError, t as requireSystemAgentInferenceRoute } from "../inference-guard-D92Jot8f.mjs"; import { i as loadSystemAgentOverview, n as formatSystemAgentOverview } from "../overview-DAa4f9mq.mjs"; import { r as hasCurrentSystemAgentOwnerPluginArtifacts } from "../verified-inference-B9tngoud.mjs"; import { r as resolveSystemAgentOperation } from "../dialogue-CGAI4JoY.mjs"; import { stdin, stdout } from "node:process"; //#region 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-7S_X4gNj.mjs"); const { loadAgentRuntimePluginRegistryHandle: s } = await import("../runtime-plugins-D5w9VRxn.mjs"); const { withPluginLifecycleLeaseAsync: c } = await import("../plugin-lifecycle-lease-B1cHoIkh.mjs"); const { createPluginCache: l, withPluginCache: u } = await import("../plugin-cache-rQ5ewrvN.mjs"); const { withPluginRuntimeRegistryScope: d } = await import("../gateway-request-scope-CF7UIf6R.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-BWr5iNSL.mjs"); e.onReady?.(); await o(e, t); } //#endregion export { runSystemAgent };