UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.99 kB
import{t as AsyncContext}from"./async-context-D4i8WbBE.mjs";import{o as getGatewayToolCallerIdentity}from"./gateway-caller-context-Dw9IijqV.mjs";import{c as getAgentToolActionDescriptor}from"./agent-tool-metadata-D7ctyGhj.mjs";import{i as recordExecutionDecisionWork}from"./execution-decision-work-DFtwEzMk.mjs";import{createHash}from"node:crypto"; //!src/agents/agent-tools.before-tool-call.decision.ts const genericDecisions={allowed:[`allowed`,`attribution-only`,`generic_action_attributed`],denied:[`denied`,`enforced`,`generic_action_policy_denied`],suppressed:[`not-applicable`,`attribution-only`,`generic_action_suppressed`]};const toolDecisionOwner=new AsyncContext(Symbol(`toolDecisionOwner`));function markToolDecisionRecorded(){const e=toolDecisionOwner.getStore();if(e)e.recorded=true}async function runWithGenericToolActionDecision(e,t,n){const r={recorded:false};try{return await toolDecisionOwner.run(r,n)}finally{if(!r.recorded)recordGenericToolActionDecision(e,t,`allowed`)}}function recordGenericToolActionDecision(e,t,n){const r=getAgentToolActionDescriptor(e);const i=getGatewayToolCallerIdentity();const a=i?.executionIdentityToken;const o=i?.receiptAuthority;if(!r||!t?.trim()||!a||!o)return false;const[s,c,l]=genericDecisions[n];const u=`tool-action:${createHash(`sha256`).update(JSON.stringify([a.contextId,a.executionId,t,r,l])).digest(`base64url`).slice(0,32)}`;try{const e=Date.now();if(o()===false)return false;return recordExecutionDecisionWork({workVersion:1,token:a,receipt:{schemaVersion:1,receiptId:u,occurredAt:e,action:r,decision:{outcome:s,reasonCode:l},enforcement:{coverageState:c,policyRefs:n===`denied`?[`tool-action-policy`]:[],grantRefs:[],contextFieldsUsed:[`contextId`,`executionId`,`runId`]},source:{owner:`tool-action`,recordRef:u,decisionBoundary:`agent-tool.before-execute`},missingEvidence:[],remediation:[]}})}catch{return false}}export{recordGenericToolActionDecision as n,runWithGenericToolActionDecision as r,markToolDecisionRecorded as t};