@@ -282,6 +282,110 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
282282 expect ( reasoningChunks [ 1 ] . text ) . toBe ( " about this problem." )
283283 } )
284284
285+ it ( "should use adaptive thinking for Opus 4.7 instead of enabled with budget_tokens" , async ( ) => {
286+ handler = new AwsBedrockHandler ( {
287+ apiProvider : "bedrock" ,
288+ apiModelId : "anthropic.claude-opus-4-7" ,
289+ awsRegion : "us-east-1" ,
290+ enableReasoningEffort : true ,
291+ modelMaxTokens : 8192 ,
292+ modelMaxThinkingTokens : 4096 ,
293+ } )
294+
295+ mockSend . mockResolvedValue ( {
296+ stream : ( async function * ( ) {
297+ yield { messageStart : { role : "assistant" } }
298+ yield {
299+ contentBlockStart : {
300+ content_block : { type : "thinking" , thinking : "Thinking adaptively..." } ,
301+ contentBlockIndex : 0 ,
302+ } ,
303+ }
304+ yield { metadata : { usage : { inputTokens : 100 , outputTokens : 50 } } }
305+ } ) ( ) ,
306+ } )
307+
308+ const messages = [ { role : "user" as const , content : "Test message" } ]
309+ const stream = handler . createMessage ( "System prompt" , messages )
310+
311+ const chunks = [ ]
312+ for await ( const chunk of stream ) {
313+ chunks . push ( chunk )
314+ }
315+
316+ // Opus 4.7 must use thinking.type: "adaptive" with output_config.effort
317+ expect ( mockSend ) . toHaveBeenCalledTimes ( 1 )
318+ expect ( capturedPayload ) . toBeDefined ( )
319+ expect ( capturedPayload . additionalModelRequestFields ) . toBeDefined ( )
320+ expect ( capturedPayload . additionalModelRequestFields . thinking ) . toEqual ( {
321+ type : "adaptive" ,
322+ } )
323+ expect ( capturedPayload . additionalModelRequestFields . output_config ) . toEqual ( {
324+ effort : "high" ,
325+ } )
326+
327+ // Must NOT have budget_tokens (causes 400 error on Opus 4.7)
328+ expect ( capturedPayload . additionalModelRequestFields . thinking ) . not . toHaveProperty ( "budget_tokens" )
329+ } )
330+
331+ it ( "should exclude temperature from inferenceConfig for Opus 4.7 (supportsTemperature: false)" , async ( ) => {
332+ handler = new AwsBedrockHandler ( {
333+ apiProvider : "bedrock" ,
334+ apiModelId : "anthropic.claude-opus-4-7" ,
335+ awsRegion : "us-east-1" ,
336+ modelTemperature : 0.7 ,
337+ } )
338+
339+ mockSend . mockResolvedValue ( {
340+ stream : ( async function * ( ) {
341+ yield { messageStart : { role : "assistant" } }
342+ yield { metadata : { usage : { inputTokens : 100 , outputTokens : 50 } } }
343+ } ) ( ) ,
344+ } )
345+
346+ const messages = [ { role : "user" as const , content : "Test message" } ]
347+ const stream = handler . createMessage ( "System prompt" , messages )
348+
349+ for await ( const chunk of stream ) {
350+ // consume stream
351+ }
352+
353+ expect ( mockSend ) . toHaveBeenCalledTimes ( 1 )
354+ expect ( capturedPayload ) . toBeDefined ( )
355+ // Temperature must NOT be present for Opus 4.7
356+ expect ( capturedPayload . inferenceConfig ) . not . toHaveProperty ( "temperature" )
357+ // maxTokens should still be present
358+ expect ( capturedPayload . inferenceConfig ) . toHaveProperty ( "maxTokens" )
359+ } )
360+
361+ it ( "should include temperature in inferenceConfig for models that support it" , async ( ) => {
362+ handler = new AwsBedrockHandler ( {
363+ apiProvider : "bedrock" ,
364+ apiModelId : "anthropic.claude-sonnet-4-20250514-v1:0" ,
365+ awsRegion : "us-east-1" ,
366+ modelTemperature : 0.5 ,
367+ } )
368+
369+ mockSend . mockResolvedValue ( {
370+ stream : ( async function * ( ) {
371+ yield { messageStart : { role : "assistant" } }
372+ yield { metadata : { usage : { inputTokens : 100 , outputTokens : 50 } } }
373+ } ) ( ) ,
374+ } )
375+
376+ const messages = [ { role : "user" as const , content : "Test message" } ]
377+ const stream = handler . createMessage ( "System prompt" , messages )
378+
379+ for await ( const chunk of stream ) {
380+ // consume stream
381+ }
382+
383+ expect ( mockSend ) . toHaveBeenCalledTimes ( 1 )
384+ expect ( capturedPayload ) . toBeDefined ( )
385+ // Temperature should be present for Sonnet 4
386+ expect ( capturedPayload . inferenceConfig ) . toHaveProperty ( "temperature" , 0.5 )
387+ } )
388+
285389 it ( "should support API key authentication" , async ( ) => {
286390 handler = new AwsBedrockHandler ( {
287391 apiProvider : "bedrock" ,
0 commit comments