Add protocol selection to Claude and Codex provider forms referencing CCSwitch
This commit is contained in:
1 parent
bae24cc439
commit
16957decb2
14 files changed
+274
-25
No files matched your search
@@ -46,7 +46,15 @@ type Models struct {
|
||||
Extra map[string]string `json:"extra,omitempty"`
|
||||
}
|
||||
|
||||
// Provider is one upstream Chat Completions endpoint.
|
||||
// Supported upstream protocols (matching CCSwitch format identifiers).
|
||||
const (
|
||||
ProtocolAnthropic = "anthropic"
|
||||
ProtocolOpenAIChat = "openai_chat"
|
||||
ProtocolOpenAIResponses = "openai_responses"
|
||||
ProtocolGeminiNative = "gemini_native"
|
||||
)
|
||||
|
||||
// Provider is one upstream endpoint.
|
||||
type Provider struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -54,6 +62,8 @@ type Provider struct {
|
||||
BaseURL string `json:"base_url"`
|
||||
APIKey string `json:"api_key"`
|
||||
Models Models `json:"models"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
APIFormat string `json:"api_format,omitempty"`
|
||||
EnabledForClaude bool `json:"enabled_for_claude"`
|
||||
EnabledForCodex bool `json:"enabled_for_codex"`
|
||||
Target string `json:"target,omitempty"`
|
||||
@@ -170,6 +180,13 @@ func (c *Config) normalize() {
|
||||
}
|
||||
for i := range c.Providers {
|
||||
c.Providers[i].Models.normalize()
|
||||
if c.Providers[i].Protocol == "" && c.Providers[i].APIFormat != "" {
|
||||
c.Providers[i].Protocol = c.Providers[i].APIFormat
|
||||
}
|
||||
if c.Providers[i].Protocol == "" {
|
||||
c.Providers[i].Protocol = ProtocolOpenAIChat
|
||||
}
|
||||
c.Providers[i].APIFormat = c.Providers[i].Protocol
|
||||
switch c.Providers[i].Target {
|
||||
case TargetClaude, TargetCodex:
|
||||
default:
|
||||
@@ -206,7 +223,7 @@ func (c *Config) clone() *Config {
|
||||
return &out
|
||||
}
|
||||
|
||||
func newProvider(name, preset, baseURL, apiKey string, models Models, target string) (*Provider, error) {
|
||||
func newProvider(name, preset, baseURL, apiKey string, models Models, target string, protocol ...string) (*Provider, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if name == "" {
|
||||
return nil, errors.New("name is required")
|
||||
@@ -231,6 +248,13 @@ func newProvider(name, preset, baseURL, apiKey string, models Models, target str
|
||||
default:
|
||||
return nil, fmt.Errorf("target must be %q or %q", TargetClaude, TargetCodex)
|
||||
}
|
||||
proto := ""
|
||||
if len(protocol) > 0 {
|
||||
proto = strings.TrimSpace(protocol[0])
|
||||
}
|
||||
if proto == "" {
|
||||
proto = ProtocolOpenAIChat
|
||||
}
|
||||
return &Provider{
|
||||
ID: newID("p_"),
|
||||
Name: name,
|
||||
@@ -238,6 +262,8 @@ func newProvider(name, preset, baseURL, apiKey string, models Models, target str
|
||||
BaseURL: strings.TrimRight(baseURL, "/"),
|
||||
APIKey: apiKey,
|
||||
Models: models,
|
||||
Protocol: proto,
|
||||
APIFormat: proto,
|
||||
Target: target,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
}, nil
|
||||
|
||||
Reference in new issue
Block a user