dashboard: derive ctx badge thresholds from the model context window
This commit is contained in:
parent
cbd4b71322
commit
4a27ef7304
4 changed files with 122 additions and 26 deletions
|
|
@ -4,11 +4,16 @@
|
|||
|
||||
(() => {
|
||||
// ─── constants ──────────────────────────────────────────────────────────
|
||||
// Context-window token thresholds — mirror the harness compaction watermarks
|
||||
// in hive-ag3nt (HIVE_COMPACT_WATERMARK_TOKENS = 150k; auto-reset at 100k).
|
||||
// TODO: source these from model metadata once damocles lands that feature.
|
||||
const CTX_WARN_TOKENS = 150_000; // ≥ this → compact territory (red)
|
||||
const CTX_CAUTION_TOKENS = 100_000; // ≥ this → approaching reset (yellow)
|
||||
// Context-window badge thresholds. Preferred source is each container's
|
||||
// `context_window_tokens` from /api/state (the real window for the model
|
||||
// it last ran on) — thresholds are then 75% / 50% of it, matching the
|
||||
// harness compaction watermarks (compact at 75%, auto-reset at 50%). The
|
||||
// fixed token constants are the fallback for when that field is absent
|
||||
// (agent has no turns yet, or no per-model config matched the model).
|
||||
const CTX_WARN_FRACTION = 0.75; // ≥ this share of the window → red
|
||||
const CTX_CAUTION_FRACTION = 0.50; // ≥ this share of the window → yellow
|
||||
const CTX_WARN_TOKENS = 150_000; // fallback red threshold (≈ 75% of 200k)
|
||||
const CTX_CAUTION_TOKENS = 100_000; // fallback yellow threshold (≈ 50% of 200k)
|
||||
|
||||
// ─── helpers ────────────────────────────────────────────────────────────
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
|
@ -680,14 +685,20 @@
|
|||
}
|
||||
if (c.ctx_tokens != null) {
|
||||
const k = Math.round(c.ctx_tokens / 1000);
|
||||
const ctxClass = c.ctx_tokens >= CTX_WARN_TOKENS ? 'badge-ctx-warn'
|
||||
: c.ctx_tokens >= CTX_CAUTION_TOKENS ? 'badge-ctx-caution'
|
||||
// Thresholds track the model's real context window when the
|
||||
// backend supplies it; otherwise fall back to fixed constants.
|
||||
const win = c.context_window_tokens;
|
||||
const warn = win != null ? win * CTX_WARN_FRACTION : CTX_WARN_TOKENS;
|
||||
const caution = win != null ? win * CTX_CAUTION_FRACTION : CTX_CAUTION_TOKENS;
|
||||
const ctxClass = c.ctx_tokens >= warn ? 'badge-ctx-warn'
|
||||
: c.ctx_tokens >= caution ? 'badge-ctx-caution'
|
||||
: 'badge-ctx-ok';
|
||||
const title = win != null
|
||||
? `last turn context: ${c.ctx_tokens.toLocaleString()} / ${win.toLocaleString()} `
|
||||
+ `tokens (${Math.round((c.ctx_tokens / win) * 100)}% of the window)`
|
||||
: `last turn context size: ${c.ctx_tokens.toLocaleString()} tokens`;
|
||||
head.append(el('span',
|
||||
{
|
||||
class: `badge ${ctxClass}`,
|
||||
title: `last turn context size: ${c.ctx_tokens.toLocaleString()} tokens`,
|
||||
},
|
||||
{ class: `badge ${ctxClass}`, title },
|
||||
`ctx·${k}k`));
|
||||
}
|
||||
body.append(head);
|
||||
|
|
|
|||
|
|
@ -165,8 +165,11 @@ a:hover {
|
|||
color: var(--cyan); border-color: var(--cyan);
|
||||
text-shadow: 0 0 6px rgba(137, 220, 235, 0.4);
|
||||
}
|
||||
/* Context-window usage badges on dashboard container rows.
|
||||
Green < 100k, yellow 100–150k, red ≥ 150k (mirrors harness watermarks). */
|
||||
/* Context-window usage badges on dashboard container rows. Thresholds
|
||||
are derived per-container: yellow ≥ 50% and red ≥ 75% of the model's
|
||||
context window (`ContainerView.context_window_tokens`), mirroring the
|
||||
harness compaction watermarks. Falls back to fixed 100k / 150k when
|
||||
the window is unknown. (issue #66) */
|
||||
.badge-ctx-ok {
|
||||
color: var(--green); border-color: var(--green);
|
||||
opacity: 0.85;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue