pub struct Handler { /* private fields */ }Expand description
Core reactive messaging handler.
Manages agent registrations, rate limiting, message injection, and audit logging.
Implementations§
Source§impl Handler
impl Handler
Sourcepub fn get_delivery_target(&self, name: &str) -> Option<&AgentRegistration>
pub fn get_delivery_target(&self, name: &str) -> Option<&AgentRegistration>
Handler::get_agent, plus a former slug’s agent: for a delivery
target only, never a name that authenticates or acts.
Sourcepub fn lookup_delivery_target(&self, name: &str) -> LookupOutcome
pub fn lookup_delivery_target(&self, name: &str) -> LookupOutcome
Handler::lookup_by_name, plus a former slug’s agent: for a
delivery target (a transcript, files, the resolve endpoint).
Sourcepub fn set_former_slug_resolver(&mut self, resolver: FormerSlugResolver)
pub fn set_former_slug_resolver(&mut self, resolver: FormerSlugResolver)
See FormerSlugResolver.
Sourcepub fn set_display_route_resolver(&mut self, resolver: FormerSlugResolver)
pub fn set_display_route_resolver(&mut self, resolver: FormerSlugResolver)
The UID of the agent whose current display name routes to a name
(Store::display_route_owner): the same delivery-only rules as a
former slug, tried first, since a current name wins over a former one.
Never consulted for a sender (#1459).
Source§impl Handler
impl Handler
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new handler without an input sender.
Call set_input_sender before injecting messages.
Sourcepub fn set_input_sender(&mut self, sender: InputSender)
pub fn set_input_sender(&mut self, sender: InputSender)
Set the input sender function for message injection.
Sourcepub fn set_message_sender(&mut self, sender: MessageSender)
pub fn set_message_sender(&mut self, sender: MessageSender)
Set the controller-aware message sender. When present, inject_message
tries it first: persistent stream-json and ACP agents receive a structured
message on their live channel (mid-turn steering); PTY-based agents report
back so injection falls through to the keystroke path.
Sourcepub fn set_agent_identity_confirmer(
&mut self,
confirmer: AgentIdentityConfirmer,
)
pub fn set_agent_identity_confirmer( &mut self, confirmer: AgentIdentityConfirmer, )
Set the agent-identity confirmer used by inject_message_inner to
double-check a resolved delivery target against its own live,
spawn-time-captured identity before delivering. Optional — if never
set, delivery proceeds exactly as before this check existed (fail-open).
Sourcepub fn set_stable_agent_identity_confirmer(
&mut self,
confirmer: AgentIdentityConfirmer,
)
pub fn set_stable_agent_identity_confirmer( &mut self, confirmer: AgentIdentityConfirmer, )
See stable_agent_identity_confirmer’s field doc comment.
Sourcepub fn set_uid_identity_confirmer(&mut self, confirmer: AgentIdentityConfirmer)
pub fn set_uid_identity_confirmer(&mut self, confirmer: AgentIdentityConfirmer)
See uid_identity_confirmer’s field doc comment (identity M2).
Sourcepub fn set_block_liveness(&mut self, probe: BlockLivenessProbe)
pub fn set_block_liveness(&mut self, probe: BlockLivenessProbe)
See block_liveness’s field doc comment (identity M2).
Sourcepub fn set_include_source(&mut self, include: bool)
pub fn set_include_source(&mut self, include: bool)
Set whether to include source agent prefix in injected messages.
Sourcepub fn register_agent(
&mut self,
agent_id: &str,
block_id: &str,
tab_id: Option<&str>,
) -> Result<(), String>
pub fn register_agent( &mut self, agent_id: &str, block_id: &str, tab_id: Option<&str>, ) -> Result<(), String>
Register an agent with a block.
Name-only registration. Every production site now goes through
[register_agent_full] with its UID and counter site; this is the
test-facing form (and the shape the pre-M2 API had).
Sourcepub fn register_agent_with_nonce(
&mut self,
agent_id: &str,
block_id: &str,
tab_id: Option<&str>,
registration_nonce: u64,
alias: Option<&str>,
) -> Result<(), String>
pub fn register_agent_with_nonce( &mut self, agent_id: &str, block_id: &str, tab_id: Option<&str>, registration_nonce: u64, alias: Option<&str>, ) -> Result<(), String>
[register_agent], recording the registering persistent-controller
spawn’s process-wide registration nonce
(AgentRegistration::registration_nonce) so its own exit-handler
can later compare-and-remove ([unregister_block_if_nonce])
instead of blindly wiping a fallback respawn’s fresh registration
(issue #2363).
alias, if given, becomes the block’s stable name binding
(NameBindings::stable): kept when a later call replaces the
display binding, so a jekt addressed to AGENTMUX_AGENT_ID still
resolves after the display name has moved on post-rename.
Sourcepub fn register_agent_full(
&mut self,
display: &str,
block_id: &str,
tab_id: Option<&str>,
registration_nonce: u64,
stable: Option<&str>,
uid: Option<&str>,
no_uid_counter: &'static str,
) -> Result<(), String>
pub fn register_agent_full( &mut self, display: &str, block_id: &str, tab_id: Option<&str>, registration_nonce: u64, stable: Option<&str>, uid: Option<&str>, no_uid_counter: &'static str, ) -> Result<(), String>
The full registration (identity M2, spec §4.4.2): display is the
block’s display binding, stable its stable binding (set or kept),
uid its identity when the caller knows it, and no_uid_counter the
§9.2 counter to bump when it does not.
Eviction is by identity, never by name:
uidalready registered on another block → that block is evicted entirely (a respawn).- a name already held by another block is left alone unless neither block has a UID — that case keeps today’s name eviction exactly, and is counted.
- a block that has a UID keeps it when re-registered without one
(sticky — a transient row miss on the presence path must not drop a
live block out of
uid_to_block); a block without one is upgraded in place when a later registration supplies one.
Sourcepub fn has_live_name(&self, name: &str) -> bool
pub fn has_live_name(&self, name: &str) -> bool
Does any live block hold name (case-insensitive, like the cloud
subscription’s keys)? An exit’s own nonce check can’t answer this:
it reports false both when a newer spawn owns the registration and
when nobody holds it any more.
Sourcepub fn lookup_by_name(&self, name: &str) -> LookupOutcome
pub fn lookup_by_name(&self, name: &str) -> LookupOutcome
Name lookup that tells an ambiguous name apart from an unknown one
(identity M2) — for callers that must refuse with candidates rather
than fall through to cross-instance forwarding (GetAgentTranscript).
No former slugs (lookup_delivery_target adds them).
Sourcepub fn unregister_agent(&mut self, agent_id: &str) -> UnregisterOutcome
pub fn unregister_agent(&mut self, agent_id: &str) -> UnregisterOutcome
Unregister by name (identity M2, spec §4.4.4 Q7). One live block →
removed. Several → nothing is removed and the candidates are
returned; the caller must not report success. None → NotFound.
Sourcepub fn unregister_block(&mut self, block_id: &str) -> Vec<String>
pub fn unregister_block(&mut self, block_id: &str) -> Vec<String>
Unregister by block ID. Returns every name the block was bound under (empty if it was not registered) so name-keyed side state can be torn down for each.
Sourcepub fn unregister_block_if_nonce(
&mut self,
block_id: &str,
expected_nonce: u64,
) -> bool
pub fn unregister_block_if_nonce( &mut self, block_id: &str, expected_nonce: u64, ) -> bool
Unregister by block ID only if the current registration was
written by the spawn with expected_nonce — a
compare-and-remove for persistent-controller exit-handlers (issue
#2363: the handler’s is_current_generation gate is read once,
while a fallback respawn re-registers on a parallel task; an
unconditional [unregister_block] here could wipe the NEW spawn’s
registration, leaving the live agent invisible to Tier-1 delivery
with nothing left to re-register it). The nonce is process-wide
unique, so the guard also holds across controller replacement
(resync_controller — codex P1 on PR #2500), where a
controller-local generation would restart at 1 and collide. Runs
atomically under the handler’s own lock (via the outer wrapper).
A registration with no recorded nonce (0 — HTTP/PTY paths) is
never removed by this variant: leaving a stale entry to the TTL
sweep is strictly safer than deleting a live one.
Returns true if the registration was ours and was removed.
Sourcepub fn update_last_seen(&mut self, agent_id: &str)
pub fn update_last_seen(&mut self, agent_id: &str)
Update the last_seen timestamp for an agent.
Sourcepub fn get_agent(&self, agent_id: &str) -> Option<&AgentRegistration>
pub fn get_agent(&self, agent_id: &str) -> Option<&AgentRegistration>
Get agent registration by agent ID — a UID, or a name held by
exactly one live block. A name held by several is None, counted
(lookup.ambiguous_name): callers that authorize on it fail closed,
and callers that display on it show nothing rather than the wrong one.
Never a former slug’s agent: callers authenticate and act on this.
Sourcepub fn has_uid_registration(&self, uid: &str) -> bool
pub fn has_uid_registration(&self, uid: &str) -> bool
Whether uid has a live registration — a lookup with no side effect
(no counter, no rate-limit token, no audit entry), for the held-jekt
replay’s presence check.
Sourcepub fn block_for_uid(&self, uid: &str) -> Option<String>
pub fn block_for_uid(&self, uid: &str) -> Option<String>
The block uid is registered on, with no side effect — for the
held-jekt replay’s quiet sign-in check.
Sourcepub fn inject_held(&mut self, req: InjectionRequest) -> InjectionResponse
pub fn inject_held(&mut self, req: InjectionRequest) -> InjectionResponse
Deliver a held jekt (durable jekt spec §2.3): the ordinary delivery
path, audited as held_delivered (or held_retry on failure).
Sourcepub fn get_agent_by_block(&self, block_id: &str) -> Option<&AgentRegistration>
pub fn get_agent_by_block(&self, block_id: &str) -> Option<&AgentRegistration>
Get agent registration by block ID.
Sourcepub fn names_for_block(&self, block_id: &str) -> Vec<String>
pub fn names_for_block(&self, block_id: &str) -> Vec<String>
Every name block_id is bound under (display first, then stable).
Production teardown gets the same list back from [unregister_block];
this read-only form is what registration subscribes for cloud delivery.
Sourcepub fn list_agents(&self) -> Vec<AgentRegistration>
pub fn list_agents(&self) -> Vec<AgentRegistration>
List all registered agents.
Sourcepub fn inject_message(&mut self, req: InjectionRequest) -> InjectionResponse
pub fn inject_message(&mut self, req: InjectionRequest) -> InjectionResponse
Inject a message into an agent’s terminal.
Sends message\r as a single payload (required for text display),
then spawns 3 delayed \r sends at 200ms intervals as separate
PTY writes to ensure submission. See docs/specs/jekt-inject-timing.md.
Sourcepub fn deliver_system_note(
&mut self,
target_agent: &str,
text: &str,
) -> Result<(), String>
pub fn deliver_system_note( &mut self, target_agent: &str, text: &str, ) -> Result<(), String>
Deliver one of srv’s own [AgentMux] system notes to target_agent
now, which starts a turn if none is running; an informational note
waits for the next one instead (held_notes). Not a jekt: no marker
block, tier or trust label, because nothing but srv wrote the text,
and no jekt or forwarded text can carry the marker
(sanitize::neutralize_markers).
Routed like a jekt: the controller’s structured channel, else
keystrokes. Audited as system_note from agentmux.
Sourcepub fn get_audit_log(&self, limit: usize) -> Vec<AuditLogEntry>
pub fn get_audit_log(&self, limit: usize) -> Vec<AuditLogEntry>
Get audit log entries, most recent first.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Handler
impl !UnwindSafe for Handler
impl Freeze for Handler
impl Send for Handler
impl Sync for Handler
impl Unpin for Handler
impl UnsafeUnpin for Handler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more