openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.34 kB
JavaScript
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{i as normalizeChatChannelId,n as CHAT_CHANNEL_ORDER}from"./ids-CXs0NhN-.mjs";import{n as loadPluginManifestRegistryForPluginRegistry}from"./plugin-registry-contributions-C4xBwxaW.mjs";import"./plugin-registry-BAbRxjjy.mjs";import"./registry-yecJKTDP.mjs";import{r as theme}from"./theme-DS2CtI9X.mjs";import{n as readConfiguredParsedLogTail}from"./log-tail-Dl0kMOWb.mjs";import{t as parseLogsPositiveInt}from"./logs-cli.options-B6kx8bea.mjs";
//!src/commands/channels/logs.ts
const DEFAULT_LIMIT=200;const MAX_BYTES=1e6;function matchesChannelContext(e,t){return[t,`channels/${t}`,`gateway/channels/${t}`].some(t=>e===t||e?.startsWith(`${t}/`)===true)}async function channelsLogsCommand(e){let t=e.channel===void 0?`all`:normalizeLowercaseStringOrEmpty(e.channel);const n=/* @__PURE__ */ new Set;if(t!==`all`){const r=loadPluginManifestRegistryForPluginRegistry({includeDisabled:true,env:process.env}).plugins.flatMap(e=>e.channels.flatMap(t=>{const n=normalizeLowercaseStringOrEmpty(t);return n?[{id:n,pluginId:e.id}]:[]}));const i=normalizeChatChannelId(t);t=i??t;for(const e of r)if(e.id===t)n.add(e.pluginId);if(!i&&n.size===0){const t=[...new Set(r.map(e=>e.id))].toSorted();const n=[`all`,.../* @__PURE__ */ new Set([...CHAT_CHANNEL_ORDER,...t])];throw new Error(`Unknown channel ${JSON.stringify(e.channel)}. Valid channels: ${n.join(`, `)}`)}}const r=parseLogsPositiveInt(e.lines,DEFAULT_LIMIT,`--lines`);const i=await readConfiguredParsedLogTail({limit:r,maxBytes:MAX_BYTES,filter:e=>t===`all`||[e.subsystem,e.module].some(e=>matchesChannelContext(e,t))||e.plugin!==void 0&&n.has(e.plugin)});const{lines:a,truncated:o}=i;if(e.json){defaultRuntime.writeJson({file:i.file,channel:t,truncated:o,lines:a});return}defaultRuntime.log(theme.info(`Log file: ${i.file}`));if(t!==`all`)defaultRuntime.log(theme.info(`Channel: ${t}`));if(o)defaultRuntime.log(theme.warn(`Log tail truncated; earlier entries were omitted.`));if(a.length===0){defaultRuntime.log(theme.muted(`No matching log lines.`));return}for(const e of a){const t=e.time?`${e.time} `:``;const n=e.level?`${normalizeLowercaseStringOrEmpty(e.level)} `:``;defaultRuntime.log(`${t}${n}${e.message}`.trim())}}export{channelsLogsCommand};