UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

95 lines 13 kB
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{R as t,wr as n,z as r}from"./control-ui-foundation-Cydpkyqa.js";import{Bn as i,Sc as a,as as o,bc as s,cr as c,k as l,lr as u,os as ee,w as te,x as ne,zn as re}from"./control-ui-core-Rwzhj6nO.js";import{$ as ie,K as d,X as f,at as p,q as m}from"./lit-runtime-CV_MH99K.js";import{An as h,J as g,Y as ae,Z as _,_ as v,_n as y,g as b,jn as x,ot as S}from"./control-ui-core-YphAl4aM.js";import{Yt as C,en as w}from"./control-ui-core-vvcQQV2m.js";import{J as T,K as oe,L as E,Q as D,X as O,Y as k,tt as A,z as j}from"./control-ui-boot-chat-_QSl8fbH.js";import{hs as M,ms as N}from"./control-ui-boot-shared-CXVvK2AW.js";import{a as P,n as F}from"./settings-targets-BmloFKW8.js";import{n as I,t as L}from"./settings-workspace-Bseic8Tf.js";import{n as R,r as z,t as B}from"./system-info-B4YQhtbY.js";function V(e){return e>=.92?`critical`:e>=.75?`warn`:`ok`}function H(e,t){let n=Math.min(Math.max(t,0),1),r=Math.round(n*100);return f` <div class="config-host__meter" role="meter" aria-label=${w(`quickSettings.system.usage`,{label:e})} aria-valuemin="0" aria-valuemax="100" aria-valuenow=${r} > <div class="config-host__meter-fill config-host__meter-fill--${V(n)}" style="--config-host-meter-fill: ${r}%" ></div> </div> `}function U(e){let t=e.path?`${e.label} ${e.path}`:e.label;return f` <div class="config-host__stat" title=${e.path??e.title??``}> <div class="config-host__stat-label"> ${e.label}${e.path?f` <span class="config-host__stat-path">${e.path}</span>`:m} </div> <div class="config-host__stat-value"> ${e.value}${e.unit?f` <span class="config-host__stat-unit">${e.unit}</span>`:m} </div> ${e.usedFraction==null?m:H(t,e.usedFraction)} ${e.detail?f`<div class="config-host__stat-detail">${e.detail}</div>`:m} </div> `}function W(e,t){if(!(e==null||t==null||e<=0))return(e-t)/e}function G(e){return`${Math.round(Math.min(Math.max(e,0),1)*100)}%`}function K(e){let t=e.loadAverage?.[0],n=e.loadAverage?w(`quickSettings.system.loadAverage`,{values:e.loadAverage.map(e=>e.toFixed(1)).join(` · `)}):void 0,r=[e.cpuModel,n].filter(Boolean).join(` · `)||void 0,i=w(e.cpuCount===1?`quickSettings.system.core`:`quickSettings.system.cores`,{count:String(e.cpuCount)}),a=t==null?{label:w(`quickSettings.system.cpu`),value:i,detail:e.cpuModel,title:r}:{label:w(`quickSettings.system.cpu`),value:t.toFixed(1),unit:w(`quickSettings.system.load`),detail:i,usedFraction:e.cpuCount>0?t/e.cpuCount:void 0,title:r},s=W(e.memoryTotalBytes,e.memoryFreeBytes),c=[a,{label:w(`quickSettings.system.memory`),value:s==null?`—`:G(s),unit:s==null?void 0:w(`quickSettings.system.used`),detail:w(`quickSettings.system.freeOf`,{free:o(e.memoryFreeBytes),total:o(e.memoryTotalBytes)}),usedFraction:s}];for(let t of e.disks??[]){let e=W(t.totalBytes,t.availableBytes);e!=null&&c.push({label:w(`quickSettings.system.disk`),value:G(e),unit:w(`quickSettings.system.used`),detail:w(`quickSettings.system.freeOf`,{free:o(t.availableBytes),total:o(t.totalBytes)}),usedFraction:e,path:t.path})}return c}function se(){return[{label:w(`quickSettings.system.cpu`),value:`—`},{label:w(`quickSettings.system.memory`),value:`—`},{label:w(`quickSettings.system.disk`),value:`—`}]}function ce(e){if(e.systemInfoUnavailable)return m;let t=e.systemInfo,n=t&&t.hostname!==t.machineName?t.hostname:void 0,r=t?.lanAddress?`${t.lanAddress}${t.port==null?``:`:${t.port}`}`:void 0,i=t?K(t):se(),a={title:w(`quickSettings.system.gatewayHost`),actions:t?D({kind:`ok`,label:w(`quickSettings.system.up`,{duration:ne(t.uptimeMs)})}):void 0};return f` <div id=${F.host}> ${O(a,f` <div class="config-host"> <div class="config-host__identity"> <div class="config-host__name" title=${n??``}> ${t?.machineName??`—`} </div> <div class="config-host__meta"> ${t?`${t.osLabel} · ${t.arch}`:`—`} </div> <div class="config-host__meta"> ${t?w(`quickSettings.system.runtime`,{version:t.nodeVersion,pid:String(t.pid)}):`—`} </div> ${r?f`<code class="config-host__address">${r}</code>`:m} </div> <div class="config-host__stats">${i.map(U)}</div> </div> `)} </div> `}function q(){return(q=e((()=>{d(),E(),C(),ee(),l(),P()})))()}function J(e){let{label:t,...n}=e;return T({title:t,control:k({...n,ariaLabel:t})})}function le(e){let t=e.hello?.snapshot,n=e.hello?.policy?.tickIntervalMs,r=n?`${(n/1e3).toFixed(n%1e3==0?0:1)}s`:w(`common.na`),i=t?.authMode===`trusted-proxy`,a=f` ${T({title:w(`connection.access.wsUrl`),control:f` <input class="settings-input" aria-label=${w(`connection.access.wsUrl`)} .value=${e.settings.gatewayUrl} @input=${t=>{let n=t.target.value;e.onConnectionChange({gatewayUrl:n})}} placeholder="ws://100.x.y.z:18789" /> `})} ${i?``:f` ${J({label:w(`connection.access.token`),value:e.settings.token,placeholder:`OPENCLAW_GATEWAY_TOKEN`,visible:e.showGatewayToken,showLabel:w(`connection.access.showToken`),hideLabel:w(`connection.access.hideToken`),toggleLabel:w(`connection.access.toggleTokenVisibility`),onInput:t=>e.onConnectionChange({token:t}),onToggle:e.onToggleGatewayTokenVisibility})} ${J({label:w(`connection.access.password`),value:e.password,placeholder:w(`connection.access.passwordPlaceholder`),visible:e.showGatewayPassword,showLabel:w(`connection.access.showPassword`),hideLabel:w(`connection.access.hidePassword`),toggleLabel:w(`connection.access.togglePasswordVisibility`),onInput:e.onPasswordChange,onToggle:e.onToggleGatewayPasswordVisibility})} `} ${T({title:w(`connection.access.sessionKey`),control:f` <input class="settings-input" aria-label=${w(`connection.access.sessionKey`)} .value=${e.settings.sessionKey} @input=${t=>e.onSessionKeyChange(t.target.value)} /> `})} <div class="settings-row"> <div class="settings-row__text"> <span class="settings-row__desc" >${w(i?`connection.access.trustedProxy`:`connection.access.connectHint`)}</span > </div> <div class="settings-row__control"> <button class="btn" @click=${()=>e.onConnect()}>${w(`common.connect`)}</button> <button class="btn" @click=${()=>e.onRefresh()}>${w(`common.refresh`)}</button> </div> </div> `,o=f` ${T({title:w(`connection.snapshot.status`),control:D({kind:e.connected?`ok`:`warn`,label:e.connected?w(`common.ok`):w(`common.offline`)})})} ${T({title:w(`connection.snapshot.tickInterval`),control:A(r)})} ${T({title:w(`connection.snapshot.lastChannelsRefresh`),control:A(e.lastChannelsRefresh?te(e.lastChannelsRefresh):w(`common.na`))})} ${e.lastError?T({title:D({kind:`danger`,label:w(`connection.snapshot.lastError`)}),description:e.lastError}):``} `;return oe([O({title:w(`connection.access.title`),description:w(`connection.access.subtitle`)},a),ce(e),O({title:w(`connection.snapshot.title`),description:w(`connection.snapshot.subtitle`)},o)])}function Y(){return(Y=e((()=>{d(),E(),C(),l(),q()})))()}var X,Z,Q;function $(){return($=e((()=>{r(),d(),ie(),y(),v(),g(),E(),L(),c(),a(),M(),i(),B(),Y(),X=1e4,Z=`https://docs.openclaw.ai/gateway/remote`,Q=class extends s{constructor(...e){super(...e),this.settings=_(),this.password=``,this.gatewayTokenVisible=!1,this.gatewayPasswordVisible=!1,this.systemInfo=null,this.systemInfoUnavailable=!1,this.sessionKeyDirty=!1,this.gatewayClient=null,this.systemInfoGatewaySource=null,this.systemInfoClient=null,this.systemInfoLoading=!1,this.systemInfoRequestId=0,this.systemInfoPolling=new N(this,X,()=>{this.loadSystemInfo()},!1),this.subscriptions=new re(this).effect(()=>this.context?.gateway,e=>(this.resetDraft(e),this.synchronizeSystemInfoGateway(e),e.subscribe(t=>{t.client===this.gatewayClient?t.phase!==`connected`&&this.resetSensitiveUi():this.resetDraft(e),this.handleSystemInfoGatewaySnapshot(t),this.requestUpdate()}))).watch(()=>this.context?.channels,(e,t)=>e.subscribe(t))}disconnectedCallback(){this.systemInfoPolling.stop(),this.invalidateSystemInfoRequest(),this.systemInfoGatewaySource=null,this.systemInfoClient=null,this.subscriptions.clear(),this.resetSensitiveUi(),super.disconnectedCallback()}resetSensitiveUi(){this.gatewayTokenVisible=!1,this.gatewayPasswordVisible=!1}synchronizeSystemInfoGateway(e){e!==this.systemInfoGatewaySource&&(this.systemInfoPolling.stop(),this.invalidateSystemInfoRequest(),this.systemInfoGatewaySource=e,this.systemInfoClient=null,this.systemInfo=null,this.systemInfoUnavailable=!1),this.handleSystemInfoGatewaySnapshot(e.snapshot)}handleSystemInfoGatewaySnapshot(e){let t=e.client!==this.systemInfoClient,n=z(e.hello);this.systemInfoClient=e.client,t?(this.invalidateSystemInfoRequest(),this.systemInfo=null,this.systemInfoUnavailable=!1):e.phase!==`connected`&&(this.invalidateSystemInfoRequest(),this.systemInfo=null),e.phase===`connected`&&e.hello&&(this.systemInfoUnavailable=!n,n||(this.invalidateSystemInfoRequest(),this.systemInfo=null)),this.syncSystemInfoPolling()}syncSystemInfoPolling(){let e=this.context.gateway.snapshot;if(!(this.isConnected&&!this.systemInfoUnavailable&&e.phase===`connected`&&z(e.hello)&&e.client!=null)){this.systemInfoPolling.stop();return}this.systemInfoPolling.start()&&this.loadSystemInfo()}invalidateSystemInfoRequest(){this.systemInfoRequestId+=1,this.systemInfoLoading=!1}isCurrentSystemInfoRequest(e,t,n){let r=n.snapshot;return this.isConnected&&e===this.systemInfoRequestId&&this.systemInfoGatewaySource===n&&this.context.gateway===n&&r.phase===`connected`&&r.client===t}async loadSystemInfo(){let e=this.systemInfoGatewaySource;if(!e||e!==this.context.gateway)return;let t=e.snapshot,n=t.client;if(t.phase!==`connected`||!n||this.systemInfoUnavailable||this.systemInfoLoading)return;let r=++this.systemInfoRequestId;this.systemInfoLoading=!0;try{let t=await n.request(`system.info`,{});if(!this.isCurrentSystemInfoRequest(r,n,e))return;this.systemInfo=t}catch(t){if(!this.isCurrentSystemInfoRequest(r,n,e))return;(u(t)||R(t))&&(this.systemInfo=null,this.systemInfoUnavailable=!0,this.systemInfoPolling.stop())}finally{this.isCurrentSystemInfoRequest(r,n,e)&&(this.systemInfoLoading=!1)}}resetDraft(e){let t=e.snapshot.sessionKey,{gatewayUrl:n,token:r,password:i}=e.connection;this.gatewayClient=e.snapshot.client,this.settings={..._(),gatewayUrl:n,token:r,sessionKey:t,lastActiveSessionKey:t},this.password=i,this.sessionKeyDirty=!1,this.resetSensitiveUi()}connect(){let e=this.sessionKeyDirty?{sessionKey:this.settings.sessionKey,lastActiveSessionKey:this.settings.sessionKey}:ae(this.settings.gatewayUrl);this.settings={...this.settings,...e},this.sessionKeyDirty=!1,this.context.gateway.connect({gatewayUrl:this.settings.gatewayUrl,token:this.settings.token,password:this.password,sessionKey:e.sessionKey})}updateConnection(e){if(e.gatewayUrl!==void 0){let t=S(this.settings.gatewayUrl,e.gatewayUrl,{token:this.settings.token,password:this.password});this.password=t.password,this.settings={...this.settings,...e,token:t.token};return}this.settings={...this.settings,...e}}render(){let e=this.context.gateway.snapshot,t=le({connected:e.phase===`connected`,hello:e.hello,settings:this.settings,password:this.password,lastError:e.lastError,lastChannelsRefresh:this.context.channels.state.channelsLastSuccess,systemInfo:this.systemInfo,systemInfoUnavailable:this.systemInfoUnavailable,showGatewayToken:this.gatewayTokenVisible,showGatewayPassword:this.gatewayPasswordVisible,onConnectionChange:e=>this.updateConnection(e),onPasswordChange:e=>this.password=e,onSessionKeyChange:e=>{this.sessionKeyDirty=!0,this.settings={...this.settings,sessionKey:e,lastActiveSessionKey:e}},onToggleGatewayTokenVisibility:()=>{this.gatewayTokenVisible=!this.gatewayTokenVisible},onToggleGatewayPasswordVisibility:()=>{this.gatewayPasswordVisible=!this.gatewayPasswordVisible},onConnect:()=>this.connect(),onRefresh:()=>void this.context.channels.refresh(!1)});return f` <section class="content-header"> <div> <div class="page-title">${x(`connection`)}</div> <div class="page-subtitle"> ${h(`connection`)} ${j(Z)} </div> </div> </section> ${I(t)} `}},n([t({context:b,subscribe:!0})],Q.prototype,`context`,void 0),n([p()],Q.prototype,`settings`,void 0),n([p()],Q.prototype,`password`,void 0),n([p()],Q.prototype,`gatewayTokenVisible`,void 0),n([p()],Q.prototype,`gatewayPasswordVisible`,void 0),n([p()],Q.prototype,`systemInfo`,void 0),n([p()],Q.prototype,`systemInfoUnavailable`,void 0),customElements.get(`openclaw-connection-page`)||customElements.define(`openclaw-connection-page`,Q)})))()}$(); //# sourceMappingURL=connection-page-BPa1FJhk.js.map