use std::fmt;
use agent_sdk_core::{IsolationClass, IsolationRuntimeRef};
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum EnvironmentRuntime {
#[serde(rename = "runtime:local.container")]
LocalContainer,
#[serde(rename = "runtime:local.sandbox")]
LocalSandbox,
#[serde(rename = "runtime:local.lightweight_vm")]
LocalLightweightVm,
#[serde(rename = "runtime:remote.sandbox")]
RemoteSandbox,
#[serde(rename = "runtime:local.host_process")]
LocalHostProcess,
}
impl EnvironmentRuntime {
pub fn as_str(self) -> &'static str {
match self {
Self::LocalContainer => "runtime:local.container",
Self::LocalSandbox => "runtime:local.sandbox",
Self::LocalLightweightVm => "runtime:local.lightweight_vm",
Self::RemoteSandbox => "runtime:remote.sandbox",
Self::LocalHostProcess => "runtime:local.host_process",
}
}
pub fn isolation_class(self) -> IsolationClass {
match self {
Self::LocalContainer => IsolationClass::Container,
Self::LocalSandbox => IsolationClass::Sandbox,
Self::LocalLightweightVm => IsolationClass::LightweightVm,
Self::RemoteSandbox => IsolationClass::RemoteSandbox,
Self::LocalHostProcess => IsolationClass::HostProcess,
}
}
pub fn runtime_ref(self) -> IsolationRuntimeRef {
IsolationRuntimeRef::new(self.as_str())
}
}
impl fmt::Display for EnvironmentRuntime {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
impl From<EnvironmentRuntime> for IsolationRuntimeRef {
fn from(runtime: EnvironmentRuntime) -> Self {
runtime.runtime_ref()
}
}