Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions codex-rs/exec-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ reqwest = { workspace = true, features = ["json", "rustls-tls", "stream"] }
prost = "0.14.3"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha2 = { workspace = true }
zeroize = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
tokio = { workspace = true, features = [
Expand Down
60 changes: 60 additions & 0 deletions codex-rs/exec-server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ use crate::protocol::ExecExitedNotification;
use crate::protocol::ExecOutputDeltaNotification;
use crate::protocol::ExecParams;
use crate::protocol::ExecResponse;
use crate::protocol::FILE_TRANSFER_CANCEL_METHOD;
use crate::protocol::FILE_TRANSFER_PREPARE_UPLOAD_METHOD;
use crate::protocol::FILE_TRANSFER_STATUS_METHOD;
use crate::protocol::FS_CANONICALIZE_METHOD;
use crate::protocol::FS_CLOSE_METHOD;
use crate::protocol::FS_COPY_METHOD;
Expand All @@ -59,6 +62,12 @@ use crate::protocol::FS_READ_DIRECTORY_METHOD;
use crate::protocol::FS_READ_FILE_METHOD;
use crate::protocol::FS_REMOVE_METHOD;
use crate::protocol::FS_WRITE_FILE_METHOD;
use crate::protocol::FileTransferCancelParams;
use crate::protocol::FileTransferCancelResponse;
use crate::protocol::FileTransferPrepareUploadParams;
use crate::protocol::FileTransferPrepareUploadResponse;
use crate::protocol::FileTransferStatusParams;
use crate::protocol::FileTransferStatusResponse;
use crate::protocol::FsCanonicalizeParams;
use crate::protocol::FsCanonicalizeResponse;
use crate::protocol::FsCloseParams;
Expand Down Expand Up @@ -406,6 +415,27 @@ impl LazyRemoteExecServerClient {
pub(crate) async fn environment_info(&self) -> Result<EnvironmentInfo, ExecServerError> {
self.get().await?.environment_info().await
}

pub(crate) async fn file_transfer_prepare_upload(
&self,
params: FileTransferPrepareUploadParams,
) -> Result<FileTransferPrepareUploadResponse, ExecServerError> {
self.get().await?.file_transfer_prepare_upload(params).await
}

pub(crate) async fn file_transfer_status(
&self,
transfer_id: String,
) -> Result<FileTransferStatusResponse, ExecServerError> {
self.get().await?.file_transfer_status(transfer_id).await
}

pub(crate) async fn file_transfer_cancel(
&self,
transfer_id: String,
) -> Result<FileTransferCancelResponse, ExecServerError> {
self.get().await?.file_transfer_cancel(transfer_id).await
}
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -509,6 +539,36 @@ impl ExecServerClient {
self.call(ENVIRONMENT_INFO_METHOD, &()).await
}

pub async fn file_transfer_prepare_upload(
&self,
params: FileTransferPrepareUploadParams,
) -> Result<FileTransferPrepareUploadResponse, ExecServerError> {
self.call(FILE_TRANSFER_PREPARE_UPLOAD_METHOD, &params)
.await
}

pub async fn file_transfer_status(
&self,
transfer_id: String,
) -> Result<FileTransferStatusResponse, ExecServerError> {
self.call(
FILE_TRANSFER_STATUS_METHOD,
&FileTransferStatusParams { transfer_id },
)
.await
}

pub async fn file_transfer_cancel(
&self,
transfer_id: String,
) -> Result<FileTransferCancelResponse, ExecServerError> {
self.call(
FILE_TRANSFER_CANCEL_METHOD,
&FileTransferCancelParams { transfer_id },
)
.await
}

pub async fn read(&self, params: ReadParams) -> Result<ReadResponse, ExecServerError> {
self.call(EXEC_READ_METHOD, &params).await
}
Expand Down
40 changes: 40 additions & 0 deletions codex-rs/exec-server/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ use crate::local_process::LocalProcess;
use crate::process::ExecBackend;
use crate::protocol::EnvironmentCapabilities;
use crate::protocol::EnvironmentInfo;
use crate::protocol::FileTransferCancelResponse;
use crate::protocol::FileTransferPrepareUploadParams;
use crate::protocol::FileTransferPrepareUploadResponse;
use crate::protocol::FileTransferStatusResponse;
use crate::protocol::ShellInfo;
use crate::remote::NoiseRendezvousEnvironmentConfig;
use crate::remote_file_system::RemoteFileSystem;
Expand Down Expand Up @@ -562,6 +566,42 @@ impl Environment {
}
}

pub async fn file_transfer_prepare_upload(
&self,
params: FileTransferPrepareUploadParams,
) -> Result<FileTransferPrepareUploadResponse, ExecServerError> {
let client = self.remote_client.as_ref().ok_or_else(|| {
ExecServerError::Protocol(
"executor-owned file transfer requires a remote environment".to_string(),
)
})?;
client.file_transfer_prepare_upload(params).await
}

pub async fn file_transfer_status(
&self,
transfer_id: String,
) -> Result<FileTransferStatusResponse, ExecServerError> {
let client = self.remote_client.as_ref().ok_or_else(|| {
ExecServerError::Protocol(
"executor-owned file transfer requires a remote environment".to_string(),
)
})?;
client.file_transfer_status(transfer_id).await
}

pub async fn file_transfer_cancel(
&self,
transfer_id: String,
) -> Result<FileTransferCancelResponse, ExecServerError> {
let client = self.remote_client.as_ref().ok_or_else(|| {
ExecServerError::Protocol(
"executor-owned file transfer requires a remote environment".to_string(),
)
})?;
client.file_transfer_cancel(transfer_id).await
}

/// Starts connecting a remote environment without waiting for it.
/// Requires an active Tokio runtime when background startup is supported.
pub fn start_connecting(&self) {
Expand Down
1 change: 1 addition & 0 deletions codex-rs/exec-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub use protocol::WriteResponse;
pub use protocol::WriteStatus;
pub use remote::RemoteEnvironmentConfig;
pub use remote::run_remote_environment;
pub use rpc::FILE_TRANSFER_SESSION_LOST_ERROR_CODE;
pub use runtime_paths::ExecServerRuntimePaths;
pub use server::DEFAULT_LISTEN_URL;
pub use server::ExecServerListenUrlParseError;
Expand Down
3 changes: 3 additions & 0 deletions codex-rs/exec-server/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub const FS_COPY_METHOD: &str = "fs/copy";
pub const HTTP_REQUEST_METHOD: &str = "http/request";
/// JSON-RPC notification method for streamed executor HTTP response bodies.
pub const HTTP_REQUEST_BODY_DELTA_METHOD: &str = "http/request/bodyDelta";
pub const FILE_TRANSFER_PREPARE_UPLOAD_METHOD: &str = "fileTransfer/prepareUpload";
pub const FILE_TRANSFER_STATUS_METHOD: &str = "fileTransfer/status";
pub const FILE_TRANSFER_CANCEL_METHOD: &str = "fileTransfer/cancel";

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
Expand Down
9 changes: 9 additions & 0 deletions codex-rs/exec-server/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::connection::JsonRpcConnectionEvent;
use crate::connection::JsonRpcTransport;

pub(crate) const SESSION_ALREADY_ATTACHED_ERROR_CODE: i64 = -32010;
pub const FILE_TRANSFER_SESSION_LOST_ERROR_CODE: i64 = -32011;

#[derive(Debug)]
pub(crate) enum RpcCallError {
Expand Down Expand Up @@ -440,6 +441,14 @@ pub(crate) fn session_already_attached(message: String) -> JSONRPCErrorError {
}
}

pub(crate) fn file_transfer_session_lost(message: String) -> JSONRPCErrorError {
JSONRPCErrorError {
code: FILE_TRANSFER_SESSION_LOST_ERROR_CODE,
data: None,
message,
}
}

pub(crate) fn method_not_found(message: String) -> JSONRPCErrorError {
JSONRPCErrorError {
code: -32601,
Expand Down
1 change: 1 addition & 0 deletions codex-rs/exec-server/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod file_system_handler;
mod file_transfer_handler;
mod handler;
mod process_handler;
mod processor;
Expand Down
Loading
Loading