mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 13:42:09 +03:00
fix(usage): stop double-counting cache-read tokens in Command Code executor (#9438)
Merge-train validated (tip 6ce4effef8). Vitest failures confirmed as base-red (#9679).
This commit is contained in:
committed by
GitHub
parent
99be4474b6
commit
e6bf92ad65
@@ -191,6 +191,23 @@ export function getReasoningTokensOrNull(tokens: unknown): number | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return non-cached (fresh) input tokens, or `null` if the provider didn't
|
||||
* report any. Command Code reports this as `inputTokenDetails.noCacheTokens`.
|
||||
* Informational only — the value is already included in prompt_tokens, so it
|
||||
* must never be added to metering totals (see commandCode.ts usageFromCommandCode).
|
||||
*/
|
||||
export function getNoCacheTokens(tokens: unknown): number | null {
|
||||
const tokenRecord = asRecord(tokens);
|
||||
const promptDetails = getPromptTokenDetails(tokenRecord);
|
||||
if (hasAnyKey(tokenRecord, ["no_cache_tokens"]) || hasAnyKey(promptDetails, ["noCacheTokens"])) {
|
||||
return toFiniteNumber(
|
||||
tokenRecord.no_cache_tokens ?? promptDetails.noCacheTokens ?? tokenRecord.noCacheTokens
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function formatUsageLog(tokens: unknown): string {
|
||||
const input = getLoggedInputTokens(tokens);
|
||||
const output = getLoggedOutputTokens(tokens);
|
||||
|
||||
Reference in New Issue
Block a user