From 14aedac1e11ab6d47d5a151190400261cac0a2ab Mon Sep 17 00:00:00 2001 From: Dustin Healy Date: Thu, 21 Aug 2025 02:25:43 -0700 Subject: [PATCH] refactor: move CostBar into its own component --- client/src/components/Chat/ChatView.tsx | 55 +------------------- client/src/components/Chat/CostBar.tsx | 69 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 53 deletions(-) create mode 100644 client/src/components/Chat/CostBar.tsx diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsx index b6fbaea530..4e9950b676 100644 --- a/client/src/components/Chat/ChatView.tsx +++ b/client/src/components/Chat/ChatView.tsx @@ -13,6 +13,7 @@ import ConversationStarters from './Input/ConversationStarters'; import MessagesView from './Messages/MessagesView'; import Presentation from './Presentation'; import ChatForm from './Input/ChatForm'; +import CostBar from './CostBar'; import Landing from './Landing'; import Header from './Header'; import Footer from './Footer'; @@ -116,59 +117,7 @@ function ChatView({ index = 0 }: { index?: number }) { !isLandingPage && conversationCosts && conversationCosts.totals && ( -
-
-
-
- - - - {conversationCosts.totals.prompt.tokenCount}t -
-
${Math.abs(conversationCosts.totals.prompt.usd).toFixed(6)}
-
-
-
{conversationCosts.totals.total.tokenCount}t
-
${Math.abs(conversationCosts.totals.total.usd).toFixed(6)}
-
-
-
- - - - {conversationCosts.totals.completion.tokenCount}t -
-
${Math.abs(conversationCosts.totals.completion.usd).toFixed(6)}
-
-
-
+ ) } costs={conversationCosts} diff --git a/client/src/components/Chat/CostBar.tsx b/client/src/components/Chat/CostBar.tsx new file mode 100644 index 0000000000..d450114842 --- /dev/null +++ b/client/src/components/Chat/CostBar.tsx @@ -0,0 +1,69 @@ +import type { TConversationCosts } from 'librechat-data-provider'; +import { cn } from '~/utils'; + +interface CostBarProps { + conversationCosts: TConversationCosts; + showCostBar: boolean; +} + +export default function CostBar({ conversationCosts, showCostBar }: CostBarProps) { + if (!conversationCosts || !conversationCosts.totals) { + return null; + } + + return ( +
+
+
+
+ + + + {conversationCosts.totals.prompt.tokenCount}t +
+
${Math.abs(conversationCosts.totals.prompt.usd).toFixed(6)}
+
+
+
{conversationCosts.totals.total.tokenCount}t
+
${Math.abs(conversationCosts.totals.total.usd).toFixed(6)}
+
+
+
+ + + + {conversationCosts.totals.completion.tokenCount}t +
+
${Math.abs(conversationCosts.totals.completion.usd).toFixed(6)}
+
+
+
+ ); +}