Skip to content

The agent that grows with you

refactor(agent/aux): ruff SIM cleanups; compact vision custom-runtime recovery

Teknium95177359f8c8
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 2df9f7a4788..3dfa8e7032f 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -2316,9 +2316,7 @@ def _endpoint_speaks_anthropic_messages(base_url: str) -> bool:
hostname = base_url_hostname(normalized)
if hostname == "api.anthropic.com":
return True
- if hostname == "api.kimi.com" and "/coding" in normalized:
- return True
- return False
+ return bool(hostname == "api.kimi.com" and "/coding" in normalized)
def _is_specialized_aux_client(client_obj: Any) -> bool:
@@ -3840,25 +3838,24 @@ def _is_payment_error(exc: Exception) -> bool:
return True
err_lower = str(exc).lower()
# Providers sometimes wrap credit errors in 429/403/404 bodies.
- if status in {402, 403, 404, 429, None}:
- if any(kw in err_lower for kw in (
- "credits", "insufficient funds",
- "can only afford", "billing",
- "payment required",
- "out of funds", "run out of funds",
- "balance_depleted", "no usable credits",
- "model_not_supported_on_free_tier",
- "not available on the free tier",
- "requires a subscription", "upgrade for access",
- "upgrade for higher limits", "reached your session usage limit",
- # Daily / monthly / weekly quota exhaustion keywords
- "quota exceeded", "quota_exceeded",
- "too many tokens per day", "daily limit",
- "tokens per day", "daily quota",
- "resource exhausted", # Vertex AI / gRPC quota errors
- "weekly usage limit", "weekly limit", # OpenCode Go weekly subscription cap
- )):
- return True
+ if status in {402, 403, 404, 429, None} and any(kw in err_lower for kw in (
+ "credits", "insufficient funds",
+ "can only afford", "billing",
+ "payment required",
+ "out of funds", "run out of funds",
+ "balance_depleted", "no usable credits",
+ "model_not_supported_on_free_tier",
+ "not available on the free tier",
+ "requires a subscription", "upgrade for access",
+ "upgrade for higher limits", "reached your session usage limit",
+ # Daily / monthly / weekly quota exhaustion keywords
+ "quota exceeded", "quota_exceeded",
+ "too many tokens per day", "daily limit",
+ "tokens per day", "daily quota",
+ "resource exhausted", # Vertex AI / gRPC quota errors
+ "weekly usage limit", "weekly limit", # OpenCode Go weekly subscription cap
+ )):
+ return True
return False
@@ -3994,9 +3991,7 @@ def _is_auth_error(exc: Exception) -> bool:
# — semantically a 401.
if status == 403 and "bad-credentials" in err_lower:
return True
- if "unauthenticated" in err_lower and "bad-credentials" in err_lower:
- return True
- return False
+ return bool("unauthenticated" in err_lower and "bad-credentials" in err_lower)
def _is_unsupported_parameter_error(exc: Exception, param: str) -> bool:
@@ -6533,22 +6528,17 @@ def resolve_vision_provider_client(
rpc_api_key = None
rpc_api_mode = resolved_api_mode
if main_provider == "custom" or main_provider.startswith("custom:"):
- runtime_base_url = runtime.get("base_url")
- if runtime_base_url:
- rpc_base_url = runtime_base_url
- rpc_api_key = runtime.get("api_key") or None
- rpc_api_mode = (
- resolved_api_mode
- or runtime.get("api_mode")
- or None
+ if runtime.get("base_url"):
+ custom_base, custom_key, custom_mode = (
+ runtime.get("base_url"), runtime.get("api_key") or None, runtime.get("api_mode"),
)
else:
# Non-gateway caller: no live runtime recorded.
custom_base, custom_key, custom_mode = _resolve_custom_runtime()
- if custom_base:
- rpc_base_url = custom_base
- rpc_api_key = custom_key
- rpc_api_mode = resolved_api_mode or custom_mode or None
+ if custom_base:
+ rpc_base_url = custom_base
+ rpc_api_key = custom_key
+ rpc_api_mode = resolved_api_mode or custom_mode or None
rpc_client, rpc_model = resolve_provider_client(
main_provider, vision_model,
api_mode=rpc_api_mode,