MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / extractClaudeConfig

Function extractClaudeConfig

internal/thinking/apply.go:509–554  ·  view source on GitHub ↗

extractClaudeConfig extracts thinking configuration from Claude format request body. Claude API format: - thinking.type: "enabled" or "disabled" - thinking.budget_tokens: integer (-1=auto, 0=disabled, >0=budget) Priority: thinking.type="disabled" takes precedence over budget_tokens. When type="ena

(body []byte)

Source from the content-addressed store, hash-verified

507// When type="enabled" without budget_tokens, returns ModeAuto to indicate
508// the user wants thinking enabled but didn't specify a budget.
509func extractClaudeConfig(body []byte) ThinkingConfig {
510 thinkingType := gjson.GetBytes(body, "thinking.type").String()
511 if thinkingType == "disabled" {
512 return ThinkingConfig{Mode: ModeNone, Budget: 0}
513 }
514 if thinkingType == "adaptive" || thinkingType == "auto" {
515 // Claude adaptive thinking uses output_config.effort (low/medium/high/max).
516 // We only treat it as a thinking config when effort is explicitly present;
517 // otherwise we passthrough and let upstream defaults apply.
518 if effort := gjson.GetBytes(body, "output_config.effort"); effort.Exists() && effort.Type == gjson.String {
519 value := strings.ToLower(strings.TrimSpace(effort.String()))
520 if value == "" {
521 return ThinkingConfig{}
522 }
523 switch value {
524 case "none":
525 return ThinkingConfig{Mode: ModeNone, Budget: 0}
526 case "auto":
527 return ThinkingConfig{Mode: ModeAuto, Budget: -1}
528 default:
529 return ThinkingConfig{Mode: ModeLevel, Level: ThinkingLevel(value)}
530 }
531 }
532 return ThinkingConfig{}
533 }
534
535 // Check budget_tokens
536 if budget := gjson.GetBytes(body, "thinking.budget_tokens"); budget.Exists() {
537 value := int(budget.Int())
538 switch value {
539 case 0:
540 return ThinkingConfig{Mode: ModeNone, Budget: 0}
541 case -1:
542 return ThinkingConfig{Mode: ModeAuto, Budget: -1}
543 default:
544 return ThinkingConfig{Mode: ModeBudget, Budget: value}
545 }
546 }
547
548 // If type="enabled" but no budget_tokens, treat as auto (user wants thinking but no budget specified)
549 if thinkingType == "enabled" {
550 return ThinkingConfig{Mode: ModeAuto, Budget: -1}
551 }
552
553 return ThinkingConfig{}
554}
555
556// extractGeminiConfig extracts thinking configuration from Gemini format request body.
557//

Callers 1

extractThinkingConfigFunction · 0.85

Calls 2

ThinkingLevelTypeAlias · 0.85
StringMethod · 0.45

Tested by

no test coverage detected