openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.94 kB
JavaScript
import{a as e}from"./openclaw-state-read-record-coerce-D1s3ReAs.mjs";import{_ as t,a as n,b as r,d as i,f as a,h as o,l as s,n as c,o as l,u,y as d}from"./openclaw-state-read-schemas-CLrAtqTl.mjs";import{a as f,i as p}from"./openclaw-state-read-agent-id-DmscQLD6.mjs";import"./openclaw-state-read-session-key-DaKMXMbu.mjs";import"node:path";const m=c([`allowlist`,`full`,`deny`]),h=c([`always`,`off`,`on-miss`]),g=u({security:m.optional(),ask:h.optional(),askFallback:m.optional(),autoAllowSkills:l().optional()});function normalizePersistedAllowlistSource(e){return e===`allow-always`?e:void 0}const _=u({pattern:t().refine(e=>e.trim().length>0),id:t().min(1),source:s(`allow-always`).optional(),commandText:i().optional(),argPattern:t().optional(),lastUsedAt:a().finite().optional(),lastUsedCommand:t().optional(),lastResolvedPath:t().optional()}),v=d([t().trim().min(1),_.extend({id:t().optional(),source:t().transform(normalizePersistedAllowlistSource).optional(),commandText:t().optional()})]).transform(e=>typeof e==`string`?{pattern:e}:e);function createExecApprovalsSchema(i,c){let l=g.extend({allowlist:n(i).optional(),mcpTools:n(u({server:t().refine(e=>e.trim().length>0),tool:t().refine(e=>e.trim().length>0),source:s(`allow-always`),addedAt:a().finite().nonnegative(),lastUsedAt:a().finite().nonnegative().optional()})).optional()}),d=r().refine(t=>!e(t)||!Object.hasOwn(t,`__proto__`)).pipe(o(t(),l)).refine(e=>c||!Object.hasOwn(e,`default`));return u({version:s(1),socket:u({path:t().optional(),token:t().optional()}).optional(),defaults:g.optional(),agents:d.optional()})}const y=createExecApprovalsSchema(_,!1),b=createExecApprovalsSchema(v,!0),x=/* @__PURE__ */ new Set([`version`,`socket`,`path`,`token`,`defaults`,`agents`,`security`,`ask`,`askFallback`,`autoAllowSkills`,`allowlist`,`mcpTools`,`server`,`tool`,`addedAt`,`pattern`,`id`,`source`,`commandText`,`argPattern`,`lastUsedAt`,`lastUsedCommand`,`lastResolvedPath`]),S=/* @__PURE__ */ new Map([[`string`,`expected a string`],[`number`,`expected a finite number`],[`boolean`,`expected a boolean`],[`array`,`expected an array`],[`object`,`expected an object`]]);function formatPersistedExecApprovalsIssue(t,n){let r=t.code===`invalid_union`?t.errors[1]?.find(e=>e.path.length===1):void 0,i=r??t,a=r?[...t.path,...r.path]:t.path,o=``;for(let[t,r]of a.slice(0,5).entries())if(t===1&&a[0]===`agents`){let t=e(n)&&e(n.agents)?n.agents:{},i=typeof r==`string`?Object.keys(t).indexOf(r)+1:0;if(!i)break;o+=` entry #${i}`}else if(t===3&&(a[2]===`allowlist`||a[2]===`mcpTools`)&&typeof r==`number`&&Number.isSafeInteger(r)&&r>=0)o+=`[${r}]`;else if(typeof r==`string`&&x.has(r))o+=`${o?`.`:``}${r}`;else break;let s=`invalid value`;switch(i.code){case`invalid_type`:s=S.get(i.expected)??s;break;case`invalid_value`:s=`expected a supported value`;break;case`invalid_union`:s=`expected a non-empty string or an object with a non-empty pattern`;break;case`too_small`:s=`expected a non-empty string`;break;case`custom`:a.at(-1)===`pattern`&&(s=`expected a non-empty string`)}return`${o||`document`}: ${s}`}function parseExecApprovals(e,t){let n;try{n=JSON.parse(e)}catch{return p(`invalid JSON syntax`)}try{let e=t.safeParse(n);if(e.success)return f(e.data);if(t===y&&b.safeParse(n).success)return p(`Legacy exec approval policy requires Doctor repair`);let r=e.error.issues[0];return p(r?formatPersistedExecApprovalsIssue(r,n):`invalid approvals structure`)}catch{return p(`invalid approvals structure`)}}function parsePersistedExecApprovals(e){return parseExecApprovals(e,y)}function stripExecApprovalsRawSocketCredentials(t){let n;try{n=JSON.parse(t)}catch{return t}if(!e(n)||!e(n.socket)||!Object.hasOwn(n.socket,`path`)&&!Object.hasOwn(n.socket,`token`))return t;let{path:r,token:i,...a}=n.socket;return Object.keys(a).length?n.socket=a:delete n.socket,`${JSON.stringify(n,null,2)}\n`}export{stripExecApprovalsRawSocketCredentials as n,parsePersistedExecApprovals as t};