Skip to content

Commit 82eb8d6

Browse files
feat: 添加模型 1M 上下文切换
1 parent bafefc3 commit 82eb8d6

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/components/ModelPicker.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import capitalize from 'lodash-es/capitalize.js'
22
import * as React from 'react'
33
import { useCallback, useMemo, useState } from 'react'
4+
import { has1mContext } from '../utils/context.js'
45
import { useExitOnCtrlCDWithKeybindings } from 'src/hooks/useExitOnCtrlCDWithKeybindings.js'
56
import {
67
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
@@ -83,6 +84,23 @@ export function ModelPicker({
8384
isFastModeEnabled() ? s.fastMode : false,
8485
)
8586

87+
const [marked1MValues, setMarked1MValues] = useState<Set<string>>(
88+
() => new Set(has1mContext(initialValue) ? [initialValue.replace(/\[1m\]/i, '')] : [])
89+
)
90+
91+
const handleToggle1M = useCallback(() => {
92+
if (!focusedValue || focusedValue === NO_PREFERENCE) return
93+
setMarked1MValues(prev => {
94+
const next = new Set(prev)
95+
if (next.has(focusedValue)) {
96+
next.delete(focusedValue)
97+
} else {
98+
next.add(focusedValue)
99+
}
100+
return next
101+
})
102+
}, [focusedValue])
103+
86104
const [hasToggledEffort, setHasToggledEffort] = useState(false)
87105
const effortValue = useAppState(s => s.effortValue)
88106
const [effort, setEffort] = useState<EffortLevel | undefined>(
@@ -136,6 +154,7 @@ export function ModelPicker({
136154
opt => opt.value === focusedValue,
137155
)?.label
138156
const focusedModel = resolveOptionModel(focusedValue)
157+
const is1MMarked = focusedValue !== undefined && focusedValue !== NO_PREFERENCE && marked1MValues.has(focusedValue)
139158
const focusedSupportsEffort = focusedModel
140159
? modelSupportsEffort(focusedModel)
141160
: false
@@ -178,6 +197,7 @@ export function ModelPicker({
178197
{
179198
'modelPicker:decreaseEffort': () => handleCycleEffort('left'),
180199
'modelPicker:increaseEffort': () => handleCycleEffort('right'),
200+
'modelPicker:toggle1M': () => handleToggle1M(),
181201
},
182202
{ context: 'ModelPicker' },
183203
)
@@ -215,7 +235,11 @@ export function ModelPicker({
215235
onSelect(null, selectedEffort)
216236
return
217237
}
218-
onSelect(value, selectedEffort)
238+
// Apply or strip [1m] suffix based on user toggle
239+
const wants1M = marked1MValues.has(value)
240+
const baseValue = value.replace(/\[1m\]/i, '')
241+
const finalValue = wants1M ? `${baseValue}[1m]` : baseValue
242+
onSelect(finalValue, selectedEffort)
219243
}
220244

221245
const content = (
@@ -270,6 +294,17 @@ export function ModelPicker({
270294
{focusedModelName ? ` for ${focusedModelName}` : ''}
271295
</Text>
272296
)}
297+
{is1MMarked ? (
298+
<Text dimColor>
299+
<EffortLevelIndicator effort={'high'} /> 1M context on
300+
<Text color="subtle"> · Space to toggle</Text>
301+
</Text>
302+
) : (
303+
<Text color="subtle">
304+
<EffortLevelIndicator effort={undefined} /> 1M context off
305+
{focusedModelName ? ` for ${focusedModelName}` : ''}
306+
</Text>
307+
)}
273308
</Box>
274309

275310
{isFastModeEnabled() ? (

src/keybindings/defaultBindings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ export const DEFAULT_BINDINGS: KeybindingBlock[] = [
322322
bindings: {
323323
left: 'modelPicker:decreaseEffort',
324324
right: 'modelPicker:increaseEffort',
325+
space: 'modelPicker:toggle1M',
325326
},
326327
},
327328
// Select component navigation (used by /model, /resume, permission prompts, etc.)

src/keybindings/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export const KEYBINDING_ACTIONS = [
153153
// Model picker actions (ant-only)
154154
'modelPicker:decreaseEffort',
155155
'modelPicker:increaseEffort',
156+
'modelPicker:toggle1M',
156157
// Select component actions (distinct from confirm: to avoid collisions)
157158
'select:next',
158159
'select:previous',

0 commit comments

Comments
 (0)