Skip to main content

ThreadStore

Struct ThreadStore 

Source
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

Source

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.

Source

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).

Source

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.

Source

pub fn list_thread_ids(&self) -> ServerResult<Vec<String>>

List all thread IDs stored in the root directory.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn steps_dir(&self, thread_id: &str, run_id: &str) -> PathBuf

Return the path to a run’s steps directory.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn thread_dir(&self, thread_id: &str) -> PathBuf

Return the path to a thread’s subdirectory.

Source

pub fn run_dir(&self, thread_id: &str, run_id: &str) -> PathBuf

Return the path to a run’s subdirectory.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,