From f092801b6188a10f05cf8c9a602a34d0a9a224f6 Mon Sep 17 00:00:00 2001 From: "huynguyen03.dev" Date: Sun, 7 Dec 2025 15:39:58 +0700 Subject: [PATCH 1/2] fix: filter whitespace-only text in Claude to OpenAI translation Skip text content blocks that are empty or contain only whitespace when translating Claude messages to OpenAI format. This fixes GLM-4.6 and other strict OpenAI-compatible providers that reject empty text with error 'text cannot be empty'. --- internal/translator/openai/claude/openai_claude_request.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/translator/openai/claude/openai_claude_request.go b/internal/translator/openai/claude/openai_claude_request.go index bff306cc..2510b19c 100644 --- a/internal/translator/openai/claude/openai_claude_request.go +++ b/internal/translator/openai/claude/openai_claude_request.go @@ -8,6 +8,7 @@ package claude import ( "bytes" "encoding/json" + "strings" "github.com/tidwall/gjson" "github.com/tidwall/sjson" @@ -245,8 +246,12 @@ func convertClaudeContentPart(part gjson.Result) (string, bool) { if !part.Get("text").Exists() { return "", false } + text := part.Get("text").String() + if strings.TrimSpace(text) == "" { + return "", false + } textContent := `{"type":"text","text":""}` - textContent, _ = sjson.Set(textContent, "text", part.Get("text").String()) + textContent, _ = sjson.Set(textContent, "text", text) return textContent, true case "image": From 549c0c2c5a7318c9409ffec4e3365b3d055a068f Mon Sep 17 00:00:00 2001 From: "huynguyen03.dev" Date: Sun, 7 Dec 2025 16:08:12 +0700 Subject: [PATCH 2/2] fix: filter whitespace-only text content in Claude to OpenAI translation Remove redundant existence check since TrimSpace handles empty strings --- internal/translator/openai/claude/openai_claude_request.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/translator/openai/claude/openai_claude_request.go b/internal/translator/openai/claude/openai_claude_request.go index 2510b19c..3521b2e5 100644 --- a/internal/translator/openai/claude/openai_claude_request.go +++ b/internal/translator/openai/claude/openai_claude_request.go @@ -243,9 +243,6 @@ func convertClaudeContentPart(part gjson.Result) (string, bool) { switch partType { case "text": - if !part.Get("text").Exists() { - return "", false - } text := part.Get("text").String() if strings.TrimSpace(text) == "" { return "", false