Skip to main content

reduce_session

Function reduce_session 

Source
pub fn reduce_session(
    entries: &[UsageEntry],
    launched_model: &str,
    session_id_hint: &str,
) -> Option<SessionUsage>
Expand description

Reduce a list of UsageEntry for a single session into a SessionUsage.

Preserves existing semantics:

  • Primary model = the model used by the most messages (mode).
  • Context window % uses the LAST entry’s total input (API resends the full conversation each turn; the last turn’s input is the current usage).
  • launched_model (from launch options) is used for context window sizing because JSONL strips the [1m] suffix; fall back to mode when empty. The window is never smaller than the session’s peak single-entry context.