Skip to main content

Module serve

Module serve 

Source
Expand description

Handlers return a Reply: an outcome or an owned stream. Dispatch carries identity, requested delivery mode and scopes. ErasedHandler is the shared registry boundary; drivers own polling and cancellation. Provider and tool authors retain their domain traits through adapters. Reply::written offers a writer that mints stream block identities.

use rig_core::serve::Dispatch;
use rig_core::effect::EffectId;

let dispatch = Dispatch::new(EffectId::from_raw(1), false);
assert!(!dispatch.is_stream());

Re-exports§

pub use adapters::Serving;

Modules§

adapters
Effect handlers adapting model, tool, and retrieval traits. Each adapter translates its effect family into trait calls and returns outcomes or streaming events.

Structs§

Dispatch
An effect’s identity, requested delivery mode, and driver-provided scopes. Reply transport and cancellation remain owned by the driver.
DispatchContext
Recorded parent dispatch, stable program scope identifier and purpose, without live runtime handles.
ErasedHandler
Shared, type-erased handler. Clones retain the same handler allocation. Implements Send + Sync on native targets, but not on WASM.
Layer
A handler wrapped in a policy: a Serve like any other, registered under the inner handler’s descriptor (with the layer’s name added, outermost first). Built with ErasedHandler::layered.
RecordBuffer
Collects the record of every dispatch it is told about, in the order the dispatches began, whatever order they resolve in. A dispatch recorded by it (Dispatch::recorded_by), and every dispatch nested in it, becomes one EffectRecord once resolved: a layer’s discard drops it and a patch replaces its request, as an effect log keeps them. Clones share the records.
SinkClosed
The receiver of an external answer or writer has been dropped.
StreamTap
What a unary consumer, the record, or a layer’s verdict takes from a stream: its outcome, the response the stream ends with or the first error item. The origin folded the response; the tap only watches for it.
StreamWriter
A streaming answer under construction, a handler’s completion writer. Obtained by Reply::written; finish ends the reply with the response it folds into, while a writer dropped without it leaves a truncated stream.

Enums§

AfterServe
What a layer decides about an answer on its way out.
BeforeServe
What a layer decides about a dispatch before the handler sees it.
Reply
An answer, or an owned stream whose execution belongs to the driver.

Traits§

Intercept
Host policy before a handler and after its first answer. A suspended verdict keeps execution in flight; driver cancellation drops its future. Streamed verdict futures are polled on the stream consumer’s thread. The layer name identifies policy when recording and validating replay.
Observe
What an observer of one dispatch sees: its outcome and, when wanted, each streamed item.
Recorder
What a driver tells about the dispatches it serves. A driver calls handlers once when recording starts, begin as each dispatch is handed to its handler, event for every streamed event when keep_events says so, and resolve when the outcome is known. A recorder is shared between the driver and its owner, so every method takes &self; it rides in the dispatch observer and uses the platform compatibility bounds.
Serve
A registered effect handler returning an outcome or an owned stream.

Functions§

cancelled
The consumer stopped listening before an answer was observed.
catch_panics
work, the task that drives the dispatch id, with a panic in it (in the handler or in its reply’s stream) turned into an internal error that recorder, if any, also records as the dispatch’s outcome. Unwinding drops the dispatch’s observer, which records a cancellation; this replaces it.
serve_inline
Serve an effect inline, using the same reply conversions as a driver.
serve_inline_with
Serve inline with driver scopes, including tool context and publication.
stream_truncated
The retryable report of a reply that ended before the provider ended it (ProviderError::Truncated). Retryability does not guarantee a subsequent attempt will succeed.

Type Aliases§

HandlerFuture
Boxed handler reply future, Send on native targets and locally polled on WASM.