openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.98 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Ji as t}from"./control-ui-foundation-ZY_Flbbd.js";import{Ci as n,Ei as r,Gl as i,aa as a,ca as o,na as s,ql as c,ta as l,yi as u}from"./control-ui-core-3P365fbR.js";function d(e={}){return{client:e.client??null,connected:e.connected??!1,requestGeneration:0,nodesLoading:!1,nodesQueuedRefresh:`none`,nodes:[],lastError:null,devicesLoading:!1,devicesQueuedRefresh:`none`,devicesError:null,devicesList:null,execApprovalsLoading:!1,execApprovalsSaving:!1,execApprovalsDirty:!1,execApprovalsSnapshot:null,execApprovalsForm:null,execApprovalsSelectedAgent:null}}function f(e,t,n){return e.connected&&e.client===t&&e.requestGeneration===n}function p(e,t){return e===`visible`||t!==!0?`visible`:`quiet`}async function m(e,t){let n=e.client;if(!n||!e.connected)return;if(e.nodesLoading){e.nodesQueuedRefresh=p(e.nodesQueuedRefresh,t?.quiet);return}e.nodesLoading=!0,t?.quiet||(e.lastError=null,e.chatError=null);let r=e.requestGeneration;try{let t=await n.request(`node.list`,{});f(e,n,r)&&(e.nodes=Array.isArray(t.nodes)?t.nodes:[])}catch(a){!t?.quiet&&f(e,n,r)&&(e.lastError=i(a))}finally{if(f(e,n,r)){e.nodesLoading=!1;let t=e.nodesQueuedRefresh;e.nodesQueuedRefresh=`none`,t!==`none`&&await m(e,{quiet:t===`quiet`})}}}async function h(e,t){let n=e.client;if(!n||!e.connected)return;if(e.devicesLoading){e.devicesQueuedRefresh=p(e.devicesQueuedRefresh,t?.quiet);return}e.devicesLoading=!0,t?.quiet||(e.devicesError=null);let r=e.requestGeneration;try{let t=await n.request(`device.pair.list`,{});f(e,n,r)&&(e.devicesList={pending:Array.isArray(t?.pending)?t.pending:[],paired:Array.isArray(t?.paired)?t.paired:[]})}catch(a){!t?.quiet&&f(e,n,r)&&(e.devicesError=i(a))}finally{if(f(e,n,r)){e.devicesLoading=!1;let t=e.devicesQueuedRefresh;e.devicesQueuedRefresh=`none`,t!==`none`&&await h(e,{quiet:t===`quiet`})}}}async function g(e,t,n){let r=e.client;if(!r||!e.connected)return;let a=e.requestGeneration;try{await r.request(n,{requestId:t}),f(e,r,a)&&await h(e)}catch(t){f(e,r,a)&&(e.devicesError=i(t))}}function _(e,t){return g(e,t,`device.pair.approve`)}function v(e,t){return g(e,t,`device.pair.reject`)}async function y(e,t){t.removeNode&&await e.request(`node.pair.remove`,{nodeId:t.id}),t.removeDevice&&await e.request(`device.pair.remove`,{deviceId:t.id})}async function b(e,t){let n=t?.error!==void 0;await Promise.all([h(e,{quiet:n}),m(e,{quiet:n})]),t?.error!==void 0&&(e.devicesError=t.error)}async function x(e,t){let n=e.client;if(n&&e.connected)try{await y(n,t),await b(e)}catch(t){await b(e,{error:i(t)})}}async function S(e,t){let n=e.client;if(!n||!e.connected||t.length===0)return;let r=[];for(let e of t)try{await y(n,e)}catch(t){r.push(`${e.name}: ${i(t)}`)}await b(e,r.length>0?{error:`Failed to remove ${r.length} entr${r.length===1?`y`:`ies`}: ${r[0]}`}:void 0)}async function C(e,t){let n=e.client;if(!n||!e.connected){let t=i(Error(`The Gateway connection is not available.`));return e.devicesError=t,t}let r=e.requestGeneration;try{return await n.request(`device.pair.rename`,t),f(e,n,r)&&await h(e),null}catch(t){let a=i(t);return f(e,n,r)&&(e.devicesError=a),a}}async function w(e,t,n){if(e.client&&e.connected)try{await e.client.request(n,{requestId:t}),await b(e)}catch(t){await b(e,{error:i(t)})}}function T(e,t){return w(e,t,`node.pair.approve`)}function E(e,t){return w(e,t,`node.pair.reject`)}function D(e,t){return typeof e==`string`&&e.trim().length>0&&e.trim()===t.trim()}function O(e,n){let r=t(e)?e:void 0,i=r?.scopes,a=r?.rotatedAtMs,o=D(r?.deviceId,n.deviceId)&&D(r?.role,n.role)&&Array.isArray(i)&&i.every(e=>typeof e==`string`&&e.length>0)&&typeof a==`number`&&Number.isInteger(a)&&a>=0,s=r?.token,c=typeof s==`string`&&s.length>0?s:void 0,l=s===void 0,u=r?.tokenDelivery;if(o){if(c&&(u===void 0||u===`in-band`))return{delivery:`in-band`,token:c};if(l&&(u===void 0||u===`withheld-cross-device`))return{delivery:`withheld-cross-device`}}throw Error(`Rotation returned an unusable result (tokenDelivery=${JSON.stringify(u)}, token ${c?`present`:l?`absent`:`malformed`}). The previous token no longer works; pair the device again if it does not reconnect.`)}async function k(e,t){let n=e.client;if(!n||!e.connected)return null;let r=e.requestGeneration;try{let{gatewayUrl:i,...s}=t,c=await n.request(`device.token.rotate`,s),l=O(c,s);if(l.delivery===`in-band`){let e=await a();(c.deviceId===e.deviceId||s.deviceId===e.deviceId)&&o({deviceId:e.deviceId,gatewayUrl:i,role:s.role,token:l.token,scopes:c.scopes??s.scopes??[]})}return f(e,n,r)&&await h(e),l}catch(t){return f(e,n,r)&&(e.devicesError=i(t)),null}}async function A(e,t){let n=e.client;if(!n||!e.connected)return;let r=e.requestGeneration;try{let{gatewayUrl:i,...o}=t;await n.request(`device.token.revoke`,o);let s=await a();o.deviceId===s.deviceId&&l({deviceId:s.deviceId,gatewayUrl:i,role:o.role}),f(e,n,r)&&await h(e)}catch(t){f(e,n,r)&&(e.devicesError=i(t))}}function j(e,t){let n=t?`set`:`get`,r=t??{};if(!e||e.kind===`gateway`)return{method:`exec.approvals.${n}`,params:r};let i=e.nodeId.trim();return i?{method:`exec.approvals.node.${n}`,params:{...r,nodeId:i}}:null}async function M(e,t){let n=e.client;if(!n||!e.connected||e.execApprovalsLoading)return;e.execApprovalsLoading=!0,e.lastError=null,e.chatError=null;let r=e.requestGeneration;try{let i=j(t);if(!i){e.lastError=`Select a node before loading exec approvals.`;return}let a=await n.request(i.method,i.params);f(e,n,r)&&N(e,a)}catch(t){f(e,n,r)&&(e.lastError=i(t))}finally{f(e,n,r)&&(e.execApprovalsLoading=!1)}}function N(e,t){if(e.execApprovalsSnapshot=t,P(t)){e.execApprovalsForm=null,e.execApprovalsDirty=!1;return}e.execApprovalsDirty||(e.execApprovalsForm=structuredClone(t.file))}function P(e){return!!(e&&`enabled`in e)}async function F(e,t){let n=e.client;if(!n||!e.connected)return;e.execApprovalsSaving=!0,e.lastError=null,e.chatError=null;let r=e.requestGeneration;try{if(P(e.execApprovalsSnapshot)){e.lastError=`Host-native node approvals are read-only here; use the companion app or approvals set --node.`;return}let i=e.execApprovalsSnapshot?.hash;if(!i){e.lastError=`Exec approvals hash missing; reload and retry.`;return}let a=j(t,{file:e.execApprovalsForm??e.execApprovalsSnapshot?.file??{},baseHash:i});if(!a){e.lastError=`Select a node before saving exec approvals.`;return}if(await n.request(a.method,a.params),!f(e,n,r))return;e.execApprovalsDirty=!1,await M(e,t)}catch(t){f(e,n,r)&&(e.lastError=i(t))}finally{f(e,n,r)&&(e.execApprovalsSaving=!1)}}function I(e,t){if(P(e.execApprovalsSnapshot)){e.lastError=`Host-native node approvals are read-only here.`;return}let n=structuredClone(e.execApprovalsForm??e.execApprovalsSnapshot?.file??{});t(n),e.execApprovalsForm=n,e.execApprovalsDirty=!0}function L(e,t,n){I(e,e=>r(e,t,n))}function R(e,t){I(e,e=>n(e,t))}function z(){return(z=e((()=>{u(),c(),s()})))()}export{F as _,P as a,m as c,R as d,x as f,k as g,A as h,z as i,v as l,C as m,T as n,h as o,S as p,d as r,M as s,_ as t,E as u,L as v};