From e66f403cb696b45f884cbb556d9cf92e951b36ce Mon Sep 17 00:00:00 2001 From: weishu Date: Thu, 21 May 2026 14:45:59 +0800 Subject: [PATCH] refactor: derive new session model options --- web/src/components/NewSession/types.test.ts | 10 +++++----- web/src/components/NewSession/types.ts | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/web/src/components/NewSession/types.test.ts b/web/src/components/NewSession/types.test.ts index 08591db0..51a499f1 100644 --- a/web/src/components/NewSession/types.test.ts +++ b/web/src/components/NewSession/types.test.ts @@ -3,13 +3,13 @@ import { describe, expect, it } from 'vitest' import { CLAUDE_EFFORT_OPTIONS, MODEL_OPTIONS } from './types' describe('Claude model options', () => { - it('includes 1m model options in the expected order', () => { + it('derives options from shared Claude model presets', () => { expect(MODEL_OPTIONS.claude).toEqual([ { value: 'auto', label: 'Default' }, - { value: 'opus', label: 'Opus' }, - { value: 'opus[1m]', label: 'Opus 1M' }, - { value: 'sonnet', label: 'Sonnet' }, - { value: 'sonnet[1m]', label: 'Sonnet 1M' }, + ...CLAUDE_MODEL_PRESETS.map((model) => ({ + value: model, + label: getClaudeModelLabel(model) ?? model + })) ]) }) diff --git a/web/src/components/NewSession/types.ts b/web/src/components/NewSession/types.ts index d7a1533d..b22f050e 100644 --- a/web/src/components/NewSession/types.ts +++ b/web/src/components/NewSession/types.ts @@ -1,4 +1,9 @@ -import { GEMINI_MODEL_PRESETS, GEMINI_MODEL_LABELS } from '@hapi/protocol' +import { + CLAUDE_MODEL_LABELS, + CLAUDE_MODEL_PRESETS, + GEMINI_MODEL_LABELS, + GEMINI_MODEL_PRESETS +} from '@hapi/protocol' import type { AgentFlavor } from '@hapi/protocol' export type AgentType = AgentFlavor @@ -6,13 +11,17 @@ export type SessionType = 'simple' | 'worktree' export type CodexReasoningEffort = 'default' | 'low' | 'medium' | 'high' | 'xhigh' export type ClaudeEffort = 'auto' | 'medium' | 'high' | 'max' +function modelPresetOptions( + presets: readonly TModel[], + labels: Record +): { value: string; label: string }[] { + return presets.map(model => ({ value: model, label: labels[model] })) +} + export const MODEL_OPTIONS: Record = { claude: [ { value: 'auto', label: 'Default' }, - { value: 'opus', label: 'Opus' }, - { value: 'opus[1m]', label: 'Opus 1M' }, - { value: 'sonnet', label: 'Sonnet' }, - { value: 'sonnet[1m]', label: 'Sonnet 1M' }, + ...modelPresetOptions(CLAUDE_MODEL_PRESETS, CLAUDE_MODEL_LABELS), ], codex: [ { value: 'auto', label: 'Default' }, @@ -20,7 +29,7 @@ export const MODEL_OPTIONS: Record ({ value: m, label: GEMINI_MODEL_LABELS[m] })), + ...modelPresetOptions(GEMINI_MODEL_PRESETS, GEMINI_MODEL_LABELS), ], opencode: [], }