MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / from_attestations

Method from_attestations

atomic-repository/src/git_binding/summary.rs:90–149  ·  view source on GitHub ↗

Project attestations onto the allowlisted summary for one session. Only the allowlisted fields survive: token counts, costs, vendor and model names, and the session id. Attestations are aggregated by (vendor, model) in deterministic order.

(session_id: &str, attestations: &[Attestation])

Source from the content-addressed store, hash-verified

88 /// model names, and the session id. Attestations are aggregated by
89 /// (vendor, model) in deterministic order.
90 pub fn from_attestations(session_id: &str, attestations: &[Attestation]) -> Self {
91 let mut buckets: BTreeMap<(String, String), SummaryModelUsage> = BTreeMap::new();
92 let mut total_input_tokens = 0u64;
93 let mut total_output_tokens = 0u64;
94 let mut total_cache_read_tokens = 0u64;
95 let mut total_cache_write_tokens = 0u64;
96 let mut total_cost_usd = 0f64;
97
98 for attestation in attestations {
99 for usage in &attestation.models {
100 let key = (attestation.agent.vendor.clone(), usage.model.clone());
101 let entry = buckets.entry(key).or_insert_with(|| SummaryModelUsage {
102 vendor: attestation.agent.vendor.clone(),
103 model: usage.model.clone(),
104 input_tokens: 0,
105 output_tokens: 0,
106 cache_read_tokens: 0,
107 cache_write_tokens: 0,
108 cost_usd: 0.0,
109 });
110 entry.input_tokens += usage.input_tokens;
111 entry.output_tokens += usage.output_tokens;
112 entry.cache_read_tokens += usage.cache_read_tokens;
113 entry.cache_write_tokens += usage.cache_write_tokens;
114 entry.cost_usd += usage.cost_usd;
115 }
116 total_input_tokens += attestation
117 .models
118 .iter()
119 .map(|m| m.input_tokens)
120 .sum::<u64>();
121 total_output_tokens += attestation
122 .models
123 .iter()
124 .map(|m| m.output_tokens)
125 .sum::<u64>();
126 total_cache_read_tokens += attestation
127 .models
128 .iter()
129 .map(|m| m.cache_read_tokens)
130 .sum::<u64>();
131 total_cache_write_tokens += attestation
132 .models
133 .iter()
134 .map(|m| m.cache_write_tokens)
135 .sum::<u64>();
136 total_cost_usd += attestation.cost_usd;
137 }
138
139 Self {
140 version: ATTESTATION_SUMMARY_VERSION,
141 session_id: session_id.to_string(),
142 models: buckets.into_values().collect(),
143 total_input_tokens,
144 total_output_tokens,
145 total_cache_read_tokens,
146 total_cache_write_tokens,
147 total_cost_usd,

Callers

nothing calls this directly

Calls 3

cloneMethod · 0.45
iterMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected