Skip to content

The agent that grows with you

refactor(auxiliary): registry auth-type table; MiniMax OAuth arm in a topical sibling

Brooklyn Nicholsond61d60d493dc
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index f1db973d12b..5c7a9da8bd4 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -5397,58 +5397,21 @@ def _resolve_registry_branch(req: _ResolveRequest) -> _ResolveResult:
return _resolve_api_key_branch(req, pconfig, resolve_api_key_provider_credentials)
if auth_type == "external_process":
return _resolve_external_process_branch(req, resolve_external_process_provider_credentials(provider))
- if auth_type == "vertex":
- client, final_model = _build_vertex_client(provider, req.model)
- elif auth_type == "aws_sdk":
- client, final_model = _build_bedrock_client(provider, req.model, raw_codex=req.raw_codex)
- elif auth_type == "oauth_minimax":
- # MiniMax OAuth → Anthropic-compatible inference endpoint with a callable bearer
- # (tokens live ~15 min; the Anthropic SDK re-invokes the provider each request).
- try:
- from agent.anthropic_adapter import build_anthropic_client
- from agent.anthropic_credentials import anthropic_route_is_oauth
- from hermes_cli.auth import resolve_minimax_oauth_runtime_credentials
- except ImportError:
- return None, None
- try:
- credentials = resolve_minimax_oauth_runtime_credentials(as_token_provider=True)
- except Exception as exc:
- logger.warning(
- "resolve_provider_client: minimax-oauth runtime resolution failed: %s", exc)
- return None, None
- token_provider = credentials.get("api_key")
- base_url = str(credentials.get("base_url") or "").strip().rstrip("/")
- if not callable(token_provider) or not base_url:
- return None, None
- final_model = _normalize_resolved_model(
- req.model or _get_aux_model_for_provider(provider) or "MiniMax-M3", provider,
- )
- if _aux_probe_active():
- return _AuxProbeClientStub(api_key="", base_url=base_url), final_model
- try:
- real_client = build_anthropic_client(token_provider, base_url)
- except ImportError:
- return None, None
- # OAuth identity only for native api.anthropic.com routes (#114967): MiniMax is a
- # third-party Anthropic-protocol host, so no Claude Code tool-name wire
- # transforms / identity rewrites / response prefix stripping here.
- client = AnthropicAuxiliaryClient(
- real_client, final_model, token_provider, base_url,
- is_oauth=anthropic_route_is_oauth(base_url, token_provider))
- return _route_client(req, client, final_model)
- elif auth_type in {"oauth_device_code", "oauth_external"}:
+ from agent.auxiliary_client_registry import REGISTRY_AUTHTYPE_ARMS
+ arm = REGISTRY_AUTHTYPE_ARMS.get(auth_type)
+ if arm is not None:
+ return arm(req)
+ if auth_type in {"oauth_device_code", "oauth_external"}:
# nous / openai-codex / xai-oauth already returned from their explicit branches.
_log_once_debug(_LOGGED_UNSUPPORTED_OAUTH_KEYS, provider,
"resolve_provider_client: OAuth provider %s not "
"directly supported, try 'auto'", provider)
return None, None
- else:
- # The first occurrence surfaces a real schema-drift bug; per-call retries stay silent.
- _log_once_debug(_LOGGED_UNHANDLED_AUTHTYPE_KEYS, (auth_type, provider),
- "resolve_provider_client: unhandled auth_type %s for %s",
- auth_type, provider)
- return None, None
- return _route_client(req, client, final_model) if client is not None else (None, None)
+ # The first occurrence surfaces a real schema-drift bug; per-call retries stay silent.
+ _log_once_debug(_LOGGED_UNHANDLED_AUTHTYPE_KEYS, (auth_type, provider),
+ "resolve_provider_client: unhandled auth_type %s for %s",
+ auth_type, provider)
+ return None, None
# Explicit providers with a dedicated branch; anything else falls through to named custom
diff --git a/agent/auxiliary_client_minimax.py b/agent/auxiliary_client_minimax.py
new file mode 100644
index 00000000000..447879b94b6
--- /dev/null
+++ b/agent/auxiliary_client_minimax.py
@@ -0,0 +1,60 @@
+"""MiniMax OAuth arm of the auxiliary registry branch (``auth_type == "oauth_minimax"``).
+
+MiniMax OAuth resolves to an Anthropic-compatible inference endpoint with a callable
+bearer: tokens live ~15 minutes and the Anthropic SDK re-invokes the provider on each
+request, so a static string would 401 mid-session. ``is_oauth`` comes from
+``anthropic_route_is_oauth`` — the MiniMax host is a third-party Anthropic-protocol
+endpoint, so the wrapper must NOT carry the native Claude Code OAuth identity (mcp__
+tool-name wire transforms, identity rewrites, response prefix stripping); those are
+api.anthropic.com-only (#114967).
+"""
+from __future__ import annotations
+
+import logging
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from agent.auxiliary_client import _ResolveRequest, _ResolveResult
+
+logger = logging.getLogger(__name__)
+
+
+def resolve_minimax_oauth_client(req: _ResolveRequest) -> _ResolveResult:
+ """``minimax-oauth`` → AnthropicAuxiliaryClient over a callable bearer; (None, None) when absent."""
+ from agent.auxiliary_client import (
+ AnthropicAuxiliaryClient, _AuxProbeClientStub, _aux_probe_active,
+ _get_aux_model_for_provider, _normalize_resolved_model, _route_client,
+ )
+ try:
+ from agent.anthropic_adapter import build_anthropic_client
+ from agent.anthropic_credentials import anthropic_route_is_oauth
+ from hermes_cli.auth import resolve_minimax_oauth_runtime_credentials
+ except ImportError:
+ return None, None
+ try:
+ credentials = resolve_minimax_oauth_runtime_credentials(as_token_provider=True)
+ except Exception as exc:
+ # Deliberate boundary: the resolver contract is "absent → (None, None), never an
+ # exception" (the aux ladder then falls through to its Step-2 chain), so every
+ # failure ends the arm here; exc_info keeps the traceback diagnosable.
+ logger.warning(
+ "resolve_provider_client: minimax-oauth runtime resolution failed: %s", exc,
+ exc_info=True)
+ return None, None
+ token_provider = credentials.get("api_key")
+ base_url = str(credentials.get("base_url") or "").strip().rstrip("/")
+ if not callable(token_provider) or not base_url:
+ return None, None
+ final_model = _normalize_resolved_model(
+ req.model or _get_aux_model_for_provider(req.provider) or "MiniMax-M3", req.provider,
+ )
+ if _aux_probe_active():
+ return _AuxProbeClientStub(api_key="", base_url=base_url), final_model
+ try:
+ real_client = build_anthropic_client(token_provider, base_url)
+ except ImportError:
+ return None, None
+ client = AnthropicAuxiliaryClient(
+ real_client, final_model, token_provider, base_url,
+ is_oauth=anthropic_route_is_oauth(base_url, token_provider))
+ return _route_client(req, client, final_model)
diff --git a/agent/auxiliary_client_registry.py b/agent/auxiliary_client_registry.py
new file mode 100644
index 00000000000..31caa0b0c68
--- /dev/null
+++ b/agent/auxiliary_client_registry.py
@@ -0,0 +1,41 @@
+"""``auth_type`` dispatch table for the auxiliary registry branch.
+
+``_resolve_registry_branch`` in ``agent/auxiliary_client`` routes every
+``PROVIDER_REGISTRY`` provider here on its registered ``auth_type``; this table is the
+registry twin of the facade's ``_EXPLICIT_PROVIDER_BRANCHES``. Arms late-import the
+facade (siblings never form a module-level cycle) so the seam every test patches —
+``agent.auxiliary_client.*`` — is the module production reads.
+"""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Callable, Dict
+
+if TYPE_CHECKING:
+ from agent.auxiliary_client import _ResolveRequest, _ResolveResult
+
+
+def _resolve_vertex_arm(req: _ResolveRequest) -> _ResolveResult:
+ from agent.auxiliary_client import _build_vertex_client, _route_client
+ client, final_model = _build_vertex_client(req.provider, req.model)
+ return _route_client(req, client, final_model) if client is not None else (None, None)
+
+
+def _resolve_bedrock_arm(req: _ResolveRequest) -> _ResolveResult:
+ from agent.auxiliary_client import _build_bedrock_client, _route_client
+ client, final_model = _build_bedrock_client(req.provider, req.model, raw_codex=req.raw_codex)
+ return _route_client(req, client, final_model) if client is not None else (None, None)
+
+
+def _resolve_minimax_oauth_arm(req: _ResolveRequest) -> _ResolveResult:
+ from agent.auxiliary_client_minimax import resolve_minimax_oauth_client
+ return resolve_minimax_oauth_client(req)
+
+
+# ``api_key`` / ``external_process`` arms stay on the facade (they share its credential
+# resolvers); the table maps the auth types whose arms are build-and-route one-liners
+# or topical siblings.
+REGISTRY_AUTHTYPE_ARMS: Dict[str, Callable[[_ResolveRequest], _ResolveResult]] = {
+ "vertex": _resolve_vertex_arm,
+ "aws_sdk": _resolve_bedrock_arm,
+ "oauth_minimax": _resolve_minimax_oauth_arm,
+}
diff --git a/tests/agent/test_auxiliary_client_minimax_oauth.py b/tests/agent/test_auxiliary_client_minimax_oauth.py
index 3bd0d669fa2..bcb8766158d 100644
--- a/tests/agent/test_auxiliary_client_minimax_oauth.py
+++ b/tests/agent/test_auxiliary_client_minimax_oauth.py
@@ -63,7 +63,7 @@ def test_resolve_minimax_oauth_builds_anthropic_wrapper_with_oauth_semantics():
assert client is not None, (
"minimax-oauth must produce a configured client when credentials are "
"present, but the resolver returned (None, None). The oauth_minimax "
- "arm in _resolve_registry_branch is missing."
+ "arm in the registry auth-type dispatch table is missing."
)
assert isinstance(client, AnthropicAuxiliaryClient), (
f"minimax-oauth must build an AnthropicAuxiliaryClient (the inference "