Skip to main content

heartbit_core/store/
mod.rs

1//! Task and audit record persistence (in-memory and PostgreSQL backends).
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// Task record stored in a task store.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct TaskRecord {
10    /// Task identifier.
11    pub id: Uuid,
12    /// Lifecycle status (`pending`, `running`, `completed`, `failed`, etc.).
13    pub status: String,
14    /// Original user input that triggered the task.
15    pub task_input: String,
16    /// Name of the agent/orchestrator config that ran the task.
17    pub config_name: Option<String>,
18    /// Final agent output (`None` until completion).
19    pub result: Option<String>,
20    /// Error message when `status` indicates failure.
21    pub error: Option<String>,
22    /// Serialized `TokenUsage` from the run.
23    pub token_usage: Option<serde_json::Value>,
24    /// Task creation timestamp.
25    pub created_at: DateTime<Utc>,
26    /// Task completion timestamp (`None` while running).
27    pub completed_at: Option<DateTime<Utc>>,
28}
29
30/// Audit log entry stored in an audit trail.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct AuditEntry {
33    /// Monotonic entry ID (database-assigned).
34    pub id: i64,
35    /// Task this entry belongs to.
36    pub task_id: Uuid,
37    /// Agent that emitted the event.
38    pub agent_name: String,
39    /// Event type discriminator (e.g. `tool_call`, `llm_request`).
40    pub event_type: String,
41    /// Event-specific JSON payload.
42    pub payload: serde_json::Value,
43    /// Input tokens consumed (when applicable).
44    pub tokens_in: Option<i32>,
45    /// Output tokens produced (when applicable).
46    pub tokens_out: Option<i32>,
47    /// Entry creation timestamp.
48    pub created_at: DateTime<Utc>,
49    /// Tenant that owns this audit entry. `None` for single-tenant deployments.
50    #[serde(default)]
51    pub tenant_id: Option<String>,
52    /// User who triggered the action. `None` when identity is unavailable.
53    #[serde(default)]
54    pub user_id: Option<String>,
55}