Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: refine page agent token usage display (#20170)

p0ny2b6a8dc72110
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 20719104e4..12943160ed 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -26,11 +26,6 @@
"chat-archived-label": "Archived",
"chat-default-title": "New chat",
"chat-list-label": "Chats",
- "chat-status-awaiting-user": "Awaiting input",
- "chat-status-error": "Error",
- "chat-status-idle": "Idle",
- "chat-status-interrupted": "Interrupted",
- "chat-status-running": "Running",
"chat-total-tokens": "Tokens used: {count}",
"close": "Close",
"confirm": "Confirm",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3251e87b07..2c8114ec89 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -26,11 +26,6 @@
"chat-archived-label": "Archivado",
"chat-default-title": "Nuevo chat",
"chat-list-label": "Chats",
- "chat-status-awaiting-user": "Esperando entrada",
- "chat-status-error": "Error",
- "chat-status-idle": "Inactivo",
- "chat-status-interrupted": "Interrumpido",
- "chat-status-running": "En ejecución",
"chat-total-tokens": "Tokens usados: {count}",
"close": "Cerrar",
"confirm": "Confirmar",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index a3f7f78b83..7ddf462823 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -26,11 +26,6 @@
"chat-archived-label": "アーカイブ済み",
"chat-default-title": "新しいチャット",
"chat-list-label": "チャット",
- "chat-status-awaiting-user": "入力待ち",
- "chat-status-error": "エラー",
- "chat-status-idle": "待機中",
- "chat-status-interrupted": "中断",
- "chat-status-running": "実行中",
"chat-total-tokens": "使用済みトークン: {count}",
"close": "閉じる",
"confirm": "確認",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 9c29f69a27..a1db6fdf6a 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -26,11 +26,6 @@
"chat-archived-label": "Đã lưu trữ",
"chat-default-title": "Chat mới",
"chat-list-label": "Các chat",
- "chat-status-awaiting-user": "Đang chờ nhập",
- "chat-status-error": "Lỗi",
- "chat-status-idle": "Rảnh",
- "chat-status-interrupted": "Bị gián đoạn",
- "chat-status-running": "Đang chạy",
"chat-total-tokens": "Token đã dùng: {count}",
"close": "Đóng",
"confirm": "Xác nhận",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 60dca8b8cb..7179e45927 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -26,11 +26,6 @@
"chat-archived-label": "已归档",
"chat-default-title": "新聊天",
"chat-list-label": "聊天",
- "chat-status-awaiting-user": "等待输入",
- "chat-status-error": "错误",
- "chat-status-idle": "空闲",
- "chat-status-interrupted": "已中断",
- "chat-status-running": "运行中",
"chat-total-tokens": "已用令牌:{count}",
"close": "关闭",
"confirm": "确认",
diff --git a/frontend/src/react/locales/en-US.json b/frontend/src/react/locales/en-US.json
index e1d15dfe1f..a61790aa59 100644
--- a/frontend/src/react/locales/en-US.json
+++ b/frontend/src/react/locales/en-US.json
@@ -28,12 +28,7 @@
"chat-archived-label": "Archived",
"chat-default-title": "New Chat",
"chat-list-label": "Chats",
- "chat-status-awaiting-user": "Awaiting user",
- "chat-status-error": "Error",
- "chat-status-idle": "Idle",
- "chat-status-interrupted": "Interrupted",
- "chat-status-running": "Running",
- "chat-total-tokens": "Total tokens",
+ "chat-total-tokens": "Total tokens: {{count}}",
"close": "Close",
"confirm": "Confirm",
"delete-all-chats": "Delete all chats",
diff --git a/frontend/src/react/locales/es-ES.json b/frontend/src/react/locales/es-ES.json
index 64bd7913a6..b15d86c061 100644
--- a/frontend/src/react/locales/es-ES.json
+++ b/frontend/src/react/locales/es-ES.json
@@ -28,12 +28,7 @@
"chat-archived-label": "Archivado",
"chat-default-title": "Nuevo chat",
"chat-list-label": "Chats",
- "chat-status-awaiting-user": "Esperando usuario",
- "chat-status-error": "Error",
- "chat-status-idle": "Inactivo",
- "chat-status-interrupted": "Interrumpido",
- "chat-status-running": "Ejecutando",
- "chat-total-tokens": "Tokens totales",
+ "chat-total-tokens": "Tokens totales: {{count}}",
"close": "Cerrar",
"confirm": "Confirmar",
"delete-all-chats": "Eliminar todos los chats",
diff --git a/frontend/src/react/locales/ja-JP.json b/frontend/src/react/locales/ja-JP.json
index b660290073..8d15004b8d 100644
--- a/frontend/src/react/locales/ja-JP.json
+++ b/frontend/src/react/locales/ja-JP.json
@@ -28,12 +28,7 @@
"chat-archived-label": "アーカイブ済み",
"chat-default-title": "新しいチャット",
"chat-list-label": "チャット",
- "chat-status-awaiting-user": "ユーザー待ち",
- "chat-status-error": "エラー",
- "chat-status-idle": "アイドル",
- "chat-status-interrupted": "中断",
- "chat-status-running": "実行中",
- "chat-total-tokens": "合計トークン数",
+ "chat-total-tokens": "合計トークン数: {{count}}",
"close": "閉じる",
"confirm": "確認",
"delete-all-chats": "すべてのチャットを削除",
diff --git a/frontend/src/react/locales/vi-VN.json b/frontend/src/react/locales/vi-VN.json
index ddb36cc31e..e4ab470514 100644
--- a/frontend/src/react/locales/vi-VN.json
+++ b/frontend/src/react/locales/vi-VN.json
@@ -28,12 +28,7 @@
"chat-archived-label": "Đã lưu trữ",
"chat-default-title": "Cuộc trò chuyện mới",
"chat-list-label": "Cuộc trò chuyện",
- "chat-status-awaiting-user": "Đang chờ người dùng",
- "chat-status-error": "Lỗi",
- "chat-status-idle": "Rảnh",
- "chat-status-interrupted": "Bị gián đoạn",
- "chat-status-running": "Đang chạy",
- "chat-total-tokens": "Tổng số token",
+ "chat-total-tokens": "Tổng số token: {{count}}",
"close": "Đóng",
"confirm": "Xác nhận",
"delete-all-chats": "Xóa tất cả cuộc trò chuyện",
diff --git a/frontend/src/react/locales/zh-CN.json b/frontend/src/react/locales/zh-CN.json
index 22903e5fa8..dd25aa0d52 100644
--- a/frontend/src/react/locales/zh-CN.json
+++ b/frontend/src/react/locales/zh-CN.json
@@ -28,12 +28,7 @@
"chat-archived-label": "已归档",
"chat-default-title": "新对话",
"chat-list-label": "对话列表",
- "chat-status-awaiting-user": "等待用户",
- "chat-status-error": "错误",
- "chat-status-idle": "空闲",
- "chat-status-interrupted": "已中断",
- "chat-status-running": "运行中",
- "chat-total-tokens": "总 token 数",
+ "chat-total-tokens": "总 token 数:{{count}}",
"close": "关闭",
"confirm": "确认",
"delete-all-chats": "删除所有对话",
diff --git a/frontend/src/react/plugins/agent/components/AgentInput.test.tsx b/frontend/src/react/plugins/agent/components/AgentInput.test.tsx
index 607a4a124d..657c4a614d 100644
--- a/frontend/src/react/plugins/agent/components/AgentInput.test.tsx
+++ b/frontend/src/react/plugins/agent/components/AgentInput.test.tsx
@@ -2,6 +2,11 @@ import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import enUS from "@/react/locales/en-US.json";
+import esES from "@/react/locales/es-ES.json";
+import jaJP from "@/react/locales/ja-JP.json";
+import viVN from "@/react/locales/vi-VN.json";
+import zhCN from "@/react/locales/zh-CN.json";
import type { DomRefSuggestion } from "../dom";
import { createAgentStore, useAgentStore } from "../store/agent";
@@ -179,6 +184,12 @@ afterEach(() => {
});
describe("AgentInput", () => {
+ test("React locale token usage labels include the token count", () => {
+ for (const locale of [enUS, esES, jaJP, viVN, zhCN]) {
+ expect(locale.agent["chat-total-tokens"]).toContain("{{count}}");
+ }
+ });
+
test("mounts mention suggestions into the agent layer root", async () => {
const suggestions: DomRefSuggestion[] = [
{
@@ -210,6 +221,70 @@ describe("AgentInput", () => {
unmount();
});
+ test("shows token usage near the textarea", () => {
+ const chatId = useAgentStore.getState().currentChatId!;
+ useAgentStore.setState({
+ chats: useAgentStore
+ .getState()
+ .chats.map((chat) =>
+ chat.id === chatId ? { ...chat, totalTokensUsed: 1234 } : chat
+ ),
+ });
+ mocks.useTranslation.mockReturnValue({
+ t: (key: string, values?: Record<string, unknown>) =>
+ key === "agent.chat-total-tokens"
+ ? `Tokens used: ${values?.count ?? ""}`
+ : key,
+ });
+
+ const { container, render, unmount } = renderIntoContainer(<AgentInput />);
+
+ render();
+
+ const inputFooter = container.querySelector("[data-agent-input-footer]");
+ expect(inputFooter).toBeInstanceOf(HTMLDivElement);
+ expect(inputFooter?.textContent).toContain("Tokens used: 1,234");
+
+ unmount();
+ });
+
+ test("keeps token usage visible while awaiting confirmation", () => {
+ const chatId = useAgentStore.getState().currentChatId!;
+ useAgentStore.setState({
+ chats: useAgentStore
+ .getState()
+ .chats.map((chat) =>
+ chat.id === chatId
+ ? { ...chat, status: "awaiting_user", totalTokensUsed: 5678 }
+ : chat
+ ),
+ pendingAskByChatId: {
+ [chatId]: {
+ toolCallId: "tool-call-confirm",
+ prompt: "Continue?",
+ kind: "confirm",
+ },
+ },
+ });
+ mocks.useTranslation.mockReturnValue({
+ t: (key: string, values?: Record<string, unknown>) =>
+ key === "agent.chat-total-tokens"
+ ? `Tokens used: ${values?.count ?? ""}`
+ : key,
+ });
+
+ const { container, render, unmount } = renderIntoContainer(<AgentInput />);
+
+ render();
+
+ const inputFooter = container.querySelector("[data-agent-input-footer]");
+ expect(inputFooter).toBeInstanceOf(HTMLDivElement);
+ expect(inputFooter?.textContent).toContain("Tokens used: 5,678");
+ expect(container.textContent).toContain("Continue?");
+
+ unmount();
+ });
+
test("repositions mention suggestions when the textarea rect changes", async () => {
const suggestions: DomRefSuggestion[] = [
{
diff --git a/frontend/src/react/plugins/agent/components/AgentInput.tsx b/frontend/src/react/plugins/agent/components/AgentInput.tsx
index 647c8119da..5a0317a391 100644
--- a/frontend/src/react/plugins/agent/components/AgentInput.tsx
+++ b/frontend/src/react/plugins/agent/components/AgentInput.tsx
@@ -35,6 +35,8 @@ const runTokens = new Map<string, number>();
// Module-level request token for dom ref suggestion loading.
let domRefRequestToken = 0;
+const tokenFormatter = new Intl.NumberFormat();
+
// ---------------------------------------------------------------------------
// Helper functions (same logic as the Vue version)
// ---------------------------------------------------------------------------
@@ -153,6 +155,13 @@ export function AgentInput() {
isAwaitingChoose ||
isAIConfigurationBlocked ||
!input.trim();
+ const currentChatTokenUsageLabel = useMemo(
+ () =>
+ t("agent.chat-total-tokens", {
+ count: tokenFormatter.format(currentChat?.totalTokensUsed ?? 0),
+ }),
+ [currentChat?.totalTokensUsed, t]
+ );
// @-mention autocomplete
const activeDomRefQuery = useMemo(
@@ -706,6 +715,13 @@ export function AgentInput() {
</div>
)}
+ <div
+ className="mb-1 flex justify-end text-xs text-control-light"
+ data-agent-input-footer
+ >
+ {currentChatTokenUsageLabel}
+ </div>
+
{/* Confirm buttons */}
{isAwaitingConfirm ? (
<div className="flex flex-wrap gap-x-2 gap-y-2">
diff --git a/frontend/src/react/plugins/agent/components/AgentWindow.test.tsx b/frontend/src/react/plugins/agent/components/AgentWindow.test.tsx
index 9d91eb268d..164f1b9dbe 100644
--- a/frontend/src/react/plugins/agent/components/AgentWindow.test.tsx
+++ b/frontend/src/react/plugins/agent/components/AgentWindow.test.tsx
@@ -148,6 +148,42 @@ describe("AgentWindow", () => {
unmount();
});
+ test("keeps chat status and token usage out of the window header", () => {
+ const chatId = useAgentStore.getState().currentChatId!;
+ useAgentStore.setState({
+ chats: useAgentStore
+ .getState()
+ .chats.map((chat) =>
+ chat.id === chatId
+ ? { ...chat, status: "running", totalTokensUsed: 1234 }
+ : chat
+ ),
+ });
+
+ mocks.useTranslation.mockReturnValue({
+ t: (key: string, values?: Record<string, unknown>) =>
+ key === "agent.chat-total-tokens"
+ ? `Tokens used: ${values?.count ?? ""}`
+ : key,
+ i18n: { language: "en-US" },
+ });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+
+ render();
+
+ const header = document.body.querySelector(
+ "[data-agent-window-header]"
+ ) as HTMLDivElement | null;
+
+ expect(header).toBeInstanceOf(HTMLDivElement);
+ expect(header?.textContent).toContain("agent.assistant-title");
+ expect(header?.textContent).not.toContain("agent.chat-status-running");
+ expect(header?.textContent).not.toContain("Tokens used");
+
+ unmount();
+ });
+
test("mounts agent menu and delete dialog into the agent layer root", async () => {
const archivedChat = useAgentStore.getState().createChat({
title: "Archived chat",
diff --git a/frontend/src/react/plugins/agent/components/AgentWindow.tsx b/frontend/src/react/plugins/agent/components/AgentWindow.tsx
index 5848b3a520..91809153ae 100644
--- a/frontend/src/react/plugins/agent/components/AgentWindow.tsx
+++ b/frontend/src/react/plugins/agent/components/AgentWindow.tsx
@@ -67,8 +67,6 @@ const resizeZoneClasses: Record<ResizeDirection, string> = {
sw: "bottom-[-6px] left-[-6px] size-[12px] cursor-sw-resize",
};
-const tokenFormatter = new Intl.NumberFormat();
-
export function AgentWindow() {
const { t } = useTranslation();
@@ -248,38 +246,6 @@ export function AgentWindow() {
[orderedChats]
);
- const currentChatStatusLabel = useMemo(() => {
- if (!currentChat) return t("agent.chat-status-idle");
- if (currentChat.interrupted) return t("agent.chat-status-interrupted");
- switch (currentChat.status) {
- case "running":
- return t("agent.chat-status-running");
- case "awaiting_user":
- return t("agent.chat-status-awaiting-user");
- case "error":
- return t("agent.chat-status-error");
- default:
- return t("agent.chat-status-idle");
- }
- }, [currentChat, t]);
-
- const currentChatStatusClass = useMemo(() => {
- if (!currentChat || currentChat.status === "idle")
- return "bg-control-bg text-control-light";
- if (currentChat.status === "running") return "bg-blue-50 text-accent";
- if (currentChat.interrupted || currentChat.status === "error")
- return "bg-red-50 text-error";
- return "bg-amber-50 text-amber-600";
- }, [currentChat]);
-
- const currentChatTokenUsageLabel = useMemo(
- () =>
- t("agent.chat-total-tokens", {
- count: tokenFormatter.format(currentChat?.totalTokensUsed ?? 0),
- }),
- [currentChat?.totalTokensUsed, t]
- );
-
const isChatCreationDisabled = hasRunningChat;
const isArchiveAllDisabled =
hasRunningChat || showArchivedOnly || activeChats.length === 0;
@@ -949,6 +915,7 @@ export function AgentWindow() {
<div className="flex size-full flex-col overflow-hidden rounded-lg border border-block-border bg-background shadow-xl">
{/* Header */}
<div
+ data-agent-window-header
className="flex cursor-move select-none items-center justify-between border-b bg-control-bg px-3 py-2 [touch-action:none]"
onPointerDown={startDrag}
>
@@ -956,14 +923,6 @@ export function AgentWindow() {
<span className="truncate text-sm font-medium">
{t("agent.assistant-title")}
</span>
- <span
- className={`inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${currentChatStatusClass}`}
- >
- {currentChatStatusLabel}
- </span>
- <span className="truncate text-xs text-control-light">
- {currentChatTokenUsageLabel}
- </span>
</div>
<div className="flex items-center gap-x-1">
<button