The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 11:00 UTC
Extract slash model option filtering into shared app settings helper
- add `getSlashModelOptions` to centralize `/model` suggestion filtering - include custom saved model slugs in slash-command suggestions - update ChatView to consume shared helper and add focused tests
Julius Marminge committed
Mar 3, 2026 at 09:28 UTC
09b32ac9dd43baab32b87c91f47f2a1651d1b1e8
3 files changed
+40
-16
apps/web/src/appSettings.test.ts
+15
-1
@@ -1,6 +1,6 @@
1
import { describe, expect, it } from "vitest";
2
3
-import { getAppModelOptions, normalizeCustomModelSlugs } from "./appSettings";
3
+import { getAppModelOptions, getSlashModelOptions, normalizeCustomModelSlugs } from "./appSettings";
4
5
describe("normalizeCustomModelSlugs", () => {
6
it("normalizes aliases, removes built-ins, and deduplicates values", () => {
@@ -40,3 +40,17 @@ describe("getAppModelOptions", () => {
40
});
41
});
42
});
43
+
44
+describe("getSlashModelOptions", () => {
45
+ it("includes saved custom model slugs for /model command suggestions", () => {
46
+ const options = getSlashModelOptions(["custom/internal-model"], "", "gpt-5.3-codex");
47
+
48
+ expect(options.some((option) => option.slug === "custom/internal-model")).toBe(true);
49
+ });
50
+
51
+ it("filters slash-model suggestions across built-in and custom model names", () => {
52
+ const options = getSlashModelOptions(["openai/gpt-oss-120b"], "oss", "gpt-5.3-codex");
53
+
54
+ expect(options.map((option) => option.slug)).toEqual(["openai/gpt-oss-120b"]);
55
+ });
56
+});
apps/web/src/appSettings.ts
+18
@@ -105,6 +105,24 @@ export function getAppModelOptions(
105
return options;
106
}
107
108
+export function getSlashModelOptions(
109
+ customModels: readonly string[],
110
+ query: string,
111
+ selectedModel?: string | null,
112
+): AppModelOption[] {
113
+ const normalizedQuery = query.trim().toLowerCase();
114
+ const options = getAppModelOptions(customModels, selectedModel);
115
+ if (!normalizedQuery) {
116
+ return options;
117
+ }
118
+
119
+ return options.filter((option) => {
120
+ const searchSlug = option.slug.toLowerCase();
121
+ const searchName = option.name.toLowerCase();
122
+ return searchSlug.includes(normalizedQuery) || searchName.includes(normalizedQuery);
123
+ });
124
+}
125
+
126
function emitChange(): void {
127
for (const listener of listeners) {
128
listener();
apps/web/src/components/ChatView.tsx
+7
-15
@@ -118,7 +118,7 @@ import { Toggle } from "./ui/toggle";
118
import { SidebarTrigger } from "./ui/sidebar";
119
import { newCommandId, newMessageId } from "~/lib/utils";
120
import { readNativeApi } from "~/nativeApi";
121
-import { getAppModelOptions, useAppSettings } from "../appSettings";
121
+import { getAppModelOptions, getSlashModelOptions, useAppSettings } from "../appSettings";
122
import {
123
type ComposerImageAttachment,
124
type DraftThreadEnvMode,
@@ -632,6 +632,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
632
() => getAppModelOptions(settings.customCodexModels, selectedModel),
633
[selectedModel, settings.customCodexModels],
634
);
635
+ const slashModelOptions = useMemo(
636
+ () => getSlashModelOptions(settings.customCodexModels, composerTrigger?.query ?? "", selectedModel),
637
+ [composerTrigger?.query, selectedModel, settings.customCodexModels],
638
+ );
639
const phase = derivePhase(activeThread?.session ?? null);
640
const isSendBusy = sendPhase !== "idle";
641
const isPreparingWorktree = sendPhase === "preparing-worktree";
@@ -907,26 +911,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
911
];
912
}
913
910
- return modelOptions
911
- .map(({ slug, name }) => ({
912
- slug,
913
- name,
914
- searchSlug: slug.toLowerCase(),
915
- searchName: name.toLowerCase(),
916
- }))
917
- .filter(({ searchSlug, searchName }) => {
918
- const query = composerTrigger.query.trim().toLowerCase();
919
- if (!query) return true;
920
- return searchSlug.includes(query) || searchName.includes(query);
921
- })
922
- .map(({ slug, name }) => ({
914
+ return slashModelOptions.map(({ slug, name }) => ({
915
id: `model:${slug}`,
916
type: "model" as const,
917
model: slug,
918
label: name,
919
description: slug,
920
}));
929
- }, [composerTrigger, modelOptions, workspaceEntries]);
921
+ }, [composerTrigger, slashModelOptions, workspaceEntries]);
922
const composerMenuOpen = Boolean(composerTrigger);
923
const activeComposerMenuItem = useMemo(
924
() =>