@@ -26,6 +26,17 @@ function turnHistory(): Message {
2626 } ;
2727}
2828
29+ function stepBreakpointWith ( otherAnthropicOptions : Record < string , unknown > ) : Message {
30+ return {
31+ role : "tool" ,
32+ content : "ok" ,
33+ providerOptions : {
34+ anthropic : { cacheControl : STEP_CACHE_CONTROL , ...otherAnthropicOptions } ,
35+ openai : { store : false } ,
36+ } ,
37+ } ;
38+ }
39+
2940function ttlOf ( message : Message | undefined ) : unknown {
3041 return ( message ?. providerOptions ?. anthropic as { cacheControl ?: { ttl ?: unknown } } | undefined )
3142 ?. cacheControl ?. ttl ;
@@ -73,6 +84,28 @@ describe("the step cache breakpoint", () => {
7384 expect ( compacted . filter ( ( message ) => ttlOf ( message ) === "5m" ) ) . toHaveLength ( 0 ) ;
7485 } ) ;
7586
87+ it ( "keeps the other anthropic options when it rolls the breakpoint off" , ( ) => {
88+ const marked = markStepCacheBreakpoint ( [
89+ stepBreakpointWith ( { anotherOption : "keep" } ) ,
90+ toolResult ( MIN_STEP_CACHE_CHARS ) ,
91+ ] ) ;
92+
93+ expect ( marked [ 0 ] ! . providerOptions ) . toEqual ( {
94+ anthropic : { anotherOption : "keep" } ,
95+ openai : { store : false } ,
96+ } ) ;
97+ expect ( ttlOf ( marked . at ( - 1 ) ) ) . toBe ( "5m" ) ;
98+ } ) ;
99+
100+ it ( "leaves no empty anthropic object behind" , ( ) => {
101+ const marked = markStepCacheBreakpoint ( [
102+ stepBreakpointWith ( { } ) ,
103+ toolResult ( MIN_STEP_CACHE_CHARS ) ,
104+ ] ) ;
105+
106+ expect ( marked [ 0 ] ! . providerOptions ) . toEqual ( { openai : { store : false } } ) ;
107+ } ) ;
108+
76109 it ( "does nothing to an empty step" , ( ) => {
77110 const empty : Message [ ] = [ ] ;
78111 expect ( markStepCacheBreakpoint ( empty ) ) . toBe ( empty ) ;
0 commit comments