feat(web): display reported chat throughput tokens context and cost

This commit is contained in:
2026-10-21 00:27:12 +01:00
parent 910028a75c
commit 0b8595f16e
12 changed files with 314 additions and 12 deletions
+34 -1
View File
@@ -8,6 +8,7 @@ import { isLocalArtifactLink } from "../artifactNavigation.js";
import { formFieldVisible, formFieldValue, formAnswerError, visibleFormAnswers, safeFormURL } from "../chatForms.js";
import { readChatStars, writeChatStars } from "../chatStars.js";
import { chatModelLabel, chatModelSelectionNote, supportsChatModels } from "../chatModels.js";
import { chatUsageMetrics } from "../chatUsage.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, nativeChatMessageId, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
@@ -790,6 +791,13 @@ function onChatEvent(frame) {
scheduleHistorySync(sessionId, "", {force:true});
return;
}
if (frame.kind === "usage") {
const current = state.chatThreads.get(sessionId);
const next = applyChatEvent(current, frame);
state.chatThreads.set(sessionId, next);
if (state.view === "chat" && sessionId === state.chatActiveId) refreshChatUsageMetrics(sessionId, next);
return;
}
markBackgroundChatUnseen(sessionId);
const thread = state.chatThreads.get(sessionId);
const messageId = String(frame?.message_id ?? "");
@@ -1384,7 +1392,7 @@ function onChatFrame(message) {
if (!frame || !frame.session_id) return;
// onChatEvent already folded this session activity with native identity
// checks and refreshed the composer. Do not reapply an ignored stale start.
if (frame.kind === "compaction") return;
if (frame.kind === "compaction" || frame.kind === "usage") return;
rt.touchView?.("chat");
const sessionId = frame.session_id;
const thread = state.chatThreads.get(sessionId);
@@ -2462,6 +2470,30 @@ function renderChatActionsMenu(session, duplicateTitles = new Set()) {
return wrap;
}
/** Reported usage, with explicit unknowns and no inferred token/cost values. */
function renderChatUsageMetrics(thread, sessionId) {
const metrics = h("dl", {
class: "chat-usage-metrics",
id: "chatUsageMetrics",
"data-session": sessionId,
"aria-label": "Chat usage and performance",
});
for (const metric of chatUsageMetrics(thread?.usage)) {
metrics.append(h("div", {
class: "chat-usage-metric",
"data-metric": metric.key,
"data-available": String(metric.available),
title: metric.title,
}, h("dt", { text: metric.label }), h("dd", { text: metric.value })));
}
return metrics;
}
function refreshChatUsageMetrics(sessionId, thread) {
const metrics = document.getElementById("chatUsageMetrics");
if (metrics?.dataset.session === sessionId) metrics.replaceWith(renderChatUsageMetrics(thread, sessionId));
}
/** The active conversation: identity, context, transcript and its controls. */
function renderChatConversation() {
const pane = h("div", { class: "detail chat-detail" });
@@ -2530,6 +2562,7 @@ function renderChatConversation() {
context.append(modelButton);
pane.append(context);
}
pane.append(renderChatUsageMetrics(thread, state.chatActiveId));
// The background-tasks bar (C11) sits above the transcript, outside the
// scroller so the C14 scroll positions are untouched. It is present only while