From e72cd513e5100182337c6c422286d4c6e27086ff Mon Sep 17 00:00:00 2001 From: Pabloader Date: Sun, 22 Mar 2026 06:42:47 +0000 Subject: [PATCH] Group models --- .../storywriter/components/settings-modal.tsx | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/games/storywriter/components/settings-modal.tsx b/src/games/storywriter/components/settings-modal.tsx index ab50d0f..d45a896 100644 --- a/src/games/storywriter/components/settings-modal.tsx +++ b/src/games/storywriter/components/settings-modal.tsx @@ -41,7 +41,30 @@ export const SettingsModal = ({ onClose }: Props) => { const modelsData = useQuery(fetchModels, connectionToFetch); const isLoadingModels = connectionToFetch != null && modelsData == undefined; - const models = modelsData ?? []; + const groupedModels = useMemo(() => { + const sorted = (modelsData ?? []).sort((a, b) => { + // Sort by tool support first (true before false) + if (a.support_tools !== b.support_tools) { + return a.support_tools ? -1 : 1; + } + // Then by max context (bigger first, undefined treated as 0) + const aContext = a.max_context ?? 0; + const bContext = b.max_context ?? 0; + if (aContext !== bContext) { + return bContext - aContext; + } + // Then by name (alphabetically) + return a.id.localeCompare(b.id); + }); + + // Group by context size + const groups = Map.groupBy(sorted, m => m.max_context ?? 0); + + // Convert to array sorted by context size (bigger first) + return Array.from(groups.entries()) + .sort((a, b) => b[0] - a[0]) + .map(([context, models]) => ({ context, models })); + }, [modelsData]); const handleBlur = () => { if (url && apiKey) { @@ -119,15 +142,21 @@ export const SettingsModal = ({ onClose }: Props) => { {connectionToTest ? ( isLoadingModels ? (

Loading models...

- ) : models.length > 0 ? ( + ) : groupedModels.length > 0 ? ( ) : (