Skip to main content

systemprompt_models/events/payloads/
system.rs

1//! System event payload shapes and context summaries.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use 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
45// Why: the owned impl delegates rather than repeating the field list. Both
46// were written out in full, so a field added to `ContextSummary` had to be
47// added in two places and the compiler flagged only one of them.
48impl From<UserContextWithStats> for ContextSummary {
49    fn from(c: UserContextWithStats) -> Self {
50        Self::from(&c)
51    }
52}
53
54impl From<&UserContextWithStats> for ContextSummary {
55    fn from(c: &UserContextWithStats) -> Self {
56        Self {
57            context_id: c.context_id.clone(),
58            name: c.name.clone(),
59            created_at: c.created_at,
60            updated_at: c.updated_at,
61            message_count: c.message_count,
62            task_count: c.task_count,
63        }
64    }
65}
66
67impl From<ContextWithStats> for ContextSummary {
68    fn from(c: ContextWithStats) -> Self {
69        Self::from(&c)
70    }
71}
72
73impl From<&ContextWithStats> for ContextSummary {
74    fn from(c: &ContextWithStats) -> Self {
75        Self {
76            context_id: c.context_id.clone(),
77            name: c.name.clone(),
78            created_at: c.created_at,
79            updated_at: c.updated_at,
80            message_count: c.message_count,
81            task_count: c.task_count,
82        }
83    }
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(rename_all = "camelCase")]
88pub struct ContextsSnapshotPayload {
89    pub contexts: Vec<ContextSummary>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct ConnectedPayload {
95    pub connection_id: systemprompt_identifiers::ConnectionId,
96}