Add ContextWindowSwitcher component to easily switch between 200k and 1m context models

This commit is contained in:
Saoud Rizwan committed 2025-09-29 16:03:23 -07:00
1 parent c2dc0e531c
commit ab88599e05
3 files changed
+91 -71

No files matched your search

@@ -1,4 +1,4 @@
import { openRouterDefaultModelId } from "@shared/api"
import { CLAUDE_SONNET_1M_SUFFIX, openRouterDefaultModelId } from "@shared/api"
import { StringRequest } from "@shared/proto/cline/common"
import { Mode } from "@shared/storage/types"
import { VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
@@ -11,6 +11,7 @@ import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { StateServiceClient } from "@/services/grpc-client"
import { highlight } from "../history/HistoryView"
import { ContextWindowSwitcher } from "./common/ContextWindowSwitcher"
import { ModelInfoView } from "./common/ModelInfoView"
import FeaturedModelCard from "./FeaturedModelCard"
import ThinkingBudgetSlider from "./ThinkingBudgetSlider"
@@ -227,24 +228,6 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
)
}, [selectedModelId])
// Check if the current model is Claude Sonnet 4.5 and determine the alternate variant
const claudeSonnet45Variant = useMemo(() => {
if (selectedModelId === "anthropic/claude-sonnet-4.5") {
return {
current: "anthropic/claude-sonnet-4.5",
alternate: "anthropic/claude-sonnet-4.5:1m",
linkText: "Switch to 1M context window model",
}
} else if (selectedModelId === "anthropic/claude-sonnet-4.5:1m") {
return {
current: "anthropic/claude-sonnet-4.5:1m",
alternate: "anthropic/claude-sonnet-4.5",
linkText: "Switch to 200K context window model",
}
}
return null
}, [selectedModelId])
return (
<div style={{ width: "100%" }}>
<style>
@@ -345,19 +328,21 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
)}
</DropdownWrapper>
{claudeSonnet45Variant && (
<div style={{ marginBottom: 2 }}>
<VSCodeLink
onClick={() => handleModelChange(claudeSonnet45Variant.alternate)}
style={{
display: "inline",
fontSize: "10.5px",
color: "var(--vscode-textLink-foreground)",
}}>
{claudeSonnet45Variant.linkText}
</VSCodeLink>
</div>
)}
{/* Context window switcher for Claude Sonnet 4.5 */}
<ContextWindowSwitcher
base1mModelId={`anthropic/claude-sonnet-4.5${CLAUDE_SONNET_1M_SUFFIX}`}
base200kModelId="anthropic/claude-sonnet-4.5"
onModelChange={handleModelChange}
selectedModelId={selectedModelId}
/>
{/* Context window switcher for Claude Sonnet 4 */}
<ContextWindowSwitcher
base1mModelId={`anthropic/claude-sonnet-4${CLAUDE_SONNET_1M_SUFFIX}`}
base200kModelId="anthropic/claude-sonnet-4"
onModelChange={handleModelChange}
selectedModelId={selectedModelId}
/>
</div>
{hasInfo ? (
@@ -0,0 +1,54 @@
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
import { useMemo } from "react"
interface ContextWindowSwitcherProps {
selectedModelId: string
base200kModelId: string
base1mModelId: string
onModelChange: (modelId: string) => void
}
/**
* A shared component for switching between 200K and 1M context window variants of Claude models.
*/
export const ContextWindowSwitcher = ({
selectedModelId,
base200kModelId,
base1mModelId,
onModelChange,
}: ContextWindowSwitcherProps) => {
const switcherInfo = useMemo(() => {
if (selectedModelId === base200kModelId) {
return {
current: base200kModelId,
alternate: base1mModelId,
linkText: "Switch to 1M context window model",
}
} else if (selectedModelId === base1mModelId) {
return {
current: base1mModelId,
alternate: base200kModelId,
linkText: "Switch to 200K context window model",
}
}
return null
}, [selectedModelId, base200kModelId, base1mModelId])
if (!switcherInfo) {
return null
}
return (
<div style={{ marginBottom: 2 }}>
<VSCodeLink
onClick={() => onModelChange(switcherInfo.alternate)}
style={{
display: "inline",
fontSize: "10.5px",
color: "var(--vscode-textLink-foreground)",
}}>
{switcherInfo.linkText}
</VSCodeLink>
</div>
)
}
@@ -1,10 +1,9 @@
import { anthropicModels, CLAUDE_SONNET_1M_SUFFIX } from "@shared/api"
import { Mode } from "@shared/storage/types"
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
import { useMemo } from "react"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { ApiKeyField } from "../common/ApiKeyField"
import { BaseUrlField } from "../common/BaseUrlField"
import { ContextWindowSwitcher } from "../common/ContextWindowSwitcher"
import { ModelInfoView } from "../common/ModelInfoView"
import { ModelSelector } from "../common/ModelSelector"
import ThinkingBudgetSlider from "../ThinkingBudgetSlider"
@@ -41,24 +40,10 @@ export const AnthropicProvider = ({ showModelOptions, isPopup, currentMode }: An
// Get the normalized configuration
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, currentMode)
// Check if the current model is Claude Sonnet 4.5 and determine the alternate variant
const claudeSonnet45Variant = useMemo(() => {
const SONNET_4_5_MODEL_ID = "claude-sonnet-4-5-20250929"
if (selectedModelId === SONNET_4_5_MODEL_ID) {
return {
current: SONNET_4_5_MODEL_ID,
alternate: `${SONNET_4_5_MODEL_ID}${CLAUDE_SONNET_1M_SUFFIX}`,
linkText: "Switch to 1M context window model",
}
} else if (selectedModelId === `${SONNET_4_5_MODEL_ID}${CLAUDE_SONNET_1M_SUFFIX}`) {
return {
current: `${SONNET_4_5_MODEL_ID}${CLAUDE_SONNET_1M_SUFFIX}`,
alternate: SONNET_4_5_MODEL_ID,
linkText: "Switch to 200K context window model",
}
}
return null
}, [selectedModelId])
// Helper function for model switching
const handleModelChange = (modelId: string) => {
handleModeFieldChange({ plan: "planModeApiModelId", act: "actModeApiModelId" }, modelId, currentMode)
}
return (
<div>
@@ -91,25 +76,21 @@ export const AnthropicProvider = ({ showModelOptions, isPopup, currentMode }: An
selectedModelId={selectedModelId}
/>
{claudeSonnet45Variant && (
<div style={{ marginBottom: 2 }}>
<VSCodeLink
onClick={() =>
handleModeFieldChange(
{ plan: "planModeApiModelId", act: "actModeApiModelId" },
claudeSonnet45Variant.alternate,
currentMode,
)
}
style={{
display: "inline",
fontSize: "10.5px",
color: "var(--vscode-textLink-foreground)",
}}>
{claudeSonnet45Variant.linkText}
</VSCodeLink>
</div>
)}
{/* Context window switcher for Claude Sonnet 4.5 */}
<ContextWindowSwitcher
base1mModelId={`claude-sonnet-4-5-20250929${CLAUDE_SONNET_1M_SUFFIX}`}
base200kModelId="claude-sonnet-4-5-20250929"
onModelChange={handleModelChange}
selectedModelId={selectedModelId}
/>
{/* Context window switcher for Claude Sonnet 4 */}
<ContextWindowSwitcher
base1mModelId={`claude-sonnet-4-20250514${CLAUDE_SONNET_1M_SUFFIX}`}
base200kModelId="claude-sonnet-4-20250514"
onModelChange={handleModelChange}
selectedModelId={selectedModelId}
/>
{SUPPORTED_ANTHROPIC_THINKING_MODELS.includes(selectedModelId) && (
<ThinkingBudgetSlider currentMode={currentMode} maxBudget={selectedModelInfo.thinkingConfig?.maxBudget} />