@@ -25,6 +25,7 @@ vi.mock("@aws-sdk/client-bedrock-runtime", () => {
2525
2626import { AwsBedrockHandler } from "../bedrock"
2727import { ConverseStreamCommand , BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime"
28+ import { BEDROCK_CLAUDE_SONNET_4_MODEL_ID } from "@roo-code/types"
2829
2930import type { Anthropic } from "@anthropic-ai/sdk"
3031
@@ -564,4 +565,184 @@ describe("AwsBedrockHandler", () => {
564565 expect ( typeof model . info . supportsPromptCache ) . toBe ( "boolean" )
565566 } )
566567 } )
568+
569+ describe ( "1M context beta feature" , ( ) => {
570+ it ( "should enable 1M context window when awsBedrock1MContext is true for Claude Sonnet 4" , ( ) => {
571+ const handler = new AwsBedrockHandler ( {
572+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
573+ awsAccessKey : "test" ,
574+ awsSecretKey : "test" ,
575+ awsRegion : "us-east-1" ,
576+ awsBedrock1MContext : true ,
577+ } )
578+
579+ const model = handler . getModel ( )
580+
581+ // Should have 1M context window when enabled
582+ expect ( model . info . contextWindow ) . toBe ( 1_000_000 )
583+ } )
584+
585+ it ( "should use default context window when awsBedrock1MContext is false for Claude Sonnet 4" , ( ) => {
586+ const handler = new AwsBedrockHandler ( {
587+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
588+ awsAccessKey : "test" ,
589+ awsSecretKey : "test" ,
590+ awsRegion : "us-east-1" ,
591+ awsBedrock1MContext : false ,
592+ } )
593+
594+ const model = handler . getModel ( )
595+
596+ // Should use default context window (200k)
597+ expect ( model . info . contextWindow ) . toBe ( 200_000 )
598+ } )
599+
600+ it ( "should not affect context window for non-Claude Sonnet 4 models" , ( ) => {
601+ const handler = new AwsBedrockHandler ( {
602+ apiModelId : "anthropic.claude-3-5-sonnet-20241022-v2:0" ,
603+ awsAccessKey : "test" ,
604+ awsSecretKey : "test" ,
605+ awsRegion : "us-east-1" ,
606+ awsBedrock1MContext : true ,
607+ } )
608+
609+ const model = handler . getModel ( )
610+
611+ // Should use default context window for non-Sonnet 4 models
612+ expect ( model . info . contextWindow ) . toBe ( 200_000 )
613+ } )
614+
615+ it ( "should include anthropic_beta parameter when 1M context is enabled" , async ( ) => {
616+ const handler = new AwsBedrockHandler ( {
617+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
618+ awsAccessKey : "test" ,
619+ awsSecretKey : "test" ,
620+ awsRegion : "us-east-1" ,
621+ awsBedrock1MContext : true ,
622+ } )
623+
624+ const messages : Anthropic . Messages . MessageParam [ ] = [
625+ {
626+ role : "user" ,
627+ content : "Test message" ,
628+ } ,
629+ ]
630+
631+ const generator = handler . createMessage ( "" , messages )
632+ await generator . next ( ) // Start the generator
633+
634+ // Verify the command was created with the right payload
635+ expect ( mockConverseStreamCommand ) . toHaveBeenCalled ( )
636+ const commandArg = mockConverseStreamCommand . mock . calls [ 0 ] [ 0 ] as any
637+
638+ // Should include anthropic_beta parameter but NOT anthropic_version (only for thinking)
639+ expect ( commandArg . anthropic_beta ) . toEqual ( [ "context-1m-2025-08-07" ] )
640+ expect ( commandArg . anthropic_version ) . toBeUndefined ( )
641+ } )
642+
643+ it ( "should not include anthropic_beta parameter when 1M context is disabled" , async ( ) => {
644+ const handler = new AwsBedrockHandler ( {
645+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
646+ awsAccessKey : "test" ,
647+ awsSecretKey : "test" ,
648+ awsRegion : "us-east-1" ,
649+ awsBedrock1MContext : false ,
650+ } )
651+
652+ const messages : Anthropic . Messages . MessageParam [ ] = [
653+ {
654+ role : "user" ,
655+ content : "Test message" ,
656+ } ,
657+ ]
658+
659+ const generator = handler . createMessage ( "" , messages )
660+ await generator . next ( ) // Start the generator
661+
662+ // Verify the command was created with the right payload
663+ expect ( mockConverseStreamCommand ) . toHaveBeenCalled ( )
664+ const commandArg = mockConverseStreamCommand . mock . calls [ 0 ] [ 0 ] as any
665+
666+ // Should not include anthropic_beta parameter
667+ expect ( commandArg . anthropic_beta ) . toBeUndefined ( )
668+ } )
669+
670+ it ( "should not include anthropic_beta parameter for non-Claude Sonnet 4 models" , async ( ) => {
671+ const handler = new AwsBedrockHandler ( {
672+ apiModelId : "anthropic.claude-3-5-sonnet-20241022-v2:0" ,
673+ awsAccessKey : "test" ,
674+ awsSecretKey : "test" ,
675+ awsRegion : "us-east-1" ,
676+ awsBedrock1MContext : true ,
677+ } )
678+
679+ const messages : Anthropic . Messages . MessageParam [ ] = [
680+ {
681+ role : "user" ,
682+ content : "Test message" ,
683+ } ,
684+ ]
685+
686+ const generator = handler . createMessage ( "" , messages )
687+ await generator . next ( ) // Start the generator
688+
689+ // Verify the command was created with the right payload
690+ expect ( mockConverseStreamCommand ) . toHaveBeenCalled ( )
691+ const commandArg = mockConverseStreamCommand . mock . calls [ 0 ] [ 0 ] as any
692+
693+ // Should not include anthropic_beta parameter for non-Sonnet 4 models
694+ expect ( commandArg . anthropic_beta ) . toBeUndefined ( )
695+ } )
696+
697+ it ( "should enable 1M context window with cross-region inference for Claude Sonnet 4" , ( ) => {
698+ const handler = new AwsBedrockHandler ( {
699+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
700+ awsAccessKey : "test" ,
701+ awsSecretKey : "test" ,
702+ awsRegion : "us-east-1" ,
703+ awsUseCrossRegionInference : true ,
704+ awsBedrock1MContext : true ,
705+ } )
706+
707+ const model = handler . getModel ( )
708+
709+ // Should have 1M context window even with cross-region prefix
710+ expect ( model . info . contextWindow ) . toBe ( 1_000_000 )
711+ // Model ID should have cross-region prefix
712+ expect ( model . id ) . toBe ( `us.${ BEDROCK_CLAUDE_SONNET_4_MODEL_ID } ` )
713+ } )
714+
715+ it ( "should include anthropic_beta parameter with cross-region inference for Claude Sonnet 4" , async ( ) => {
716+ const handler = new AwsBedrockHandler ( {
717+ apiModelId : BEDROCK_CLAUDE_SONNET_4_MODEL_ID ,
718+ awsAccessKey : "test" ,
719+ awsSecretKey : "test" ,
720+ awsRegion : "us-east-1" ,
721+ awsUseCrossRegionInference : true ,
722+ awsBedrock1MContext : true ,
723+ } )
724+
725+ const messages : Anthropic . Messages . MessageParam [ ] = [
726+ {
727+ role : "user" ,
728+ content : "Test message" ,
729+ } ,
730+ ]
731+
732+ const generator = handler . createMessage ( "" , messages )
733+ await generator . next ( ) // Start the generator
734+
735+ // Verify the command was created with the right payload
736+ expect ( mockConverseStreamCommand ) . toHaveBeenCalled ( )
737+ const commandArg = mockConverseStreamCommand . mock . calls [
738+ mockConverseStreamCommand . mock . calls . length - 1
739+ ] [ 0 ] as any
740+
741+ // Should include anthropic_beta parameter but NOT anthropic_version (only for thinking)
742+ expect ( commandArg . anthropic_beta ) . toEqual ( [ "context-1m-2025-08-07" ] )
743+ expect ( commandArg . anthropic_version ) . toBeUndefined ( )
744+ // Model ID should have cross-region prefix
745+ expect ( commandArg . modelId ) . toBe ( `us.${ BEDROCK_CLAUDE_SONNET_4_MODEL_ID } ` )
746+ } )
747+ } )
567748} )
0 commit comments