@@ -5,6 +5,7 @@ import { describe, expect, it, jest, beforeEach } from "@jest/globals"
55import { TelemetryService } from "@roo-code/telemetry"
66
77import { ApiHandler } from "../../../api"
8+ import { AwsBedrockHandler } from "../../../api/providers"
89import { ApiMessage } from "../../task-persistence/apiMessages"
910import { maybeRemoveImageBlocks } from "../../../api/transform/image-cleaning"
1011import { summarizeConversation , getMessagesSinceLastSummary , N_MESSAGES_TO_KEEP } from "../index"
@@ -25,14 +26,20 @@ const taskId = "test-task-id"
2526const DEFAULT_PREV_CONTEXT_TOKENS = 1000
2627
2728describe ( "getMessagesSinceLastSummary" , ( ) => {
29+ let mockApiHandler : ApiHandler
30+
31+ beforeEach ( ( ) => {
32+ mockApiHandler = { } as unknown as ApiHandler
33+ } )
34+
2835 it ( "should return all messages when there is no summary" , ( ) => {
2936 const messages : ApiMessage [ ] = [
3037 { role : "user" , content : "Hello" , ts : 1 } ,
3138 { role : "assistant" , content : "Hi there" , ts : 2 } ,
3239 { role : "user" , content : "How are you?" , ts : 3 } ,
3340 ]
3441
35- const result = getMessagesSinceLastSummary ( messages )
42+ const result = getMessagesSinceLastSummary ( messages , mockApiHandler )
3643 expect ( result ) . toEqual ( messages )
3744 } )
3845
@@ -45,7 +52,7 @@ describe("getMessagesSinceLastSummary", () => {
4552 { role : "assistant" , content : "I'm good" , ts : 5 } ,
4653 ]
4754
48- const result = getMessagesSinceLastSummary ( messages )
55+ const result = getMessagesSinceLastSummary ( messages , mockApiHandler )
4956 expect ( result ) . toEqual ( [
5057 { role : "assistant" , content : "Summary of conversation" , ts : 3 , isSummary : true } ,
5158 { role : "user" , content : "How are you?" , ts : 4 } ,
@@ -62,17 +69,63 @@ describe("getMessagesSinceLastSummary", () => {
6269 { role : "user" , content : "What's new?" , ts : 5 } ,
6370 ]
6471
65- const result = getMessagesSinceLastSummary ( messages )
72+ const result = getMessagesSinceLastSummary ( messages , mockApiHandler )
6673 expect ( result ) . toEqual ( [
6774 { role : "assistant" , content : "Second summary" , ts : 4 , isSummary : true } ,
6875 { role : "user" , content : "What's new?" , ts : 5 } ,
6976 ] )
7077 } )
7178
7279 it ( "should handle empty messages array" , ( ) => {
73- const result = getMessagesSinceLastSummary ( [ ] )
80+ const result = getMessagesSinceLastSummary ( [ ] , mockApiHandler )
7481 expect ( result ) . toEqual ( [ ] )
7582 } )
83+
84+ it ( "should prepend user message when using AwsBedrockHandler with summary as first message" , ( ) => {
85+ const mockAwsBedrockHandler = new AwsBedrockHandler ( {
86+ apiModelId : "anthropic.claude-3-5-sonnet-20241022-v2:0" ,
87+ awsAccessKey : "test-key" ,
88+ awsSecretKey : "test-secret" ,
89+ awsRegion : "us-east-1" ,
90+ } )
91+
92+ const messages : ApiMessage [ ] = [
93+ { role : "user" , content : "Hello" , ts : 1 } ,
94+ { role : "assistant" , content : "Hi there" , ts : 2 } ,
95+ { role : "assistant" , content : "Summary of conversation" , ts : 1000 , isSummary : true } ,
96+ { role : "user" , content : "How are you?" , ts : 1001 } ,
97+ { role : "assistant" , content : "I'm good" , ts : 1002 } ,
98+ ]
99+
100+ const result = getMessagesSinceLastSummary ( messages , mockAwsBedrockHandler )
101+
102+ // Should prepend user message before the summary
103+ expect ( result ) . toEqual ( [
104+ { role : "user" , content : "Please continue from the following summary:" , ts : 999 } ,
105+ { role : "assistant" , content : "Summary of conversation" , ts : 1000 , isSummary : true } ,
106+ { role : "user" , content : "How are you?" , ts : 1001 } ,
107+ { role : "assistant" , content : "I'm good" , ts : 1002 } ,
108+ ] )
109+ } )
110+
111+ it ( "should not prepend user message when using non-AwsBedrockHandler" , ( ) => {
112+ const messages : ApiMessage [ ] = [
113+ { role : "user" , content : "Hello" , ts : 1 } ,
114+ { role : "assistant" , content : "Hi there" , ts : 2 } ,
115+ { role : "assistant" , content : "Summary of conversation" , ts : 1000 , isSummary : true } ,
116+ { role : "user" , content : "How are you?" , ts : 1001 } ,
117+ { role : "assistant" , content : "I'm good" , ts : 1002 } ,
118+ ]
119+
120+ const result = getMessagesSinceLastSummary ( messages , mockApiHandler )
121+
122+ // Should not prepend user message for non-AwsBedrockHandler
123+ expect ( result ) . toEqual ( [
124+ { role : "assistant" , content : "Summary of conversation" , ts : 1000 , isSummary : true } ,
125+ { role : "user" , content : "How are you?" , ts : 1001 } ,
126+ { role : "assistant" , content : "I'm good" , ts : 1002 } ,
127+ ] )
128+ } )
76129} )
77130
78131describe ( "summarizeConversation" , ( ) => {
0 commit comments