/** * Presentation primitives copied from OpenAI Codex. * * Every function mirrors a specific Rust function so the panel renders numbers * exactly the way Codex does. The originals live in the open-source * `openai/codex` repository: * * - `formatTokensCompact` ← `tui/src/status/helpers.rs` (status card) * - `compactAmount` ← `tui/src/analytics/data.rs` (analytics headline) * - `formatWithSeparators` ← `protocol/src/num_format.rs` * - `countValue` ← `tui/src/analytics/summary_panel.rs` * - `formatDuration` ← `tui/src/analytics/summary_panel.rs` * - `renderLimitProgressBar` ← `tui/src/status/rate_limits.rs` * - `percentRemaining` ← `tui/src/token_usage.rs` * - `formatResetTimestamp` ← `tui/src/status/helpers.rs` * * The Rust source is quoted in each doc comment so a future Codex change can be * diffed against this file instead of guessed at. * * @module dsh-token-dashboard/format */ /** Codex's `STATUS_LIMIT_BAR_SEGMENTS`. */ export declare const LIMIT_BAR_SEGMENTS = 20; /** Codex's `STATUS_LIMIT_BAR_FILLED`. */ export declare const LIMIT_BAR_FILLED = "\u2588"; /** Codex's `STATUS_LIMIT_BAR_EMPTY`. */ export declare const LIMIT_BAR_EMPTY = "\u2591"; /** Codex's `BarPlot` glyph ramp, index 0-8 (`analytics/plot/painting.rs`). */ export declare const BAR_RAMP: readonly [" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"]; /** The em dash Codex renders for a missing value. */ export declare const MISSING = "\u2014"; /** * Codex's `BASELINE_TOKENS`, subtracted from both sides of the occupancy ratio. * * Deliberately NOT applied by default here. Codex subtracts a fixed 12K to * discount its own system prompt and tool schemas; DSH's prompt overhead is a * different size, so copying the constant would make the percentage wrong * rather than compatible. It stays exposed so a deployment can opt in. */ export declare const CODEX_BASELINE_TOKENS = 12000; /** * Codex `format_tokens_compact`: K/M/B/T with 2/1/0 decimals and trailing zeros * stripped. * * ```rust * if value == 0 { return "0".to_string(); } * if value < 1_000 { return value.to_string(); } * let (scaled, suffix) = if value >= 1_000_000_000_000 { (v / 1e12, "T") } * else if value >= 1_000_000_000 { (v / 1e9, "B") } * else if value >= 1_000_000 { (v / 1e6, "M") } * else { (v / 1e3, "K") }; * let decimals = if scaled < 10.0 { 2 } else if scaled < 100.0 { 1 } else { 0 }; * ``` * @param value - Raw token count; negatives clamp to zero like `value.max(0)`. * @returns The compact label, for example `999`, `12.35K`, `128K`, `1.2M`. */ export declare function formatTokensCompact(value: number): string; /** * Codex `compact_amount` from the analytics headline: always ONE decimal, and * it promotes the unit before rounding could print `1000K`. * * ```rust * while scaled.abs() >= 999.95 && unit + 1 < units.len() { scaled /= 1_000.0; unit += 1; } * let rounded = format!("{:.1}", (scaled * 10.0).round() / 10.0); * ``` * @param value - The headline figure. * @returns The compact label, for example `142.3B`, `7B`. */ export declare function compactAmount(value: number): string; /** * Codex `format_with_separators`: locale-aware grouping, `12345` → `12,345`. * * Codex resolves one formatter from the system locale and falls back to * `en-US`; passing the locale in keeps this pure and lets the panel follow the * DSH UI language rather than the OS. * @param value - Integer to group. * @param locale - BCP-47 tag, or `undefined` for the runtime default. * @returns The grouped integer. */ export declare function formatWithSeparators(value: number, locale?: string): string; /** * Codex `count_value`: manual thousands grouping with `—` for a missing value. * @param value - Count, or `undefined` to render the missing placeholder. * @returns The grouped count or `—`. */ export declare function countValue(value: number | undefined): string; /** * Codex `duration(seconds)`. * * ```rust * match (hours, minutes) { * (0, 0) => format!("{seconds}s"), * (0, minutes) => format!("{minutes}m"), * (hours, 0) => format!("{hours}h"), * (hours, minutes) => format!("{hours}h {minutes}m"), * } * ``` * @param seconds - Non-negative duration; negatives clamp to zero. * @returns The duration label, for example `44h 7m`. */ export declare function formatDuration(seconds: number): string; /** * A duration in the units the active locale actually reads. * * Codex only ever renders for English, so `formatDuration` alone would print * `46m 59s` where a Chinese UI expects `46分59秒`. Seconds are dropped once an * hour is on the clock, which is what the reference panel does. * @param seconds - Non-negative duration; negatives clamp to zero. * @param locale - BCP-47 tag of the active UI language. * @returns The localized duration label. */ export declare function localeDuration(seconds: number, locale?: string): string; /** * A token count in the units the active locale actually reads. * * The reference panel renders Chinese counts as 万 / 亿 rather than K / M, one * decimal either way: `370_000_000` reads `3.7亿` and `53_171_000` reads * `5317.1万`. English keeps Codex's own `compactAmount` rule. * * Rounding must not print a unit it has outgrown: `99_999_999 / 10_000` rounds * to `10000`, and `10000万` is a worse label than the `1亿` the same value has. * The 万 arm therefore re-checks its own rounded magnitude and promotes. * @param value - The count. * @param locale - BCP-47 tag of the active UI language. * @returns The localized compact label. */ export declare function localeCompact(value: number, locale?: string): string; /** * A plain grouped count that also follows the Chinese convention. * @param value - Count, or `undefined` for the missing placeholder. * @param locale - BCP-47 tag of the active UI language. * @returns The grouped count or `—`. */ export declare function localeCount(value: number | undefined, locale?: string): string; /** * Codex `render_limit_progress_bar`: a fixed-width `[███░░░]` bar. * * ```rust * let ratio = (percent_remaining / 100.0).clamp(0.0, 1.0); * let filled = (ratio * segments as f64).round() as usize; * ``` * The argument is the REMAINING percentage: a low value yields a short bar, * matching Codex. Passing a used percentage inverts the bar. * @param percentRemaining - Remaining share in `0..=100`; clamped. * @param segments - Bar width in cells; defaults to Codex's 20. * @returns The bracketed bar, using Codex's block glyphs. */ export declare function renderLimitProgressBar(percentRemaining: number, segments?: number): string; /** * Codex `format_status_limit_summary`: `"{percent:.0}% left"`. * @param percentRemaining - Remaining share; rounded to 0 decimals. * @returns The summary label. */ export declare function formatLimitSummary(percentRemaining: number): string; /** Options for {@link percentOfContextWindowRemaining}. */ export interface ContextOccupancyOptions { /** * Tokens discounted from both sides before the ratio, mirroring Codex's * `BASELINE_TOKENS`. Defaults to `0` — see {@link CODEX_BASELINE_TOKENS}. */ baselineTokens?: number; } /** * Codex `TokenUsage::percent_of_context_window_remaining`, with the baseline * made explicit instead of hard-coded. * * ```rust * if context_window <= BASELINE_TOKENS { return 0; } * let effective_window = context_window - BASELINE_TOKENS; * let used = (self.tokens_in_context_window() - BASELINE_TOKENS).max(0); * let remaining = (effective_window - used).max(0); * ((remaining as f64 / effective_window as f64) * 100.0).clamp(0.0, 100.0).round() as i64 * ``` * @param tokensInContext - Prompt size of the request under measurement. * @param contextWindow - Model context capacity. * @param options - Baseline override; see {@link ContextOccupancyOptions}. * @returns Remaining percentage in `0..=100`. */ export declare function percentOfContextWindowRemaining(tokensInContext: number, contextWindow: number, options?: ContextOccupancyOptions): number; /** * The context-window value string from Codex's `context_window_spans`: * `"{percent}% left ({used} used / {window})"`. * @param tokensInContext - Prompt size of the request under measurement. * @param contextWindow - Model context capacity. * @param options - Baseline override; see {@link ContextOccupancyOptions}. * @returns The formatted value. */ export declare function formatContextWindow(tokensInContext: number, contextWindow: number, options?: ContextOccupancyOptions): string; /** * Codex `format_reset_timestamp`, reused for the freshness stamp. * * ```rust * let time = dt.format(clock_format.time_format()); * if dt.date_naive() == captured_at.date_naive() { time } * else { format!("{time} on {}", dt.format("%-d %b")) } * ``` * Reset times are ALWAYS absolute clock times — there is no relative countdown * anywhere in Codex's status card, so this panel does not invent one. * @param instant - The moment to render. * @param reference - The moment "today" is measured against. * @param locale - BCP-47 tag used for the time format. * @returns `09:25` for today, otherwise `09:25 on 7 May`. */ export declare function formatAbsoluteTime(instant: Date, reference: Date, locale?: string): string; /** * Codex `ratio_percent`: `{value:.0}%`, or the em dash when absent. * @param value - Percentage, or `undefined`. * @returns The formatted percentage or `—`. */ export declare function formatPercent(value: number | undefined): string; /** * Map a value onto Codex's 8-step bar-chart ramp. * @param value - The datum. * @param max - The series maximum; a non-positive max yields the lowest glyph. * @returns One glyph from {@link BAR_RAMP}. */ export declare function barGlyph(value: number, max: number): string;