UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.42 kB
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as validateToolArguments}from"./src-BHImOHU3.mjs";import"./validation-BWrqfeZS.mjs";import{AsyncLocalStorage}from"node:async_hooks"; //!src/agents/agent-tools.execution-validation.ts const executionValidators=resolveGlobalSingleton(Symbol.for(`openclaw.toolExecutionValidationContext`),()=>new AsyncLocalStorage);function rejectClosedToolExecutionValidation(){throw new Error(`Tool execution validation scope is closed`)}async function runWithToolExecutionValidation(e,t,n){const r={toolCallId:e,validate:t};try{return await executionValidators.run(r,n)}finally{r.validate=rejectClosedToolExecutionValidation}}async function validateToolExecutionParams(e,t){const n=executionValidators.getStore();if(n?.toolCallId===e)await n.validate(t)}function isToolParameters(e){return isRecord(e)}function coerceToolExecutionArguments(e,t,n){if(!isToolParameters(t)||!isRecord(n))return n;try{const r=validateToolArguments({name:e.name,description:e.description??``,parameters:t},{type:`toolCall`,id:e.name,name:e.name,arguments:n});if(isRecord(r))for(const e of Object.getOwnPropertySymbols(n))Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e));return r}catch{return n}}export{runWithToolExecutionValidation as n,validateToolExecutionParams as r,coerceToolExecutionArguments as t};