Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(chat): sort model pickers newest first and fold older models

rubenluetke10-beepbae51e91f960
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index 6239fcd6c7..f561207a8e 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -23,7 +23,8 @@ import type { ProviderOption } from "@/store/agentChat";
import { useEventStore } from "@/store/events";
import { folderLeaf } from "@/lib/folderPath";
import { effortLadder, snapEffort } from "@/lib/effortLadder";
-import { isApiRunner, pickAgentChatFolder } from "@/lib/agentChatApi";
+import { rankModels } from "@/lib/modelRanking";
+import { isApiRunner, pickAgentChatFolder, type CuratedModel } from "@/lib/agentChatApi";
import { runningTurn } from "@/components/agentchat/reduce";
import { permissionModeIcon } from "@/components/agentchat/permissionIcons";
import { useComposerDictation } from "@/components/agentchat/useComposerDictation";
@@ -446,6 +447,16 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
<span className="truncate">{note ? `${p.label} · ${note}` : p.label}</span>
</span>
);
+ const toOption = (m: CuratedModel): ComboboxOption => ({
+ value: brainValue(p.id, m.id),
+ label: m.label || m.id,
+ description: owner(m.note),
+ hint,
+ disabled,
+ searchText: `${p.label} ${m.id}`,
+ });
+ // Newest of each model line first; earlier versions fold away.
+ const { current, older } = rankModels(models.filter((m) => m.id));
return {
id: p.id,
label: p.label,
@@ -459,17 +470,9 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
disabled,
searchText: `${p.label} ${p.family}`,
},
- ...models
- .filter((m) => m.id)
- .map((m) => ({
- value: brainValue(p.id, m.id),
- label: m.label || m.id,
- description: owner(m.note),
- hint,
- disabled,
- searchText: `${p.label} ${m.id}`,
- })),
+ ...current.map(toOption),
],
+ more: older.length ? { label: t("agent_chat.older_models"), options: older.map(toOption) } : undefined,
};
});
}, [brainProviders, liveModels, providerMark, t]);
@@ -484,18 +487,22 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
const modelGroups = useMemo<ComboboxGroup[]>(() => {
if (!provider) return [];
+ const toOption = (m: CuratedModel): ComboboxOption => ({
+ value: m.id,
+ label: m.label || m.id,
+ hint: m.note || (m.label && m.label !== m.id ? m.id : undefined),
+ searchText: m.id,
+ });
+ const { current, older } = rankModels(modelList.filter((m) => m.id));
const options: ComboboxOption[] = [
{ value: "", label: t("agent_chat.model_default"), hint: provider.label },
- ...modelList
- .filter((m) => m.id)
- .map((m) => ({
- value: m.id,
- label: m.label || m.id,
- hint: m.note || (m.label && m.label !== m.id ? m.id : undefined),
- searchText: m.id,
- })),
+ ...current.map(toOption),
];
- return [{ id: "models", options }];
+ return [{
+ id: "models",
+ options,
+ more: older.length ? { label: t("agent_chat.older_models"), options: older.map(toOption) } : undefined,
+ }];
}, [provider, modelList, t]);
// The effort ladder is the provider's, narrowed to the chosen model's own
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ComposerBrainPicker.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ComposerBrainPicker.tsx
index 161eb5962d..928d421970 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ComposerBrainPicker.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ComposerBrainPicker.tsx
@@ -1,7 +1,7 @@
import { useCallback, useMemo, useState, type ReactNode } from "react";
import { Star } from "lucide-react";
-import { Combobox, type ComboboxGroup } from "@/components/ui/combobox";
+import { Combobox, type ComboboxGroup, type ComboboxOption } from "@/components/ui/combobox";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
@@ -100,43 +100,43 @@ export function ComposerBrainPicker({
// Every row carries its star; the favourites tab lists the starred rows in
// the order they were starred.
- const starred = useMemo<ComboboxGroup[]>(
- () =>
- groups.map((group) => ({
- ...group,
- options: group.options.map((option) => {
- const on = favorites.includes(option.value);
- const label = on ? t("agent_chat.favorite_remove") : t("agent_chat.favorite_add");
- return {
- ...option,
- trailing: (
- <button
- type="button"
- aria-label={label}
- aria-pressed={on}
- title={label}
- data-testid="composer-model-star"
- onClick={(event) => {
- event.stopPropagation();
- toggleFavorite(option.value);
- }}
- className={cn(
- "-my-1 inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-sheen/[0.08]",
- on ? "text-warning" : "text-faint-foreground hover:text-foreground",
- )}
- >
- <Star className={cn("h-3.5 w-3.5", on && "fill-current")} aria-hidden />
- </button>
- ),
- };
- }),
- })),
- [groups, favorites, toggleFavorite, t],
- );
+ const starred = useMemo<ComboboxGroup[]>(() => {
+ const withStar = (option: ComboboxOption): ComboboxOption => {
+ const on = favorites.includes(option.value);
+ const label = on ? t("agent_chat.favorite_remove") : t("agent_chat.favorite_add");
+ return {
+ ...option,
+ trailing: (
+ <button
+ type="button"
+ aria-label={label}
+ aria-pressed={on}
+ title={label}
+ data-testid="composer-model-star"
+ onClick={(event) => {
+ event.stopPropagation();
+ toggleFavorite(option.value);
+ }}
+ className={cn(
+ "-my-1 inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-sheen/[0.08]",
+ on ? "text-warning" : "text-faint-foreground hover:text-foreground",
+ )}
+ >
+ <Star className={cn("h-3.5 w-3.5", on && "fill-current")} aria-hidden />
+ </button>
+ ),
+ };
+ };
+ return groups.map((group) => ({
+ ...group,
+ options: group.options.map(withStar),
+ more: group.more && { ...group.more, options: group.more.options.map(withStar) },
+ }));
+ }, [groups, favorites, toggleFavorite, t]);
const browseGroups = useMemo<ComboboxGroup[]>(() => {
if (section === FAVORITES) {
- const all = starred.flatMap((group) => group.options);
+ const all = starred.flatMap((group) => [...group.options, ...(group.more?.options ?? [])]);
const options = favorites
.map((fav) => all.find((option) => option.value === fav))
.filter((option): option is NonNullable<typeof option> => Boolean(option));
diff --git a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadPickers.tsx b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadPickers.tsx
index b2e72ad9ec..19584c2c41 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadPickers.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadPickers.tsx
@@ -1,10 +1,11 @@
import { useMemo } from "react";
import { AgentMark } from "@/components/agentic/AgentMark";
import { isUnguardedPermissionMode, permissionModeIcon } from "@/components/agentchat/permissionIcons";
-import { Combobox, type ComboboxGroup } from "@/components/ui/combobox";
+import { Combobox, type ComboboxGroup, type ComboboxOption } from "@/components/ui/combobox";
import { useT } from "@/i18n";
import type { CuratedModel } from "@/lib/agentChatApi";
import { effortLadder } from "@/lib/effortLadder";
+import { rankModels } from "@/lib/modelRanking";
import { cn } from "@/lib/utils";
import type { ComposerDraft, ProviderOption } from "@/store/agentChat";
@@ -61,28 +62,33 @@ export function AgentModelPicker({
lockedProvider: string | null;
onPick: (provider: string, model: string) => void;
}) {
+ const olderLabel = useT()("agent_chat.older_models");
const groups = useMemo<ComboboxGroup[]>(() => providers.map((provider) => {
const locked = lockedProvider !== null && provider.id !== lockedProvider;
const disabled = !provider.connected || locked;
const hint = locked ? "new thread" : !provider.connected ? (provider.cli_installed === false ? "not installed" : "connect first") : undefined;
const icon = <AgentMark agent={provider.agent ?? ""} label={provider.label} logoUrl={provider.logoUrl} variant="plain" size="sm" />;
const models = modelsOf(provider, liveModels).filter((model) => model.id);
+ const toOption = (model: CuratedModel): ComboboxOption => ({
+ value: `${provider.id}${SEP}${model.id}`,
+ label: model.label || model.id,
+ hint: hint ?? model.note,
+ searchText: `${model.id} ${agentName(provider)}`,
+ icon,
+ disabled,
+ });
+ // Newest of each model line first; earlier versions fold away.
+ const ranked = rankModels(models);
return {
id: provider.id,
label: agentName(provider),
options: [
{ value: `${provider.id}${SEP}`, label: agentName(provider), hint: hint ?? "default model", icon, disabled },
- ...models.map((model) => ({
- value: `${provider.id}${SEP}${model.id}`,
- label: model.label || model.id,
- hint: hint ?? model.note,
- searchText: `${model.id} ${agentName(provider)}`,
- icon,
- disabled,
- })),
+ ...ranked.current.map(toOption),
],
+ more: ranked.older.length ? { label: olderLabel, options: ranked.older.map(toOption) } : undefined,
};
- }), [providers, liveModels, lockedProvider]);
+ }), [providers, liveModels, lockedProvider, olderLabel]);
return <Combobox ariaLabel="Coding agent and model" testId="thread-model-picker"
value={`${draft.provider}${SEP}${draft.model}`} groups={groups}
onChange={(value) => { const [provider, model = ""] = value.split(SEP); onPick(provider, model); }}
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentModelPicker.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentModelPicker.tsx
index 67bbf51187..7925d5f1fe 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentModelPicker.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentModelPicker.tsx
@@ -9,6 +9,7 @@ import type { CuratedModel } from "@/lib/agentChatApi";
import { cn } from "@/lib/utils";
import { effortsFor, type BrainSeat } from "../create/brainPicker";
import { useUpdateAgentModel, type SocietyAgent } from "../data";
+import { rankModels } from "@/lib/modelRanking";
import { collapsibleModels, matchesModel, modelEffort, modelGroupOrder, modelSeats, providerTitle, visibleModels } from "./modelChoices";
import { useModelMenuData } from "./useModelMenuData";
@@ -53,9 +54,13 @@ export function AgentModelPicker({ agent, busy, onSavingChange }: {
const titleKey = JSON.stringify(seats.map((seat) => providerTitle(seat, t)));
const groups = useMemo(() => {
const titles = JSON.parse(titleKey) as string[];
- return seats.map((seat, index) => ({ seat, title: titles[index],
- models: seat.provider.curated_models.filter((model) => matchesModel(seat, model, search, titles[index])),
- })).filter((group) => group.models.length > 0).sort((a, b) =>
+ return seats.map((seat, index) => {
+ const matched = seat.provider.curated_models.filter((model) => matchesModel(seat, model, search, titles[index]));
+ // Newest of each model line first; earlier versions fold away. Catalogs
+ // with their own fold (OpenCode, OpenRouter) keep their order.
+ const ranked = collapsibleModels(seat) ? { current: matched, older: [] } : rankModels(matched);
+ return { seat, title: titles[index], models: [...ranked.current, ...ranked.older], older: new Set(ranked.older) };
+ }).filter((group) => group.models.length > 0).sort((a, b) =>
modelGroupOrder(a.seat) - modelGroupOrder(b.seat) || a.title.localeCompare(b.title));
}, [seats, search, titleKey]);
const sideSeat = seats.find((seat) => seat.provider.id === submenu?.provider);
@@ -199,29 +204,19 @@ export function AgentModelPicker({ agent, busy, onSavingChange }: {
{loading ? <p role="status" className="px-3 py-3 text-xs text-muted-foreground">{t("society.create.catalog_loading")}</p> : null}
{failed ? <p role="alert" className="px-3 py-3 text-xs text-destructive">{t("society.chat.model_load_failed")}</p> : null}
{!loading && !failed && groups.length === 0 ? <p className="px-3 py-3 text-xs text-muted-foreground">{t(refreshing ? "society.chat.models_loading" : "society.chat.model_no_matches")}</p> : null}
- {!loading && !failed ? groups.map(({ seat, title, models }) => {
+ {!loading && !failed ? groups.map(({ seat, title, models, older }) => {
const isExpanded = expanded[seat.provider.id] ?? false;
const shown = visibleModels(seat, models, isExpanded, search);
const foldable = collapsibleModels(seat) && !search.trim();
const isRouter = seat.provider.family === "openrouter";
const choicesId = `${menuId}-${seat.provider.id}-models`;
const toggle = () => { setSubmenu(null); setExpanded((previous) => ({ ...previous, [seat.provider.id]: !isExpanded })); };
- return <div key={seat.provider.id} role="group" aria-label={title}>
- <div className="sticky top-0 z-10 flex items-center gap-1 bg-popover px-3 pb-1 pt-3">
- {foldable && isRouter ? <button type="button" data-menu-choice disabled={busy || saving}
- onClick={toggle} aria-label={title} aria-expanded={isExpanded} aria-controls={choicesId}
- className="flex min-w-0 flex-1 items-center gap-1 rounded text-left text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
- {isExpanded ? <ChevronDown className="h-3 w-3 shrink-0" aria-hidden /> : <ChevronRight className="h-3 w-3 shrink-0" aria-hidden />}
- <span className="truncate">{title}</span><span className="ml-auto">{models.length}</span>
- </button> : <span className="min-w-0 flex-1 truncate text-[11px] font-semibold uppercase tracking-wide text-muted-foreground" title={title}>{title}</span>}
- {seat.accounts.length ? <button type="button" disabled={busy || saving} data-menu-choice
- aria-label={`${t("society.chat.model_account")}: ${title}`} aria-haspopup="menu" aria-expanded={submenu?.provider === seat.provider.id && !submenu.model}
- onClick={(event) => setSubmenu({ provider: seat.provider.id, anchor: event.currentTarget.getBoundingClientRect() })}
- className="flex max-w-[140px] items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-secondary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
- <Users className="h-3 w-3 shrink-0" aria-hidden /><span className="truncate">{seat.accounts.find((account) => account.id === currentAccount(seat))?.label ?? t("society.chat.model_active_account")}</span><ChevronDown className="h-2.5 w-2.5 shrink-0" aria-hidden />
- </button> : null}
- </div>
- <div id={choicesId}>{shown.map((model) => {
+ const olderKey = `older:${seat.provider.id}`;
+ const folded = search.trim() ? [] : shown.filter((model) => older.has(model));
+ const lineup = folded.length ? shown.filter((model) => !older.has(model)) : shown;
+ const olderOpen = expanded[olderKey] ?? folded.some((model) => agent.provider === seat.provider.id && agent.model === model.id);
+ const toggleOlder = () => { setSubmenu(null); setExpanded((previous) => ({ ...previous, [olderKey]: !olderOpen })); };
+ const row = (model: CuratedModel) => {
const selected = agent.provider === seat.provider.id && agent.model === model.id && (agent.accountId ?? "") === currentAccount(seat);
const effort = preferredEffort(seat, model);
return <div key={model.id} className={cn("group flex items-center", selected && "bg-secondary/70")}>
@@ -242,7 +237,32 @@ export function AgentModelPicker({ agent, busy, onSavingChange }: {
<ChevronRight className="h-3 w-3" aria-hidden />
</button> : null}
</div>;
- })}</div>
+ };
+ return <div key={seat.provider.id} role="group" aria-label={title}>
+ <div className="sticky top-0 z-10 flex items-center gap-1 bg-popover px-3 pb-1 pt-3">
+ {foldable && isRouter ? <button type="button" data-menu-choice disabled={busy || saving}
+ onClick={toggle} aria-label={title} aria-expanded={isExpanded} aria-controls={choicesId}
+ className="flex min-w-0 flex-1 items-center gap-1 rounded text-left text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
+ {isExpanded ? <ChevronDown className="h-3 w-3 shrink-0" aria-hidden /> : <ChevronRight className="h-3 w-3 shrink-0" aria-hidden />}
+ <span className="truncate">{title}</span><span className="ml-auto">{models.length}</span>
+ </button> : <span className="min-w-0 flex-1 truncate text-[11px] font-semibold uppercase tracking-wide text-muted-foreground" title={title}>{title}</span>}
+ {seat.accounts.length ? <button type="button" disabled={busy || saving} data-menu-choice
+ aria-label={`${t("society.chat.model_account")}: ${title}`} aria-haspopup="menu" aria-expanded={submenu?.provider === seat.provider.id && !submenu.model}
+ onClick={(event) => setSubmenu({ provider: seat.provider.id, anchor: event.currentTarget.getBoundingClientRect() })}
+ className="flex max-w-[140px] items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-secondary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
+ <Users className="h-3 w-3 shrink-0" aria-hidden /><span className="truncate">{seat.accounts.find((account) => account.id === currentAccount(seat))?.label ?? t("society.chat.model_active_account")}</span><ChevronDown className="h-2.5 w-2.5 shrink-0" aria-hidden />
+ </button> : null}
+ </div>
+ <div id={choicesId}>
+ {lineup.map(row)}
+ {folded.length ? <button type="button" data-menu-choice disabled={busy || saving} aria-expanded={olderOpen} onClick={toggleOlder}
+ className={cn(menuRow, "text-muted-foreground")}>
+ <span className="min-w-0 flex-1 truncate">{t("agent_chat.older_models")}</span>
+ <span className="text-xs">{folded.length}</span>
+ <ChevronRight className={cn("h-3 w-3 shrink-0 transition-transform", olderOpen && "rotate-90")} aria-hidden />
+ </button> : null}
+ {olderOpen ? folded.map(row) : null}
+ </div>
{foldable && !isRouter && (isExpanded || shown.length < models.length) ? <button type="button" data-menu-choice
disabled={busy || saving} aria-expanded={isExpanded} aria-controls={choicesId} onClick={toggle}
className={cn(menuRow, "text-muted-foreground")}>
diff --git a/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx b/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
index 83b4634fd8..b5adb80d1b 100644
--- a/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
@@ -301,3 +301,44 @@ describe("isComboboxPanelEvent", () => {
expect(isComboboxPanelEvent({ target: document.createElement("div") })).toBe(false);
});
});
+
+describe("Combobox fold", () => {
+ const FOLDED = [
+ {
+ id: "models",
+ options: [{ value: "new", label: "Newest" }],
+ more: { label: "Older models", options: [{ value: "old", label: "Oldest" }] },
+ },
+ ];
+
+ it("folds older options behind one row that opens in place", async () => {
+ const onChange = vi.fn();
+ render(<Combobox value="new" groups={FOLDED} onChange={onChange} ariaLabel="Model" searchPlaceholder="Search" testId="m" />);
+ fireEvent.click(screen.getByRole("combobox", { name: "Model" }));
+ const fold = await screen.findByTestId("m-fold");
+ expect(screen.queryByRole("option", { name: "Oldest" })).toBeNull();
+
+ fireEvent.click(fold);
+ fireEvent.click(await screen.findByRole("option", { name: "Oldest" }));
+ expect(onChange).toHaveBeenCalledWith("old");
+ });
+
+ it("opens the fold by keyboard and by search", async () => {
+ render(<Combobox value="new" groups={FOLDED} onChange={() => {}} ariaLabel="Model" searchPlaceholder="Search" testId="m" />);
+ fireEvent.click(screen.getByRole("combobox", { name: "Model" }));
+ const search = await screen.findByTestId("m-search");
+ fireEvent.keyDown(search, { key: "ArrowDown" });
+ fireEvent.keyDown(search, { key: "Enter" });
+ expect(await screen.findByRole("option", { name: "Oldest" })).toBeTruthy();
+
+ fireEvent.change(search, { target: { value: "oldest" } });
+ expect(screen.queryByTestId("m-fold")).toBeNull();
+ expect(screen.getByRole("option", { name: "Oldest" })).toBeTruthy();
+ });
+
+ it("starts unfolded when the current value is folded", async () => {
+ render(<Combobox value="old" groups={FOLDED} onChange={() => {}} ariaLabel="Model" searchPlaceholder="Search" testId="m" />);
+ fireEvent.click(screen.getByRole("combobox", { name: "Model" }));
+ expect(await screen.findByRole("option", { name: "Oldest" })).toBeTruthy();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/ui/combobox.tsx b/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
index 62d3589e22..f319aebd75 100644
--- a/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
+++ b/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
@@ -9,7 +9,7 @@ import {
type ReactNode,
} from "react";
import { createPortal } from "react-dom";
-import { Check, ChevronDown, Search } from "lucide-react";
+import { Check, ChevronDown, ChevronRight, Search } from "lucide-react";
import { cn } from "@/lib/utils";
@@ -71,6 +71,12 @@ export interface ComboboxGroup {
/** Rendered as a quiet micro heading; omit for an ungrouped lead band. */
label?: string;
options: ComboboxOption[];
+ /**
+ * Options folded behind one row at the group's end ("Older models · 7"),
+ * opened in place. Search always reaches them, and the fold opens by
+ * itself when it holds the current value.
+ */
+ more?: { label: string; options: ComboboxOption[] };
}
export interface ComboboxProps {
@@ -216,6 +222,19 @@ interface PanelPosition {
interface OptionOccurrence {
option: ComboboxOption;
id: string;
+ /** Set on a group's fold row: the group whose `more` it opens. */
+ fold?: string;
+}
+
+interface VisibleGroup {
+ id: string;
+ label?: string;
+ options: ComboboxOption[];
+ fold?: { label: string; count: number; open: boolean; options: ComboboxOption[] };
+}
+
+function allOptions(group: ComboboxGroup): ComboboxOption[] {
+ return group.more ? [...group.options, ...group.more.options] : group.options;
}
function optionOccurrenceId(
@@ -256,6 +275,7 @@ export function Combobox({
const [query, setQuery] = useState("");
const [activeIndex, setActiveIndex] = useState(0);
const [position, setPosition] = useState<PanelPosition | null>(null);
+ const [unfolded, setUnfolded] = useState<ReadonlySet<string>>(new Set());
const triggerRef = useRef<HTMLButtonElement>(null);
const panelRef = useRef<HTMLDivElement>(null);
@@ -268,15 +288,24 @@ export function Combobox({
const selected = useMemo(() => {
for (const group of groups) {
- for (const option of group.options) {
+ for (const option of allOptions(group)) {
if (option.value === value) return option;
}
}
return null;
}, [groups, value]);
- const visibleGroups = useMemo(() => {
- if (!query.trim()) return browseGroups ?? groups;
+ const visibleGroups = useMemo<VisibleGroup[]>(() => {
+ if (!query.trim()) {
+ return (browseGroups ?? groups).map((group) => ({
+ id: group.id,
+ label: group.label,
+ options: group.options,
+ fold: group.more?.options.length
+ ? { label: group.more.label, count: group.more.options.length, open: unfolded.has(group.id), options: group.more.options }
+ : undefined,
+ }));
+ }
// Searching collapses the bands into one flat result list. Groups are a
// browsing aid, and a shortlist band deliberately repeats entries that are
// also in the full list below it — which is fine while browsing and reads
@@ -285,7 +314,7 @@ export function Combobox({
const seen = new Set<string>();
const hits: ComboboxOption[] = [];
for (const group of groups) {
- for (const option of group.options) {
+ for (const option of allOptions(group)) {
if (seen.has(option.value)) continue;
if (!matches(option, query)) continue;
seen.add(option.value);
@@ -293,25 +322,34 @@ export function Combobox({
}
}
return hits.length ? [{ id: "results", options: hits }] : [];
- }, [groups, browseGroups, matches, query]);
+ }, [groups, browseGroups, matches, query, unfolded]);
// Flat order of concrete rendered occurrences — arrow keys walk this, not
// merely option values. A shortlist may repeat the same logical value in the
// full group, so every occurrence needs its own DOM id and active state.
const flat = useMemo<OptionOccurrence[]>(
() =>
- visibleGroups.flatMap((group, groupIndex) =>
- group.options.map((option, optionIndex) => ({
+ visibleGroups.flatMap((group, groupIndex) => [
+ ...group.options.map((option, optionIndex) => ({
option,
- id: optionOccurrenceId(
- listId,
- group.id,
- groupIndex,
- optionIndex,
- option.value,
- ),
+ id: optionOccurrenceId(listId, group.id, groupIndex, optionIndex, option.value),
})),
- ),
+ ...(group.fold
+ ? [
+ {
+ option: { value: `\u0000fold:${group.id}`, label: group.fold.label },
+ id: `${listId}-fold-${encodeURIComponent(group.id)}-${groupIndex}`,
+ fold: group.id,
+ },
+ ...(group.fold.open
+ ? group.fold.options.map((option, optionIndex) => ({
+ option,
+ id: optionOccurrenceId(listId, `${group.id}-more`, groupIndex, optionIndex, option.value),
+ }))
+ : []),
+ ]
+ : []),
+ ]),
[listId, visibleGroups],
);
const enabled = useMemo(
@@ -476,6 +514,26 @@ export function Combobox({
return () => document.removeEventListener("pointerdown", onPointerDown, true);
}, [open, close]);
+ // Each open starts folded, except a fold that holds the current value. Set
+ // in the same update as `open`, so the highlight can land on that value.
+ function openPanel() {
+ setUnfolded(new Set(groups.filter((group) => group.more?.options.some((option) => option.value === value)).map((group) => group.id)));
+ setOpen(true);
+ }
+
+ function toggleFold(groupId: string) {
+ setUnfolded((current) => {
+ const next = new Set(current);
+ if (!next.delete(groupId)) next.add(groupId);
+ return next;
+ });
+ }
+
+ function activate(occurrence: OptionOccurrence) {
+ if (occurrence.fold) toggleFold(occurrence.fold);
+ else commit(occurrence.option);
+ }
+
function commit(option: ComboboxOption) {
if (option.disabled) return;
close();
@@ -511,14 +569,14 @@ export function Combobox({
if (event.key === "Enter") {
event.preventDefault();
const occurrence = enabled[activeIndex];
- if (occurrence) commit(occurrence.option);
+ if (occurrence) activate(occurrence);
}
}
function onTriggerKeyDown(event: React.KeyboardEvent) {
if (event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") {
event.preventDefault();
- if (!disabled) setOpen(true);
+ if (!disabled && !open) openPanel();
}
}
@@ -541,7 +599,11 @@ export function Combobox({
disabled={disabled}
data-testid={testId}
data-value={value}
- onClick={() => !disabled && setOpen((wasOpen) => !wasOpen)}
+ onClick={() => {
+ if (disabled) return;
+ if (open) close(false);
+ else openPanel();
+ }}
onKeyDown={onTriggerKeyDown}
// A field is a lift surface, so the fill does the separating and the
// trigger carries no border at all. Every state used to be a --primary
@@ -649,7 +711,78 @@ export function Combobox({
</p>
)}
- {visibleGroups.map((group, groupIndex) => (
+ {visibleGroups.map((group, groupIndex) => {
+ const renderOption = (option: ComboboxOption, occurrenceId: string) => {
+ const isActive = activeOption?.id === occurrenceId;
+ const isSelected = option.value === value;
+ return (
+ <div
+ key={option.value}
+ id={occurrenceId}
+ role="option"
+ aria-selected={isSelected}
+ aria-disabled={option.disabled || undefined}
+ data-active={isActive}
+ data-value={option.value}
+ // Pointer, not mouse: the highlight has to follow a
+ // pen or touch drag as well, and `onMouseMove` never
+ // fires for either.
+ onPointerMove={() => {
+ if (!option.disabled) {
+ setActiveIndex(
+ enabled.findIndex(({ id }) => id === occurrenceId),
+ );
+ }
+ }}
+ onClick={() => commit(option)}
+ // The highlight is drawn on the whole row, and it is a
+ // sheen rather than a named surface because the ladder
+ // has run out: the panel is already the float layer,
+ // and --secondary would sit BELOW it in dark mode —
+ // the "selection reads as a hole" defect. A true
+ // overlay on a floating layer lifts on black and
+ // deepens on paper, which is right in both themes.
+ className={cn(
+ "relative flex cursor-pointer flex-col rounded-md px-3 py-1.5 text-sm transition-colors",
+ isActive && "bg-sheen/[0.08] text-foreground",
+ isSelected && "font-medium text-foreground-strong",
+ option.disabled && "cursor-not-allowed text-faint-foreground",
+ )}
+ >
+ <span className="flex min-w-0 items-center gap-2">
+ {option.icon}
+ <span className="min-w-0 truncate">{option.label}</span>
+ {option.badge && (
+ <span className="shrink-0 rounded-md border border-border-strong px-1.5 text-micro font-medium leading-5 text-muted-foreground">
+ {option.badge}
+ </span>
+ )}
+ <span className="flex-1" />
+ {option.hint && (
+ <span className="shrink-0 truncate text-sm font-normal text-muted-foreground">
+ {option.hint}
+ </span>
+ )}
+ {option.trailing}
+ {isSelected && (
+ <Check
+ aria-hidden="true"
+ className="h-3.5 w-3.5 shrink-0 text-foreground-strong"
+ />
+ )}
+ </span>
+ {option.description && (
+ // Under the label, not under the icon: a 16 px glyph
+ // plus the row's 8 px gap.
+ <span className={cn("mt-0.5 line-clamp-2 text-xs font-normal leading-4 text-muted-foreground", option.icon && "pl-6")}>
+ {option.description}
+ </span>
+ )}
+ </div>
+ );
+ };
+ const foldId = `${listId}-fold-${encodeURIComponent(group.id)}-${groupIndex}`;
+ return (
<div key={group.id}>
{group.label && (
// Micro, the scale's floor — not a 10px all-caps label.
@@ -659,84 +792,42 @@ export function Combobox({
{group.label}
</div>
)}
- {group.options.map((option, optionIndex) => {
- const occurrenceId = optionOccurrenceId(
- listId,
- group.id,
- groupIndex,
- optionIndex,
- option.value,
- );
- const isActive = activeOption?.id === occurrenceId;
- const isSelected = option.value === value;
- return (
- <div
- key={option.value}
- id={occurrenceId}
- role="option"
- aria-selected={isSelected}
- aria-disabled={option.disabled || undefined}
- data-active={isActive}
- data-value={option.value}
- // Pointer, not mouse: the highlight has to follow a
- // pen or touch drag as well, and `onMouseMove` never
- // fires for either.
- onPointerMove={() => {
- if (!option.disabled) {
- setActiveIndex(
- enabled.findIndex(({ id }) => id === occurrenceId),
- );
- }
- }}
- onClick={() => commit(option)}
- // The highlight is drawn on the whole row, and it is a
- // sheen rather than a named surface because the ladder
- // has run out: the panel is already the float layer,
- // and --secondary would sit BELOW it in dark mode —
- // the "selection reads as a hole" defect. A true
- // overlay on a floating layer lifts on black and
- // deepens on paper, which is right in both themes.
- className={cn(
- "relative flex cursor-pointer flex-col rounded-md px-3 py-1.5 text-sm transition-colors",
- isActive && "bg-sheen/[0.08] text-foreground",
- isSelected && "font-medium text-foreground-strong",
- option.disabled && "cursor-not-allowed text-faint-foreground",
- )}
- >
- <span className="flex min-w-0 items-center gap-2">
- {option.icon}
- <span className="min-w-0 truncate">{option.label}</span>
- {option.badge && (
- <span className="shrink-0 rounded-md border border-border-strong px-1.5 text-micro font-medium leading-5 text-muted-foreground">
- {option.badge}
- </span>
- )}
- <span className="flex-1" />
- {option.hint && (
- <span className="shrink-0 truncate text-sm font-normal text-muted-foreground">
- {option.hint}
- </span>
- )}
- {option.trailing}
- {isSelected && (
- <Check
- aria-hidden="true"
- className="h-3.5 w-3.5 shrink-0 text-foreground-strong"
- />
- )}
- </span>
- {option.description && (
- // Under the label, not under the icon: a 16 px glyph
- // plus the row's 8 px gap.
- <span className={cn("mt-0.5 line-clamp-2 text-xs font-normal leading-4 text-muted-foreground", option.icon && "pl-6")}>
- {option.description}
- </span>
- )}
- </div>
- );
- })}
+ {group.options.map((option, optionIndex) =>
+ renderOption(option, optionOccurrenceId(listId, group.id, groupIndex, optionIndex, option.value)),
+ )}
+ {group.fold && (
+ <div
+ id={foldId}
+ role="option"
+ aria-selected={false}
+ aria-expanded={group.fold.open}
+ data-active={activeOption?.id === foldId}
+ data-testid={testId ? `${testId}-fold` : undefined}
+ onPointerMove={() => setActiveIndex(enabled.findIndex(({ id }) => id === foldId))}
+ // Keep the search box focused: typing right after
+ // opening the fold still searches.
+ onMouseDown={(event) => event.preventDefault()}
+ onClick={() => toggleFold(group.id)}
+ className={cn(
+ "flex cursor-pointer items-center gap-2 rounded-md px-3 py-1.5 text-sm text-muted-foreground transition-colors",
+ activeOption?.id === foldId && "bg-sheen/[0.08] text-foreground",
+ )}
+ >
+ <span className="min-w-0 flex-1 truncate">{group.fold.label}</span>
+ <span className="shrink-0 text-xs">{group.fold.count}</span>
+ <ChevronRight
+ aria-hidden="true"
+ className={cn("h-3.5 w-3.5 shrink-0 transition-transform", group.fold.open && "rotate-90")}
+ />
+ </div>
+ )}
+ {group.fold?.open &&
+ group.fold.options.map((option, optionIndex) =>
+ renderOption(option, optionOccurrenceId(listId, `${group.id}-more`, groupIndex, optionIndex, option.value)),
+ )}
</div>
- ))}
+ );
+ })}
</div>
</div>
</div>,
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index f0da902feb..ea234cfb7d 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -830,6 +830,7 @@
"search_providers": "Anbieter suchen …",
"search_models": "Modelle suchen …",
"no_models": "Keine Modelle gefunden",
+ "older_models": "Ältere Modelle",
"favorites": "Favoriten",
"favorites_empty": "Markiere ein Modell mit dem Stern, um es hier zu behalten",
"favorite_add": "Zu Favoriten hinzufügen",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index a698c0e5a2..2c4198f677 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -830,6 +830,7 @@
"search_providers": "Search providers…",
"search_models": "Search models…",
"no_models": "No models found",
+ "older_models": "Older models",
"favorites": "Favorites",
"favorites_empty": "Star a model to keep it here",
"favorite_add": "Add to favorites",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 43bfd553f0..a88cbd0154 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -830,6 +830,7 @@
"search_providers": "Buscar proveedores…",
"search_models": "Buscar modelos…",
"no_models": "No se encontraron modelos",
+ "older_models": "Modelos anteriores",
"favorites": "Favoritos",
"favorites_empty": "Marca un modelo con la estrella para tenerlo aquí",
"favorite_add": "Añadir a favoritos",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/zh.json b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
index bf4cb1b96e..b2ef192ac6 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/zh.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
@@ -830,6 +830,7 @@
"search_providers": "搜索服务商…",
"search_models": "搜索模型…",
"no_models": "未找到模型",
+ "older_models": "更早的模型",
"favorites": "收藏",
"favorites_empty": "给模型加星标,即可固定在这里",
"favorite_add": "添加到收藏",
diff --git a/jarvis/ui/web/frontend/src/lib/modelRanking.test.ts b/jarvis/ui/web/frontend/src/lib/modelRanking.test.ts
new file mode 100644
index 0000000000..4cb10141f7
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/modelRanking.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, it } from "vitest";
+
+import { rankModels } from "./modelRanking";
+
+const ids = (models: { id: string }[]) => models.map((model) => model.id);
+
+describe("rankModels", () => {
+ it("keeps the newest version of each line and folds earlier ones", () => {
+ const { current, older } = rankModels([
+ { id: "claude-opus-5-5", label: "Claude Opus 5.5" },
+ { id: "claude-fable-5-1", label: "Claude Fable 5.1" },
+ { id: "claude-fable-5", label: "Claude Fable 5" },
+ { id: "claude-opus-5", label: "Claude Opus 5" },
+ { id: "claude-sonnet-5", label: "Claude Sonnet 5" },
+ { id: "claude-haiku-4-5-20251001", label: "Claude Haiku 4.5" },
+ { id: "opusplan", label: "Opus plans, Sonnet builds" },
+ { id: "claude-opus-4-8", label: "Claude Opus 4.8" },
+ { id: "claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5" },
+ ]);
+ expect(ids(current)).toEqual(["claude-opus-5-5", "claude-fable-5-1", "claude-sonnet-5", "claude-haiku-4-5-20251001"]);
+ expect(ids(older)).toEqual(["claude-fable-5", "claude-opus-5", "claude-opus-4-8", "claude-sonnet-4-5-20250929", "opusplan"]);
+ });
+
+ it("keeps variants of the newest version together in the lineup", () => {
+ const { current } = rankModels([
+ { id: "claude-opus-5", label: "Claude Opus 5" },
+ { id: "claude-opus-5[1m]", label: "Claude Opus 5", note: "1M context" },
+ ]);
+ expect(ids(current)).toEqual(["claude-opus-5", "claude-opus-5[1m]"]);
+ });
+
+ it("treats named variants as their own lines", () => {
+ const { current, older } = rankModels([
+ { id: "gpt-5.6-sol", label: "GPT-5.6 Sol" },
+ { id: "gpt-5.6-luna", label: "GPT-5.6 Luna" },
+ { id: "gpt-5.5", label: "GPT-5.5" },
+ { id: "gpt-5.2", label: "GPT-5.2" },
+ ]);
+ expect(ids(current)).toEqual(["gpt-5.6-sol", "gpt-5.6-luna", "gpt-5.5"]);
+ expect(ids(older)).toEqual(["gpt-5.2"]);
+ });
+
+ it("sorts the lineup newest first and keeps the default on top", () => {
+ const { current } = rankModels([
+ { id: "", label: "Default model" },
+ { id: "gemini-2.5-flash", label: "Gemini 2.5 Flash" },
+ { id: "gemini-3.1-pro", label: "Gemini 3.1 Pro" },
+ ]);
+ expect(ids(current)).toEqual(["", "gemini-3.1-pro", "gemini-2.5-flash"]);
+ });
+
+ it("folds nothing when no model carries a version", () => {
+ const models = [{ id: "auto", label: "Auto" }, { id: "composer", label: "Composer" }];
+ expect(rankModels(models)).toEqual({ current: models, older: [] });
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/modelRanking.ts b/jarvis/ui/web/frontend/src/lib/modelRanking.ts
new file mode 100644
index 0000000000..19ad85d304
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/modelRanking.ts
@@ -0,0 +1,81 @@
+import type { CuratedModel } from "@/lib/agentChatApi";
+
+/**
+ * Splits a provider's model list into the current lineup and older models.
+ *
+ * Each model line ("Claude Opus", "Gemini Pro", "GPT Sol") keeps only its
+ * newest version in the lineup; earlier versions of that line, and named
+ * aliases without a version, move to an "older models" fold. The lineup is
+ * sorted newest version first, ties keeping the catalog's own order.
+ *
+ * Nothing is folded when the list carries no versions at all (Cursor's
+ * "Auto", a user's own aliases): there is no evidence of what is older.
+ */
+
+export interface RankedModels<T extends CuratedModel = CuratedModel> {
+ current: T[];
+ older: T[];
+}
+
+interface Parsed {
+ line: string;
+ version: number[];
+}
+
+const VERSION = /(\d+(?:[.-]\d+)*)/;
+/** Snapshot dates in ids (`-20251001`) and context sizes (`[1m]`) are not versions. */
+const NOISE = /(?:[-_]?\d{8}\b)|\[[^\]]*\]|\(\s*[^)]*\)/g;
+
+function parse(model: CuratedModel): Parsed | null {
+ for (const source of [model.label, model.id.split("/").pop() ?? model.id]) {
+ const text = (source ?? "").replace(NOISE, " ").trim();
+ const match = VERSION.exec(text);
+ if (!match) continue;
+ const version = match[1].split(/[.-]/).map(Number);
+ if (version.some((part) => !Number.isFinite(part)) || version[0] > 999) continue;
+ const line = (text.slice(0, match.index) + " " + text.slice(match.index + match[0].length))
+ .toLocaleLowerCase()
+ .replace(/[^a-z]+/g, " ")
+ .trim();
+ return { line, version };
+ }
+ return null;
+}
+
+function compareVersions(a: number[], b: number[]): number {
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
+ const diff = (a[i] ?? 0) - (b[i] ?? 0);
+ if (diff) return diff;
+ }
+ return 0;
+}
+
+export function rankModels<T extends CuratedModel>(models: T[]): RankedModels<T> {
+ const parsed = models.map((model) => ({ model, info: model.id ? parse(model) : null }));
+ if (!parsed.some((entry) => entry.info)) return { current: [...models], older: [] };
+
+ const newest = new Map<string, number[]>();
+ for (const { info } of parsed) {
+ if (!info) continue;
+ const best = newest.get(info.line);
+ if (!best || compareVersions(info.version, best) > 0) newest.set(info.line, info.version);
+ }
+
+ const byVersion = (a: (typeof parsed)[number], b: (typeof parsed)[number]) =>
+ compareVersions(b.info?.version ?? [], a.info?.version ?? []);
+ const current: typeof parsed = [];
+ const older: typeof parsed = [];
+ for (const entry of parsed) {
+ // The provider's own default ("" id) always leads.
+ if (!entry.model.id) current.unshift(entry);
+ else if (entry.info && compareVersions(entry.info.version, newest.get(entry.info.line)!) === 0) current.push(entry);
+ else older.push(entry);
+ }
+ const head = current.filter((entry) => !entry.model.id);
+ const rest = current.filter((entry) => entry.model.id).sort(byVersion);
+ return {
+ current: [...head, ...rest].map((entry) => entry.model),
+ // Array.prototype.sort is stable, so equal versions keep catalog order.
+ older: older.sort(byVersion).map((entry) => entry.model),
+ };
+}