UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

87 lines (86 loc) • 3.19 kB
import { t as expandHomePrefix } from "./home-dir-EKmgmdPG.mjs"; import { f as resolveExecApprovalsSocketPath, u as resolveExecApprovalsDisplayPath } from "./exec-approvals-config-BBzEUJlE.mjs"; import { t as resolveExecApprovalsFromFileInternal } from "./exec-approvals-resolver-C6IwmycS.mjs"; import { r as readExecApprovalsSocket } from "./exec-approvals-socket-DEOHtzox.mjs"; import { a as loadExecApprovalsReadOnlyAsync, n as ensureExecApprovalsSnapshot, t as commitExecAuthorizations } from "./exec-approvals-store-BUZ9uOWF.mjs"; import "./exec-approvals-allowlist-f3-u9Y6p.mjs"; import "./exec-approvals-generated-migration-BCmbxD17.mjs"; import { i as createExecApprovalPolicySnapshot, n as assertCurrentUsageAuthorization, r as buildAllowlistEntryMatchKey } from "./exec-approvals-authorization.kernel-DITNT1Lg.mjs"; //#region src/infra/exec-approvals-authorization.ts async function recordAllowlistMatchesUse(e, t) { const n = structuredClone({ agentId: e.agentId, matches: [...e.matches], command: e.command, resolvedPath: e.resolvedPath, authorization: e.authorization }); return retainedAuthorization(n, await commitExecAuthorizations(n, e.assertCurrent, t)); } async function commitExecAuthorizationLocked(e) { const t = structuredClone(e); return retainedAuthorization(t, await commitExecAuthorizations(t)); } function retainedAuthorization(e, { file: t, readCurrent: n }) { const r = new Set(e.matches.filter((e) => e.pattern).map(buildAllowlistEntryMatchKey)); const i = { ...e.authorization, policySnapshot: createExecApprovalPolicySnapshot({ file: t, agentId: e.agentId }) }; return () => assertCurrentUsageAuthorization({ file: n(), agentId: e.agentId, command: e.command, matchKeys: r, authorization: i }); } //#endregion //#region src/infra/exec-approvals.ts function redactExecApprovals(e) { const { raw: t, ...n } = e; const r = e.file.socket?.path?.trim(); return { ...n, file: { ...e.file, socket: r ? { path: r } : void 0 } }; } function shapeResolvedExecApprovals(e) { const t = resolveExecApprovalsSocketPath(); return resolveExecApprovalsFromFileInternal({ file: e.file, agentId: e.agentId, overrides: e.overrides, path: e.filePath, socketPath: e.socket === "persisted" ? expandHomePrefix(e.file.socket?.path ?? t) : t, token: e.socket === "persisted" ? e.file.socket?.token ?? "" : "" }); } async function resolveExecApprovalsLocked(e, t) { const n = resolveExecApprovalsDisplayPath(); if (!t?.requireSocket) { const r = shapeResolvedExecApprovals({ file: await loadExecApprovalsReadOnlyAsync(), filePath: n, agentId: e, overrides: t, socket: "none" }); if ((r.agent.security === "full" || r.agent.security === "deny") && r.agent.ask === "off" && !(await readExecApprovalsSocket())?.socket_token?.trim()) return r; } return shapeResolvedExecApprovals({ file: (await ensureExecApprovalsSnapshot()).file, filePath: resolveExecApprovalsDisplayPath(), agentId: e, overrides: t, socket: "persisted" }); } //#endregion export { recordAllowlistMatchesUse as i, resolveExecApprovalsLocked as n, commitExecAuthorizationLocked as r, redactExecApprovals as t };