Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/types/src/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,6 @@ export const BEDROCK_CLAUDE_SONNET_4_MODEL_ID = "anthropic.claude-sonnet-4-20250
export const BEDROCK_1M_CONTEXT_MODEL_IDS = [
"anthropic.claude-sonnet-4-20250514-v1:0",
"anthropic.claude-sonnet-4-5-20250929-v1:0",
"anthropic.claude-3-5-sonnet-20241022-v2:0",
"anthropic.claude-3-5-sonnet-20240620-v1:0",
] as const
1 change: 1 addition & 0 deletions tmp-pr-8415/Roo-Code
Submodule Roo-Code added at 2c3161
1 change: 1 addition & 0 deletions tmp/pr-8380-Roo-Code
Submodule pr-8380-Roo-Code added at 815444
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ describe("useSelectedModel", () => {
expect(result.current.info?.contextWindow).toBe(200_000)
})

it("should not affect context window for non-Claude Sonnet 4 Bedrock models", () => {
it("should enable 1M context window for Bedrock Claude 3.5 Sonnet when awsBedrock1MContext is true", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "bedrock",
apiModelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
Expand All @@ -510,6 +510,99 @@ describe("useSelectedModel", () => {
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("anthropic.claude-3-5-sonnet-20241022-v2:0")
expect(result.current.info?.contextWindow).toBe(1_000_000)
})

it("should enable 1M context window for older Bedrock Claude 3.5 Sonnet when awsBedrock1MContext is true", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "bedrock",
apiModelId: "anthropic.claude-3-5-sonnet-20240620-v1:0",
awsBedrock1MContext: true,
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("anthropic.claude-3-5-sonnet-20240620-v1:0")
expect(result.current.info?.contextWindow).toBe(1_000_000)
})

it("should not affect context window for non-Claude Sonnet models", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "bedrock",
apiModelId: "anthropic.claude-3-opus-20240229-v1:0",
awsBedrock1MContext: true,
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("anthropic.claude-3-opus-20240229-v1:0")
expect(result.current.info?.contextWindow).toBe(200_000)
})
})

describe("anthropic provider with 1M context", () => {
beforeEach(() => {
mockUseRouterModels.mockReturnValue({
data: {
openrouter: {},
requesty: {},
glama: {},
unbound: {},
litellm: {},
"io-intelligence": {},
},
isLoading: false,
isError: false,
} as any)

mockUseOpenRouterModelProviders.mockReturnValue({
data: {},
isLoading: false,
isError: false,
} as any)
})

it("should enable 1M context window for Claude Sonnet 4 when anthropicBeta1MContext is true", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "anthropic",
apiModelId: "claude-sonnet-4-20250514",
anthropicBeta1MContext: true,
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("claude-sonnet-4-20250514")
expect(result.current.info?.contextWindow).toBe(1_000_000)
})

it("should enable 1M context window for Claude 3.5 Sonnet (claude-sonnet-4-5) when anthropicBeta1MContext is true", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "anthropic",
apiModelId: "claude-sonnet-4-5",
anthropicBeta1MContext: true,
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("claude-sonnet-4-5")
expect(result.current.info?.contextWindow).toBe(1_000_000)
})

it("should use default context window when anthropicBeta1MContext is false", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "anthropic",
apiModelId: "claude-sonnet-4-5",
anthropicBeta1MContext: false,
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("claude-sonnet-4-5")
expect(result.current.info?.contextWindow).toBe(200_000)
})
})
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/components/ui/hooks/useSelectedModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ function getSelectedModel({
const id = apiConfiguration.apiModelId ?? anthropicDefaultModelId
const baseInfo = anthropicModels[id as keyof typeof anthropicModels]

// Apply 1M context beta tier pricing for Claude Sonnet 4
// Apply 1M context beta tier pricing for Claude Sonnet 4 and 4.5
if (
provider === "anthropic" &&
id === "claude-sonnet-4-20250514" &&
(id === "claude-sonnet-4-20250514" || id === "claude-sonnet-4-5") &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Minor maintainability suggestion — model ID checks for 1M context (e.g., 'claude-sonnet-4-20250514' and 'claude-sonnet-4-5') could be centralized into a small set/constant to simplify future additions.

apiConfiguration.anthropicBeta1MContext &&
baseInfo
) {
Expand Down
Loading