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

Function change_metadata_projection

libatomic/src/daemon/services_query.rs:227–289  ·  view source on GitHub ↗

Privacy-limited metadata from the change already decoded by atomic-core. Values are recorded attribution, not verified billing or authorship.

(
    change: &atomic_core::change::Change,
    hash: &atomic_core::types::Hash,
)

Source from the content-addressed store, hash-verified

225/// Privacy-limited metadata from the change already decoded by atomic-core.
226/// Values are recorded attribution, not verified billing or authorship.
227fn change_metadata_projection(
228 change: &atomic_core::change::Change,
229 hash: &atomic_core::types::Hash,
230) -> ChangeMetadata {
231 let mut warnings = Vec::new();
232 let usage = change
233 .hashed
234 .provenance
235 .iter()
236 .enumerate()
237 .map(|(index, record)| {
238 let cost = &record.cost;
239 let cost_micro_usd = if cost.usd.is_finite() && cost.usd >= 0.0 {
240 if cost.micro_usd > 0 || cost.usd == 0.0 {
241 Some(cost.micro_usd)
242 } else if cost.usd * 1_000_000.0 < u64::MAX as f64 {
243 Some(atomic_core::change::Cost::from_usd(cost.usd).micro_usd)
244 } else {
245 None
246 }
247 } else {
248 None
249 };
250 if cost_micro_usd.is_none() {
251 warnings.push(format!(
252 "Usage record {index} has an invalid/out-of-range recorded cost"
253 ));
254 }
255 ChangeAiUsage {
256 record_index: index as u32,
257 vendor: record.vendor.to_string(),
258 model: record.model.clone(),
259 model_version: record.model_version.clone(),
260 tool: record.tool.to_string(),
261 request_id: record.request_id.clone(),
262 session_id: record.session_id.clone(),
263 session_slug: record.session_slug.clone(),
264 step_count: record.step_count,
265 tokens: Some(ChangeTokenUsage {
266 input_tokens: record.tokens.input_tokens,
267 output_tokens: record.tokens.output_tokens,
268 total_tokens: record.tokens.total_tokens,
269 cache_read_tokens: record.tokens.cache_read_tokens,
270 cache_write_tokens: record.tokens.cache_write_tokens,
271 reasoning_tokens: record.tokens.reasoning_tokens,
272 }),
273 cost_micro_usd,
274 }
275 })
276 .collect();
277 let mut affected_paths = atomic_repository::get_files_in_change(change);
278 affected_paths.extend(change.file_ops().iter().map(|ops| ops.path().to_string()));
279 affected_paths.sort();
280 affected_paths.dedup();
281 ChangeMetadata {
282 schema_version: 1,
283 change_hash: Some(hash_proto(hash)),
284 usage,

Calls 12

get_files_in_changeFunction · 0.85
change_graph_summaryFunction · 0.85
is_noneMethod · 0.80
extendMethod · 0.80
sortMethod · 0.80
hash_protoFunction · 0.70
collectMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
file_opsMethod · 0.45
pathMethod · 0.45