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§
Provided Methods§
Sourcefn enforce(&self) -> PluginPhase
fn enforce(&self) -> PluginPhase
Plugin execution phase
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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_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.
Sourcefn 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 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.
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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 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
Sourcefn transform_stream(&self, stream: Box<TextStream>) -> Box<TextStream>
fn transform_stream(&self, stream: Box<TextStream>) -> Box<TextStream>
Transform text stream
Plugins can wrap or modify the stream of text chunks.