Files
openclaw-config/cache/control-ui-assets/d08fd045b9cb86d13f0b4aa403c8a06ddcd32e533058ae463245169e5cff5e85/assets/connection-page-Dj6w6eBB.js
T

93 lines
13 KiB
JavaScript

import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{Ks as n,_ as r,b as i,fl as a,ml as o,ni as s,qs as c,ti as l,vr as u,w as d,yr as f}from"./control-ui-core-pH6nakZ-.js";import{G as p,J as m,W as h,Z as g,rt as _}from"./lit-runtime-BEtFSUCp.js";import{B as v,Cn as ee,Q as te,Sn as y,U as b,V as x,ln as S,m as ne,p as C}from"./control-ui-core-DGVkFhVB.js";import{Ht as w,qt as T}from"./control-ui-core-Br5DB0Zj.js";import{In as re,Ln as ie}from"./control-ui-boot-wpHCbPL9.js";import{Cn as E,Ns as ae,Ps as oe,_n as D,bn as O,cn as k,gn as A,mn as j,on as M,vn as N}from"./control-ui-boot-Cdpgu1Gm.js";import{a as P,n as F}from"./settings-targets-GAGqNu16.js";import{n as I,t as L}from"./settings-workspace-Bo4nqRhI.js";import{n as R,r as z,t as B}from"./system-info-BKnpc1o9.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 m`
<div
class="config-host__meter"
role="meter"
aria-label=${T(`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){return m`
<div class="config-host__stat" title=${e.title??``}>
<div class="config-host__stat-label">${e.label}</div>
<div class="config-host__stat-value">
${e.value}${e.unit?m` <span class="config-host__stat-unit">${e.unit}</span>`:p}
</div>
${e.usedFraction==null?p:H(e.label,e.usedFraction)}
${e.detail?m`<div class="config-host__stat-detail">${e.detail}</div>`:p}
</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],r=e.loadAverage?T(`quickSettings.system.loadAverage`,{values:e.loadAverage.map(e=>e.toFixed(1)).join(` · `)}):void 0,i=[e.cpuModel,r].filter(Boolean).join(` · `)||void 0,a=T(e.cpuCount===1?`quickSettings.system.core`:`quickSettings.system.cores`,{count:String(e.cpuCount)}),o=t==null?{label:T(`quickSettings.system.cpu`),value:a,detail:e.cpuModel,title:i}:{label:T(`quickSettings.system.cpu`),value:t.toFixed(1),unit:T(`quickSettings.system.load`),detail:a,usedFraction:e.cpuCount>0?t/e.cpuCount:void 0,title:i},s=W(e.memoryTotalBytes,e.memoryFreeBytes),c=[o,{label:T(`quickSettings.system.memory`),value:s==null?`—`:G(s),unit:s==null?void 0:T(`quickSettings.system.used`),detail:T(`quickSettings.system.freeOf`,{free:n(e.memoryFreeBytes),total:n(e.memoryTotalBytes)}),usedFraction:s}],l=W(e.diskTotalBytes,e.diskAvailableBytes);return l!=null&&c.push({label:T(`quickSettings.system.disk`),value:G(l),unit:T(`quickSettings.system.used`),detail:T(`quickSettings.system.freeOf`,{free:n(e.diskAvailableBytes),total:n(e.diskTotalBytes)}),usedFraction:l,title:e.diskPath}),c}function se(){return[{label:T(`quickSettings.system.cpu`),value:`—`},{label:T(`quickSettings.system.memory`),value:`—`},{label:T(`quickSettings.system.disk`),value:`—`}]}function ce(e){if(e.systemInfoUnavailable)return p;let t=e.systemInfo,n=t&&t.hostname!==t.machineName?t.hostname:void 0,i=t?.lanAddress?`${t.lanAddress}${t.port==null?``:`:${t.port}`}`:void 0,a=t?K(t):se(),o={title:T(`quickSettings.system.gatewayHost`),actions:t?O({kind:`ok`,label:T(`quickSettings.system.up`,{duration:r(t.uptimeMs)})}):void 0};return m`
<div id=${F.host}>
${N(o,m`
<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?T(`quickSettings.system.runtime`,{version:t.nodeVersion,pid:String(t.pid)}):``}
</div>
${i?m`<code class="config-host__address">${i}</code>`:p}
</div>
<div class="config-host__stats">${a.map(U)}</div>
</div>
`)}
</div>
`}function q(){return(q=e((()=>{h(),M(),w(),c(),d(),P()})))()}function J(e){let{label:t,...n}=e;return A({title:t,control:D({...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`:T(`common.na`),a=t?.authMode===`trusted-proxy`,o=m`
${A({title:T(`connection.access.wsUrl`),control:m`
<input
class="settings-input"
aria-label=${T(`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"
/>
`})}
${a?``:m`
${J({label:T(`connection.access.token`),value:e.settings.token,placeholder:`OPENCLAW_GATEWAY_TOKEN`,visible:e.showGatewayToken,showLabel:T(`connection.access.showToken`),hideLabel:T(`connection.access.hideToken`),toggleLabel:T(`connection.access.toggleTokenVisibility`),onInput:t=>e.onConnectionChange({token:t}),onToggle:e.onToggleGatewayTokenVisibility})}
${J({label:T(`connection.access.password`),value:e.password,placeholder:T(`connection.access.passwordPlaceholder`),visible:e.showGatewayPassword,showLabel:T(`connection.access.showPassword`),hideLabel:T(`connection.access.hidePassword`),toggleLabel:T(`connection.access.togglePasswordVisibility`),onInput:e.onPasswordChange,onToggle:e.onToggleGatewayPasswordVisibility})}
`}
${A({title:T(`connection.access.sessionKey`),control:m`
<input
class="settings-input"
aria-label=${T(`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"
>${T(a?`connection.access.trustedProxy`:`connection.access.connectHint`)}</span
>
</div>
<div class="settings-row__control">
<button class="btn" @click=${()=>e.onConnect()}>${T(`common.connect`)}</button>
<button class="btn" @click=${()=>e.onRefresh()}>${T(`common.refresh`)}</button>
</div>
</div>
`,s=m`
${A({title:T(`connection.snapshot.status`),control:O({kind:e.connected?`ok`:`warn`,label:e.connected?T(`common.ok`):T(`common.offline`)})})}
${A({title:T(`connection.snapshot.tickInterval`),control:E(r)})}
${A({title:T(`connection.snapshot.lastChannelsRefresh`),control:E(e.lastChannelsRefresh?i(e.lastChannelsRefresh):T(`common.na`))})}
${e.lastError?A({title:O({kind:`danger`,label:T(`connection.snapshot.lastError`)}),description:e.lastError}):``}
`;return j([N({title:T(`connection.access.title`),description:T(`connection.access.subtitle`)},o),ce(e),N({title:T(`connection.snapshot.title`),description:T(`connection.snapshot.subtitle`)},s)])}function Y(){return(Y=e((()=>{h(),M(),w(),d(),q()})))()}var X,Z,Q;function $(){return($=e((()=>{ie(),h(),g(),S(),ne(),v(),M(),L(),l(),o(),oe(),f(),B(),Y(),X=1e4,Z=`https://docs.openclaw.ai/gateway/remote`,Q=class extends a{constructor(...e){super(...e),this.settings=b(),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 ae(this,X,()=>{this.loadSystemInfo()},!1),this.subscriptions=new u(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;(s(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={...b(),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}:x(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=te(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 m`
<section class="content-header">
<div>
<div class="page-title">${ee(`connection`)}</div>
<div class="page-subtitle">
${y(`connection`)} ${k(Z)}
</div>
</div>
</section>
${I(t)}
`}},t([re({context:C,subscribe:!0})],Q.prototype,`context`,void 0),t([_()],Q.prototype,`settings`,void 0),t([_()],Q.prototype,`password`,void 0),t([_()],Q.prototype,`gatewayTokenVisible`,void 0),t([_()],Q.prototype,`gatewayPasswordVisible`,void 0),t([_()],Q.prototype,`systemInfo`,void 0),t([_()],Q.prototype,`systemInfoUnavailable`,void 0),customElements.get(`openclaw-connection-page`)||customElements.define(`openclaw-connection-page`,Q)})))()}$();
//# sourceMappingURL=connection-page-Dj6w6eBB.js.map