UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.03 kB
import{s as resolveExecApprovalRequestAllowedDecisions}from"./exec-approvals-policy-DUqwCsoC.mjs";import"./exec-approvals-BLANskJu.mjs";import{n as summarizeApprovalScope}from"./approval-scope-BgbNHTF5.mjs";import{t as resolveCanonicalPluginApprovalRequestAllowedDecisions}from"./plugin-approval-canonical-decisions-CtlPZigd.mjs";import{s as buildTypedApprovalActionDescriptors}from"./exec-approval-reply-B7xtl996.mjs";import{h as normalizeApprovalRequest}from"./approval-request-account-binding-DFLDpifZ.mjs";import{t as resolveExecApprovalCommandDisplay}from"./exec-approval-command-display-Jw_ow0f2.mjs";import{t as SYSTEM_AGENT_APPROVAL_DECISIONS}from"./system-agent-approvals-BHI6CMvj.mjs"; //!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}}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}}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}:{}}}function buildExpiredApprovalView(e){return buildApprovalViewBase(normalizeApprovalRequest(e),`expired`)}export{buildPendingApprovalView as n,buildResolvedApprovalView as r,buildExpiredApprovalView as t};