systemprompt_models/events/payloads/
system.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use systemprompt_identifiers::ContextId;
4use systemprompt_traits::ContextWithStats;
5
6use crate::api::contexts::UserContextWithStats;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ContextCreatedPayload {
11    pub context_id: ContextId,
12    pub name: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct ContextUpdatedPayload {
18    pub context_id: ContextId,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub name: Option<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct ContextDeletedPayload {
26    pub context_id: ContextId,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(rename_all = "snake_case")]
31pub struct ContextSummary {
32    pub context_id: ContextId,
33    pub name: String,
34    pub created_at: DateTime<Utc>,
35    pub updated_at: DateTime<Utc>,
36    pub message_count: i64,
37    pub task_count: i64,
38}
39
40impl From<UserContextWithStats> for ContextSummary {
41    fn from(c: UserContextWithStats) -> Self {
42        Self {
43            context_id: c.context_id.clone(),
44            name: c.name,
45            created_at: c.created_at,
46            updated_at: c.updated_at,
47            message_count: c.message_count,
48            task_count: c.task_count,
49        }
50    }
51}
52
53impl From<&UserContextWithStats> for ContextSummary {
54    fn from(c: &UserContextWithStats) -> Self {
55        Self {
56            context_id: c.context_id.clone(),
57            name: c.name.clone(),
58            created_at: c.created_at,
59            updated_at: c.updated_at,
60            message_count: c.message_count,
61            task_count: c.task_count,
62        }
63    }
64}
65
66impl From<ContextWithStats> for ContextSummary {
67    fn from(c: ContextWithStats) -> Self {
68        Self {
69            context_id: ContextId::new(c.context_id),
70            name: c.name,
71            created_at: c.created_at,
72            updated_at: c.updated_at,
73            message_count: c.message_count,
74            task_count: c.task_count,
75        }
76    }
77}
78
79impl From<&ContextWithStats> for ContextSummary {
80    fn from(c: &ContextWithStats) -> Self {
81        Self {
82            context_id: ContextId::new(&c.context_id),
83            name: c.name.clone(),
84            created_at: c.created_at,
85            updated_at: c.updated_at,
86            message_count: c.message_count,
87            task_count: c.task_count,
88        }
89    }
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct ContextsSnapshotPayload {
95    pub contexts: Vec<ContextSummary>,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct ConnectedPayload {
101    pub connection_id: String,
102}