refactor(translator): P4 concern #5 buildUsage — apply to kiro/ollama/commandcode

- Replace 3 inline {prompt,completion,total} usage objects with buildUsage()
- Preserves ?? vs total fallback semantics (commandcode)
- Golden tests pass, identical output

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-13 21:27:22 +07:00
parent 252bf56a9f
commit 633b66dcb6
3 changed files with 13 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { buildChunk } from "../helpers/chunkBuilder.js";
import { buildUsage } from "../helpers/usageHelper.js";
import { fallbackToolCallId } from "../helpers/toolCallHelper.js";
/**
@@ -79,11 +80,8 @@ export function ollamaToOpenAI(chunk, state) {
* Extract usage stats from Ollama response
*/
function extractUsage(ollamaChunk) {
return {
prompt_tokens: ollamaChunk.prompt_eval_count || 0,
completion_tokens: ollamaChunk.eval_count || 0,
total_tokens: (ollamaChunk.prompt_eval_count || 0) + (ollamaChunk.eval_count || 0)
};
const inTok = ollamaChunk.prompt_eval_count || 0, outTok = ollamaChunk.eval_count || 0;
return buildUsage({ promptTokens: inTok, completionTokens: outTok, totalTokens: inTok + outTok });
}
/**