@@ -138,44 +138,44 @@ impl CompactConfig {
138138 last_is_user : bool ,
139139 ) -> bool {
140140 // Check token threshold
141- if let Some ( threshold) = self . thresholds . token_threshold {
142- if token_count >= threshold {
143- return true ;
144- }
141+ if let Some ( threshold) = self . thresholds . token_threshold
142+ && token_count >= threshold
143+ {
144+ return true ;
145145 }
146146
147147 // Check turn threshold
148- if let Some ( threshold) = self . thresholds . turn_threshold {
149- if turn_count >= threshold {
150- return true ;
151- }
148+ if let Some ( threshold) = self . thresholds . turn_threshold
149+ && turn_count >= threshold
150+ {
151+ return true ;
152152 }
153153
154154 // Check message threshold
155- if let Some ( threshold) = self . thresholds . message_threshold {
156- if message_count >= threshold {
157- return true ;
158- }
155+ if let Some ( threshold) = self . thresholds . message_threshold
156+ && message_count >= threshold
157+ {
158+ return true ;
159159 }
160160
161161 // Check turn end trigger
162- if let Some ( true ) = self . thresholds . on_turn_end {
163- if last_is_user {
164- // Only trigger if we're also close to other thresholds
165- let near_token = self
166- . thresholds
167- . token_threshold
168- . map ( |t| token_count >= t / 2 )
169- . unwrap_or ( false ) ;
170- let near_turn = self
171- . thresholds
172- . turn_threshold
173- . map ( |t| turn_count >= t / 2 )
174- . unwrap_or ( false ) ;
175-
176- if near_token || near_turn {
177- return true ;
178- }
162+ if let Some ( true ) = self . thresholds . on_turn_end
163+ && last_is_user
164+ {
165+ // Only trigger if we're also close to other thresholds
166+ let near_token = self
167+ . thresholds
168+ . token_threshold
169+ . map ( |t| token_count >= t / 2 )
170+ . unwrap_or ( false ) ;
171+ let near_turn = self
172+ . thresholds
173+ . turn_threshold
174+ . map ( |t| turn_count >= t / 2 )
175+ . unwrap_or ( false ) ;
176+
177+ if near_token || near_turn {
178+ return true ;
179179 }
180180 }
181181
@@ -189,31 +189,31 @@ impl CompactConfig {
189189 turn_count : usize ,
190190 message_count : usize ,
191191 ) -> Option < String > {
192- if let Some ( threshold) = self . thresholds . token_threshold {
193- if token_count >= threshold {
194- return Some ( format ! (
195- "token count ({}) >= threshold ({})" ,
196- token_count , threshold
197- ) ) ;
198- }
192+ if let Some ( threshold) = self . thresholds . token_threshold
193+ && token_count >= threshold
194+ {
195+ return Some ( format ! (
196+ "token count ({}) >= threshold ({})" ,
197+ token_count , threshold
198+ ) ) ;
199199 }
200200
201- if let Some ( threshold) = self . thresholds . turn_threshold {
202- if turn_count >= threshold {
203- return Some ( format ! (
204- "turn count ({}) >= threshold ({})" ,
205- turn_count , threshold
206- ) ) ;
207- }
201+ if let Some ( threshold) = self . thresholds . turn_threshold
202+ && turn_count >= threshold
203+ {
204+ return Some ( format ! (
205+ "turn count ({}) >= threshold ({})" ,
206+ turn_count , threshold
207+ ) ) ;
208208 }
209209
210- if let Some ( threshold) = self . thresholds . message_threshold {
211- if message_count >= threshold {
212- return Some ( format ! (
213- "message count ({}) >= threshold ({})" ,
214- message_count , threshold
215- ) ) ;
216- }
210+ if let Some ( threshold) = self . thresholds . message_threshold
211+ && message_count >= threshold
212+ {
213+ return Some ( format ! (
214+ "message count ({}) >= threshold ({})" ,
215+ message_count , threshold
216+ ) ) ;
217217 }
218218
219219 None
0 commit comments