UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.58 kB
import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{c as prepareChildRuntimeViability}from"./child-runtime-viability-1cqYEa1U.mjs";import{n as getSessionRowProjection}from"./session-row-projection-access-w2LnU_PB.mjs";import{r as HEALTH_REFRESH_INTERVAL_MS}from"./server-constants-BmIepgnr.mjs";import{t as settleCurrentReadPreparations}from"./current-read-authority-J_xgisvq.mjs";import{t as getPreparedModelRuntimeStartupStatus}from"./prepared-model-runtime.startup-status-BVh-NiXH.mjs";import{n as readGatewayMaintenanceWork}from"./gateway-active-work-CdK8AANw.mjs";import{r as getGatewayRecentCrashes}from"./gateway-crash-DCoZGkY8.mjs";import{r as respondUnavailableOnThrow}from"./response-BYbuAh7a.mjs";import{n as readGatewayProcessVitals,r as readGatewayWorkerPoolFacts}from"./process-vitals-CF2jdSpc.mjs";import{t as prepareStatusSummary}from"./summary-BOdtipH0.mjs";import{r as buildContextEngineHealthSummary,t as buildDeliveryQueueHealthSummary}from"./delivery-queue-jQVbV6E0.mjs";import{t as createGatewayServerActiveWorkInspectors}from"./server-active-work-CBHwEcWm.mjs";import{t as shouldScheduleBackgroundHealthRefresh}from"./health-refresh-admission-CLSXCttj.mjs"; //!src/gateway/server-methods/health.ts const ADMIN_SCOPE=`operator.admin`;function formatPublishedChildRuntime(e,t){return t?e:{execPath:`[redacted]`,available:e.available}}function cachedLifecycleDiffersFromRuntime(e,t){return[`running`,`connected`,`lifecycle`].some(n=>t[n]!==void 0&&e?.[n]!==t[n])}function cachedHealthDiffersFromRuntime(e,t){return Object.entries(t.channels).some(([t,n])=>n&&cachedLifecycleDiffersFromRuntime(e.channels[t],n))||Object.entries(t.channelAccounts).some(([t,n])=>{if(!n)return false;const r=e.channels[t]?.accounts;return Object.entries(n).some(([e,t])=>t&&cachedLifecycleDiffersFromRuntime(r?.[e],t))})}const healthHandlers={health:async({respond:e,context:t,params:n,client:r})=>{const{getHealthCache:i,refreshHealthSnapshot:a,logHealth:o}=t;const s=n?.probe===true;const c=r?.connect.scopes?.includes(ADMIN_SCOPE)??false;const l=Date.now();const u=i();let d=false;if(!s&&u)try{d=cachedHealthDiffersFromRuntime(u,t.getRuntimeSnapshot())}catch{d=true}if(!s&&u&&!d&&l-u.ts<6e4){const n=t.getEventLoopHealth;const i=t.getConfigReloaderHotReloadStatus?.();const{contextEngines:s,deliveryQueues:d,eventLoop:f,...p}=u;const[m,h]=await settleCurrentReadPreparations([buildDeliveryQueueHealthSummary(),buildContextEngineHealthSummary()]);const g=(await prepareChildRuntimeViability()).publish();const _=n?.();e(true,{...p,coreReady:t.getReadiness?.(g).coreReady,modelRuntime:getPreparedModelRuntimeStartupStatus(),..._?{eventLoop:_}:{},...h?{contextEngines:h}:{},...m?{deliveryQueues:m}:{},...i?{configReload:{hotReloadStatus:i}}:{},childRuntime:formatPublishedChildRuntime(g,r?.connect.scopes?.includes(ADMIN_SCOPE)??false),recentCrashes:getGatewayRecentCrashes()},void 0,{cached:true});if(shouldScheduleBackgroundHealthRefresh(a,l))a({probe:false,includeSensitive:c}).catch(e=>o.error(`background health refresh failed: ${formatErrorMessage(e)}`));return}await respondUnavailableOnThrow(e,async()=>{const n=await a({probe:s,includeSensitive:c});const i=(await prepareChildRuntimeViability()).publish();e(true,{...n,coreReady:t.getReadiness?.(i).coreReady,modelRuntime:getPreparedModelRuntimeStartupStatus(),childRuntime:formatPublishedChildRuntime(i,r?.connect.scopes?.includes(ADMIN_SCOPE)??false),recentCrashes:getGatewayRecentCrashes()},void 0)})},status:async({respond:e,client:t,params:n,context:r})=>{const i=(t?.connect.scopes??[]).includes(ADMIN_SCOPE);const a=await r.hostDesktopService?.status();const o=await prepareStatusSummary({includeSensitive:i,includeChannelSummary:n.includeChannelSummary!==false,includeCliProjection:n.includeCliProjection===true,sessionRowProjection:getSessionRowProjection(r),...a?{hostDesktopStatus:a}:{}});const s=await readGatewayWorkerPoolFacts();const c=await prepareChildRuntimeViability();const l=o.publish().summary;const u=r.hostLifecycle?.getShutdownBudget?.();const d=u?readGatewayMaintenanceWork(createGatewayServerActiveWorkInspectors(r)):void 0;const f=u&&d?{...u,activeWork:d.counts,writeCustody:d.writeCustody}:void 0;e(true,{...l,modelRuntime:getPreparedModelRuntimeStartupStatus(),...readGatewayProcessVitals(r.getEventLoopHealth),workerPools:s,pid:process.pid,shutdownBudget:f,childRuntime:formatPublishedChildRuntime(c.publish(),t?.connect.scopes?.includes(ADMIN_SCOPE)??false),recentCrashes:getGatewayRecentCrashes(),pluginReload:r.getPluginReloadStatus?.()},void 0)}};export{healthHandlers};