pub struct JsAgent { /* private fields */ }Expand description
JavaScript scripting agent
Implementations§
Source§impl JsAgent
impl JsAgent
Sourcepub fn new(script_path: PathBuf, fail_open: bool) -> Result<Self>
pub fn new(script_path: PathBuf, fail_open: bool) -> Result<Self>
Create a new JavaScript agent with the given script file
Sourcepub fn from_source(script_content: String, fail_open: bool) -> Result<Self>
pub fn from_source(script_content: String, fail_open: bool) -> Result<Self>
Create a new JavaScript agent from script source code
Sourcepub fn reconfigure(&self, config: JsConfigJson) -> Result<()>
pub fn reconfigure(&self, config: JsConfigJson) -> Result<()>
Reconfigure the agent with new settings
This allows dynamic reconfiguration without restarting the agent.
Sourcepub fn call_function(
&self,
fn_name: &str,
arg: Value,
) -> Result<Option<ScriptResult>>
pub fn call_function( &self, fn_name: &str, arg: Value, ) -> Result<Option<ScriptResult>>
Execute a JavaScript function
Sourcepub fn build_response(result: ScriptResult) -> AgentResponse
pub fn build_response(result: ScriptResult) -> AgentResponse
Build AgentResponse from ScriptResult
Trait Implementations§
Source§impl AgentHandler for JsAgent
impl AgentHandler for JsAgent
Source§fn on_configure<'life0, 'async_trait>(
&'life0 self,
event: ConfigureEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_configure<'life0, 'async_trait>(
&'life0 self,
event: ConfigureEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a configure event Read more
Source§fn on_request_headers<'life0, 'async_trait>(
&'life0 self,
event: RequestHeadersEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_request_headers<'life0, 'async_trait>(
&'life0 self,
event: RequestHeadersEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a request headers event
Source§fn on_response_headers<'life0, 'async_trait>(
&'life0 self,
event: ResponseHeadersEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_response_headers<'life0, 'async_trait>(
&'life0 self,
event: ResponseHeadersEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a response headers event
Source§fn on_request_body_chunk<'life0, 'async_trait>(
&'life0 self,
_event: RequestBodyChunkEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn on_request_body_chunk<'life0, 'async_trait>(
&'life0 self,
_event: RequestBodyChunkEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a request body chunk event
Source§fn on_response_body_chunk<'life0, 'async_trait>(
&'life0 self,
_event: ResponseBodyChunkEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn on_response_body_chunk<'life0, 'async_trait>(
&'life0 self,
_event: ResponseBodyChunkEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a response body chunk event
Source§fn on_request_complete<'life0, 'async_trait>(
&'life0 self,
_event: RequestCompleteEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn on_request_complete<'life0, 'async_trait>(
&'life0 self,
_event: RequestCompleteEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a request complete event
Source§fn on_websocket_frame<'life0, 'async_trait>(
&'life0 self,
_event: WebSocketFrameEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn on_websocket_frame<'life0, 'async_trait>(
&'life0 self,
_event: WebSocketFrameEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a WebSocket frame event Read more
Source§fn on_guardrail_inspect<'life0, 'async_trait>(
&'life0 self,
_event: GuardrailInspectEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn on_guardrail_inspect<'life0, 'async_trait>(
&'life0 self,
_event: GuardrailInspectEvent,
) -> Pin<Box<dyn Future<Output = AgentResponse> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a guardrail inspection event Read more
impl Send for JsAgent
impl Sync for JsAgent
Auto Trait Implementations§
impl !Freeze for JsAgent
impl RefUnwindSafe for JsAgent
impl Unpin for JsAgent
impl UnwindSafe for JsAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request