mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-17 15:20:55 +08:00
- Fall back to schema prompts for Antigravity Claude 5.5 while preserving unrelated request settings. - Normalize unsupported forced tool choices before thinking preparation in direct Claude execution and token-count paths. - Add regression coverage for schema integrity, model boundaries, retries, and final payload rule precedence. Closes: #7000
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package helps
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/thinking"
|
|
"github.com/tidwall/gjson"
|
|
"github.com/tidwall/sjson"
|
|
)
|
|
|
|
// NormalizeClaudeToolChoice downgrades forced tool use on Claude 5.5 to auto.
|
|
// Use the routed upstream model, not the payload model, and run before thinking
|
|
// preparation so forced-mode cleanup cannot discard thinking or signed history.
|
|
// Delegated providers keep their own tool-choice contract. User payload rules
|
|
// must run afterwards and remain authoritative.
|
|
func NormalizeClaudeToolChoice(provider, model string, payload []byte) []byte {
|
|
if provider != "claude" {
|
|
return payload
|
|
}
|
|
model = strings.ToLower(thinking.ParseSuffix(strings.TrimSpace(model)).ModelName)
|
|
if !claude55Model.MatchString(model) {
|
|
return payload
|
|
}
|
|
switch gjson.GetBytes(payload, "tool_choice.type").String() {
|
|
case "any", "tool":
|
|
payload, _ = sjson.SetBytes(payload, "tool_choice.type", "auto")
|
|
payload, _ = sjson.DeleteBytes(payload, "tool_choice.name")
|
|
}
|
|
return payload
|
|
}
|