The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the custom-model action out of the model id namespace
brooklyn!a88121ac8c2e
diff --git a/apps/desktop/src/app/settings/model-select.tsx b/apps/desktop/src/app/settings/model-select.tsxindex caabf146a27..385fec618a4 100644--- a/apps/desktop/src/app/settings/model-select.tsx+++ b/apps/desktop/src/app/settings/model-select.tsx@@ -18,9 +18,17 @@ import { CONTROL_TEXT } from './constants'export const withActive = (models: readonly string[], active: string): readonly string[] =>active && !models.includes(active) ? [active, ...models] : models-// Radix <Select> items cannot be typed into; this sentinel row swaps the-// control for a text field. Never a real model id.-const CUSTOM_ITEM = '__custom__'+// Radix <Select> items cannot be typed into; an action row swaps the control+// for a text field. Model ids live under their own prefix so no slug — this+// feature admits any whitespace-free string — can alias the action's value.+const CUSTOM_ITEM = 'custom'+const MODEL_PREFIX = 'model:'++export const toItemValue = (model: string): string => (model ? MODEL_PREFIX + model : '')++/** The model id behind a Radix item value; `null` for the custom action row. */+export const fromItemValue = (item: string): string | null =>+ item.startsWith(MODEL_PREFIX) ? item.slice(MODEL_PREFIX.length) : nullinterface ModelSelectProps {'aria-label'?: string@@ -122,20 +130,22 @@ export function ModelSelect({return (<SelectonValueChange={next => {- if (next === CUSTOM_ITEM) {+ const model = fromItemValue(next)++ if (model === null) {setTyping(true)} else {- onValueChange(next)+ onValueChange(model)}}}- value={value}+ value={toItemValue(value)}><SelectTrigger aria-label={ariaLabel} className={cn(className, CONTROL_TEXT)}><SelectValue placeholder={m.model} /></SelectTrigger><SelectContent>{withActive(models, value).map(model => (- <SelectItem key={model} value={model}>+ <SelectItem key={model} value={toItemValue(model)}>{model}</SelectItem>))}diff --git a/apps/desktop/src/app/settings/with-active.test.ts b/apps/desktop/src/app/settings/with-active.test.tsindex 26947a71697..8ff7b9e2941 100644--- a/apps/desktop/src/app/settings/with-active.test.ts+++ b/apps/desktop/src/app/settings/with-active.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest'-import { withActive } from './model-select'+import { fromItemValue, toItemValue, withActive } from './model-select'// A Radix <Select> shows a blank trigger when its `value` matches no// <SelectItem>. `withActive` guarantees the controlled value is always@@ -20,3 +20,16 @@ describe('withActive', () => {expect(withActive(curated, '')).toEqual(curated)})})++// The "Custom model…" action row shares the Radix value namespace with the+// model rows. Any whitespace-free slug is a legal model id here, so a model+// must round-trip and never decode as the action.+describe('item values', () => {+ it.each(['hermes-4', '__custom__', 'custom', 'model:', 'model:custom'])('round-trips %s as a model', slug => {+ expect(fromItemValue(toItemValue(slug))).toBe(slug)+ })++ it('keeps an empty selection empty so the trigger shows its placeholder', () => {+ expect(toItemValue('')).toBe('')+ })+})