Skip to content

Commit 5660c3b

Browse files
committed
feat(sidecar): unified picker candidate set consumed by the vision options (#2188)
pickerVisibleSidecarCandidates = management picker rows (disabled rows dropped) ∪ auth slots, de-duplicated with the slot flag winning; a catalog outage degrades to the logged-in slots instead of an empty 500. visionSidecarCandidates applies rule 2 (drop provably text-only) on top. visionCandidateRows now wraps the unified set, so a hidden Luna/Haiku stays offerable for a logged-in side and the catalog-wide expansion of visionEligibleModelOptions is bounded by picker visibility.
1 parent 377f229 commit 5660c3b

3 files changed

Lines changed: 213 additions & 11 deletions

File tree

‎src/server/management/vision-sidecar-options.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
type VisionSidecarBackend,
1818
} from "../../vision/eligibility";
1919
import { listOpenAiForwardSidecarCandidates } from "../../providers/openai-sidecar";
20-
import { listManagementModelRows } from "./model-rows";
20+
import { pickerVisibleSidecarCandidates, visionSidecarCandidates } from "../../sidecar/candidates";
21+
import { resolveSidecarAuth } from "../../sidecar/auth";
2122

2223
/**
2324
* Backends whose executor could actually run: openai forward, anthropic OAuth.
@@ -41,17 +42,20 @@ export function enabledVisionBackends(
4142
return backends.length > 0 ? backends : ["openai", "anthropic"];
4243
}
4344

44-
/** Visible catalog rows in the shape the eligibility predicate consumes. */
45+
/**
46+
* Visible catalog rows in the shape the eligibility predicate consumes.
47+
* Now sourced from the unified picker set (#2188): picker-visible rows ∪ auth
48+
* slots, then rule 2 (− provably text-only). The auth slots are what keep a
49+
* hidden Luna/Haiku offerable for a logged-in side.
50+
*/
4551
export async function visionCandidateRows(config: OcxConfig): Promise<VisionCandidateModel[]> {
46-
let rows: Awaited<ReturnType<typeof listManagementModelRows>> = [];
47-
// A catalog outage must not 500 the settings route nor reject a write; with []
48-
// the option list degrades to the baselines, which is the intended floor.
49-
try { rows = await listManagementModelRows(config); } catch { rows = []; }
50-
return rows.filter(row => row.disabled !== true).map(row => ({
51-
provider: row.provider,
52-
id: row.id,
53-
...(row.inputModalities ? { inputModalities: row.inputModalities } : {}),
54-
...(row.native ? { native: true } : {}),
52+
const auth = resolveSidecarAuth(config);
53+
const all = await pickerVisibleSidecarCandidates(config, auth);
54+
return visionSidecarCandidates(config, all).map(candidate => ({
55+
provider: candidate.provider,
56+
id: candidate.id,
57+
...(candidate.inputModalities ? { inputModalities: candidate.inputModalities } : {}),
58+
...(candidate.native ? { native: true } : {}),
5559
}));
5660
}
5761

‎src/sidecar/candidates.ts‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* The unified picker-visibility candidate set both sidecars consume (#2188).
3+
*
4+
* Rule 1 (picker): a model may be OFFERED as a sidecar backend only if the
5+
* management picker would show it — the same `listManagementModelRows` rows
6+
* the GUI Models tab renders, minus disabled rows. Rule 1's only exception is
7+
* the auth slots: a logged-in side keeps its fixed slot model (Luna/Haiku)
8+
* even when the picker hides it, because the slot is the login's entitlement.
9+
*
10+
* Vision additionally applies rule 2 (− provably text-only); web-search
11+
* applies its own rule 2 (∩ probed backend with an executor) in
12+
* src/web-search/backends.ts. Both start from THIS set so the two sidecars
13+
* cannot diverge on what "visible" means.
14+
*/
15+
import type { OcxConfig } from "../types";
16+
import { listManagementModelRows } from "../server/management/model-rows";
17+
import { modelAcceptsImageInput, type VisionCandidateModel } from "../vision/eligibility";
18+
import { sidecarAuthSlots, type SidecarAuthState } from "./auth";
19+
20+
export interface SidecarCandidate {
21+
provider: string;
22+
id: string;
23+
native?: boolean;
24+
inputModalities?: string[];
25+
/** True when this row is an auth-slot entitlement rather than a picker row. */
26+
authSlot?: boolean;
27+
}
28+
29+
/**
30+
* (picker-visible rows) ∪ (auth slots). De-duplicated by provider+id with the
31+
* auth-slot flag winning, so a slot model that is ALSO picker-visible still
32+
* reads as slot-backed. A catalog outage degrades to slots only — the settings
33+
* routes must not 500 and must keep the logged-in floor populated.
34+
*/
35+
export async function pickerVisibleSidecarCandidates(
36+
config: OcxConfig,
37+
auth: SidecarAuthState,
38+
): Promise<SidecarCandidate[]> {
39+
let rows: Awaited<ReturnType<typeof listManagementModelRows>> = [];
40+
try { rows = await listManagementModelRows(config); } catch { rows = []; }
41+
const byKey = new Map<string, SidecarCandidate>();
42+
for (const row of rows) {
43+
if (row.disabled === true) continue;
44+
byKey.set(`${row.provider}/${row.id}`, {
45+
provider: row.provider,
46+
id: row.id,
47+
...(row.inputModalities ? { inputModalities: row.inputModalities } : {}),
48+
...(row.native ? { native: true } : {}),
49+
});
50+
}
51+
for (const slot of sidecarAuthSlots(auth)) {
52+
byKey.set(`${slot.provider}/${slot.id}`, {
53+
provider: slot.provider,
54+
id: slot.id,
55+
// Slot models are known image-capable; their only exclusion path is the
56+
// provider's explicit consumer list (same stance as baselineCandidate).
57+
inputModalities: ["text", "image"],
58+
authSlot: true,
59+
});
60+
}
61+
return [...byKey.values()];
62+
}
63+
64+
/**
65+
* Rule 2 for vision: drop rows PROVABLY text-only. Unknown stays eligible —
66+
* the picker filter (rule 1) already bounded the set, so permissive-unknown
67+
* no longer expands to the whole catalog.
68+
*/
69+
export function visionSidecarCandidates(
70+
config: Pick<OcxConfig, "providers">,
71+
all: readonly SidecarCandidate[],
72+
): SidecarCandidate[] {
73+
return all.filter(candidate => modelAcceptsImageInput(config, toVisionCandidate(candidate)) !== false);
74+
}
75+
76+
function toVisionCandidate(candidate: SidecarCandidate): VisionCandidateModel {
77+
return {
78+
provider: candidate.provider,
79+
id: candidate.id,
80+
...(candidate.inputModalities ? { inputModalities: candidate.inputModalities } : {}),
81+
...(candidate.native ? { native: true } : {}),
82+
};
83+
}

‎tests/sidecar-candidates.test.ts‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { afterEach, describe, expect, mock, test } from "bun:test";
2+
import * as storeModule from "../src/oauth/store";
3+
import * as usabilityModule from "../src/codex/account-usability";
4+
import * as modelRowsModule from "../src/server/management/model-rows";
5+
6+
let accountSets: Record<string, { accounts: Array<{ id: string; needsReauth?: boolean }>; activeAccountId?: string }> = {};
7+
let usableCodexAccounts: Set<string> = new Set();
8+
let managementRows: Array<Record<string, unknown>> | Error = [];
9+
10+
mock.module("../src/oauth/store", () => ({
11+
...storeModule,
12+
getAccountSet: (provider: string) => accountSets[provider] ?? null,
13+
}));
14+
mock.module("../src/codex/account-usability", () => ({
15+
...usabilityModule,
16+
isCodexAccountUsable: (_config: unknown, accountId: string) => usableCodexAccounts.has(accountId),
17+
}));
18+
mock.module("../src/server/management/model-rows", () => ({
19+
...modelRowsModule,
20+
listManagementModelRows: async () => {
21+
if (managementRows instanceof Error) throw managementRows;
22+
return managementRows;
23+
},
24+
}));
25+
26+
import { pickerVisibleSidecarCandidates, visionSidecarCandidates } from "../src/sidecar/candidates";
27+
import { resolveSidecarAuth } from "../src/sidecar/auth";
28+
import { MAIN_CODEX_ACCOUNT_ID } from "../src/codex/account-id";
29+
import type { OcxConfig, OcxProviderConfig } from "../src/types";
30+
31+
const forward: OcxProviderConfig = { adapter: "openai-responses", baseUrl: "https://chatgpt.com/backend-api/codex", authMode: "forward" };
32+
const anthropicOAuth: OcxProviderConfig = { adapter: "anthropic", baseUrl: "https://api.anthropic.com", authMode: "oauth" };
33+
34+
function config(overrides: Partial<OcxConfig> = {}): OcxConfig {
35+
return { port: 10100, defaultProvider: "openai", providers: { openai: forward }, ...overrides };
36+
}
37+
38+
afterEach(() => {
39+
accountSets = {};
40+
usableCodexAccounts = new Set();
41+
managementRows = [];
42+
});
43+
44+
function loginBoth(): void {
45+
usableCodexAccounts.add(MAIN_CODEX_ACCOUNT_ID);
46+
accountSets = { claude: { accounts: [{ id: "a1" }], activeAccountId: "a1" } };
47+
}
48+
49+
describe("pickerVisibleSidecarCandidates", () => {
50+
test("disabled rows disappear; hidden Luna survives via the auth slot", async () => {
51+
loginBoth();
52+
managementRows = [
53+
{ provider: "openai", id: "gpt-5.6-luna", disabled: true, native: true },
54+
{ provider: "openai", id: "gpt-5.6-terra", disabled: false, native: true },
55+
{ provider: "routed", id: "some-model", disabled: false },
56+
];
57+
const cfg = config({ providers: { openai: forward, claude: anthropicOAuth } });
58+
const all = await pickerVisibleSidecarCandidates(cfg, resolveSidecarAuth(cfg));
59+
const ids = all.map(c => `${c.provider}/${c.id}`).sort();
60+
expect(ids).toEqual([
61+
"claude/claude-haiku-4-5",
62+
"openai/gpt-5.6-luna",
63+
"openai/gpt-5.6-terra",
64+
"routed/some-model",
65+
]);
66+
expect(all.find(c => c.id === "gpt-5.6-luna")?.authSlot).toBe(true);
67+
});
68+
69+
test("picker-visible slot model keeps the slot flag (slot wins de-dup)", async () => {
70+
loginBoth();
71+
managementRows = [{ provider: "openai", id: "gpt-5.6-luna", disabled: false, native: true }];
72+
const cfg = config({ providers: { openai: forward, claude: anthropicOAuth } });
73+
const all = await pickerVisibleSidecarCandidates(cfg, resolveSidecarAuth(cfg));
74+
expect(all.filter(c => c.id === "gpt-5.6-luna")).toHaveLength(1);
75+
expect(all.find(c => c.id === "gpt-5.6-luna")?.authSlot).toBe(true);
76+
});
77+
78+
test("catalog outage degrades to auth slots only, not a 500", async () => {
79+
loginBoth();
80+
managementRows = new Error("catalog down");
81+
const cfg = config({ providers: { openai: forward, claude: anthropicOAuth } });
82+
const all = await pickerVisibleSidecarCandidates(cfg, resolveSidecarAuth(cfg));
83+
expect(all.map(c => c.id).sort()).toEqual(["claude-haiku-4-5", "gpt-5.6-luna"]);
84+
});
85+
86+
test("no logins and empty catalog -> empty set", async () => {
87+
const all = await pickerVisibleSidecarCandidates(config(), resolveSidecarAuth(config()));
88+
expect(all).toEqual([]);
89+
});
90+
});
91+
92+
describe("visionSidecarCandidates (rule 2: − provably text-only)", () => {
93+
test("provably text-only row excluded; unknown stays; slots stay", async () => {
94+
loginBoth();
95+
managementRows = [
96+
{ provider: "routed", id: "text-model", disabled: false, inputModalities: ["text"] },
97+
{ provider: "routed", id: "unknown-model", disabled: false },
98+
];
99+
const cfg = config({ providers: { openai: forward, claude: anthropicOAuth } });
100+
const all = await pickerVisibleSidecarCandidates(cfg, resolveSidecarAuth(cfg));
101+
const vision = visionSidecarCandidates(cfg, all);
102+
const ids = vision.map(c => c.id).sort();
103+
expect(ids).toEqual(["claude-haiku-4-5", "gpt-5.6-luna", "unknown-model"]);
104+
});
105+
106+
test("noVisionModels consumer listing beats the slot's advertised modalities", async () => {
107+
loginBoth();
108+
const blindLuna: OcxProviderConfig = { ...forward, noVisionModels: ["gpt-5.6-luna"] };
109+
const cfg = config({ providers: { openai: blindLuna, claude: anthropicOAuth } });
110+
const all = await pickerVisibleSidecarCandidates(cfg, resolveSidecarAuth(cfg));
111+
const vision = visionSidecarCandidates(cfg, all);
112+
expect(vision.map(c => c.id)).not.toContain("gpt-5.6-luna");
113+
expect(vision.map(c => c.id)).toContain("claude-haiku-4-5");
114+
});
115+
});

0 commit comments

Comments
 (0)