diff --git a/pyproject.toml b/pyproject.toml index 414108a48997a54414122e92ab5f47c1790fedde..d47807b2b90f3941f1603d32b658d3b32bbb92e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "free-claude-code" -version = "6.16.4" +version = "6.18.5" description = "Local proxy connecting coding agents to OpenAI-compatible AI providers" readme = "README.md" license = "AGPL-3.0-only" @@ -17,28 +17,28 @@ dependencies = [ "httpx[socks]>=0.28.1", "httpx2[socks]>=2.7.0,<3", "markdown-it-py>=4.2.0", - "pydantic>=2.13.5", + "pydantic>=2.14.1", "python-dotenv>=1.2.4", "tiktoken>=0.13.0", "python-telegram-bot>=22.8", "discord.py>=2.7.1", - "openai>=3.25.0", + "openai>=3.37.0", "loguru>=0.7.0", - "aiohttp>=3.14.4", + "aiohttp>=3.14.5", "jsonschema>=4.25.0", - "json5>=0.15.0", - "tomlkit>=0.13.3", + "json5>=0.17.3", + "tomlkit>=0.15.2", "google-auth[requests]>=2.56.3", "requests[socks]>=2.34.2", "pystray>=0.19.5; sys_platform == 'win32' or sys_platform == 'darwin'", - "Pillow>=12.0.0; sys_platform == 'win32' or sys_platform == 'darwin'", - "github-copilot-sdk>=1.0.16", + "Pillow>=13.0.0; sys_platform == 'win32' or sys_platform == 'darwin'", + "github-copilot-sdk>=1.0.26", "simplejson>=4.2.0", - "grpcio>=1.84.0", + "grpcio>=1.84.1", "grpcio-tools>=1.81.1", "nvidia-riva-client>=2.26.0", "pyperclip>=1.11.0", - "sqlalchemy>=2.1.3", + "sqlalchemy>=2.1.6", "ruamel-yaml>=0.19.1", ] @@ -55,6 +55,7 @@ fcc-hermes = "free_claude_code.cli.launchers.hermes:launch" fcc-dsh = "free_claude_code.cli.launchers.dsh:launch" fcc-grok = "free_claude_code.cli.launchers.grok:launch" fcc-muse = "free_claude_code.cli.launchers.muse:launch" +fcc-agy = "free_claude_code.cli.launchers.agy:launch" fcc-aider = "free_claude_code.cli.launchers.aider:launch" [project.gui-scripts] @@ -63,11 +64,14 @@ fcc-desktop = "free_claude_code.cli.desktop_entrypoint:launch" [project.optional-dependencies] voice_local = [ "torch>=2.14.1", - "transformers>=5.19.0", + "transformers>=5.20.2", "accelerate>=1.15.0", "librosa>=1.0.0", ] +[tool.hatch.build] +artifacts = ["src/free_claude_code/assets/macos/fcc-desktop-*"] + [tool.hatch.build.targets.wheel] packages = ["src/free_claude_code"] @@ -76,7 +80,7 @@ packages = ["src/free_claude_code"] "scripts/update/fcc-update.cmd" = "fcc-update.cmd" [tool.uv] -required-version = ">=0.12.13" +required-version = ">=0.13.6" cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true } }] [tool.uv.sources] @@ -92,10 +96,10 @@ dev = [ "pytest>=9.1.1", "pytest-asyncio>=1.4.0", "pytest-cov>=7.1.0", - "ty>=0.0.84", - "ruff>=0.16.10", + "ty>=0.0.91", + "ruff>=0.17.2", "pytest-xdist>=3.8.0", - "pytest-playwright>=0.9.0", + "pytest-playwright>=0.10.0", "pyyaml>=6.0.3", "pytest-split>=0.11.0", ] diff --git a/src/free_claude_code/api/admin_routes.py b/src/free_claude_code/api/admin_routes.py index f1383e9b5cd59068e4dac7b7a5348bcbc9fc6943..47625fbfd3ecc0ec2ec318b1ae7fd32fe48a820c 100644 --- a/src/free_claude_code/api/admin_routes.py +++ b/src/free_claude_code/api/admin_routes.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Awaitable, Callable, Mapping from pathlib import Path +from time import perf_counter import httpx from fastapi import ( @@ -300,6 +301,33 @@ async def vscode_chat_status( return await _integration_response(services.admin.vscode_chat_status) +@router.get("/admin/api/integrations/antigravity") +async def antigravity_status( + request: Request, + services: ApiServices = Depends(get_services), +): + require_loopback_admin(request) + return await _integration_response(services.admin.antigravity_status) + + +@router.post("/admin/api/integrations/antigravity/connect") +async def connect_antigravity( + request: Request, + services: ApiServices = Depends(get_services), +): + require_loopback_admin(request) + return await _integration_response(services.admin.connect_antigravity) + + +@router.post("/admin/api/integrations/antigravity/disconnect") +async def disconnect_antigravity( + request: Request, + services: ApiServices = Depends(get_services), +): + require_loopback_admin(request) + return await _integration_response(services.admin.disconnect_antigravity) + + @router.post("/admin/api/integrations/vscode-chat/connect") async def connect_vscode_chat( request: Request, @@ -551,9 +579,13 @@ async def _check_local_provider( "status": "missing_url", "label": "Missing URL", "base_url": base_url, + "probe_path": path, + "latency_ms": None, + "error_type": None, } url = f"{clean_url}{path}" + started = perf_counter() try: async with httpx.AsyncClient(timeout=1.5) as client: response = await client.get(url) @@ -564,6 +596,9 @@ async def _check_local_provider( "label": "Reachable" if ok else "Offline", "base_url": base_url, "status_code": response.status_code, + "probe_path": path, + "latency_ms": round((perf_counter() - started) * 1000, 2), + "error_type": None if ok else "http_error", } except Exception as exc: logger.debug( @@ -571,15 +606,40 @@ async def _check_local_provider( provider_id, type(exc).__name__, ) + error_type, message = _local_provider_failure(exc) return { "provider_id": provider_id, "status": "offline", "label": "Offline", "base_url": base_url, - "message": _LOCAL_PROVIDER_CHECK_FAILURE_MESSAGE, + "message": message, + "probe_path": path, + "latency_ms": round((perf_counter() - started) * 1000, 2), + "error_type": error_type, } +def _local_provider_failure(exc: Exception) -> tuple[str, str]: + if isinstance(exc, httpx.TimeoutException): + return ( + "timeout", + "The local provider availability check timed out. Check that its server is responsive and retry.", + ) + if isinstance(exc, (httpx.ConnectError, httpx.ProxyError)): + return "connection_error", _LOCAL_PROVIDER_CHECK_FAILURE_MESSAGE + if isinstance(exc, (httpx.InvalidURL, httpx.UnsupportedProtocol)): + return ( + "invalid_url", + "Check the local provider's HTTP or HTTPS base URL and port.", + ) + if isinstance(exc, httpx.RequestError): + return ( + "transport_error", + "The connection ended before the availability check completed. Retry and check the local server logs.", + ) + return "unexpected_error", _LOCAL_PROVIDER_CHECK_FAILURE_MESSAGE + + def _require_connected_account_provider(provider_id: str) -> None: descriptor = PROVIDER_CATALOG.get(provider_id) if ( diff --git a/src/free_claude_code/api/admin_static/admin.css b/src/free_claude_code/api/admin_static/admin.css index 08e7a1d4fbf2192281b6c85b969a52d82230fc64..f65e6f3dfc5b101ab2b653589e0f851e2dfeb579 100644 --- a/src/free_claude_code/api/admin_static/admin.css +++ b/src/free_claude_code/api/admin_static/admin.css @@ -361,7 +361,8 @@ button.startup-busy::before, .provider-dialog .field-grid { grid-template-columns: minmax(0, 1fr); } .provider-dialog .field.advanced-field { display: flex; } .provider-dialog .provider-actions:not(:empty), -.provider-dialog .provider-check-result:not([hidden]) { margin-bottom: 20px; } +.provider-dialog .provider-check-result:not([hidden]), +.provider-dialog .provider-availability-result:not([hidden]) { margin-bottom: 20px; } .provider-dialog .message-area:empty { display: none; } .provider-dialog-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; } @@ -411,24 +412,28 @@ button.startup-busy::before, overflow-wrap: anywhere; } -.provider-check-result { +.provider-check-result, +.provider-availability-result { color: var(--muted); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; } -.provider-check-result.ok { +.provider-check-result.ok, +.provider-availability-result.ok { color: var(--ok); } -.provider-check-result.error { +.provider-check-result.error, +.provider-availability-result.error { color: var(--error); } .provider-meta.error { color: var(--error); } -.provider-check-result.checking { +.provider-check-result.checking, +.provider-availability-result.checking { color: var(--info); } diff --git a/src/free_claude_code/api/admin_static/admin.js b/src/free_claude_code/api/admin_static/admin.js index 1e08faf85ce1fff5c87ff000b63983c9b0fbcad3..0236074c308fc29f668148fe3480a09358bd6efd 100644 --- a/src/free_claude_code/api/admin_static/admin.js +++ b/src/free_claude_code/api/admin_static/admin.js @@ -19,7 +19,7 @@ const state = { startupRequest: null, startupTimer: null, startupAgain: false, - codeCatalogRetry: false, + configRequest: 0, modelOptionsRequest: 0, activeView: viewFromLocation(), }; @@ -142,6 +142,7 @@ function renderStartup() { renderProviderCheckResult(provider.provider_id); }); renderClaudeIntegration(); + renderAntigravityIntegration(); renderVSCodeChatIntegration(); renderJetBrainsIntegration(); renderCodexIntegration(); @@ -177,8 +178,8 @@ async function refreshStartup() { const changed = !previous || previous.instance_id !== result.instance_id || JSON.stringify(previous.startup) !== JSON.stringify(current); if (changed) void hydrateModelOptions(); - if (changed || state.codeCatalogRetry) state.codeCatalogRetry = await window.CodeSessions?.refresh(result) === false; - pending = state.codeCatalogRetry || current.catalog === "starting" || current.catalog_file === "starting" || + if (changed) void window.CodeSessions?.refresh(result); + pending = current.catalog === "starting" || current.catalog_file === "starting" || current.code?.state === "starting" || current.messaging?.state === "starting" || Object.values(current.integrations || {}).some((update) => update.state === "starting") || Object.values(current.providers || {}).includes("starting"); @@ -209,11 +210,13 @@ window.addEventListener("pagehide", () => { }); async function load({ providersOnly = false } = {}) { + const request = ++state.configRequest; state.localStatusRequest = null; state.startupRequest?.controller.abort(); state.startupRequest = null; showMessage("Loading admin config"); const config = await api("/admin/api/config"); + if (request !== state.configRequest) return; config.custom_providers ||= []; config.provider_status.push(...config.custom_providers.map((provider) => ({ ...provider, kind: "custom", status: "configured", settings_keys: [], missing_configuration_keys: [] }))); state.config = config; @@ -229,11 +232,10 @@ async function load({ providersOnly = false } = {}) { byId("configPath").textContent = config.paths.managed; void refreshLocalStatus(config); void refreshStartup(); - await Promise.all([ - refreshConnectedAccounts(), - hydrateModelOptions(), - providersOnly ? window.CodeSessions.refresh() : window.CodeSessions.initialize(api), - ]); + void refreshConnectedAccounts(); + void hydrateModelOptions(); + if (providersOnly) void window.CodeSessions.refresh(); + else window.CodeSessions.initialize(api); if (state.config !== config) return; updateDirtyState(); showMessage(""); @@ -265,7 +267,7 @@ function setActiveView(viewId, { scroll = false } = {}) { state.activeView = activeView.id; byId("pageTitle").textContent = activeView.title; renderStartup(); - if (activeView.id === "code") state.codeCatalogRetry = true; + if (activeView.id === "code") void window.CodeSessions.refresh(); void refreshStartup(); const sessionActive = activeView.id === "code"; document.querySelector(".app-shell").classList.toggle("session-active", sessionActive); @@ -295,6 +297,7 @@ function setActiveView(viewId, { scroll = false } = {}) { if (activeView.id === "code") window.CodeSessions.activate(window.location.pathname); else window.CodeSessions.deactivate(); if (activeView.id === "integrations") { + refreshAntigravityIntegration(); refreshClaudeIntegration(); refreshClaudeOnboarding(); refreshVSCodeChatIntegration(); @@ -407,6 +410,10 @@ function updateProviderCard(provider) { result.className = "provider-check-result"; result.dataset.providerCheckResult = provider.provider_id; result.hidden = true; + const availability = document.createElement("span"); + availability.className = "provider-availability-result"; + availability.dataset.providerAvailabilityResult = provider.provider_id; + availability.hidden = true; const actions = document.createElement("div"); actions.className = "provider-actions"; if (oauth) populateConnectedAccountActions(provider, status, actions); @@ -418,7 +425,7 @@ function updateProviderCard(provider) { settings.setAttribute("aria-controls", "providerDialog"); actions.appendChild(settings); } - card.replaceChildren(title, meta, result, actions); + card.replaceChildren(title, meta, result, availability, actions); const next = [...grid.children].find((other) => other !== card && connectedAccountName(provider).localeCompare(providerDisplayName(other.dataset.provider), "en", { sensitivity: "base" }) < 0); if (card.parentElement !== grid || card.nextElementSibling !== (next || null)) grid.insertBefore(card, next || null); @@ -489,6 +496,7 @@ async function openCustomProviderDialog(providerId = null) { byId("providerDialogTitle").textContent = providerId ? provider.display_name : "Add provider"; byId("providerMessage").textContent = ""; byId("providerDialogCheck").hidden = true; + renderProviderCheckMessage(byId("providerDialogAvailability"), null); const fields = byId("providerFields"); fields.replaceChildren(); const formats = (state.config.custom_reasoning_formats || {})[provider.api_format] || ["provider_default"]; @@ -553,10 +561,8 @@ function renderProviderDialogActions(provider) { actions.appendChild(button); } const check = oauth ? null : providerCheckResult(provider.provider_id); - const result = byId("providerDialogCheck"); - result.className = `provider-check-result ${check?.status || ""}`; - result.textContent = check?.message || ""; - result.hidden = !check?.message; + renderProviderCheckMessage(byId("providerDialogCheck"), check); + renderProviderCheckMessage(byId("providerDialogAvailability"), check?.availability); byId("saveProvider").hidden = !provider.settings_keys?.length; renderStartup(); } @@ -779,14 +785,22 @@ function providerCheckResult(providerId) { // An explicit check takes precedence over background discovery and reachability. if (check?.source === "manual") return check; const discovery = state.startup?.startup?.providers?.[providerId]; - if (discovery === "starting") return { status: "checking", message: "Checking models…" }; - if (discovery === "failed") { - return { status: "error", message: "Could not load models. Check the provider's settings and retry." }; - } - if (discovery === "ready") { - return { status: "ok", message: modelCountMessage(state.startup.cached_models[providerId]?.length || 0) }; + let result; + if (discovery === "starting") { + result = { status: "checking", message: "Checking models…" }; + } else if (discovery === "failed") { + result = { status: "error", message: state.startup.startup.provider_errors?.[providerId] || "Could not load models. Check the provider's settings and retry." }; + } else if (discovery === "ready") { + result = { status: "ok", message: modelCountMessage(state.startup.cached_models[providerId]?.length || 0) }; + } else if (discovery === "unavailable") { + return { + status: "", + message: "Local server unavailable", + availability: check ? { ...check, status: "" } : undefined, + }; } - return check; + // Model discovery and endpoint reachability are separate observations. + return result ? { ...result, availability: check } : check; } function updateProviderCheckResult(providerId, status, message, source = "manual") { @@ -794,8 +808,17 @@ function updateProviderCheckResult(providerId, status, message, source = "manual renderProviderCheckResult(providerId); } +function renderProviderCheckMessage(element, check) { + for (const status of ["ok", "error", "checking"]) { + element.classList.toggle(status, check?.status === status); + } + element.textContent = check?.message || ""; + element.hidden = !check?.message; +} + function renderProviderCheckResult(providerId) { - const { status = "", message = "" } = providerCheckResult(providerId) || {}; + const check = providerCheckResult(providerId); + const { status = "" } = check || {}; const card = document.querySelector(`[data-provider="${providerId}"]`); if (!card) return; const provider = connectedAccountDescriptor(providerId); @@ -810,15 +833,11 @@ function renderProviderCheckResult(providerId) { if (account?.state === "error") meta.classList.add("error"); return; } - const result = card.querySelector(".provider-check-result"); - result.className = `provider-check-result ${status}`; - result.textContent = message; - result.hidden = !message; + renderProviderCheckMessage(card.querySelector(".provider-check-result"), check); + renderProviderCheckMessage(card.querySelector(".provider-availability-result"), check?.availability); if (state.providerId === providerId) { - const modalResult = byId("providerDialogCheck"); - modalResult.className = result.className; - modalResult.textContent = message; - modalResult.hidden = !message; + renderProviderCheckMessage(byId("providerDialogCheck"), check); + renderProviderCheckMessage(byId("providerDialogAvailability"), check?.availability); } } @@ -1544,7 +1563,7 @@ async function showRestartNotice() { async function restoreSavedProvider(providerId, checks) { if (!connectedAccountDescriptor(providerId)) return; await openProviderDialog(providerId); - showCredentialErrors(checks); + showCredentialErrors(checks.map((check) => ({ ...check, message: `Key saved. ${check.message}` }))); byId("providerMessage").textContent = "Saved. Some keys could not be verified."; byId("providerMessage").className = "message-area warn"; } @@ -1598,7 +1617,7 @@ async function apply(providerId = null, customAction = null) { applied = true; const warningChecks = checks.filter((check) => check.status === "unverified"); const warnings = warningChecks.map((check) => - `${state.fields.get(check.key)?.label || "API keys"}, Key ${check.index + 1}: ${check.message}` + `${state.fields.get(check.key)?.label || "API keys"}, Key ${check.index + 1}: Key saved. ${check.message}` ); const savedProviderId = warnings.length && providerId && mutation?.action !== "delete" ? result.custom_provider_id || providerId : null; if (providerId && !savedProviderId) byId("providerDialog").close(); @@ -1653,8 +1672,14 @@ async function refreshLocalStatus(config) { const provider = await api(`/admin/api/providers/${providerId}/local-status`); if (state.localStatusRequest !== request || !request.providerIds.has(providerId)) return; if (provider.status === "missing_url") return; + const diagnostics = []; + if (provider.probe_path) diagnostics.push(`GET ${provider.probe_path}`); + if (typeof provider.latency_ms === "number" && Number.isFinite(provider.latency_ms)) { + diagnostics.push(`${provider.latency_ms} ms`); + } + const suffix = diagnostics.length ? ` (${diagnostics.join(", ")})` : ""; if (provider.status === "reachable") { - updateProviderCheckResult(providerId, "ok", `Reachable: ${provider.base_url}`, "availability"); + updateProviderCheckResult(providerId, "ok", `Reachable: ${provider.base_url}${suffix}`, "availability"); return; } const detail = provider.message @@ -1662,7 +1687,7 @@ async function refreshLocalStatus(config) { : provider.status_code ? `${provider.base_url} returned HTTP ${provider.status_code}` : "The local provider did not respond."; - updateProviderCheckResult(providerId, "error", `Unavailable: ${detail}`, "availability"); + updateProviderCheckResult(providerId, "error", `Unavailable: ${detail}${suffix}`, "availability"); } catch { if (state.localStatusRequest !== request || !request.providerIds.has(providerId)) return; updateProviderCheckResult(providerId, "error", "Availability check failed. Use Test to retry.", "availability"); @@ -1693,7 +1718,7 @@ async function testProvider(providerId, button) { "ok", modelCountMessage(result.models.length), ); - await hydrateModelOptions(); + void hydrateModelOptions(); } else { updateProviderCheckResult( providerId, @@ -1733,7 +1758,7 @@ async function loadModelOptions(refresh = false) { method: refresh ? "POST" : "GET", }); if (request === state.modelOptionsRequest && config === state.config) { state.modelLabels = new Map(Object.entries(result.model_labels || {})); setModelOptions(result.models); } - if (refresh && window.CodeSessions) await window.CodeSessions.refresh(); + if (refresh && window.CodeSessions) void window.CodeSessions.refresh(); return result; } @@ -2077,6 +2102,112 @@ claudeIntegrationDialog.addEventListener("click", (event) => { } }); +const antigravityIntegrationDialog = byId("antigravityIntegrationDialog"); +const antigravityIntegration = { connected: null, canDisconnect: false, disconnecting: false, busy: false, paths: null }; +const antigravityIntegrationPath = "/admin/api/integrations/antigravity"; + +function renderAntigravityIntegration() { + const { connected, canDisconnect, disconnecting, busy, paths } = antigravityIntegration; + const action = connected ? "Disconnect" : "Connect"; + byId("openAntigravityIntegration").textContent = busy ? "Loading…" : connected === null ? "Retry" : action; + byId("openAntigravityIntegration").disabled = busy; + byId("openAntigravityIntegration").setAttribute("aria-busy", String(busy)); + byId("openAntigravityIntegration").className = connected && !busy ? "danger-button" : "primary-button"; + byId("disconnectAntigravityIntegration").hidden = connected !== false || !canDisconnect; + byId("disconnectAntigravityIntegration").disabled = busy; + byId("confirmAntigravityIntegration").textContent = busy ? "Saving…" : disconnecting ? "Disconnect" : "Connect"; + byId("confirmAntigravityIntegration").disabled = busy || connected === null; + byId("confirmAntigravityIntegration").className = disconnecting ? "danger-button" : "primary-button"; + byId("antigravityIntegrationDescription").textContent = disconnecting + ? connected + ? "Restore Antigravity CLI's previous provider and remove FCC's models. Running sessions can continue. Connect again before your next fcc-agy launch." + : "Remove FCC's saved connection and models. Keep your current Antigravity CLI provider." + : "Switch Antigravity CLI to the Gemini API provider and add FCC's models. Then launch with fcc-agy."; + const files = byId("antigravityIntegrationFiles"); + files.replaceChildren(); + for (const path of Object.values(paths || {})) { + const item = document.createElement("li"); + const code = document.createElement("code"); + code.textContent = path; + item.appendChild(code); + files.appendChild(item); + } +} + +async function refreshAntigravityIntegration() { + const request = beginIntegrationCheck(antigravityIntegration); + if (!request) return; + integrationMessage("antigravityIntegrationMessage", ""); + renderAntigravityIntegration(); + try { + const result = await api(antigravityIntegrationPath); + if (!currentIntegrationCheck(antigravityIntegration, request)) return; + antigravityIntegration.connected = result.connected; + antigravityIntegration.canDisconnect = result.can_disconnect; + antigravityIntegration.paths = result.paths; + } catch (error) { + if (!currentIntegrationCheck(antigravityIntegration, request)) return; + antigravityIntegration.connected = null; + integrationMessage("antigravityIntegrationMessage", error.message, true); + } finally { + finishIntegrationCheck(antigravityIntegration, request, renderAntigravityIntegration); + } +} + +function openAntigravityIntegration(disconnect) { + antigravityIntegration.disconnecting = disconnect; + renderAntigravityIntegration(); + integrationMessage("antigravityIntegrationDialogMessage", ""); + antigravityIntegrationDialog.showModal(); +} + +byId("openAntigravityIntegration").addEventListener("click", () => { + if (antigravityIntegration.connected === null) { + void refreshAntigravityIntegration(); + return; + } + openAntigravityIntegration(antigravityIntegration.connected); +}); +byId("disconnectAntigravityIntegration").addEventListener("click", () => openAntigravityIntegration(true)); +byId("confirmAntigravityIntegration").addEventListener("click", async () => { + if (byId("confirmAntigravityIntegration").disabled) return; + const disconnect = antigravityIntegration.disconnecting; + const config = state.config; + let failed = false; + antigravityIntegration.busy = true; + renderAntigravityIntegration(); + integrationMessage("antigravityIntegrationDialogMessage", ""); + integrationMessage("antigravityIntegrationMessage", ""); + try { + const result = await api(`${antigravityIntegrationPath}/${disconnect ? "disconnect" : "connect"}`, { method: "POST" }); + if (config !== state.config) return; + antigravityIntegration.connected = result.connected; + antigravityIntegration.canDisconnect = result.can_disconnect; + antigravityIntegration.paths = result.paths; + antigravityIntegrationDialog.close(); + integrationMessage("antigravityIntegrationMessage", disconnect + ? "Disconnected. FCC's connection removed." + : "Connected. Launch Antigravity CLI with fcc-agy."); + } catch (error) { + if (config !== state.config) return; + failed = true; + integrationMessage("antigravityIntegrationDialogMessage", error.message, true); + integrationMessage("antigravityIntegrationMessage", error.message, true); + } finally { + antigravityIntegration.busy = false; + renderAntigravityIntegration(); + if (failed || config !== state.config) void refreshAntigravityIntegration(); + } +}); +byId("closeAntigravityIntegration").addEventListener("click", () => antigravityIntegrationDialog.close()); +antigravityIntegrationDialog.addEventListener("click", (event) => { + if (event.target !== antigravityIntegrationDialog) return; + const bounds = antigravityIntegrationDialog.getBoundingClientRect(); + if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) { + antigravityIntegrationDialog.close(); + } +}); + const vscodeChatIntegrationDialog = byId("vscodeChatIntegrationDialog"); const vscodeChatIntegration = { connected: null, busy: false, paths: null, update: null }; const vscodeChatIntegrationPath = "/admin/api/integrations/vscode-chat"; diff --git a/src/free_claude_code/api/admin_static/code_sessions.js b/src/free_claude_code/api/admin_static/code_sessions.js index a4c8fe4d47e4fb78cb8145acf61ed23d76042e95..c020fb7d94e51e9300b4565ae5863a1e9e8dbabd 100644 --- a/src/free_claude_code/api/admin_static/code_sessions.js +++ b/src/free_claude_code/api/admin_static/code_sessions.js @@ -14,9 +14,15 @@ catalogLoaded = false, catalogPhase = "starting", catalogVersion = null, + catalogTarget = null, + catalogProviders = {}, catalogInstance = null, catalogRequest = 0, settingsPending = false; + let catalogFlight = null, + catalogAgain = false, + catalogRetryTimer = null, + catalogController = null; let visibleIds = [], query = "", libraryToken = 0, @@ -364,32 +370,60 @@ record.nextBefore = data.next_before; render(!before && outputChanged); } - function olderCatalog(candidate) { - return candidate && catalogVersion && (candidate.generation_id < catalogVersion.generation_id || - (candidate.generation_id === catalogVersion.generation_id && candidate.catalog_revision < catalogVersion.catalog_revision)); + function olderCatalog(candidate, version = catalogTarget) { + return candidate && version && (candidate.generation_id < version.generation_id || + (candidate.generation_id === version.generation_id && candidate.catalog_revision < version.catalog_revision)); } - async function bootstrap() { + async function readBootstrap() { const token = syncToken; const request = ++catalogRequest; + const controller = new AbortController(); + catalogController = controller; try { - const data = await api(`${base}/bootstrap`); - if (request !== catalogRequest || token !== syncToken || (epoch && data.epoch !== epoch) || olderCatalog(data.startup)) return false; + const data = await api(`${base}/bootstrap`, { signal: controller.signal }); + if (request !== catalogRequest || token !== syncToken || (epoch && data.epoch !== epoch) || olderCatalog(data.startup) || olderCatalog(data.startup, catalogVersion)) return false; if (data.startup) catalogVersion = data.startup; available = data.available; catalogPhase = data.startup?.catalog || "ready"; - if (catalogPhase === "ready" || !catalogLoaded) { - catalog = data.models; - harnesses = data.harnesses; - } - if (catalogPhase === "ready") catalogLoaded = true; + catalogProviders = data.startup?.providers || {}; + catalog = data.models; + harnesses = data.harnesses; + catalogLoaded = true; availabilityNotice = data.message || ""; return true; } catch (error) { - if (request === catalogRequest && token === syncToken) { + if (error.name !== "AbortError" && request === catalogRequest && token === syncToken) { availabilityNotice = error.message; if (!catalogLoaded) catalogPhase = "failed"; } - throw error; + return false; + } finally { + if (catalogController === controller) catalogController = null; + } + } + + async function bootstrap() { + if (!api || document.hidden) return false; + catalogAgain = true; + clearTimeout(catalogRetryTimer); + catalogRetryTimer = null; + if (catalogFlight) return catalogFlight; + catalogFlight = (async () => { + while (catalogAgain && !document.hidden) { + catalogAgain = false; + const refreshed = await readBootstrap(); + render(); + if (!refreshed && !catalogAgain) { + if (!document.hidden) catalogRetryTimer = setTimeout(() => void bootstrap(), 500); + return false; + } + } + return true; + })(); + try { + return await catalogFlight; + } finally { + catalogFlight = null; } } @@ -402,6 +436,7 @@ if (epoch !== readyData.epoch) { if (epoch) { catalogVersion = null; + catalogTarget = null; catalogLoaded = false; catalogPhase = "starting"; } @@ -429,7 +464,7 @@ for (const summary of readyData.sessions) merge({ ...summary, cursor: readyData.cursor }); render(); - void bootstrap().then(() => render()).catch(() => render()); + void bootstrap(); try { const results = await Promise.allSettled([ list(), @@ -479,17 +514,12 @@ source.addEventListener(type, (event) => { if (feed === source) receive(type, event); }); - const disconnected = async () => { + const disconnected = () => { if (feed !== source) return; restart(); // A stopped store cannot open its event feed. Read its availability // so that the retry screen can explain why it is unavailable. - try { - await bootstrap(); - render(); - } catch { - /* The scheduled connection retries the reads. */ - } + void bootstrap(); }; source.addEventListener("feed.resync_required", disconnected); source.onerror = disconnected; @@ -591,11 +621,7 @@ if (selected === id) notice = error.message; } if (error.status === 400 || error.status === 409) { - try { - await bootstrap(); - } catch (failure) { - restart(failure.message); - } + await bootstrap(); } } finally { sends.delete(id); @@ -837,7 +863,9 @@ if (providerDraft) return "Choose a model for the selected provider."; if (!catalogLoaded) return catalogPhase === "starting" ? "Models are loading…" : "Model list unavailable."; const model = catalog.find((model) => model.id === record.session.model); - if (!model) return "Selected model is unavailable. Choose another model."; + if (!model) return catalogProviders[record.session.provider_id] === "starting" + ? "Models for the selected provider are loading…" + : "Selected model is unavailable. Choose another model."; if ( record.session.reasoning_effort && !model.reasoning_efforts.includes(record.session.reasoning_effort) @@ -846,6 +874,12 @@ return ""; } + function selectionLoading(record) { + if (!catalogLoaded) return catalogPhase === "starting"; + return !!record?.session && !catalog.some((model) => model.id === record.session.model) && + catalogProviders[record.session.provider_id] === "starting"; + } + function remove() { const record = records.get(selected), id = selected, @@ -1241,8 +1275,8 @@ stop.hidden = !isBusy; stop.disabled = !connected || record?.run?.stop_requested; send.textContent = saved(selected).pending ? "Retry Send" : "Send"; - send.classList.toggle("startup-busy", !catalogLoaded && catalogPhase === "starting"); - send.setAttribute("aria-busy", String(!catalogLoaded && catalogPhase === "starting")); + send.classList.toggle("startup-busy", selectionLoading(record)); + send.setAttribute("aria-busy", String(selectionLoading(record))); send.disabled = !ready(record) || !available || @@ -1268,12 +1302,12 @@ record.session?.status === "deleting" || isBusy || pending(record); - const disabled = + const sessionDisabled = !ready(record) || isBusy || pending(record) || - settingsPending || - !catalogLoaded; + settingsPending; + const disabled = sessionDisabled || !catalogLoaded || !catalog.length; const provider = providerDraft?.provider || record?.session?.provider_id || ""; if (modelControl.group.dataset.provider !== provider) { @@ -1298,7 +1332,7 @@ ); harnessControl.select.disabled = true; modeControl.select.value = record?.session?.mode || "config"; - modeControl.select.disabled = disabled; + modeControl.select.disabled = sessionDisabled; const model = catalog.find((model) => model.id === record?.session?.model), effort = record?.session?.reasoning_effort || @@ -1661,6 +1695,18 @@ dismissDialog(); } window.addEventListener("pagehide", deactivate); + function pauseCatalog() { + clearTimeout(catalogRetryTimer); + catalogRetryTimer = null; + catalogAgain = false; + ++catalogRequest; + catalogController?.abort(); + } + window.addEventListener("pagehide", pauseCatalog); + document.addEventListener("visibilitychange", () => { + if (document.hidden) pauseCatalog(); + else void bootstrap(); + }); window.CodeSessions = { setProviderNames(providers) { providerNames = new Map(providers.map((provider) => [provider.provider_id, provider.display_name])); @@ -1675,18 +1721,15 @@ async refresh(status) { if (!api) return false; if (status?.startup) { - if (catalogInstance !== status.instance_id) catalogVersion = null; + if (catalogInstance !== status.instance_id) { + catalogTarget = null; + catalogVersion = null; + ++catalogRequest; + } catalogInstance = status.instance_id; - if (!olderCatalog(status.startup)) catalogVersion = status.startup; - } - try { - const refreshed = await bootstrap(); - render(); - return refreshed; - } catch { - render(); - return false; + if (!olderCatalog(status.startup)) catalogTarget = status.startup; } + return bootstrap(); }, }; document.addEventListener("pointerdown", (event) => { diff --git a/src/free_claude_code/api/admin_static/index.html b/src/free_claude_code/api/admin_static/index.html index c8a3fe235e53959f20be0e024d5b27f863b231e0..00814ea9f46b32140f3648dbe8c73ae32a8e6e6c 100644 --- a/src/free_claude_code/api/admin_static/index.html +++ b/src/free_claude_code/api/admin_static/index.html @@ -65,6 +65,32 @@