UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

70 lines (69 loc) • 2.52 kB
import { i as getLogger, n as writeRootConsoleLine, o as defaultRuntime, s as isVerbose, t as createSubsystemLogger } from "./subsystem-Caj1-NVj.mjs"; import chalk, { Chalk } from "chalk"; //#region packages/terminal-core/src/palette.ts const LOBSTER_PALETTE = { accent: "#FF5A2D", accentBright: "#FF7A3D", accentDim: "#D14A22", info: "#FF8A5B", success: "#2FBF71", warn: "#FFB020", error: "#E23D2D", muted: "#8B7F77" }; //#endregion //#region packages/terminal-core/src/theme.ts const hasForceColor = typeof process.env.FORCE_COLOR === "string" && process.env.FORCE_COLOR.trim().length > 0 && process.env.FORCE_COLOR.trim() !== "0"; const baseChalk = process.env.NO_COLOR && !hasForceColor ? new Chalk({ level: 0 }) : chalk; const hex = (value) => baseChalk.hex(value); /** Shared terminal theme color functions. */ const theme = { accent: hex(LOBSTER_PALETTE.accent), accentBright: hex(LOBSTER_PALETTE.accentBright), accentDim: hex(LOBSTER_PALETTE.accentDim), info: hex(LOBSTER_PALETTE.info), success: hex(LOBSTER_PALETTE.success), warn: hex(LOBSTER_PALETTE.warn), error: hex(LOBSTER_PALETTE.error), muted: hex(LOBSTER_PALETTE.muted), heading: baseChalk.bold.hex(LOBSTER_PALETTE.accent), command: hex(LOBSTER_PALETTE.accentBright), option: hex(LOBSTER_PALETTE.warn) }; //#endregion //#region src/logger.ts const subsystemPrefixRe = /^([a-z][a-z0-9-]{1,20}):\s+(.*)$/i; function splitSubsystem(message) { const match = message.match(subsystemPrefixRe); if (!match) return null; const subsystem = match.at(1); const rest = match.at(2); if (subsystem === void 0 || rest === void 0) return null; return { subsystem, rest }; } function logWithSubsystem(level, message, runtime) { const parsed = runtime === defaultRuntime ? splitSubsystem(message) : null; if (parsed) { createSubsystemLogger(parsed.subsystem)[level](parsed.rest); return; } const runtimeMethod = level === "error" ? "error" : "log"; const formatted = theme[level](message); if (runtime !== defaultRuntime || !writeRootConsoleLine(runtimeMethod, formatted)) runtime[runtimeMethod](formatted); getLogger()[level](message); } function logWarn(message, runtime = defaultRuntime) { logWithSubsystem("warn", message, runtime); } function logError(message, runtime = defaultRuntime) { logWithSubsystem("error", message, runtime); } function logDebug(message) { getLogger().debug(message); if (isVerbose()) console.log(theme.muted(message)); } //#endregion export { theme as i, logError as n, logWarn as r, logDebug as t };