|
15 | 15 |
|
16 | 16 | let { settings, onsave }: Props = $props(); |
17 | 17 |
|
18 | | - let model = $state(settings.model ?? ''); |
| 18 | + // Parse a saved model value into (base, has1m) so the UI can split the [1m] suffix |
| 19 | + // from the underlying ID. The suffix is documented as a Claude Code extension that |
| 20 | + // is stripped before the request reaches the provider. |
| 21 | + function splitModelValue(raw: string | undefined): { base: string; has1m: boolean } { |
| 22 | + if (!raw) return { base: '', has1m: false }; |
| 23 | + if (raw.endsWith('[1m]')) return { base: raw.slice(0, -'[1m]'.length), has1m: true }; |
| 24 | + return { base: raw, has1m: false }; |
| 25 | + } |
| 26 | +
|
| 27 | + const initial = splitModelValue(settings.model); |
| 28 | + const knownValues = CLAUDE_MODELS.map((m) => m.value) as readonly string[]; |
| 29 | + const initialIsKnown = !initial.base || knownValues.includes(initial.base); |
| 30 | +
|
| 31 | + let modelChoice = $state<string>(initialIsKnown ? initial.base : '__custom__'); |
| 32 | + let customModel = $state<string>(initialIsKnown ? '' : initial.base); |
| 33 | + let use1mContext = $state<boolean>(initial.has1m); |
19 | 34 | let availableModels = $state<string[]>([...settings.availableModels]); |
20 | 35 | let outputStyle = $state(settings.outputStyle ?? ''); |
21 | 36 | let language = $state(settings.language ?? ''); |
22 | 37 | let alwaysThinkingEnabled = $state<boolean | undefined>(settings.alwaysThinkingEnabled); |
23 | 38 |
|
24 | 39 | // Reset local state when settings prop changes |
25 | 40 | $effect(() => { |
26 | | - model = settings.model ?? ''; |
| 41 | + const next = splitModelValue(settings.model); |
| 42 | + const known = !next.base || knownValues.includes(next.base); |
| 43 | + modelChoice = known ? next.base : '__custom__'; |
| 44 | + customModel = known ? '' : next.base; |
| 45 | + use1mContext = next.has1m; |
27 | 46 | availableModels = [...settings.availableModels]; |
28 | 47 | outputStyle = settings.outputStyle ?? ''; |
29 | 48 | language = settings.language ?? ''; |
30 | 49 | alwaysThinkingEnabled = settings.alwaysThinkingEnabled; |
31 | 50 | }); |
32 | 51 |
|
| 52 | + // Resolve the effective model string from the dropdown + custom field + 1m toggle. |
| 53 | + // Returns undefined when nothing is selected so the setting is omitted entirely. |
| 54 | + function resolveModelValue(): string | undefined { |
| 55 | + const base = modelChoice === '__custom__' ? customModel.trim() : modelChoice; |
| 56 | + if (!base) return undefined; |
| 57 | + if (!use1mContext) return base; |
| 58 | + // Don't double-append [1m] if the user typed it themselves |
| 59 | + return base.endsWith('[1m]') ? base : `${base}[1m]`; |
| 60 | + } |
| 61 | +
|
| 62 | + // 1M context only applies to models that support it. Built-in entries declare this |
| 63 | + // via supports1m; custom IDs are assumed eligible (we can't verify) and the user |
| 64 | + // keeps responsibility for typing a valid ID. |
| 65 | + function selectionSupports1m(): boolean { |
| 66 | + if (modelChoice === '__custom__') return customModel.trim().length > 0; |
| 67 | + const entry = CLAUDE_MODELS.find((m) => m.value === modelChoice); |
| 68 | + return entry?.supports1m ?? false; |
| 69 | + } |
| 70 | +
|
| 71 | + // Auto-clear the 1M flag if the user picks a model that doesn't support it |
| 72 | + $effect(() => { |
| 73 | + if (!selectionSupports1m() && use1mContext) { |
| 74 | + use1mContext = false; |
| 75 | + } |
| 76 | + }); |
| 77 | +
|
33 | 78 | function handleSave() { |
34 | 79 | onsave({ |
35 | 80 | ...settings, |
36 | | - model: model || undefined, |
| 81 | + model: resolveModelValue(), |
37 | 82 | availableModels, |
38 | 83 | outputStyle: outputStyle || undefined, |
39 | 84 | language: language || undefined, |
|
74 | 119 | </label> |
75 | 120 | <select |
76 | 121 | id="model-select" |
77 | | - bind:value={model} |
| 122 | + bind:value={modelChoice} |
78 | 123 | class="input text-sm w-full" |
79 | 124 | > |
80 | 125 | <option value="">Not set (use default)</option> |
81 | 126 | {#each CLAUDE_MODELS as m} |
82 | 127 | <option value={m.value}>{m.label} — {m.description}</option> |
83 | 128 | {/each} |
| 129 | + <option value="__custom__">Other (custom model ID)…</option> |
84 | 130 | </select> |
| 131 | + {#if modelChoice === '__custom__'} |
| 132 | + <input |
| 133 | + type="text" |
| 134 | + bind:value={customModel} |
| 135 | + placeholder="e.g. claude-opus-4-7 or arn:aws:bedrock:…" |
| 136 | + class="input text-sm w-full mt-2" |
| 137 | + aria-label="Custom model ID" |
| 138 | + /> |
| 139 | + <p class="text-xs text-gray-500 dark:text-gray-400 mt-1"> |
| 140 | + Enter any model ID, alias, or provider-specific identifier. Append <code>[1m]</code> |
| 141 | + yourself if not using the toggle below. |
| 142 | + </p> |
| 143 | + {/if} |
| 144 | + <p class="text-xs text-gray-500 dark:text-gray-400 mt-1"> |
| 145 | + Aliases like <code>opus</code>, <code>sonnet</code>, <code>haiku</code> auto-resolve |
| 146 | + to the latest version. See |
| 147 | + <a |
| 148 | + href="https://code.claude.com/docs/en/model-config#available-models" |
| 149 | + target="_blank" |
| 150 | + rel="noopener" |
| 151 | + class="underline hover:text-primary-600">model configuration docs</a>. |
| 152 | + </p> |
| 153 | + </div> |
| 154 | + |
| 155 | + <!-- 1M Context Window --> |
| 156 | + <div> |
| 157 | + <label class="flex items-center gap-2 cursor-pointer"> |
| 158 | + <input |
| 159 | + type="checkbox" |
| 160 | + bind:checked={use1mContext} |
| 161 | + disabled={!selectionSupports1m()} |
| 162 | + class="rounded border-gray-300 dark:border-gray-600" |
| 163 | + /> |
| 164 | + <span class="text-sm font-medium text-gray-700 dark:text-gray-300"> |
| 165 | + Use 1M token context window |
| 166 | + </span> |
| 167 | + </label> |
| 168 | + <p class="text-xs text-gray-500 dark:text-gray-400 mt-1 ml-6"> |
| 169 | + Appends the <code>[1m]</code> suffix to the model ID. Supported on Opus and Sonnet |
| 170 | + (not Haiku). Standard pricing — no premium beyond 200K tokens. |
| 171 | + <a |
| 172 | + href="https://code.claude.com/docs/en/model-config#extended-context" |
| 173 | + target="_blank" |
| 174 | + rel="noopener" |
| 175 | + class="underline hover:text-primary-600">Docs</a>. |
| 176 | + </p> |
85 | 177 | </div> |
86 | 178 |
|
87 | 179 | <!-- Available Models --> |
|
0 commit comments