Files
codex/codex-rs/thread-store/src/remote/mod.rs
T
Tom a718b6fd47 Read conversation summaries through thread store (#18716)
Migrate the conversation summary App Server methods to ThreadStore

Because this app server api allows explicitly fetching the thread by
rollout path, intercept that case in the app server code and (a) route
directly to underlying local thread store methods if we're using a local
thread store, or (b) throw an unsupported error if we're using a remote
thread store. This keeps the thread store API clean and all filesystem
operations inside of the local thread store, which pushing the
"fundamental incompatibility" check as early as possible.
2026-04-20 22:39:10 +00:00

112 lines
3.1 KiB
Rust

mod helpers;
mod list_threads;
use async_trait::async_trait;
use crate::AppendThreadItemsParams;
use crate::ArchiveThreadParams;
use crate::CreateThreadParams;
use crate::ListThreadsParams;
use crate::LoadThreadHistoryParams;
use crate::ReadThreadParams;
use crate::ResumeThreadRecorderParams;
use crate::StoredThread;
use crate::StoredThreadHistory;
use crate::ThreadPage;
use crate::ThreadRecorder;
use crate::ThreadStore;
use crate::ThreadStoreError;
use crate::ThreadStoreResult;
use crate::UpdateThreadMetadataParams;
use proto::thread_store_client::ThreadStoreClient;
#[path = "proto/codex.thread_store.v1.rs"]
mod proto;
/// gRPC-backed [`ThreadStore`] implementation for deployments whose durable thread data lives
/// outside the app-server process.
#[derive(Clone, Debug)]
pub struct RemoteThreadStore {
endpoint: String,
}
impl RemoteThreadStore {
pub fn new(endpoint: impl Into<String>) -> Self {
Self {
endpoint: endpoint.into(),
}
}
async fn client(&self) -> ThreadStoreResult<ThreadStoreClient<tonic::transport::Channel>> {
ThreadStoreClient::connect(self.endpoint.clone())
.await
.map_err(|err| ThreadStoreError::Internal {
message: format!("failed to connect to remote thread store: {err}"),
})
}
}
#[async_trait]
impl ThreadStore for RemoteThreadStore {
fn as_any(&self) -> &dyn std::any::Any {
self
}
async fn create_thread(
&self,
_params: CreateThreadParams,
) -> ThreadStoreResult<Box<dyn ThreadRecorder>> {
Err(not_implemented("create_thread"))
}
async fn resume_thread_recorder(
&self,
_params: ResumeThreadRecorderParams,
) -> ThreadStoreResult<Box<dyn ThreadRecorder>> {
Err(not_implemented("resume_thread_recorder"))
}
async fn append_items(&self, _params: AppendThreadItemsParams) -> ThreadStoreResult<()> {
Err(not_implemented("append_items"))
}
async fn load_history(
&self,
_params: LoadThreadHistoryParams,
) -> ThreadStoreResult<StoredThreadHistory> {
Err(not_implemented("load_history"))
}
async fn read_thread(&self, _params: ReadThreadParams) -> ThreadStoreResult<StoredThread> {
Err(not_implemented("read_thread"))
}
async fn list_threads(&self, params: ListThreadsParams) -> ThreadStoreResult<ThreadPage> {
list_threads::list_threads(self, params).await
}
async fn update_thread_metadata(
&self,
_params: UpdateThreadMetadataParams,
) -> ThreadStoreResult<StoredThread> {
Err(not_implemented("update_thread_metadata"))
}
async fn archive_thread(&self, _params: ArchiveThreadParams) -> ThreadStoreResult<()> {
Err(not_implemented("archive_thread"))
}
async fn unarchive_thread(
&self,
_params: ArchiveThreadParams,
) -> ThreadStoreResult<StoredThread> {
Err(not_implemented("unarchive_thread"))
}
}
fn not_implemented(method: &str) -> ThreadStoreError {
ThreadStoreError::Internal {
message: format!("remote thread store does not implement {method} yet"),
}
}