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    /// UnattachedActions samples judged actions that found no matching
112    /// tool_use (capped) — expected for non-tool events like subagent
113    /// handbacks; anything else is matcher signal worth reading.
114    #[serde(deserialize_with = "super::null_default")]
115    pub unattached_actions: Vec<String>,
116
117    /// WebSummaryAttached counts web-summary calls linked back to their
118    /// WebFetch/WebSearch tool_use.
119    pub web_summary_attached: i32,
120}
121
122impl ContractModel for RederiveReport {
123    const SCHEMA: &'static str = "RederiveReport";
124}
125
126/// The transcript-to-wire fusion for one org.
127///
128/// Models the contract's `ReconcileStats` schema.
129#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
130#[serde(default)]
131#[non_exhaustive]
132pub struct ReconcileStats {
133    /// Counts anchor rows carrying a non-started kind — interacted re-entries
134    /// a capture client banked for future rendering.
135    pub codex_interacted_rows: i32,
136
137    /// Codex thread-spawn anchoring (see codex.go). Unanchored threads
138    /// degrade to trace-root placement — a non-zero count is the visible
139    /// signal that spawn-anchor rows are missing or ambiguous.
140    pub codex_threads_anchored: i32,
141
142    /// The contract's `codex_threads_unanchored`.
143    pub codex_threads_unanchored: i32,
144
145    /// `ConversationJoined` and `ConversationTotal` measure how many
146    /// conversation- spine nodes' content appears in a transcript — the Go-
147    /// native version of the prototype's join-rate oracle.
148    pub conversation_joined: i32,
149
150    /// The contract's `conversation_total`.
151    pub conversation_total: i32,
152
153    /// The contract's `forked_chains`.
154    pub forked_chains: i32,
155
156    /// The contract's `main_chains_joined`.
157    pub main_chains_joined: i32,
158
159    /// The contract's `subagent_forks`.
160    pub subagent_forks: i32,
161
162    /// The contract's `transcript_files`.
163    pub transcript_files: i32,
164}
165
166impl ContractModel for ReconcileStats {
167    const SCHEMA: &'static str = "ReconcileStats";
168}
169
170/// The response for `GET /v1/stats`.
171///
172/// The figures are sums over the trace-grain rollups, so they agree with the
173/// session detail and trace views rather than being a second count. Duration
174/// is served in milliseconds, not the nanoseconds the spans carry: a summed
175/// nanosecond figure over a wide window leaves a JSON consumer's safe-integer
176/// range.
177///
178/// Models the contract's `StatsResponse` schema.
179#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
180#[serde(default)]
181#[non_exhaustive]
182pub struct StatsResponse {
183    /// The contract's `completed_count`.
184    pub completed_count: i32,
185
186    /// The contract's `input_tokens`.
187    pub input_tokens: i64,
188
189    /// The contract's `output_tokens`.
190    pub output_tokens: i64,
191
192    /// The contract's `session_count`.
193    pub session_count: i32,
194
195    /// The contract's `tool_calls`.
196    pub tool_calls: i32,
197
198    /// The contract's `total_cost`.
199    pub total_cost: f64,
200
201    /// The contract's `total_duration_ms`.
202    pub total_duration_ms: i64,
203
204    /// The contract's `turn_count`.
205    pub turn_count: i32,
206}
207
208impl ContractModel for StatsResponse {
209    const SCHEMA: &'static str = "StatsResponse";
210}