The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): model-pill label providers for plugins
tobenwarrior2b4a5a09243b
diff --git a/apps/desktop/src/app/chat/composer/contrib.ts b/apps/desktop/src/app/chat/composer/contrib.tsindex ab4f205bb2f..41a6f2c820b 100644--- a/apps/desktop/src/app/chat/composer/contrib.ts+++ b/apps/desktop/src/app/chat/composer/contrib.ts@@ -37,7 +37,8 @@ export const COMPOSER_AREAS = {middleware: 'composer.middleware',attachments: 'composer.attachments',microActions: 'composer.microActions',- atCompletions: 'composer.atCompletions'+ atCompletions: 'composer.atCompletions',+ modelPill: 'composer.modelPill'} as constexport interface ComposerDraft {@@ -159,3 +160,50 @@ export function useComposerMicroActionProviders(): ComposerMicroActionProvider[][contributions])}++/** What a model-pill label provider gets to branch on. Deliberately small:+ * every field here is a standing compatibility promise to the plugins using it. */+export interface ComposerModelPillContext {+ /** The model slug the pill would show. */+ model: string+ /** The session's live reasoning effort ('' when the model has none). */+ reasoningEffort: string+ /** Floating-composer mode renders only the chevron; providers are not consulted. */+ compact: boolean+}++/** Payload of a `composer.modelPill` data contribution — the pill's label text.+ * Return the label to show, or `null` to let the next provider (then the core+ * label) win. The pill keeps its chrome and menu; only the label changes. */+export interface ComposerModelPillProvider {+ label: (ctx: ComposerModelPillContext) => null | string+}++/** The first provider-supplied pill label, or `null` for the core label. A+ * throwing provider is treated as declining — a broken plugin can't blank the+ * pill. */+export function useComposerModelPillLabel(ctx: ComposerModelPillContext): null | string {+ const contributions = useContributions(COMPOSER_AREAS.modelPill)++ return useMemo(() => {+ if (ctx.compact) {+ return null+ }++ for (const contribution of contributions) {+ const provider = contribution.data as ComposerModelPillProvider | undefined++ try {+ const label = provider?.label?.(ctx)++ if (label) {+ return label+ }+ } catch {+ // Decline on throw: the next provider, then the core label, wins.+ }+ }++ return null+ }, [contributions, ctx.compact, ctx.model, ctx.reasoningEffort])+}diff --git a/apps/desktop/src/app/chat/composer/model-pill.test.tsx b/apps/desktop/src/app/chat/composer/model-pill.test.tsxindex 2dc32500b71..719f6275a61 100644--- a/apps/desktop/src/app/chat/composer/model-pill.test.tsx+++ b/apps/desktop/src/app/chat/composer/model-pill.test.tsx@@ -6,8 +6,10 @@ import { afterEach, describe, expect, it } from 'vitest'import type { ChatBarState } from '@/app/chat/composer/types'import { type SessionView, SessionViewProvider } from '@/app/chat/session-view'import { ModelMenuCloseContext } from '@/app/shell/model-menu-panel'+import { registry } from '@/contrib/registry'import { $activeSessionId, $currentModel, setCurrentModel, setCurrentModelSource } from '@/store/session'+import { COMPOSER_AREAS, type ComposerModelPillProvider } from './contrib'import { requestModelMenuToggle } from './focus'import { ModelPill } from './model-pill'import { RICH_INPUT_SLOT } from './rich-editor'@@ -164,3 +166,59 @@ describe('ModelPill per-surface model label', () => {expect(screen.queryByText(/primary/i)).toBeNull()})})++// The `composer.modelPill` slot: a provider may override the pill's LABEL+// (compact reasoning label, custom naming) while the pill keeps its chrome,+// pin dot, and menu. A declining provider leaves the core label untouched.+describe('ModelPill label providers', () => {+ const disposers: Array<() => void> = []++ afterEach(() => {+ disposers.splice(0).forEach(dispose => dispose())+ })++ const register = (label: ComposerModelPillProvider['label'], id = 'pill-label') =>+ disposers.push(+ registry.register({+ area: COMPOSER_AREAS.modelPill,+ data: { label } satisfies ComposerModelPillProvider,+ id,+ source: 'disk'+ })+ )++ it('renders a provider-supplied label, and the core label once the provider declines', () => {+ setCurrentModel('deepseek/deepseek-v4-flash')++ register(({ model, reasoningEffort }) => `${model} · ${reasoningEffort || 'none'}`)++ const { unmount } = render(+ <ModelPill disabled={false} model={modelState({ model: 'deepseek/deepseek-v4-flash' })} />+ )++ expect(screen.getByText('deepseek/deepseek-v4-flash · none')).toBeTruthy()+ unmount()++ // Declining provider: the override text is gone, the core label is back.+ disposers.splice(0).forEach(dispose => dispose())+ register(() => null)++ render(<ModelPill disabled={false} model={modelState({ model: 'deepseek/deepseek-v4-flash' })} />)++ expect(screen.queryByText(/· none/)).toBeNull()+ })++ it('treats a throwing provider as declining and lets the next provider win', () => {+ setCurrentModel('deepseek/deepseek-v4-flash')++ register(() => {+ throw new Error('broken provider')+ }, 'broken')+ register(() => 'next wins', 'working')++ render(<ModelPill disabled={false} model={modelState({ model: 'deepseek/deepseek-v4-flash' })} />)++ // The broken provider declined; the next one's label renders.+ expect(screen.getByText('next wins')).toBeTruthy()+ })+})diff --git a/apps/desktop/src/app/chat/composer/model-pill.tsx b/apps/desktop/src/app/chat/composer/model-pill.tsxindex 5f9379337a3..40a91bd7eb5 100644--- a/apps/desktop/src/app/chat/composer/model-pill.tsx+++ b/apps/desktop/src/app/chat/composer/model-pill.tsx@@ -16,6 +16,7 @@ import { formatModelPillLabel, providerDisplayName } from '@/lib/model-status-laimport { cn } from '@/lib/utils'import { $currentModelSource, setModelPickerOpen } from '@/store/session'+import { useComposerModelPillLabel } from './contrib'import { onComposerModelMenuRequest } from './focus'import { RICH_INPUT_SLOT } from './rich-editor'import { useComposerScope } from './scope'@@ -57,6 +58,7 @@ export function ModelPill({const currentModel = model.model || viewModelconst currentProvider = model.provider || viewProviderconst fastMode = useStore(view.$fast)+ const reasoningEffort = useStore(view.$reasoningEffort)const modelSource = useStore($currentModelSource)const runtimeId = useStore(view.$runtimeId)const [open, setOpen] = useState(false)@@ -124,12 +126,18 @@ export function ModelPill({// The model resolves a beat after the gateway/session comes up. Rather than// flash a literal "No model", show a quiet loader (inherits the pill text// color at half opacity) until a model lands.+ //+ // A `composer.modelPill` provider may override the LABEL (compact reasoning+ // label, custom naming) — the pill keeps its chrome, pin dot, and menu; only+ // the text changes, and a provider that declines leaves the core label.+ const pillLabel = useComposerModelPillLabel({ compact, model: currentModel, reasoningEffort: reasoningEffort || '' })+const label = compact ? (<ChevronDown className="size-3.5 shrink-0 opacity-70" />) : (<>{currentModel.trim() ? (- <span className="truncate">{formatModelPillLabel(currentModel, { fastMode })}</span>+ <span className="truncate">{pillLabel ?? formatModelPillLabel(currentModel, { fastMode })}</span>) : (<GlyphSpinner className="opacity-50" spinner="braille" />)}diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 0ba9404519a..8d5c7b91acb 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -1598,7 +1598,9 @@ export {type ComposerAtCompletionItem,type ComposerAtCompletionSource,type ComposerAttachmentProvider,- type ComposerMiddleware+ type ComposerMiddleware,+ type ComposerModelPillContext,+ type ComposerModelPillProvider} from '@/app/chat/composer/contrib'/** THE session status dot — the one primitive the sidebar row, the pane tabs* and the session switcher render, so a session's status can never disagreediff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.mdindex ed5d263165a..c9c5ce7fed6 100644--- a/website/docs/developer-guide/desktop-plugin-sdk.md+++ b/website/docs/developer-guide/desktop-plugin-sdk.md@@ -567,6 +567,13 @@ Migration for the held catalog plugins:row's status dot (the durable id it needed from `_lineage_root_id` is theslot's `sessionId`).+`COMPOSER_AREAS.modelPill` overrides the model pill's **label** — a provider+(`{ label: (ctx: ComposerModelPillContext) => string | null }`) receives+`{ model, reasoningEffort, compact }` and returns the text to show, or `null` to+let the next provider (then the core label) win. The pill keeps its chrome, pin+dot, and menu; only the label changes — the sanctioned replacement for the+MutationObserver text-rewriting plugins do today.+### Transcript directives — inline components the model addresses`TRANSCRIPT_DIRECTIVE_AREA` makes the transcript itself a contribution area.