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

@@ -112,7 +112,10 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
} else if typeStr == "response.completed" {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
p := (*param).(*ConvertCodexResponseToClaudeParams).HasToolCall
if p {
stopReason := rootResult.Get("response.stop_reason").String()
if stopReason != "" {
template, _ = sjson.Set(template, "delta.stop_reason", stopReason)
} else if p {
template, _ = sjson.Set(template, "delta.stop_reason", "tool_use")
} else {
template, _ = sjson.Set(template, "delta.stop_reason", "end_turn")