The summed counters as a dashboard-shaped usage object, resetting the turn sums (the cumulative-total dedup guard survives across turns).
(&mut self)
| 901 | /// The summed counters as a dashboard-shaped usage object, resetting the |
| 902 | /// turn sums (the cumulative-total dedup guard survives across turns). |
| 903 | pub(crate) fn take(&mut self) -> Option<Value> { |
| 904 | if !self.seen { |
| 905 | return None; |
| 906 | } |
| 907 | let mut usage = serde_json::Map::new(); |
| 908 | usage.insert("input_tokens".to_string(), Value::from(self.input)); |
| 909 | usage.insert("output_tokens".to_string(), Value::from(self.output)); |
| 910 | if self.cache_read > 0 { |
| 911 | usage.insert( |
| 912 | "cache_read_input_tokens".to_string(), |
| 913 | Value::from(self.cache_read), |
| 914 | ); |
| 915 | } |
| 916 | if self.reasoning > 0 { |
| 917 | usage.insert("reasoning_tokens".to_string(), Value::from(self.reasoning)); |
| 918 | } |
| 919 | if self.total > 0 { |
| 920 | usage.insert("total_tokens".to_string(), Value::from(self.total)); |
| 921 | } |
| 922 | self.input = 0; |
| 923 | self.output = 0; |
| 924 | self.cache_read = 0; |
| 925 | self.reasoning = 0; |
| 926 | self.total = 0; |
| 927 | self.seen = false; |
| 928 | Some(Value::Object(usage)) |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /// Add `add`'s numeric counters field-wise into `existing` (both are usage |