Subagent Token and Duration Formatter (shared/subagents-format.ts)

openclaw-zero-token · src/shared/subagents-format.ts · typescript · MIT
ui, ai, dev-tools, analytics, lang:typescript, tag:knn-classified

Formats token usage counts and duration timestamps into compact display strings. Use this when logging or rendering LLM subagent metrics.

// Source: https://github.com/linuxhsj/openclaw-zero-token | License: MIT | Copyright 2025 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
export function formatDurationCompact(valueMs?: number) {
  if (!valueMs || !Number.isFinite(valueMs) || valueMs <= 0) {
    return "n/a";
  }
  const minutes = Math.max(1, Math.round(valueMs / 60_000));
  if (minutes < 60) {
    return `${minutes}m`;
  }
  const hours = Math.floor(minutes / 60);
  const minutesRemainder = minutes % 60;
  if (hours < 24) {
    return minutesRemainder > 0 ? `${hours}h${minutesRemainder}m` : `${hours}h`;
  }
  const days = Math.floor(hours / 24);
  const hoursRemainder = hours % 24;
  return hoursRemainder > 0 ? `${days}d${hoursRemainder}h` : `${days}d`;
}

export function formatTokenSho

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key