Skip to main content

wire/answer/
cost.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The city's cost view: one authoritative total and the cuts of it a
7//! page draws (`crates/wire/spec/Server.lean` ยง8-2).
8
9use kernel::UsdMicros;
10use serde::{Deserialize, Serialize};
11
12/// The five cuts of one authoritative total. Four cuts sum to `total`;
13/// `by_run` names the active runs and the few billed most, so it may sum
14/// to less. Shares render against `total`, so a remainder stays visible.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
17pub struct CostAnswer {
18    pub total: UsdMicros,
19    pub by_run: Vec<(String, UsdMicros)>,
20    pub by_actor: Vec<(String, UsdMicros)>,
21    pub by_segment: Vec<(String, UsdMicros)>,
22    pub by_tool: Vec<(String, UsdMicros)>,
23    pub by_skill: Vec<(String, UsdMicros)>,
24    /// The calls no provider priced, which `total` cannot show.
25    pub unpriced: UnpricedCalls,
26}
27
28/// The model calls that came back with no authoritative amount, and the
29/// tokens they used. A city whose provider never prices a call has a
30/// zero `total` after any number of runs; this is what tells that city
31/// apart from one where nothing ran.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
33#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
34pub struct UnpricedCalls {
35    pub calls: u64,
36    pub tokens: u64,
37}