Skip to main content

systemprompt_agent/models/
database_rows.rs

1//! `FromRow` structs mirroring the agent crate's database tables.
2//!
3//! Each struct maps one query result shape (tasks, messages, message parts,
4//! artifacts, execution steps, push-notification configs) onto typed
5//! identifiers, with `From` conversions to the public domain types where the
6//! row is exposed beyond the repository layer.
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 serde::{Deserialize, Serialize};
13use sqlx::FromRow;
14use systemprompt_identifiers::{
15    AgentName, ArtifactId, ContextId, ExecutionStepId, McpExecutionId, MessageId, SessionId,
16    SkillId, TaskId, TraceId, UserId,
17};
18
19#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
20pub(crate) struct TaskRow {
21    pub task_id: TaskId,
22    pub context_id: ContextId,
23    pub status: String,
24    pub status_timestamp: Option<DateTime<Utc>>,
25    pub user_id: Option<UserId>,
26    pub session_id: Option<SessionId>,
27    pub trace_id: Option<TraceId>,
28    pub agent_name: Option<AgentName>,
29    pub started_at: Option<DateTime<Utc>>,
30    pub completed_at: Option<DateTime<Utc>>,
31    pub execution_time_ms: Option<i32>,
32    pub error_message: Option<String>,
33    pub metadata: Option<serde_json::Value>,
34    pub created_at: DateTime<Utc>,
35    pub updated_at: DateTime<Utc>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
39pub struct TaskMessage {
40    pub id: i32,
41    pub task_id: TaskId,
42    pub message_id: MessageId,
43    pub client_message_id: Option<String>,
44    pub role: String,
45    pub context_id: ContextId,
46    pub user_id: Option<UserId>,
47    pub session_id: Option<SessionId>,
48    pub trace_id: Option<TraceId>,
49    pub sequence_number: i32,
50    pub created_at: DateTime<Utc>,
51    pub updated_at: DateTime<Utc>,
52    pub metadata: Option<serde_json::Value>,
53    pub reference_task_ids: Option<Vec<String>>,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
57pub struct MessagePart {
58    pub id: i32,
59    pub message_id: MessageId,
60    pub task_id: TaskId,
61    pub part_kind: String,
62    pub sequence_number: i32,
63    pub text_content: Option<String>,
64    pub file_name: Option<String>,
65    pub file_mime_type: Option<String>,
66    pub file_uri: Option<String>,
67    pub file_bytes: Option<String>,
68    pub data_content: Option<serde_json::Value>,
69    pub metadata: Option<serde_json::Value>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
73pub struct ArtifactRow {
74    pub artifact_id: ArtifactId,
75    pub task_id: TaskId,
76    pub context_id: ContextId,
77    pub name: Option<String>,
78    pub description: Option<String>,
79    pub artifact_type: String,
80    pub source: Option<String>,
81    pub tool_name: Option<String>,
82    pub mcp_execution_id: Option<McpExecutionId>,
83    pub fingerprint: Option<String>,
84    pub skill_id: Option<SkillId>,
85    pub skill_name: Option<String>,
86    pub metadata: Option<serde_json::Value>,
87    pub created_at: DateTime<Utc>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
91pub struct ArtifactPartRow {
92    pub id: i32,
93    pub artifact_id: ArtifactId,
94    pub context_id: ContextId,
95    pub part_kind: String,
96    pub sequence_number: i32,
97    pub text_content: Option<String>,
98    pub file_name: Option<String>,
99    pub file_mime_type: Option<String>,
100    pub file_uri: Option<String>,
101    pub file_bytes: Option<String>,
102    pub data_content: Option<serde_json::Value>,
103    pub metadata: Option<serde_json::Value>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
107pub struct ExecutionStepBatchRow {
108    pub step_id: ExecutionStepId,
109    pub task_id: TaskId,
110    pub status: String,
111    pub content: serde_json::Value,
112    pub started_at: DateTime<Utc>,
113    pub completed_at: Option<DateTime<Utc>>,
114    pub duration_ms: Option<i32>,
115    pub error_message: Option<String>,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
119pub(crate) struct PushNotificationConfigRow {
120    pub id: String,
121    pub task_id: TaskId,
122    pub url: String,
123    pub endpoint: String,
124    pub token: Option<String>,
125    pub headers: Option<serde_json::Value>,
126    pub authentication: Option<serde_json::Value>,
127    pub created_at: DateTime<Utc>,
128    pub updated_at: DateTime<Utc>,
129}