Watch
0
0
Fork
You've already forked hyperhive
0

archetype flows on the board list the agents the router sends to, and the docs say a switch-off key outlives its flow

This commit is contained in:
atlas 2026-11-11 20:45:07 +01:00 • committed by mara
commit 13ff33ead0

View file

@ -20,3 +20,34 @@ pub async fn open_or_create(
)
.await
}
/// The agents of the swarm: the agent names in the bucket's keys
/// (`<hive>.<agent>`), read from the stream's subject list. This is the
/// roster the notification router sends to.
///
/// # Errors
///
/// The bucket's stream cannot be opened or its subjects listed.
#[cfg(feature = "kv")]
pub async fn roster(
client: &async_nats::Client,
) -> Result<std::collections::BTreeSet<String>, Box<dyn std::error::Error + Send + Sync>> {
use futures_util::TryStreamExt as _;
let bucket = swarm_wire::agent_status::BUCKET;
let js = async_nats::jetstream::new(client.clone());
let stream = js.get_stream(format!("KV_{bucket}")).await?;
let subjects: Vec<(String, usize)> = stream
.info_with_subjects(format!("$KV.{bucket}.>"))
.await?
.try_collect()
.await?;
let prefix = format!("$KV.{bucket}.");
Ok(subjects
.into_iter()
.filter_map(|(subject, _)| {
let key = subject.strip_prefix(&prefix)?;
swarm_wire::agent_status::split_key(key).map(|(_, agent)| agent.to_owned())
})
.collect())
}