Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Send
    + Sync
    + Debug
    + 'static {
    // Required method
    fn name(&self) -> &str;

    // Provided methods
    fn enforce(&self) -> PluginPhase { ... }
    fn resolve_model<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _model_id: &'life1 str,
        _ctx: &'life2 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn load_template<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _template_name: &'life1 str,
        _ctx: &'life2 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Message>>, AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn transform_params<'life0, 'life1, 'async_trait>(
        &'life0 self,
        params: TextParams,
        _ctx: &'life1 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<TextParams, AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn transform_result<'life0, 'life1, 'async_trait>(
        &'life0 self,
        result: TextResult,
        _ctx: &'life1 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<TextResult, AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_request_start<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_request_end<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 RequestContext,
        _result: &'life2 TextResult,
    ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _error: &'life1 AiError,
        _ctx: &'life2 RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn transform_stream(&self, stream: Box<TextStream>) -> Box<TextStream> { ... }
}
Expand description

Plugin trait for runtime-level hooks.

Plugins provide application-level functionality that works across multiple providers and models. Unlike layers which wrap providers, plugins hook into the runtime execution flow.

Required Methods§

Source

fn name(&self) -> &str

Plugin name

Provided Methods§

Source

fn enforce(&self) -> PluginPhase

Plugin execution phase

Source

fn resolve_model<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _model_id: &'life1 str, _ctx: &'life2 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Resolve model ID

Allows plugins to intercept and modify model selection.

Source

fn load_template<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _template_name: &'life1 str, _ctx: &'life2 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Message>>, AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Load template

Allows plugins to provide message templates.

Source

fn transform_params<'life0, 'life1, 'async_trait>( &'life0 self, params: TextParams, _ctx: &'life1 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<TextParams, AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Transform request parameters

Plugins can modify parameters before sending to the provider.

Source

fn transform_result<'life0, 'life1, 'async_trait>( &'life0 self, result: TextResult, _ctx: &'life1 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<TextResult, AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Transform result

Plugins can modify the result after receiving from the provider.

Source

fn on_request_start<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Hook called when a request starts

Source

fn on_request_end<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _ctx: &'life1 RequestContext, _result: &'life2 TextResult, ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called when a request ends successfully

Source

fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _error: &'life1 AiError, _ctx: &'life2 RequestContext, ) -> Pin<Box<dyn Future<Output = Result<(), AiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Hook called when an error occurs

Source

fn transform_stream(&self, stream: Box<TextStream>) -> Box<TextStream>

Transform text stream

Plugins can wrap or modify the stream of text chunks.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§