normalizedCompactionConfig returns a copy of the compaction options with defaults applied. The bool is false when compaction is disabled (nil options, missing Persist callback, or threshold at 100%).
(opts *CompactionOptions)
| 200 | // disabled (nil options, missing Persist callback, or threshold at |
| 201 | // 100%). |
| 202 | func normalizedCompactionConfig(opts *CompactionOptions) (CompactionOptions, bool) { |
| 203 | if opts == nil { |
| 204 | return CompactionOptions{}, false |
| 205 | } |
| 206 | |
| 207 | config := *opts |
| 208 | if config.Persist == nil { |
| 209 | return CompactionOptions{}, false |
| 210 | } |
| 211 | if strings.TrimSpace(config.SummaryPrompt) == "" { |
| 212 | config.SummaryPrompt = defaultCompactionSummaryPrompt |
| 213 | } |
| 214 | if strings.TrimSpace(config.SystemSummaryPrefix) == "" { |
| 215 | config.SystemSummaryPrefix = defaultCompactionSystemSummaryPrefix |
| 216 | } |
| 217 | if config.Timeout <= 0 { |
| 218 | config.Timeout = defaultCompactionTimeout |
| 219 | } |
| 220 | if config.ThresholdPercent < minCompactionThresholdPercent || |
| 221 | config.ThresholdPercent > maxCompactionThresholdPercent { |
| 222 | config.ThresholdPercent = defaultCompactionThresholdPercent |
| 223 | } |
| 224 | if config.ThresholdPercent == maxCompactionThresholdPercent { |
| 225 | return CompactionOptions{}, false |
| 226 | } |
| 227 | |
| 228 | return config, true |
| 229 | } |
| 230 | |
| 231 | // contextTokensFromUsage returns the total context token count from |
| 232 | // a step's usage report. It sums input, cache-read, and |