Watch
0
0
Fork
You've already forked hyperhive
0

agent_permissions, agent_term and subagent_term take their wire contracts from swarm-wire

This commit is contained in:
atlas 2026-10-18 23:37:05 +02:00 • committed by mara
commit 839efd1642
27 changed files with 661 additions and 607 deletions

View file

@ -9,7 +9,7 @@
//! **Replay, then the live tail, through one consumer.** `hive-agent`
//! publishes each already-classified `TermMsg` row to the core subject
//! `$SWARM.term.{agent}`, and the stream `term-main-{agent}`
//! (`swarm_queue_client::agent_term`) keeps them. The handler creates an
//! (`swarm_wire::agent_term`) keeps them. The handler creates an
//! ephemeral consumer on that stream starting at the newest
//! `agent_term::REPLAY_ROWS` rows, so the reader gets those and then every
//! new row, in stream order, with no gap and no duplicate between the two.
@ -35,7 +35,7 @@ use axum::http::HeaderMap;
use axum::response::sse::{Event, KeepAlive, Sse};
use futures_util::stream::BoxStream;
use futures_util::{Stream, StreamExt as _};
use swarm_queue_client::agent_term;
use swarm_wire::agent_term;
use crate::routes::AppState;
@ -121,7 +121,7 @@ pub(crate) async fn stream_agent_term(
let stream = replay_or_live(
&client,
&agent_term::stream_name(&agent),
swarm_queue_client::term_subject(&agent),
swarm_wire::term_subject(&agent),
last_event_id(&headers),
"term",
)
@ -198,8 +198,12 @@ pub(crate) async fn replay(
"term-replay-{}",
deliver_subject.rsplit('.').next().unwrap_or_default()
);
let config =
agent_term::replay_consumer_config(subject.clone(), consumer_name, deliver_subject, start);
let config = swarm_queue_client::agent_term::replay_consumer_config(
subject.clone(),
consumer_name,
deliver_subject,
start,
);
let consumer = stream.create_consumer(config).await.map_err(|e| {
format!(
"creating a consumer on {stream_name}: {}",
@ -301,10 +305,7 @@ mod tests {
async fn publish_rows(client: &async_nats::Client, rows: std::ops::RangeInclusive<u64>) {
for i in rows {
client
.publish(
swarm_queue_client::term_subject(AGENT),
format!("row{i}").into(),
)
.publish(swarm_wire::term_subject(AGENT), format!("row{i}").into())
.await
.expect("publish");
}
@ -335,7 +336,7 @@ mod tests {
replay(
client,
&agent_term::stream_name(AGENT),
swarm_queue_client::term_subject(AGENT),
swarm_wire::term_subject(AGENT),
resume_after,
)
.await
@ -352,7 +353,7 @@ mod tests {
for subagent in ["scout", "builder"] {
client
.publish(
swarm_queue_client::subagent_term::subject(AGENT, subagent),
swarm_wire::subagent_term::subject(AGENT, subagent),
format!("{subagent}{i}").into(),
)
.await
@ -368,8 +369,8 @@ mod tests {
) -> Result<BoxStream<'static, Row>, String> {
replay(
client,
&swarm_queue_client::subagent_term::stream_name(AGENT),
swarm_queue_client::subagent_term::subject(AGENT, "scout"),
&swarm_wire::subagent_term::stream_name(AGENT),
swarm_wire::subagent_term::subject(AGENT, "scout"),
resume_after,
)
.await
@ -413,7 +414,7 @@ mod tests {
let nats = TestNats::start();
let client = nats.client().await;
let stream = agent_term::open_or_create(&client, AGENT)
let stream = swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("the stream");
publish_rows(&client, 1..=3).await;
@ -445,12 +446,12 @@ mod tests {
async fn ensuring_the_terminal_stream_again_leaves_it_as_it_is() {
let nats = TestNats::start();
let client = nats.client().await;
let created = agent_term::open_or_create(&client, AGENT)
let created = swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("the first ensure creates the stream");
publish_rows(&client, 1..=3).await;
stored(&client, 3).await;
agent_term::open_or_create(&client, AGENT)
swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("a second ensure succeeds");
// Read back from the server, not from what the ensure returned.
@ -484,7 +485,7 @@ mod tests {
.expect("an earlier stream");
publish_rows(&client, 1..=2).await;
stored(&client, 2).await;
let opened = agent_term::open_or_create(&client, AGENT)
let opened = swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("an existing stream opens");
assert_eq!(opened.cached_info().config.max_message_size, 4096);
@ -497,7 +498,7 @@ mod tests {
async fn the_replay_reaches_the_reader_before_the_live_tail() {
let nats = TestNats::start();
let client = nats.client().await;
agent_term::open_or_create(&client, AGENT)
swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("the stream");
publish_rows(&client, 1..=150).await;
@ -514,7 +515,7 @@ mod tests {
async fn a_reconnect_gets_every_later_row_once() {
let nats = TestNats::start();
let client = nats.client().await;
agent_term::open_or_create(&client, AGENT)
swarm_queue_client::agent_term::open_or_create(&client, AGENT)
.await
.expect("the stream");
publish_rows(&client, 1..=150).await;
@ -541,7 +542,7 @@ mod tests {
async fn a_subagent_replays_its_own_newest_rows_before_the_live_tail() {
let nats = TestNats::start();
let client = nats.client().await;
let stream_name = swarm_queue_client::subagent_term::stream_name(AGENT);
let stream_name = swarm_wire::subagent_term::stream_name(AGENT);
swarm_queue_client::subagent_term::open_or_create(&client, AGENT)
.await
.expect("the stream");
@ -559,7 +560,7 @@ mod tests {
async fn a_subagent_reconnect_gets_every_later_row_once() {
let nats = TestNats::start();
let client = nats.client().await;
let stream_name = swarm_queue_client::subagent_term::stream_name(AGENT);
let stream_name = swarm_wire::subagent_term::stream_name(AGENT);
swarm_queue_client::subagent_term::open_or_create(&client, AGENT)
.await
.expect("the stream");