pub trait ProviderAdapter:
Send
+ Sync
+ 'static {
// Required methods
fn contract(&self) -> AdapterContract<'_>;
fn name(&self) -> &'static str;
fn matches_path(&self, method: &Method, path: &str) -> bool;
fn upstream_base(&self) -> &Url;
fn request_pii_surfaces<'a>(
&self,
body: &'a mut Value,
) -> Vec<PiiSurface<'a>>;
fn response_pii_surfaces<'a>(
&self,
body: &'a mut Value,
) -> Vec<PiiSurface<'a>>;
fn sse_event_pii_surfaces<'a>(
&self,
event: &'a mut SseEvent,
) -> Vec<PiiSurface<'a>>;
// Provided method
fn requests_json_output(&self, _request: &Value) -> bool { ... }
}Expand description
A provider the proxy forwards to.
Every adapter must declare its AdapterContract; the trait has no default, so an adapter
that says nothing about its coverage does not compile:
use gaze_proxy::{PiiSurface, ProviderAdapter, SseEvent};
use http::Method;
use serde_json::Value;
use url::Url;
struct Silent(Url);
#[async_trait::async_trait]
impl ProviderAdapter for Silent {
fn name(&self) -> &'static str { "silent" }
fn matches_path(&self, _: &Method, _: &str) -> bool { false }
fn upstream_base(&self) -> &Url { &self.0 }
fn request_pii_surfaces<'a>(&self, _: &'a mut Value) -> Vec<PiiSurface<'a>> { Vec::new() }
fn response_pii_surfaces<'a>(&self, _: &'a mut Value) -> Vec<PiiSurface<'a>> { Vec::new() }
fn sse_event_pii_surfaces<'a>(&self, _: &'a mut SseEvent) -> Vec<PiiSurface<'a>> { Vec::new() }
}Declaring AdapterContract::legacy opts into the string-surface path, where the proxy
re-scans the whole outbound request body and refuses it if anything is left unprotected:
use gaze_proxy::{AdapterContract, PiiSurface, ProviderAdapter, SseEvent};
use http::Method;
use serde_json::Value;
use url::Url;
struct Declared(Url);
#[async_trait::async_trait]
impl ProviderAdapter for Declared {
fn contract(&self) -> AdapterContract<'_> { AdapterContract::legacy() }
fn name(&self) -> &'static str { "declared" }
fn matches_path(&self, _: &Method, _: &str) -> bool { false }
fn upstream_base(&self) -> &Url { &self.0 }
fn request_pii_surfaces<'a>(&self, _: &'a mut Value) -> Vec<PiiSurface<'a>> { Vec::new() }
fn response_pii_surfaces<'a>(&self, _: &'a mut Value) -> Vec<PiiSurface<'a>> { Vec::new() }
fn sse_event_pii_surfaces<'a>(&self, _: &'a mut SseEvent) -> Vec<PiiSurface<'a>> { Vec::new() }
}Required Methods§
Sourcefn contract(&self) -> AdapterContract<'_>
fn contract(&self) -> AdapterContract<'_>
Declares protocol, session, routing and coverage behavior. Required: a default here would make every adapter that forgets it silently take the legacy path.
fn name(&self) -> &'static str
fn matches_path(&self, method: &Method, path: &str) -> bool
fn upstream_base(&self) -> &Url
fn request_pii_surfaces<'a>(&self, body: &'a mut Value) -> Vec<PiiSurface<'a>>
fn response_pii_surfaces<'a>(&self, body: &'a mut Value) -> Vec<PiiSurface<'a>>
fn sse_event_pii_surfaces<'a>( &self, event: &'a mut SseEvent, ) -> Vec<PiiSurface<'a>>
Provided Methods§
Sourcefn requests_json_output(&self, _request: &Value) -> bool
fn requests_json_output(&self, _request: &Value) -> bool
Reports whether request asked the model for JSON output (a JSON mode or a JSON
schema), which makes every SurfaceSyntax::ModelOutput response surface a JSON
document. The default, false, restores model output as free text.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".