diff options
Diffstat (limited to 'app/backends/audiocpp.py')
| -rwxr-xr-x | app/backends/audiocpp.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/app/backends/audiocpp.py b/app/backends/audiocpp.py index a8c5568..ee0ee21 100755 --- a/app/backends/audiocpp.py +++ b/app/backends/audiocpp.py @@ -48,6 +48,7 @@ from backends import ( ServerSpec, common, format_launch_hint, + probe, servers, ) from backends.common import ( @@ -1746,14 +1747,14 @@ def build_parser() -> argparse.ArgumentParser: def detect() -> BackendStatus: """Detect how far audio.cpp is set up, plus the command to start it.""" checkout = find_local_checkout() - # Probe the server first: it may be running externally even with no - # local checkout, and the status table should show that. - running = common.server_running(config.AUDIOCPP_API_URL) details: List[str] = [] launch = "" if checkout is None: + # No local checkout: only a remote server can make this usable. + remote = _detect_remote() return BackendStatus("audiocpp", "audio.cpp", installed=False, - configured=False, running=running, + configured=False, running=remote[0], + remote=remote[0], remote_urls=remote[1], details=["not cloned — run setup to clone " "./app/audio.cpp"]) details.append(f"checkout: {checkout}") @@ -1779,10 +1780,32 @@ def detect() -> BackendStatus: details.append("no server.json — run setup to configure models") if specs: launch = format_launch_hint(specs) + managed = servers.manages(specs) + remote_running, remote_urls = _detect_remote(managed) return BackendStatus("audiocpp", "audio.cpp", installed=built, - configured=configured, running=running, + configured=configured, + running=managed or remote_running, details=details, launch_hint=launch, - servers=specs, managed=servers.manages(specs)) + servers=specs, managed=managed, + remote=remote_running, remote_urls=remote_urls) + + +def _detect_remote(managed: bool = False) -> Tuple[bool, dict]: + """Detect an externally-run audiocpp_server at the remote URL. + + Returns ``(running, {spec_name: url})``. The remote URL is probed only + when configured (non-empty); a server answering there is ignored when it + is this tool's own managed server (remote URL == local URL and our pid is + still alive) — that instance is already reported as "[local]". + """ + url = (config.AUDIOCPP_REMOTE_URL or "").strip() + if not url: + return False, {} + if managed and probe.same_endpoint(url, config.AUDIOCPP_API_URL): + return False, {} + if probe.identify_server(url) == probe.IDENTITY_AUDIOCPP: + return True, {"audiocpp": url} + return False, {} configure_actions: List[ConfigureAction] = [ |
