RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
/*
* Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useTranslation } from 'react-i18next';
import { ITurnUsage } from '@/interfaces/database/chat';
/**
* The one-line cost footer under an answer: tokens spent and how long the turn
* took.
*
* It renders only when the turn reported a cost, either in the final SSE chunk
* or in a message restored from history.
*/
export function TurnUsage({
usage,
elapsedMs,
}: {
usage?: ITurnUsage;
elapsedMs?: number;
}) {
// `chat` is where the rest of the chat-setting wording lives; the footer is
// part of the same surface.
const { t } = useTranslation('translation', { keyPrefix: 'chat' });
if (!usage || !usage.total_tokens) return null;
const seconds = elapsedMs ? elapsedMs / 1000 : undefined;
return (
<div
className="text-text-secondary text-xs mt-2 select-none"
data-testid="turn-usage"
>
{t('tokensSpent', {
total: usage.total_tokens,
prompt: usage.prompt_tokens,
completion: usage.completion_tokens,
})}
{seconds !== undefined && (
<>
{' · '}
{t('turnElapsed', { seconds: seconds.toFixed(1) })}
</>
)}
</div>
);
}