fix: resolve Codex provider bugs and simplify implementation

This commit is contained in:
Re-bin
2026-02-16 11:43:36 +00:00
parent 9e5f7348fe
commit 1ce586e9f5
5 changed files with 65 additions and 52 deletions

View File

@@ -192,7 +192,7 @@ class ProvidersConfig(BaseModel):
moonshot: ProviderConfig = Field(default_factory=ProviderConfig)
minimax: ProviderConfig = Field(default_factory=ProviderConfig)
aihubmix: ProviderConfig = Field(default_factory=ProviderConfig) # AiHubMix API gateway
openai_codex: ProviderConfig = Field(default_factory=ProviderConfig) # OpenAI Codex (OAuth) # AiHubMix API gateway
openai_codex: ProviderConfig = Field(default_factory=ProviderConfig) # OpenAI Codex (OAuth)
class GatewayConfig(BaseModel):
@@ -252,19 +252,19 @@ class Config(BaseSettings):
model_lower = (model or self.agents.defaults.model).lower()
# Match by keyword (order follows PROVIDERS registry)
# Note: OAuth providers don't require api_key, so we check is_oauth flag
for spec in PROVIDERS:
p = getattr(self.providers, spec.name, None)
if p and any(kw in model_lower for kw in spec.keywords):
# OAuth providers don't need api_key
if spec.is_oauth or p.api_key:
return p, spec.name
# Fallback: gateways first, then others (follows registry order)
# OAuth providers are also valid fallbacks
# OAuth providers are NOT valid fallbacks — they require explicit model selection
for spec in PROVIDERS:
if spec.is_oauth:
continue
p = getattr(self.providers, spec.name, None)
if p and (spec.is_oauth or p.api_key):
if p and p.api_key:
return p, spec.name
return None, None