UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.56 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ju as t,Qa as n,Wo as r,li as i,oi as a}from"./_4____________________________.js";import{It as o,Lj as s,Lt as c,ak as l,fk as u,jj as d,mk as f,ok as p}from"./_2_____________________________.js";import{f as m,h,u as g}from"./config-form-utils-runtime-CqcGJa6w.js";import{i as _,n as v,t as y}from"./stored-secret-source-Ddeyumyj.js";function b(e,t,n){let r=m(e,t,n);if(!r.ok)throw Error(`Couldn’t save this setting at its current location. Check its location in the config file.`);return r.value}function x(e,t){return Array.isArray(e)&&typeof t==`number`&&t<e.length}function S(e){let n=e.base,r=e.draft??e.base;for(let[i,a]of e.path.entries()){if(Array.isArray(n)||Array.isArray(r)){if(!Array.isArray(n)||w(n,r))return!0;let e=n;return typeof a==`number`&&Array.isArray(r)&&r.length>e.length&&e.every((e,t)=>w(e,r[t]))}if(i===e.path.length-1)return!0;n=t(n)?n[String(a)]:void 0,r=t(r)?r[String(a)]:void 0}return!0}function C(e){let{path:n,value:r}=e,i={},a=[],s=i,c=e.base,l=e.draft,u;for(let[e,i]of n.entries()){let d=String(i),f=n.slice(e+1),p=t(c)?c[d]:void 0,m=t(l)?l[d]:void 0;if(u=o(u,d),f.length===0){s[d]=r===void 0?null:r;break}if(Array.isArray(p)||Array.isArray(m)){let e=x(p,f[0])?p:m??[];s[d]=b(e,f,r),Array.isArray(p)&&a.push(u);break}if(!t(p)){s[d]=b(t(m)?m:{},f,r);break}let h={};s[d]=h,s=h,c=p,l=m}return{patch:i,replacePaths:a}}var w;function T(){return(T=e((()=>{c(),h(),w=(e,t)=>JSON.stringify(e)===JSON.stringify(t)})))()}function E(e,n){let r=s(e);if(r===null)return j;for(let e of n){if(t(r)&&_(r))return g;r=t(r)||Array.isArray(r)?r[e]:void 0}return t(r)&&_(r)?g:r}function D(e,t,n){let r=E(e,t);if(r!==j)return r===`__OPENCLAW_REDACTED__`?v(e,t).kind===`literal`:!(typeof r==`string`&&r.includes("${")&&r!==n)}function O(e){let t=e.runtimeConfig,a=new Map,o=new Set,c,u=!1,d=()=>{for(let e of o)e()},p=()=>l(e.gateway).key,m=()=>{if(a.size>0&&c!==p()){let e=[...a.values()];a.clear(),d();for(let t of e)f({severity:`error`,message:i(`configForm.secretDroppedOnConnectionChange`,{field:t.label}),durationMs:12e3})}},h=t.state.configSnapshot;t.subscribe(()=>{t.state.configSnapshot!==h&&(h=t.state.configSnapshot,d())});let g=e=>{let n=s(t.state.configSnapshot);return!n||S({base:n,draft:t.state.configForm,path:e})},_=e=>D(t.state.configSnapshot,e,a.get(A(e))?.baseline),y=()=>{let e=!1;for(let[t,n]of a)_(n.path)===!1&&(a.delete(t),e=!0);e&&d()},b=t=>{let n=[...a.values()].find(e=>e.pathname!==t);n&&f({severity:void 0,actionPrimary:!0,message:i(`configForm.secretUnsavedOnLeave`,{field:n.label}),actionLabel:i(`configForm.secretReview`),onAction:()=>e.navigate(n.routeId,{pathname:n.pathname,search:n.search}),durationMs:12e3})},x=()=>{if(u)return;u=!0,r(window,`beforeunload`,e=>{a.size>0&&(e.preventDefault(),e.returnValue=``)}),t.subscribe(()=>{m(),y()});let n=e.router.getState().location.pathname;e.router.subscribe(e=>{e.location.pathname!==n&&(n=e.location.pathname,b(n))})},w=(e,n,r)=>t.runExternalMutation(r=>{let i=t.state.configSnapshot,a=s(i);if(!a||!i?.hash)throw Error(`Configuration is unavailable; refresh and try again.`);let{patch:o,replacePaths:c}=C({base:a,draft:t.state.configForm,path:e,value:n});return r.request(`config.patch`,{baseHash:i.hash,raw:JSON.stringify(o),sessionKey:t.state.applySessionKey,note:`settings: update ${e.map(String).join(`.`)}`,...c.length>0?{replacePaths:c}:{}})},{canDispatch:()=>r===p()&&_(e)!==!1&&g(e),configWriteAck:e=>e}),T=e=>(y(),a.delete(A(e))&&d(),{ok:!1,error:``});return{source:e=>v(t.state.configSnapshot,e),read(e){return m(),a.get(A(e))?.text},hold(n,r,i){x(),m(),c=p();let o=A(n),s=a.get(o),{location:l,matches:u}=e.router.getState();a.set(o,{path:[...n],baseline:s?s.baseline:E(t.state.configSnapshot,n),label:i,text:r,routeId:u[0]?.routeId??``,pathname:l.pathname,search:l.search}),d()},release(e){a.delete(A(e))&&d()},async save(e,n){m();let r=p();if(_(e)===!1)return T(e);if(!g(e))return{ok:!1,error:i(`configForm.draftRejected`)};let a=await w(e,n,r);if(!a.ok&&a.reason===`conflict`&&r===p()){if(await t.refresh({background:!0}),r!==p())return{ok:!1,error:``};a=_(e)===!1?a:await w(e,n,r)}return r===p()?!a.ok&&_(e)===!1?T(e):!a.ok&&!g(e)?{ok:!1,error:i(`configForm.draftRejected`)}:a.ok?{ok:!0}:{ok:!1,error:a.error}:{ok:!1,error:``}},subscribe:e=>n(o,e)}}function k(e){let t=M.get(e.runtimeConfig);return t||(t=O(e),M.set(e.runtimeConfig,t)),t}var A,j,M;function N(){return(N=e((()=>{p(),a(),h(),u(),T(),d(),y(),A=e=>JSON.stringify(e),j=Symbol(`missing`),M=new WeakMap})))()}export{N as n,k as t};