The Preact tree's ui/src/base/ was deleted with the dashboard. This rebuilds what depended on it, on the shadcn layer rather than as new bespoke markup. Badge and Card come from the shadcn-vue CLI, so they match the already-vendored components, and the composed pieces sit on top of them: - Badge gains the five status variants the pills used, over the palette's status tokens. The pill's dot did not come across: the Badge's own shape is the affordance, and the same variant now covers a trend indicator, where a dot reads as noise. - base/StatTile.vue uses full Card composition instead of dumping everything into one content slot, with base/Sparkline.vue and the goodDirection logic that says whether "up" is good news. - base/Gauge.vue and base/SegmentBar.vue, both of them: the original exported two components from one file and budget composition uses the second. - base/LogRow.vue over lib/log.ts, which holds the LOG_LEVELS wire contract (the server matches that CSV server-side, so it is not a display choice). - lib/status.ts, so status colour has one home: a task state, a gate result, a log level and a trend all draw from the same five kinds. Two deliberate departures: The icon module is not ported. Its name-to-glyph string lookup is the pattern shadcn-vue's rules call out as wrong, and nothing consumes the five bespoke glyphs anyway: the navigation is text with tooltips. Icons come from @lucide/vue at the call site, and the five become components if a page draws them. The gauge's aria-label announces the rounded percentage. It announced the raw one, so a screen reader read 71.38461538461539% where the screen showed 71% (bead 86au). Also lands the four modules the checklist marks copy-verbatim, which encode bugs fixed just before the delete: dashboard/activity-detail, chat/ command-scroll, workflows/workflow-rows and logs/logs-empty.
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import type { StatusKind } from "./status";
|
|
|
|
/**
|
|
* Log-entry vocabulary shared by the daemon-wide log page and a task's own
|
|
* attempt log, which render the same entry shape from internal/logging.
|
|
*/
|
|
|
|
/**
|
|
* The level filter vocabulary. Server-side level filtering takes a CSV of
|
|
* levels (`splitCSV` in internal/webui/api_tasks_logs.go), so the combined
|
|
* options are a wire concern too, not a display choice.
|
|
*/
|
|
export const LOG_LEVELS = [
|
|
{ value: "", label: "All levels" },
|
|
{ value: "ERROR", label: "Errors" },
|
|
{ value: "WARN,ERROR", label: "Warnings and errors" },
|
|
{ value: "INFO,WARN,ERROR", label: "Info and above" },
|
|
{ value: "DEBUG", label: "Debug only" },
|
|
];
|
|
|
|
/** The kinds a log level uses. Never `ok`: a log line is not a pass. */
|
|
export type LevelKind = Exclude<StatusKind, "ok">;
|
|
|
|
/** One entry as internal/logging serialises it. */
|
|
export interface LogEntry {
|
|
time: string | number | Date;
|
|
level?: string | null;
|
|
message?: string;
|
|
msg?: string;
|
|
fields?: Record<string, unknown>;
|
|
}
|
|
|
|
/** The level label's colour, by kind. One place, so two log panes agree. */
|
|
export const LEVEL_COLOR: Record<LevelKind, string> = {
|
|
danger: "text-danger",
|
|
warn: "text-warn",
|
|
info: "text-info",
|
|
idle: "text-idle",
|
|
};
|
|
|
|
export function levelKind(level: string | null | undefined): LevelKind {
|
|
switch ((level || "").toUpperCase()) {
|
|
case "ERROR":
|
|
return "danger";
|
|
case "WARN":
|
|
return "warn";
|
|
case "DEBUG":
|
|
return "idle";
|
|
default:
|
|
return "info";
|
|
}
|
|
}
|
|
|
|
export function fmtValue(v: unknown): string {
|
|
if (v == null) return "";
|
|
return typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
}
|
|
|
|
export function shortTime(value: string | number | Date): string {
|
|
const d = value instanceof Date ? value : new Date(value);
|
|
if (Number.isNaN(d.getTime())) return "--:--:--";
|
|
return d.toTimeString().slice(0, 8);
|
|
}
|