Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] preserve custom model slugs (#4168)

Maxwell Youngfa69f05b69d0
diff --git a/apps/server/src/provider/Layers/ClaudeProvider.ts b/apps/server/src/provider/Layers/ClaudeProvider.ts
index 94b24405e..ff0d19924 100644
--- a/apps/server/src/provider/Layers/ClaudeProvider.ts
+++ b/apps/server/src/provider/Layers/ClaudeProvider.ts
@@ -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,
);
diff --git a/apps/server/src/provider/Layers/CursorProvider.ts b/apps/server/src/provider/Layers/CursorProvider.ts
index 063f2c1bf..fee4306c4 100644
--- a/apps/server/src/provider/Layers/CursorProvider.ts
+++ b/apps/server/src/provider/Layers/CursorProvider.ts
@@ -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,
),
diff --git a/apps/server/src/provider/Layers/GrokProvider.ts b/apps/server/src/provider/Layers/GrokProvider.ts
index 33f61ad97..934eecdb5 100644
--- a/apps/server/src/provider/Layers/GrokProvider.ts
+++ b/apps/server/src/provider/Layers/GrokProvider.ts
@@ -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(
diff --git a/apps/server/src/provider/Layers/OpenCodeProvider.ts b/apps/server/src/provider/Layers/OpenCodeProvider.ts
index 2c6335001..21014e33f 100644
--- a/apps/server/src/provider/Layers/OpenCodeProvider.ts
+++ b/apps/server/src/provider/Layers/OpenCodeProvider.ts
@@ -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,
);
diff --git a/apps/server/src/provider/providerSnapshot.test.ts b/apps/server/src/provider/providerSnapshot.test.ts
index abe138fdf..011572780 100644
--- a/apps/server/src/provider/providerSnapshot.test.ts
+++ b/apps/server/src/provider/providerSnapshot.test.ts
@@ -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", () => {
diff --git a/apps/server/src/provider/providerSnapshot.ts b/apps/server/src/provider/providerSnapshot.ts
index dfe31ffdc..e741a7a2c 100644
--- a/apps/server/src/provider/providerSnapshot.ts
+++ b/apps/server/src/provider/providerSnapshot.ts
@@ -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;
}
diff --git a/apps/web/src/components/settings/ProviderModelsSection.tsx b/apps/web/src/components/settings/ProviderModelsSection.tsx
index f1100ab93..27d139975 100644
--- a/apps/web/src/components/settings/ProviderModelsSection.tsx
+++ b/apps/web/src/components/settings/ProviderModelsSection.tsx
@@ -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;
diff --git a/apps/web/src/modelSelection.test.ts b/apps/web/src/modelSelection.test.ts
index 3d973ccca..e8fc8a244 100644
--- a/apps/web/src/modelSelection.test.ts
+++ b/apps/web/src/modelSelection.test.ts
@@ -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 = {
diff --git a/apps/web/src/modelSelection.ts b/apps/web/src/modelSelection.ts
index 7ede9665a..f1d527880 100644
--- a/apps/web/src/modelSelection.ts
+++ b/apps/web/src/modelSelection.ts
@@ -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;
}
diff --git a/packages/shared/src/model.test.ts b/packages/shared/src/model.test.ts
index ee91e0b53..b055c255b 100644
--- a/packages/shared/src/model.test.ts
+++ b/packages/shared/src/model.test.ts
@@ -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");
+ });
+});
diff --git a/packages/shared/src/model.ts b/packages/shared/src/model.ts
index 9fdbd6c04..bdc0c0cc8 100644
--- a/packages/shared/src/model.ts
+++ b/packages/shared/src/model.ts
@@ -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,