Skip to main content

systemprompt_models/documents/
comment_events.rs

1//! Payloads of the comment events beyond creation and resolution: an edit
2//! of a comment's body or mentions, a deletion, and the notice a mentioned
3//! user receives.
4//!
5//! Like every document event they are also published on the document's live
6//! topic, so an open workspace updates its comment sidebar in place.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11use chrono::{DateTime, Utc};
12use schemars::JsonSchema;
13use serde::{Deserialize, Serialize};
14use systemprompt_identifiers::{DocumentCommentId, DocumentId, UserId};
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
17pub struct DocumentCommentUpdatedEvent {
18    pub document_id: DocumentId,
19    pub comment_id: DocumentCommentId,
20    pub edited_by: UserId,
21    #[serde(default, skip_serializing_if = "Vec::is_empty")]
22    pub mentions: Vec<UserId>,
23}
24
25impl DocumentCommentUpdatedEvent {
26    pub const NAME: &'static str = "document.comment.updated";
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
30pub struct DocumentCommentDeletedEvent {
31    pub document_id: DocumentId,
32    pub comment_id: DocumentCommentId,
33    pub deleted_by: UserId,
34}
35
36impl DocumentCommentDeletedEvent {
37    pub const NAME: &'static str = "document.comment.deleted";
38}
39
40/// The notice one mentioned user receives.
41///
42/// It is the input contract of the notifications project
43/// (`v` = [`MENTION_EVENT_VERSION`]). `author_id` is
44/// the acting user; `via_agent` names the agent that wrote the comment for
45/// them. `mentions` is the comment's whole mention list and `granted` the
46/// users this comment gave `comment` access. `excerpt` is the start of the
47/// body, mention tokens (`@[Name](user:<id>)`) included; the full thread is
48/// read by `comment_id`. Fields after `author_id` default when absent, so a
49/// frame from an older server still decodes.
50#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
51pub struct DocumentCommentMentionedEvent {
52    pub document_id: DocumentId,
53    pub comment_id: DocumentCommentId,
54    pub mentioned_user_id: UserId,
55    pub author_id: UserId,
56    #[serde(default)]
57    pub v: u32,
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub via_agent: Option<String>,
60    #[serde(default)]
61    pub mentions: Vec<UserId>,
62    #[serde(default)]
63    pub granted: Vec<UserId>,
64    #[serde(default)]
65    pub excerpt: String,
66    #[serde(default, skip_serializing_if = "Option::is_none")]
67    pub anchor_quote: Option<String>,
68    #[serde(default, skip_serializing_if = "Option::is_none")]
69    pub created_at: Option<DateTime<Utc>>,
70}
71
72pub const MENTION_EVENT_VERSION: u32 = 1;
73
74pub const MENTION_EXCERPT_CHARS: usize = 280;
75
76impl DocumentCommentMentionedEvent {
77    pub const NAME: &'static str = "document.comment.mentioned";
78}