Files
archie/ui/src/lib/log.ts
T
sam 0dc5bf9a9b
deploy / gate (push) Successful in 4m54s
Quality / check (push) Successful in 6m44s
deploy / archied-image (push) Successful in 3m44s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
fix(ui): times honour the Appearance zone, one duration formatter everywhere (#1761)
lib/format.ts gains shortTime(value, zone) and becomes the home of the
single duration() formatter (moved from timeline-event.ts, which
re-exports it so the stage rail and duration.test.ts are unchanged).
LogTable's time column, audit's From/To chips and chat session titles now
format in the zone chosen under Appearance instead of the browser's.
StepNode, schedule runDuration, labels formatMs and ChatToolCall all
delegate to duration(), removing the "12ms" vs "12 ms" vs "under 1 s"
split.
2026-11-06 22:21:45 +11:00

64 lines
1.9 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 {
id?: number;
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";
}
}
/** An error line is a block the eye lands on, not red text in a grey column. */
export function rowClass(level: string | null | undefined): string {
return levelKind(level) === "danger" ? "bg-danger-soft hover:bg-danger-soft" : "";
}
export function fmtValue(v: unknown): string {
if (v == null) return "";
return typeof v === "object" ? JSON.stringify(v) : String(v);
}