openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.46 kB
JavaScript
import{x as uniqueValues}from"./string-normalization-D_oBUpO3.mjs";import{o as getAsyncWorkSignal}from"./async-work-scope-DBcxYU4O.mjs";import{t as classifyOpenClawArgv}from"./gateway-process-argv-CNoJIDKD.mjs";import{a as resolveSqliteInspectionSignal}from"./sqlite-readonly-worker-context-BjXXEC4m.mjs";import{a as readGatewayLockProcessCmdline,i as readGatewayOwnerLeaseAsync,r as readGatewayOwnerLease,s as readWindowsListeningPidsOnPortSync}from"./gateway-owner-lease-9K6iKMiO.mjs";import{r as findGatewayPidsOnPortSync}from"./restart-stale-pids-DF3h-m9n.mjs";
//!src/infra/gateway-processes.ts
function inspectGatewayProcessArgv(e,t){const n={...t,pid:e,command:`gateway`};const r=classifyOpenClawArgv(readGatewayLockProcessCmdline(e,process.platform,1e3,void 0,t.env)??[],n);return{identity:r,requiresLease:r.kind!==`openclaw`&&process.platform===`win32`,withOwner:e=>classifyOpenClawArgv([],{...n,owner:e})}}function inspectGatewayProcess(e,t){try{const n=inspectGatewayProcessArgv(e,t);return n.requiresLease?n.withOwner(readGatewayOwnerLease({...t,current:true})):n.identity}catch{return{kind:`unclassified`,reason:`process ownership inspection failed`}}}async function findVerifiedGatewayListenerPidsOnPort(e,t={}){const n=resolveSqliteInspectionSignal(getAsyncWorkSignal());n?.throwIfAborted();const r=[];for(const i of gatewayListenerPidsOnPort(e))try{n?.throwIfAborted();const a=inspectGatewayProcessArgv(i,{...t,port:e});const o=a.requiresLease?await readGatewayOwnerLeaseAsync({...t,port:e}):void 0;n?.throwIfAborted();if((a.requiresLease?a.withOwner(o):a.identity).kind===`openclaw`)r.push(i)}catch{n?.throwIfAborted()}return r}function signalVerifiedGatewayPidSync(e,t,n={}){if(inspectGatewayProcess(e,n).kind!==`openclaw`)throw new Error(`refusing to signal non-gateway process pid ${e}`);try{process.kill(e,t)}catch(e){if(e.code!==`ESRCH`)throw e}}function findVerifiedGatewayListenerPidsOnPortSync(e,t={}){return gatewayListenerPidsOnPort(e).filter(n=>inspectGatewayProcess(n,{...t,port:e}).kind===`openclaw`)}function gatewayListenerPidsOnPort(e){const t=process.platform===`win32`?readWindowsListeningPidsOnPortSync(e):findGatewayPidsOnPortSync(e);return uniqueValues(t).filter(e=>Number.isFinite(e)&&e>0&&e!==process.pid)}function formatGatewayPidList(e){return e.join(`, `)}export{signalVerifiedGatewayPidSync as i,findVerifiedGatewayListenerPidsOnPortSync as n,formatGatewayPidList as r,findVerifiedGatewayListenerPidsOnPort as t};