fix: skip unsupported image profile refreshes

This commit is contained in:
2026-07-10 07:34:01 +08:00
parent c79e85e635
commit 135dbc845a
4 changed files with 55 additions and 9 deletions
+24 -7
View File
@@ -24,7 +24,7 @@ from typing import Any
APP_NAME = "codex-retry-gateway-tui"
FALLBACK_VERSION = "0.1.9"
FALLBACK_VERSION = "0.1.10"
DEFAULT_GATEWAY_ADMIN_PATH = "/__codex_retry_gateway"
DEFAULT_GATEWAY_URL = "http://127.0.0.1:4610/__codex_retry_gateway"
DEFAULT_API_URL = DEFAULT_GATEWAY_URL
@@ -2023,6 +2023,17 @@ def open_url(url: str) -> None:
subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def gateway_supports_image_profiles(status_payload: dict[str, Any]) -> bool:
config = status_payload.get("config") if isinstance(status_payload.get("config"), dict) else {}
state = status_payload.get("state") if isinstance(status_payload.get("state"), dict) else {}
paths = status_payload.get("paths") if isinstance(status_payload.get("paths"), dict) else {}
return (
"image_profile_name" in config
or "image_profile_name" in state
or "image_profiles_dir" in paths
)
def fetch_dashboard_snapshot(
gateway_url: str,
status_url: str,
@@ -2033,29 +2044,35 @@ def fetch_dashboard_snapshot(
current_view: str = "overview",
) -> dict[str, Any]:
gateway_root = gateway_admin_url(gateway_url)
status_endpoint = status_url or gateway_status_url(gateway_root)
status_payload, status_error = fetch_optional_payload(status_endpoint, timeout, access_key)
payload = status_payload if isinstance(status_payload, dict) else {}
endpoints = {
"status": status_url or gateway_status_url(gateway_root),
"logs": build_api_url(gateway_root, "/api/logs", {"limit": 200}),
"requests": build_api_url(gateway_root, "/api/requests", {"limit": 200}),
"profiles": build_api_url(gateway_root, "/api/profiles"),
"image_profiles": build_api_url(gateway_root, "/api/image-profiles"),
}
image_profiles_supported = gateway_supports_image_profiles(payload)
if image_profiles_supported:
endpoints["image_profiles"] = build_api_url(gateway_root, "/api/image-profiles")
def fetch_optional(url: str, *, allow_not_found: bool = False) -> tuple[dict[str, Any], str]:
return fetch_optional_payload(url, timeout, access_key, allow_not_found=allow_not_found)
with ThreadPoolExecutor(max_workers=5) as pool:
with ThreadPoolExecutor(max_workers=len(endpoints)) as pool:
futures = {
name: pool.submit(fetch_optional, url, allow_not_found=name == "image_profiles")
for name, url in endpoints.items()
}
status_payload, status_error = futures["status"].result()
logs_payload, logs_error = futures["logs"].result()
requests_payload, requests_error = futures["requests"].result()
profiles_payload, profiles_error = futures["profiles"].result()
image_profiles_payload, image_profiles_error = futures["image_profiles"].result()
if image_profiles_supported:
image_profiles_payload, image_profiles_error = futures["image_profiles"].result()
else:
image_profiles_payload, image_profiles_error = {}, ""
payload = status_payload if isinstance(status_payload, dict) else {}
requests_source = requests_payload if isinstance(requests_payload, dict) else {}
logs_source = logs_payload if isinstance(logs_payload, dict) else {}
profiles_source = profiles_payload if isinstance(profiles_payload, dict) else {}