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

@@ -5,6 +5,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";
import { reasoningDelta } from "../helpers/reasoningHelper.js";
@@ -143,11 +144,8 @@ export function convertKiroToOpenAI(chunk, state) {
if (eventType === "usageEvent" || data.usageEvent) {
const usage = data.usageEvent || data;
if (usage && typeof usage === 'object') {
state.usage = {
prompt_tokens: usage.inputTokens || 0,
completion_tokens: usage.outputTokens || 0,
total_tokens: (usage.inputTokens || 0) + (usage.outputTokens || 0)
};
const inTok = usage.inputTokens || 0, outTok = usage.outputTokens || 0;
state.usage = buildUsage({ promptTokens: inTok, completionTokens: outTok, totalTokens: inTok + outTok });
}
return null;
}