@gguf/claw
Version:
Multi-channel AI gateway with extensible messaging integrations
28 lines (26 loc) • 1.42 kB
JavaScript
import { B as theme, R as colorize, z as isRich } from "./utils-CP9YLh6M.js";
//#region src/commands/health-format.ts
const formatKv = (line, rich) => {
const idx = line.indexOf(": ");
if (idx <= 0) return colorize(rich, theme.muted, line);
const key = line.slice(0, idx);
const value = line.slice(idx + 2);
const valueColor = key === "Gateway target" || key === "Config" ? theme.command : key === "Source" ? theme.muted : theme.info;
return `${colorize(rich, theme.muted, `${key}:`)} ${colorize(rich, valueColor, value)}`;
};
function formatHealthCheckFailure(err, opts = {}) {
const rich = opts.rich ?? isRich();
const raw = String(err);
const message = err instanceof Error ? err.message : raw;
if (!rich) return `Health check failed: ${raw}`;
const lines = message.split("\n").map((l) => l.trimEnd()).filter(Boolean);
const detailsIdx = lines.findIndex((l) => l.startsWith("Gateway target: "));
const summaryLines = (detailsIdx >= 0 ? lines.slice(0, detailsIdx) : lines).map((l) => l.trim()).filter(Boolean);
const detailLines = detailsIdx >= 0 ? lines.slice(detailsIdx) : [];
const summary = summaryLines.length > 0 ? summaryLines.join(" ") : message;
const out = [`${colorize(rich, theme.error.bold, "Health check failed")}: ${summary}`];
for (const line of detailLines) out.push(` ${formatKv(line, rich)}`);
return out.join("\n");
}
//#endregion
export { formatHealthCheckFailure as t };