+ {contextPercentage !== null ? (
+ <>
+
+
+
+ {t("thread.composer.context.contextTitle", {
+ defaultValue: "Context",
+ })}
+
+
+ {formatCompactTokenCount(context!.contextTokens)} / {formatCompactTokenCount(
+ context!.contextWindowTokens!,
+ )}
+
+
+
+ {contextPercentage}%
+
+
+
+ >
+ ) : null}
+
+ {normalizedRounds.length > 0 ? (
+ <>
+
+
+ {t("thread.composer.context.recentRounds", {
+ defaultValue: "Recent rounds",
+ })}
+
+
+ {t("thread.composer.context.inputTrend", {
+ defaultValue: "Input tokens",
+ })}
+
+
+
+ {normalizedRounds.map((round, index) => {
+ const cachedKnown = typeof round.cachedTokens === "number";
+ const cachedTokens = round.cachedTokens ?? 0;
+ const notReusedTokens = Math.max(0, round.inputTokens - cachedTokens);
+ const cacheHitRate = cachedKnown
+ ? percentageFormatter.format(cachedTokens / round.inputTokens)
+ : null;
+ const cachedHeight = cachedKnown
+ ? cachedTokens / round.inputTokens * 100
+ : 0;
+ const barHeight = round.inputTokens / maxInputTokens * 108;
+ const timestampLabel = roundDateFormatter.format(round.timestamp);
+ const detailRows = [
+ {
+ key: "input",
+ label: t("thread.composer.context.input", {
+ defaultValue: "Input tokens",
+ }),
+ value: numberFormatter.format(round.inputTokens),
+ },
+ cachedKnown
+ ? {
+ key: "cache-hit-rate",
+ label: t("thread.composer.context.cacheHitRate", {
+ defaultValue: "KV cache hit rate",
+ }),
+ value: cacheHitRate!,
+ }
+ : null,
+ {
+ key: "output",
+ label: t("thread.composer.context.output", {
+ defaultValue: "Output tokens",
+ }),
+ value: numberFormatter.format(round.outputTokens),
+ },
+ typeof round.generationMs === "number"
+ ? {
+ key: "duration",
+ label: t("thread.composer.context.duration", {
+ defaultValue: "Generation time",
+ }),
+ value: formatTurnLatency(round.generationMs, i18n.language),
+ }
+ : null,
+ ].filter((row): row is NonNullable => !!row);
+ const detailNote = (round.estimatedTokens ?? 0) > 0
+ ? t("message.usage.estimated", {
+ defaultValue: "Includes estimated usage",
+ })
+ : null;
+ const detailLabel = [
+ timestampLabel,
+ ...detailRows.map((row) => `${row.label} ${row.value}`),
+ detailNote,
+ ].filter((part): part is string => !!part).join(". ");
+
+ return (
+ 1
+ && index === normalizedRounds.length - 1
+ && "justify-end",
+ index === normalizedRounds.length - 1 && "opacity-100",
+ )}
+ >
+
+
+
+ {cachedKnown ? (
+ <>
+ {notReusedTokens > 0 ? (
+
+ ) : null}
+ {cachedTokens > 0 ? (
+
+ ) : null}
+ >
+ ) : (
+
+ )}
+
+
+
+
+ {timestampLabel}
+
+
+ {detailRows.map((row) => (
+
+
+ {row.label}
+
+
+ {row.value}
+
+
+ ))}
+
+ {detailNote ? (
+
+ {detailNote}
+
+ ) : null}
+
+
+
+ );
+ })}
+
+ >
+ ) : null}
+
+
+