From e6ff4ce909a449c19ab029e2b2fd57ab507e2d62 Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 6 Nov 2026 15:10:49 -0800 Subject: [PATCH] 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 --- llmhost/web/index.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/llmhost/web/index.html b/llmhost/web/index.html index 0f235aa..b71e4ca 100644 --- a/llmhost/web/index.html +++ b/llmhost/web/index.html @@ -304,7 +304,9 @@ pre { placeholder="https://llm-api.example.com/v1" aria-label="API base URL">
  • Save the key where the provider reads it (paste it at the prompt; it stays out of your shell history):
  • -
  • Merge this into ~/.config/opencode/opencode.json, under "provider": +
  • Put this in ~/.config/opencode/opencode.json. If the file is empty or missing, paste the whole thing; + if it already has settings, add the entry under "provider" to its own "provider" + (and set "model" only if you want this as the default):
  • Pick in opencode's model list.
  • @@ -389,10 +391,17 @@ function renderOpencode() { block.options.baseURL = url || "https:///v1"; block.options.apiKey = `{file:${keyfile}}`; 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 = - `mkdir -p ~/.config/opencode && printf 'API key: ' && stty -echo && read -r k; stty echo; echo\n` + - `printf '%s\\n' "$k" > ${keyfile} && chmod 600 ${keyfile}; unset k`; + // 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-pick").textContent = `${block.name} → ${Object.values(block.models)[0]?.name || CONNECT.model}`; try { localStorage.setItem("llmhost-api-url", $("cx-url").value.trim()); } catch (e) {} }