pub struct ThreadStore { /* private fields */ }Expand description
Disk-backed store for threads, messages, and runs.
All methods are synchronous and are intended to be called from within a
tokio::task::spawn_blocking context (see the route handlers and worker).
Implementations§
Source§impl ThreadStore
impl ThreadStore
Sourcepub fn new(dir: PathBuf) -> ServerResult<Self>
pub fn new(dir: PathBuf) -> ServerResult<Self>
Open (or create) the thread store root directory.
Creates the directory and any missing parents if they do not exist.
Sourcepub fn create_thread(&self, thread: &Thread) -> ServerResult<()>
pub fn create_thread(&self, thread: &Thread) -> ServerResult<()>
Persist a new thread to disk.
Creates {root}/{thread_id}/meta.json atomically. Fails if the
directory already exists (duplicate ID).
Sourcepub fn get_thread(&self, id: &str) -> ServerResult<Thread>
pub fn get_thread(&self, id: &str) -> ServerResult<Thread>
Read a thread’s metadata from disk.
Returns ServerError::ThreadNotFound if no directory or meta.json
exists for the given ID.
Sourcepub fn list_thread_ids(&self) -> ServerResult<Vec<String>>
pub fn list_thread_ids(&self) -> ServerResult<Vec<String>>
List all thread IDs stored in the root directory.
Sourcepub fn append_message(
&self,
thread_id: &str,
msg: &ThreadMessage,
) -> ServerResult<()>
pub fn append_message( &self, thread_id: &str, msg: &ThreadMessage, ) -> ServerResult<()>
Append a single message to the thread’s messages.jsonl file.
Appends are not atomic at the OS level (no fsync fence), but each
line is a complete JSON object, so a reader will never observe a
partially-written message — incomplete trailing lines are filtered out
by list_messages.
Sourcepub fn list_messages(&self, thread_id: &str) -> ServerResult<Vec<ThreadMessage>>
pub fn list_messages(&self, thread_id: &str) -> ServerResult<Vec<ThreadMessage>>
Read all messages for a thread in append order (oldest first).
Blank lines and lines that fail to parse as JSON are silently skipped so that a partial write at the end of a previous session does not break future reads.
Sourcepub fn create_run(&self, thread_id: &str, run: &Run) -> ServerResult<()>
pub fn create_run(&self, thread_id: &str, run: &Run) -> ServerResult<()>
Persist a new run to disk.
Creates {root}/{thread_id}/runs/{run_id}/status.json atomically.
Returns ThreadNotFound if the thread does not exist.
Sourcepub fn get_run(&self, thread_id: &str, run_id: &str) -> ServerResult<Run>
pub fn get_run(&self, thread_id: &str, run_id: &str) -> ServerResult<Run>
Read a run’s status from disk.
Returns RunNotFound if no status.json exists for the given IDs.
Sourcepub fn update_run_status(
&self,
thread_id: &str,
run_id: &str,
status: RunStatus,
error: Option<RunError>,
) -> ServerResult<()>
pub fn update_run_status( &self, thread_id: &str, run_id: &str, status: RunStatus, error: Option<RunError>, ) -> ServerResult<()>
Atomically update a run’s status (and optionally set last_error).
Returns RunNotFound if the run does not exist, or
RunInTerminalState if the run is already in a terminal state.
Sourcepub fn force_update_run_status(
&self,
thread_id: &str,
run_id: &str,
status: RunStatus,
error: Option<RunError>,
) -> ServerResult<()>
pub fn force_update_run_status( &self, thread_id: &str, run_id: &str, status: RunStatus, error: Option<RunError>, ) -> ServerResult<()>
Force-update a run’s status bypassing terminal-state guard.
Used by the cancel handler to transition a queued/in-progress run to
Cancelled even if no worker is currently processing it.
Sourcepub fn steps_dir(&self, thread_id: &str, run_id: &str) -> PathBuf
pub fn steps_dir(&self, thread_id: &str, run_id: &str) -> PathBuf
Return the path to a run’s steps directory.
Sourcepub fn append_step(
&self,
thread_id: &str,
run_id: &str,
step: &RunStep,
) -> ServerResult<()>
pub fn append_step( &self, thread_id: &str, run_id: &str, step: &RunStep, ) -> ServerResult<()>
Persist a new run step to disk.
Creates {root}/{thread_id}/runs/{run_id}/steps/{step_id}.json
atomically. Returns RunNotFound if the run does not exist.
Sourcepub fn list_steps(
&self,
thread_id: &str,
run_id: &str,
) -> ServerResult<Vec<RunStep>>
pub fn list_steps( &self, thread_id: &str, run_id: &str, ) -> ServerResult<Vec<RunStep>>
Read all steps for a run, sorted by created_at ascending.
Returns RunNotFound if the run does not exist.
Sourcepub fn get_step(
&self,
thread_id: &str,
run_id: &str,
step_id: &str,
) -> ServerResult<RunStep>
pub fn get_step( &self, thread_id: &str, run_id: &str, step_id: &str, ) -> ServerResult<RunStep>
Read a single run step by ID.
Returns RunStepNotFound if no step with this ID exists.
Sourcepub fn update_step_status(
&self,
thread_id: &str,
run_id: &str,
step_id: &str,
status: RunStepStatus,
) -> ServerResult<()>
pub fn update_step_status( &self, thread_id: &str, run_id: &str, step_id: &str, status: RunStepStatus, ) -> ServerResult<()>
Atomically update a run step’s status (and optionally timestamps/error).
Returns RunStepNotFound if no step with this ID exists.
Sourcepub fn thread_dir(&self, thread_id: &str) -> PathBuf
pub fn thread_dir(&self, thread_id: &str) -> PathBuf
Return the path to a thread’s subdirectory.
Auto Trait Implementations§
impl Freeze for ThreadStore
impl RefUnwindSafe for ThreadStore
impl Send for ThreadStore
impl Sync for ThreadStore
impl Unpin for ThreadStore
impl UnsafeUnpin for ThreadStore
impl UnwindSafe for ThreadStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more