UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

75 lines (74 loc) • 2.81 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { r as defaultRuntime } from "./runtime-B-SLYP-m.mjs"; import { i as normalizeChatChannelId, n as CHAT_CHANNEL_ORDER } from "./ids-BRSWrLzE.mjs"; import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-iAw3gSDD.mjs"; import "./plugin-registry-BrQav-kR.mjs"; import "./registry-BB86xKJa.mjs"; import { r as theme } from "./theme-BOI0xyRZ.mjs"; import { n as readConfiguredParsedLogTail } from "./log-tail-CKSM_qfb.mjs"; import { t as parseLogsPositiveInt } from "./logs-cli.options-DAFf8S0V.mjs"; //#region 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); } /** Print or serialize recent log lines matching one channel subsystem/module. */ 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()); } } //#endregion export { channelsLogsCommand };