openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
6 lines • 6.2 kB
JavaScript
import{c as normalizeOptionalLowercaseString,l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{t as canAccess}from"./path-existence-BR9MXlgL.mjs";import{o as listSessionBindingsBySessionsAsync}from"./session-binding-service-TO5btU7E.mjs";import{a as toAcpRuntimeError}from"./errors-C1zF32os.mjs";import{t as formatAcpRuntimeErrorText}from"./error-text-CMofcA5J.mjs";import"./errors-BaJzP_Lf.mjs";import{i as requireAcpRuntimeBackend,t as getAcpRuntimeBackend}from"./registry-Dg88GMl5.mjs";import{i as resolveBundledPluginInstallCommandHint}from"./bundled-sources-imFFFyl2.mjs";import{n as getAcpSessionManager}from"./manager-CpIPv3ym.mjs";import{n as readAcpSessionEntryAsync}from"./session-meta-read-hVOPXzGo.mjs";import{o as listAcpSessionEntries}from"./session-meta-skdU9pJ4.mjs";import{n as commandReply}from"./command-gates-BMLoLImo.mjs";import{r as resolveAcpCommandBindingContext,t as resolveAcpTargetSessionKey}from"./targets-q0eTYMpe.mjs";import{n as ACP_DOCTOR_USAGE,p as formatAcpCapabilitiesText,r as ACP_INSTALL_USAGE,s as ACP_SESSIONS_USAGE}from"./shared-BGKM9NK1.mjs";import path from"node:path";
//!src/auto-reply/reply/commands-acp/diagnostics.ts
async function resolveAcpInstallCommandHint(e){const t=normalizeOptionalString(e.acp?.runtime?.installCommand);if(t)return t;const n=process.cwd();const r=normalizeOptionalLowercaseString(e.acp?.backend)??`acpx`;if(r===`acpx`){const e=path.join(n,`extensions`,`acpx`);if(await canAccess(e))return`openclaw plugins install ${e}`;const t=resolveBundledPluginInstallCommandHint({pluginId:r,workspaceDir:n});if(t){const e=t.replace(/^openclaw plugins install /u,``);const r=path.resolve(e);const i=path.relative(n,r);if((i.length===0||!i.startsWith(`..`)&&!path.isAbsolute(i))&&await canAccess(r))return t}return`openclaw plugins install acpx`}return`Install and enable the plugin that provides ACP backend "${r}".`}async function handleAcpDoctorAction(e,t){if(t.length>0)return commandReply(`⚠️ ${ACP_DOCTOR_USAGE}`);const n=normalizeOptionalString(e.cfg.acp?.backend)??`acpx`;const r=await resolveAcpInstallCommandHint(e.cfg);const i=getAcpRuntimeBackend(n);const a=getAcpSessionManager().getObservabilitySnapshot();const o=[`ACP doctor:`,`-----`,`configuredBackend: ${n}`,`activeRuntimeSessions: ${a.runtimeCache.activeSessions}`,`runtimeIdleTtlMs: ${a.runtimeCache.idleTtlMs}`,`evictedIdleRuntimes: ${a.runtimeCache.evictedTotal}`,`activeTurns: ${a.turns.active}`,`queueDepth: ${a.turns.queueDepth}`,`turnLatencyMs: avg=${a.turns.averageLatencyMs}, max=${a.turns.maxLatencyMs}`,`turnCounts: completed=${a.turns.completed}, failed=${a.turns.failed}`];const s=Object.entries(a.errorsByCode).map(([e,t])=>`${e}=${t}`).join(`, `)||`(none)`;o.push(`errorCodes: ${s}`);o.push(`registeredBackend: ${i?i.id:`(none)`}`);const c=e.cfg.plugins?.allow;const l=normalizeLowercaseStringOrEmpty(n);const u=Array.isArray(c)&&c.length>0&&Boolean(l)&&!c.some(e=>normalizeLowercaseStringOrEmpty(e)===l);if(u)o.push(`pluginActivation: blocked (${n} is missing from plugins.allow)`);if(i?.runtime.doctor)try{const e=await i.runtime.doctor();o.push(`runtimeDoctor: ${e.ok?`ok`:`error`} (${e.message})`);if(e.code)o.push(`runtimeDoctorCode: ${e.code}`);if(e.installCommand)o.push(`runtimeDoctorInstall: ${e.installCommand}`);for(const t of e.details??[])o.push(`runtimeDoctorDetail: ${t}`)}catch(e){o.push(`runtimeDoctor: error (${toAcpRuntimeError({error:e,fallbackCode:`ACP_TURN_FAILED`,fallbackMessage:`Runtime doctor failed.`}).message})`)}try{const e=requireAcpRuntimeBackend(n);const t=e.runtime.getCapabilities?await e.runtime.getCapabilities({}):{controls:[],configOptionKeys:[]};o.push(`healthy: yes`);o.push(`capabilities: ${formatAcpCapabilitiesText(t.controls??[])}`);if((t.configOptionKeys?.length??0)>0)o.push(`configKeys: ${t.configOptionKeys?.join(`, `)}`)}catch(e){const t=toAcpRuntimeError({error:e,fallbackCode:`ACP_TURN_FAILED`,fallbackMessage:`ACP backend doctor failed.`});o.push(`healthy: no`);o.push(formatAcpRuntimeErrorText(t));if(u)o.push(`next: add "${n}" to plugins.allow or unset plugins.allow.`);o.push(`next: ${r}`);o.push(`next: openclaw config set plugins.entries.${n}.enabled true`);if(l===`acpx`)o.push("next: verify acpx is installed (`acpx --help`).")}return commandReply(o.join(`
`))}async function handleAcpInstallAction(e,t){if(t.length>0)return commandReply(`⚠️ ${ACP_INSTALL_USAGE}`);const n=normalizeOptionalString(e.cfg.acp?.backend)??`acpx`;const r=await resolveAcpInstallCommandHint(e.cfg);const i=[`ACP install:`,`-----`,`configuredBackend: ${n}`,`run: ${r}`,`then: openclaw config set plugins.entries.${n}.enabled true`,`then: /acp doctor`];return commandReply(i.join(`
`))}async function handleAcpSessionsAction(e,t){if(t.length>0)return commandReply(ACP_SESSIONS_USAGE);const n=await resolveAcpTargetSessionKey({commandParams:e});if(!n.ok)return commandReply(`⚠️ ${n.error}`);const r=n.sessionKey;const i=resolveAcpCommandBindingContext(e);const a=i.channel;const o=i.accountId||void 0;const s=e.command.senderIsOwner?null:await readAcpSessionEntryAsync({cfg:e.cfg,sessionKey:r,agentId:n.agentId,assertCurrent:e.command.assertOwnerCurrent});e.command.assertOwnerCurrent?.();const c=e.command.senderIsOwner?await listAcpSessionEntries({cfg:e.cfg}):s?.entry&&s.acp?[s]:[];e.command.assertOwnerCurrent?.();const l=c.toSorted((e,t)=>(t.entry?.updatedAt??0)-(e.entry?.updatedAt??0)).slice(0,20);const u=await listSessionBindingsBySessionsAsync(l.filter(({entry:e,acp:t})=>e&&t).map(({storeSessionKey:e})=>e));e.command.assertOwnerCurrent?.();const d=l.map(({storeSessionKey:e,agentId:t,entry:i,acp:s})=>{if(!i||!s)return``;const c=(u.get(e)??[]).find(e=>(!a||e.conversation.channel===a)&&(!o||e.conversation.accountId===o))?.conversation.conversationId;const l=r===e&&n.agentId===t?`*`:` `;const d=normalizeOptionalString(i.label)||s.agent;const f=c?`, thread:${c}`:``;return`${l} ${d} (${s.mode}, ${s.state}, backend:${s.backend}${t?`, owner:${t}`:``}${f}) -> ${e}`}).filter(Boolean);return commandReply([`ACP sessions:`,`-----`,...d.length?d:[`(none)`]].join(`
`))}export{handleAcpDoctorAction,handleAcpInstallAction,handleAcpSessionsAction};