UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

87 lines (86 loc) • 2.92 kB
import { st as expectDefined } from "./redact-BwKH5fIe.mjs"; import { a as getLogger, f as isVerbose, r as writeRootConsoleLine, t as createSubsystemLogger, u as defaultRuntime } from "./subsystem-EYGCijzb.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(params) { const parsed = params.runtime === defaultRuntime ? splitSubsystem(params.message) : null; if (parsed) { expectDefined(createSubsystemLogger(parsed.subsystem)[params.subsystemMethod], "subsystem logger method")(parsed.rest); return; } const formatted = params.runtimeFormatter(params.message); if (params.runtime !== defaultRuntime || !writeRootConsoleLine(params.runtimeMethod, formatted)) params.runtime[params.runtimeMethod](formatted); getLogger()[params.loggerMethod](params.message); } theme.info; const warn = theme.warn; const danger = theme.error; function logWarn(message, runtime = defaultRuntime) { logWithSubsystem({ message, runtime, runtimeMethod: "log", runtimeFormatter: warn, loggerMethod: "warn", subsystemMethod: "warn" }); } function logError(message, runtime = defaultRuntime) { logWithSubsystem({ message, runtime, runtimeMethod: "error", runtimeFormatter: danger, loggerMethod: "error", subsystemMethod: "error" }); } 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 };