Skip to main content

HostState

Struct HostState 

Source
pub struct HostState { /* private fields */ }

Implementations§

Source§

impl HostState

Source

pub fn new() -> Self

Source

pub async fn subscribe(&self, client_id: &str, channel: Arc<WsChannel>)

Source

pub async fn unsubscribe(&self, client_id: &str)

Source

pub async fn register_agent( &self, client_id: &str, req: RegisterHostAgentRequest, ) -> Result<HostAgent, String>

Source

pub async fn unregister_agent( &self, caller_client_id: &str, agent_id: &str, ) -> Result<(), String>

Source

pub async fn set_status( &self, caller_client_id: &str, req: SetHostAgentStatusRequest, ) -> Result<HostAgent, String>

Source

pub async fn create_approval( &self, caller_client_id: Option<&str>, req: CreateHostApprovalRequest, ) -> Result<HostApprovalRequest, String>

Create an approval owned by caller_client_id. Pass None to mark the approval system-level — the high-risk-method approval gate uses this so the local UI session (a different session than the one whose dispatch is parking) can resolve it. Audit 2026-05: prior to this caller arg, create_approval had no notion of ownership and resolve_approval was open to any caller, allowing cross-session approval squatting.

Source

pub async fn resolve_approval( &self, caller_client_id: &str, req: ResolveHostApprovalRequest, ) -> Result<HostApprovalRequest, String>

Resolve an approval. ACL rules (audit 2026-05, fan-out added 2026-05-15):

  • Approval has client_id: None (system-level, e.g. raised by the high-risk-method gate) → any authed caller may resolve, since the gate’s whole point is that the user acks it via whichever session their UI happens to use.
  • Approval has client_id: Some(x) AND caller IS x → resolve directly, fire approval.resolved.
  • Approval has client_id: Some(x) AND caller is a DIFFERENT session AND owner is still subscribed → fan-out: record an approval.resolve_requested event that the owning agent hooks to call resolve_approval on its own session. The approval row stays Pending until the owner completes it. Caller gets back the pending approval (status: Pending). This unblocks UIs like CarHost that surface every approval in host.approvals — including ones agents pushed via host.request_approval — without breaking the squat- prevention property: only the OWNER ever mutates the row, the non-owning caller just signals intent.
  • Cross-session AND owner is NOT subscribed → return error identifying the disconnected owner. Caller’s UI knows the resolution can’t land right now and surfaces accordingly.
Source

pub async fn reap_session_approvals(&self, client_id: &str) -> usize

Reap a disconnected session’s pending approvals. Called on WS close — covers graceful unregister+close, hard crash (TCP reset), and ping timeout in one place. Only approvals owned by this session (client_id == Some(client_id)) are touched; system-level gate approvals (client_id: None) are left for the user to act on. car-releases#48.

Source

pub async fn reap_agent_approvals( &self, caller_client_id: &str, agent_id: &str, ) -> usize

Reap a specific agent’s pending approvals when it unregisters while its session stays open (agent restarts under a new id on the same WS). Scoped to approvals this caller’s session owns so it can’t cancel another session’s — or a system gate’s — work.

Source

pub async fn request_and_wait_approval( &self, req: CreateHostApprovalRequest, approve_label: &str, timeout: Duration, ) -> Result<ApprovalOutcome, String>

Create an approval and block until the user resolves it (or timeout elapses).

Used by the high-risk-method gate in the WS dispatcher to make the human a load-bearing participant in actions like automation.run_applescript, messages.send, etc. The outcome maps as follows:

Subscribers receive the standard approval.requested event the moment the approval is created; the local HTML UI and any other host shell can render approve/deny buttons that call host.resolve_approval.

On timeout, the approval row is left in Pending on purpose — the UI still shows it (with a “expired” hint the renderer can derive from created_at) and the gate path returns TimedOut so the caller surfaces a clear error.

Source

pub async fn agents(&self) -> Vec<HostAgent>

Source

pub async fn approvals(&self) -> Vec<HostApprovalRequest>

Source

pub async fn events(&self, limit: usize) -> Vec<HostEvent>

Source

pub async fn record_event( &self, kind: impl Into<String>, agent_id: Option<String>, message: impl Into<String>, payload: Value, ) -> HostEvent

Trait Implementations§

Source§

impl Default for HostState

Source§

fn default() -> HostState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,