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
|
|
@ -173,7 +173,9 @@ pre {
|
|||
.dialog .actions { display: flex; justify-content: flex-end; }
|
||||
.dialog details.manual { margin-bottom: 12px; font-size: 13px; }
|
||||
.dialog details.manual summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
|
||||
#cx-install { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.dialog .snip pre.cmd { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
#cx-installs .where { font-size: 12.5px; color: var(--muted); margin: 0 0 4px; }
|
||||
#cx-installs .snip { margin: 0 0 14px; }
|
||||
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
|
||||
padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .25s; pointer-events: none; }
|
||||
.toast.show { opacity: 1; }
|
||||
|
|
@ -308,15 +310,12 @@ pre {
|
|||
<div class="keyrow"><input id="cx-key" type="password" readonly autocomplete="off" aria-label="API key"><button id="cx-show">Show</button><button id="cx-copy">Copy</button></div>
|
||||
|
||||
<h4>Add to opencode</h4>
|
||||
<p>The API's address, as the machine running opencode reaches it:</p>
|
||||
<div class="keyrow"><input id="cx-url" type="url" spellcheck="false" autocomplete="off"
|
||||
placeholder="https://llm-api.example.com" aria-label="API base URL"></div>
|
||||
<p>Then run this there, or send it to whoever you're giving access, with the key. It needs only the API, not this
|
||||
dashboard: it installs opencode if it's missing, asks for the key (hidden), saves it, and adds this server to
|
||||
<code>opencode.json</code>, keeping their other settings:</p>
|
||||
<div class="snip" style="margin-bottom:14px"><pre id="cx-install"></pre><button class="small" data-copy="cx-install">Copy</button></div>
|
||||
<p>Run this on the machine with opencode, or send it to whoever you're giving access, with the key. It needs
|
||||
only the API, not this dashboard: it installs opencode if it's missing, asks for the key (hidden), saves it,
|
||||
and adds this server to <code>opencode.json</code>, keeping their other settings.</p>
|
||||
<div id="cx-installs"></div>
|
||||
<details class="manual">
|
||||
<summary>Or set it up by hand</summary>
|
||||
<summary id="cx-manual-title">Or set it up by hand</summary>
|
||||
<ol>
|
||||
<li>Save the key where the provider reads it (paste it at the prompt; it stays out of your shell history):
|
||||
<div class="snip"><pre id="cx-keycmd"></pre><button class="small" data-copy="cx-keycmd">Copy</button></div></li>
|
||||
|
|
@ -427,7 +426,22 @@ function closeConnect() {
|
|||
// filled in here: baseURL, and the provider id and label named after its host.
|
||||
function renderOpencode() {
|
||||
if (!CONNECT) return;
|
||||
let url = $("cx-url").value.trim().replace(/\/+$/, "");
|
||||
// One command per address the API is reached at (server's choice; see client_targets).
|
||||
const box = $("cx-installs"); box.textContent = "";
|
||||
for (const t of CONNECT.targets) {
|
||||
if (CONNECT.targets.length > 1) {
|
||||
const w = document.createElement("div"); w.className = "where";
|
||||
w.textContent = t.where[0].toUpperCase() + t.where.slice(1) + ":"; box.appendChild(w);
|
||||
}
|
||||
const snip = document.createElement("div"); snip.className = "snip";
|
||||
const pre = document.createElement("pre"); pre.className = "cmd"; pre.textContent = t.command;
|
||||
const b = document.createElement("button"); b.className = "small"; b.textContent = "Copy";
|
||||
b.onclick = async () => toast(await copyText(t.command) ? "Copied" : "Couldn't copy; select it and copy by hand");
|
||||
snip.append(pre, b); box.appendChild(snip);
|
||||
}
|
||||
// By hand: for the first (most useful) address.
|
||||
let url = CONNECT.targets[0].url.replace(/\/+$/, "");
|
||||
$("cx-manual-title").textContent = `Or set it up by hand (for ${url})`;
|
||||
let host = "";
|
||||
try { host = new URL(url).hostname; } catch (e) {}
|
||||
if (url && !/\/v1$/.test(url)) url += "/v1";
|
||||
|
|
@ -450,27 +464,16 @@ function renderOpencode() {
|
|||
// One line: pasted as two, the first line's `read` would swallow the second as the key.
|
||||
`mkdir -p ~/.config/opencode && printf 'API key: ' && stty -echo && read -r k; stty echo; echo; ` +
|
||||
`[ -n "$k" ] && (umask 077 && printf '%s\\n' "$k" > ${keyfile}) && echo "saved ${keyfile}"; unset k`;
|
||||
$("cx-install").textContent = url
|
||||
? `/bin/bash -c "$(curl -fsSL ${CONNECT.installer})" -- --url ${url.replace(/\/v1$/, "")}`
|
||||
: "Type the API's address above first.";
|
||||
$("cx-pick").textContent = `${block.name} → ${Object.values(block.models)[0]?.name || CONNECT.model}`;
|
||||
try { localStorage.setItem("llmhost-api-url", $("cx-url").value.trim()); } catch (e) {}
|
||||
}
|
||||
$("connect").onclick = async () => {
|
||||
let c;
|
||||
try { c = await api("/api/connect"); } catch (e) { if (e.message !== "unauthorized") toast("Couldn't load: " + e.message); return; }
|
||||
CONNECT = c;
|
||||
$("cx-key").value = c.key;
|
||||
// The public API address can't be known here, so remember what the viewer typed; on a
|
||||
// plain-http LAN visit the API is on this same host, at its own port.
|
||||
let saved = "";
|
||||
try { saved = localStorage.getItem("llmhost-api-url") || ""; } catch (e) {}
|
||||
if (!saved && location.protocol === "http:") saved = `http://${location.hostname}:${c.api_port}/v1`;
|
||||
$("cx-url").value = saved;
|
||||
renderOpencode();
|
||||
$("connect-modal").classList.add("show"); $("cx-close").focus();
|
||||
};
|
||||
$("cx-url").addEventListener("input", renderOpencode);
|
||||
document.querySelectorAll("#connect-modal [data-copy]").forEach((b) => {
|
||||
b.onclick = async () => toast(await copyText($(b.dataset.copy).textContent) ? "Copied" : "Couldn't copy; select it and copy by hand");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue