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