Skip to main content

BlockConfig

Struct BlockConfig 

Source
pub struct BlockConfig {
    pub script: ScriptSource,
    pub project_root: PathBuf,
    pub relay_url: Option<String>,
    pub secret_key: Option<SecretKeySource>,
    pub mcp_rpc_timeout: Duration,
    pub prompt: Option<PromptSource>,
    pub context: Option<PromptSource>,
    pub host_handlers: HashMap<String, Arc<dyn Handler>>,
    pub host_handler: Option<Arc<dyn Handler>>,
    pub auto_serve_bus: bool,
    pub shutdown_token: Option<CancellationToken>,
}

Fields§

§script: ScriptSource

Lua script to execute. See ScriptSource for the supported shapes (filesystem path / inline source / embedded default agent invoker).

§project_root: PathBuf§relay_url: Option<String>§secret_key: Option<SecretKeySource>

Ed25519 secret key for mesh identity. See SecretKeySource for the supported shapes (inline 64-hex / environment variable). None generates a random keypair. Required to talk to registry/ACL-gated hosted meshes.

§mcp_rpc_timeout: Duration

Per-RPC timeout for every MCP round-trip (connect / list / call). Defaults to agent_block_mcp::DEFAULT_RPC_TIMEOUT.

§prompt: Option<PromptSource>

Prompt payload injected as _PROMPT Lua global. See PromptSource for the supported shapes. None leaves the global unset.

§context: Option<PromptSource>

Context payload injected as _CONTEXT Lua global (typically the system prompt). Same shape rules as Self::prompt.

§host_handlers: HashMap<String, Arc<dyn Handler>>

Host-side Rust handlers pre-installed on the EventBus before the user script starts. Each entry registers handler against kind via EventBus::on, so a script-side bus.emit(kind, payload) is captured by the Rust handler rather than dispatched to a Lua function.

Intended for SDK consumers that embed agent-block-core and need to receive script output programmatically (e.g. a Spawner adapter that turns LLM script output into a typed WorkerResult). Lua-side bus.on(kind, fn) registrations layered on top of the handler Isle are still possible, but the EventBus dispatches a single handler per kind (last-write-wins), so host-side and Lua-side registrations on the same kind collide; choose one side per routing key.

Defaults to an empty map (no host handlers).

§host_handler: Option<Arc<dyn Handler>>

Single host-side Rust handler that catches every event regardless of kind. Internally registered via EventBus::on_any, so it acts as a fallback when no entry in Self::host_handlers matches the incoming kind.

This is the SDK-embed 1-shot sink: SDK consumers do not need to invent or coordinate a string kind between the Lua script and their Rust code. The agent invoker’s emit-kind is irrelevant — the handler receives every event.

Use this when you want a single Rust handler to receive results (typical embedded use). Use Self::host_handlers instead when you actually need string-keyed routing (multi-source / multi- handler dispatch). The two may coexist: kind-specific handlers in host_handlers take precedence, and this single handler is the fallback for unmatched kinds.

Defaults to None.

§auto_serve_bus: bool

When true, the EventBus dispatcher loop is driven in the background for the duration of the script and shut down gracefully after the script completes. Required for SDK-embed callers that supply Self::host_handlers and need bus.emit(kind, payload) events emitted from the script to actually reach those handlers without requiring the script to call bus.serve() (which blocks on SIGTERM / Ctrl+C and never returns under programmatic embedding).

After the script finishes, the dispatcher is given a grace window (AGENT_BLOCK_TASK_GRACE_MS, default 1000ms) to drain queued events and finish any in-flight handler, then is cancelled.

Mutually exclusive with Lua-side bus.serve(): enabling this flag takes ownership of the EventBus before the script runs, so a script that calls bus.on(...) followed by bus.serve() will error (“bus.serve() has already taken ownership”). Use this flag when the script’s sole purpose is to push events to host handlers.

Defaults to false (legacy behavior: dispatcher only runs when the script calls bus.serve()).

§shutdown_token: Option<CancellationToken>

Optional caller-supplied cancellation token. When cancelled, the in-flight script is interrupted via the Isle’s debug-hook cancel path, the auto-serve dispatcher (if any) is shut down, and run() returns Err(BlockError::Cancelled).

Intended for SDK consumers that spawn run() as a tokio task and need an out-of-band abort signal (timeouts, parent-task cancellation propagation, user-driven stop). The token is observed across the coroutine_eval await; once cancellation propagates, the shutdown sequence (MCP disconnect, Isle drivers, auto-serve dispatcher) still runs so file descriptors and remote handles are released.

Defaults to None (legacy behavior: run() only completes when the script returns naturally).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> MaybeSend for T

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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