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    /// The keep-warm renewals: their spend, already inside `total`, and
27    /// how many there were by what each showed.
28    pub renewals: Renewals,
29}
30
31/// The model calls that came back with no authoritative amount, and the
32/// tokens they used. A city whose provider never prices a call has a
33/// zero `total` after any number of runs; this is what tells that city
34/// apart from one where nothing ran.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
36#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
37pub struct UnpricedCalls {
38    pub calls: u64,
39    pub tokens: u64,
40}
41
42/// The keep-warm renewals the city sent, as `storage::Renewals` counts
43/// them (storage D35, D36). `billed` is already inside `total` and the
44/// cuts, under the room and the `keep_warm` bucket, so a page draws it
45/// as a line inside the total and never adds it again. The four counts
46/// sum to the renewals sent; `late` ones arrived after the cache had
47/// gone and paid the write price for the prefix.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
49#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
50pub struct Renewals {
51    pub billed: UsdMicros,
52    pub read: u64,
53    pub late: u64,
54    pub unreported: u64,
55    pub refused: u64,
56}