feat: Update response handling and logging for improved usage tracking

This commit is contained in:
decolua
2026-02-03 10:22:43 +07:00
parent a33924b336
commit df0e1d6485
7 changed files with 348 additions and 152 deletions

View File

@@ -146,6 +146,8 @@ export function convertKiroToOpenAI(chunk, state) {
// Handle completion/done events
if (eventType === "messageStopEvent" || eventType === "done" || data.messageStopEvent) {
state.finishReason = "stop"; // Mark for usage injection in stream.js
const openaiChunk = {
id: state.responseId,
object: "chat.completion.chunk",

View File

@@ -505,6 +505,8 @@ export function openaiResponsesToOpenAIResponse(chunk, state) {
if (!state.finishReasonSent) {
state.finishReasonSent = true;
state.finishReason = "stop"; // Mark for usage injection in stream.js
const finalChunk = {
id: state.chatId,
object: "chat.completion.chunk",

View File

@@ -192,7 +192,10 @@ export function openaiToClaudeResponse(chunk, state) {
});
}
// Use tracked usage or default to 0
// Mark finish for later usage injection in stream.js
state.finishReason = choice.finish_reason;
// Use tracked usage (will be estimated in stream.js if not valid)
const finalUsage = state.usage || { input_tokens: 0, output_tokens: 0 };
results.push({
type: "message_delta",