Connect dialog: a complete opencode.json, and a one-line key command

The snippet was only the provider entry, which an empty or missing opencode.json can't take,
and without a "model" opencode starts on its own hosted default and asks for that service's
key. It is now a whole config (schema, provider, model), as `llmhost opencode-config` prints,
with instructions for merging into an existing file.

The key-saving command was two lines; pasted together, the first line's `read` swallowed the
second as the key and no file was written. It's one line now, and writes only a non-empty key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-06 15:10:49 -08:00
parent 04ff14c58f
commit e6ff4ce909

View file

@ -304,7 +304,9 @@ pre {
placeholder="https://llm-api.example.com/v1" aria-label="API base URL"></div></li> placeholder="https://llm-api.example.com/v1" aria-label="API base URL"></div></li>
<li>Save the key where the provider reads it (paste it at the prompt; it stays out of your shell history): <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> <div class="snip"><pre id="cx-keycmd"></pre><button class="small" data-copy="cx-keycmd">Copy</button></div></li>
<li>Merge this into <code>~/.config/opencode/opencode.json</code>, under <code>"provider"</code>: <li>Put this in <code>~/.config/opencode/opencode.json</code>. If the file is empty or missing, paste the whole thing;
if it already has settings, add the entry under <code>"provider"</code> to its own <code>"provider"</code>
(and set <code>"model"</code> only if you want this as the default):
<div class="snip"><pre id="cx-block"></pre><button class="small" data-copy="cx-block">Copy</button></div></li> <div class="snip"><pre id="cx-block"></pre><button class="small" data-copy="cx-block">Copy</button></div></li>
<li>Pick <b id="cx-pick"></b> in opencode's model list.</li> <li>Pick <b id="cx-pick"></b> in opencode's model list.</li>
</ol> </ol>
@ -389,10 +391,17 @@ function renderOpencode() {
block.options.baseURL = url || "https://<API host>/v1"; block.options.baseURL = url || "https://<API host>/v1";
block.options.apiKey = `{file:${keyfile}}`; block.options.apiKey = `{file:${keyfile}}`;
for (const m of Object.values(block.models || {})) if (m.name) m.name = m.name.replace("LABEL", label); for (const m of Object.values(block.models || {})) if (m.name) m.name = m.name.replace("LABEL", label);
$("cx-block").textContent = JSON.stringify({ [prov]: block }, null, 2); // A whole config, like `llmhost opencode-config` prints: it works as-is in an empty
// file, and its "provider" entry is what to merge into an existing one.
$("cx-block").textContent = JSON.stringify({
$schema: "https://opencode.ai/config.json",
provider: { [prov]: block },
model: `${prov}/${CONNECT.model}`,
}, null, 2);
$("cx-keycmd").textContent = $("cx-keycmd").textContent =
`mkdir -p ~/.config/opencode && printf 'API key: ' && stty -echo && read -r k; stty echo; echo\n` + // One line: pasted as two, the first line's `read` would swallow the second as the key.
`printf '%s\\n' "$k" > ${keyfile} && chmod 600 ${keyfile}; unset k`; `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-pick").textContent = `${block.name} → ${Object.values(block.models)[0]?.name || CONNECT.model}`; $("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) {} try { localStorage.setItem("llmhost-api-url", $("cx-url").value.trim()); } catch (e) {}
} }