Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 2x 6x | import { SkillRunSummary } from "@/objects/Skill";
import resourceHref from "@/routes/resourceHref";
import { parseServerDate, parseServerDateOrNull } from "@/util/time";
/** Where a skill lives. The route always exists, so never null here. */
export const skillHref = (skillId: string): string =>
resourceHref("skill", skillId) ?? "";
/** "4.2s", "1m 12s" — or null while there is nothing to measure. */
export function formatElapsed(ms: number | null | undefined): string | null {
if (ms === null || ms === undefined || ms < 0) return null;
if (ms < 1000) return `${Math.round(ms)}ms`;
if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;
const minutes = Math.floor(ms / 60_000);
return `${minutes}m ${Math.round((ms % 60_000) / 1000)}s`;
}
/**
* How long a run took, or has been going: the svc-ai call's own latency
* when it finished, the wall clock since it started while it is running.
*/
export function runDuration(run: SkillRunSummary, now: number): string | null {
if (run.latency_ms !== null) return formatElapsed(run.latency_ms);
const started = parseServerDate(run.started_at).getTime();
const finished = parseServerDateOrNull(run.finished_at)?.getTime();
return formatElapsed((finished ?? now) - started);
}
/** One value as a short line of text. */
export function formatValue(value: unknown, max = 80): string {
const text =
typeof value === "string"
? value
: value === null || value === undefined
? "—"
: JSON.stringify(value);
const flat = text.replace(/\s+/g, " ").trim();
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
}
/** A run's inputs as one line — how the runs list tells two runs apart. */
export function summariseInputs(
inputs: Record<string, unknown>,
prompt: string | null,
max = 120,
): string {
const parts = Object.entries(inputs).map(
([k, v]) => `${k}: ${formatValue(v, 40)}`,
);
if (prompt) parts.push(`“${formatValue(prompt, 60)}”`);
return formatValue(parts.join(" · ") || "—", max);
}
|