UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.6 kB
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Qt as n,Xt as r,ft as i,gt as a,nu as o,pt as s,vt as c}from"./control-ui-connection-Bfj9beF_.js";import{o as l,r as u}from"./config-form-utils-BqrafwiP.js";var d=t({createInitialDevicesState:()=>f,loadDevices:()=>h,loadExecApprovals:()=>P,loadNodes:()=>m});function f(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,devicesDeciding:[],execApprovalsLoading:!1,execApprovalsSaving:!1,execApprovalsDirty:!1,execApprovalsSnapshot:null,execApprovalsForm:null,execApprovalsSelectedAgent:null}}function p(e,t,n){return e.connected&&e.client===t&&e.requestGeneration===n}function m(e,t){return g(e,`nodes`,t)}function h(e,t){return g(e,`devices`,t)}async function g(e,t,n){let i=e.client;if(!i||!e.connected)return;let a=`${t}Loading`,o=`${t}QueuedRefresh`,s=t===`nodes`?`lastError`:`devicesError`;if(e[a]){e[o]=e[o]===`visible`||n?.quiet!==!0?`visible`:`quiet`;return}e[a]=!0,n?.quiet||(e[s]=null);let c=e.requestGeneration;try{if(t===`nodes`){let t=await i.request(`node.list`,{});p(e,i,c)&&(e.nodes=t.nodes)}else{let t=await i.request(`device.pair.list`,{});p(e,i,c)&&(e.devicesList=t)}}catch(t){!n?.quiet&&p(e,i,c)&&(e[s]=r(t))}finally{if(p(e,i,c)){e[a]=!1;let n=e[o];e[o]=`none`,n!==`none`&&await g(e,t,{quiet:n===`quiet`})}}}async function _(e,t){let n=e.client;if(!n||!e.connected)return null;let i=e.requestGeneration;try{let r=await t(n);return p(e,n,i)&&await h(e),r}catch(t){return p(e,n,i)&&(e.devicesError=r(t)),null}}async function v(e,t,n){if(e.devicesDeciding.some(e=>e.requestId===t))return;let r={requestId:t};e.devicesDeciding=[...e.devicesDeciding,r];try{await n()}finally{e.devicesDeciding=e.devicesDeciding.filter(e=>e!==r)}}async function y(e,t){await v(e,t,()=>_(e,e=>e.request(`device.pair.approve`,{requestId:t})))}async function b(e,t){await v(e,t,()=>_(e,e=>e.request(`device.pair.reject`,{requestId:t})))}async function x(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 S(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 C(e,t){let n=e.client;if(n&&e.connected)try{await t(n),await S(e)}catch(t){await S(e,{error:r(t)})}}function w(e,t){return C(e,e=>x(e,t))}async function T(e,t){let n=e.client;if(!n||!e.connected||t.length===0)return;let i=[];for(let e of t)try{await x(n,e)}catch(t){i.push(`${e.name}: ${r(t)}`)}await S(e,i.length>0?{error:`Failed to remove ${i.length} entr${i.length===1?`y`:`ies`}: ${i[0]}`}:void 0)}async function E(e,t){let n=e.client;if(!n||!e.connected){let t=r(Error(`The Gateway connection is not available.`));return e.devicesError=t,t}let i=e.requestGeneration;try{return await n.request(`device.pair.rename`,t),p(e,n,i)&&await h(e),null}catch(t){let a=r(t);return p(e,n,i)&&(e.devicesError=a),a}}function D(e,t){return v(e,t,()=>C(e,e=>e.request(`node.pair.approve`,{requestId:t})))}function O(e,t){return v(e,t,()=>C(e,e=>e.request(`node.pair.reject`,{requestId:t})))}function k(e,t){return typeof e==`string`&&e.trim().length>0&&e.trim()===t.trim()}function A(e,t){let n=o(e),r=n?.scopes,i=n?.rotatedAtMs,a=k(n?.deviceId,t.deviceId)&&k(n?.role,t.role)&&Array.isArray(r)&&r.every(e=>typeof e==`string`&&e.length>0)&&typeof i==`number`&&Number.isInteger(i)&&i>=0,s=n?.token,c=typeof s==`string`&&s.length>0?s:void 0,l=s===void 0,u=n?.tokenDelivery;if(a){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 j(e,t){return _(e,async e=>{let{gatewayUrl:n,...r}=t,i=await e.request(`device.token.rotate`,r),o=A(i,r);if(o.delivery===`in-band`){let e=await a();(i.deviceId===e.deviceId||r.deviceId===e.deviceId)&&c({deviceId:e.deviceId,gatewayUrl:n,role:r.role,token:o.token,scopes:i.scopes??r.scopes??[]})}return o})}async function M(e,t){await _(e,async e=>{let{gatewayUrl:n,...r}=t;await e.request(`device.token.revoke`,r);let o=await a();r.deviceId===o.deviceId&&i({deviceId:o.deviceId,gatewayUrl:n,role:r.role})})}function N(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 P(e,t){let n=e.client;if(!n||!e.connected||e.execApprovalsLoading)return;e.execApprovalsLoading=!0,e.lastError=null;let i=e.requestGeneration;try{let r=N(t);if(!r){e.lastError=`Select a node before loading exec approvals.`;return}let a=await n.request(r.method,r.params);p(e,n,i)&&F(e,a)}catch(t){p(e,n,i)&&(e.lastError=r(t))}finally{p(e,n,i)&&(e.execApprovalsLoading=!1)}}function F(e,t){e.execApprovalsDirty||(e.execApprovalsSnapshot=t,I(t)?(e.execApprovalsForm=null,e.execApprovalsDirty=!1):e.execApprovalsForm=t.file)}function I(e){return!!(e&&`enabled`in e)}async function L(e,t){let n=e.client;if(!n||!e.connected)return;e.execApprovalsSaving=!0,e.lastError=null;let i=e.requestGeneration;try{if(I(e.execApprovalsSnapshot)){e.lastError=`Host-native node approvals are read-only here; use the companion app or approvals set --node.`;return}let r=e.execApprovalsSnapshot?.hash;if(!r){e.lastError=`Exec approvals hash missing; reload and retry.`;return}let a=N(t,{file:e.execApprovalsForm??e.execApprovalsSnapshot?.file??{},baseHash:r});if(!a){e.lastError=`Select a node before saving exec approvals.`;return}if(await n.request(a.method,a.params),!p(e,n,i))return;e.execApprovalsDirty=!1,await P(e,t)}catch(t){p(e,n,i)&&(e.lastError=r(t))}finally{p(e,n,i)&&(e.execApprovalsSaving=!1)}}function R(e,t,n,r){if(I(e.execApprovalsSnapshot)){e.lastError=`Host-native node approvals are read-only here.`;return}let i=e.execApprovalsForm??e.execApprovalsSnapshot?.file??{},a=u(i,t,n,r);e.execApprovalsForm=(a.ok?o(a.value):void 0)??i,e.execApprovalsDirty=!0}function z(e,t,n){R(e,t,n,`copy-set`)}function B(e,t){R(e,t,void 0,`copy-remove`)}function V(){return(V=e((()=>{l(),n(),s()})))()}export{j as _,I as a,m as c,O as d,B as f,M as g,E as h,V as i,d as l,T as m,D as n,h as o,w as p,f as r,P as s,y as t,b as u,L as v,z as y};