Skip to main content

session_totals

Function session_totals 

Source
pub fn session_totals(s: &EconomicsSession) -> Option<EconomicsUsage>
Expand description

A session’s totals. The harness’s per-model totals are preferred, because they include the calls the harness makes on its own account (titles, summaries) that the transcript does not show as messages; the per-request sum is used only when they are absent. None when the session reported neither: absence stays absence.

use majordomus_cli::economics::model::{EconomicsModelTotal, EconomicsSession};
use majordomus_cli::economics::usage::{anthropic_request, session_totals};
let usage = serde_json::json!({"input_tokens": 5, "cache_read_input_tokens": 90,
    "output_tokens": 10});
let mut s = session(vec![anthropic_request("m", &usage)]);
assert_eq!(session_totals(&s).map(|t| (t.total_input, t.total)), Some((95, 105)));
s.models.push(EconomicsModelTotal { model: "m".into(), input_tokens: 25,
    cache_creation_input_tokens: 0, cache_read_input_tokens: 90, output_tokens: 12,
    cost_microusd: None });
assert_eq!(session_totals(&s).unwrap().total, 127, "the harness's totals win");
s.models.clear();
s.requests.clear();
assert_eq!(session_totals(&s), None, "absence stays absence");