diff --git a/codex-rs/thread-store/src/in_memory.rs b/codex-rs/thread-store/src/in_memory.rs index 5956b3dc41..b48368ac9c 100644 --- a/codex-rs/thread-store/src/in_memory.rs +++ b/codex-rs/thread-store/src/in_memory.rs @@ -70,9 +70,9 @@ mod tests { let items_err = store .list_items(ListItemsParams { thread_id, - turn_id: "turn_1".to_string(), + turn_id: Some("turn_1".to_string()), include_archived: true, - cursor: None, + start: None, page_size: 10, sort_direction: SortDirection::Asc, }) diff --git a/codex-rs/thread-store/src/lib.rs b/codex-rs/thread-store/src/lib.rs index aec8270a53..2679c9c7a1 100644 --- a/codex-rs/thread-store/src/lib.rs +++ b/codex-rs/thread-store/src/lib.rs @@ -27,6 +27,7 @@ pub use types::ClearableField; pub use types::CreateThreadParams; pub use types::GitInfoPatch; pub use types::ItemPage; +pub use types::ItemPageStart; pub use types::ListItemsParams; pub use types::ListThreadsParams; pub use types::ListTurnsParams; @@ -36,6 +37,8 @@ pub use types::ReadThreadParams; pub use types::ResumeThreadParams; pub use types::SearchThreadsParams; pub use types::SortDirection; +pub use types::StoredCanonicalItem; +pub use types::StoredItemRef; pub use types::StoredThread; pub use types::StoredThreadHistory; pub use types::StoredThreadSearchResult; diff --git a/codex-rs/thread-store/src/types.rs b/codex-rs/thread-store/src/types.rs index ca75ca1b69..b289f2b169 100644 --- a/codex-rs/thread-store/src/types.rs +++ b/codex-rs/thread-store/src/types.rs @@ -18,6 +18,7 @@ use serde::Deserialize; use serde::Deserializer; use serde::Serialize; use serde::Serializer; +use serde_json::Value; mod optional_option { use super::*; @@ -325,31 +326,66 @@ pub struct TurnPage { pub backwards_cursor: Option, } -/// Parameters for listing persisted items within a single turn. +/// Reference to a stored item by its canonical ordinal within a thread. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct StoredItemRef { + /// Thread id containing the item. + pub thread_id: ThreadId, + /// Canonical client-visible item ordinal, not a raw rollout index. + pub item_ordinal: u64, +} + +/// Starting point for canonical item pagination. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum ItemPageStart { + /// Opaque store-owned continuation token returned by a previous list call. + Cursor(String), + /// Canonical client-visible item ordinal. `Ordinal(0)` starts before the first item. + Ordinal(u64), +} + +/// Parameters for listing persisted item snapshots by canonical item ordinal within a thread. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ListItemsParams { /// Thread id to read. pub thread_id: ThreadId, - /// Turn id to hydrate. - pub turn_id: String, + /// Optional turn id filter when callers need to hydrate one stored turn. + pub turn_id: Option, /// Whether archived threads are eligible. pub include_archived: bool, - /// Opaque cursor returned by a previous list call. - pub cursor: Option, + /// Optional starting point for the page. + pub start: Option, /// Maximum number of items to return. pub page_size: usize, - /// Sort direction requested by the caller. + /// Sort direction requested by the caller, applied to canonical item ordinal order. pub sort_direction: SortDirection, } -/// A page of persisted rollout items within a turn. +/// Store-owned item snapshot addressed by a canonical item ordinal. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct StoredCanonicalItem { + /// Canonical item reference. + pub item_ref: StoredItemRef, + /// Turn id associated with this item, when the item belongs to a known turn. + /// + /// This can be `None` for thread-level items, legacy data without turn markers, or stores that + /// cannot assign a turn id while still exposing canonical item ordinals. + pub turn_id: Option, + /// Store-owned item payload. + /// + /// This is intentionally not the current raw `RolloutItem` type or an app-server `ThreadItem`. + /// Callers above the store own projection into public API shapes. + pub item: Value, +} + +/// A page of persisted item snapshots within a thread, ordered by canonical item ordinal. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ItemPage { /// Items returned for this page. - pub items: Vec, - /// Opaque cursor to continue listing. + pub items: Vec, + /// Opaque store-owned continuation token. pub next_cursor: Option, - /// Opaque cursor for fetching in the opposite direction. + /// Opaque store-owned continuation token for fetching in the opposite direction. pub backwards_cursor: Option, }