Skip to main content

agentmux_srv_core/backend/container_status/
source.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The real [`Source`]: the container runtime this srv found (Docker or Podman), through the same
5//! self-healing handle every container start uses.
6
7use std::sync::Arc;
8
9use futures_util::stream::BoxStream;
10
11use super::{DockerEvent, Listed, Probe, Source};
12use crate::backend::container::ContainerRuntimeHandle;
13
14pub struct DockerSource {
15    handle: Arc<ContainerRuntimeHandle>,
16}
17
18impl DockerSource {
19    pub fn new(handle: Arc<ContainerRuntimeHandle>) -> Self {
20        Self { handle }
21    }
22}
23
24impl Source for DockerSource {
25    async fn ping(&self) -> Probe {
26        probe_of(&self.handle).await
27    }
28
29    async fn list(&self) -> Result<Vec<Listed>, String> {
30        let manager = self.handle.get().await.ok_or("no container runtime")?;
31        manager.agent_containers().await.map_err(|e| e.to_string())
32    }
33
34    async fn events(&self) -> Result<BoxStream<'static, Result<DockerEvent, String>>, String> {
35        let manager = self.handle.get().await.ok_or("no container runtime")?;
36        Ok(manager.agent_container_events())
37    }
38}
39
40/// A live look at the runtime: the fields `containerruntimeavailable` answers.
41pub async fn probe_of(handle: &ContainerRuntimeHandle) -> Probe {
42    let available = handle.is_available().await;
43    Probe {
44        available,
45        runtime: if available { handle.runtime_label().await } else { None },
46        detail: if available { None } else { handle.missing_message() },
47    }
48}