fix(translator): skip empty text parts in Claude request conversion

- Updated `ConvertClaudeRequestToGemini` to ignore empty `text` entries during processing.
- Added unit tests to ensure empty `text` parts are skipped correctly.

Closes: #3485
This commit is contained in:
Luis Pater
2026-05-20 11:59:31 +08:00
parent 0ec07e57dd
commit 1c632d151d
2 changed files with 31 additions and 1 deletions
@@ -81,8 +81,12 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
contentsResult.ForEach(func(_, contentResult gjson.Result) bool {
switch contentResult.Get("type").String() {
case "text":
text := contentResult.Get("text").String()
if text == "" {
return true
}
part := []byte(`{"text":""}`)
part, _ = sjson.SetBytes(part, "text", contentResult.Get("text").String())
part, _ = sjson.SetBytes(part, "text", text)
contentJSON, _ = sjson.SetRawBytes(contentJSON, "parts.-1", part)
case "tool_use":