From a9aa5c4a057c1a5cb9fbdd5c4170809186cc88ad Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 25 Mar 2026 14:26:17 -0700 Subject: [PATCH] Centralize provider settings under server authority - Move Codex and Claude config lookups to `settings.providers` - Update web composer, settings UI, and model selection to use unified settings - Refresh browser fixtures and contracts for the new settings shape --- .../src/git/Layers/ClaudeTextGeneration.ts | 2 +- .../src/git/Layers/CodexTextGeneration.ts | 2 +- apps/server/src/serverSettings.ts | 14 +- apps/web/src/appSettings.test.ts | 266 ------------------ apps/web/src/components/ChatView.browser.tsx | 11 +- apps/web/src/components/ChatView.tsx | 13 +- .../components/KeybindingsToast.browser.tsx | 8 +- .../components/chat/TraitsPicker.browser.tsx | 7 +- apps/web/src/composerDraftStore.ts | 15 +- apps/web/src/modelSelection.ts | 77 +---- apps/web/src/routes/_chat.settings.tsx | 137 +++++---- packages/contracts/src/server.ts | 13 +- 12 files changed, 137 insertions(+), 428 deletions(-) delete mode 100644 apps/web/src/appSettings.test.ts diff --git a/apps/server/src/git/Layers/ClaudeTextGeneration.ts b/apps/server/src/git/Layers/ClaudeTextGeneration.ts index 66fb3cbed7..a85ed3f90c 100644 --- a/apps/server/src/git/Layers/ClaudeTextGeneration.ts +++ b/apps/server/src/git/Layers/ClaudeTextGeneration.ts @@ -90,7 +90,7 @@ const makeClaudeTextGeneration = Effect.gen(function* () { const claudeSettings = yield* Effect.map( serverSettingsService.getSettings, - (settings) => settings.claude, + (settings) => settings.providers.claudeAgent, ).pipe(Effect.catch(() => Effect.undefined)); const runClaudeCommand = Effect.gen(function* () { diff --git a/apps/server/src/git/Layers/CodexTextGeneration.ts b/apps/server/src/git/Layers/CodexTextGeneration.ts index 194cb990a9..2b16f675e5 100644 --- a/apps/server/src/git/Layers/CodexTextGeneration.ts +++ b/apps/server/src/git/Layers/CodexTextGeneration.ts @@ -142,7 +142,7 @@ const makeCodexTextGeneration = Effect.gen(function* () { const codexSettings = yield* Effect.map( serverSettingsService.getSettings, - (settings) => settings.codex, + (settings) => settings.providers.codex, ).pipe(Effect.catch(() => Effect.undefined)); const runCodexCommand = Effect.gen(function* () { diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index bb28ad7132..c156c31bed 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -89,18 +89,22 @@ export function deriveProviderStartOptions( settings: ServerSettings, ): ProviderStartOptions | undefined { const providerOptions: ProviderStartOptions = { - ...(settings.codex + ...(settings.providers.codex ? { codex: { - ...(settings.codex.binaryPath ? { binaryPath: settings.codex.binaryPath } : {}), - ...(settings.codex.homePath ? { homePath: settings.codex.homePath } : {}), + ...(settings.providers.codex.binaryPath + ? { binaryPath: settings.providers.codex.binaryPath } + : {}), + ...(settings.providers.codex.homePath + ? { homePath: settings.providers.codex.homePath } + : {}), }, } : {}), - ...(settings.claude + ...(settings.providers.claudeAgent ? { claudeAgent: { - binaryPath: settings.claude.binaryPath, + binaryPath: settings.providers.claudeAgent.binaryPath, }, } : {}), diff --git a/apps/web/src/appSettings.test.ts b/apps/web/src/appSettings.test.ts deleted file mode 100644 index d0d5ae53eb..0000000000 --- a/apps/web/src/appSettings.test.ts +++ /dev/null @@ -1,266 +0,0 @@ -import { describe, expect, it } from "vitest"; - -import { - DEFAULT_SIDEBAR_PROJECT_SORT_ORDER, - DEFAULT_SIDEBAR_THREAD_SORT_ORDER, - DEFAULT_TIMESTAMP_FORMAT, -} from "./appSettings"; -import { - getAppModelOptions, - getCustomModelOptionsByProvider, - getCustomModelsByProvider, - getCustomModelsForProvider, - getDefaultCustomModelsForProvider, - MODEL_PROVIDER_SETTINGS, - normalizeCustomModelSlugs, - patchCustomModels, - resolveAppModelSelectionState, - resolveAppModelSelection, -} from "./modelSelection"; - -describe("normalizeCustomModelSlugs", () => { - it("normalizes aliases, removes built-ins, and deduplicates values", () => { - expect( - normalizeCustomModelSlugs([ - " custom/internal-model ", - "gpt-5.3-codex", - "5.3", - "custom/internal-model", - "", - null, - ]), - ).toEqual(["custom/internal-model"]); - }); - - it("normalizes provider-specific aliases for claude", () => { - expect(normalizeCustomModelSlugs(["sonnet"], "claudeAgent")).toEqual([]); - expect(normalizeCustomModelSlugs(["claude/custom-sonnet"], "claudeAgent")).toEqual([ - "claude/custom-sonnet", - ]); - }); -}); - -describe("getAppModelOptions", () => { - it("appends saved custom models after the built-in options", () => { - const options = getAppModelOptions("codex", ["custom/internal-model"]); - - expect(options.map((option) => option.slug)).toEqual([ - "gpt-5.4", - "gpt-5.4-mini", - "gpt-5.3-codex", - "gpt-5.3-codex-spark", - "gpt-5.2-codex", - "gpt-5.2", - "custom/internal-model", - ]); - }); - - it("keeps the currently selected custom model available even if it is no longer saved", () => { - const options = getAppModelOptions("codex", [], "custom/selected-model"); - - expect(options.at(-1)).toEqual({ - slug: "custom/selected-model", - name: "custom/selected-model", - isCustom: true, - }); - }); - it("keeps a saved custom provider model available as an exact slug option", () => { - const options = getAppModelOptions("claudeAgent", ["claude/custom-opus"], "claude/custom-opus"); - - expect(options.some((option) => option.slug === "claude/custom-opus" && option.isCustom)).toBe( - true, - ); - }); -}); - -describe("resolveAppModelSelection", () => { - it("preserves saved custom model slugs instead of falling back to the default", () => { - expect( - resolveAppModelSelection( - "codex", - { codex: ["galapagos-alpha"], claudeAgent: [] }, - "galapagos-alpha", - ), - ).toBe("galapagos-alpha"); - }); - - it("falls back to the provider default when no model is selected", () => { - expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "")).toBe("gpt-5.4"); - }); - - it("resolves display names through the shared resolver", () => { - expect(resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "GPT-5.3 Codex")).toBe( - "gpt-5.3-codex", - ); - }); - - it("resolves aliases through the shared resolver", () => { - expect(resolveAppModelSelection("claudeAgent", { codex: [], claudeAgent: [] }, "sonnet")).toBe( - "claude-sonnet-4-6", - ); - }); - - it("resolves transient selected custom models included in app model options", () => { - expect( - resolveAppModelSelection("codex", { codex: [], claudeAgent: [] }, "custom/selected-model"), - ).toBe("custom/selected-model"); - }); -}); - -describe("timestamp format defaults", () => { - it("defaults timestamp format to locale", () => { - expect(DEFAULT_TIMESTAMP_FORMAT).toBe("locale"); - }); -}); - -describe("sidebar sort defaults", () => { - it("defaults project sorting to updated_at", () => { - expect(DEFAULT_SIDEBAR_PROJECT_SORT_ORDER).toBe("updated_at"); - }); - - it("defaults thread sorting to updated_at", () => { - expect(DEFAULT_SIDEBAR_THREAD_SORT_ORDER).toBe("updated_at"); - }); -}); - -describe("provider-specific custom models", () => { - it("includes provider-specific custom slugs in non-codex model lists", () => { - const claudeOptions = getAppModelOptions("claudeAgent", ["claude/custom-opus"]); - - expect(claudeOptions.some((option) => option.slug === "claude/custom-opus")).toBe(true); - }); -}); - -describe("provider-indexed custom model settings", () => { - const settings = { - customCodexModels: ["custom/codex-model"], - customClaudeModels: ["claude/custom-opus"], - } as const; - - it("exports one provider config per provider", () => { - expect(MODEL_PROVIDER_SETTINGS.map((config) => config.provider)).toEqual([ - "codex", - "claudeAgent", - ]); - }); - - it("reads custom models for each provider", () => { - expect(getCustomModelsForProvider(settings, "codex")).toEqual(["custom/codex-model"]); - expect(getCustomModelsForProvider(settings, "claudeAgent")).toEqual(["claude/custom-opus"]); - }); - - it("reads default custom models for each provider", () => { - const defaults = { - customCodexModels: ["default/codex-model"], - customClaudeModels: ["claude/default-opus"], - } as const; - - expect(getDefaultCustomModelsForProvider(defaults, "codex")).toEqual(["default/codex-model"]); - expect(getDefaultCustomModelsForProvider(defaults, "claudeAgent")).toEqual([ - "claude/default-opus", - ]); - }); - - it("patches custom models for codex", () => { - expect(patchCustomModels("codex", ["custom/codex-model"])).toEqual({ - customCodexModels: ["custom/codex-model"], - }); - }); - - it("patches custom models for claude", () => { - expect(patchCustomModels("claudeAgent", ["claude/custom-opus"])).toEqual({ - customClaudeModels: ["claude/custom-opus"], - }); - }); - - it("builds a complete provider-indexed custom model record", () => { - expect(getCustomModelsByProvider(settings)).toEqual({ - codex: ["custom/codex-model"], - claudeAgent: ["claude/custom-opus"], - }); - }); - - it("builds provider-indexed model options including custom models", () => { - const modelOptionsByProvider = getCustomModelOptionsByProvider(settings); - - expect( - modelOptionsByProvider.codex.some((option) => option.slug === "custom/codex-model"), - ).toBe(true); - expect( - modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude/custom-opus"), - ).toBe(true); - }); - - it("normalizes and deduplicates custom model options per provider", () => { - const modelOptionsByProvider = getCustomModelOptionsByProvider({ - customCodexModels: [" custom/codex-model ", "gpt-5.4", "custom/codex-model"], - customClaudeModels: [" sonnet ", "claude/custom-opus", "claude/custom-opus"], - }); - - expect( - modelOptionsByProvider.codex.filter((option) => option.slug === "custom/codex-model"), - ).toHaveLength(1); - expect(modelOptionsByProvider.codex.some((option) => option.slug === "gpt-5.4")).toBe(true); - expect( - modelOptionsByProvider.claudeAgent.filter((option) => option.slug === "claude/custom-opus"), - ).toHaveLength(1); - expect( - modelOptionsByProvider.claudeAgent.some((option) => option.slug === "claude-sonnet-4-6"), - ).toBe(true); - }); -}); - -describe("resolveAppModelSelectionState", () => { - it("falls back to the default git-writing codex selection", () => { - expect( - resolveAppModelSelectionState({ - customCodexModels: [], - customClaudeModels: [], - textGenerationModelSelection: undefined, - }), - ).toEqual({ - provider: "codex", - model: "gpt-5.4-mini", - }); - }); - - it("preserves the selected provider and resolves saved custom models", () => { - expect( - resolveAppModelSelectionState({ - customCodexModels: [], - customClaudeModels: ["claude/custom-haiku"], - textGenerationModelSelection: { - provider: "claudeAgent", - model: "claude/custom-haiku", - }, - }), - ).toEqual({ - provider: "claudeAgent", - model: "claude/custom-haiku", - }); - }); - - it("normalizes provider options against the resolved model capabilities", () => { - expect( - resolveAppModelSelectionState({ - customCodexModels: [], - customClaudeModels: [], - textGenerationModelSelection: { - provider: "claudeAgent", - model: "claude-haiku-4-5", - options: { - effort: "max", - thinking: false, - fastMode: true, - }, - }, - }), - ).toEqual({ - provider: "claudeAgent", - model: "claude-haiku-4-5", - options: { - thinking: false, - }, - }); - }); -}); diff --git a/apps/web/src/components/ChatView.browser.tsx b/apps/web/src/components/ChatView.browser.tsx index 3594efbdc5..1ace2d88a7 100644 --- a/apps/web/src/components/ChatView.browser.tsx +++ b/apps/web/src/components/ChatView.browser.tsx @@ -12,6 +12,7 @@ import { WS_CHANNELS, WS_METHODS, OrchestrationSessionStatus, + DEFAULT_SERVER_SETTINGS, } from "@t3tools/contracts"; import { RouterProvider, createMemoryHistory } from "@tanstack/react-router"; import { HttpResponse, http, ws } from "msw"; @@ -30,6 +31,7 @@ import { isMacPlatform } from "../lib/utils"; import { getRouter } from "../router"; import { useStore } from "../store"; import { estimateTimelineMessageHeight } from "./timelineHeight"; +import { DEFAULT_CLIENT_SETTINGS } from "~/clientSettings"; const THREAD_ID = "thread-browser-test" as ThreadId; const UUID_ROUTE_RE = /^\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; @@ -118,13 +120,8 @@ function createBaseServerConfig(): ServerConfig { ], availableEditors: [], settings: { - claude: { binaryPath: "" }, - codex: { binaryPath: "", homePath: "" }, - enableAssistantStreaming: false, - defaultThreadEnvMode: "local" as const, - customCodexModels: [], - customClaudeModels: [], - textGenerationModelSelection: { provider: "codex" as const, model: "gpt-5.4-mini" }, + ...DEFAULT_SERVER_SETTINGS, + ...DEFAULT_CLIENT_SETTINGS, }, }; } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 6fb6cea214..dc5e3ef3ed 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -121,11 +121,7 @@ import { SidebarTrigger } from "./ui/sidebar"; import { newCommandId, newMessageId, newThreadId } from "~/lib/utils"; import { readNativeApi } from "~/nativeApi"; import { useAppSettings } from "../appSettings"; -import { - getCustomModelOptionsByProvider, - getCustomModelsByProvider, - resolveAppModelSelection, -} from "../modelSelection"; +import { getCustomModelOptionsByProvider, resolveAppModelSelection } from "../modelSelection"; import { isTerminalFocused } from "../lib/terminalFocus"; import { type ComposerImageAttachment, @@ -610,13 +606,12 @@ export default function ChatView({ threadId }: ChatViewProps) { : null; const selectedProvider: ProviderKind = lockedProvider ?? selectedProviderByThreadId ?? threadProvider ?? "codex"; - const customModelsByProvider = useMemo(() => getCustomModelsByProvider(settings), [settings]); const { modelOptions: composerModelOptions, selectedModel } = useEffectiveComposerModelState({ threadId, selectedProvider, threadModelSelection: activeThread?.modelSelection, projectModelSelection: activeProject?.defaultModelSelection, - customModelsByProvider, + settings, }); const composerProviderState = useMemo( () => @@ -3100,7 +3095,7 @@ export default function ChatView({ threadId }: ChatViewProps) { scheduleComposerFocus(); return; } - const resolvedModel = resolveAppModelSelection(provider, customModelsByProvider, model); + const resolvedModel = resolveAppModelSelection(provider, settings, model); const nextModelSelection: ModelSelection = { provider, model: resolvedModel, @@ -3115,7 +3110,7 @@ export default function ChatView({ threadId }: ChatViewProps) { scheduleComposerFocus, setComposerDraftModelSelection, setStickyComposerModelSelection, - customModelsByProvider, + settings, ], ); const setPromptFromTraits = useCallback( diff --git a/apps/web/src/components/KeybindingsToast.browser.tsx b/apps/web/src/components/KeybindingsToast.browser.tsx index 8d674a2a90..c2ff2b1467 100644 --- a/apps/web/src/components/KeybindingsToast.browser.tsx +++ b/apps/web/src/components/KeybindingsToast.browser.tsx @@ -54,13 +54,13 @@ function createBaseServerConfig(): ServerConfig { ], availableEditors: [], settings: { - claude: { binaryPath: "" }, - codex: { binaryPath: "", homePath: "" }, enableAssistantStreaming: false, defaultThreadEnvMode: "local" as const, - customCodexModels: [], - customClaudeModels: [], textGenerationModelSelection: { provider: "codex" as const, model: "gpt-5.4-mini" }, + providers: { + codex: { binaryPath: "", homePath: "", customModels: [] }, + claudeAgent: { binaryPath: "", customModels: [] }, + }, }, }; } diff --git a/apps/web/src/components/chat/TraitsPicker.browser.tsx b/apps/web/src/components/chat/TraitsPicker.browser.tsx index 61697c944a..56bac1be70 100644 --- a/apps/web/src/components/chat/TraitsPicker.browser.tsx +++ b/apps/web/src/components/chat/TraitsPicker.browser.tsx @@ -5,6 +5,7 @@ import { ClaudeModelOptions, CodexModelOptions, DEFAULT_MODEL_BY_PROVIDER, + DEFAULT_SERVER_SETTINGS, ProjectId, ThreadId, } from "@t3tools/contracts"; @@ -21,6 +22,7 @@ import { useComposerThreadDraft, useEffectiveComposerModelState, } from "../../composerDraftStore"; +import { DEFAULT_CLIENT_SETTINGS } from "~/clientSettings"; // ── Claude TraitsPicker tests ───────────────────────────────────────── @@ -38,7 +40,10 @@ function ClaudeTraitsPickerHarness(props: { selectedProvider: "claudeAgent", threadModelSelection: props.fallbackModelSelection, projectModelSelection: null, - customModelsByProvider: { codex: [], claudeAgent: [] }, + settings: { + ...DEFAULT_SERVER_SETTINGS, + ...DEFAULT_CLIENT_SETTINGS, + }, }); const handlePromptChange = useCallback( (nextPrompt: string) => { diff --git a/apps/web/src/composerDraftStore.ts b/apps/web/src/composerDraftStore.ts index a4acd810e7..7cd40f4b18 100644 --- a/apps/web/src/composerDraftStore.ts +++ b/apps/web/src/composerDraftStore.ts @@ -31,6 +31,7 @@ import { import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; import { createDebouncedStorage, createMemoryStorage } from "./lib/storage"; +import { UnifiedSettings } from "./appSettings"; export const COMPOSER_DRAFT_STORAGE_KEY = "t3code:composer-drafts:v1"; const COMPOSER_DRAFT_STORAGE_VERSION = 3; @@ -616,7 +617,7 @@ export function deriveEffectiveComposerModelState(input: { selectedProvider: ProviderKind; threadModelSelection: ModelSelection | null | undefined; projectModelSelection: ModelSelection | null | undefined; - customModelsByProvider: Record; + settings: UnifiedSettings; }): EffectiveComposerModelState { const baseModel = resolveModelSlugForProvider( input.selectedProvider, @@ -626,11 +627,7 @@ export function deriveEffectiveComposerModelState(input: { ); const activeSelection = input.draft?.modelSelectionByProvider?.[input.selectedProvider]; const selectedModel = activeSelection?.model - ? resolveAppModelSelection( - input.selectedProvider, - input.customModelsByProvider, - activeSelection.model, - ) + ? resolveAppModelSelection(input.selectedProvider, input.settings, activeSelection.model) : baseModel; const modelOptions = modelSelectionByProviderToOptions(input.draft?.modelSelectionByProvider) ?? @@ -2160,7 +2157,7 @@ export function useEffectiveComposerModelState(input: { selectedProvider: ProviderKind; threadModelSelection: ModelSelection | null | undefined; projectModelSelection: ModelSelection | null | undefined; - customModelsByProvider: Record; + settings: UnifiedSettings; }): EffectiveComposerModelState { const draft = useComposerThreadDraft(input.threadId); @@ -2171,11 +2168,11 @@ export function useEffectiveComposerModelState(input: { selectedProvider: input.selectedProvider, threadModelSelection: input.threadModelSelection, projectModelSelection: input.projectModelSelection, - customModelsByProvider: input.customModelsByProvider, + settings: input.settings, }), [ draft, - input.customModelsByProvider, + input.settings, input.projectModelSelection, input.selectedProvider, input.threadModelSelection, diff --git a/apps/web/src/modelSelection.ts b/apps/web/src/modelSelection.ts index 9534170b1f..28859bc6cd 100644 --- a/apps/web/src/modelSelection.ts +++ b/apps/web/src/modelSelection.ts @@ -10,19 +10,13 @@ import { resolveSelectableModel, } from "@t3tools/shared/model"; import { getComposerProviderState } from "./components/chat/composerProviderRegistry"; +import { UnifiedSettings } from "./appSettings"; const MAX_CUSTOM_MODEL_COUNT = 32; export const MAX_CUSTOM_MODEL_LENGTH = 256; -export type CustomModelSettings = { - customCodexModels: readonly string[]; - customClaudeModels: readonly string[]; -}; - export type ProviderCustomModelConfig = { provider: ProviderKind; - settingsKey: keyof CustomModelSettings; - defaultSettingsKey: keyof CustomModelSettings; title: string; description: string; placeholder: string; @@ -38,8 +32,6 @@ export interface AppModelOption { const PROVIDER_CUSTOM_MODEL_CONFIG: Record = { codex: { provider: "codex", - settingsKey: "customCodexModels", - defaultSettingsKey: "customCodexModels", title: "Codex", description: "Save additional Codex model slugs for the picker and `/model` command.", placeholder: "your-codex-model-slug", @@ -47,8 +39,6 @@ const PROVIDER_CUSTOM_MODEL_CONFIG: Record { - return { - [PROVIDER_CUSTOM_MODEL_CONFIG[provider].settingsKey]: models, - }; -} - -export function getCustomModelsByProvider( - settings: CustomModelSettings, -): Record { - return { - codex: getCustomModelsForProvider(settings, "codex"), - claudeAgent: getCustomModelsForProvider(settings, "claudeAgent"), - }; -} - export function getAppModelOptions( + settings: UnifiedSettings, provider: ProviderKind, - customModels: readonly string[], selectedModel?: string | null, ): AppModelOption[] { const options: AppModelOption[] = getModelOptions(provider).map(({ slug, name }) => ({ @@ -137,6 +95,7 @@ export function getAppModelOptions( const seen = new Set(options.map((option) => option.slug)); const trimmedSelectedModel = selectedModel?.trim().toLowerCase(); + const customModels = settings.providers[provider].customModels; for (const slug of normalizeCustomModelSlugs(customModels, provider)) { if (seen.has(slug)) { continue; @@ -171,57 +130,51 @@ export function getAppModelOptions( export function resolveAppModelSelection( provider: ProviderKind, - customModels: Record, + settings: UnifiedSettings, + selectedModel: string | null | undefined, ): string { - const customModelsForProvider = customModels[provider]; - const options = getAppModelOptions(provider, customModelsForProvider, selectedModel); + const options = getAppModelOptions(settings, provider, selectedModel); return resolveSelectableModel(provider, selectedModel, options) ?? getDefaultModel(provider); } export function getCustomModelOptionsByProvider( - settings: CustomModelSettings, + settings: UnifiedSettings, selectedProvider?: ProviderKind | null, selectedModel?: string | null, ): Record> { - const customModelsByProvider = getCustomModelsByProvider(settings); return { codex: getAppModelOptions( + settings, "codex", - customModelsByProvider.codex, selectedProvider === "codex" ? selectedModel : undefined, ), claudeAgent: getAppModelOptions( + settings, "claudeAgent", - customModelsByProvider.claudeAgent, selectedProvider === "claudeAgent" ? selectedModel : undefined, ), }; } -export function resolveAppModelSelectionState( - settings: CustomModelSettings & { - textGenerationModelSelection: ModelSelection | undefined; - }, -): ModelSelection { +export function resolveAppModelSelectionState(settings: UnifiedSettings): ModelSelection { const selection = settings.textGenerationModelSelection ?? { provider: "codex" as const, model: DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER.codex, }; - const provider = selection.provider; - const customModelsByProvider = getCustomModelsByProvider(settings); - const model = resolveAppModelSelection(provider, customModelsByProvider, selection.model); + + const model = resolveAppModelSelection(selection.provider, settings, selection.model); const { modelOptionsForDispatch } = getComposerProviderState({ - provider, + provider: selection.provider, model, prompt: "", modelOptions: { - [provider]: selection.options, + [selection.provider]: selection.options, }, }); return { - provider, + provider: selection.provider, model, ...(modelOptionsForDispatch ? { options: modelOptionsForDispatch } : {}), }; diff --git a/apps/web/src/routes/_chat.settings.tsx b/apps/web/src/routes/_chat.settings.tsx index 38e324dac1..98da7583a6 100644 --- a/apps/web/src/routes/_chat.settings.tsx +++ b/apps/web/src/routes/_chat.settings.tsx @@ -7,10 +7,8 @@ import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model"; import { useAppSettings } from "../appSettings"; import { getCustomModelOptionsByProvider, - getCustomModelsForProvider, MAX_CUSTOM_MODEL_LENGTH, MODEL_PROVIDER_SETTINGS, - patchCustomModels, resolveAppModelSelectionState, } from "../modelSelection"; import { APP_VERSION } from "../branding"; @@ -61,11 +59,9 @@ const TIMESTAMP_FORMAT_LABELS = { "24-hour": "24-hour", } as const; -type InstallBinarySettingsKey = "claudeBinaryPath" | "codexBinaryPath"; type InstallProviderSettings = { provider: ProviderKind; title: string; - binaryPathKey: InstallBinarySettingsKey; binaryPlaceholder: string; binaryDescription: ReactNode; homePathKey?: "codexHomePath"; @@ -77,7 +73,6 @@ const INSTALL_PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [ { provider: "codex", title: "Codex", - binaryPathKey: "codexBinaryPath", binaryPlaceholder: "Codex binary path", binaryDescription: ( <> @@ -91,7 +86,6 @@ const INSTALL_PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [ { provider: "claudeAgent", title: "Claude", - binaryPathKey: "claudeBinaryPath", binaryPlaceholder: "Claude binary path", binaryDescription: ( <> @@ -195,8 +189,8 @@ function SettingsRouteView() { const [isOpeningKeybindings, setIsOpeningKeybindings] = useState(false); const [openKeybindingsError, setOpenKeybindingsError] = useState(null); const [openInstallProviders, setOpenInstallProviders] = useState>({ - codex: Boolean(settings.codex?.binaryPath || settings.codex?.homePath), - claudeAgent: Boolean(settings.claude?.binaryPath), + codex: Boolean(settings.providers.codex.binaryPath || settings.providers.codex.homePath), + claudeAgent: Boolean(settings.providers.claudeAgent.binaryPath), }); const [selectedCustomModelProvider, setSelectedCustomModelProvider] = useState("codex"); @@ -211,9 +205,7 @@ function SettingsRouteView() { >({}); const [showAllCustomModels, setShowAllCustomModels] = useState(false); - const codexBinaryPath = settings.codex?.binaryPath ?? ""; - const codexHomePath = settings.codex?.homePath ?? ""; - const claudeBinaryPath = settings.claude?.binaryPath ?? ""; + const codexHomePath = settings.providers.codex.homePath; const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null; const availableEditors = serverConfigQuery.data?.availableEditors; @@ -231,9 +223,11 @@ function SettingsRouteView() { )!; const selectedCustomModelInput = customModelInputByProvider[selectedCustomModelProvider]; const selectedCustomModelError = customModelErrorByProvider[selectedCustomModelProvider] ?? null; - const totalCustomModels = settings.customCodexModels.length + settings.customClaudeModels.length; + const totalCustomModels = + settings.providers.codex.customModels.length + + settings.providers.claudeAgent.customModels.length; const savedCustomModelRows = MODEL_PROVIDER_SETTINGS.flatMap((providerSettings) => - getCustomModelsForProvider(settings, providerSettings.provider).map((slug) => ({ + settings.providers[providerSettings.provider].customModels.map((slug) => ({ key: `${providerSettings.provider}:${slug}`, provider: providerSettings.provider, providerTitle: providerSettings.title, @@ -244,9 +238,9 @@ function SettingsRouteView() { ? savedCustomModelRows : savedCustomModelRows.slice(0, 5); const isInstallSettingsDirty = - settings.claude?.binaryPath !== defaults.claude?.binaryPath || - settings.codex?.binaryPath !== defaults.codex?.binaryPath || - settings.codex?.homePath !== defaults.codex?.homePath; + settings.providers.claudeAgent.binaryPath !== defaults.providers.claudeAgent.binaryPath || + settings.providers.codex.binaryPath !== defaults.providers.codex.binaryPath || + settings.providers.codex.homePath !== defaults.providers.codex.homePath; const changedSettingLabels = [ ...(theme !== "system" ? ["Theme"] : []), ...(settings.timestampFormat !== defaults.timestampFormat ? ["Time format"] : []), @@ -262,7 +256,8 @@ function SettingsRouteView() { JSON.stringify(defaults.textGenerationModelSelection ?? null) ? ["Git writing model"] : []), - ...(settings.customCodexModels.length > 0 || settings.customClaudeModels.length > 0 + ...(settings.providers.codex.customModels.length > 0 || + settings.providers.claudeAgent.customModels.length > 0 ? ["Custom models"] : []), ...(isInstallSettingsDirty ? ["Provider installs"] : []), @@ -294,7 +289,7 @@ function SettingsRouteView() { const addCustomModel = useCallback( (provider: ProviderKind) => { const customModelInput = customModelInputByProvider[provider]; - const customModels = getCustomModelsForProvider(settings, provider); + const customModels = settings.providers[provider].customModels; const normalized = normalizeModelSlug(customModelInput, provider); if (!normalized) { setCustomModelErrorByProvider((existing) => ({ @@ -325,7 +320,15 @@ function SettingsRouteView() { return; } - updateSettings(patchCustomModels(provider, [...customModels, normalized])); + updateSettings({ + providers: { + ...settings.providers, + [provider]: { + ...settings.providers[provider], + customModels: [...customModels, normalized], + }, + }, + }); setCustomModelInputByProvider((existing) => ({ ...existing, [provider]: "", @@ -340,13 +343,16 @@ function SettingsRouteView() { const removeCustomModel = useCallback( (provider: ProviderKind, slug: string) => { - const customModels = getCustomModelsForProvider(settings, provider); - updateSettings( - patchCustomModels( - provider, - customModels.filter((model) => model !== slug), - ), - ); + const customModels = settings.providers[provider].customModels; + updateSettings({ + providers: { + ...settings.providers, + [provider]: { + ...settings.providers[provider], + customModels: customModels.filter((model) => model !== slug), + }, + }, + }); setCustomModelErrorByProvider((existing) => ({ ...existing, [provider]: null, @@ -699,8 +705,17 @@ function SettingsRouteView() { label="custom models" onClick={() => { updateSettings({ - customCodexModels: defaults.customCodexModels, - customClaudeModels: defaults.customClaudeModels, + providers: { + ...settings.providers, + codex: { + ...settings.providers.codex, + customModels: defaults.providers.codex.customModels, + }, + claudeAgent: { + ...settings.providers.claudeAgent, + customModels: defaults.providers.claudeAgent.customModels, + }, + }, }); setCustomModelErrorByProvider({}); setShowAllCustomModels(false); @@ -831,10 +846,17 @@ function SettingsRouteView() { label="provider installs" onClick={() => { updateSettings({ - claude: { binaryPath: defaults.claude?.binaryPath ?? "" }, - codex: { - binaryPath: defaults.codex?.binaryPath ?? "", - homePath: defaults.codex?.homePath ?? "", + providers: { + ...settings.providers, + claudeAgent: { + ...settings.providers.claudeAgent, + binaryPath: defaults.providers.claudeAgent.binaryPath, + }, + codex: { + ...settings.providers.codex, + binaryPath: defaults.providers.codex.binaryPath, + homePath: defaults.providers.codex.homePath, + }, }, }); setOpenInstallProviders({ @@ -852,13 +874,15 @@ function SettingsRouteView() { const isOpen = openInstallProviders[providerSettings.provider]; const isDirty = providerSettings.provider === "codex" - ? settings.codex?.binaryPath !== defaults.codex?.binaryPath || - settings.codex?.homePath !== defaults.codex?.homePath - : settings.claude?.binaryPath !== defaults.claude?.binaryPath; + ? settings.providers.codex.binaryPath !== + defaults.providers.codex.binaryPath || + settings.providers.codex.homePath !== defaults.providers.codex.homePath + : settings.providers.claudeAgent.binaryPath !== + defaults.providers.claudeAgent.binaryPath; const binaryPathValue = - providerSettings.binaryPathKey === "claudeBinaryPath" - ? (settings.claude?.binaryPath ?? "") - : codexBinaryPath; + providerSettings.provider === "claudeAgent" + ? settings.providers.claudeAgent.binaryPath + : settings.providers.codex.binaryPath; return (