Show required key when nessicary for private resources

This commit is contained in:
Owen
2026-08-20 11:38:47 -04:00
parent c1051db4a5
commit df7e26a444
+16 -9
View File
@@ -49,8 +49,15 @@ export type AiClientGuide = {
presets: AiConfigPreset[]; presets: AiConfigPreset[];
}; };
/**
* Placeholder key for keyless (private/site) resources. Those resources need
* no credential, but most clients refuse to start without *some* key set, so
* they get an obviously-inert one rather than an omitted field.
*/
const KEYLESS_PLACEHOLDER_KEY = "none";
function keyValue(auth: AiClientAuth): string { function keyValue(auth: AiClientAuth): string {
return auth.mode === "keyed" ? auth.key : "-"; return auth.mode === "keyed" ? auth.key : KEYLESS_PLACEHOLDER_KEY;
} }
function block( function block(
@@ -132,7 +139,7 @@ function buildClaudeGuide(
(key) => (key) =>
[ [
`export ANTHROPIC_BASE_URL=${endpoint}`, `export ANTHROPIC_BASE_URL=${endpoint}`,
`export ANTHROPIC_API_KEY=${auth.mode === "keyed" ? key : "none"}`, `export ANTHROPIC_API_KEY=${key}`,
"claude" "claude"
].join("\n"), ].join("\n"),
auth auth
@@ -334,7 +341,7 @@ function buildOpencodeGuide(
"More providers", "More providers",
() => () =>
"OpenCode configures providers individually, so Anthropic and OpenAI are just the ones set up above. " + "OpenCode configures providers individually, so Anthropic and OpenAI are just the ones set up above. " +
'You can point any other OpenCode-supported provider (e.g. "openrouter", "google", "groq") at this gateway the same way: add a matching entry under "provider" in opencode.json, and under auth.json if it needs an API key.', 'You can point any other OpenCode-supported provider (e.g. "openrouter", "google", "groq") at this gateway the same way: add a matching entry under "provider" in opencode.json, and a matching key in auth.json.',
auth, auth,
"steps" "steps"
); );
@@ -348,10 +355,10 @@ function buildOpencodeGuide(
id: "default", id: "default",
label: "Default", label: "Default",
relation: "steps", relation: "steps",
blocks: // auth.json is written even for keyless resources: OpenCode
auth.mode === "keyed" // refuses to start a provider with no key at all ("OpenAI API
? [config, authFile, moreProviders] // key is missing"), so it gets the inert placeholder instead.
: [config, moreProviders] blocks: [config, authFile, moreProviders]
} }
] ]
}; };
@@ -368,7 +375,7 @@ function buildGeminiGuide(
(key) => (key) =>
[ [
`GOOGLE_GEMINI_BASE_URL=${endpoint}`, `GOOGLE_GEMINI_BASE_URL=${endpoint}`,
`GEMINI_API_KEY=${auth.mode === "keyed" ? key : "none"}` `GEMINI_API_KEY=${key}`
].join("\n"), ].join("\n"),
auth auth
); );
@@ -379,7 +386,7 @@ function buildGeminiGuide(
(key) => (key) =>
[ [
`export GOOGLE_GEMINI_BASE_URL=${endpoint}`, `export GOOGLE_GEMINI_BASE_URL=${endpoint}`,
`export GEMINI_API_KEY=${auth.mode === "keyed" ? key : "none"}`, `export GEMINI_API_KEY=${key}`,
"gemini" "gemini"
].join("\n"), ].join("\n"),
auth auth