Skip to content

Commit 6eec210

Browse files
feat(setup): pass SIM_AGENT_API_URL through, and warn on a half-set mothership
Sim devs testing against a non-prod mothership export SIM_CLI_AUTH_ORIGIN so the Chat key is minted there, but nothing carried the matching backend URL into the install — the app kept defaulting to prod copilot, which rejects a staging key with 'Invalid API key'. Persist SIM_AGENT_API_URL when it is exported, so later docker compose up / dev runs stay on that backend instead of reverting to prod once the shell is gone: SIM_CLI_AUTH_ORIGIN=https://www.staging.sim.ai \ SIM_AGENT_API_URL=https://www.staging.copilot.sim.ai \ bun run setup Setting only the auth origin is the trap, so that combination warns. Neither set is the self-hoster default and stays silent — no prompts, no flags.
1 parent 6a093c3 commit 6eec210

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

scripts/setup/modes/compose.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { httpHealth, waitFor } from '../probes.ts'
88
import * as p from '../prompter.ts'
99
import {
1010
collectSecrets,
11+
mothershipOverride,
1112
promptCopilotKey,
1213
promptEmail,
1314
promptLlmKeys,
@@ -60,6 +61,7 @@ export async function runComposeMode(detection: Detection, quick: boolean): Prom
6061
const copilotKey = await promptCopilotKey(root.vars.get('COPILOT_API_KEY'))
6162
if (copilotKey) values.COPILOT_API_KEY = copilotKey
6263
Object.assign(values, await promptLlmKeys(detection, !quick))
64+
Object.assign(values, mothershipOverride())
6365
if (!quick) {
6466
const storage = await promptStorage(root.vars, true)
6567
if (storage) Object.assign(values, storage)

scripts/setup/modes/dev.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as p from '../prompter.ts'
1010
import { ensureRedis, resolveRedis } from '../redis.ts'
1111
import {
1212
collectSecrets,
13+
mothershipOverride,
1314
promptCopilotKey,
1415
promptEmail,
1516
promptLlmKeys,
@@ -120,6 +121,7 @@ export async function runDevMode(
120121
const copilotKey = await promptCopilotKey(simAfter.vars.get('COPILOT_API_KEY'))
121122
if (copilotKey) values.COPILOT_API_KEY = copilotKey
122123
Object.assign(values, await promptLlmKeys(detection, !quick))
124+
Object.assign(values, mothershipOverride())
123125

124126
// Redis is set up in every mode, quick included. Storage falls back to
125127
// PostgreSQL without it, but the pub/sub channels (live Chat task-status,

scripts/setup/steps.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ export async function promptCopilotKey(existing?: string): Promise<string | null
6565
return key
6666
}
6767

68+
/**
69+
* Escape hatch for Sim devs pointing an install at a non-prod mothership:
70+
*
71+
* SIM_CLI_AUTH_ORIGIN=https://www.staging.sim.ai \
72+
* SIM_AGENT_API_URL=https://www.staging.copilot.sim.ai \
73+
* bun run setup
74+
*
75+
* The two belong together — SIM_CLI_AUTH_ORIGIN decides where the Chat key is
76+
* minted, SIM_AGENT_API_URL decides which backend validates it, and a key from
77+
* one environment is rejected by the other. Persisting the URL keeps later
78+
* `docker compose up` / dev runs on the same backend instead of silently
79+
* reverting to prod once the shell that exported it is gone.
80+
*/
81+
export function mothershipOverride(): Record<string, string> {
82+
const agentUrl = process.env.SIM_AGENT_API_URL
83+
const authOrigin = process.env.SIM_CLI_AUTH_ORIGIN
84+
if (authOrigin && !agentUrl) {
85+
p.log.warn(
86+
`SIM_CLI_AUTH_ORIGIN points the Chat key handoff at ${authOrigin}, but SIM_AGENT_API_URL is unset — the app will validate that key against production and reject it. Set both, or neither.`
87+
)
88+
}
89+
if (!agentUrl) return {}
90+
p.log.step(`Using mothership ${agentUrl} (SIM_AGENT_API_URL)`)
91+
return { SIM_AGENT_API_URL: agentUrl }
92+
}
93+
6894
export async function promptLlmKeys(
6995
detection: Detection,
7096
custom: boolean

0 commit comments

Comments
 (0)