Skip to main content

systemprompt_models/brain/
payload.rs

1//! The typed payloads the document store and the gateway carry in a brain
2//! event, so the producer and the consumer agree on one decoded shape.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use serde::{Deserialize, Serialize};
8use systemprompt_identifiers::{
9    AiRequestId, ContentHash, ContextId, DocumentCommentId, DocumentFolderId, DocumentId,
10    DocumentNodeId, DocumentRevisionId, GatewayConversationId, SessionId, TaskId, TraceId, UserId,
11};
12
13use crate::documents::{ActorKind, RevisionOriginKind};
14
15/// A revision that moved its document's head.
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct RevisionLanded {
18    pub document_id: DocumentId,
19    pub revision_id: DocumentRevisionId,
20    pub parent_revision_id: Option<DocumentRevisionId>,
21    pub actor_kind: ActorKind,
22    pub origin_kind: RevisionOriginKind,
23    pub author: UserId,
24    pub session_id: Option<SessionId>,
25    pub context_id: Option<ContextId>,
26    pub trace_id: Option<TraceId>,
27    pub task_id: Option<TaskId>,
28    pub on_behalf_of: Option<UserId>,
29    pub folder_id: Option<DocumentFolderId>,
30    pub content_sha256: ContentHash,
31}
32
33/// Where a resolved comment was anchored: its stable node and, optionally,
34/// the `nth` occurrence of a quote inside it.
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36pub struct CommentAnchorRef {
37    pub node_id: DocumentNodeId,
38    pub hash8: Option<String>,
39    pub find: Option<String>,
40    pub nth: Option<i32>,
41}
42
43/// A comment that was resolved, with the head it was resolved against.
44#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
45pub struct CommentResolved {
46    pub document_id: DocumentId,
47    pub comment_id: DocumentCommentId,
48    pub comment_author: UserId,
49    pub resolved_by: UserId,
50    pub anchor: CommentAnchorRef,
51    pub head_revision_id: Option<DocumentRevisionId>,
52    pub answering_revision_id: Option<DocumentRevisionId>,
53    pub folder_id: Option<DocumentFolderId>,
54}
55
56/// A gateway turn that completed: the last user text and the assistant's
57/// answer, each bounded to the profile's `capture.session.max_chars`.
58///
59/// Scaffolding for the session pathway: the gateway emits it only when
60/// `brain.capture.session.enabled` is on and `capture.sources` lists
61/// `session`.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct SessionTurnClosed {
64    pub user_id: UserId,
65    pub session_id: SessionId,
66    pub ai_request_id: AiRequestId,
67    pub gateway_conversation_id: Option<GatewayConversationId>,
68    pub context_id: Option<ContextId>,
69    pub user_text: String,
70    pub assistant_text: String,
71    pub model: String,
72    pub client: String,
73}
74
75impl SessionTurnClosed {
76    #[must_use]
77    pub fn bounded(text: &str, max_chars: usize) -> String {
78        text.chars().take(max_chars).collect()
79    }
80}