[codex] preserve custom model slugs (#4168)

This commit is contained in:
Maxwell Young authored and GitHub committed 2026-07-20 13:32:30 +02:00
1 parent c710167bde
commit fa69f05b69
11 files changed
+88 -58

No files matched your search

@@ -2,7 +2,6 @@ import {
type ClaudeSettings,
type ModelCapabilities,
type ModelSelection,
ProviderDriverKind,
type ServerProviderModel,
type ServerProviderSlashCommand,
} from "@t3tools/contracts";
@@ -44,7 +43,6 @@ const DEFAULT_CLAUDE_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabili
optionDescriptors: [],
});
const PROVIDER = ProviderDriverKind.make("claudeAgent");
const CLAUDE_PRESENTATION = {
displayName: "Claude",
showInteractionModeToggle: true,
@@ -691,7 +689,6 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
const checkedAt = DateTime.formatIso(yield* DateTime.now);
const allModels = providerModelsFromSettings(
BUILT_IN_MODELS,
PROVIDER,
claudeSettings.customModels,
DEFAULT_CLAUDE_MODEL_CAPABILITIES,
);
@@ -782,7 +779,6 @@ export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(
const models = providerModelsFromSettings(
getBuiltInClaudeModelsForVersion(parsedVersion),
PROVIDER,
claudeSettings.customModels,
DEFAULT_CLAUDE_MODEL_CAPABILITIES,
);
@@ -851,7 +847,6 @@ export const makePendingClaudeProvider = (
const checkedAt = yield* nowIso;
const models = providerModelsFromSettings(
BUILT_IN_MODELS,
PROVIDER,
claudeSettings.customModels,
DEFAULT_CLAUDE_MODEL_CAPABILITIES,
);
@@ -8,7 +8,6 @@ import type {
ServerProviderModel,
ServerProviderState,
} from "@t3tools/contracts";
import { ProviderDriverKind } from "@t3tools/contracts";
import type * as EffectAcpSchema from "effect-acp/schema";
import { causeErrorTag } from "@t3tools/shared/observability";
import * as Crypto from "effect/Crypto";
@@ -51,7 +50,6 @@ import { CursorListAvailableModelsResponse } from "../acp/CursorAcpExtension.ts"
const decodeCursorListAvailableModelsResponse = Schema.decodeUnknownEffect(
CursorListAvailableModelsResponse,
);
const PROVIDER = ProviderDriverKind.make("cursor");
const CURSOR_PRESENTATION = {
displayName: "Cursor",
badgeLabel: "Early Access",
@@ -576,7 +574,7 @@ export const discoverCursorModelsViaAcp = (
export function getCursorFallbackModels(
cursorSettings: Pick<CursorSettings, "customModels">,
): ReadonlyArray<ServerProviderModel> {
return providerModelsFromSettings([], PROVIDER, cursorSettings.customModels, EMPTY_CAPABILITIES);
return providerModelsFromSettings([], cursorSettings.customModels, EMPTY_CAPABILITIES);
}
/** Timeout for `agent about` — it's slower than a simple `--version` probe. */
@@ -638,7 +636,6 @@ export function buildCursorProviderSnapshot(input: {
checkedAt: input.checkedAt,
models: providerModelsFromSettings(
input.discoveredModels ?? [],
PROVIDER,
input.cursorSettings.customModels,
EMPTY_CAPABILITIES,
),
@@ -1,7 +1,6 @@
import {
type GrokSettings,
type ModelCapabilities,
ProviderDriverKind,
type ServerProvider,
type ServerProviderModel,
} from "@t3tools/contracts";
@@ -38,7 +37,6 @@ const GROK_PRESENTATION = {
showInteractionModeToggle: false,
requiresNewThreadForModelChange: true,
} as const;
const PROVIDER = ProviderDriverKind.make("grok");
const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
optionDescriptors: [],
});
@@ -98,12 +96,7 @@ function grokModelsFromSettings(
customModels: ReadonlyArray<string> | undefined,
builtInModels: ReadonlyArray<ServerProviderModel> = GROK_BUILT_IN_MODELS,
): ReadonlyArray<ServerProviderModel> {
return providerModelsFromSettings(
builtInModels,
PROVIDER,
customModels ?? [],
EMPTY_CAPABILITIES,
);
return providerModelsFromSettings(builtInModels, customModels ?? [], EMPTY_CAPABILITIES);
}
function buildGrokDiscoveredModelsFromSessionModelState(
@@ -1,5 +1,4 @@
import {
ProviderDriverKind,
type ModelCapabilities,
type OpenCodeSettings,
type ServerProviderModel,
@@ -25,7 +24,6 @@ import {
} from "../opencodeRuntime.ts";
import type { Agent, ProviderListResponse } from "@opencode-ai/sdk/v2";
const PROVIDER = ProviderDriverKind.make("opencode");
const OPENCODE_PRESENTATION = {
displayName: "OpenCode",
showInteractionModeToggle: false,
@@ -259,7 +257,6 @@ export const makePendingOpenCodeProvider = (
const checkedAt = yield* Effect.map(DateTime.now, DateTime.formatIso);
const models = providerModelsFromSettings(
[],
PROVIDER,
openCodeSettings.customModels,
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
);
@@ -319,12 +316,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
presentation: OPENCODE_PRESENTATION,
enabled: openCodeSettings.enabled,
checkedAt,
models: providerModelsFromSettings(
[],
PROVIDER,
customModels,
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
),
models: providerModelsFromSettings([], customModels, DEFAULT_OPENCODE_MODEL_CAPABILITIES),
probe: {
installed: failure.installed,
version,
@@ -340,12 +332,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
presentation: OPENCODE_PRESENTATION,
enabled: false,
checkedAt,
models: providerModelsFromSettings(
[],
PROVIDER,
customModels,
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
),
models: providerModelsFromSettings([], customModels, DEFAULT_OPENCODE_MODEL_CAPABILITIES),
probe: {
installed: false,
version: null,
@@ -391,12 +378,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
presentation: OPENCODE_PRESENTATION,
enabled: openCodeSettings.enabled,
checkedAt,
models: providerModelsFromSettings(
[],
PROVIDER,
customModels,
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
),
models: providerModelsFromSettings([], customModels, DEFAULT_OPENCODE_MODEL_CAPABILITIES),
probe: {
installed: true,
version,
@@ -444,7 +426,6 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
const models = providerModelsFromSettings(
flattenOpenCodeModels(inventoryExit.value),
PROVIDER,
customModels,
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
);
@@ -1,5 +1,5 @@
import { describe, expect, it } from "@effect/vitest";
import { ProviderDriverKind, type ModelCapabilities } from "@t3tools/contracts";
import type { ModelCapabilities } from "@t3tools/contracts";
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
import { createModelCapabilities } from "@t3tools/shared/model";
import * as Effect from "effect/Effect";
@@ -38,7 +38,6 @@ describe("providerModelsFromSettings", () => {
it("applies the provided capabilities to custom models", () => {
const models = providerModelsFromSettings(
[],
ProviderDriverKind.make("opencode"),
["openai/gpt-5"],
OPENCODE_CUSTOM_MODEL_CAPABILITIES,
);
@@ -52,6 +51,25 @@ describe("providerModelsFromSettings", () => {
},
]);
});
it("preserves a custom slug that collides with a provider alias", () => {
const capabilities = createModelCapabilities({ optionDescriptors: [] });
const models = providerModelsFromSettings(
[
{
slug: "claude-opus-4-8",
name: "Claude Opus 4.8",
isCustom: false,
capabilities,
},
],
[" opus "],
capabilities,
);
expect(models.map((model) => model.slug)).toEqual(["claude-opus-4-8", "opus"]);
expect(models[1]?.isCustom).toBe(true);
});
});
describe("ProviderCommandNotFoundError", () => {
+2 -3
View File
@@ -13,7 +13,7 @@ import * as PlatformError from "effect/PlatformError";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import { normalizeModelSlug } from "@t3tools/shared/model";
import { normalizeCustomModelSlug } from "@t3tools/shared/model";
import { isWindowsCommandNotFound } from "../processRunner.ts";
import { createProviderVersionAdvisory } from "./providerMaintenance.ts";
import { collectUint8StreamText } from "../stream/collectUint8StreamText.ts";
@@ -140,7 +140,6 @@ export function parseGenericCliVersion(output: string): string | null {
export function providerModelsFromSettings(
builtInModels: ReadonlyArray<ServerProviderModel>,
provider: ProviderDriverKind,
customModels: ReadonlyArray<string>,
customModelCapabilities: ModelCapabilities,
): ReadonlyArray<ServerProviderModel> {
@@ -149,7 +148,7 @@ export function providerModelsFromSettings(
const customEntries: ServerProviderModel[] = [];
for (const candidate of customModels) {
const normalized = normalizeModelSlug(candidate, provider);
const normalized = normalizeCustomModelSlug(candidate);
if (!normalized || seen.has(normalized)) {
continue;
}
@@ -16,7 +16,7 @@ import {
type ProviderInstanceId,
type ServerProviderModel,
} from "@t3tools/contracts";
import { normalizeModelSlug } from "@t3tools/shared/model";
import { normalizeCustomModelSlug } from "@t3tools/shared/model";
import { cn } from "../../lib/utils";
import { sortModelsForProviderInstance } from "../../modelOrdering";
@@ -111,7 +111,7 @@ export function ProviderModelsSection({
}, [favoriteModelSet, modelOrder, models]);
const handleAdd = () => {
const normalized = driverKind ? normalizeModelSlug(input, driverKind) : input.trim() || null;
const normalized = normalizeCustomModelSlug(input);
if (!normalized) {
setError("Enter a model slug.");
return;
+33
View File
@@ -101,6 +101,39 @@ describe("instance-scoped model selection", () => {
).toBe("openai/gpt-5.5");
});
it("preserves a custom slug that collides with a provider alias", () => {
const providers = [
provider({
provider: ProviderDriverKind.make("claudeAgent"),
instanceId: "claude_openrouter",
models: ["claude-opus-4-8"],
}),
];
const settings: UnifiedSettings = {
...settingsWithProviderInstances(),
providerInstances: {
...settingsWithProviderInstances().providerInstances,
[ProviderInstanceId.make("claude_openrouter")]: {
driver: ProviderDriverKind.make("claudeAgent"),
config: { customModels: ["opus"] },
},
},
};
const openrouter = deriveProviderInstanceEntries(providers)[0]!;
expect(
getAppModelOptionsForInstance(settings, openrouter).map((option) => option.slug),
).toEqual(["claude-opus-4-8", "opus"]);
expect(
resolveAppModelSelectionForInstance(
ProviderInstanceId.make("claude_openrouter"),
settings,
providers,
"opus",
),
).toBe("opus");
});
it("includes Grok custom models from the selected provider instance", () => {
const providers = [provider({ provider: ProviderDriverKind.make("grok"), instanceId: "grok" })];
const settings: UnifiedSettings = {
+4 -6
View File
@@ -9,7 +9,7 @@ import {
} from "@t3tools/contracts";
import {
createModelSelection,
normalizeModelSlug,
normalizeCustomModelSlug,
resolveSelectableModel,
} from "@t3tools/shared/model";
import { getComposerProviderState } from "./components/chat/composerProviderState";
@@ -117,13 +117,12 @@ function applyInstanceModelPreferences(
export function normalizeCustomModelSlugs(
models: Iterable<string | null | undefined>,
builtInModelSlugs: ReadonlySet<string>,
provider: ProviderDriverKind = ProviderDriverKind.make("codex"),
): string[] {
const normalizedModels: string[] = [];
const seen = new Set<string>();
for (const candidate of models) {
const normalized = normalizeModelSlug(candidate, provider);
const normalized = normalizeCustomModelSlug(candidate);
if (
!normalized ||
normalized.length > MAX_CUSTOM_MODEL_LENGTH ||
@@ -163,7 +162,7 @@ export function getAppModelOptions(
// see the user's authored custom models.
const defaultInstanceId = defaultInstanceIdForDriver(provider);
const customModels = readInstanceCustomModels(settings, defaultInstanceId, provider);
for (const slug of normalizeCustomModelSlugs(customModels, builtInModelSlugs, provider)) {
for (const slug of normalizeCustomModelSlugs(customModels, builtInModelSlugs)) {
if (seen.has(slug)) {
continue;
}
@@ -206,8 +205,7 @@ export function getAppModelOptionsForInstance(
);
const customModels = readInstanceCustomModels(settings, entry.instanceId, entry.driverKind);
const normalizer = entry.driverKind;
for (const slug of normalizeCustomModelSlugs(customModels, builtInModelSlugs, normalizer)) {
for (const slug of normalizeCustomModelSlugs(customModels, builtInModelSlugs)) {
if (seen.has(slug)) {
continue;
}
+12 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vite-plus/test";
import { ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
import { ProviderDriverKind, ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
import {
buildProviderOptionSelectionsFromDescriptors,
@@ -10,6 +10,8 @@ import {
getProviderOptionDescriptors,
getProviderOptionBooleanSelectionValue,
getProviderOptionStringSelectionValue,
normalizeCustomModelSlug,
normalizeModelSlug,
} from "./model.ts";
const codexCaps: ModelCapabilities = createModelCapabilities({
@@ -144,3 +146,12 @@ describe("descriptor helpers", () => {
expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
});
});
describe("model slug normalization", () => {
it("preserves exact custom slugs instead of expanding provider aliases", () => {
const claude = ProviderDriverKind.make("claudeAgent");
expect(normalizeModelSlug("opus", claude)).toBe("claude-opus-4-8");
expect(normalizeCustomModelSlug(" opus ")).toBe("opus");
});
});
+10 -5
View File
@@ -236,11 +236,7 @@ export function normalizeModelSlug(
model: string | null | undefined,
provider: ProviderDriverKind = DEFAULT_PROVIDER_DRIVER_KIND,
): string | null {
if (typeof model !== "string") {
return null;
}
const trimmed = model.trim();
const trimmed = normalizeCustomModelSlug(model);
if (!trimmed) {
return null;
}
@@ -252,6 +248,15 @@ export function normalizeModelSlug(
return typeof aliased === "string" ? aliased : trimmed;
}
/** Custom model identifiers are provider-owned, so only trim them; never expand aliases. */
export function normalizeCustomModelSlug(model: string | null | undefined): string | null {
if (typeof model !== "string") {
return null;
}
return model.trim() || null;
}
export function resolveSelectableModel(
provider: ProviderDriverKind,
value: string | null | undefined,