fix(antigravity): strip thinking blocks with empty signatures instead of rejecting
Thinking blocks with empty signatures come from proxy-generated responses (Antigravity/Gemini routed as Claude). These should be silently dropped from the request payload before forwarding, not rejected with 400. Fixes 10 "missing thinking signature" errors.
This commit is contained in:
@@ -55,6 +55,7 @@ import (
|
||||
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/cache"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
)
|
||||
|
||||
@@ -72,6 +73,44 @@ type claudeSignatureTree struct {
|
||||
HasField7 bool
|
||||
}
|
||||
|
||||
// StripEmptySignatureThinkingBlocks removes thinking blocks with empty signatures
|
||||
// from messages[].content[]. These come from proxy-generated responses (Antigravity/Gemini)
|
||||
// where no real Claude signature exists.
|
||||
func StripEmptySignatureThinkingBlocks(payload []byte) []byte {
|
||||
messages := gjson.GetBytes(payload, "messages")
|
||||
if !messages.IsArray() {
|
||||
return payload
|
||||
}
|
||||
modified := false
|
||||
for i, msg := range messages.Array() {
|
||||
content := msg.Get("content")
|
||||
if !content.IsArray() {
|
||||
continue
|
||||
}
|
||||
var kept []string
|
||||
stripped := false
|
||||
for _, part := range content.Array() {
|
||||
if part.Get("type").String() == "thinking" && strings.TrimSpace(part.Get("signature").String()) == "" {
|
||||
stripped = true
|
||||
continue
|
||||
}
|
||||
kept = append(kept, part.Raw)
|
||||
}
|
||||
if stripped {
|
||||
modified = true
|
||||
if len(kept) == 0 {
|
||||
payload, _ = sjson.SetRawBytes(payload, fmt.Sprintf("messages.%d.content", i), []byte("[]"))
|
||||
} else {
|
||||
payload, _ = sjson.SetRawBytes(payload, fmt.Sprintf("messages.%d.content", i), []byte("["+strings.Join(kept, ",")+"]"))
|
||||
}
|
||||
}
|
||||
}
|
||||
if !modified {
|
||||
return payload
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
func ValidateClaudeBypassSignatures(inputRawJSON []byte) error {
|
||||
messages := gjson.GetBytes(inputRawJSON, "messages")
|
||||
if !messages.IsArray() {
|
||||
|
||||
Reference in New Issue
Block a user