Skip to content

Commit c520469

Browse files
authored
Keep picker order in the Claude availableModels allowlist
The Claude adapter's availableModels allowlist rebuilt the picker in the order the models were listed in settings, overriding the family/version sort (Codex, which does not apply the allowlist, was already correct). Re-sort the filtered list with the picker comparator so the allowlist only restricts which models appear, not their order. Generated-By: PostHog Code Task-Id: ea8239ab-8fc1-46b7-8dc6-d3661caf8800
1 parent 5fee4ab commit c520469

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/agent/src/adapters/claude/session/model-config.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ describe("applyAvailableModelsAllowlist", () => {
1919
).toEqual(rawModelOptions);
2020
});
2121

22+
it("reorders the allowlist to the picker order instead of the listed order", () => {
23+
expect(
24+
applyAvailableModelsAllowlist(rawModelOptions, [
25+
"claude-sonnet-4-6",
26+
"claude-opus-4-8",
27+
]).options,
28+
).toEqual([
29+
{ value: "claude-opus-4-8", name: "Claude Opus 4.8" },
30+
{ value: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },
31+
]);
32+
});
33+
2234
it("switches the current model when the previous one is filtered out", () => {
2335
expect(
2436
applyAvailableModelsAllowlist(rawModelOptions, ["claude-sonnet-4-6"]),

packages/agent/src/adapters/claude/session/model-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SessionConfigSelectOption } from "@agentclientprotocol/sdk";
2+
import { compareModelsForPicker } from "../../../gateway-models";
23

34
export interface ModelConfigOptions {
45
currentModelId: string;
@@ -30,6 +31,9 @@ export function applyAvailableModelsAllowlist(
3031

3132
if (filtered.length === 0) return modelOptions;
3233

34+
// The allowlist is a filter, not a display order: keep the picker's ordering.
35+
filtered.sort((a, b) => compareModelsForPicker(a.value, b.value));
36+
3337
const currentModelId = filtered.some(
3438
(o) => o.value === modelOptions.currentModelId,
3539
)

0 commit comments

Comments
 (0)