Skip to content

Commit 44c343b

Browse files
committed
Handle uncataloged current models in config
1 parent 0da3d7a commit 44c343b

3 files changed

Lines changed: 55 additions & 8 deletions

File tree

src/CodexAcpServer.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ export class CodexAcpServer {
694694
private applyModelChange(sessionState: SessionState, value: string): void {
695695
const model = sessionState.availableModels.find(m => m.id === value);
696696
if (!model) {
697+
const currentModel = ModelId.fromString(sessionState.currentModelId).model;
698+
if (value === currentModel) {
699+
return;
700+
}
697701
throw RequestError.invalidParams();
698702
}
699703
const currentEffort = ModelId.fromString(sessionState.currentModelId).effort;
@@ -763,12 +767,17 @@ export class CodexAcpServer {
763767

764768
private createSessionConfigOptions(sessionState: SessionState): Array<acp.SessionConfigOption> {
765769
const currentModelId = ModelId.fromString(sessionState.currentModelId);
766-
return [
770+
const configOptions = [
767771
sessionState.agentMode.toConfigOption(),
768772
createModelConfigOption(sessionState.availableModels, currentModelId.model),
769-
createReasoningEffortConfigOption(sessionState.supportedReasoningEfforts, currentModelId.effort),
770-
createFastModeConfigOption(sessionState.fastModeEnabled),
771773
];
774+
if (sessionState.supportedReasoningEfforts.length > 0) {
775+
configOptions.push(
776+
createReasoningEffortConfigOption(sessionState.supportedReasoningEfforts, currentModelId.effort),
777+
);
778+
}
779+
configOptions.push(createFastModeConfigOption(sessionState.fastModeEnabled));
780+
return configOptions;
772781
}
773782

774783
private createSessionConfigOptionsResponse(sessionState: SessionState): {

src/ModelConfigOption.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@ export function findSupportedEffort(
1414
}
1515

1616
export function createModelConfigOption(availableModels: Array<Model>, currentBaseModelId: string): SessionConfigOption {
17+
const options: Array<{ value: string; name: string; description: string | null }> = availableModels.map(model => ({
18+
value: model.id,
19+
name: model.displayName,
20+
description: model.description,
21+
}));
22+
if (!availableModels.some(model => model.id === currentBaseModelId)) {
23+
options.unshift({
24+
value: currentBaseModelId,
25+
name: currentBaseModelId,
26+
description: null,
27+
});
28+
}
29+
1730
return {
1831
id: MODEL_CONFIG_ID,
1932
name: "Model",
2033
description: "Model Codex uses for the session",
2134
category: "model",
2235
type: "select",
2336
currentValue: currentBaseModelId,
24-
options: availableModels.map(model => ({
25-
value: model.id,
26-
name: model.displayName,
27-
description: model.description,
28-
})),
37+
options,
2938
};
3039
}
3140

src/__tests__/CodexACPAgent/session-config-options.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ describe("Session config options", () => {
9090
);
9191
});
9292

93+
it("shows the current uncataloged model as its own selectable option", async () => {
94+
const {fast, slow} = buildModels();
95+
const {codexAcpAgent, response} = await createSession("custom-model[high]", [fast, slow]);
96+
97+
const ids = response.configOptions?.map(o => o.id);
98+
expect(ids).toEqual([MODE_CONFIG_ID, MODEL_CONFIG_ID, "fast-mode"]);
99+
100+
const modelOption = response.configOptions?.find(o => o.id === MODEL_CONFIG_ID);
101+
expect(modelOption).toMatchObject({
102+
category: "model",
103+
currentValue: "custom-model",
104+
type: "select",
105+
options: [
106+
{value: "custom-model", name: "custom-model", description: null},
107+
{value: "fast-model", name: "Fast model", description: "Frontier"},
108+
{value: "slow-model", name: "Slow model", description: "Strong"},
109+
],
110+
});
111+
expect(response.configOptions?.some(o => o.id === REASONING_EFFORT_CONFIG_ID)).toBe(false);
112+
113+
await codexAcpAgent.setSessionConfigOption({
114+
sessionId: "session-id",
115+
configId: MODEL_CONFIG_ID,
116+
value: "custom-model",
117+
});
118+
119+
expect(codexAcpAgent.getSessionState("session-id").currentModelId).toBe("custom-model[high]");
120+
});
121+
93122
it("keeps the legacy models list as combined model/effort entries", async () => {
94123
const {fast, slow} = buildModels();
95124
const {response} = await createSession("fast-model[medium]", [fast, slow]);

0 commit comments

Comments
 (0)