openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.46 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Nt as t,jt as n}from"./control-ui-connection-Bfj9beF_.js";import{a as r,c as i,d as a,f as o,l as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./device-pair-setup-runtime-DXEqakSV.js";function h(e){let n=d({client:e.gateway.snapshot.client,connected:e.gateway.snapshot.phase===`connected`,onChange:e.publish}),{gateway:r,isDisposed:a,publish:o}=e,u=0,f={invalidate(e={}){u+=1,e.clear&&(n.pendingCount=0)},async refresh(){let e=r.snapshot.client;if(!e||r.snapshot.phase!==`connected`||a()||!n.devicePairSetupOpen||!t(r.snapshot).canAdmin)return;let i=++u,s;try{s=await e.request(`device.pair.list`,{})}catch{return}!a()&&i===u&&r.snapshot.client===e&&r.snapshot.phase===`connected`&&n.devicePairSetupOpen&&t(r.snapshot).canAdmin&&(n.pendingCount=Array.isArray(s.pending)?s.pending.length:0,o())}};return{runtime:g,state:n,pendingCount:f,close(e=!0){f.invalidate({clear:e}),p(n)},handleEvent(e){if(e.event===`device.pair.setup.completed`){let t=i(e.payload);return t&&c(n,t),!0}if(e.event===`device.pair.setup.deliveryUncertain`){let t=s(e.payload);return t&&l(n,t),!0}return e.event===`device.pair.requested`||e.event===`device.pair.resolved`?(f.refresh(),!0):!1}}}var g;function _(){return(_=e((()=>{r(),n(),g={openDevicePairSetup:f,readDevicePairSetupSnapshot:m,refreshDevicePairSetup:a,setDevicePairSetupAccess:o,syncDevicePairSetupCountdown:u}})))()}_();export{h as createOverlayPairing};