@@ -1055,7 +1055,7 @@ describe("summarizeConversation", () => {
10551055 expect ( mockApiHandler . createMessage ) . not . toHaveBeenCalled ( )
10561056 } )
10571057
1058- it ( "should return error when both condensing and main API handlers are invalid" , async ( ) => {
1058+ it ( "should return error when API handler is invalid" , async ( ) => {
10591059 const messages : ApiMessage [ ] = [
10601060 { role : "user" , content : "Hello" , ts : 1 } ,
10611061 { role : "assistant" , content : "Hi there" , ts : 2 } ,
@@ -1066,14 +1066,8 @@ describe("summarizeConversation", () => {
10661066 { role : "user" , content : "Tell me more" , ts : 7 } ,
10671067 ]
10681068
1069- // Create invalid handlers (missing createMessage)
1070- const invalidMainHandler = {
1071- countTokens : vi . fn ( ) ,
1072- getModel : vi . fn ( ) ,
1073- // createMessage is missing
1074- } as unknown as ApiHandler
1075-
1076- const invalidCondensingHandler = {
1069+ // Create invalid handler (missing createMessage)
1070+ const invalidHandler = {
10771071 countTokens : vi . fn ( ) ,
10781072 getModel : vi . fn ( ) ,
10791073 // createMessage is missing
@@ -1086,26 +1080,21 @@ describe("summarizeConversation", () => {
10861080
10871081 const result = await summarizeConversation (
10881082 messages ,
1089- invalidMainHandler ,
1083+ invalidHandler ,
10901084 defaultSystemPrompt ,
10911085 taskId ,
10921086 DEFAULT_PREV_CONTEXT_TOKENS ,
1093- false ,
1094- undefined ,
1095- invalidCondensingHandler ,
10961087 )
10971088
1098- // Should return original messages when both handlers are invalid
1089+ // Should return original messages when handler is invalid
10991090 expect ( result . messages ) . toEqual ( messages )
11001091 expect ( result . cost ) . toBe ( 0 )
11011092 expect ( result . summary ) . toBe ( "" )
11021093 expect ( result . error ) . toBeTruthy ( ) // Error should be set
11031094 expect ( result . newContextTokens ) . toBeUndefined ( )
11041095
11051096 // Verify error was logged
1106- expect ( mockError ) . toHaveBeenCalledWith (
1107- expect . stringContaining ( "Main API handler is also invalid for condensing" ) ,
1108- )
1097+ expect ( mockError ) . toHaveBeenCalledWith ( expect . stringContaining ( "API handler is invalid for condensing" ) )
11091098
11101099 // Restore console.error
11111100 console . error = originalError
@@ -1157,10 +1146,6 @@ describe("summarizeConversation", () => {
11571146 defaultSystemPrompt ,
11581147 taskId ,
11591148 DEFAULT_PREV_CONTEXT_TOKENS ,
1160- false , // isAutomaticTrigger
1161- undefined , // customCondensingPrompt
1162- undefined , // condensingApiHandler
1163- true , // useNativeTools - required for tool_use block preservation
11641149 )
11651150
11661151 // Find the summary message
@@ -1236,10 +1221,6 @@ describe("summarizeConversation", () => {
12361221 defaultSystemPrompt ,
12371222 taskId ,
12381223 DEFAULT_PREV_CONTEXT_TOKENS ,
1239- false ,
1240- undefined ,
1241- undefined ,
1242- true ,
12431224 )
12441225
12451226 expect ( result . error ) . toBeUndefined ( )
@@ -1315,10 +1296,6 @@ describe("summarizeConversation", () => {
13151296 defaultSystemPrompt ,
13161297 taskId ,
13171298 DEFAULT_PREV_CONTEXT_TOKENS ,
1318- false ,
1319- undefined ,
1320- undefined ,
1321- true ,
13221299 )
13231300
13241301 // Find the summary message (it has isSummary: true)
@@ -1389,10 +1366,6 @@ describe("summarizeConversation", () => {
13891366 defaultSystemPrompt ,
13901367 taskId ,
13911368 DEFAULT_PREV_CONTEXT_TOKENS ,
1392- false , // isAutomaticTrigger
1393- undefined , // customCondensingPrompt
1394- undefined , // condensingApiHandler
1395- true , // useNativeTools - required for tool_use block preservation
13961369 )
13971370
13981371 // Find the summary message
@@ -1458,10 +1431,6 @@ describe("summarizeConversation", () => {
14581431 defaultSystemPrompt ,
14591432 taskId ,
14601433 DEFAULT_PREV_CONTEXT_TOKENS ,
1461- false , // isAutomaticTrigger
1462- undefined , // customCondensingPrompt
1463- undefined , // condensingApiHandler
1464- false , // useNativeTools - not using tools in this test
14651434 )
14661435
14671436 // Find the summary message
@@ -1489,7 +1458,6 @@ describe("summarizeConversation", () => {
14891458describe ( "summarizeConversation with custom settings" , ( ) => {
14901459 // Mock necessary dependencies
14911460 let mockMainApiHandler : ApiHandler
1492- let mockCondensingApiHandler : ApiHandler
14931461 const defaultSystemPrompt = "Default prompt"
14941462 const taskId = "test-task"
14951463
@@ -1511,7 +1479,7 @@ describe("summarizeConversation with custom settings", () => {
15111479 // Reset telemetry mock
15121480 ; ( TelemetryService . instance . captureContextCondensed as Mock ) . mockClear ( )
15131481
1514- // Setup mock API handlers
1482+ // Setup mock API handler
15151483 mockMainApiHandler = {
15161484 createMessage : vi . fn ( ) . mockImplementation ( ( ) => {
15171485 return ( async function * ( ) {
@@ -1534,29 +1502,6 @@ describe("summarizeConversation with custom settings", () => {
15341502 } ,
15351503 } ) ,
15361504 } as unknown as ApiHandler
1537-
1538- mockCondensingApiHandler = {
1539- createMessage : vi . fn ( ) . mockImplementation ( ( ) => {
1540- return ( async function * ( ) {
1541- yield { type : "text" as const , text : "Summary from condensing handler" }
1542- yield { type : "usage" as const , totalCost : 0.03 , outputTokens : 80 }
1543- } ) ( )
1544- } ) ,
1545- countTokens : vi . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( 40 ) ) ,
1546- getModel : vi . fn ( ) . mockReturnValue ( {
1547- id : "condensing-model" ,
1548- info : {
1549- contextWindow : 4000 ,
1550- supportsImages : true ,
1551- supportsVision : false ,
1552- maxTokens : 2000 ,
1553- supportsPromptCache : false ,
1554- maxCachePoints : 0 ,
1555- minTokensPerCachePoint : 0 ,
1556- cachableFields : [ ] ,
1557- } ,
1558- } ) ,
1559- } as unknown as ApiHandler
15601505 } )
15611506
15621507 /**
@@ -1619,84 +1564,6 @@ describe("summarizeConversation with custom settings", () => {
16191564 expect ( createMessageCalls [ 0 ] [ 0 ] ) . toContain ( "Your task is to create a detailed summary" )
16201565 } )
16211566
1622- /**
1623- * Test that condensing API handler is used when provided and valid
1624- */
1625- it ( "should use condensingApiHandler when provided and valid" , async ( ) => {
1626- await summarizeConversation (
1627- sampleMessages ,
1628- mockMainApiHandler ,
1629- defaultSystemPrompt ,
1630- taskId ,
1631- DEFAULT_PREV_CONTEXT_TOKENS ,
1632- false ,
1633- undefined ,
1634- mockCondensingApiHandler ,
1635- )
1636-
1637- // Verify the condensing handler was used
1638- expect ( ( mockCondensingApiHandler . createMessage as Mock ) . mock . calls . length ) . toBe ( 1 )
1639- expect ( ( mockMainApiHandler . createMessage as Mock ) . mock . calls . length ) . toBe ( 0 )
1640- } )
1641-
1642- /**
1643- * Test fallback to main API handler when condensing handler is not provided
1644- */
1645- it ( "should fall back to mainApiHandler if condensingApiHandler is not provided" , async ( ) => {
1646- await summarizeConversation (
1647- sampleMessages ,
1648- mockMainApiHandler ,
1649- defaultSystemPrompt ,
1650- taskId ,
1651- DEFAULT_PREV_CONTEXT_TOKENS ,
1652- false ,
1653- undefined ,
1654- undefined ,
1655- )
1656-
1657- // Verify the main handler was used
1658- expect ( ( mockMainApiHandler . createMessage as Mock ) . mock . calls . length ) . toBe ( 1 )
1659- } )
1660-
1661- /**
1662- * Test fallback to main API handler when condensing handler is invalid
1663- */
1664- it ( "should fall back to mainApiHandler if condensingApiHandler is invalid" , async ( ) => {
1665- // Create an invalid handler (missing createMessage)
1666- const invalidHandler = {
1667- countTokens : vi . fn ( ) ,
1668- getModel : vi . fn ( ) ,
1669- // createMessage is missing
1670- } as unknown as ApiHandler
1671-
1672- // Mock console.warn to verify warning message
1673- const originalWarn = console . warn
1674- const mockWarn = vi . fn ( )
1675- console . warn = mockWarn
1676-
1677- await summarizeConversation (
1678- sampleMessages ,
1679- mockMainApiHandler ,
1680- defaultSystemPrompt ,
1681- taskId ,
1682- DEFAULT_PREV_CONTEXT_TOKENS ,
1683- false ,
1684- undefined ,
1685- invalidHandler ,
1686- )
1687-
1688- // Verify the main handler was used as fallback
1689- expect ( ( mockMainApiHandler . createMessage as Mock ) . mock . calls . length ) . toBe ( 1 )
1690-
1691- // Verify warning was logged
1692- expect ( mockWarn ) . toHaveBeenCalledWith (
1693- expect . stringContaining ( "Chosen API handler for condensing does not support message creation" ) ,
1694- )
1695-
1696- // Restore console.warn
1697- console . warn = originalWarn
1698- } )
1699-
17001567 /**
17011568 * Test that telemetry is called for custom prompt usage
17021569 */
@@ -1716,38 +1583,13 @@ describe("summarizeConversation with custom settings", () => {
17161583 taskId ,
17171584 false ,
17181585 true , // usedCustomPrompt
1719- false , // usedCustomApiHandler
1720- )
1721- } )
1722-
1723- /**
1724- * Test that telemetry is called for custom API handler usage
1725- */
1726- it ( "should capture telemetry when using custom API handler" , async ( ) => {
1727- await summarizeConversation (
1728- sampleMessages ,
1729- mockMainApiHandler ,
1730- defaultSystemPrompt ,
1731- taskId ,
1732- DEFAULT_PREV_CONTEXT_TOKENS ,
1733- false ,
1734- undefined ,
1735- mockCondensingApiHandler ,
1736- )
1737-
1738- // Verify telemetry was called with custom API handler flag
1739- expect ( TelemetryService . instance . captureContextCondensed ) . toHaveBeenCalledWith (
1740- taskId ,
1741- false ,
1742- false , // usedCustomPrompt
1743- true , // usedCustomApiHandler
17441586 )
17451587 } )
17461588
17471589 /**
1748- * Test that telemetry is called with both custom prompt and API handler
1590+ * Test that telemetry is called with isAutomaticTrigger flag
17491591 */
1750- it ( "should capture telemetry when using both custom prompt and API handler " , async ( ) => {
1592+ it ( "should capture telemetry with isAutomaticTrigger flag " , async ( ) => {
17511593 await summarizeConversation (
17521594 sampleMessages ,
17531595 mockMainApiHandler ,
@@ -1756,15 +1598,13 @@ describe("summarizeConversation with custom settings", () => {
17561598 DEFAULT_PREV_CONTEXT_TOKENS ,
17571599 true , // isAutomaticTrigger
17581600 "Custom prompt" ,
1759- mockCondensingApiHandler ,
17601601 )
17611602
1762- // Verify telemetry was called with both flags
1603+ // Verify telemetry was called with isAutomaticTrigger flag
17631604 expect ( TelemetryService . instance . captureContextCondensed ) . toHaveBeenCalledWith (
17641605 taskId ,
17651606 true , // isAutomaticTrigger
17661607 true , // usedCustomPrompt
1767- true , // usedCustomApiHandler
17681608 )
17691609 } )
17701610} )
0 commit comments