Add bounded item reads to ThreadStore

This commit is contained in:
Richard Lee
2026-07-03 11:22:25 -07:00
parent da4c8ca57d
commit 448b040ef2
5 changed files with 24 additions and 1 deletions
@@ -2448,6 +2448,8 @@ impl ThreadRequestProcessor {
SortDirection::Asc => StoreSortDirection::Asc,
SortDirection::Desc => StoreSortDirection::Desc,
},
after_updated_at: None,
through_updated_at: None,
})
.await
.map_err(|err| match err {
+7
View File
@@ -46,6 +46,13 @@ pub enum ThreadStoreError {
operation: &'static str,
},
/// The store cannot return the requested result within a required resource limit.
#[error("thread-store resource exhausted: {message}")]
ResourceExhausted {
/// User-facing explanation of the exhausted resource.
message: String,
},
/// Catch-all for implementation failures that do not fit a more specific category.
#[error("thread-store internal error: {message}")]
Internal {
+2
View File
@@ -90,6 +90,8 @@ mod tests {
cursor: None,
page_size: 10,
sort_direction: SortDirection::Asc,
after_updated_at: None,
through_updated_at: None,
})
.await
.expect_err("default list_items should be unsupported");
+3 -1
View File
@@ -111,7 +111,9 @@ pub trait ThreadStore: Any + Send + Sync {
})
}
/// Lists persisted items within a stored thread, optionally filtered to a turn.
/// Lists persisted items within a stored thread, optionally filtered to a turn or update
/// interval. Implementations must return [`ThreadStoreError::Unsupported`] rather than ignore
/// timestamp bounds they cannot apply.
fn list_items(&self, _params: ListItemsParams) -> ThreadStoreFuture<'_, ItemPage> {
Box::pin(async {
Err(ThreadStoreError::Unsupported {
+10
View File
@@ -387,6 +387,13 @@ pub struct ListItemsParams {
pub page_size: usize,
/// Sort direction requested by the caller.
pub sort_direction: SortDirection,
/// Exclusive lower bound for item updates. Requires `through_updated_at` when set.
#[serde(default)]
pub after_updated_at: Option<DateTime<Utc>>,
/// Inclusive upper bound for item updates. Implementations that do not support bounded reads
/// must return [`crate::ThreadStoreError::Unsupported`] instead of ignoring this field.
#[serde(default)]
pub through_updated_at: Option<DateTime<Utc>>,
}
/// A projected app-server `ThreadItem` snapshot within a turn.
@@ -408,6 +415,9 @@ pub struct ItemPage {
pub next_cursor: Option<String>,
/// Opaque cursor for fetching in the opposite direction.
pub backwards_cursor: Option<String>,
/// Inclusive update bound applied by the store, echoed for bounded reads.
#[serde(default)]
pub read_through_updated_at: Option<DateTime<Utc>>,
}
/// Store-owned thread metadata used by list/read/resume responses.