openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
134 lines (133 loc) • 4.87 kB
JavaScript
import { s as resolveExecApprovalRequestAllowedDecisions } from "./exec-approvals-policy-BGzNHuNm.mjs";
import "./exec-approvals-rOfoWejC.mjs";
import { n as summarizeApprovalScope } from "./approval-scope-DOnX7GXe.mjs";
import { t as resolveCanonicalPluginApprovalRequestAllowedDecisions } from "./plugin-approval-canonical-decisions-CVZjVlcb.mjs";
import { s as buildTypedApprovalActionDescriptors } from "./exec-approval-reply-CfpNUvnC.mjs";
import { h as normalizeApprovalRequest } from "./approval-request-account-binding-DOCAr58L.mjs";
import { t as resolveExecApprovalCommandDisplay } from "./exec-approval-command-display-Bd5aITVg.mjs";
import { t as SYSTEM_AGENT_APPROVAL_DECISIONS } from "./system-agent-approvals-r0J6k0r_.mjs";
//#region src/infra/approval-view-model.ts
function buildMetadata(e) {
return e.flatMap(([e, t]) => t ? [{
label: e,
value: t
}] : []);
}
function buildExecMetadata(e) {
const t = buildMetadata([
["Agent", e.request.agentId],
["CWD", e.request.cwd],
["Host", e.request.host]
]);
if (Array.isArray(e.request.envKeys) && e.request.envKeys.length > 0) t.push({
label: "Env Overrides",
value: e.request.envKeys.join(", ")
});
if (e.request.scope) t.push({
label: "Scope",
value: summarizeApprovalScope(e.request.scope)
});
return t;
}
function buildPluginMetadata(e) {
const t = e.request.severity ?? "warning";
const n = buildMetadata([
["Severity", t === "critical" ? "Critical" : t === "info" ? "Info" : "Warning"],
["Tool", e.request.toolName],
["Plugin", e.request.pluginId],
["Agent", e.request.agentId]
]);
if (e.request.scope) n.push({
label: "Scope",
value: summarizeApprovalScope(e.request.scope)
});
return n;
}
function buildApprovalViewBase(e, t) {
if (e.approvalKind === "system-agent") return {
approvalId: e.id,
approvalKind: "system-agent",
phase: t,
title: t === "pending" ? "OpenClaw change requires approval" : "OpenClaw change",
description: e.request.description,
metadata: e.request.agentId ? [{
label: "Agent",
value: e.request.agentId
}] : [],
agentId: e.request.agentId ?? null,
commandText: e.request.description,
commandPreview: e.request.description,
cwd: null,
host: "gateway",
nodeId: null,
sessionKey: e.request.sessionKey ?? null,
operationSummary: e.request.description
};
if (e.approvalKind === "plugin") return {
approvalId: e.id,
approvalKind: "plugin",
phase: t,
title: e.request.title,
description: e.request.description ?? null,
metadata: buildPluginMetadata(e),
agentId: e.request.agentId ?? null,
pluginId: e.request.pluginId ?? null,
...e.request.scope ? { scope: e.request.scope } : {},
toolName: e.request.toolName ?? null,
severity: e.request.severity ?? "warning"
};
const { commandText: n, commandPreview: r } = resolveExecApprovalCommandDisplay(e.request);
return {
approvalId: e.id,
approvalKind: "exec",
phase: t,
title: t === "pending" ? "Exec Approval Required" : "Exec Approval",
description: t === "pending" ? "A command needs your approval." : null,
metadata: buildExecMetadata(e),
ask: e.request.ask ?? null,
agentId: e.request.agentId ?? null,
warningText: e.request.warningText ?? null,
commandAnalysis: e.request.commandAnalysis ?? null,
commandText: n,
commandPreview: r,
cwd: e.request.cwd ?? null,
envKeys: e.request.envKeys ?? void 0,
host: e.request.host ?? null,
nodeId: e.request.nodeId ?? null,
...e.request.scope ? { scope: e.request.scope } : {},
sessionKey: e.request.sessionKey ?? null
};
}
/** Builds the presentation model for an unresolved approval. */
function buildPendingApprovalView(e) {
const t = normalizeApprovalRequest(e);
const n = t.approvalKind === "system-agent" ? SYSTEM_AGENT_APPROVAL_DECISIONS : t.approvalKind === "plugin" ? resolveCanonicalPluginApprovalRequestAllowedDecisions(t.request) : resolveExecApprovalRequestAllowedDecisions(t.request);
return {
...buildApprovalViewBase(t, "pending"),
actions: buildTypedApprovalActionDescriptors({
approvalCommandId: t.id,
approvalKind: t.approvalKind,
allowedDecisions: n
}),
expiresAtMs: t.expiresAtMs
};
}
/** Builds the presentation model for an approval after a decision was recorded. */
function buildResolvedApprovalView(e, t) {
const n = buildApprovalViewBase(normalizeApprovalRequest(e), "resolved");
return {
...n,
decision: t.decision,
resolvedBy: t.resolvedBy,
...n.approvalKind === "system-agent" ? {
applicationStatus: t.applicationStatus,
terminalStatus: t.terminalStatus
} : {}
};
}
/** Builds the presentation model shown when an approval can no longer be acted on. */
function buildExpiredApprovalView(e) {
return buildApprovalViewBase(normalizeApprovalRequest(e), "expired");
}
//#endregion
export { buildPendingApprovalView as n, buildResolvedApprovalView as r, buildExpiredApprovalView as t };