fix(providers): honor Codex proxy config consistently

This commit is contained in:
chengyongru
2026-07-15 20:01:48 +08:00
committed by chengyongru
parent ba86dccc8d
commit 681edfa6f3
6 changed files with 145 additions and 3 deletions
+1
View File
@@ -129,6 +129,7 @@ class ImageGenerationTool(Tool):
"api_base": provider.api_base if provider else None,
"extra_headers": provider.extra_headers if provider else None,
"extra_body": provider.extra_body if provider else None,
"proxy": provider.proxy if provider else None,
}
return cls(**kwargs)
+8 -1
View File
@@ -2687,7 +2687,7 @@ def _set_oauth_provider_as_main(
from nanobot.config.loader import get_config_path, load_config, save_config, set_config_path
resolved_config_path = Path(config_path).expanduser().resolve() if config_path else None
if resolved_config_path is not None:
if resolved_config_path is not None and get_config_path() != resolved_config_path:
set_config_path(resolved_config_path)
console.print(f"[dim]Using config: {resolved_config_path}[/dim]")
@@ -2731,6 +2731,13 @@ def provider_login(
console.print(f"[red]Login not implemented for {spec.label}[/red]")
raise typer.Exit(1)
if config:
from nanobot.config.loader import set_config_path
resolved_config_path = Path(config).expanduser().resolve()
set_config_path(resolved_config_path)
console.print(f"[dim]Using config: {resolved_config_path}[/dim]")
console.print(f"{__logo__} OAuth Login - {spec.label}\n")
handler()
if set_main or model:
+9 -2
View File
@@ -187,6 +187,7 @@ class ImageGenerationProvider(ABC):
api_base: str | None = None,
extra_headers: dict[str, str] | None = None,
extra_body: dict[str, Any] | None = None,
proxy: str | None = None,
timeout: float | None = None,
client: httpx.AsyncClient | None = None,
) -> None:
@@ -194,6 +195,7 @@ class ImageGenerationProvider(ABC):
self.api_base = self._resolve_base_url(api_base)
self.extra_headers = extra_headers or {}
self.extra_body = extra_body or {}
self.proxy = proxy or None
self.timeout = timeout if timeout is not None else self.default_timeout
self._client = client
@@ -240,7 +242,11 @@ class ImageGenerationProvider(ABC):
return await client.post(url, headers=headers, json=body)
if self._client is not None:
return await self._client.post(url, headers=headers, json=body)
async with httpx.AsyncClient(timeout=self.timeout) as c:
client_kwargs: dict[str, Any] = {"timeout": self.timeout}
if self.proxy:
client_kwargs["proxy"] = self.proxy
client_kwargs["trust_env"] = False
async with httpx.AsyncClient(**client_kwargs) as c:
return await c.post(url, headers=headers, json=body)
@@ -1233,7 +1239,8 @@ class CodexImageGenerationClient(ImageGenerationProvider):
raise ImageGenerationError(self.missing_key_message)
try:
token = await asyncio.to_thread(get_codex_token)
token_kwargs = {"proxy": self.proxy} if self.proxy else {}
token = await asyncio.to_thread(get_codex_token, **token_kwargs)
except Exception as exc:
raise ImageGenerationError(self.missing_key_message) from exc
if not token or not token.access: