feat: Update response handling and logging for improved usage tracking
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user