Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
keep a keyed non-gateway service's key on an OpenCode route, and record only OpenAI URLs as endpoint (#7562)
[._.]/ Adam Eivyb697d0ebfb89
diff --git a/server/lib/providerRouteRecipes.js b/server/lib/providerRouteRecipes.jsindex 80d3c8c30a..aed3cf834a 100644--- a/server/lib/providerRouteRecipes.js+++ b/server/lib/providerRouteRecipes.js@@ -419,21 +419,28 @@ export function materializeRoute({// inline config or provider name as every shipped wrapper sample does — the// readiness probe and the catalog refresh read it off the record. A binding// that writes none (the program signs in itself) records none.+ // `endpoint` is the OpenAI-compatible URL everywhere it is read (catalog+ // probes, the local-runtime classifier), so an Anthropic-only service records+ // none.const endpoint = !binding.baseUrl ? null- : binding.baseUrl.via === 'field' ? baseUrl : instance.transports.openai?.baseUrl ?? baseUrl;+ : binding.baseUrl.via === 'field' ? baseUrl : instance.transports.openai?.baseUrl ?? null;if (endpoint) fields.endpoint = endpoint;// --- credential ------------------------------------------------------------const credential = binding.credential || null;- const credentialEnvName = credential?.via === 'gatewayEnv'- ? definition.gateway?.apiKeyEnv ?? null- : credential?.via === 'env' ? credential.name ?? definition.credential.envVars[0] ?? null : null;+ // A `gatewayEnv` credential lands under the gateway's own variable (what the+ // spawner exports for OpenCode); on a service that is not a gateway it lands+ // on the record's `apiKey`, which the inline-config builder attaches at spawn.+ const credentialVia = credential?.via === 'gatewayEnv' && !definition.gateway ? 'field' : credential?.via;+ const credentialEnvName = credentialVia === 'gatewayEnv'+ ? definition.gateway.apiKeyEnv+ : credentialVia === 'env' ? credential.name ?? definition.credential.envVars[0] ?? null : null;const credentialRequired = credential?.required === true && instance.credentialVia !== 'bootstrap';if (credentialRequired && apiKey === '') {throw serviceError('SERVICE_CREDENTIAL_REQUIRED',`${harness.label} will not start without a ${credentialEnvName || 'key'} for ${definition.label}. Set one first — any non-empty value works for a local daemon that ignores it.`);}- if (credential?.via === 'field') fields.apiKey = apiKey;+ if (credentialVia === 'field') fields.apiKey = apiKey;if (credentialEnvName && (apiKey !== '' || credentialRequired)) {envVars[credentialEnvName] = apiKey;secretEnvVars.push(credentialEnvName);diff --git a/server/lib/providerRouteRecipes.materialize.test.js b/server/lib/providerRouteRecipes.materialize.test.jsindex f1336d9147..391e395eb0 100644--- a/server/lib/providerRouteRecipes.materialize.test.js+++ b/server/lib/providerRouteRecipes.materialize.test.js@@ -103,6 +103,23 @@ describe('materializeRoute writes what each binding shape says', () => {expect(record).not.toHaveProperty('endpoint');});+ // The reviewer's catch: OpenCode's key binding names the gateway's env var,+ // which a keyed non-gateway service does not have — the key must not vanish.+ it('keeps a keyed non-gateway service\'s key on the OpenCode record', () => {+ const record = materializeRoute({ harness: 'opencode', method: 'cli', serviceInstance: { definitionId: 'cerebras', credentials: { apiKey: 'cb' } } });+ expect(record.apiKey).toBe('cb');+ expect(record.secretEnvVars).toEqual([]);+ expect(JSON.parse(record.envVars.OPENCODE_CONFIG_CONTENT).provider.cerebras.options.baseURL).toBe('https://api.cerebras.ai/v1');+ });++ it('records only an OpenAI-compatible URL as endpoint', () => {+ const anthropicOnly = materializeRoute({ harness: 'claude', method: 'cli', serviceInstance: { definitionId: 'anthropic', credentials: { apiKey: 'k' } } });+ expect(anthropicOnly.envVars.ANTHROPIC_BASE_URL).toBe('https://api.anthropic.com');+ expect(anthropicOnly).not.toHaveProperty('endpoint');+ const both = materializeRoute({ harness: 'claude', method: 'cli', serviceInstance: { definitionId: 'ollama', transports: LOCAL_TRANSPORTS, credentials: { apiKey: 'k' } } });+ expect(both.endpoint).toBe(LOCAL_TRANSPORTS.openai.baseUrl);+ });+it('declares OpenCode Zen as the provider OpenCode ships, permissions only', () => {const record = materializeRoute({ harness: 'opencode', method: 'cli', serviceInstance: { definitionId: 'opencode-zen', credentials: { apiKey: 'zen' } } });expect(record.envVars.OPENCODE_CONFIG_CONTENT).toBe(SAMPLES['opencode-zen-cli'].envVars.OPENCODE_CONFIG_CONTENT);