Skip to content

Commit 78be18f

Browse files
authored
feat: Format token counts with locale-aware thousands separators (eigent-ai#1475)
1 parent 6a504a0 commit 78be18f

2 files changed

Lines changed: 67 additions & 50 deletions

File tree

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
1-
import { Button } from "@/components/ui/button";
2-
import { PlayCircle } from "lucide-react";
3-
import { useTranslation } from "react-i18next";
1+
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
14+
15+
import { Button } from '@/components/ui/button';
16+
import { PlayCircle } from 'lucide-react';
17+
import { useTranslation } from 'react-i18next';
418

519
interface HeaderBoxProps {
6-
/** Token count to display */
7-
tokens: number;
8-
/** Task status for determining what button to show */
9-
status?: 'running' | 'finished' | 'pending' | 'pause';
10-
/** Whether replay is loading */
11-
replayLoading?: boolean;
12-
/** Callback when replay button is clicked */
13-
onReplay?: () => void;
14-
/** Optional class name */
15-
className?: string;
20+
/** Token count to display */
21+
tokens: number;
22+
/** Task status for determining what button to show */
23+
status?: 'running' | 'finished' | 'pending' | 'pause';
24+
/** Whether replay is loading */
25+
replayLoading?: boolean;
26+
/** Callback when replay button is clicked */
27+
onReplay?: () => void;
28+
/** Optional class name */
29+
className?: string;
1630
}
1731

1832
export function HeaderBox({
19-
tokens,
20-
status,
21-
replayLoading = false,
22-
onReplay,
23-
className,
33+
tokens,
34+
status,
35+
replayLoading = false,
36+
onReplay,
37+
className,
2438
}: HeaderBoxProps) {
25-
const { t } = useTranslation();
26-
27-
// Replay button only appears when task is finished
28-
const showReplayButton = status === 'finished';
29-
// Replay button is disabled when task is running or pending
30-
const isReplayDisabled = status === 'running' || status === 'pending' || status === 'pause';
39+
const { t } = useTranslation();
3140

32-
return (
33-
<div className={`w-full h-[44px] flex flex-row items-center justify-between px-3 ${className || ""}`}>
34-
<div className="flex items-center gap-md">
35-
<div className="text-text-body font-bold text-body-base leading-relaxed">
36-
Chat
37-
</div>
38-
<div className="text-text-information text-xs font-semibold leading-17">
39-
# {tokens || 0}
40-
</div>
41-
</div>
41+
// Replay button only appears when task is finished
42+
const showReplayButton = status === 'finished';
43+
// Replay button is disabled when task is running or pending
44+
const isReplayDisabled =
45+
status === 'running' || status === 'pending' || status === 'pause';
4246

43-
{showReplayButton && (
44-
<Button
45-
onClick={onReplay}
46-
disabled={isReplayDisabled || replayLoading}
47-
variant="ghost"
48-
size="sm"
49-
className="no-drag !text-text-information bg-surface-information font-semibold rounded-full"
50-
>
51-
<PlayCircle />
52-
{replayLoading ? t("common.loading") : t("chat.replay")}
53-
</Button>
54-
)}
47+
return (
48+
<div
49+
className={`flex h-[44px] w-full flex-row items-center justify-between px-3 ${className || ''}`}
50+
>
51+
<div className="flex items-center gap-md">
52+
<div className="text-body-base font-bold leading-relaxed text-text-body">
53+
Chat
54+
</div>
55+
<div className="text-xs font-semibold leading-17 text-text-information">
56+
# {(tokens || 0).toLocaleString()}
5557
</div>
56-
);
57-
}
58+
</div>
59+
60+
{showReplayButton && (
61+
<Button
62+
onClick={onReplay}
63+
disabled={isReplayDisabled || replayLoading}
64+
variant="ghost"
65+
size="sm"
66+
className="no-drag rounded-full bg-surface-information font-semibold !text-text-information"
67+
>
68+
<PlayCircle />
69+
{replayLoading ? t('common.loading') : t('chat.replay')}
70+
</Button>
71+
)}
72+
</div>
73+
);
74+
}

‎src/components/HistorySidebar/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export default function HistorySidebar() {
417417
<Tag variant="info" size="sm">
418418
<Hash className="h-3.5 w-3.5" />
419419
<span className="text-xs">
420-
{project.total_tokens || 0}
420+
{(project.total_tokens || 0).toLocaleString()}
421421
</span>
422422
</Tag>
423423
</TooltipSimple>
@@ -536,7 +536,7 @@ export default function HistorySidebar() {
536536
<Tag variant="info" size="sm">
537537
<Hash className="h-3.5 w-3.5" />
538538
<span className="text-xs">
539-
{project.total_tokens || 0}
539+
{(project.total_tokens || 0).toLocaleString()}
540540
</span>
541541
</Tag>
542542
</TooltipSimple>

0 commit comments

Comments
 (0)