printobserver_supervisor_api/
session.rs1use printobserver_types::contract::Sample;
10use printobserver_types::schemars::JsonSchema;
11use printobserver_types::serde::{Deserialize, Serialize};
12use printobserver_types::{PrintId, Timestamp};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
16#[serde(
17 crate = "printobserver_types::serde",
18 rename_all = "snake_case",
19 deny_unknown_fields
20)]
21#[schemars(crate = "printobserver_types::schemars")]
22pub enum SessionPhase {
23 Created,
25 Continued,
27}
28
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
31#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
32#[schemars(crate = "printobserver_types::schemars")]
33pub struct SupervisionSession {
34 pub print_id: PrintId,
36 pub session_name: String,
38 pub harness_identity: String,
40 pub created_at: Timestamp,
42 pub last_turn_at: Timestamp,
44 #[serde(default, skip_serializing_if = "Option::is_none")]
46 pub closed_at: Option<Timestamp>,
47 #[serde(default, skip_serializing_if = "Option::is_none")]
49 pub close_reason: Option<String>,
50}
51
52impl Sample for SessionPhase {
53 fn sample_full() -> Self {
54 Self::Created
55 }
56}
57
58impl Sample for SupervisionSession {
59 fn sample_full() -> Self {
60 Self {
61 print_id: PrintId::sample_full(),
62 session_name: "print-0191f0a0".to_owned(),
63 harness_identity: "printobserver-supervisor".to_owned(),
64 created_at: Timestamp::sample_full(),
65 last_turn_at: later_instant(),
66 closed_at: Some(later_instant()),
67 close_reason: Some("the print ended".to_owned()),
68 }
69 }
70
71 fn sample_minimal() -> Self {
72 Self {
73 closed_at: None,
74 close_reason: None,
75 ..Self::sample_full()
76 }
77 }
78}
79
80fn later_instant() -> Timestamp {
82 "2026-03-01T12:30:00Z"
83 .parse()
84 .expect("a fixed RFC 3339 instant")
85}