mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
feat(dashboard): show cache percentage in request logs (#11970)
Mostra a % de cache nos logs de requisição, com teste próprio (`request-logger-cache-percentage.test.ts`). Validado no worktree combinado do lote. Pequeno ajuste feito por cima: `formatCachePercentage` movida de `RequestLoggerV2.tsx` para `src/shared/utils/formatting.ts`. `RequestLoggerV2.tsx` importa `RequestLoggerDetail`, que desde o #11703 (mergeado nesta mesma sessão) importa CSS bruto de `react18-json-view` — algo que o Node native test runner não consegue carregar. O teste original importava a função direto do componente e quebrava por causa dessa cadeia de import, não por bug na PR. Movida a função (pura, sem dependências) para o utils compartilhado; ajustado o import do componente e do teste. Typecheck limpo, teste passando (6/6).
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
maskAccount,
|
||||
stableAccountSuffix,
|
||||
formatApiKeyLabel,
|
||||
formatCachePercentage,
|
||||
} from "@/shared/utils/formatting";
|
||||
import { getProviderDisplayLabel } from "@/shared/utils/providerDisplayLabel";
|
||||
import useEmailPrivacyStore from "@/store/emailPrivacyStore";
|
||||
@@ -1572,7 +1573,8 @@ const RequestLoggerV2 = forwardRef<RequestLoggerV2Handle, { initialSelectedId?:
|
||||
className="text-sky-700 dark:text-sky-400"
|
||||
title={tCache("cachedTokensCol")}
|
||||
>
|
||||
{log.tokens.cacheRead.toLocaleString()}
|
||||
{log.tokens.cacheRead.toLocaleString()} (
|
||||
{formatCachePercentage(log.tokens.in, log.tokens.cacheRead)}%)
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -216,3 +216,13 @@ export function formatErrorForDisplay(err: unknown): string | null {
|
||||
return String(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** Percentage of `tokensIn` served from cache, clamped to [0, 100]. */
|
||||
export function formatCachePercentage(
|
||||
tokensIn: number | null | undefined,
|
||||
cacheRead: number | null | undefined
|
||||
): number {
|
||||
if (!tokensIn || tokensIn <= 0) return 0;
|
||||
if (!cacheRead || cacheRead <= 0) return 0;
|
||||
return Math.min(100, Math.round((cacheRead / tokensIn) * 100));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user