mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
fix(desktop): show newly configured model providers (#41545)
This commit is contained in:
parent
15c99b437f
commit
039fbb41fc
3 changed files with 70 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ import {
|
|||
$visibleModels,
|
||||
collapseModelFamilies,
|
||||
DEFAULT_VISIBLE_PER_PROVIDER,
|
||||
effectiveVisibleKeys,
|
||||
type ModelFamily,
|
||||
modelVisibilityKey,
|
||||
setModelVisibilityOpen
|
||||
|
|
@ -86,13 +87,17 @@ export function ModelMenuPanel({ gateway, onSelectModel, requestGateway }: Model
|
|||
: null
|
||||
|
||||
const providers = modelOptions.data?.providers
|
||||
const effectiveVisibleModels = useMemo(
|
||||
() => effectiveVisibleKeys(visibleModels, providers ?? []),
|
||||
[visibleModels, providers]
|
||||
)
|
||||
|
||||
const switchTo = (model: string, provider: string) =>
|
||||
onSelectModel({ model, persistGlobal: !activeSessionId, provider })
|
||||
|
||||
const groups = useMemo(
|
||||
() => groupModels(providers ?? [], search, { model: optionsModel, provider: optionsProvider }, visibleModels),
|
||||
[providers, search, optionsModel, optionsProvider, visibleModels]
|
||||
() => groupModels(providers ?? [], search, { model: optionsModel, provider: optionsProvider }, effectiveVisibleModels),
|
||||
[providers, search, optionsModel, optionsProvider, effectiveVisibleModels]
|
||||
)
|
||||
|
||||
return (
|
||||
|
|
|
|||
37
apps/desktop/src/store/model-visibility.test.ts
Normal file
37
apps/desktop/src/store/model-visibility.test.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type { ModelOptionProvider } from '@/types/hermes'
|
||||
|
||||
import { effectiveVisibleKeys, modelVisibilityKey } from './model-visibility'
|
||||
|
||||
const provider = (slug: string, models: string[]): ModelOptionProvider => ({
|
||||
models,
|
||||
name: slug,
|
||||
slug
|
||||
})
|
||||
|
||||
describe('model visibility', () => {
|
||||
it('keeps newly configured providers visible when stored choices are stale', () => {
|
||||
const stored = new Set([modelVisibilityKey('copilot', 'claude-sonnet-4.6')])
|
||||
|
||||
const visible = effectiveVisibleKeys(stored, [
|
||||
provider('copilot', ['claude-sonnet-4.6']),
|
||||
provider('local-ollama', ['qwen3:latest', 'llama3.2:latest'])
|
||||
])
|
||||
|
||||
expect(visible.has(modelVisibilityKey('copilot', 'claude-sonnet-4.6'))).toBe(true)
|
||||
expect(visible.has(modelVisibilityKey('local-ollama', 'qwen3:latest'))).toBe(true)
|
||||
expect(visible.has(modelVisibilityKey('local-ollama', 'llama3.2:latest'))).toBe(true)
|
||||
})
|
||||
|
||||
it('does not re-add models from a provider that already has stored choices', () => {
|
||||
const stored = new Set([modelVisibilityKey('local-ollama', 'qwen3:latest')])
|
||||
|
||||
const visible = effectiveVisibleKeys(stored, [
|
||||
provider('local-ollama', ['qwen3:latest', 'llama3.2:latest'])
|
||||
])
|
||||
|
||||
expect(visible.has(modelVisibilityKey('local-ollama', 'qwen3:latest'))).toBe(true)
|
||||
expect(visible.has(modelVisibilityKey('local-ollama', 'llama3.2:latest'))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
|
@ -104,5 +104,30 @@ export function effectiveVisibleKeys(
|
|||
stored: Set<string> | null,
|
||||
providers: readonly ModelOptionProvider[]
|
||||
): Set<string> {
|
||||
return stored ?? defaultVisibleKeys(providers)
|
||||
if (!stored) {
|
||||
return defaultVisibleKeys(providers)
|
||||
}
|
||||
|
||||
if (stored.size === 0) {
|
||||
return new Set()
|
||||
}
|
||||
|
||||
const next = new Set(stored)
|
||||
|
||||
for (const provider of providers) {
|
||||
const providerPrefix = `${provider.slug}::`
|
||||
const hasStoredProvider = [...stored].some(key => key.startsWith(providerPrefix))
|
||||
|
||||
if (hasStoredProvider) {
|
||||
continue
|
||||
}
|
||||
|
||||
const families = collapseModelFamilies(provider.models ?? [])
|
||||
|
||||
for (const family of families.slice(0, DEFAULT_VISIBLE_PER_PROVIDER)) {
|
||||
next.add(modelVisibilityKey(provider.slug, family.id))
|
||||
}
|
||||
}
|
||||
|
||||
return next
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue