Skip to content

The agent that grows with you

feat(desktop): add a custom model from the composer menu and pickers

brooklyn!7fe3318ed5c2
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.tsx b/apps/desktop/src/app/shell/model-catalog-menu.tsx
index 1db80a27c60..6420356d07e 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.tsx
@@ -30,6 +30,7 @@ import { reasoningEffortLabel } from '@/lib/reasoning-effort'
import { foldIncludes, normalize } from '@/lib/text'
import { useStoreSelector } from '@/lib/use-session-slice'
import { cn } from '@/lib/utils'
+import { $customModels, addCustomModel, customModelCandidate, withCustomModels } from '@/store/custom-models'
import { $localModelsEnabled } from '@/store/local-models-flag'
import { $localRuntimeJobs, runningModelDownloads, watchLocalRuntimeJobs } from '@/store/local-runtime-jobs'
import {
@@ -139,6 +140,11 @@ export function ModelCatalogMenu({
const copyPicker = t.modelPicker
const closeMenu = useContext(ModelMenuCloseContext)
const [search, setSearch] = useState('')
+ // "Add custom model…" turns the search box into slug entry: the catalog
+ // steps aside until something is typed, and the placeholder says what to
+ // type. Typing a slug without this works too; the row just makes it findable.
+ const [slugEntry, setSlugEntry] = useState(false)
+ const searchRef = useRef<HTMLInputElement>(null)
const collapsedProviders = useStoreCollapsed()
const defaultEffort = useDefaultEffort()
// Which models the user curated in Edit Models. Read HERE rather than taken
@@ -146,6 +152,7 @@ export function ModelCatalogMenu({
// catalog must show the same shortlist. A per-caller opt-in is how the board
// and the composer would end up disagreeing about what "my models" means.
const visibleModels = useStore($visibleModels)
+ const customModels = useStore($customModels)
const modelOptions = useQuery({
queryKey: modelOptionsQueryKey(profile, sessionId, ownerConnectionId),
@@ -246,14 +253,17 @@ export function ModelCatalogMenu({
const pickerProviders = useMemo(
() =>
- providers?.filter(
- provider =>
- provider.slug.toLowerCase() !== 'moa' &&
- // Strict --local gate: staged local models exist on disk, but
- // without the flag the GUI doesn't offer them.
- (localModelsEnabled || provider.slug !== LOCAL_PROVIDER_SLUG)
- ) ?? [],
- [providers, localModelsEnabled]
+ withCustomModels(
+ providers?.filter(
+ provider =>
+ provider.slug.toLowerCase() !== 'moa' &&
+ // Strict --local gate: staged local models exist on disk, but
+ // without the flag the GUI doesn't offer them.
+ (localModelsEnabled || provider.slug !== LOCAL_PROVIDER_SLUG)
+ ) ?? [],
+ customModels
+ ),
+ [providers, localModelsEnabled, customModels]
)
const current = controller.current
@@ -289,7 +299,31 @@ export function ModelCatalogMenu({
[moaPresets, q]
)
- const selectFamily = async (family: ModelFamily, provider: ModelOptionProvider) => {
+ // A typed id no provider lists is still a model to the backend. Offer it as
+ // a row per configured provider (the current one first) so a slug the
+ // catalog lacks is one Enter away, then remember it as a normal row.
+ const customSlug = customModelCandidate(search, pickerProviders)
+ const hideCatalog = slugEntry && !search
+
+ // The scrolling catalog list only mounts when it has rows; otherwise a
+ // section below it (MoA, custom slug) would sit under two separators.
+ const hasList = !hideCatalog && (groups.length > 0 || shownDownloads.length > 0)
+
+ const customProviders = useMemo(
+ () =>
+ customSlug
+ ? pickerProviders
+ .filter(provider => (provider.models ?? []).length > 0)
+ .sort(
+ (a, b) =>
+ Number(catalogProviderMatches(b, current.provider)) -
+ Number(catalogProviderMatches(a, current.provider))
+ )
+ : [],
+ [customSlug, pickerProviders, current.provider]
+ )
+
+ const selectFamily = async (family: ModelFamily, provider: ModelOptionProvider): Promise<boolean> => {
const caps = provider.capabilities?.[family.id]
const preset = controller.presetFor(provider.slug, family.id)
@@ -300,7 +334,7 @@ export function ModelCatalogMenu({
const targetId = variantFast && preset.fast === true ? family.fastId! : family.id
if ((await controller.select(targetId, provider.slug)) === false) {
- return
+ return false
}
controller.applyPreset(
@@ -310,6 +344,8 @@ export function ModelCatalogMenu({
},
{ model: family.id, provider: provider.slug }
)
+
+ return true
}
const selectMoaPreset = async (preset: string) => {
@@ -320,10 +356,20 @@ export function ModelCatalogMenu({
closeMenu()
}
+ const selectCustom = async (slug: string, provider: ModelOptionProvider) => {
+ if (!(await selectFamily({ fastId: null, id: slug }, provider))) {
+ return
+ }
+
+ addCustomModel(provider.slug, slug, provider)
+ closeMenu()
+ }
+
// ── Keyboard selection (cmdk semantics on a Radix menu) ───────────────────
// One flat list mirroring EXACTLY what's rendered (collapse, filter, presets),
// so the selection can never sit on a hidden row.
type KbRow =
+ | { key: string; kind: 'custom'; provider: ModelOptionProvider; slug: string }
| { family: ModelFamily; key: string; kind: 'family'; provider: ModelOptionProvider }
| { key: string; kind: 'moa'; preset: string }
@@ -339,9 +385,17 @@ export function ModelCatalogMenu({
provider: group.provider
}))
),
- ...shownMoaPresets.map((preset): KbRow => ({ key: `moa:${preset}`, kind: 'moa', preset }))
+ ...shownMoaPresets.map((preset): KbRow => ({ key: `moa:${preset}`, kind: 'moa', preset })),
+ ...(customSlug
+ ? customProviders.map((provider): KbRow => ({
+ key: `custom:${provider.slug}`,
+ kind: 'custom',
+ provider,
+ slug: customSlug
+ }))
+ : [])
],
- [groups, collapsedProviders, search, shownMoaPresets]
+ [groups, collapsedProviders, search, shownMoaPresets, customSlug, customProviders]
)
const [kbOverride, setKbOverride] = useState<null | number>(null)
@@ -352,8 +406,10 @@ export function ModelCatalogMenu({
const rowIsCurrent = (row: KbRow) =>
row.kind === 'moa'
? current.provider === 'moa' && row.preset === current.model
- : catalogProviderMatches(row.provider, current.provider) &&
- (row.family.id === current.model || row.family.fastId === current.model)
+ : row.kind === 'custom'
+ ? false
+ : catalogProviderMatches(row.provider, current.provider) &&
+ (row.family.id === current.model || row.family.fastId === current.model)
const autoIndex = q ? (kbRows.length > 0 ? 0 : -1) : kbRows.findIndex(row => rowIsCurrent(row))
@@ -383,6 +439,12 @@ export function ModelCatalogMenu({
return
}
+ if (row.kind === 'custom') {
+ void selectCustom(row.slug, row.provider)
+
+ return
+ }
+
if (!rowIsCurrent(row)) {
void selectFamily(row.family, row.provider)
}
@@ -430,13 +492,14 @@ export function ModelCatalogMenu({
setSearch(value)
setKbOverride(null)
}}
- placeholder={copy.search}
+ placeholder={slugEntry ? copyPicker.customModelPlaceholder : copy.search}
+ ref={searchRef}
value={search}
/>
- <DropdownMenuSeparator className="mx-0" />
+ {!hideCatalog && <DropdownMenuSeparator className="mx-0" />}
- {loading ? (
+ {hideCatalog ? null : loading ? (
<DropdownMenuGroup className="py-1">
{Array.from({ length: 4 }, (_, index) => (
<DropdownMenuItem
@@ -453,11 +516,11 @@ export function ModelCatalogMenu({
<DropdownMenuItem className={dropdownMenuRow} disabled>
{error}
</DropdownMenuItem>
- ) : groups.length === 0 && moaPresets.length === 0 && shownDownloads.length === 0 ? (
+ ) : groups.length === 0 && moaPresets.length === 0 && shownDownloads.length === 0 && !customSlug ? (
<DropdownMenuItem className={dropdownMenuRow} disabled>
{copy.noModels}
</DropdownMenuItem>
- ) : (
+ ) : hasList ? (
<div className={cn('max-h-[max(150px,30dvh)] overflow-y-auto py-0.5', quietRows)} ref={listRef}>
{groups.map(group => {
const slug = group.provider.slug
@@ -621,11 +684,11 @@ export function ModelCatalogMenu({
</DropdownMenuGroup>
)}
</div>
- )}
+ ) : null}
- {shownMoaPresets.length > 0 ? (
+ {!hideCatalog && shownMoaPresets.length > 0 ? (
<div className={cn(quietRows)}>
- <DropdownMenuSeparator className="mx-0" />
+ {hasList ? <DropdownMenuSeparator className="mx-0" /> : null}
<DropdownMenuLabel className={dropdownMenuSectionLabel}>MoA presets</DropdownMenuLabel>
{shownMoaPresets.map(preset => {
const isCurrentMoa = current.provider === 'moa' && current.model === preset
@@ -649,6 +712,28 @@ export function ModelCatalogMenu({
</div>
) : null}
+ {customSlug && customProviders.length > 0 ? (
+ <div className={cn(quietRows)}>
+ {hasList || shownMoaPresets.length > 0 ? <DropdownMenuSeparator className="mx-0" /> : null}
+ <DropdownMenuLabel className={dropdownMenuSectionLabel}>{copyPicker.customModel}</DropdownMenuLabel>
+ {customProviders.map(provider => (
+ <DropdownMenuItem
+ key={`custom:${provider.slug}`}
+ onSelect={event => {
+ event.preventDefault()
+ void selectCustom(customSlug, provider)
+ }}
+ {...kbRowProps(`custom:${provider.slug}`)}
+ >
+ <span className="min-w-0 flex-1 truncate">
+ {customSlug}
+ <span className="text-(--ui-text-tertiary)"> {provider.name}</span>
+ </span>
+ </DropdownMenuItem>
+ ))}
+ </div>
+ ) : null}
+
{/* Curation belongs to the catalog, not to one host: wherever you can
pick a model you can say which models you want, and the shortlist is
the same everywhere because it's one stored preference. It shares the
@@ -657,6 +742,20 @@ export function ModelCatalogMenu({
trailing block it has always rendered. */}
<DropdownMenuSeparator className="mx-0" />
{footer}
+ <DropdownMenuItem
+ className={cn(dropdownMenuRow, 'text-(--ui-text-tertiary)', slugEntry && 'text-foreground')}
+ onSelect={event => {
+ event.preventDefault()
+ setSearch('')
+ setKbOverride(null)
+ setSlugEntry(true)
+ // Radix hands focus back to the row after onSelect; refocus after.
+ window.setTimeout(() => searchRef.current?.focus(), 0)
+ }}
+ >
+ <Codicon name="add" size="0.75rem" />
+ {copyPicker.addCustomModelAction}
+ </DropdownMenuItem>
<DropdownMenuItem
className={cn(dropdownMenuRow, 'text-(--ui-text-tertiary)')}
onSelect={() => setModelVisibilityOpen(true)}
@@ -713,7 +812,7 @@ function DownloadingModelRow({ jobId, target }: { jobId: string; target: string
// spans every available model so anything is reachable past the cut. A search
// is itself a narrowing action, so we do NOT cap per-provider matches.
function groupModels(
- providers: ModelOptionProvider[],
+ providers: readonly ModelOptionProvider[],
search: string,
current: { model: string; provider: string },
visible: Set<string> | null
diff --git a/apps/desktop/src/components/model-picker.tsx b/apps/desktop/src/components/model-picker.tsx
index e6d41580907..2260d8e09fd 100644
--- a/apps/desktop/src/components/model-picker.tsx
+++ b/apps/desktop/src/components/model-picker.tsx
@@ -1,5 +1,6 @@
import type { ModelOptionProvider, ModelPricing } from '@hermes/shared'
import { fuzzyRank, modelSearchText } from '@hermes/shared'
+import { useStore } from '@nanostores/react'
import { useQuery } from '@tanstack/react-query'
import { useEffect, useMemo, useState } from 'react'
@@ -9,6 +10,7 @@ import { catalogProviderMatches, modelOptionsQueryKey, requestModelOptions } fro
import { currentPickerSelection } from '@/lib/model-status-label'
import { foldIncludes, normalize } from '@/lib/text'
import { useStoreSelector } from '@/lib/use-session-slice'
+import { $customModels, addCustomModel, customModelCandidate, withCustomModels } from '@/store/custom-models'
import { $localModelsEnabled } from '@/store/local-models-flag'
import { $localRuntimeJobs, runningModelDownloads, watchLocalRuntimeJobs } from '@/store/local-runtime-jobs'
import type { LocalModelLoadProgress } from '@/types/hermes'
@@ -147,7 +149,8 @@ export function ModelPickerDialog({
})
}, [open, refetchOptions])
- const providers = modelOptions.data?.providers ?? []
+ const customModels = useStore($customModels)
+ const providers = withCustomModels(modelOptions.data?.providers ?? [], customModels)
const { model: optionsModel, provider: optionsProvider } = currentPickerSelection(
{ model: currentModel, provider: currentProvider },
@@ -167,6 +170,11 @@ export function ModelPickerDialog({
onOpenChange(false)
}
+ const selectCustomModel = (provider: ModelOptionProvider, model: string) => {
+ addCustomModel(provider.slug, model, provider)
+ selectModel(provider, model)
+ }
+
// Open the full onboarding provider selector to add/switch a provider.
// Reuses the entire onboarding flow (OAuth rows, API-key form, device-code,
// model-confirm) instead of duplicating provider UI here. Closes the picker
@@ -201,6 +209,7 @@ export function ModelPickerDialog({
error={error}
loading={loading}
loadingModels={loadingModels}
+ onSelectCustomModel={selectCustomModel}
onSelectModel={selectModel}
providers={providers}
search={search}
@@ -230,16 +239,18 @@ function ModelResults({
downloads,
loadingModels,
onSelectModel,
+ onSelectCustomModel,
search
}: {
loading: boolean
error: string | null
- providers: ModelOptionProvider[]
+ providers: readonly ModelOptionProvider[]
currentModel: string
currentProvider: string
downloads: { jobId: string; target: string }[]
loadingModels: Record<string, LocalModelLoadProgress>
onSelectModel: (provider: ModelOptionProvider, model: string) => void
+ onSelectCustomModel: (provider: ModelOptionProvider, model: string) => void
search: string
}) {
const { t } = useI18n()
@@ -294,6 +305,17 @@ function ModelResults({
const visibleDownloads = downloads.filter(job => !q || foldIncludes(job.target || '', q))
const hasLocalGroup = configured.some(p => p.slug === LOCAL_PROVIDER_SLUG)
+ // A typed id no provider lists: one row per configured provider, current
+ // provider first, so the slug is one Enter away and remembered afterwards.
+ const customSlug = customModelCandidate(search, configured)
+
+ const customProviders = customSlug
+ ? [...configured].sort(
+ (a, b) =>
+ Number(catalogProviderMatches(b, currentProvider)) - Number(catalogProviderMatches(a, currentProvider))
+ )
+ : []
+
return (
<>
{configured.map(provider => {
@@ -381,6 +403,21 @@ function ModelResults({
))}
</CommandGroup>
)}
+ {customSlug && customProviders.length > 0 && (
+ <CommandGroup heading={copy.customModel} key="custom-model">
+ {customProviders.map(provider => (
+ <CommandItem
+ className="flex items-center gap-2 pl-6 font-mono"
+ key={`custom:${provider.slug}`}
+ onSelect={() => onSelectCustomModel(provider, customSlug)}
+ value={`custom:${provider.slug}:${customSlug}`}
+ >
+ <span className="min-w-0 flex-1 truncate">{customSlug}</span>
+ <span className="shrink-0 text-[0.66rem] text-muted-foreground">{provider.name}</span>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ )}
</>
)
}
diff --git a/apps/desktop/src/components/model-visibility-dialog.tsx b/apps/desktop/src/components/model-visibility-dialog.tsx
index e5bbbed42fd..e739de77760 100644
--- a/apps/desktop/src/components/model-visibility-dialog.tsx
+++ b/apps/desktop/src/components/model-visibility-dialog.tsx
@@ -12,10 +12,18 @@ import { HighlightMatches } from '@/components/ui/highlight-matches'
import { Switch } from '@/components/ui/switch'
import type { HermesGateway } from '@/hermes'
import { useI18n } from '@/i18n'
-import { Search } from '@/lib/icons'
+import { Plus, Search, X } from '@/lib/icons'
import { modelOptionsQueryKey, requestModelOptions } from '@/lib/model-options'
import { displayModelName, modelDisplayParts } from '@/lib/model-status-label'
import { foldIncludes, normalize } from '@/lib/text'
+import {
+ $customModels,
+ addCustomModel,
+ customModelCandidate,
+ isCustomModel,
+ removeCustomModel,
+ withCustomModels
+} from '@/store/custom-models'
import {
$visibleModels,
collapseModelFamilies,
@@ -52,6 +60,7 @@ export function ModelVisibilityDialog({
const [search, setSearch] = useState('')
const stored = useStore($visibleModels)
const collapsedProviders = useStore($collapsedProviders)
+ const customModels = useStore($customModels)
const modelOptions = useQuery({
queryKey: modelOptionsQueryKey(profile, sessionId, ownerConnectionId),
@@ -60,8 +69,12 @@ export function ModelVisibilityDialog({
})
const providers = useMemo(
- () => (modelOptions.data?.providers ?? []).filter(provider => (provider.models ?? []).length > 0),
- [modelOptions.data]
+ () =>
+ withCustomModels(
+ (modelOptions.data?.providers ?? []).filter(provider => (provider.models ?? []).length > 0),
+ customModels
+ ),
+ [modelOptions.data, customModels]
)
useEffect(() => seedKnownModels(providers), [providers])
@@ -81,6 +94,10 @@ export function ModelVisibilityDialog({
const matches = (provider: ModelOptionProvider, model: string) =>
!q || foldIncludes(`${model} ${provider.name} ${provider.slug} ${displayModelName(model)}`, q)
+ // Typing an id no provider lists offers to add it — same gesture as the
+ // pickers, minus the switch — and the new row lands visible.
+ const customSlug = customModelCandidate(search, providers)
+
return (
<Dialog onOpenChange={onOpenChange} open={open}>
<DialogContent bodyClassName="gap-0 overflow-hidden p-0" className="max-w-xs">
@@ -159,6 +176,21 @@ export function ModelVisibilityDialog({
<HighlightMatches foldSeparators query={search} text={name} />
{tag ? <span className="text-(--ui-text-tertiary)"> {tag}</span> : null}
</span>
+ {isCustomModel(customModels, provider.slug, family.id) && (
+ <Button
+ aria-label={copy.removeCustomModel}
+ className="-my-1 text-(--ui-text-tertiary)"
+ onClick={event => {
+ event.preventDefault()
+ removeCustomModel(provider.slug, family.id)
+ }}
+ size="icon-xs"
+ type="button"
+ variant="ghost"
+ >
+ <X className="size-3" />
+ </Button>
+ )}
<Switch
checked={visible.has(key)}
onCheckedChange={() => toggle(provider, family.id)}
@@ -171,6 +203,30 @@ export function ModelVisibilityDialog({
)
})
)}
+ {customSlug && providers.length > 0 && (
+ <div className="py-0.5">
+ <div className="px-3 pb-0.5 pt-1 text-[0.625rem] font-semibold uppercase tracking-wider text-(--ui-text-tertiary)">
+ {copy.addCustomModel}
+ </div>
+ {providers.map(provider => (
+ <button
+ className="flex w-full cursor-pointer items-center gap-2 px-3 py-1 text-left text-xs hover:bg-(--ui-control-active-background)"
+ key={`custom:${provider.slug}`}
+ onClick={() => {
+ addCustomModel(provider.slug, customSlug, provider)
+ setSearch('')
+ }}
+ type="button"
+ >
+ <span className="min-w-0 flex-1 truncate">
+ {customSlug}
+ <span className="text-(--ui-text-tertiary)"> {provider.name}</span>
+ </span>
+ <Plus className="size-3 shrink-0 text-(--ui-text-tertiary)" />
+ </button>
+ ))}
+ </div>
+ )}
</div>
<div className="px-3 py-2">