mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## What changed - Add the experimental `environment/status` request for inspecting a configured environment without starting or reconnecting it. - Report `ready`, `pending`, `disconnected`, or `unknown`, including error details for disconnected and unknown environments. - Probe ready remote environments over their existing exec-server connection. ## Testing - Add an app-server integration test covering local and remote ready, pending, disconnected, and unknown environments. GitOrigin-RevId: 397bba603aa9e0b59008ee6cb7cbde46e357652c
79 lines
2.7 KiB
Rust
79 lines
2.7 KiB
Rust
use super::*;
|
|
use std::time::Duration;
|
|
|
|
#[derive(Clone)]
|
|
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.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()))
|
|
}
|
|
}
|