UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 9.88 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{B as t,Gr as n,H as r,K as i,U as ee,ii as a,ri as o}from"./_4____________________________.js";import{Ej as te,FN as ne,GN as re,JN as s,JT as ie,PN as c,Pv as l,XN as ae,YN as oe,ZT as se,fo as ce,fr as u,g as d,jj as f,mo as le,po as p,pr as ue,vO as m,wl as de,xO as fe,xl as pe}from"./_2_____________________________.js";import{B as h,Ct as me,F as g,J as he,P as ge,Rt as _e,U as ve,d as ye,f as be,gt as xe,j as _,u as Se,x as Ce}from"./_6____________________.js";import{_ as v}from"./route-controls-runtime-LXiVRSj4.js";import{n as we,t as y}from"./gateway-page-runtime-CW2orlv_.js";import{o as Te,p as Ee,w as b}from"./settings-controls-runtime-CwXZmgDo.js";import{a as De,o as x}from"./route-chrome-Dr9fhzjf.js";import{_ as Oe,c as ke,f as Ae,i as S,n as je,o as Me,r as C,s as Ne,t as Pe,v as Fe,y as Ie}from"./page-operations-qhsfObo1.js";import{a as Le,c as w,d as Re,f as T,i as E,l as ze,m as Be,n as D,o as O,p as k,r as Ve,s as He,t as Ue,u as A}from"./view-CfmIUG0t.js";function j(e){let n=ne(),[i,re]=h([],{ownedWrite:!0}),[ie,c]=h(null,{ownedWrite:!0}),[oe,u]=h(void 0,{ownedWrite:!0}),d=Be([]);function f(e){let t=Be(e),n=t!==d;return d=t,re(e),n}let p=!1,m=C(),[pe,ve]=h(null),[Se,Ce]=h(null),y=!1,b=!1,x,S=!0,w=null,T=null,E=`gateway`,D=null,O=!1,k,A=()=>{},j=ae(()=>m,e=>e());A=j.publish;let M=de(n.runtimeConfig),N=Re({canManagePairing:()=>R.connected&&y,gatewayConnected:()=>R.connected,gatewayClient:()=>R.client,gatewayUrl:()=>n.gateway.connection.gatewayUrl,runPageTask:G,runInventoryTask:e=>V.run(()=>G(e)).presented,rotateDevice:e=>V.run(()=>G(t=>Oe(t,e))).result,setDevicesError:e=>{m.devicesError=e,A()}}),P=v(()=>{},{task:async(e,{signal:t})=>R.connected&&S&&R.gateway?R.client?.request(`system-presence`,{},{signal:t}):void 0,onComplete:e=>{e!==void 0&&f(e)},onError:e=>{se(e)&&f([])}}),F=v(()=>{},{task:async(e,{signal:t})=>R.gateway&&K()&&R.client?le(R.gateway,t).then(e=>e.value):void 0,onComplete:e=>{e!==void 0&&(c(e),L.stop(),L.start())},onError:e=>{se(e)&&(c(null),p=!0,L.stop())}}),I=v(()=>{},{task:async(e,{signal:t})=>R.gateway&&q()?R.client?.request(`environments.list`,{},{signal:t}):void 0,onComplete:e=>{e!==void 0&&u(e.environments)},onError:()=>u(void 0)}),L=ue(6e4,J),Ge=ue(3e4,()=>{X(!0),y&&Y(!0)}),R=we({getGateway:()=>me(()=>n.gateway),onIdentityChange:e=>{w=null,T=null,W(e.snapshot)},invalidateRequests:Qe,onSnapshot:Ze,ensureInitialData:tt}),z=Le({state:j.read,config:()=>M.read().state,hasConfig:()=>ot(qe().state)!==null,gateway:R,target:()=>`${E}:${D??``}`}),Ke=g(()=>j.read().execApprovalsSnapshot),qe=g(()=>M.read()),B=He({scope:()=>({state:j.read(),gateway:R.gateway,epoch:R.epoch,target:E===`node`?D:null}),canSave:()=>b&&R.connected,canEdit:()=>b,runtimeConfig:()=>n.runtimeConfig,isCurrent:e=>e.state===m&&e.gateway===n.gateway&&e.epoch===R.readEpoch(),read:()=>Ke,run:()=>G(e=>Fe(e,at())),publish:()=>A()}),{scope:Je,read:Ye}=Ve({scope:()=>({gateway:n.gateway,state:j.read(),epoch:R.epoch}),nodesRead:pe,devicesRead:Se}),V=ze({scope:Je,isCurrent:e=>e.gateway===n.gateway&&e.state===m&&e.epoch===R.epoch,read:Ye,publish:()=>A()});xe(()=>{H();let e=M.subscribe(H),t=n.router.subscribe(()=>{V.retire(),m.devicesDeciding=[],A();let e=n.router.getState();(e.pendingMatches[0]??e.matches[0])?.routeId!==`devices`&&B.retire()});return()=>{B.retire(),V.retire(),t(),e(),k?.(),N.cancel(),P.cancel(),F.cancel(),I.cancel(),y=!1,b=!1}});function Xe(e){$e(e),e&&R.connected&&R.isRouteDataCurrent(e)&&n.runtimeConfig.refresh({background:!0}).catch(()=>void 0),tt(),A()}function H(){te(n.runtimeConfig.state)&&(w=R.gateway,T=R.client)}function Ze(e){let t=e.snapshot;m.client=t.client,m.connected=t.phase===`connected`,m.requestGeneration=R.epoch;let r=t.phase===`connected`;if(e.becameConnected&&(p=!1),U(t),H(),e.initial||e.sourceChanged){k?.();let e=n.gateway;k=e.subscribeEvents(t=>{if(R.gateway!==e||n.gateway!==e)return;let r=t.event===`presence`?l(t.payload):null;r&&S&&(P.cancel(),f(r)&&(y&&Y(!0),X(!0))),(t.event===`device.pair.changed`||t.event===`device.pair.requested`||t.event===`device.pair.resolved`)&&y&&Y(!0),(t.event===`node.pair.requested`||t.event===`node.pair.resolved`||t.event===`node.runnerInventory.changed`||t.event===`node.hostStats`)&&X(!0)})}if(e.identityChanged&&Z(),r&&!K()&&(F.cancel(),c(null)),r&&!q()&&(I.cancel(),u(void 0)),O&&t.phase===`connected`&&t.client&&(e.identityChanged||e.connectionChanged)){let e=l(t.hello?.snapshot);e&&S&&f(e),P.run(),X(!0),y&&Y(!0)}(e.initial||e.identityChanged||e.connectionChanged)&&(J(),q()&&I.run()),nt(),A()}function Qe(){m.devicesDeciding=[],B.retire(),V.retire(),m.requestGeneration=R.epoch,m.nodesLoading=!1,m.nodesQueuedRefresh=`none`,m.devicesLoading=!1,m.devicesQueuedRefresh=`none`,m.execApprovalsLoading=!1,m.execApprovalsSaving=!1,P.cancel(),F.cancel(),I.cancel()}function U(e){if(e.phase!==`connected`)return;let n=e.hello?.auth??null;x=n?.roleAllowsAdmin;let i=ee(n),a=t(n),o=!n||r(n);(S&&!i||b&&!a||y&&!o)&&(R.invalidate(),Qe()),S=i,b=a,y=o,S||(m.nodes=[],Z()),y||(m.devicesList=null,m.devicesError=null,N.cancel()),b||(m.execApprovalsSnapshot=null,m.execApprovalsForm=null,m.execApprovalsDirty=!1,m.execApprovalsError=null,m.execApprovalsSavedNotice=!1)}function $e(e){if(!e)return;O=!0;let t=n.gateway.snapshot;if(!R.isRouteDataCurrent(e)){W(t),U(t),Z(),S&&f(l(t.hello?.snapshot)??[]),P.run();return}B.retire(),m={...e.devices,client:t.client,connected:t.phase===`connected`,requestGeneration:R.epoch},U(t);let r=l(t.hello?.snapshot);r&&S&&f(r),P.run()}function W(e){B.retire(),V.retire(),N.cancel(),m.requestGeneration+=1;let t=C({client:e.client,connected:e.phase===`connected`});t.requestGeneration=R.epoch,m=t,P.cancel(),F.cancel(),I.cancel(),L.stop(),p=!1,S=!1,b=!1,y=!1,E=`gateway`,D=null}async function G(e){let t=m;try{let n=e(t);return m===t&&A(),await n}finally{m===t&&A()}}function et(e){b&&G(e)}function tt(){let e=m;e.connected&&e.client&&O&&(S&&!e.nodes.length&&!e.nodesLoading&&X(),y&&!e.devicesList&&!e.devicesLoading&&Y(),n.runtimeConfig.ensureLoaded().catch(()=>void 0),b&&!e.execApprovalsSnapshot&&!e.execApprovalsLoading&&Q())}function nt(){K()?L.start():L.stop(),R.connected&&R.client&&S?Ge.start():Ge.stop()}function K(){let e=R.snapshot;return R.connected&&!p&&ce(e)}function q(){let e=R.snapshot;return R.connected&&!!(e&&fe(e))}function J(){K()&&!F.pending&&F.run()}function rt(e,t){let r=n.gateway,i=m,ee=R.epoch,a=e===`nodes`?i.nodesLoading:i.devicesLoading,o=G(n=>e===`nodes`?ke(n,{quiet:t}):Me(n,{quiet:t}));return a||(e===`nodes`?ve:Ce)({gateway:r,state:i,epoch:ee,result:o}),o}function Y(e=!1){return rt(`devices`,e)}function X(e=!1){S&&(J(),q()&&!I.pending&&I.run(),rt(`nodes`,e))}function Z(){f([]),c(null),u(void 0)}async function it(e,t){let n=m;n.execApprovalsDirty&&!await N.confirmExecApprovalsDiscard()?A():m===n&&(B.retire(),E=e,D=t,n.execApprovalsSnapshot=null,n.execApprovalsForm=null,n.execApprovalsDirty=!1,n.execApprovalsError=null,A(),(e===`gateway`||t)&&Q())}function at(){return E===`node`&&D?{kind:`node`,nodeId:D}:{kind:`gateway`}}function Q(){if(!b||m.execApprovalsLoading)return;let e=m,t=G(e=>Ne(e,at()));z.observeApprovals(e,t)}function ot(e){return S?te(e)??(w===R.gateway&&T===R.client?e.configForm:null):null}function st(){let e=j.read(),t=qe().state,r=R.snapshot??n.gateway.snapshot;return{configRead:z.config,execApprovalsRead:z.approvals,loading:e.nodesLoading,initialInventoryReady:O,inventoryRead:Ye,inventoryScope:Je(),onReloadInventory:()=>{X(),y&&Y()},connected:R.connected,nodes:e.nodes,presence:i(),gatewayVersion:r.hello?.server?.version?.trim()||null,basePath:n.basePath,gatewaySystemInfo:ie(),desktopEnvironments:oe(),lastError:e.lastError,devicesLoading:e.devicesLoading,devicesError:e.devicesError,devicesList:e.devicesList,devicesDeciding:e.devicesDeciding,canPairDevice:b,canManagePairing:y,canAdmin:b,roleAllowsAdmin:x,configForm:ot(t),configLoading:t.configLoading,configSaving:t.configSaving,configFormMode:t.configFormMode,execApprovalsLoading:e.execApprovalsLoading,execApprovalsSaving:e.execApprovalsSaving,execApprovalsDirty:e.execApprovalsDirty,execApprovalsSnapshot:Ke(),execApprovalsForm:e.execApprovalsForm,execApprovalsError:e.execApprovalsError,execApprovalsSavedNotice:e.execApprovalsSavedNotice,execApprovalsTarget:E,execApprovalsTargetNodeId:D,onDevicePairSetupOpen:()=>{b&&R.connected&&n.overlays.openDevicePairSetup()},onDeviceApprove:e=>{y&&G(t=>Pe(t,e))},onDeviceReject:e=>void N.confirmPairingReject(`device`,e),onNodeApprove:e=>{y&&G(t=>je(t,e))},onNodeReject:e=>void N.confirmPairingReject(`node`,e),onInventoryRemove:e=>void N.confirmInventoryRemoval({kind:`entry`,entry:e}),onInventoryCleanup:e=>{e.length>0&&N.confirmInventoryRemoval({kind:`stale`,entries:e})},onDeviceRotate:(e,t,n)=>void N.reportRotationOutcome(e,t,n),onDeviceRevoke:(e,t)=>void N.confirmTokenRevoke(e,t),onDeviceRename:e=>void N.editAlias(e),onLoadConfig:()=>void n.runtimeConfig.discardDraft({reloadOnly:!0}),onLoadExecApprovals:Q,onBindDefault:e=>B.bindNode(e),onBindAgent:(e,t)=>B.bindNode(t,e),onExecApprovalsTargetChange:(e,t)=>void it(e,t),onExecApprovalsPatch:(e,t)=>et(n=>Ie(n,e,t)),onExecApprovalsRemove:e=>et(t=>Ae(t,e)),onSaveExecApprovals:()=>void B.save()}}let ct=g(st);ge(g(()=>e.routeData),Xe);var $=We(),lt=$.firstChild,ut=lt.nextSibling;return $._$owner=_e(),ye($,_(Ee,{get title(){return a(`devices`,s)},get subtitle(){return[be(()=>o(`devices`,s)),` `,_(Te,{url:`https://docs.openclaw.ai/nodes`})]}}),lt),ye($,_(De,{get children(){return _(Ue,he(ct,{get inventorySaving(){return V.saving()},get execApprovalsSaving(){return B.approvalsSaving()||ct().execApprovalsSaving}}))}}),ut),$}var We;function M(){return(M=e((()=>{Se(),ve(),d(),n(),i(),m(),b(),x(),f(),ie(),k(),S(),c(),pe(),y(),re(),oe(),u(),p(),T(),A(),w(),O(),E(),D(),We=Ce(`<openclaw-devices-page><!><!>`,1)})))()}export{M as n,j as t};