@@ -23,10 +23,12 @@ import (
2323 "time"
2424
2525 "github.com/google/uuid"
26+ "github.com/router-for-me/CLIProxyAPI/v6/internal/cache"
2627 "github.com/router-for-me/CLIProxyAPI/v6/internal/config"
2728 "github.com/router-for-me/CLIProxyAPI/v6/internal/misc"
2829 "github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/executor/helps"
2930 "github.com/router-for-me/CLIProxyAPI/v6/internal/thinking"
31+ antigravityclaude "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/antigravity/claude"
3032 "github.com/router-for-me/CLIProxyAPI/v6/internal/util"
3133 sdkAuth "github.com/router-for-me/CLIProxyAPI/v6/sdk/auth"
3234 cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
@@ -182,6 +184,24 @@ func newAntigravityHTTPClient(ctx context.Context, cfg *config.Config, auth *cli
182184 return client
183185}
184186
187+ func validateAntigravityRequestSignatures (from sdktranslator.Format , rawJSON []byte ) error {
188+ if from .String () != "claude" {
189+ return nil
190+ }
191+ if cache .SignatureCacheEnabled () {
192+ return nil
193+ }
194+ if ! cache .SignatureBypassStrictMode () {
195+ // Non-strict bypass: let the translator handle invalid signatures
196+ // by dropping unsigned thinking blocks silently (no 400).
197+ return nil
198+ }
199+ if err := antigravityclaude .ValidateClaudeBypassSignatures (rawJSON ); err != nil {
200+ return statusErr {code : http .StatusBadRequest , msg : err .Error ()}
201+ }
202+ return nil
203+ }
204+
185205// Identifier returns the executor identifier.
186206func (e * AntigravityExecutor ) Identifier () string { return antigravityAuthType }
187207
@@ -664,14 +684,6 @@ func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Au
664684 return e .executeClaudeNonStream (ctx , auth , req , opts )
665685 }
666686
667- token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
668- if errToken != nil {
669- return resp , errToken
670- }
671- if updatedAuth != nil {
672- auth = updatedAuth
673- }
674-
675687 reporter := helps .NewUsageReporter (ctx , e .Identifier (), baseModel , auth )
676688 defer reporter .TrackFailure (ctx , & err )
677689
@@ -683,6 +695,16 @@ func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Au
683695 originalPayloadSource = opts .OriginalRequest
684696 }
685697 originalPayload := originalPayloadSource
698+ if errValidate := validateAntigravityRequestSignatures (from , originalPayload ); errValidate != nil {
699+ return resp , errValidate
700+ }
701+ token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
702+ if errToken != nil {
703+ return resp , errToken
704+ }
705+ if updatedAuth != nil {
706+ auth = updatedAuth
707+ }
686708 originalTranslated := sdktranslator .TranslateRequest (from , to , baseModel , originalPayload , false )
687709 translated := sdktranslator .TranslateRequest (from , to , baseModel , req .Payload , false )
688710
@@ -874,14 +896,6 @@ func (e *AntigravityExecutor) executeClaudeNonStream(ctx context.Context, auth *
874896 return resp , statusErr {code : http .StatusTooManyRequests , msg : fmt .Sprintf ("auth in short cooldown, %s remaining" , remaining ), retryAfter : & d }
875897 }
876898
877- token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
878- if errToken != nil {
879- return resp , errToken
880- }
881- if updatedAuth != nil {
882- auth = updatedAuth
883- }
884-
885899 reporter := helps .NewUsageReporter (ctx , e .Identifier (), baseModel , auth )
886900 defer reporter .TrackFailure (ctx , & err )
887901
@@ -893,6 +907,16 @@ func (e *AntigravityExecutor) executeClaudeNonStream(ctx context.Context, auth *
893907 originalPayloadSource = opts .OriginalRequest
894908 }
895909 originalPayload := originalPayloadSource
910+ if errValidate := validateAntigravityRequestSignatures (from , originalPayload ); errValidate != nil {
911+ return resp , errValidate
912+ }
913+ token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
914+ if errToken != nil {
915+ return resp , errToken
916+ }
917+ if updatedAuth != nil {
918+ auth = updatedAuth
919+ }
896920 originalTranslated := sdktranslator .TranslateRequest (from , to , baseModel , originalPayload , true )
897921 translated := sdktranslator .TranslateRequest (from , to , baseModel , req .Payload , true )
898922
@@ -1335,14 +1359,6 @@ func (e *AntigravityExecutor) ExecuteStream(ctx context.Context, auth *cliproxya
13351359 return nil , statusErr {code : http .StatusTooManyRequests , msg : fmt .Sprintf ("auth in short cooldown, %s remaining" , remaining ), retryAfter : & d }
13361360 }
13371361
1338- token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
1339- if errToken != nil {
1340- return nil , errToken
1341- }
1342- if updatedAuth != nil {
1343- auth = updatedAuth
1344- }
1345-
13461362 reporter := helps .NewUsageReporter (ctx , e .Identifier (), baseModel , auth )
13471363 defer reporter .TrackFailure (ctx , & err )
13481364
@@ -1354,6 +1370,16 @@ func (e *AntigravityExecutor) ExecuteStream(ctx context.Context, auth *cliproxya
13541370 originalPayloadSource = opts .OriginalRequest
13551371 }
13561372 originalPayload := originalPayloadSource
1373+ if errValidate := validateAntigravityRequestSignatures (from , originalPayload ); errValidate != nil {
1374+ return nil , errValidate
1375+ }
1376+ token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
1377+ if errToken != nil {
1378+ return nil , errToken
1379+ }
1380+ if updatedAuth != nil {
1381+ auth = updatedAuth
1382+ }
13571383 originalTranslated := sdktranslator .TranslateRequest (from , to , baseModel , originalPayload , true )
13581384 translated := sdktranslator .TranslateRequest (from , to , baseModel , req .Payload , true )
13591385
@@ -1593,6 +1619,16 @@ func (e *AntigravityExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Au
15931619func (e * AntigravityExecutor ) CountTokens (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (cliproxyexecutor.Response , error ) {
15941620 baseModel := thinking .ParseSuffix (req .Model ).ModelName
15951621
1622+ from := opts .SourceFormat
1623+ to := sdktranslator .FromString ("antigravity" )
1624+ respCtx := context .WithValue (ctx , "alt" , opts .Alt )
1625+ originalPayloadSource := req .Payload
1626+ if len (opts .OriginalRequest ) > 0 {
1627+ originalPayloadSource = opts .OriginalRequest
1628+ }
1629+ if errValidate := validateAntigravityRequestSignatures (from , originalPayloadSource ); errValidate != nil {
1630+ return cliproxyexecutor.Response {}, errValidate
1631+ }
15961632 token , updatedAuth , errToken := e .ensureAccessToken (ctx , auth )
15971633 if errToken != nil {
15981634 return cliproxyexecutor.Response {}, errToken
@@ -1604,10 +1640,6 @@ func (e *AntigravityExecutor) CountTokens(ctx context.Context, auth *cliproxyaut
16041640 return cliproxyexecutor.Response {}, statusErr {code : http .StatusUnauthorized , msg : "missing access token" }
16051641 }
16061642
1607- from := opts .SourceFormat
1608- to := sdktranslator .FromString ("antigravity" )
1609- respCtx := context .WithValue (ctx , "alt" , opts .Alt )
1610-
16111643 // Prepare payload once (doesn't depend on baseURL)
16121644 payload := sdktranslator .TranslateRequest (from , to , baseModel , req .Payload , false )
16131645
0 commit comments