mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
fix(web,shared): prefer hub custom Claude models and dedupe choices
A custom endpoint can report aliases and resolved ids more than once, and the CLI catalog offers aliases the endpoint does not serve. Prefer the hub-configured custom list when present, fall back to the machine catalog, and emit one picker row per model value. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -123,6 +123,19 @@ describe('getClaudeModelChoices', () => {
|
||||
{ value: 'claude-custom', label: 'claude-custom', section: 'main' },
|
||||
])
|
||||
})
|
||||
|
||||
test('lists each value once when a custom endpoint reports duplicate rows', () => {
|
||||
const choices = getClaudeModelChoices([
|
||||
{ value: 'deepseek-v4.1-flash[1m]', displayName: 'deepseek-v4.1-flash[1m]' },
|
||||
{ value: 'deepseek-v4.1-flash', displayName: 'deepseek-v4.1-flash' },
|
||||
{ value: 'deepseek-v4.1-flash[1m]', displayName: 'deepseek-v4.1-flash[1m]' },
|
||||
{ value: 'deepseek-v4.1-flash[1m]' },
|
||||
])
|
||||
expect(choices.map((choice) => choice.value)).toEqual([
|
||||
'deepseek-v4.1-flash[1m]',
|
||||
'deepseek-v4.1-flash',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('getClaudeEffortLevelsForModel', () => {
|
||||
|
||||
+10
-1
@@ -99,8 +99,17 @@ function getClaudeModelFamily(value: string): string {
|
||||
*/
|
||||
export function getClaudeModelChoices(catalog: readonly ClaudeModelSummary[]): ClaudeModelChoice[] {
|
||||
const families = new Set<string>()
|
||||
const seenValues = new Set<string>()
|
||||
const choices: ClaudeModelChoice[] = catalog
|
||||
.filter((model) => model.value !== 'default')
|
||||
.filter((model) => {
|
||||
// A custom endpoint can report the same id more than once (aliases
|
||||
// and resolved ids overlap); each value is one row in the picker.
|
||||
if (model.value === 'default' || seenValues.has(model.value)) {
|
||||
return false
|
||||
}
|
||||
seenValues.add(model.value)
|
||||
return true
|
||||
})
|
||||
.map((model) => {
|
||||
const family = getClaudeModelFamily(model.value)
|
||||
const section = families.has(family) ? 'other' : 'main'
|
||||
|
||||
@@ -1202,9 +1202,13 @@ function SessionChatInner(props: SessionChatProps) {
|
||||
getClaudeEffortLevelsForModel(props.session.model ?? null, claudeModelsState.availableModels)
|
||||
?.map((level) => ({ value: level }))
|
||||
), [props.session.model, claudeModelsState.availableModels])
|
||||
// Machine catalog first; hub-configured custom Claude models fill in when
|
||||
// the runner has no discovery catalog.
|
||||
const claudeComposerModelOptions = claudeModelOptions ?? claudeCustomModelOptions
|
||||
// Hub-configured custom Claude models describe what the session's endpoint
|
||||
// actually serves; the CLI catalog is Anthropic's own model list and would
|
||||
// offer aliases the endpoint does not have (and repeat resolved ids).
|
||||
// Prefer the custom list when present; otherwise keep the machine catalog.
|
||||
const claudeComposerModelOptions = (claudeCustomModelOptions?.length ?? 0) > 0
|
||||
? claudeCustomModelOptions
|
||||
: claudeModelOptions
|
||||
const piModelsState = usePiModels({
|
||||
api: props.api,
|
||||
sessionId: props.session.id,
|
||||
|
||||
Reference in New Issue
Block a user