UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.72 kB
import{r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{i as SESSION_PROCESS_TAIL_MAX_CHARS,n as SESSION_PROCESSES_MAX_ROWS,r as SESSION_PROCESS_NAME_MAX_CHARS,t as SESSION_PROCESSES_MAX_BYTES}from"./session-processes-CygLobpL.mjs";import{I as deriveSessionName,O as tail,a as compareProcessSessionStartOrder,m as listRunningSessions,p as listFinishedSessions,u as getSession,x as processSessionInstanceId}from"./bash-process-registry-BL4zA8Yf.mjs";import{a as isConfirmedRequestedStop,i as isBackgroundExecCancellable,t as cancelBackgroundExecSession}from"./bash-process-control-ByEEGn0n.mjs"; //!src/agents/bash-process-observation.ts function inScope(e,t){return Boolean(e.scopeKey&&t.scopeKeys.includes(e.scopeKey)&&(e.agentId===void 0||e.agentId===t.agentId)&&(e.scopeKey!==`global`||e.agentId===t.agentId))}function countRunningBackgroundProcesses(e){return listRunningSessions().filter(t=>!t.exited&&inScope(t,e)).length}function prepareRunningBackgroundProcessCount(){const e=/* @__PURE__ */ new Map;for(const t of listRunningSessions()){const{scopeKey:n,agentId:r}=t;if(t.exited||!n||n===`global`&&r===void 0)continue;let i=e.get(n);if(!i)e.set(n,i=/* @__PURE__ */ new Map);i.set(r,(i.get(r)??0)+1)}return({scopeKeys:t,agentId:n})=>{let r=0;for(let i=0;i<t.length;i++){const a=t[i];if(t.indexOf(a)!==i)continue;const o=e.get(a);r+=(o?.get(n)??0)+(o?.get(void 0)??0)}return r}}function readBackgroundProcesses(e){const t=[...listRunningSessions(),...listFinishedSessions()].filter(t=>inScope(t,e)).toSorted((e,t)=>Number(e.exited)-Number(t.exited)||compareProcessSessionStartOrder(e,t));const n=[];let r=0;for(const e of t){const t=tail(e.tail,SESSION_PROCESS_TAIL_MAX_CHARS);const i={processId:e.id,instanceId:processSessionInstanceId(e),name:truncateUtf16Safe(deriveSessionName(e.command)||e.command,160),status:isConfirmedRequestedStop(e)?`killed`:e.terminalStatus??`running`,startedAt:e.startedAt,...e.endedAt!==void 0?{endedAt:e.endedAt}:{},tail:t,truncated:e.truncated||e.totalOutputChars>t.length,canStop:isBackgroundExecCancellable(e)&&!e.cancellationRequested,...e.exitCode!==void 0?{exitCode:e.exitCode}:{},...e.exitSignal!==void 0?{exitSignal:e.exitSignal}:{},...e.exitReason!==void 0?{exitReason:e.exitReason}:{}};r+=Buffer.byteLength(JSON.stringify(i),`utf8`);if(n.length>=50||r>49152)break;n.push(i)}return{processes:n,truncated:n.length<t.length}}function stopBackgroundProcess(e,t){const n=getSession(t.processId);return{requested:Boolean(n&&inScope(n,e)&&processSessionInstanceId(n)===t.instanceId&&cancelBackgroundExecSession(n.id))}}export{stopBackgroundProcess as i,prepareRunningBackgroundProcessCount as n,readBackgroundProcesses as r,countRunningBackgroundProcesses as t};