Hand out the right opencode command: the API's public URL, and setup uses the install script
install-newt now asks for the API's public URL first (--api-url) and records it; it names the Pangolin resource and refuses an endpoint on the same host. expose-dashboard records only that the dashboard is public. One rule (opencode.client_targets) decides which opencode-install.sh commands are shown -- local only without a tunnel; internet and local with one; internet only once the dashboard is public -- and setup's closing message, `llmhost opencode-config` and the dashboard's Connect dialog all use it. Setup's offer to install opencode now goes through opencode-install.sh --install-only, a new mode that only installs opencode; this machine's own provider is still configured by llm-host, which keeps it in sync on every switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c8b70afdbf
commit
3e9ebeed42
10 changed files with 266 additions and 109 deletions
|
|
@ -417,42 +417,8 @@ class Sampler:
|
|||
threading.Thread(target=fn, args=("model",), daemon=True).start()
|
||||
|
||||
|
||||
DEFAULT_REPO = "https://git.neilbantoc.dev/pub/llm-host.git" # install.sh's default too
|
||||
|
||||
|
||||
def raw_file_url(repo, ref, name):
|
||||
"""Where a file in `repo` at `ref` is fetched raw: GitHub's raw host, or the
|
||||
/raw/branch/ path Gitea and Forgejo use. None for a remote that isn't https."""
|
||||
m = re.match(r"^https://([^/]+)/(.+?)(\.git)?/?$", repo or "")
|
||||
if not m:
|
||||
return None
|
||||
host, path = m.group(1), m.group(2)
|
||||
if host.lower() == "github.com":
|
||||
return f"https://raw.githubusercontent.com/{path}/{ref}/{name}"
|
||||
return f"https://{host}/{path}/raw/branch/{ref}/{name}"
|
||||
|
||||
|
||||
_installer = None
|
||||
|
||||
|
||||
def installer_url():
|
||||
"""The opencode installer's URL in the repo this server was installed from, so the
|
||||
command the Connect dialog gives out works for people who can't reach this dashboard
|
||||
(an API-only tunnel) and follows a fork. Falls back to the main repo."""
|
||||
global _installer
|
||||
if _installer is None:
|
||||
import subprocess
|
||||
def git(*args):
|
||||
try:
|
||||
r = subprocess.run(["git", "-C", str(paths.SRC), *args], capture_output=True, text=True, timeout=5)
|
||||
return r.stdout.strip() if r.returncode == 0 else ""
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return ""
|
||||
ref = git("rev-parse", "--abbrev-ref", "HEAD")
|
||||
_installer = (raw_file_url(git("config", "--get", "remote.origin.url"),
|
||||
ref if ref and ref != "HEAD" else "main", "opencode-install.sh")
|
||||
or raw_file_url(DEFAULT_REPO, "main", "opencode-install.sh"))
|
||||
return _installer
|
||||
# The opencode installer's URL is worked out once, from the repo this was installed from.
|
||||
raw_file_url, installer_url = opencode.raw_file_url, opencode.installer_url
|
||||
|
||||
|
||||
def make_handler(sampler, key, oidc=None, otp=None, key_login=True):
|
||||
|
|
@ -602,17 +568,19 @@ def make_handler(sampler, key, oidc=None, otp=None, key_login=True):
|
|||
if self.authed():
|
||||
self.send_json(200, sampler.snapshot())
|
||||
elif path == "/api/connect":
|
||||
# What the Connect dialog hands to clients: the key, and opencode's provider
|
||||
# block from the same builder as `llmhost opencode-config`. The public API
|
||||
# address can't be known here, so the page fills in baseURL, the provider id
|
||||
# and its label from what the viewer types. Behind the same sign-in as
|
||||
# everything else; send_json marks it no-store.
|
||||
# What the Connect dialog hands to clients: the key; the API's addresses with
|
||||
# the opencode-install.sh command for each, chosen by the same rule as setup and
|
||||
# `llmhost opencode-config` (opencode.client_targets); and opencode's provider
|
||||
# block for setting it up by hand, whose address-dependent parts the page fills
|
||||
# in. Behind the same sign-in as everything else; send_json marks it no-store.
|
||||
if self.authed():
|
||||
cfg = paths.load_config() or sampler.cfg
|
||||
h = socket.gethostname()
|
||||
targets = [{"where": w, "url": u, "command": opencode.remote_command(u)}
|
||||
for w, u in opencode.client_targets(cfg, h if "." in h else h + ".local")]
|
||||
block = opencode.provider_block(cfg, "HOST", "KEYFILE", "LABEL")
|
||||
self.send_json(200, {"key": key, "api_port": cfg["api_port"],
|
||||
"model": plan.SERVED_ALIAS, "opencode": block,
|
||||
"installer": installer_url()})
|
||||
self.send_json(200, {"key": key, "model": plan.SERVED_ALIAS, "opencode": block,
|
||||
"targets": targets})
|
||||
elif path == "/api/logs":
|
||||
if self.authed():
|
||||
lines = [l for l in service.logs("model", 1500)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue