fix(translator): handle stop_reason and MAX_TOKENS for Claude responses

This commit is contained in:
Luis Pater
2026-01-31 04:03:01 +08:00
parent f887f9985d
commit f99cddf97f
3 changed files with 8 additions and 1 deletions

View File

@@ -244,6 +244,8 @@ func ConvertGeminiCLIResponseToClaude(_ context.Context, _ string, originalReque
// Set tool_use stop reason if tools were used in this response
if usedTool {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
} else if finish := gjson.GetBytes(rawJSON, "response.candidates.0.finishReason"); finish.Exists() && finish.String() == "MAX_TOKENS" {
template = `{"type":"message_delta","delta":{"stop_reason":"max_tokens","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
}
// Include thinking tokens in output token count if present