fix: remove ClaudeMax references not yet in upstream/main
Remove SimulateClaudeMaxEnabled field and related logic from admin_service.go, and remove applyClaudeMaxCacheBillingPolicyToUsage, applyClaudeMaxNonStreamingRewrite, setupClaudeMaxStreamingHook calls from antigravity_gateway_service.go. These symbols are not yet available in upstream/main.
This commit is contained in:
@@ -145,8 +145,7 @@ type CreateGroupInput struct {
|
|||||||
// 模型路由配置(仅 anthropic 平台使用)
|
// 模型路由配置(仅 anthropic 平台使用)
|
||||||
ModelRouting map[string][]int64
|
ModelRouting map[string][]int64
|
||||||
ModelRoutingEnabled bool // 是否启用模型路由
|
ModelRoutingEnabled bool // 是否启用模型路由
|
||||||
MCPXMLInject *bool
|
MCPXMLInject *bool
|
||||||
SimulateClaudeMaxEnabled *bool
|
|
||||||
// 支持的模型系列(仅 antigravity 平台使用)
|
// 支持的模型系列(仅 antigravity 平台使用)
|
||||||
SupportedModelScopes []string
|
SupportedModelScopes []string
|
||||||
// Sora 存储配额
|
// Sora 存储配额
|
||||||
@@ -185,8 +184,7 @@ type UpdateGroupInput struct {
|
|||||||
// 模型路由配置(仅 anthropic 平台使用)
|
// 模型路由配置(仅 anthropic 平台使用)
|
||||||
ModelRouting map[string][]int64
|
ModelRouting map[string][]int64
|
||||||
ModelRoutingEnabled *bool // 是否启用模型路由
|
ModelRoutingEnabled *bool // 是否启用模型路由
|
||||||
MCPXMLInject *bool
|
MCPXMLInject *bool
|
||||||
SimulateClaudeMaxEnabled *bool
|
|
||||||
// 支持的模型系列(仅 antigravity 平台使用)
|
// 支持的模型系列(仅 antigravity 平台使用)
|
||||||
SupportedModelScopes *[]string
|
SupportedModelScopes *[]string
|
||||||
// Sora 存储配额
|
// Sora 存储配额
|
||||||
@@ -870,13 +868,6 @@ func (s *adminServiceImpl) CreateGroup(ctx context.Context, input *CreateGroupIn
|
|||||||
if input.MCPXMLInject != nil {
|
if input.MCPXMLInject != nil {
|
||||||
mcpXMLInject = *input.MCPXMLInject
|
mcpXMLInject = *input.MCPXMLInject
|
||||||
}
|
}
|
||||||
simulateClaudeMaxEnabled := false
|
|
||||||
if input.SimulateClaudeMaxEnabled != nil {
|
|
||||||
if platform != PlatformAnthropic && *input.SimulateClaudeMaxEnabled {
|
|
||||||
return nil, fmt.Errorf("simulate_claude_max_enabled only supported for anthropic groups")
|
|
||||||
}
|
|
||||||
simulateClaudeMaxEnabled = *input.SimulateClaudeMaxEnabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果指定了复制账号的源分组,先获取账号 ID 列表
|
// 如果指定了复制账号的源分组,先获取账号 ID 列表
|
||||||
var accountIDsToCopy []int64
|
var accountIDsToCopy []int64
|
||||||
@@ -933,7 +924,6 @@ func (s *adminServiceImpl) CreateGroup(ctx context.Context, input *CreateGroupIn
|
|||||||
FallbackGroupIDOnInvalidRequest: fallbackOnInvalidRequest,
|
FallbackGroupIDOnInvalidRequest: fallbackOnInvalidRequest,
|
||||||
ModelRouting: input.ModelRouting,
|
ModelRouting: input.ModelRouting,
|
||||||
MCPXMLInject: mcpXMLInject,
|
MCPXMLInject: mcpXMLInject,
|
||||||
SimulateClaudeMaxEnabled: simulateClaudeMaxEnabled,
|
|
||||||
SupportedModelScopes: input.SupportedModelScopes,
|
SupportedModelScopes: input.SupportedModelScopes,
|
||||||
SoraStorageQuotaBytes: input.SoraStorageQuotaBytes,
|
SoraStorageQuotaBytes: input.SoraStorageQuotaBytes,
|
||||||
AllowMessagesDispatch: input.AllowMessagesDispatch,
|
AllowMessagesDispatch: input.AllowMessagesDispatch,
|
||||||
@@ -1140,15 +1130,6 @@ func (s *adminServiceImpl) UpdateGroup(ctx context.Context, id int64, input *Upd
|
|||||||
if input.MCPXMLInject != nil {
|
if input.MCPXMLInject != nil {
|
||||||
group.MCPXMLInject = *input.MCPXMLInject
|
group.MCPXMLInject = *input.MCPXMLInject
|
||||||
}
|
}
|
||||||
if input.SimulateClaudeMaxEnabled != nil {
|
|
||||||
if group.Platform != PlatformAnthropic && *input.SimulateClaudeMaxEnabled {
|
|
||||||
return nil, fmt.Errorf("simulate_claude_max_enabled only supported for anthropic groups")
|
|
||||||
}
|
|
||||||
group.SimulateClaudeMaxEnabled = *input.SimulateClaudeMaxEnabled
|
|
||||||
}
|
|
||||||
if group.Platform != PlatformAnthropic {
|
|
||||||
group.SimulateClaudeMaxEnabled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// 支持的模型系列(仅 antigravity 平台使用)
|
// 支持的模型系列(仅 antigravity 平台使用)
|
||||||
if input.SupportedModelScopes != nil {
|
if input.SupportedModelScopes != nil {
|
||||||
|
|||||||
@@ -1719,7 +1719,7 @@ func (s *AntigravityGatewayService) Forward(ctx context.Context, c *gin.Context,
|
|||||||
var clientDisconnect bool
|
var clientDisconnect bool
|
||||||
if claudeReq.Stream {
|
if claudeReq.Stream {
|
||||||
// 客户端要求流式,直接透传转换
|
// 客户端要求流式,直接透传转换
|
||||||
streamRes, err := s.handleClaudeStreamingResponse(c, resp, startTime, originalModel, account.ID)
|
streamRes, err := s.handleClaudeStreamingResponse(c, resp, startTime, originalModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LegacyPrintf("service.antigravity_gateway", "%s status=stream_error error=%v", prefix, err)
|
logger.LegacyPrintf("service.antigravity_gateway", "%s status=stream_error error=%v", prefix, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1729,7 +1729,7 @@ func (s *AntigravityGatewayService) Forward(ctx context.Context, c *gin.Context,
|
|||||||
clientDisconnect = streamRes.clientDisconnect
|
clientDisconnect = streamRes.clientDisconnect
|
||||||
} else {
|
} else {
|
||||||
// 客户端要求非流式,收集流式响应后转换返回
|
// 客户端要求非流式,收集流式响应后转换返回
|
||||||
streamRes, err := s.handleClaudeStreamToNonStreaming(c, resp, startTime, originalModel, account.ID)
|
streamRes, err := s.handleClaudeStreamToNonStreaming(c, resp, startTime, originalModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.LegacyPrintf("service.antigravity_gateway", "%s status=stream_collect_error error=%v", prefix, err)
|
logger.LegacyPrintf("service.antigravity_gateway", "%s status=stream_collect_error error=%v", prefix, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1738,9 +1738,6 @@ func (s *AntigravityGatewayService) Forward(ctx context.Context, c *gin.Context,
|
|||||||
firstTokenMs = streamRes.firstTokenMs
|
firstTokenMs = streamRes.firstTokenMs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claude Max cache billing: 同步 ForwardResult.Usage 与客户端响应体一致
|
|
||||||
applyClaudeMaxCacheBillingPolicyToUsage(usage, parsedRequestFromGinContext(c), claudeMaxGroupFromGinContext(c), originalModel, account.ID)
|
|
||||||
|
|
||||||
return &ForwardResult{
|
return &ForwardResult{
|
||||||
RequestID: requestID,
|
RequestID: requestID,
|
||||||
Usage: *usage,
|
Usage: *usage,
|
||||||
@@ -3644,7 +3641,7 @@ func (s *AntigravityGatewayService) writeGoogleError(c *gin.Context, status int,
|
|||||||
|
|
||||||
// handleClaudeStreamToNonStreaming 收集上游流式响应,转换为 Claude 非流式格式返回
|
// handleClaudeStreamToNonStreaming 收集上游流式响应,转换为 Claude 非流式格式返回
|
||||||
// 用于处理客户端非流式请求但上游只支持流式的情况
|
// 用于处理客户端非流式请求但上游只支持流式的情况
|
||||||
func (s *AntigravityGatewayService) handleClaudeStreamToNonStreaming(c *gin.Context, resp *http.Response, startTime time.Time, originalModel string, accountID int64) (*antigravityStreamResult, error) {
|
func (s *AntigravityGatewayService) handleClaudeStreamToNonStreaming(c *gin.Context, resp *http.Response, startTime time.Time, originalModel string) (*antigravityStreamResult, error) {
|
||||||
scanner := bufio.NewScanner(resp.Body)
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
maxLineSize := defaultMaxLineSize
|
maxLineSize := defaultMaxLineSize
|
||||||
if s.settingService.cfg != nil && s.settingService.cfg.Gateway.MaxLineSize > 0 {
|
if s.settingService.cfg != nil && s.settingService.cfg.Gateway.MaxLineSize > 0 {
|
||||||
@@ -3802,9 +3799,6 @@ returnResponse:
|
|||||||
return nil, s.writeClaudeError(c, http.StatusBadGateway, "upstream_error", "Failed to parse upstream response")
|
return nil, s.writeClaudeError(c, http.StatusBadGateway, "upstream_error", "Failed to parse upstream response")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claude Max cache billing simulation (non-streaming)
|
|
||||||
claudeResp = applyClaudeMaxNonStreamingRewrite(c, claudeResp, agUsage, originalModel, accountID)
|
|
||||||
|
|
||||||
c.Data(http.StatusOK, "application/json", claudeResp)
|
c.Data(http.StatusOK, "application/json", claudeResp)
|
||||||
|
|
||||||
// 转换为 service.ClaudeUsage
|
// 转换为 service.ClaudeUsage
|
||||||
@@ -3819,7 +3813,7 @@ returnResponse:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleClaudeStreamingResponse 处理 Claude 流式响应(Gemini SSE → Claude SSE 转换)
|
// handleClaudeStreamingResponse 处理 Claude 流式响应(Gemini SSE → Claude SSE 转换)
|
||||||
func (s *AntigravityGatewayService) handleClaudeStreamingResponse(c *gin.Context, resp *http.Response, startTime time.Time, originalModel string, accountID int64) (*antigravityStreamResult, error) {
|
func (s *AntigravityGatewayService) handleClaudeStreamingResponse(c *gin.Context, resp *http.Response, startTime time.Time, originalModel string) (*antigravityStreamResult, error) {
|
||||||
c.Header("Content-Type", "text/event-stream")
|
c.Header("Content-Type", "text/event-stream")
|
||||||
c.Header("Cache-Control", "no-cache")
|
c.Header("Cache-Control", "no-cache")
|
||||||
c.Header("Connection", "keep-alive")
|
c.Header("Connection", "keep-alive")
|
||||||
@@ -3832,8 +3826,6 @@ func (s *AntigravityGatewayService) handleClaudeStreamingResponse(c *gin.Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
processor := antigravity.NewStreamingProcessor(originalModel)
|
processor := antigravity.NewStreamingProcessor(originalModel)
|
||||||
setupClaudeMaxStreamingHook(c, processor, originalModel, accountID)
|
|
||||||
|
|
||||||
var firstTokenMs *int
|
var firstTokenMs *int
|
||||||
// 使用 Scanner 并限制单行大小,避免 ReadString 无上限导致 OOM
|
// 使用 Scanner 并限制单行大小,避免 ReadString 无上限导致 OOM
|
||||||
scanner := bufio.NewScanner(resp.Body)
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
|
|||||||
Reference in New Issue
Block a user