mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-20 20:34:36 +00:00
chore: merge upstream CLIProxyAPI v6.9.27
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/cache"
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/misc"
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/executor/helps"
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/thinking"
|
||||
antigravityclaude "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/antigravity/claude"
|
||||
@@ -184,22 +185,24 @@ func newAntigravityHTTPClient(ctx context.Context, cfg *config.Config, auth *cli
|
||||
return client
|
||||
}
|
||||
|
||||
func validateAntigravityRequestSignatures(from sdktranslator.Format, rawJSON []byte) error {
|
||||
func validateAntigravityRequestSignatures(from sdktranslator.Format, rawJSON []byte) ([]byte, error) {
|
||||
if from.String() != "claude" {
|
||||
return nil
|
||||
return rawJSON, nil
|
||||
}
|
||||
// Always strip thinking blocks with empty signatures (proxy-generated).
|
||||
rawJSON = antigravityclaude.StripEmptySignatureThinkingBlocks(rawJSON)
|
||||
if cache.SignatureCacheEnabled() {
|
||||
return nil
|
||||
return rawJSON, nil
|
||||
}
|
||||
if !cache.SignatureBypassStrictMode() {
|
||||
// Non-strict bypass: let the translator handle invalid signatures
|
||||
// by dropping unsigned thinking blocks silently (no 400).
|
||||
return nil
|
||||
return rawJSON, nil
|
||||
}
|
||||
if err := antigravityclaude.ValidateClaudeBypassSignatures(rawJSON); err != nil {
|
||||
return statusErr{code: http.StatusBadRequest, msg: err.Error()}
|
||||
return rawJSON, statusErr{code: http.StatusBadRequest, msg: err.Error()}
|
||||
}
|
||||
return nil
|
||||
return rawJSON, nil
|
||||
}
|
||||
|
||||
// Identifier returns the executor identifier.
|
||||
@@ -695,9 +698,11 @@ func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Au
|
||||
originalPayloadSource = opts.OriginalRequest
|
||||
}
|
||||
originalPayload := originalPayloadSource
|
||||
if errValidate := validateAntigravityRequestSignatures(from, originalPayload); errValidate != nil {
|
||||
originalPayload, errValidate := validateAntigravityRequestSignatures(from, originalPayload)
|
||||
if errValidate != nil {
|
||||
return resp, errValidate
|
||||
}
|
||||
req.Payload = originalPayload
|
||||
token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth)
|
||||
if errToken != nil {
|
||||
return resp, errToken
|
||||
@@ -907,9 +912,11 @@ func (e *AntigravityExecutor) executeClaudeNonStream(ctx context.Context, auth *
|
||||
originalPayloadSource = opts.OriginalRequest
|
||||
}
|
||||
originalPayload := originalPayloadSource
|
||||
if errValidate := validateAntigravityRequestSignatures(from, originalPayload); errValidate != nil {
|
||||
originalPayload, errValidate := validateAntigravityRequestSignatures(from, originalPayload)
|
||||
if errValidate != nil {
|
||||
return resp, errValidate
|
||||
}
|
||||
req.Payload = originalPayload
|
||||
token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth)
|
||||
if errToken != nil {
|
||||
return resp, errToken
|
||||
@@ -1370,9 +1377,11 @@ func (e *AntigravityExecutor) ExecuteStream(ctx context.Context, auth *cliproxya
|
||||
originalPayloadSource = opts.OriginalRequest
|
||||
}
|
||||
originalPayload := originalPayloadSource
|
||||
if errValidate := validateAntigravityRequestSignatures(from, originalPayload); errValidate != nil {
|
||||
originalPayload, errValidate := validateAntigravityRequestSignatures(from, originalPayload)
|
||||
if errValidate != nil {
|
||||
return nil, errValidate
|
||||
}
|
||||
req.Payload = originalPayload
|
||||
token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth)
|
||||
if errToken != nil {
|
||||
return nil, errToken
|
||||
@@ -1626,9 +1635,11 @@ func (e *AntigravityExecutor) CountTokens(ctx context.Context, auth *cliproxyaut
|
||||
if len(opts.OriginalRequest) > 0 {
|
||||
originalPayloadSource = opts.OriginalRequest
|
||||
}
|
||||
if errValidate := validateAntigravityRequestSignatures(from, originalPayloadSource); errValidate != nil {
|
||||
originalPayloadSource, errValidate := validateAntigravityRequestSignatures(from, originalPayloadSource)
|
||||
if errValidate != nil {
|
||||
return cliproxyexecutor.Response{}, errValidate
|
||||
}
|
||||
req.Payload = originalPayloadSource
|
||||
token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth)
|
||||
if errToken != nil {
|
||||
return cliproxyexecutor.Response{}, errToken
|
||||
@@ -1945,6 +1956,15 @@ func (e *AntigravityExecutor) buildRequest(ctx context.Context, auth *cliproxyau
|
||||
payload = geminiToAntigravity(modelName, payload, projectID)
|
||||
payload, _ = sjson.SetBytes(payload, "model", modelName)
|
||||
|
||||
// Cap maxOutputTokens to model's max_completion_tokens from registry
|
||||
if maxOut := gjson.GetBytes(payload, "request.generationConfig.maxOutputTokens"); maxOut.Exists() && maxOut.Type == gjson.Number {
|
||||
if modelInfo := registry.LookupModelInfo(modelName, "antigravity"); modelInfo != nil && modelInfo.MaxCompletionTokens > 0 {
|
||||
if int(maxOut.Int()) > modelInfo.MaxCompletionTokens {
|
||||
payload, _ = sjson.SetBytes(payload, "request.generationConfig.maxOutputTokens", modelInfo.MaxCompletionTokens)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useAntigravitySchema := strings.Contains(modelName, "claude") || strings.Contains(modelName, "gemini-3-pro") || strings.Contains(modelName, "gemini-3.1-pro")
|
||||
var (
|
||||
bodyReader io.Reader
|
||||
|
||||
@@ -21,6 +21,14 @@ func testGeminiSignaturePayload() string {
|
||||
return base64.StdEncoding.EncodeToString(payload)
|
||||
}
|
||||
|
||||
// testFakeClaudeSignature returns a base64 string starting with 'E' that passes
|
||||
// the lightweight hasValidClaudeSignature check but has invalid protobuf content
|
||||
// (first decoded byte 0x12 is correct, but no valid protobuf field 2 follows),
|
||||
// so it fails deep validation in strict mode.
|
||||
func testFakeClaudeSignature() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte{0x12, 0xFF, 0xFE, 0xFD})
|
||||
}
|
||||
|
||||
func testAntigravityAuth(baseURL string) *cliproxyauth.Auth {
|
||||
return &cliproxyauth.Auth{
|
||||
Attributes: map[string]string{
|
||||
@@ -40,7 +48,7 @@ func invalidClaudeThinkingPayload() []byte {
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{"type": "thinking", "thinking": "bad", "signature": "` + testGeminiSignaturePayload() + `"},
|
||||
{"type": "thinking", "thinking": "bad", "signature": "` + testFakeClaudeSignature() + `"},
|
||||
{"type": "text", "text": "hello"}
|
||||
]
|
||||
}
|
||||
@@ -134,7 +142,7 @@ func TestAntigravityExecutor_NonStrictBypassSkipsPrecheck(t *testing.T) {
|
||||
payload := invalidClaudeThinkingPayload()
|
||||
from := sdktranslator.FromString("claude")
|
||||
|
||||
err := validateAntigravityRequestSignatures(from, payload)
|
||||
_, err := validateAntigravityRequestSignatures(from, payload)
|
||||
if err != nil {
|
||||
t.Fatalf("non-strict bypass should skip precheck, got: %v", err)
|
||||
}
|
||||
@@ -150,7 +158,7 @@ func TestAntigravityExecutor_CacheModeSkipsPrecheck(t *testing.T) {
|
||||
payload := invalidClaudeThinkingPayload()
|
||||
from := sdktranslator.FromString("claude")
|
||||
|
||||
err := validateAntigravityRequestSignatures(from, payload)
|
||||
_, err := validateAntigravityRequestSignatures(from, payload)
|
||||
if err != nil {
|
||||
t.Fatalf("cache mode should skip precheck, got: %v", err)
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ func (e *IFlowExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au
|
||||
}
|
||||
|
||||
body = preserveReasoningContentInMessages(body)
|
||||
// Ensure tools array exists to avoid provider quirks similar to Qwen's behaviour.
|
||||
// Ensure tools array exists to avoid provider quirks observed in some upstreams.
|
||||
toolsResult := gjson.GetBytes(body, "tools")
|
||||
if toolsResult.Exists() && toolsResult.IsArray() && len(toolsResult.Array()) == 0 {
|
||||
body = ensureToolsArray(body)
|
||||
|
||||
Reference in New Issue
Block a user