The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): remember typed model slugs as custom models
brooklyn!d24d5556edc9
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.tsindex 63502cbdc91..519f2da05a7 100644--- a/apps/desktop/src/i18n/ar.ts+++ b/apps/desktop/src/i18n/ar.ts@@ -1086,6 +1086,9 @@ export const ar = defineLocale({moaSetDefault: 'تعيين الافتراضي',moaNewPresetPlaceholder: 'إعداد جديد',moaAddPreset: 'إضافة إعداد',+ customModel: 'نموذج مخصص…',+ customModelPlaceholder: 'معرّف النموذج',+ chooseFromList: 'اختر من القائمة',moaDefault: 'الافتراضي:',moaReferenceToggle: (enabled, index) => `${enabled ? 'تعطيل' : 'تفعيل'} المرجع ${index}`,moaReferenceTitle: index => `المرجع ${index}`,@@ -2739,13 +2742,18 @@ export const ar = defineLocale({proNeedsSubscription: 'يتطلب اشتراكا',free: 'مجاني',freeTier: 'طبقة مجانية',- priceTitle: 'السعر'+ priceTitle: 'السعر',+ customModel: 'نموذج مخصص',+ addCustomModelAction: 'إضافة نموذج مخصص…',+ customModelPlaceholder: 'اكتب معرّف النموذج، مثل openai/gpt-5'},modelVisibility: {title: 'النماذج',search: 'بحث في النماذج',noAuthenticatedProviders: 'لا يوجد مزوّدون مصادق عليهم.',- addProvider: 'إضافة مزوّد…'+ addProvider: 'إضافة مزوّد…',+ addCustomModel: 'إضافة نموذج مخصص',+ removeCustomModel: 'إزالة النموذج المخصص'},shell: {windowControls: 'تحكم النافذة',diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 9d8f1a125d3..69a653318ad 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -1702,6 +1702,9 @@ export const en: Translations = {moaSetDefault: 'Set default',moaNewPresetPlaceholder: 'new preset',moaAddPreset: 'Add preset',+ customModel: 'Custom model…',+ customModelPlaceholder: 'Model id',+ chooseFromList: 'Choose from list',moaDefault: 'Default:',moaReferenceToggle: (enabled, index) => `${enabled ? 'Disable' : 'Enable'} reference ${index}`,moaReferenceTitle: index => `Reference ${index}`,@@ -4377,14 +4380,19 @@ export const en: Translations = {free: 'Free',freeTier: 'Free tier',priceTitle: 'Input / Output price per million tokens',- wasPrice: 'was'+ wasPrice: 'was',+ customModel: 'Custom model',+ addCustomModelAction: 'Add custom model…',+ customModelPlaceholder: 'Type a model id, e.g. openai/gpt-5'},modelVisibility: {title: 'Models',search: 'Search models',noAuthenticatedProviders: 'No authenticated providers.',- addProvider: 'Add provider…'+ addProvider: 'Add provider…',+ addCustomModel: 'Add custom model',+ removeCustomModel: 'Remove custom model'},shell: {diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex 66abefee350..6e2616fb671 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -1280,6 +1280,9 @@ export const ja = defineLocale({moaSetDefault: 'デフォルトに設定',moaNewPresetPlaceholder: '新しいプリセット',moaAddPreset: 'プリセットを追加',+ customModel: 'カスタムモデル…',+ customModelPlaceholder: 'モデル ID',+ chooseFromList: 'リストから選択',moaDefault: 'デフォルト:',moaReferenceToggle: (enabled, index) => `参照 ${index} を${enabled ? '無効化' : '有効化'}`,moaReferenceTitle: index => `参照 ${index}`,@@ -3190,14 +3193,19 @@ export const ja = defineLocale({free: '無料',freeTier: '無料プラン',priceTitle: '100 万トークンあたりの入力/出力価格',- wasPrice: '旧価格'+ wasPrice: '旧価格',+ customModel: 'カスタムモデル',+ addCustomModelAction: 'カスタムモデルを追加…',+ customModelPlaceholder: 'モデル ID を入力(例: openai/gpt-5)'},modelVisibility: {title: 'モデル',search: 'モデルを検索',noAuthenticatedProviders: '認証済みプロバイダーがありません。',- addProvider: 'プロバイダーを追加…'+ addProvider: 'プロバイダーを追加…',+ addCustomModel: 'カスタムモデルを追加',+ removeCustomModel: 'カスタムモデルを削除'},shell: {diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.tsindex b4d82f174bf..cb434b19e8e 100644--- a/apps/desktop/src/i18n/ru.ts+++ b/apps/desktop/src/i18n/ru.ts@@ -1439,6 +1439,9 @@ export const ru = defineLocale({moaSetDefault: 'Сделать основным',moaNewPresetPlaceholder: 'новый пресет',moaAddPreset: 'Добавить пресет',+ customModel: 'Своя модель…',+ customModelPlaceholder: 'ID модели',+ chooseFromList: 'Выбрать из списка',moaDefault: 'По умолчанию:',moaReferenceToggle: (enabled, index) => `${enabled ? 'Отключить' : 'Включить'} референс ${index}`,moaReferenceTitle: index => `Референс ${index}`,@@ -3425,14 +3428,19 @@ export const ru = defineLocale({free: 'Free',freeTier: 'Бесплатный тариф',priceTitle: 'Цена вход / выход за миллион токенов',- wasPrice: 'было'+ wasPrice: 'было',+ customModel: 'Своя модель',+ addCustomModelAction: 'Добавить свою модель…',+ customModelPlaceholder: 'Введите id модели, например openai/gpt-5'},modelVisibility: {title: 'Модели',search: 'Поиск моделей',noAuthenticatedProviders: 'Нет провайдеров с аутентификацией.',- addProvider: 'Добавить провайдера…'+ addProvider: 'Добавить провайдера…',+ addCustomModel: 'Добавить свою модель',+ removeCustomModel: 'Удалить свою модель'},shell: {windowControls: 'Управление окном',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 27b42dcf76d..2128bacc844 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -1446,6 +1446,9 @@ export interface Translations {moaSetDefault: stringmoaNewPresetPlaceholder: stringmoaAddPreset: string+ customModel: string+ customModelPlaceholder: string+ chooseFromList: stringmoaDefault: stringmoaReferenceToggle: (enabled: boolean, index: number) => stringmoaReferenceTitle: (index: number) => string@@ -3658,6 +3661,9 @@ export interface Translations {freeTier: stringpriceTitle: stringwasPrice: string+ customModel: string+ addCustomModelAction: string+ customModelPlaceholder: string}modelVisibility: {@@ -3665,6 +3671,8 @@ export interface Translations {search: stringnoAuthenticatedProviders: stringaddProvider: string+ addCustomModel: string+ removeCustomModel: string}shell: {diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.tsindex 5563a7597b0..3a2e274c299 100644--- a/apps/desktop/src/i18n/zh-hant.ts+++ b/apps/desktop/src/i18n/zh-hant.ts@@ -1314,6 +1314,9 @@ export const zhHant = defineLocale({moaSetDefault: '設為預設',moaNewPresetPlaceholder: '新預設',moaAddPreset: '新增預設',+ customModel: '自訂模型…',+ customModelPlaceholder: '模型 ID',+ chooseFromList: '從清單中選擇',moaDefault: '預設:',moaReferenceToggle: (enabled, index) => `${enabled ? '停用' : '啟用'}參考 ${index}`,moaReferenceTitle: index => `參考 ${index}`,@@ -3387,14 +3390,19 @@ export const zhHant = defineLocale({free: '免費',freeTier: '免費層',priceTitle: '每百萬 Token 的輸入/輸出價格',- wasPrice: '原價'+ wasPrice: '原價',+ customModel: '自訂模型',+ addCustomModelAction: '新增自訂模型…',+ customModelPlaceholder: '輸入模型 ID,例如 openai/gpt-5'},modelVisibility: {title: '模型',search: '搜尋模型',noAuthenticatedProviders: '沒有已驗證的提供方。',- addProvider: '新增提供方…'+ addProvider: '新增提供方…',+ addCustomModel: '新增自訂模型',+ removeCustomModel: '移除自訂模型'},shell: {diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 2746fd3037a..70d0fbbf21b 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -1652,6 +1652,9 @@ export const zh = defineLocale({moaSetDefault: '设为默认',moaNewPresetPlaceholder: '新预设',moaAddPreset: '添加预设',+ customModel: '自定义模型…',+ customModelPlaceholder: '模型 ID',+ chooseFromList: '从列表中选择',moaDefault: '默认:',moaReferenceToggle: (enabled, index) => `${enabled ? '禁用' : '启用'}参考 ${index}`,moaReferenceTitle: index => `参考 ${index}`,@@ -4124,14 +4127,19 @@ export const zh = defineLocale({free: '免费',freeTier: '免费层',priceTitle: '每百万 token 的输入/输出价格',- wasPrice: '原价'+ wasPrice: '原价',+ customModel: '自定义模型',+ addCustomModelAction: '添加自定义模型…',+ customModelPlaceholder: '输入模型 ID,例如 openai/gpt-5'},modelVisibility: {title: '模型',search: '搜索模型',noAuthenticatedProviders: '没有已认证的提供方。',- addProvider: '添加提供方…'+ addProvider: '添加提供方…',+ addCustomModel: '添加自定义模型',+ removeCustomModel: '移除自定义模型'},shell: {diff --git a/apps/desktop/src/store/custom-models.test.ts b/apps/desktop/src/store/custom-models.test.tsnew file mode 100644index 00000000000..72d1be40063--- /dev/null+++ b/apps/desktop/src/store/custom-models.test.ts@@ -0,0 +1,36 @@+import type { ModelOptionProvider } from '@hermes/shared'+import { describe, expect, it } from 'vitest'++import { customModelCandidate, withCustomModels } from './custom-models'++const provider = (slug: string, models: string[]): ModelOptionProvider => ({+ models,+ name: slug,+ slug+})++describe('custom models', () => {+ it('offers a typed id only while no provider lists it', () => {+ const providers = [provider('openrouter', ['openai/gpt-5'])]++ expect(customModelCandidate('acme/model-x', providers)).toBe('acme/model-x')+ expect(customModelCandidate('OpenAI/GPT-5', providers)).toBeNull()+ expect(customModelCandidate('two words', providers)).toBeNull()+ })++ it('appends each remembered id under its own provider and keeps the input when nothing applies', () => {+ const providers = [provider('openrouter', ['openai/gpt-5']), provider('nous', ['hermes-4'])]++ const customs = [+ { model: 'acme/model-x', provider: 'openrouter' },+ { model: 'hermes-4', provider: 'nous' },+ { model: 'ghost', provider: 'missing' }+ ]++ const merged = withCustomModels(providers, customs)++ expect(merged.map(row => row.models)).toEqual([['openai/gpt-5', 'acme/model-x'], ['hermes-4']])+ expect(merged[1]).toBe(providers[1])+ expect(withCustomModels(providers, [])).toBe(providers)+ })+})diff --git a/apps/desktop/src/store/custom-models.ts b/apps/desktop/src/store/custom-models.tsnew file mode 100644index 00000000000..502ea7625c8--- /dev/null+++ b/apps/desktop/src/store/custom-models.ts@@ -0,0 +1,156 @@+import type { ModelOptionProvider } from '@hermes/shared'+import { atom } from 'nanostores'++import { persistString, storedString } from '@/lib/storage'+import { normalize } from '@/lib/text'++import {+ $visibleModels,+ emptyProviderSentinelKey,+ modelVisibilityKey,+ resolveVisibleKeys,+ setVisibleModels+} from './model-visibility'++/** A model id the user typed in rather than picked from a provider's catalog.+ * The catalog is a hint list; a slug the row lacks is still a real model to+ * the backend (a newer release, a custom endpoint), so remembering it makes+ * it a normal row on every picker instead of something to retype. */+export interface CustomModel {+ model: string+ provider: string+}++const STORAGE_KEY = 'hermes.desktop.custom-models'++function loadCustomModels(): CustomModel[] {+ const raw = storedString(STORAGE_KEY)++ if (!raw) {+ return []+ }++ try {+ const parsed: unknown = JSON.parse(raw)++ if (!Array.isArray(parsed)) {+ return []+ }++ return parsed.filter(+ (entry): entry is CustomModel =>+ !!entry &&+ typeof entry === 'object' &&+ typeof (entry as CustomModel).model === 'string' &&+ typeof (entry as CustomModel).provider === 'string'+ )+ } catch {+ return []+ }+}++/** Global like model visibility: a slug is scoped by its provider slug, so it+ * is harmless under any profile that lacks the provider and correct under any+ * profile that has it. */+export const $customModels = atom<readonly CustomModel[]>(loadCustomModels())++function persist(next: readonly CustomModel[]): void {+ $customModels.set(next)+ persistString(STORAGE_KEY, JSON.stringify(next))+}++const sameEntry = (entry: CustomModel, provider: string, model: string): boolean =>+ entry.provider === provider && entry.model === model++export function isCustomModel(customs: readonly CustomModel[], provider: string, model: string): boolean {+ return customs.some(entry => sameEntry(entry, provider, model))+}++/** A typed model id: something with no whitespace inside it. Nothing stricter —+ * ids differ per provider (`org/model:tag`, `model@date`) and the gateway's+ * switch result is the only authority on validity. */+export function customModelSlug(text: string): string | null {+ const slug = text.trim()++ return slug && !/\s/.test(slug) ? slug : null+}++/** The slug a search query would add, or null when some provider already lists+ * it exactly (then the normal row is the thing to pick). */+export function customModelCandidate(search: string, providers: readonly ModelOptionProvider[]): string | null {+ const slug = customModelSlug(search)++ if (!slug) {+ return null+ }++ const q = normalize(slug)++ return providers.some(provider => (provider.models ?? []).some(model => normalize(model) === q)) ? null : slug+}++/** Catalog rows with the user's custom models appended to their providers.+ * Returns `providers` itself when nothing applies so memoized consumers keep+ * their reference. */+export function withCustomModels(+ providers: readonly ModelOptionProvider[],+ customs: readonly CustomModel[]+): readonly ModelOptionProvider[] {+ if (customs.length === 0) {+ return providers+ }++ let changed = false++ const next = providers.map(provider => {+ const models = provider.models ?? []+ const extra = customs.filter(entry => entry.provider === provider.slug && !models.includes(entry.model))++ if (extra.length === 0) {+ return provider+ }++ changed = true++ return { ...provider, models: [...models, ...extra.map(entry => entry.model)] }+ })++ return changed ? next : providers+}++/** Remember `model` under `provider` and make sure it shows in the composer+ * menu. Pass the provider's catalog row when you have it: the visible set is+ * re-resolved against that row before the key is added, so a provider the+ * user never curated keeps its default shortlist instead of collapsing to+ * the one new row. */+export function addCustomModel(provider: string, model: string, row?: ModelOptionProvider): void {+ const slug = customModelSlug(model)++ if (!slug) {+ return+ }++ const customs = $customModels.get()++ if (!isCustomModel(customs, provider, slug)) {+ persist([...customs, { model: slug, provider }])+ }++ if (!row) {+ return+ }++ const merged = withCustomModels([row], $customModels.get())+ const next = resolveVisibleKeys($visibleModels.get(), merged)+ next.delete(emptyProviderSentinelKey(provider))+ next.add(modelVisibilityKey(provider, slug))+ setVisibleModels(next, merged)+}++export function removeCustomModel(provider: string, model: string): void {+ const customs = $customModels.get()++ if (isCustomModel(customs, provider, model)) {+ persist(customs.filter(entry => !sameEntry(entry, provider, model)))+ }+}