1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum MessageKind {
9 Task,
11 Reply,
13 Question,
15 Status,
17 Artifact,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(tag = "type", rename_all = "snake_case")]
24pub enum Part {
25 Text {
27 text: String,
29 },
30 Data {
32 data: serde_json::Value,
34 },
35 File {
37 uri: String,
39 },
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
44#[serde(rename_all = "snake_case")]
45pub enum MsgState {
46 Unread,
48 Delivered,
50 Consumed,
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct Message {
57 pub id: Uuid,
59 pub team_id: String,
61 pub task_id: Option<Uuid>,
63 pub from: String,
65 pub to: String,
67 pub kind: MessageKind,
69 pub parts: Vec<Part>,
71 pub in_reply_to: Option<Uuid>,
73 pub state: MsgState,
75 pub created_at: DateTime<Utc>,
77 pub consumed_at: Option<DateTime<Utc>>,
79}
80
81impl Message {
82 pub fn new(
84 team_id: impl Into<String>,
85 from: impl Into<String>,
86 to: impl Into<String>,
87 kind: MessageKind,
88 parts: Vec<Part>,
89 ) -> Self {
90 Message {
91 id: Uuid::new_v4(),
92 team_id: team_id.into(),
93 task_id: None,
94 from: from.into(),
95 to: to.into(),
96 kind,
97 parts,
98 in_reply_to: None,
99 state: MsgState::Unread,
100 created_at: Utc::now(),
101 consumed_at: None,
102 }
103 }
104}
105
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
108pub struct Artifact {
109 pub kind: String,
111 pub content: String,
113 pub name: Option<String>,
115}