Download codex-rs/app-server/src/request_processors/environment_processor.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server/src/request_processors/environment_processor.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/app-server/src/request_processors/environment_processor.rs
-
curl -L -o environment_processor.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server/src/request_processors/environment_processor.rs
2.74 kB
| use super::*; | |
| use std::time::Duration; | |
| pub(crate) struct EnvironmentRequestProcessor { | |
| environment_manager: Arc<EnvironmentManager>, | |
| } | |
| impl EnvironmentRequestProcessor { | |
| pub(crate) fn new(environment_manager: Arc<EnvironmentManager>) -> Self { | |
| Self { | |
| environment_manager, | |
| } | |
| } | |
| pub(crate) async fn environment_add( | |
| &self, | |
| params: EnvironmentAddParams, | |
| ) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> { | |
| self.environment_manager | |
| .upsert_environment( | |
| params.environment_id, | |
| params.exec_server_url, | |
| params.connect_timeout_ms.map(Duration::from_millis), | |
| ) | |
| .map_err(|err| invalid_request(err.to_string()))?; | |
| Ok(Some(EnvironmentAddResponse {}.into())) | |
| } | |
| pub(crate) async fn environment_info( | |
| &self, | |
| params: EnvironmentInfoParams, | |
| ) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> { | |
| let environment_id = params.environment_id; | |
| let environment = self | |
| .environment_manager | |
| .get_environment(&environment_id) | |
| .ok_or_else(|| invalid_request(format!("unknown environment id `{environment_id}`")))?; | |
| let info = environment.force_info().await.map_err(|err| { | |
| internal_error(format!( | |
| "failed to get info for environment `{environment_id}`: {err}" | |
| )) | |
| })?; | |
| Ok(Some( | |
| EnvironmentInfoResponse { | |
| shell: EnvironmentShellInfo { | |
| name: info.shell.name, | |
| path: info.shell.path, | |
| }, | |
| cwd: info.cwd, | |
| } | |
| .into(), | |
| )) | |
| } | |
| pub(crate) async fn environment_status( | |
| &self, | |
| params: EnvironmentStatusParams, | |
| ) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> { | |
| let environment_id = params.environment_id; | |
| let (status, error) = match self | |
| .environment_manager | |
| .get_environment_status(&environment_id) | |
| .await | |
| { | |
| Some(EnvironmentObservedStatus::Ready) => (EnvironmentStatusKind::Ready, None), | |
| Some(EnvironmentObservedStatus::Pending) => (EnvironmentStatusKind::Pending, None), | |
| Some(EnvironmentObservedStatus::Disconnected { error }) => { | |
| (EnvironmentStatusKind::Disconnected, Some(error)) | |
| } | |
| None => ( | |
| EnvironmentStatusKind::Unknown, | |
| Some(format!("unknown environment id `{environment_id}`")), | |
| ), | |
| }; | |
| Ok(Some(EnvironmentStatusResponse { status, error }.into())) | |
| } | |
| } | |