openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
102 lines (101 loc) • 4.33 kB
JavaScript
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { t as createLazyImportLoader } from "./lazy-promise-DiCvjz9w.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { n as mergeGatewayAgentCliPath } from "./openclaw-cli-shim-spskOd_w.mjs";
import { d as withExecRequestOwners, o as captureExecRequestOwners } from "./exec-request-context-C8VKkMcB.mjs";
import { a as EXEC_TOOL_DISPLAY_SUMMARY } from "./tool-catalog-C1ALpCJD.mjs";
import { t as applyExecPolicyLayer } from "./exec-policy-B0KOmSWr.mjs";
import { t as bindAgentToolAvailability } from "./agent-tool-availability-ecKW8hOH.mjs";
import { a as withInstallationTarget, n as getInstallationTarget } from "./installation-target-context-C_xR1SHA.mjs";
import { t as resolveExecCommandHighlighting } from "./exec-command-highlighting-Cekkq9KD.mjs";
import { i as resolveMergedSafeBinProfileFixtures } from "./exec-safe-bin-runtime-policy-DUQ-JlOU.mjs";
import { n as describeExecTool } from "./bash-tools.descriptions-CjRLwO0Y.mjs";
import { a as createExecSchema, i as createExecCompletionSchema, o as execSchema, t as createExecToolExecutionTimeoutResolver } from "./exec-tool-timeout-CpkOuB67.mjs";
//#region src/agents/lazy-exec-tool.ts
const bashToolsModuleLoader = createLazyImportLoader(() => import("./bash-tools-BSb3XkVL.mjs"));
/** Build the exec tool lazily so non-shell agent surfaces avoid loading bash runtime code. */
function createLazyExecTool(e, t) {
const n = getInstallationTarget();
const r = captureExecRequestOwners({
runId: e?.runId,
sessionId: e?.sessionId
});
const i = e?.processToolAvailabilityRef ?? {};
const a = createExecSchema(e);
const o = createExecCompletionSchema(e);
let s;
let c;
const loadTool = () => {
c ??= bashToolsModuleLoader.load().then(({ createExecTool: t }) => {
s = withInstallationTarget(n, () => t(withExecRequestOwners({
...e,
processToolAvailabilityRef: i
}, r)));
return s;
});
return c;
};
return bindAgentToolAvailability({
name: "exec",
label: "exec",
displaySummary: t?.displaySummary ?? "Run shell now.",
getExecutionTimeoutMs: createExecToolExecutionTimeoutResolver(e),
get description() {
return t?.description ?? describeExecTool({
hasCronTool: e?.hasCronTool === true,
hasProcessTool: i.value,
autoReview: e?.mode === "auto"
});
},
get parameters() {
return t?.parameters ?? (i.value === false ? o : a);
},
prepareBeforeToolCallParams: async (...e) => (await loadTool()).prepareBeforeToolCallParams?.(...e) ?? e[0],
finalizeBeforeToolCallParams: (e, t) => s?.finalizeBeforeToolCallParams?.(e, t) ?? e,
execute: async (e, t, n, r) => (await loadTool()).execute(e, t, n, r)
}, {
prepareBeforeNormalization: true,
prepare: (e, t) => {
i.value = t.has("process");
},
executionSchema: t?.parameters ? void 0 : () => execSchema
});
}
/** Resolve global and per-agent exec defaults before runtime-only overrides. */
function resolveExecToolConfig(e) {
const t = e.cfg;
const n = t?.tools?.exec;
const r = t && e.agentId ? resolveAgentConfig(t, e.agentId)?.tools?.exec : void 0;
const i = applyExecPolicyLayer(applyExecPolicyLayer({}, n), r);
const a = r?.pathPrepend ?? n?.pathPrepend;
return {
host: r?.host ?? n?.host,
mode: i.mode,
security: i.security,
ask: i.ask,
node: r?.node ?? n?.node,
configuredPathPrepend: a,
pathPrepend: mergeGatewayAgentCliPath(a),
safeBins: r?.safeBins ?? n?.safeBins,
strictInlineEval: r?.strictInlineEval ?? n?.strictInlineEval,
commandHighlighting: resolveExecCommandHighlighting({
config: t,
agentId: e.agentId
}),
safeBinTrustedDirs: r?.safeBinTrustedDirs ?? n?.safeBinTrustedDirs,
safeBinProfiles: resolveMergedSafeBinProfileFixtures({
global: n,
local: r
}),
reviewer: r?.reviewer ?? n?.reviewer,
backgroundMs: r?.backgroundMs ?? n?.backgroundMs,
timeoutSec: r?.timeoutSeconds ?? n?.timeoutSeconds,
approvalRunningNoticeMs: r?.approvalRunningNoticeMs ?? n?.approvalRunningNoticeMs,
cleanupMs: r?.cleanupMs ?? n?.cleanupMs,
notifyOnExit: r?.notifyOnExit ?? n?.notifyOnExit,
notifyOnExitEmptySuccess: r?.notifyOnExitEmptySuccess ?? n?.notifyOnExitEmptySuccess,
applyPatch: r?.applyPatch ?? n?.applyPatch
};
}
//#endregion
export { resolveExecToolConfig as n, createLazyExecTool as t };