diff options
| author | Adam Malczewski <[email protected]> | 2026-06-12 01:01:32 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-12 01:01:32 +0900 |
| commit | 6bd7b39f6f53dd8f3743347a1cb72c2f74424dd8 (patch) | |
| tree | b41911099883e8386ea8edbd88d42911de401d27 /.dispatch | |
| parent | fd565a6555e8bc9f37f21cf9d900523ef3be531b (diff) | |
| download | dispatch-web-6bd7b39f6f53dd8f3743347a1cb72c2f74424dd8.tar.gz dispatch-web-6bd7b39f6f53dd8f3743347a1cb72c2f74424dd8.zip | |
feat(metrics): consume contextSize — current context-usage readout
Backend context-size handoff: re-pin [email protected] / [email protected]
(+ re-mirror .dispatch reference snapshots). Thread the optional contextSize
through core/metrics (done fold + durable + selectCurrentContextSize: latest
turn's defined value, undefined=>unknown never 0, durable-wins-over-live).
Chat store exposes currentContextSize; ContextSizeBadge renders
"N tokens in context" / "context size unknown" above the composer.
GLOSSARY: add context size / context window. 533 tests green.
Diffstat (limited to '.dispatch')
| -rw-r--r-- | .dispatch/transport-contract.reference.md | 13 | ||||
| -rw-r--r-- | .dispatch/wire.reference.md | 36 |
2 files changed, 44 insertions, 5 deletions
diff --git a/.dispatch/transport-contract.reference.md b/.dispatch/transport-contract.reference.md index c2e2076..40ced1e 100644 --- a/.dispatch/transport-contract.reference.md +++ b/.dispatch/transport-contract.reference.md @@ -5,9 +5,16 @@ > hangs on a permission prompt). Your CODE still imports `@dispatch/transport-contract` normally — > this file is for READING only. > -> **Orchestrator:** SNAPSHOT of `[email protected]` (committed, backend `6db12ff`; the metrics -> endpoint shipped + version-bumped + LIVE-VERIFIED). Depends on `@dispatch/[email protected]` (see -> `wire.reference.md`) + `@dispatch/ui-contract` (see `ui-contract.reference.md`). +> **Orchestrator:** SNAPSHOT of `[email protected]` (the metrics endpoint shipped + +> version-bumped + LIVE-VERIFIED). Depends on `@dispatch/[email protected]` (see `wire.reference.md`) + +> `@dispatch/[email protected]` (see `ui-contract.reference.md`). +> +> **2026-06-12 delta (context-size handoff — package bumped `0.5.0` → `0.6.0`, depends on +> `[email protected]`):** no NEW transport shape — the optional `contextSize?: number` rides the +> re-exported `TurnMetrics` (so `ConversationMetricsResponse.turns[].contextSize`) and, live, the +> `TurnDoneEvent.contextSize` on the `done` AgentEvent (`chat.delta` WS / `/chat` NDJSON). On +> (re)hydrate take the LAST `turns[]` element with a defined `contextSize`; live, update on `done`. +> See the `wire.reference.md` context-size delta for the definition. > > **2026-06 delta (cache-warming handoff, additive — package still `0.4.0`):** adds > `POST /chat/warm` (`WarmRequest` → `WarmResponse`) for an on-demand prompt-cache warm, and the diff --git a/.dispatch/wire.reference.md b/.dispatch/wire.reference.md index ee5488c..cf1410a 100644 --- a/.dispatch/wire.reference.md +++ b/.dispatch/wire.reference.md @@ -4,8 +4,15 @@ > types WITHOUT following the `file:` dep symlink out of this repo (which hangs on a permission > prompt). Your CODE still imports `@dispatch/wire` normally — this file is for READING only. > -> **Orchestrator:** SNAPSHOT of `[email protected]` (committed, backend `6db12ff`; the metrics types below -> shipped + version-bumped). Regenerate whenever `@dispatch/wire` changes. +> **Orchestrator:** SNAPSHOT of `[email protected]` (the metrics types below shipped + version-bumped). +> Regenerate whenever `@dispatch/wire` changes. +> +> **2026-06-12 delta (context-size handoff — package bumped `0.4.0` → `0.5.0`):** adds an OPTIONAL +> `contextSize?: number` to BOTH `TurnDoneEvent` (live `done`) and `TurnMetrics` (persisted) — the +> turn's FINAL step `inputTokens + outputTokens` (current context occupancy), NOT the aggregate +> `usage` (which overcounts multi-step turns). The two carriers are equal for the same turn. Current +> value = the LATEST turn's `contextSize`; `undefined` ⇒ render "unknown", never `0`. See the field +> doc-comments on `TurnMetrics`/`TurnDoneEvent` below. > > **0.3.0 changes (token + timing metrics):** > - **Live per-step/per-turn telemetry on the event stream** (transient — NOT persisted): @@ -221,6 +228,16 @@ export interface TurnMetrics { readonly durationMs?: number; /** Per-step metrics in step order. */ readonly steps: readonly StepMetrics[]; + /** + * **Context size** — tokens the conversation occupies as of this turn: the + * turn's FINAL step `inputTokens + outputTokens` (the last entry of `steps`), + * NOT the aggregate `usage` (which sums per-step prompts and overcounts a + * multi-step turn). The persisted, replayable counterpart of + * `TurnDoneEvent.contextSize` and equal to it for the same turn. A client + * reopening a past conversation reads the LAST turn's `contextSize` as the + * current context usage. Optional: absent when no per-step usage was available. + */ + readonly contextSize?: number; } // ─── Outward events ───────────────────────────────────────────────────────── @@ -393,6 +410,21 @@ export interface TurnDoneEvent { * provider reported no usage). */ readonly usage?: Usage; + /** + * **Context size** — tokens the conversation occupies right now: the turn's + * FINAL step `inputTokens + outputTokens` (the prompt sent into the last LLM + * round-trip plus that round-trip's output). This is the "tokens in context" + * figure a client renders as the chat's current context usage, and a client + * treats the LATEST turn's value as the live total. + * + * Deliberately NOT the aggregate `usage` above: `usage` SUMS each step's + * `inputTokens`, which overcounts a multi-step / tool-calling turn because every + * step re-prefills the growing prompt — the final step's input already includes + * all prior context, so its input+output is the true occupancy. Optional: absent + * when no per-step usage was observed this turn (mirrors `usage`). A later field + * will carry the model's max context-window LIMIT; this is only the current size. + */ + readonly contextSize?: number; } /** |
