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
|
|
@ -119,7 +119,7 @@ def carried_settings(old, names):
|
|||
longer fit lose their setting along with their plan."""
|
||||
kept = {k: v for k, v in (old.get("reasoning") or {}).items() if k in names}
|
||||
out = {"reasoning": kept} if kept else {}
|
||||
for k in ("newt", "dashboard_auth", "dashboard_key_login"): # set by install-*/expose-dashboard, not the plan
|
||||
for k in ("newt", "dashboard_auth", "dashboard_key_login", "dashboard_public"): # set by install-*/expose-dashboard
|
||||
if old.get(k) is not None: # dashboard_key_login is False when it matters
|
||||
out[k] = old[k]
|
||||
return out
|
||||
|
|
@ -208,7 +208,11 @@ Done.
|
|||
Model: {active} — {"not started yet; run: llmhost start" if a.no_start else ("loading" if hfcache.is_downloaded(first["repo"]) else "downloading, then loading") + "; watch progress with: llmhost watch"}""")
|
||||
if not a.no_opencode:
|
||||
setup_opencode(cfg, ask=sys.stdin.isatty() and not a.yes, install_ok=a.opencode)
|
||||
say(f"\nOther machines: run `llmhost opencode-config` here for their opencode setup.")
|
||||
say("\nOther machines: connect their opencode to this server with one line there. It installs\n"
|
||||
"opencode if needed, asks for the API key (show it here with `llmhost key`), and adds the\n"
|
||||
"server to opencode.json.")
|
||||
for where, url in opencode.client_targets(cfg, host):
|
||||
say(f" {where}:\n {opencode.remote_command(url)}")
|
||||
if os.environ.get("LLMHOST_PATH_NOTE"):
|
||||
say("\n" + os.environ["LLMHOST_PATH_NOTE"])
|
||||
|
||||
|
|
@ -358,7 +362,9 @@ def cmd_status(a):
|
|||
+ (["authenticator code"] if paths.OTP_SECRET_FILE.exists() else [])
|
||||
say(f"sign-in {' or '.join(ways)}")
|
||||
if cfg.get("newt"):
|
||||
say(f"tunnel newt -> {cfg['newt']['endpoint']}")
|
||||
api = cfg["newt"].get("api_url")
|
||||
say(f"tunnel newt -> {cfg['newt']['endpoint']}" + (f"; API at {api}/v1" if api else ""))
|
||||
say(f"dashboard {'public (expose-dashboard)' if cfg.get('dashboard_public') else 'local network only'}")
|
||||
|
||||
|
||||
def cmd_models(a):
|
||||
|
|
@ -546,8 +552,16 @@ def cmd_install_newt(a):
|
|||
old_n = cfg.get("newt") or {}
|
||||
newt.platform_tag() # fail before asking anything on a platform newt doesn't ship for
|
||||
|
||||
say("Pangolin site (Pangolin: Sites -> Add Site -> Newt):")
|
||||
endpoint = _check_url("Pangolin endpoint", _ask(" Pangolin endpoint", a.endpoint, old_n.get("endpoint"), "--endpoint"))
|
||||
api_url = _ask("The API's public URL, as clients will reach it (e.g. https://llm-api.example.com)",
|
||||
a.api_url, old_n.get("api_url"), "--api-url").strip().rstrip("/")
|
||||
api_url = _check_url("API URL", api_url[:-3] if api_url.endswith("/v1") else api_url)
|
||||
|
||||
say("\nPangolin site (Pangolin: Sites -> Add Site -> Newt):")
|
||||
endpoint = _check_url("Pangolin endpoint", _ask(" Pangolin endpoint (your Pangolin server, not the API's URL)",
|
||||
a.endpoint, old_n.get("endpoint"), "--endpoint"))
|
||||
if urllib.parse.urlsplit(endpoint).netloc == urllib.parse.urlsplit(api_url).netloc:
|
||||
sys.exit("The Pangolin endpoint is the Pangolin server itself; the API's URL is a resource on it, "
|
||||
"so the two can't be the same.")
|
||||
site_id = _ask(" Newt ID", a.newt_id, old_n.get("id"), "--newt-id")
|
||||
have_secret = paths.NEWT_SECRET_FILE.exists() and old_n
|
||||
newt_secret = _ask(" Newt secret", None, "keep" if have_secret else None, secret=True, env="LLMHOST_NEWT_SECRET")
|
||||
|
|
@ -555,7 +569,7 @@ def cmd_install_newt(a):
|
|||
newt.ensure_binary(say)
|
||||
if newt_secret != "keep":
|
||||
paths.save_secret(paths.NEWT_SECRET_FILE, newt_secret)
|
||||
cfg["newt"] = {"endpoint": endpoint, "id": site_id}
|
||||
cfg["newt"] = {"endpoint": endpoint, "id": site_id, "api_url": api_url}
|
||||
paths.save_config(cfg)
|
||||
service.install("newt")
|
||||
if not service.restart("newt"):
|
||||
|
|
@ -563,12 +577,13 @@ def cmd_install_newt(a):
|
|||
ip = lan_ip()
|
||||
say(f"""
|
||||
Done. newt is running. In Pangolin, add an HTTP resource on this site for the API:
|
||||
<a host of your choice> -> http://{ip}:{cfg['api_port']}
|
||||
{urllib.parse.urlsplit(api_url).netloc} -> http://{ip}:{cfg['api_port']}
|
||||
with Pangolin's own authentication off (llm-host checks the API key). Point it at {ip}, not
|
||||
localhost: requests from localhost count as local here.
|
||||
|
||||
Clients then use https://<that host>/v1 with the API key; for opencode, see the dashboard's
|
||||
Connect button, or opencode-install.sh in the llm-host repo.
|
||||
Clients then use {api_url}/v1 with the API key. To connect opencode on another machine, run
|
||||
this there (it asks for the key, which `llmhost key` shows):
|
||||
{opencode.remote_command(api_url)}
|
||||
|
||||
The dashboard stays on your local network. To put it online too, first give it a sign-in
|
||||
that isn't the API key you hand out (`llmhost install-oidc` or `llmhost install-otp`), then
|
||||
|
|
@ -583,6 +598,7 @@ def cmd_remove_newt(a):
|
|||
shutil.rmtree(paths.NEWT_DIR, ignore_errors=True)
|
||||
paths.NEWT_SECRET_FILE.unlink(missing_ok=True)
|
||||
had = bool(cfg.pop("newt", None))
|
||||
cfg.pop("dashboard_public", None) # nothing is public without the tunnel
|
||||
paths.save_config(cfg)
|
||||
say("Removed newt; nothing is reachable from the internet through it now." if had else "newt wasn't installed.")
|
||||
|
||||
|
|
@ -760,6 +776,10 @@ In Pangolin, on the same site as the API, add an HTTP resource:
|
|||
authentication {pangolin_auth}""")
|
||||
if oidc_on:
|
||||
say(f" and make sure your OIDC client allows the redirect URI {public_url}/auth/callback")
|
||||
# Only that it's public, not where: what's handed to clients is the API's address, and
|
||||
# a public dashboard is seen from outside, so it stops offering the LAN one.
|
||||
cfg["dashboard_public"] = True
|
||||
paths.save_config(cfg)
|
||||
if not sys.stdin.isatty():
|
||||
return
|
||||
input("\nPress Enter once the resource is saved, to check it from here... ")
|
||||
|
|
@ -788,24 +808,32 @@ def cmd_download(a):
|
|||
|
||||
def cmd_opencode(a):
|
||||
cfg = _service_check()
|
||||
host = a.host or default_host()
|
||||
if a.host: # an address given explicitly: that one, as before
|
||||
targets = [("", f"http://{a.host}:{cfg['api_port']}")]
|
||||
else:
|
||||
targets = opencode.client_targets(cfg, default_host())
|
||||
base = targets[0][1]
|
||||
host = urllib.parse.urlsplit(base).hostname
|
||||
prov = a.provider or opencode.remote_provider(host)
|
||||
keyfile = opencode.remote_key_file(prov)
|
||||
snippet = {
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {prov: opencode.provider_block(cfg, host, keyfile, host)},
|
||||
"provider": {prov: opencode.provider_block(cfg, host, keyfile, host, base_url=base + "/v1")},
|
||||
"model": f"{prov}/{plan.SERVED_ALIAS}", # the block's only entry
|
||||
}
|
||||
if a.json:
|
||||
say(json.dumps(snippet, indent=2))
|
||||
return
|
||||
say(f"""(On this machine itself, `llmhost opencode-setup` does all of this automatically.)
|
||||
say("(On this machine itself, `llmhost opencode-setup` does all of this automatically.)\n\n"
|
||||
"On another machine, run this there. It installs opencode if needed, asks for the API key\n"
|
||||
"(`llmhost key` shows it here), and adds this server to opencode.json:")
|
||||
for where, url in targets:
|
||||
say(f" {where}:\n {opencode.remote_command(url)}" if where else f" {opencode.remote_command(url)}")
|
||||
say(f"""
|
||||
Or by hand, for {base}/v1:
|
||||
|
||||
On another machine running opencode:
|
||||
|
||||
1. Save the API key:
|
||||
mkdir -p ~/.config/opencode && ssh {os.environ.get('USER', 'you')}@{host} 'cat {paths.KEY_FILE}' > {keyfile} && chmod 600 {keyfile}
|
||||
(or paste the output of `llmhost key` into {keyfile})
|
||||
1. Save the API key: paste the output of `llmhost key` into {keyfile} (mode 600), or
|
||||
mkdir -p ~/.config/opencode && ssh {os.environ.get('USER', 'you')}@{default_host()} 'cat {paths.KEY_FILE}' > {keyfile} && chmod 600 {keyfile}
|
||||
|
||||
2. Merge this into ~/.config/opencode/opencode.json:
|
||||
""")
|
||||
|
|
@ -1001,6 +1029,7 @@ def main(argv=None):
|
|||
sub.add_parser("key", help="print the API key").set_defaults(fn=cmd_key)
|
||||
s = sub.add_parser("install-newt", help="reach the API from the internet through a Pangolin tunnel (dashboard stays local)")
|
||||
s.add_argument("--endpoint", help="Pangolin server, e.g. https://pangolin.example.com")
|
||||
s.add_argument("--api-url", help="the API's public address, e.g. https://llm-api.example.com (a resource on Pangolin)")
|
||||
s.add_argument("--newt-id", help="the site's Newt ID (its secret: prompted, or $LLMHOST_NEWT_SECRET)")
|
||||
s.set_defaults(fn=cmd_install_newt)
|
||||
sub.add_parser("remove-newt", help="undo install-newt: stop the tunnel").set_defaults(fn=cmd_remove_newt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue