Skip to main content

SessionBackend

Trait SessionBackend 

Source
pub trait SessionBackend: Send + 'static {
    // Required methods
    fn id(&self) -> &str;
    fn model_id(&self) -> &ModelId;
    fn send(
        &mut self,
        input: SessionInput,
    ) -> impl Future<Output = Result<(), KitError>> + Send + '_;
    fn recv(
        &mut self,
    ) -> impl Future<Output = Result<SessionEvent, KitError>> + Send + '_;
    fn close(self) -> impl Future<Output = Result<(), KitError>> + Send;
}
Expand description

Public implementation contract for one unique provider-native session.

Caller models return their concrete session implementation directly through crate::ModelBackend::Session.

Sessions are unique, mutable, and non-Clone. Consuming close settles the session transport; the Provider retains separate shared shutdown authority. Ordinary multi-turn generation instead uses messages and continuation.

See the complete native turn for service setup and cleanup, or crate::ProviderBackend for an executable caller-owned session.

Required Methods§

Source

fn id(&self) -> &str

Stable session identifier.

See crate::SessionBackend for a complete example.

Source

fn model_id(&self) -> &ModelId

Exact selected model.

See crate::SessionBackend for a complete example.

Source

fn send( &mut self, input: SessionInput, ) -> impl Future<Output = Result<(), KitError>> + Send + '_

Sends interactive input.

§Errors

Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.

See the complete session turn for bounded observation and cleanup.

Source

fn recv( &mut self, ) -> impl Future<Output = Result<SessionEvent, KitError>> + Send + '_

Receives the next interactive event.

A delta or usage event does not finish the turn. Continue receiving until its terminal event, as in the complete session turn.

§Errors

Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.

See the complete session turn for bounded observation and cleanup.

Source

fn close(self) -> impl Future<Output = Result<(), KitError>> + Send

Closes the unique session and its transport.

Consuming close does not make the session reusable, even when it fails.

§Errors

Returns the owning input, unsupported, closed, transport, deadline, service-rejection, or protocol error.

See the complete session turn for bounded observation and cleanup.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SessionBackend for Infallible

Source§

fn id(&self) -> &str

Source§

fn model_id(&self) -> &ModelId

Source§

async fn send(&mut self, _input: SessionInput) -> Result<(), KitError>

Source§

async fn recv(&mut self) -> Result<SessionEvent, KitError>

Source§

async fn close(self) -> Result<(), KitError>

Implementors§