mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
feat: 添加模型 1M 上下文切换
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import capitalize from 'lodash-es/capitalize.js'
|
import capitalize from 'lodash-es/capitalize.js'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { useCallback, useMemo, useState } from 'react'
|
import { useCallback, useMemo, useState } from 'react'
|
||||||
|
import { has1mContext } from '../utils/context.js'
|
||||||
import { useExitOnCtrlCDWithKeybindings } from 'src/hooks/useExitOnCtrlCDWithKeybindings.js'
|
import { useExitOnCtrlCDWithKeybindings } from 'src/hooks/useExitOnCtrlCDWithKeybindings.js'
|
||||||
import {
|
import {
|
||||||
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||||
@@ -83,6 +84,23 @@ export function ModelPicker({
|
|||||||
isFastModeEnabled() ? s.fastMode : false,
|
isFastModeEnabled() ? s.fastMode : false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [marked1MValues, setMarked1MValues] = useState<Set<string>>(
|
||||||
|
() => new Set(has1mContext(initialValue) ? [initialValue.replace(/\[1m\]/i, '')] : [])
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleToggle1M = useCallback(() => {
|
||||||
|
if (!focusedValue || focusedValue === NO_PREFERENCE) return
|
||||||
|
setMarked1MValues(prev => {
|
||||||
|
const next = new Set(prev)
|
||||||
|
if (next.has(focusedValue)) {
|
||||||
|
next.delete(focusedValue)
|
||||||
|
} else {
|
||||||
|
next.add(focusedValue)
|
||||||
|
}
|
||||||
|
return next
|
||||||
|
})
|
||||||
|
}, [focusedValue])
|
||||||
|
|
||||||
const [hasToggledEffort, setHasToggledEffort] = useState(false)
|
const [hasToggledEffort, setHasToggledEffort] = useState(false)
|
||||||
const effortValue = useAppState(s => s.effortValue)
|
const effortValue = useAppState(s => s.effortValue)
|
||||||
const [effort, setEffort] = useState<EffortLevel | undefined>(
|
const [effort, setEffort] = useState<EffortLevel | undefined>(
|
||||||
@@ -136,6 +154,7 @@ export function ModelPicker({
|
|||||||
opt => opt.value === focusedValue,
|
opt => opt.value === focusedValue,
|
||||||
)?.label
|
)?.label
|
||||||
const focusedModel = resolveOptionModel(focusedValue)
|
const focusedModel = resolveOptionModel(focusedValue)
|
||||||
|
const is1MMarked = focusedValue !== undefined && focusedValue !== NO_PREFERENCE && marked1MValues.has(focusedValue)
|
||||||
const focusedSupportsEffort = focusedModel
|
const focusedSupportsEffort = focusedModel
|
||||||
? modelSupportsEffort(focusedModel)
|
? modelSupportsEffort(focusedModel)
|
||||||
: false
|
: false
|
||||||
@@ -178,6 +197,7 @@ export function ModelPicker({
|
|||||||
{
|
{
|
||||||
'modelPicker:decreaseEffort': () => handleCycleEffort('left'),
|
'modelPicker:decreaseEffort': () => handleCycleEffort('left'),
|
||||||
'modelPicker:increaseEffort': () => handleCycleEffort('right'),
|
'modelPicker:increaseEffort': () => handleCycleEffort('right'),
|
||||||
|
'modelPicker:toggle1M': () => handleToggle1M(),
|
||||||
},
|
},
|
||||||
{ context: 'ModelPicker' },
|
{ context: 'ModelPicker' },
|
||||||
)
|
)
|
||||||
@@ -215,7 +235,11 @@ export function ModelPicker({
|
|||||||
onSelect(null, selectedEffort)
|
onSelect(null, selectedEffort)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSelect(value, selectedEffort)
|
// Apply or strip [1m] suffix based on user toggle
|
||||||
|
const wants1M = marked1MValues.has(value)
|
||||||
|
const baseValue = value.replace(/\[1m\]/i, '')
|
||||||
|
const finalValue = wants1M ? `${baseValue}[1m]` : baseValue
|
||||||
|
onSelect(finalValue, selectedEffort)
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
@@ -270,6 +294,17 @@ export function ModelPicker({
|
|||||||
{focusedModelName ? ` for ${focusedModelName}` : ''}
|
{focusedModelName ? ` for ${focusedModelName}` : ''}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
{is1MMarked ? (
|
||||||
|
<Text dimColor>
|
||||||
|
<EffortLevelIndicator effort={'high'} /> 1M context on
|
||||||
|
<Text color="subtle"> · Space to toggle</Text>
|
||||||
|
</Text>
|
||||||
|
) : (
|
||||||
|
<Text color="subtle">
|
||||||
|
<EffortLevelIndicator effort={undefined} /> 1M context off
|
||||||
|
{focusedModelName ? ` for ${focusedModelName}` : ''}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{isFastModeEnabled() ? (
|
{isFastModeEnabled() ? (
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ export const DEFAULT_BINDINGS: KeybindingBlock[] = [
|
|||||||
bindings: {
|
bindings: {
|
||||||
left: 'modelPicker:decreaseEffort',
|
left: 'modelPicker:decreaseEffort',
|
||||||
right: 'modelPicker:increaseEffort',
|
right: 'modelPicker:increaseEffort',
|
||||||
|
space: 'modelPicker:toggle1M',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Select component navigation (used by /model, /resume, permission prompts, etc.)
|
// Select component navigation (used by /model, /resume, permission prompts, etc.)
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ export const KEYBINDING_ACTIONS = [
|
|||||||
// Model picker actions (ant-only)
|
// Model picker actions (ant-only)
|
||||||
'modelPicker:decreaseEffort',
|
'modelPicker:decreaseEffort',
|
||||||
'modelPicker:increaseEffort',
|
'modelPicker:increaseEffort',
|
||||||
|
'modelPicker:toggle1M',
|
||||||
// Select component actions (distinct from confirm: to avoid collisions)
|
// Select component actions (distinct from confirm: to avoid collisions)
|
||||||
'select:next',
|
'select:next',
|
||||||
'select:previous',
|
'select:previous',
|
||||||
|
|||||||
Reference in New Issue
Block a user