tirea_contract/storage/
run_traits.rs

1use async_trait::async_trait;
2
3use super::{RunPage, RunQuery, RunRecord, RunStoreError};
4
5#[async_trait]
6pub trait RunReader: Send + Sync {
7    /// Load one run by run id.
8    async fn load_run(&self, run_id: &str) -> Result<Option<RunRecord>, RunStoreError>;
9
10    /// List runs with optional filtering and pagination.
11    async fn list_runs(&self, query: &RunQuery) -> Result<RunPage, RunStoreError>;
12
13    /// Resolve thread id from run id.
14    async fn resolve_thread_id(&self, run_id: &str) -> Result<Option<String>, RunStoreError> {
15        Ok(self.load_run(run_id).await?.map(|r| r.thread_id))
16    }
17
18    /// Load the most recent non-terminal run for a thread, if any.
19    ///
20    /// Returns the latest run whose status is not `Done`, ordered by
21    /// `created_at` descending (with `updated_at` and `run_id` as tiebreakers).
22    async fn load_current_run(&self, thread_id: &str) -> Result<Option<RunRecord>, RunStoreError>;
23}
24
25#[async_trait]
26pub trait RunWriter: RunReader {
27    /// Upsert one run record.
28    async fn upsert_run(&self, record: &RunRecord) -> Result<(), RunStoreError>;
29
30    /// Delete one run record by run id.
31    async fn delete_run(&self, run_id: &str) -> Result<(), RunStoreError>;
32}
33
34/// Full run projection store trait.
35pub trait RunStore: RunWriter {}
36
37impl<T: RunWriter + ?Sized> RunStore for T {}