Skip to main content

tapes_client/core/models/
admin.rs

1//! Administrative and aggregate shapes: seeding, derive runs, and stats.
2
3use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6
7use super::ContractModel;
8
9/// A summary of one seeding run.
10///
11/// Models the contract's `SeedResult` schema.
12#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
13#[serde(default)]
14#[non_exhaustive]
15pub struct SeedResult {
16    /// The total number of corpus rows replayed.
17    pub raw_turns: i32,
18
19    /// The contract's `raw_turns_deduped`.
20    pub raw_turns_deduped: i64,
21
22    /// RawTurnsInserted counts rows that landed as new raw turns;
23    /// RawTurnsDeduped counts replays the raw layer's dedup absorbed (a re-
24    /// seed reports everything deduped).
25    pub raw_turns_inserted: i64,
26
27    /// The number of demo sessions the corpora replay into.
28    pub sessions: i32,
29}
30
31impl ContractModel for SeedResult {
32    const SCHEMA: &'static str = "SeedResult";
33}
34
35/// The `POST /v1/admin/seed/demo` body.
36///
37/// Models the contract's `seedDemoRequest` schema.
38#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
39#[serde(default)]
40pub struct SeedDemoRequest {
41    /// The contract's `overwrite`.
42    pub overwrite: bool,
43}
44
45impl ContractModel for SeedDemoRequest {
46    const SCHEMA: &'static str = "seedDemoRequest";
47}
48
49/// The derive-run result, keyed by org.
50///
51/// Models the contract's `deriveRunResponse` schema.
52#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
53#[serde(default)]
54#[non_exhaustive]
55pub struct DeriveRunResponse {
56    /// The contract's `orgs`.
57    #[serde(deserialize_with = "super::null_default")]
58    pub orgs: BTreeMap<String, RederiveReport>,
59}
60
61impl ContractModel for DeriveRunResponse {
62    const SCHEMA: &'static str = "deriveRunResponse";
63}
64
65/// A summary of one derive pass.
66///
67/// Models the contract's `RederiveReport` schema.
68#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
69#[serde(default)]
70#[non_exhaustive]
71pub struct RederiveReport {
72    /// The contract's `attached_verdicts`.
73    pub attached_verdicts: i32,
74
75    /// The contract's `call_kinds`.
76    #[serde(deserialize_with = "super::null_default")]
77    pub call_kinds: BTreeMap<String, i32>,
78
79    /// Verdict attach: judged actions grouped across stages, and how many
80    /// attached one-to-one to a captured tool_use.
81    pub judged_actions: i32,
82
83    /// The contract's `node_kinds`.
84    #[serde(deserialize_with = "super::null_default")]
85    pub node_kinds: BTreeMap<String, i32>,
86
87    /// The contract's `nodes`.
88    pub nodes: i32,
89
90    /// The contract's `parse_failures`.
91    #[serde(deserialize_with = "super::null_default")]
92    pub parse_failures: Vec<String>,
93
94    /// The contract's `parsed_turns`.
95    pub parsed_turns: i32,
96
97    /// PlansAttached counts plan-name-gen calls linked to the ExitPlanMode
98    /// tool_use that accepted the plan.
99    pub plans_attached: i32,
100
101    /// The contract's `raw_only_turns`.
102    pub raw_only_turns: i32,
103
104    /// The contract's `raw_turns`.
105    pub raw_turns: i32,
106
107    /// The contract's `reconcile`.
108    #[serde(deserialize_with = "super::null_default")]
109    pub reconcile: ReconcileStats,
110
111    /// The contract's `transcript_projection`.
112    #[serde(deserialize_with = "super::null_default")]
113    pub transcript_projection: TranscriptProjectionStats,
114
115    /// UnattachedActions samples judged actions that found no matching
116    /// tool_use (capped) — expected for non-tool events like subagent
117    /// handbacks; anything else is matcher signal worth reading.
118    #[serde(deserialize_with = "super::null_default")]
119    pub unattached_actions: Vec<String>,
120
121    /// WebSummaryAttached counts web-summary calls linked back to their
122    /// WebFetch/WebSearch tool_use.
123    pub web_summary_attached: i32,
124}
125
126impl ContractModel for RederiveReport {
127    const SCHEMA: &'static str = "RederiveReport";
128}
129
130/// The transcript-to-wire fusion for one org.
131///
132/// Models the contract's `ReconcileStats` schema.
133#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
134#[serde(default)]
135#[non_exhaustive]
136pub struct ReconcileStats {
137    /// Counts anchor rows carrying a non-started kind — interacted re-entries
138    /// a capture client banked for future rendering.
139    pub codex_interacted_rows: i32,
140
141    /// Codex thread-spawn anchoring (see codex.go). Unanchored threads
142    /// degrade to trace-root placement — a non-zero count is the visible
143    /// signal that spawn-anchor rows are missing or ambiguous.
144    pub codex_threads_anchored: i32,
145
146    /// The contract's `codex_threads_unanchored`.
147    pub codex_threads_unanchored: i32,
148
149    /// `ConversationJoined` and `ConversationTotal` measure how many
150    /// conversation- spine nodes' content appears in a transcript — the Go-
151    /// native version of the prototype's join-rate oracle.
152    pub conversation_joined: i32,
153
154    /// The contract's `conversation_total`.
155    pub conversation_total: i32,
156
157    /// The contract's `forked_chains`.
158    pub forked_chains: i32,
159
160    /// The contract's `main_chains_joined`.
161    pub main_chains_joined: i32,
162
163    /// The contract's `subagent_forks`.
164    pub subagent_forks: i32,
165
166    /// The contract's `transcript_files`.
167    pub transcript_files: i32,
168}
169
170impl ContractModel for ReconcileStats {
171    const SCHEMA: &'static str = "ReconcileStats";
172}
173
174/// The deliberately partial transcript fallback, described.
175///
176/// `omitted_types` makes forward schema skew visible: unsupported records
177/// remain immutable in raw turns, but do not poison records that can be
178/// projected.
179///
180/// Models the contract's `TranscriptProjectionStats` schema.
181#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
182#[serde(default)]
183#[non_exhaustive]
184pub struct TranscriptProjectionStats {
185    /// The contract's `files`.
186    pub files: i32,
187
188    /// The contract's `omitted_records`.
189    pub omitted_records: i32,
190
191    /// The contract's `omitted_types`.
192    #[serde(deserialize_with = "super::null_default")]
193    pub omitted_types: BTreeMap<String, i32>,
194
195    /// The contract's `projected_records`.
196    pub projected_records: i32,
197
198    /// The contract's `records`.
199    pub records: i32,
200
201    /// The contract's `suppressed_by_wire`.
202    pub suppressed_by_wire: bool,
203}
204
205impl ContractModel for TranscriptProjectionStats {
206    const SCHEMA: &'static str = "TranscriptProjectionStats";
207}
208
209/// The response for `GET /v1/stats`.
210///
211/// The figures are sums over the trace-grain rollups, so they agree with the
212/// session detail and trace views rather than being a second count. Duration
213/// is served in milliseconds, not the nanoseconds the spans carry: a summed
214/// nanosecond figure over a wide window leaves a JSON consumer's safe-integer
215/// range.
216///
217/// Models the contract's `StatsResponse` schema.
218#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
219#[serde(default)]
220#[non_exhaustive]
221pub struct StatsResponse {
222    /// The contract's `completed_count`.
223    pub completed_count: i32,
224
225    /// The contract's `input_tokens`.
226    pub input_tokens: i64,
227
228    /// The contract's `output_tokens`.
229    pub output_tokens: i64,
230
231    /// The contract's `session_count`.
232    pub session_count: i32,
233
234    /// The contract's `tool_calls`.
235    pub tool_calls: i32,
236
237    /// The contract's `total_cost`.
238    pub total_cost: f64,
239
240    /// The contract's `total_duration_ms`.
241    pub total_duration_ms: i64,
242
243    /// The contract's `turn_count`.
244    pub turn_count: i32,
245}
246
247impl ContractModel for StatsResponse {
248    const SCHEMA: &'static str = "StatsResponse";
249}