From 4980d00b951d450772afc5340e157d7a6e505eeb Mon Sep 17 00:00:00 2001 From: Rasmus Rygaard Date: Thu, 23 Apr 2026 15:38:15 -0700 Subject: [PATCH] Add remote agent graph store implementation --- codex-rs/Cargo.lock | 5 + codex-rs/agent-graph-store/Cargo.toml | 10 + .../examples/generate-proto.rs | 19 + .../scripts/generate-proto.sh | 38 ++ codex-rs/agent-graph-store/src/lib.rs | 2 + .../agent-graph-store/src/remote/AGENTS.md | 13 + .../agent-graph-store/src/remote/helpers.rs | 42 ++ codex-rs/agent-graph-store/src/remote/mod.rs | 339 +++++++++++ .../proto/codex.agent_graph_store.v1.proto | 53 ++ .../proto/codex.agent_graph_store.v1.rs | 569 ++++++++++++++++++ 10 files changed, 1090 insertions(+) create mode 100644 codex-rs/agent-graph-store/examples/generate-proto.rs create mode 100755 codex-rs/agent-graph-store/scripts/generate-proto.sh create mode 100644 codex-rs/agent-graph-store/src/remote/AGENTS.md create mode 100644 codex-rs/agent-graph-store/src/remote/helpers.rs create mode 100644 codex-rs/agent-graph-store/src/remote/mod.rs create mode 100644 codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.proto create mode 100644 codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.rs diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index df938b9c1a..ca7d0f3e6a 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -1756,11 +1756,16 @@ dependencies = [ "codex-protocol", "codex-state", "pretty_assertions", + "prost 0.14.3", "serde", "serde_json", "tempfile", "thiserror 2.0.18", "tokio", + "tokio-stream", + "tonic", + "tonic-prost", + "tonic-prost-build", ] [[package]] diff --git a/codex-rs/agent-graph-store/Cargo.toml b/codex-rs/agent-graph-store/Cargo.toml index e221ef61b2..c4035960ef 100644 --- a/codex-rs/agent-graph-store/Cargo.toml +++ b/codex-rs/agent-graph-store/Cargo.toml @@ -8,6 +8,10 @@ version.workspace = true name = "codex_agent_graph_store" path = "src/lib.rs" +[[example]] +name = "generate-proto" +path = "examples/generate-proto.rs" + [lints] workspace = true @@ -15,11 +19,17 @@ workspace = true async-trait = { workspace = true } codex-protocol = { workspace = true } codex-state = { workspace = true } +prost = "0.14.3" serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } +tonic = { workspace = true } +tonic-prost = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } serde_json = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } +tokio-stream = { workspace = true, features = ["net"] } +tonic = { workspace = true, features = ["router", "transport"] } +tonic-prost-build = { version = "=0.14.3", default-features = false, features = ["transport"] } diff --git a/codex-rs/agent-graph-store/examples/generate-proto.rs b/codex-rs/agent-graph-store/examples/generate-proto.rs new file mode 100644 index 0000000000..f79feb90e2 --- /dev/null +++ b/codex-rs/agent-graph-store/examples/generate-proto.rs @@ -0,0 +1,19 @@ +use std::path::PathBuf; + +fn main() -> Result<(), Box> { + let Some(proto_dir_arg) = std::env::args().nth(1) else { + eprintln!("Usage: generate-proto "); + std::process::exit(1); + }; + + let proto_dir = PathBuf::from(proto_dir_arg); + let proto_file = proto_dir.join("codex.agent_graph_store.v1.proto"); + + tonic_prost_build::configure() + .build_client(true) + .build_server(true) + .out_dir(&proto_dir) + .compile_protos(&[proto_file], &[proto_dir])?; + + Ok(()) +} diff --git a/codex-rs/agent-graph-store/scripts/generate-proto.sh b/codex-rs/agent-graph-store/scripts/generate-proto.sh new file mode 100755 index 0000000000..270ed5c226 --- /dev/null +++ b/codex-rs/agent-graph-store/scripts/generate-proto.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +repo_root="$(cd "$script_dir/../../.." && pwd)" +proto_dir="$repo_root/codex-rs/agent-graph-store/src/remote/proto" +generated="$proto_dir/codex.agent_graph_store.v1.rs" +tmpdir="$(mktemp -d)" + +cleanup() { + rm -rf "$tmpdir" +} +trap cleanup EXIT + +( + cd "$repo_root/codex-rs" + CARGO_TARGET_DIR="$tmpdir/target" cargo run \ + -p codex-agent-graph-store \ + --example generate-proto \ + -- "$proto_dir" +) + +if ! sed -n '2p' "$generated" | grep -q 'clippy::trivially_copy_pass_by_ref'; then + { + sed -n '1p' "$generated" + printf '#![allow(clippy::trivially_copy_pass_by_ref)]\n' + sed '1d' "$generated" + } > "$tmpdir/generated.rs" + mv "$tmpdir/generated.rs" "$generated" +fi + +rustfmt --edition 2024 "$generated" + +awk ' + NR == 3 && previous ~ /clippy::trivially_copy_pass_by_ref/ && $0 != "" { print "" } + { print; previous = $0 } +' "$generated" > "$tmpdir/formatted.rs" +mv "$tmpdir/formatted.rs" "$generated" diff --git a/codex-rs/agent-graph-store/src/lib.rs b/codex-rs/agent-graph-store/src/lib.rs index 72e8b45e84..cd7a8c48e0 100644 --- a/codex-rs/agent-graph-store/src/lib.rs +++ b/codex-rs/agent-graph-store/src/lib.rs @@ -2,11 +2,13 @@ mod error; mod local; +mod remote; mod store; mod types; pub use error::AgentGraphStoreError; pub use error::AgentGraphStoreResult; pub use local::LocalAgentGraphStore; +pub use remote::RemoteAgentGraphStore; pub use store::AgentGraphStore; pub use types::ThreadSpawnEdgeStatus; diff --git a/codex-rs/agent-graph-store/src/remote/AGENTS.md b/codex-rs/agent-graph-store/src/remote/AGENTS.md new file mode 100644 index 0000000000..48a82ce2f4 --- /dev/null +++ b/codex-rs/agent-graph-store/src/remote/AGENTS.md @@ -0,0 +1,13 @@ +# Remote Agent Graph Store + +- The Rust protobuf output in `proto/codex.agent_graph_store.v1.rs` is checked in. +- Do not add build-time protobuf generation to `codex-agent-graph-store` unless the Bazel/Cargo story is intentionally changed. +- When `proto/codex.agent_graph_store.v1.proto` changes, regenerate the Rust file manually and include both files in the same commit. + +Run this from the repository root: + +```sh +./codex-rs/agent-graph-store/scripts/generate-proto.sh +``` + +The command requires `protoc` to be available on `PATH`. diff --git a/codex-rs/agent-graph-store/src/remote/helpers.rs b/codex-rs/agent-graph-store/src/remote/helpers.rs new file mode 100644 index 0000000000..a45f7c7573 --- /dev/null +++ b/codex-rs/agent-graph-store/src/remote/helpers.rs @@ -0,0 +1,42 @@ +use codex_protocol::ThreadId; + +use super::proto; +use crate::AgentGraphStoreError; +use crate::AgentGraphStoreResult; +use crate::ThreadSpawnEdgeStatus; + +pub(super) fn proto_status(status: ThreadSpawnEdgeStatus) -> proto::ThreadSpawnEdgeStatus { + match status { + ThreadSpawnEdgeStatus::Open => proto::ThreadSpawnEdgeStatus::Open, + ThreadSpawnEdgeStatus::Closed => proto::ThreadSpawnEdgeStatus::Closed, + } +} + +pub(super) fn proto_status_filter(status: Option) -> Option { + status.map(proto_status).map(Into::into) +} + +pub(super) fn thread_ids_from_proto( + thread_ids: Vec, + field_name: &str, +) -> AgentGraphStoreResult> { + thread_ids + .into_iter() + .map(|thread_id| { + ThreadId::from_string(&thread_id).map_err(|err| AgentGraphStoreError::InvalidRequest { + message: format!("remote agent graph store returned invalid {field_name}: {err}"), + }) + }) + .collect() +} + +pub(super) fn remote_status_to_error(status: tonic::Status) -> AgentGraphStoreError { + match status.code() { + tonic::Code::InvalidArgument => AgentGraphStoreError::InvalidRequest { + message: status.message().to_string(), + }, + _ => AgentGraphStoreError::Internal { + message: format!("remote agent graph store request failed: {status}"), + }, + } +} diff --git a/codex-rs/agent-graph-store/src/remote/mod.rs b/codex-rs/agent-graph-store/src/remote/mod.rs new file mode 100644 index 0000000000..859102dd80 --- /dev/null +++ b/codex-rs/agent-graph-store/src/remote/mod.rs @@ -0,0 +1,339 @@ +mod helpers; + +use async_trait::async_trait; +use codex_protocol::ThreadId; +use proto::agent_graph_store_client::AgentGraphStoreClient; + +use crate::AgentGraphStore; +use crate::AgentGraphStoreError; +use crate::AgentGraphStoreResult; +use crate::ThreadSpawnEdgeStatus; + +#[path = "proto/codex.agent_graph_store.v1.rs"] +mod proto; + +/// gRPC-backed [`AgentGraphStore`] implementation for deployments whose durable +/// subagent graph lives outside the app-server process. +#[derive(Clone, Debug)] +pub struct RemoteAgentGraphStore { + endpoint: String, +} + +impl RemoteAgentGraphStore { + pub fn new(endpoint: impl Into) -> Self { + Self { + endpoint: endpoint.into(), + } + } + + async fn client( + &self, + ) -> AgentGraphStoreResult> { + AgentGraphStoreClient::connect(self.endpoint.clone()) + .await + .map_err(|err| AgentGraphStoreError::Internal { + message: format!("failed to connect to remote agent graph store: {err}"), + }) + } +} + +#[async_trait] +impl AgentGraphStore for RemoteAgentGraphStore { + async fn upsert_thread_spawn_edge( + &self, + parent_thread_id: ThreadId, + child_thread_id: ThreadId, + status: ThreadSpawnEdgeStatus, + ) -> AgentGraphStoreResult<()> { + let request = proto::UpsertThreadSpawnEdgeRequest { + parent_thread_id: parent_thread_id.to_string(), + child_thread_id: child_thread_id.to_string(), + status: helpers::proto_status(status).into(), + }; + self.client() + .await? + .upsert_thread_spawn_edge(request) + .await + .map_err(helpers::remote_status_to_error)?; + Ok(()) + } + + async fn set_thread_spawn_edge_status( + &self, + child_thread_id: ThreadId, + status: ThreadSpawnEdgeStatus, + ) -> AgentGraphStoreResult<()> { + let request = proto::SetThreadSpawnEdgeStatusRequest { + child_thread_id: child_thread_id.to_string(), + status: helpers::proto_status(status).into(), + }; + self.client() + .await? + .set_thread_spawn_edge_status(request) + .await + .map_err(helpers::remote_status_to_error)?; + Ok(()) + } + + async fn list_thread_spawn_children( + &self, + parent_thread_id: ThreadId, + status_filter: Option, + ) -> AgentGraphStoreResult> { + let response = self + .client() + .await? + .list_thread_spawn_children(proto::ListThreadSpawnChildrenRequest { + parent_thread_id: parent_thread_id.to_string(), + status_filter: helpers::proto_status_filter(status_filter), + }) + .await + .map_err(helpers::remote_status_to_error)? + .into_inner(); + helpers::thread_ids_from_proto(response.thread_ids, "child thread_id") + } + + async fn list_thread_spawn_descendants( + &self, + root_thread_id: ThreadId, + status_filter: Option, + ) -> AgentGraphStoreResult> { + let response = self + .client() + .await? + .list_thread_spawn_descendants(proto::ListThreadSpawnDescendantsRequest { + root_thread_id: root_thread_id.to_string(), + status_filter: helpers::proto_status_filter(status_filter), + }) + .await + .map_err(helpers::remote_status_to_error)? + .into_inner(); + helpers::thread_ids_from_proto(response.thread_ids, "descendant thread_id") + } +} + +#[cfg(test)] +mod tests { + use super::proto; + use super::proto::agent_graph_store_server; + use super::proto::agent_graph_store_server::AgentGraphStoreServer; + use super::*; + use pretty_assertions::assert_eq; + use tonic::Request; + use tonic::Response; + use tonic::Status; + use tonic::transport::Server; + + fn thread_id(suffix: u128) -> ThreadId { + ThreadId::from_string(&format!("00000000-0000-0000-0000-{suffix:012}")) + .expect("valid thread id") + } + + async fn serve_test_server(server: TestServer) -> (RemoteAgentGraphStore, ServerShutdown) { + let listener = tokio::net::TcpListener::bind("127.0.0.1:0") + .await + .expect("bind test server"); + let addr = listener.local_addr().expect("test server addr"); + let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel(); + let handle = tokio::spawn(async move { + Server::builder() + .add_service(AgentGraphStoreServer::new(server)) + .serve_with_incoming_shutdown( + tokio_stream::wrappers::TcpListenerStream::new(listener), + async { + let _ = shutdown_rx.await; + }, + ) + .await + }); + + ( + RemoteAgentGraphStore::new(format!("http://{addr}")), + ServerShutdown { + shutdown_tx, + handle, + }, + ) + } + + struct ServerShutdown { + shutdown_tx: tokio::sync::oneshot::Sender<()>, + handle: tokio::task::JoinHandle>, + } + + impl ServerShutdown { + async fn shutdown(self) { + let _ = self.shutdown_tx.send(()); + self.handle.await.expect("join server").expect("server"); + } + } + + #[derive(Clone, Copy, Debug)] + enum TestServer { + HappyPath, + InvalidThreadIdResponse, + InvalidArgumentStatus, + } + + #[tonic::async_trait] + impl agent_graph_store_server::AgentGraphStore for TestServer { + async fn upsert_thread_spawn_edge( + &self, + request: Request, + ) -> Result, Status> { + match self { + TestServer::InvalidArgumentStatus => { + Err(Status::invalid_argument("status must be specified")) + } + TestServer::HappyPath | TestServer::InvalidThreadIdResponse => { + let request = request.into_inner(); + assert_eq!( + request.parent_thread_id, + "00000000-0000-0000-0000-000000000001" + ); + assert_eq!( + request.child_thread_id, + "00000000-0000-0000-0000-000000000002" + ); + assert_eq!( + proto::ThreadSpawnEdgeStatus::try_from(request.status), + Ok(proto::ThreadSpawnEdgeStatus::Open) + ); + Ok(Response::new(proto::Empty {})) + } + } + } + + async fn set_thread_spawn_edge_status( + &self, + request: Request, + ) -> Result, Status> { + let request = request.into_inner(); + assert_eq!( + request.child_thread_id, + "00000000-0000-0000-0000-000000000002" + ); + assert_eq!( + proto::ThreadSpawnEdgeStatus::try_from(request.status), + Ok(proto::ThreadSpawnEdgeStatus::Closed) + ); + Ok(Response::new(proto::Empty {})) + } + + async fn list_thread_spawn_children( + &self, + request: Request, + ) -> Result, Status> { + let request = request.into_inner(); + assert_eq!( + request.parent_thread_id, + "00000000-0000-0000-0000-000000000001" + ); + assert_eq!( + request + .status_filter + .map(proto::ThreadSpawnEdgeStatus::try_from), + Some(Ok(proto::ThreadSpawnEdgeStatus::Open)) + ); + let thread_ids = match self { + TestServer::InvalidThreadIdResponse => vec!["not-a-thread-id".to_string()], + TestServer::HappyPath | TestServer::InvalidArgumentStatus => { + vec![ + "00000000-0000-0000-0000-000000000002".to_string(), + "00000000-0000-0000-0000-000000000003".to_string(), + ] + } + }; + Ok(Response::new(proto::ListThreadSpawnChildrenResponse { + thread_ids, + })) + } + + async fn list_thread_spawn_descendants( + &self, + request: Request, + ) -> Result, Status> { + let request = request.into_inner(); + assert_eq!( + request.root_thread_id, + "00000000-0000-0000-0000-000000000001" + ); + assert_eq!(request.status_filter, None); + Ok(Response::new(proto::ListThreadSpawnDescendantsResponse { + thread_ids: vec![ + "00000000-0000-0000-0000-000000000002".to_string(), + "00000000-0000-0000-0000-000000000003".to_string(), + "00000000-0000-0000-0000-000000000004".to_string(), + ], + })) + } + } + + #[tokio::test] + async fn remote_store_calls_agent_graph_service() { + let (store, shutdown) = serve_test_server(TestServer::HappyPath).await; + let parent_thread_id = thread_id(1); + let child_thread_id = thread_id(2); + + store + .upsert_thread_spawn_edge( + parent_thread_id, + child_thread_id, + ThreadSpawnEdgeStatus::Open, + ) + .await + .expect("upsert should succeed"); + store + .set_thread_spawn_edge_status(child_thread_id, ThreadSpawnEdgeStatus::Closed) + .await + .expect("status update should succeed"); + + let children = store + .list_thread_spawn_children(parent_thread_id, Some(ThreadSpawnEdgeStatus::Open)) + .await + .expect("children should load"); + assert_eq!(children, vec![thread_id(2), thread_id(3)]); + + let descendants = store + .list_thread_spawn_descendants(parent_thread_id, None) + .await + .expect("descendants should load"); + assert_eq!(descendants, vec![thread_id(2), thread_id(3), thread_id(4)]); + + shutdown.shutdown().await; + } + + #[tokio::test] + async fn remote_store_maps_invalid_response_thread_id_to_invalid_request() { + let (store, shutdown) = serve_test_server(TestServer::InvalidThreadIdResponse).await; + + let err = store + .list_thread_spawn_children(thread_id(1), Some(ThreadSpawnEdgeStatus::Open)) + .await + .expect_err("invalid response thread id should fail"); + + assert!(matches!( + err, + AgentGraphStoreError::InvalidRequest { message } if message.contains("invalid child thread_id") + )); + + shutdown.shutdown().await; + } + + #[tokio::test] + async fn remote_store_maps_invalid_argument_status_to_invalid_request() { + let (store, shutdown) = serve_test_server(TestServer::InvalidArgumentStatus).await; + + let err = store + .upsert_thread_spawn_edge(thread_id(1), thread_id(2), ThreadSpawnEdgeStatus::Open) + .await + .expect_err("invalid argument should fail"); + + assert!(matches!( + err, + AgentGraphStoreError::InvalidRequest { message } if message == "status must be specified" + )); + + shutdown.shutdown().await; + } +} diff --git a/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.proto b/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.proto new file mode 100644 index 0000000000..256f5fde9e --- /dev/null +++ b/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; + +package codex.agent_graph_store.v1; + +service AgentGraphStore { + rpc UpsertThreadSpawnEdge(UpsertThreadSpawnEdgeRequest) returns (Empty); + rpc SetThreadSpawnEdgeStatus(SetThreadSpawnEdgeStatusRequest) returns (Empty); + rpc ListThreadSpawnChildren(ListThreadSpawnChildrenRequest) returns (ListThreadSpawnChildrenResponse); + rpc ListThreadSpawnDescendants(ListThreadSpawnDescendantsRequest) returns (ListThreadSpawnDescendantsResponse); +} + +message Empty {} + +message UpsertThreadSpawnEdgeRequest { + string parent_thread_id = 1; + string child_thread_id = 2; + // Servers must reject THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED. + ThreadSpawnEdgeStatus status = 3; +} + +message SetThreadSpawnEdgeStatusRequest { + string child_thread_id = 1; + // Servers must reject THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED. + ThreadSpawnEdgeStatus status = 2; +} + +message ListThreadSpawnChildrenRequest { + string parent_thread_id = 1; + // Absent means all statuses. + optional ThreadSpawnEdgeStatus status_filter = 2; +} + +message ListThreadSpawnChildrenResponse { + // Ordered child thread ids. + repeated string thread_ids = 1; +} + +message ListThreadSpawnDescendantsRequest { + string root_thread_id = 1; + // Absent means all statuses. + optional ThreadSpawnEdgeStatus status_filter = 2; +} + +message ListThreadSpawnDescendantsResponse { + // Ordered descendant thread ids. + repeated string thread_ids = 1; +} + +enum ThreadSpawnEdgeStatus { + THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED = 0; + THREAD_SPAWN_EDGE_STATUS_OPEN = 1; + THREAD_SPAWN_EDGE_STATUS_CLOSED = 2; +} diff --git a/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.rs b/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.rs new file mode 100644 index 0000000000..9df0204a93 --- /dev/null +++ b/codex-rs/agent-graph-store/src/remote/proto/codex.agent_graph_store.v1.rs @@ -0,0 +1,569 @@ +// This file is @generated by prost-build. +#![allow(clippy::trivially_copy_pass_by_ref)] + +#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)] +pub struct Empty {} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct UpsertThreadSpawnEdgeRequest { + #[prost(string, tag = "1")] + pub parent_thread_id: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub child_thread_id: ::prost::alloc::string::String, + /// Servers must reject THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED. + #[prost(enumeration = "ThreadSpawnEdgeStatus", tag = "3")] + pub status: i32, +} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct SetThreadSpawnEdgeStatusRequest { + #[prost(string, tag = "1")] + pub child_thread_id: ::prost::alloc::string::String, + /// Servers must reject THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED. + #[prost(enumeration = "ThreadSpawnEdgeStatus", tag = "2")] + pub status: i32, +} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct ListThreadSpawnChildrenRequest { + #[prost(string, tag = "1")] + pub parent_thread_id: ::prost::alloc::string::String, + /// Absent means all statuses. + #[prost(enumeration = "ThreadSpawnEdgeStatus", optional, tag = "2")] + pub status_filter: ::core::option::Option, +} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct ListThreadSpawnChildrenResponse { + /// Ordered child thread ids. + #[prost(string, repeated, tag = "1")] + pub thread_ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, +} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct ListThreadSpawnDescendantsRequest { + #[prost(string, tag = "1")] + pub root_thread_id: ::prost::alloc::string::String, + /// Absent means all statuses. + #[prost(enumeration = "ThreadSpawnEdgeStatus", optional, tag = "2")] + pub status_filter: ::core::option::Option, +} +#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] +pub struct ListThreadSpawnDescendantsResponse { + /// Ordered descendant thread ids. + #[prost(string, repeated, tag = "1")] + pub thread_ids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum ThreadSpawnEdgeStatus { + Unspecified = 0, + Open = 1, + Closed = 2, +} +impl ThreadSpawnEdgeStatus { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Unspecified => "THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED", + Self::Open => "THREAD_SPAWN_EDGE_STATUS_OPEN", + Self::Closed => "THREAD_SPAWN_EDGE_STATUS_CLOSED", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "THREAD_SPAWN_EDGE_STATUS_UNSPECIFIED" => Some(Self::Unspecified), + "THREAD_SPAWN_EDGE_STATUS_OPEN" => Some(Self::Open), + "THREAD_SPAWN_EDGE_STATUS_CLOSED" => Some(Self::Closed), + _ => None, + } + } +} +/// Generated client implementations. +pub mod agent_graph_store_client { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value + )] + use tonic::codegen::http::Uri; + use tonic::codegen::*; + #[derive(Debug, Clone)] + pub struct AgentGraphStoreClient { + inner: tonic::client::Grpc, + } + impl AgentGraphStoreClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl AgentGraphStoreClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> AgentGraphStoreClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + >>::Error: + Into + std::marker::Send + std::marker::Sync, + { + AgentGraphStoreClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn upsert_thread_spawn_edge( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner.ready().await.map_err(|e| { + tonic::Status::unknown(format!("Service was not ready: {}", e.into())) + })?; + let codec = tonic_prost::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/codex.agent_graph_store.v1.AgentGraphStore/UpsertThreadSpawnEdge", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new( + "codex.agent_graph_store.v1.AgentGraphStore", + "UpsertThreadSpawnEdge", + )); + self.inner.unary(req, path, codec).await + } + pub async fn set_thread_spawn_edge_status( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner.ready().await.map_err(|e| { + tonic::Status::unknown(format!("Service was not ready: {}", e.into())) + })?; + let codec = tonic_prost::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/codex.agent_graph_store.v1.AgentGraphStore/SetThreadSpawnEdgeStatus", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new( + "codex.agent_graph_store.v1.AgentGraphStore", + "SetThreadSpawnEdgeStatus", + )); + self.inner.unary(req, path, codec).await + } + pub async fn list_thread_spawn_children( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner.ready().await.map_err(|e| { + tonic::Status::unknown(format!("Service was not ready: {}", e.into())) + })?; + let codec = tonic_prost::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/codex.agent_graph_store.v1.AgentGraphStore/ListThreadSpawnChildren", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new( + "codex.agent_graph_store.v1.AgentGraphStore", + "ListThreadSpawnChildren", + )); + self.inner.unary(req, path, codec).await + } + pub async fn list_thread_spawn_descendants( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner.ready().await.map_err(|e| { + tonic::Status::unknown(format!("Service was not ready: {}", e.into())) + })?; + let codec = tonic_prost::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/codex.agent_graph_store.v1.AgentGraphStore/ListThreadSpawnDescendants", + ); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new( + "codex.agent_graph_store.v1.AgentGraphStore", + "ListThreadSpawnDescendants", + )); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod agent_graph_store_server { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value + )] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with AgentGraphStoreServer. + #[async_trait] + pub trait AgentGraphStore: std::marker::Send + std::marker::Sync + 'static { + async fn upsert_thread_spawn_edge( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; + async fn set_thread_spawn_edge_status( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; + async fn list_thread_spawn_children( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn list_thread_spawn_descendants( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + #[derive(Debug)] + pub struct AgentGraphStoreServer { + inner: Arc, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + impl AgentGraphStoreServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for AgentGraphStoreServer + where + T: AgentGraphStore, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + match req.uri().path() { + "/codex.agent_graph_store.v1.AgentGraphStore/UpsertThreadSpawnEdge" => { + #[allow(non_camel_case_types)] + struct UpsertThreadSpawnEdgeSvc(pub Arc); + impl + tonic::server::UnaryService + for UpsertThreadSpawnEdgeSvc + { + type Response = super::Empty; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::upsert_thread_spawn_edge(&inner, request) + .await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = UpsertThreadSpawnEdgeSvc(inner); + let codec = tonic_prost::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/codex.agent_graph_store.v1.AgentGraphStore/SetThreadSpawnEdgeStatus" => { + #[allow(non_camel_case_types)] + struct SetThreadSpawnEdgeStatusSvc(pub Arc); + impl + tonic::server::UnaryService + for SetThreadSpawnEdgeStatusSvc + { + type Response = super::Empty; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::set_thread_spawn_edge_status( + &inner, request, + ) + .await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = SetThreadSpawnEdgeStatusSvc(inner); + let codec = tonic_prost::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/codex.agent_graph_store.v1.AgentGraphStore/ListThreadSpawnChildren" => { + #[allow(non_camel_case_types)] + struct ListThreadSpawnChildrenSvc(pub Arc); + impl + tonic::server::UnaryService + for ListThreadSpawnChildrenSvc + { + type Response = super::ListThreadSpawnChildrenResponse; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::list_thread_spawn_children(&inner, request) + .await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = ListThreadSpawnChildrenSvc(inner); + let codec = tonic_prost::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/codex.agent_graph_store.v1.AgentGraphStore/ListThreadSpawnDescendants" => { + #[allow(non_camel_case_types)] + struct ListThreadSpawnDescendantsSvc(pub Arc); + impl + tonic::server::UnaryService + for ListThreadSpawnDescendantsSvc + { + type Response = super::ListThreadSpawnDescendantsResponse; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::list_thread_spawn_descendants( + &inner, request, + ) + .await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = ListThreadSpawnDescendantsSvc(inner); + let codec = tonic_prost::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => Box::pin(async move { + let mut response = http::Response::new(tonic::body::Body::default()); + let headers = response.headers_mut(); + headers.insert( + tonic::Status::GRPC_STATUS, + (tonic::Code::Unimplemented as i32).into(), + ); + headers.insert( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ); + Ok(response) + }), + } + } + } + impl Clone for AgentGraphStoreServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "codex.agent_graph_store.v1.AgentGraphStore"; + impl tonic::server::NamedService for AgentGraphStoreServer { + const NAME: &'static str = SERVICE_NAME; + } +}