Skip to content

The agent that grows with you

feat(desktop-sdk): model menu row decorations (MODEL_MENU_ROW_AREA)

teknium1c0c029c37638
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.test.tsx b/apps/desktop/src/app/shell/model-catalog-menu.test.tsx
index 84f649af025..61bf9a1095a 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.test.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.test.tsx
@@ -15,6 +15,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-libra
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { DropdownMenu, DropdownMenuContent } from '@/components/ui/dropdown-menu'
+import { registry } from '@/contrib/registry'
import { queryClient } from '@/lib/query-client'
import { $favoriteModels, favoriteModelKey, toggleFavoriteModel } from '@/store/favorite-models'
import { $localModelsEnabled } from '@/store/local-models-flag'
@@ -31,6 +32,7 @@ import { $defaultReasoningEffort } from '@/store/session'
import type { LocalRuntimeJob } from '@/types/hermes'
import { ModelCatalogMenu, ModelMenuCloseContext, type ModelMenuController } from './model-catalog-menu'
+import { MODEL_MENU_ROW_AREA, type ModelMenuRowContribution } from './model-menu-row-decorations'
// Radix calls these on open; jsdom doesn't implement them.
beforeAll(() => {
@@ -86,6 +88,48 @@ afterEach(() => {
vi.clearAllMocks()
})
+describe('model menu row decorations (MODEL_MENU_ROW_AREA)', () => {
+ it('paints a contributed icon and badge in the row slots, skipping a throwing decorator', async () => {
+ const dispose = [
+ registry.register({
+ area: MODEL_MENU_ROW_AREA,
+ data: {
+ decorate: () => {
+ throw new Error('broken plugin')
+ }
+ } satisfies ModelMenuRowContribution,
+ id: 'broken'
+ }),
+ registry.register({
+ area: MODEL_MENU_ROW_AREA,
+ data: {
+ decorate: ({ model, provider }) =>
+ model === 'gemini-3.1-pro' ? { badge: 'new', icon: <img alt="" data-testid={`mark-${provider}`} /> } : null
+ } satisfies ModelMenuRowContribution,
+ id: 'marks'
+ })
+ ]
+
+ try {
+ renderMenu()
+
+ const row = (await screen.findByText('Gemini 3.1 Pro')).closest('[role="menuitem"]')!
+ const icon = row.querySelector('[data-slot="model-menu-row-icon"]')
+
+ expect(icon?.querySelector('[data-testid="mark-google"]')).toBeTruthy()
+ expect(row.querySelector('[data-model-menu-row-badge]')?.textContent).toBe('new')
+
+ // A decorator returning null leaves its row bare.
+ const bare = screen.getByText('Gemini 2.5').closest('[role="menuitem"]')!
+
+ expect(bare.querySelector('[data-slot="model-menu-row-icon"]')).toBeNull()
+ expect(bare.querySelector('[data-model-menu-row-badge]')).toBeNull()
+ } finally {
+ dispose.forEach(release => release())
+ }
+ })
+})
+
describe('the current row effort', () => {
it('does not label the current model with the profile default before its session reports one (#79807)', async () => {
$defaultReasoningEffort.set('ultra')
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.tsx b/apps/desktop/src/app/shell/model-catalog-menu.tsx
index 55efe0e78a6..3777132678e 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.tsx
@@ -65,6 +65,7 @@ import { $defaultReasoningEffort } from '@/store/session'
import type { LocalModelLoadProgress, LocalRuntimeJob } from '@/types/hermes'
import { type FastControl, ModelEditSubmenu, resolveFastControl } from './model-edit-submenu'
+import { ModelMenuRowIcon, useModelMenuRowDecoration } from './model-menu-row-decorations'
// Lets the host dropdown (model-pill, a kanban field trigger, …) hand the panel
// a way to dismiss itself so clicking a model row commits + closes, while the
@@ -976,6 +977,7 @@ function ModelFamilyRow({
const isCurrent = activeId !== null
const { name, tag } = modelDisplayParts(family.id)
+ const decoration = useModelMenuRowDecoration({ label: name, model: family.id, provider: provider.slug })
const caps = provider.capabilities?.[family.id]
// Live per-model $/Mtok pricing (Nous Portal and other providers that ship
@@ -1085,6 +1087,7 @@ function ModelFamilyRow({
</button>
</Tip>
<span className="flex min-w-0 flex-1 items-center gap-1.5">
+ {decoration.icon !== undefined ? <ModelMenuRowIcon icon={decoration.icon} /> : null}
<span className="min-w-0 truncate">
<HighlightMatches foldSeparators query={search} text={name} />
</span>
@@ -1093,6 +1096,16 @@ function ModelFamilyRow({
{chip}
</Badge>
))}
+ {decoration.badge ? (
+ <Badge
+ className="shrink-0 uppercase tracking-wide"
+ data-model-menu-row-badge=""
+ size="xs"
+ variant="muted"
+ >
+ {decoration.badge}
+ </Badge>
+ ) : null}
</span>
{loadProgress ? (
<span className="ml-auto flex shrink-0 items-center gap-1.5" title={copyPicker.loadingIntoMemory}>
diff --git a/apps/desktop/src/app/shell/model-menu-row-decorations.tsx b/apps/desktop/src/app/shell/model-menu-row-decorations.tsx
new file mode 100644
index 00000000000..d538c9aaf0d
--- /dev/null
+++ b/apps/desktop/src/app/shell/model-menu-row-decorations.tsx
@@ -0,0 +1,99 @@
+import { isValidElement, type ReactElement, type ReactNode, useMemo } from 'react'
+
+import { ErrorBoundary } from '@/components/error-boundary'
+import { useContributions } from '@/contrib/react/use-contributions'
+
+/**
+ * Model menu row decorations — a plugin's per-model mark inside the native
+ * model catalog menu (the composer's model pill menu and every other surface
+ * that renders `ModelCatalogMenu`).
+ *
+ * data kind (`data`): modelMenu.row (ModelMenuRowContribution)
+ *
+ * Core keeps the row: its markup, name, chips, star, submenu and what a click
+ * means. A contribution only fills two fixed slots — a leading icon before the
+ * name and a trailing badge after core's own chips — so several plugins can
+ * register at once without fighting over the row.
+ */
+export const MODEL_MENU_ROW_AREA = 'modelMenu.row'
+
+/** What a row decorator gets to branch on. Deliberately small: every field
+ * here is a standing compatibility promise to the plugins using it. */
+export interface ModelMenuRowContext {
+ /** The display name core paints on the row (`Opus 4.5`). */
+ label: string
+ /** The model id the row commits (the base id when a `-fast` sibling shares it). */
+ model: string
+ /** The provider slug the row belongs to (`anthropic`, `openrouter`, …). */
+ provider: string
+}
+
+export interface ModelMenuRowDecoration {
+ /** Plain text chip after core's own chips (`$3/M`, `NEW`). */
+ badge?: string
+ /** Leading mark drawn in a fixed 1rem box before the name: an element
+ * (`<img>`, `<svg>`, a component) or short text (an emoji, a monogram). */
+ icon?: ReactNode
+}
+
+/** Payload of a `modelMenu.row` data contribution. Return the decoration for
+ * this row, or `null` for rows you have nothing to say about. */
+export interface ModelMenuRowContribution {
+ decorate: (row: ModelMenuRowContext) => ModelMenuRowDecoration | null
+}
+
+const usableIcon = (icon: unknown): icon is ReactNode =>
+ isValidElement(icon) || (typeof icon === 'string' && icon.trim() !== '')
+
+const usableBadge = (badge: unknown): badge is string => typeof badge === 'string' && badge.trim() !== ''
+
+/** The row's decoration: per slot, the first contribution (registry order)
+ * that supplies a usable value wins, so an icon plugin and a badge plugin
+ * compose. A decorator that throws or returns garbage declines — a broken
+ * plugin can never take the menu down. */
+export function useModelMenuRowDecoration({ label, model, provider }: ModelMenuRowContext): ModelMenuRowDecoration {
+ const contributions = useContributions(MODEL_MENU_ROW_AREA)
+
+ return useMemo(() => {
+ const result: ModelMenuRowDecoration = {}
+
+ for (const contribution of contributions) {
+ if (result.icon !== undefined && result.badge !== undefined) {
+ break
+ }
+
+ try {
+ const { badge, icon } =
+ (contribution.data as ModelMenuRowContribution | undefined)?.decorate?.({ label, model, provider }) ?? {}
+
+ if (result.icon === undefined && usableIcon(icon)) {
+ result.icon = icon
+ }
+
+ if (result.badge === undefined && usableBadge(badge)) {
+ result.badge = badge.trim()
+ }
+ } catch {
+ // Decline on throw: the next contribution, then the bare row, wins.
+ }
+ }
+
+ return result
+ }, [contributions, label, model, provider])
+}
+
+/** The fixed leading slot. Its own boundary: a plugin component that throws
+ * while rendering blanks only its icon, never the row or the menu. */
+export function ModelMenuRowIcon({ icon }: { icon: ReactNode }): ReactElement {
+ return (
+ <span
+ aria-hidden="true"
+ className="grid size-4 shrink-0 place-items-center overflow-hidden text-[0.75rem] leading-none [&>img]:size-full [&>img]:object-contain [&>svg]:size-full"
+ data-slot="model-menu-row-icon"
+ >
+ <ErrorBoundary fallback={() => null} label={`contrib:${MODEL_MENU_ROW_AREA}`}>
+ {icon}
+ </ErrorBoundary>
+ </span>
+ )
+}
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index f47dfa846af..e49e7317f0b 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -1771,6 +1771,17 @@ export {
ModelMenuCloseContext,
type ModelMenuController
} from '@/app/shell/model-catalog-menu'
+/** Per-model marks inside that same menu: register a `MODEL_MENU_ROW_AREA`
+ * data contribution whose `decorate({ provider, model, label })` returns
+ * `{ icon?, badge? }` (or `null`). Core paints the leading icon slot and a
+ * trailing badge chip; per slot the first usable answer wins, and a throwing
+ * decorator is skipped. Never patch the menu's rows yourself. */
+export {
+ MODEL_MENU_ROW_AREA,
+ type ModelMenuRowContext,
+ type ModelMenuRowContribution,
+ type ModelMenuRowDecoration
+} from '@/app/shell/model-menu-row-decorations'
export type { StatusbarItem } from '@/app/shell/statusbar-controls'
export type { TitlebarTool } from '@/app/shell/titlebar-controls'
/** Canonical raw message renderer: applies Desktop message transforms (including