openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.21 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{A_ as t,N_ as n,Rc as r,Vc as i}from"./control-ui-boot-shared-DFTSUQQ0.js";import{B as a,Ct as o,F as s,St as c,U as l,gt as u}from"./solid-runtime-C416s-HC.js";function d(e,t){let r=n(e.gateway),l=i(e.runtimeConfig),d=!1,f,p=()=>{let e=r.read().snapshot;return!d&&e.phase===`connected`&&t.access(e.hello?.auth??null)?e.client:null},m={},[h,g]=a({scope:m}),_=s(()=>h().scope),v=s(e=>{let t=h(),n=e?.scope===t.scope?e.outcome:void 0;return t.promise?t.promise.then(e=>({scope:t.scope,outcome:e??n})):{scope:t.scope,outcome:n}}),y=()=>{let e=o(v);return e.scope===_()?e.outcome:void 0},b=s(()=>!!p()&&(c(v)||y()===void 0)),x=s(()=>{let e=y();return e&&`result`in e?e.result:void 0}),S=()=>{if(!p())return x();let e=v().outcome;if(e&&`error`in e)throw e.error;return e?.result},C,w=()=>u(k),T=()=>{let t=e.gateway.snapshot;return[t.client,t.phase,t.hello,t.hello?.auth]};u(()=>{let n=T(),r=e.gateway.subscribe(()=>{let e=T();if(n.some((t,n)=>t!==e[n])){let r=n[0]!==e[0]||e[1]===`connected`&&!t.access(e[3]??null);n=e,f?.(),C=void 0,r&&(m={},g({scope:m})),t.onConnectionChange?.(r),w()}}),i=l.subscribe(w);return k(),()=>{d=!0,r(),i(),f?.()}});function E(){let n=e.gateway,r=p(),i=T();return()=>{let a=T();return r!==null&&!d&&a[0]===r&&a[1]===`connected`&&t.access(a[3]??null)&&e.gateway===n&&i.every((e,t)=>e===a[t])}}let D=()=>e.runtimeConfig.state.configSnapshot?.[t.configHash];function O(){let t=e.gateway.snapshot;return[p(),D(),t.phase,t.hello,t.hello?.auth]}function k(){let e=O();C?.every((t,n)=>t===e[n])||A(e)}function A(e){if(d)return;let[n,r]=e;if(C=e,f?.(),!n)return;let i=new AbortController,a=Promise.withResolvers(),o=()=>{i.abort(),a.resolve(void 0)};f=o;let s=E(),c=()=>s()&&D()===r,l=()=>!i.signal.aborted&&f===o&&c(),u=n.request(t.method,{},{signal:i.signal}).then(e=>{if(l())return t.onStatus?.(e,l),{result:{status:e,isCurrent:c}}},e=>{if(l())return t.onError?.(),{error:e}}),p=Promise.race([u,a.promise]);g({scope:m,promise:p})}return{client:p,pending:b,result:x,read:S,scopeKey:_,requestKey:h,refresh:()=>{A(O())},capture:E,gatewayProjection:r,configProjection:l}}function f(){return(f=e((()=>{l(),t(),r()})))()}export{f as n,d as t};