Stream token usage on every agent message (#5342)
This commit is contained in:
@@ -70,9 +70,9 @@ interface ChatInputProps {
|
||||
droppedFiles?: DroppedFile[];
|
||||
onFilesProcessed?: () => void; // Callback to clear dropped files after processing
|
||||
setView: (view: View) => void;
|
||||
numTokens?: number;
|
||||
inputTokens?: number;
|
||||
outputTokens?: number;
|
||||
totalTokens?: number;
|
||||
accumulatedInputTokens?: number;
|
||||
accumulatedOutputTokens?: number;
|
||||
messages?: Message[];
|
||||
sessionCosts?: {
|
||||
[key: string]: {
|
||||
@@ -103,9 +103,9 @@ export default function ChatInput({
|
||||
droppedFiles = [],
|
||||
onFilesProcessed,
|
||||
setView,
|
||||
numTokens,
|
||||
inputTokens,
|
||||
outputTokens,
|
||||
totalTokens,
|
||||
accumulatedInputTokens,
|
||||
accumulatedOutputTokens,
|
||||
messages = [],
|
||||
disableAnimation = false,
|
||||
sessionCosts,
|
||||
@@ -505,16 +505,16 @@ export default function ChatInput({
|
||||
clearAlerts();
|
||||
|
||||
// Show alert when either there is registered token usage, or we know the limit
|
||||
if ((numTokens && numTokens > 0) || (isTokenLimitLoaded && tokenLimit)) {
|
||||
if ((totalTokens && totalTokens > 0) || (isTokenLimitLoaded && tokenLimit)) {
|
||||
addAlert({
|
||||
type: AlertType.Info,
|
||||
message: 'Context window',
|
||||
progress: {
|
||||
current: numTokens || 0,
|
||||
current: totalTokens || 0,
|
||||
total: tokenLimit,
|
||||
},
|
||||
showCompactButton: true,
|
||||
compactButtonDisabled: !numTokens,
|
||||
compactButtonDisabled: !totalTokens,
|
||||
onCompact: () => {
|
||||
window.dispatchEvent(new CustomEvent('hide-alert-popover'));
|
||||
|
||||
@@ -542,7 +542,7 @@ export default function ChatInput({
|
||||
}
|
||||
// We intentionally omit setView as it shouldn't trigger a re-render of alerts
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [numTokens, toolCount, tokenLimit, isTokenLimitLoaded, addAlert, clearAlerts]);
|
||||
}, [totalTokens, toolCount, tokenLimit, isTokenLimitLoaded, addAlert, clearAlerts]);
|
||||
|
||||
// Cleanup effect for component unmount - prevent memory leaks
|
||||
useEffect(() => {
|
||||
@@ -1540,8 +1540,8 @@ export default function ChatInput({
|
||||
<>
|
||||
<div className="flex items-center h-full ml-1 mr-1">
|
||||
<CostTracker
|
||||
inputTokens={inputTokens}
|
||||
outputTokens={outputTokens}
|
||||
inputTokens={accumulatedInputTokens}
|
||||
outputTokens={accumulatedOutputTokens}
|
||||
sessionCosts={sessionCosts}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user