openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
86 lines (85 loc) • 4.5 kB
JavaScript
import { t as createLazyImportLoader } from "./lazy-promise-DGqyc4Y4.mjs";
import { r as resolveAgentConfig } from "./agent-scope-config-BU4qc9bA.mjs";
import "./agent-scope-DWB4x52T.mjs";
import "./tool-description-presets-CcdpQmwX.mjs";
import { a as withInstallationTarget, n as getInstallationTarget } from "./installation-target-context-CIQIaD3U.mjs";
import { t as applyExecPolicyLayer } from "./exec-policy-Fg0Bqqoy.mjs";
import { n as execSchema, t as execCompletionSchema } from "./bash-tools.schemas-CB8uAUJo.mjs";
import { i as resolveMergedSafeBinProfileFixtures } from "./exec-safe-bin-runtime-policy-De2TWewW.mjs";
import { n as mergeGatewayAgentCliPath } from "./openclaw-cli-shim-BUQvcEdc.mjs";
import { n as describeExecTool } from "./bash-tools.descriptions-CdVoGX1S.mjs";
import { t as resolveExecCommandHighlighting } from "./exec-command-highlighting-DGzytf0P.mjs";
import { t as createExecToolExecutionTimeoutResolver } from "./exec-tool-timeout-Bv8Jutor.mjs";
//#region src/agents/lazy-exec-tool.ts
const bashToolsModuleLoader = createLazyImportLoader(() => import("./bash-tools-DeLzEt_o.mjs"));
/** Build the exec tool lazily so non-shell agent surfaces avoid loading bash runtime code. */
function createLazyExecTool(defaults, presentation) {
const installationTarget = getInstallationTarget();
let loadedTool;
let loadingTool;
const loadTool = () => {
if (loadedTool) return Promise.resolve(loadedTool);
loadingTool ??= bashToolsModuleLoader.load().then(({ createExecTool }) => {
loadedTool = withInstallationTarget(installationTarget, () => createExecTool(defaults));
return loadedTool;
});
return loadingTool;
};
return {
name: "exec",
label: "exec",
displaySummary: presentation?.displaySummary ?? "Run shell now.",
getExecutionTimeoutMs: createExecToolExecutionTimeoutResolver(defaults),
get description() {
return presentation?.description ?? describeExecTool({
hasCronTool: defaults?.hasCronTool === true,
hasProcessTool: defaults?.processToolAvailabilityRef?.value,
autoReview: defaults?.mode === "auto"
});
},
get parameters() {
return presentation?.parameters ?? (defaults?.processToolAvailabilityRef?.value === false ? execCompletionSchema : execSchema);
},
prepareBeforeToolCallParams: async (...args) => (await loadTool()).prepareBeforeToolCallParams?.(...args) ?? args[0],
finalizeBeforeToolCallParams: (params, preparedParams) => loadedTool?.finalizeBeforeToolCallParams?.(params, preparedParams) ?? params,
execute: async (toolCallId, params, signal, onUpdate) => (await loadTool()).execute(toolCallId, params, signal, onUpdate)
};
}
/** Resolve global and per-agent exec defaults before runtime-only overrides. */
function resolveExecToolConfig(params) {
const cfg = params.cfg;
const globalExec = cfg?.tools?.exec;
const agentExec = cfg && params.agentId ? resolveAgentConfig(cfg, params.agentId)?.tools?.exec : void 0;
const layeredPolicy = applyExecPolicyLayer(applyExecPolicyLayer({}, globalExec), agentExec);
const configuredPathPrepend = agentExec?.pathPrepend ?? globalExec?.pathPrepend;
return {
host: agentExec?.host ?? globalExec?.host,
mode: layeredPolicy.mode,
security: layeredPolicy.security,
ask: layeredPolicy.ask,
node: agentExec?.node ?? globalExec?.node,
configuredPathPrepend,
pathPrepend: mergeGatewayAgentCliPath(configuredPathPrepend),
safeBins: agentExec?.safeBins ?? globalExec?.safeBins,
strictInlineEval: agentExec?.strictInlineEval ?? globalExec?.strictInlineEval,
commandHighlighting: resolveExecCommandHighlighting({
config: cfg,
agentId: params.agentId
}),
safeBinTrustedDirs: agentExec?.safeBinTrustedDirs ?? globalExec?.safeBinTrustedDirs,
safeBinProfiles: resolveMergedSafeBinProfileFixtures({
global: globalExec,
local: agentExec
}),
reviewer: agentExec?.reviewer ?? globalExec?.reviewer,
backgroundMs: agentExec?.backgroundMs ?? globalExec?.backgroundMs,
timeoutSec: agentExec?.timeoutSeconds ?? globalExec?.timeoutSeconds,
approvalRunningNoticeMs: agentExec?.approvalRunningNoticeMs ?? globalExec?.approvalRunningNoticeMs,
cleanupMs: agentExec?.cleanupMs ?? globalExec?.cleanupMs,
notifyOnExit: agentExec?.notifyOnExit ?? globalExec?.notifyOnExit,
notifyOnExitEmptySuccess: agentExec?.notifyOnExitEmptySuccess ?? globalExec?.notifyOnExitEmptySuccess,
applyPatch: agentExec?.applyPatch ?? globalExec?.applyPatch
};
}
//#endregion
export { resolveExecToolConfig as n, createLazyExecTool as t };