Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(settings): configurable gateway discovery path (defaults to /v1/models)
Darren Kattan4d15f3911b51
diff --git a/src/core/agent-env-ipc.ts b/src/core/agent-env-ipc.tsindex 300a49e7d..e93be1d64 100644--- a/src/core/agent-env-ipc.ts+++ b/src/core/agent-env-ipc.ts@@ -28,7 +28,7 @@ async function discoverModels(saved: ModelGatewaySettings | undefined,storedSecret: string | null): Promise<ModelDiscoveryResult> {- const routes = modelGatewayRoutes(settings?.baseUrl ?? '')+ const routes = modelGatewayRoutes(settings?.baseUrl ?? '', settings?.discoveryPath)const apiKeyField = settings?.apiKey ?? ''// SECURITY GATE — this handler is reachable by relay peers and Server Edition WS clients, and// `settings` (URL included) is caller-supplied. `${secret:…}` / `${env:…}` references resolve@@ -37,6 +37,11 @@ async function discoverModels(// your own host. References therefore resolve ONLY when the requested baseUrl is byte-identical// to the persisted gateway URL; a literal key pasted into the form is the caller's own and may// be tested against any URL (the pre-save "does this key work?" flow in Settings).+ //+ // The discovery PATH needs no such byte-identity gate: `modelGatewayRoutes` reduces it to a+ // validated path SUFFIX on the same baseUrl, so a forged one cannot aim the request — or the+ // resolved key — at a different host; worst case is a 404 on the saved gateway, surfaced as an+ // ordinary discovery error.const isReference = apiKeyField.includes('${')const trusted = !!settings?.baseUrl && settings.baseUrl === saved?.baseUrlif (isReference && !trusted) {diff --git a/src/renderer/components/settings/sections/ModelGatewaySection.tsx b/src/renderer/components/settings/sections/ModelGatewaySection.tsxindex 94b4b4888..e0d650034 100644--- a/src/renderer/components/settings/sections/ModelGatewaySection.tsx+++ b/src/renderer/components/settings/sections/ModelGatewaySection.tsx@@ -21,6 +21,11 @@ const ROWS = {description: 'One gateway root URL for OpenAI-compatible discovery and agent routes.',keywords: ['openai compatible', 'bifrost', 'litellm', 'model', 'provider', 'base url', 'endpoint']},+ discoveryPath: {+ title: 'Discovery path',+ description: 'Path the model catalogue is read from, appended to the gateway root.',+ keywords: ['discover', 'models route', 'v1/models', 'openai/v1/models', 'catalogue path']+ },key: {title: 'API key',description: 'A gateway bearer key from protected storage or an environment variable.',@@ -203,6 +208,31 @@ export function ModelGatewaySection({ isActive }: { isActive: boolean }): React.) : null}</SearchableRow>+ <SearchableRow {...ROWS.discoveryPath}>+ <FieldRow+ label="Discovery path"+ description="Where the OpenAI-compatible model catalogue lives on the gateway — appended to the root URL. Leave as /v1/models unless your gateway serves it elsewhere (e.g. /openai/v1/models)."+ htmlFor="model-gateway-discovery-path"+ control={+ <Input+ id="model-gateway-discovery-path"+ className="w-64 font-mono"+ type="text"+ autoComplete="off"+ spellCheck={false}+ placeholder="/v1/models"+ value={gateway.discoveryPath ?? ''}+ onChange={(e) => patchGateway({ discoveryPath: e.target.value })}+ />+ }+ />+ {gateway.discoveryPath && !routes ? (+ <p className="mt-2 text-right text-xs text-[color:var(--warn)]">+ The path is ignored — fix the gateway URL above first.+ </p>+ ) : null}+ </SearchableRow>+<SearchableRow {...ROWS.key}><div className="space-y-3"><FieldRowdiff --git a/src/shared/agents/model-gateway.test.ts b/src/shared/agents/model-gateway.test.tsindex 7144f890c..06ac9dadd 100644--- a/src/shared/agents/model-gateway.test.ts+++ b/src/shared/agents/model-gateway.test.ts@@ -33,6 +33,38 @@ describe('modelGatewayRoutes', () => {expect(modelGatewayRoutes('https://example.test/#fragment')).toBeNull()expect(modelGatewayRoutes('not a URL')).toBeNull()})++ it('appends a supplied discovery path instead of the conventional /v1/models', () => {+ expect(modelGatewayRoutes('https://bifrost.example.test', '/openai/v1/models')).toEqual({+ discovery: 'https://bifrost.example.test/openai/v1/models',+ openai: 'https://bifrost.example.test/openai/v1',+ anthropic: 'https://bifrost.example.test/anthropic'+ })+ })++ it('falls back to /v1/models when the discovery path is absent, empty, or unsafe', () => {+ // Absent/empty = the conventional suffix. Unsafe values (full URLs — a caller-chosen host+ // would be a credential-exfiltration oracle — query, fragment, traversal) degrade to the+ // derived default, never to a fetch somewhere unvetted.+ expect(modelGatewayRoutes('https://bifrost.example.test', undefined)?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ expect(modelGatewayRoutes('https://bifrost.example.test', '')?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ expect(modelGatewayRoutes('https://bifrost.example.test', 'https://evil.test/x')?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ expect(modelGatewayRoutes('https://bifrost.example.test', '/../etc')?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ expect(modelGatewayRoutes('https://bifrost.example.test', '/x?y=1')?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ expect(modelGatewayRoutes('https://bifrost.example.test', '/x#f')?.discovery).toBe(+ 'https://bifrost.example.test/v1/models'+ )+ })})describe('parseGatewayModels', () => {diff --git a/src/shared/agents/model-gateway.ts b/src/shared/agents/model-gateway.tsindex 1c9aca3ce..db02736c8 100644--- a/src/shared/agents/model-gateway.ts+++ b/src/shared/agents/model-gateway.ts@@ -8,6 +8,28 @@ export interface ModelGatewaySettings {baseUrl: string/** Literal legacy key, `${env:VAR}` reference, or `MODEL_GATEWAY_SECRET_REF`. */apiKey: string+ /** Path the discovery (Models API) request is sent to, appended to `baseUrl` — e.g.+ * `/openai/v1/models` for a gateway that serves its model catalogue under a protocol prefix.+ * Deliberately a PATH SUFFIX and never a full URL: discovery sends the resolved API key to the+ * target, and a caller-chosen host would turn the pre-save/relay flow into a credential-exfil-+ * tration oracle (the same reason `${env:VAR}` references resolve only for the saved baseUrl).+ * Empty/absent = the conventional derived `/v1/models` (see `modelGatewayRoutes`). */+ discoveryPath?: string+}++/** Characters a discovery path may contain, minus URL structure that could change WHERE the+ * request goes: no query (`?`), fragment (`#`), dot-dot traversal, or second scheme. The value is+ * hand-editable settings.json AND caller-supplied over IPC, so it is re-validated at the point it+ * is appended to the root (the same rule as permission modes / model ids on a command line) — an+ * unrecognized value yields the derived default path, never a guessed one. */+const GATEWAY_DISCOVERY_PATH = /^\/[A-Za-z0-9\-._~!$&'()*+,;=:@/]*$/++/** A validated discovery path, or null when absent/unsafe (null ⇒ use the derived default). */+export function sanitizedGatewayDiscoveryPath(path: string | undefined): string | null {+ const value = path?.trim() ?? ''+ if (!value) return null+ if (value.length > 500 || value.includes('..') || !GATEWAY_DISCOVERY_PATH.test(value)) return null+ return value.replace(/\/+$/, '') || null}/** Stored in settings.json when the literal credential lives in the shell's secret store. */@@ -100,8 +122,18 @@ export function resolveModelGatewayApiKey(* the provider-specific paths are the Bifrost layout requested by the launch mapping. Only http(s)* URLs are accepted: this value is later handed to `fetch` and agent CLIs, and settings.json is* hand-editable. Invalid input degrades to null, never to a guessed endpoint.+ *+ * `discoveryPath` (optional, from the same `ModelGatewaySettings`) replaces the conventional+ * `/v1/models` suffix when it is present and passes `sanitizedGatewayDiscoveryPath`. It changes+ * only WHICH path on the saved root the catalogue is read from — never the host — so the+ * credential trust gate upstream (references resolve only for the saved baseUrl) is unaffected.+ * An unsafe value falls back to the derived default rather than sending a fetch somewhere the+ * user did not vet.*/-export function modelGatewayRoutes(baseUrl: string): ModelGatewayRoutes | null {+export function modelGatewayRoutes(+ baseUrl: string,+ discoveryPath?: string+): ModelGatewayRoutes | null {const raw = baseUrl.trim().replace(/\/+$/, '')if (!raw) return nulltry {@@ -111,8 +143,9 @@ export function modelGatewayRoutes(baseUrl: string): ModelGatewayRoutes | null {// The separate API-key field exists precisely so a secret never has to live there.if (parsed.username || parsed.password || parsed.search || parsed.hash) return nullconst root = parsed.toString().replace(/\/+$/, '')+ const discoverySuffix = sanitizedGatewayDiscoveryPath(discoveryPath) ?? '/v1/models'return {- discovery: `${root}/v1/models`,+ discovery: `${root}${discoverySuffix}`,openai: `${root}/openai/v1`,anthropic: `${root}/anthropic`}