Skip to main content

tapes_client/core/models/
raw_turn.rs

1//! Raw-turn shapes: the wire log behind a derivation, and its repairs.
2//!
3//! The raw layer is immutable. What can be corrected is the *attribution*
4//! projected over it, which is why the repair shapes describe a replacement
5//! projection rather than an edit.
6
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10use super::ContractModel;
11
12/// One wire-log row: what crossed the wire (or arrived as a transcript push),
13/// without the payload blobs.
14///
15/// Models the contract's `RawTurnHeaderItem` schema.
16#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
17#[serde(default)]
18#[non_exhaustive]
19pub struct RawTurnHeaderItem {
20    /// The contract's `agent_name`.
21    pub agent_name: String,
22
23    /// The contract's `id`.
24    pub id: i64,
25
26    /// The contract's `meta`.
27    pub meta: Value,
28
29    /// The contract's `provider`.
30    pub provider: String,
31
32    /// The contract's `received_at`, an RFC 3339 timestamp.
33    pub received_at: String,
34
35    /// The contract's `request_bytes`.
36    pub request_bytes: i64,
37
38    /// The contract's `request_id`.
39    pub request_id: String,
40
41    /// The contract's `response_bytes`.
42    pub response_bytes: i64,
43
44    /// The contract's `source`.
45    pub source: String,
46}
47
48impl ContractModel for RawTurnHeaderItem {
49    const SCHEMA: &'static str = "RawTurnHeaderItem";
50}
51
52/// A session's wire log.
53///
54/// Models the contract's `RawTurnListResponse` schema.
55#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
56#[serde(default)]
57#[non_exhaustive]
58pub struct RawTurnListResponse {
59    /// The contract's `items`.
60    #[serde(deserialize_with = "super::null_default")]
61    pub items: Vec<RawTurnHeaderItem>,
62}
63
64impl ContractModel for RawTurnListResponse {
65    const SCHEMA: &'static str = "RawTurnListResponse";
66}
67
68/// The effective, repairable attribution projected over an immutable raw
69/// turn.
70///
71/// Models the contract's `RawTurnAttribution` schema.
72#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
73#[serde(default)]
74#[non_exhaustive]
75pub struct RawTurnAttribution {
76    /// The contract's `harness_id`.
77    pub harness_id: String,
78
79    /// The contract's `harness_session_id`.
80    pub harness_session_id: String,
81
82    /// The contract's `parent_harness_session_id`.
83    pub parent_harness_session_id: String,
84
85    /// The contract's `raw_turn_id`.
86    pub raw_turn_id: i64,
87
88    /// The contract's `thread_id`.
89    pub thread_id: String,
90}
91
92impl ContractModel for RawTurnAttribution {
93    const SCHEMA: &'static str = "RawTurnAttribution";
94}
95
96/// Selects exactly one raw row and supplies a complete replacement
97/// attribution.
98///
99/// Models the contract's `RawTurnAttributionRepairRequest` schema.
100/// default.
101#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
102#[serde(default)]
103pub struct RawTurnAttributionRepairRequest {
104    /// The contract's `harness_id`.
105    pub harness_id: String,
106
107    /// The contract's `harness_session_id`.
108    pub harness_session_id: String,
109
110    /// The contract's `paper_proxy_request_id`.
111    pub paper_proxy_request_id: String,
112
113    /// The contract's `parent_harness_session_id`.
114    pub parent_harness_session_id: String,
115
116    /// The contract's `raw_turn_id`.
117    pub raw_turn_id: i64,
118
119    /// The contract's `reason`.
120    pub reason: String,
121
122    /// The contract's `thread_id`.
123    pub thread_id: String,
124}
125
126impl ContractModel for RawTurnAttributionRepairRequest {
127    const SCHEMA: &'static str = "RawTurnAttributionRepairRequest";
128}
129
130/// What an attribution repair changed, and what it left to converge.
131///
132/// Models the contract's `RawTurnAttributionRepairResult` schema.
133/// default.
134#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
135#[serde(default)]
136#[non_exhaustive]
137pub struct RawTurnAttributionRepairResult {
138    /// The contract's `effective`.
139    #[serde(deserialize_with = "super::null_default")]
140    pub effective: RawTurnAttribution,
141
142    /// The contract's `previous`.
143    #[serde(deserialize_with = "super::null_default")]
144    pub previous: RawTurnAttribution,
145
146    /// ProjectionsPending lists the sessions whose synchronous rebuild failed
147    /// after the correction committed.
148    #[serde(deserialize_with = "super::null_default")]
149    pub projections_pending: Vec<RepairPendingSession>,
150
151    /// The contract's `recorded`.
152    pub recorded: bool,
153
154    /// SourceCleanupPending reports that the best-effort removal of the
155    /// emptied previous-session row failed after the correction and both
156    /// projection rebuilds applied.
157    pub source_cleanup_pending: bool,
158}
159
160impl ContractModel for RawTurnAttributionRepairResult {
161    const SCHEMA: &'static str = "RawTurnAttributionRepairResult";
162}
163
164/// One harness session whose projection rebuild did not complete
165/// synchronously during a repair.
166///
167/// Models the contract's `RepairPendingSession` schema.
168#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
169#[serde(default)]
170#[non_exhaustive]
171pub struct RepairPendingSession {
172    /// The contract's `harness_id`.
173    pub harness_id: String,
174
175    /// The contract's `harness_session_id`.
176    pub harness_session_id: String,
177}
178
179impl ContractModel for RepairPendingSession {
180    const SCHEMA: &'static str = "RepairPendingSession";
181}