pub struct AppState { /* private fields */ }Expand description
Shared application state injected into every route handler.
Why: Connectors, the poller cache, metrics caches, and HTTP client are
created once at startup and reused for every request so there is no per-
request allocation. A separate MetricsCache is maintained for each
stdio-MCP-polled service (analyze, memory, search, review) so they can be
updated independently and served without coupling. analyze_handle is held
in Arc so the on-demand visualize/index routes can call the analyze stdio MCP
without going through the /proxy path.
mcp_handles maps each service id to its McpServiceHandle so the
services route can overlay the connector-reported status with the actual
tools/list probe result (Degraded when console_metrics is absent).
What: Wraps the connector list, poller cache, per-service metrics caches,
reqwest client, the analyze MCP handle, and the full handle map in Arcs
for cheap cloning.
Test: Constructed in build_router; exercised by the integration tests.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(connectors: Vec<Box<dyn ServiceConnector>>) -> Self
pub fn new(connectors: Vec<Box<dyn ServiceConnector>>) -> Self
Create a new AppState from a list of connectors.
Why: Lets tests inject a custom connector list and fresh caches.
What: Wraps connectors in Arc; initialises empty PollerCache,
three MetricsCache instances (analyze / memory / search), and a
default reqwest::Client. Creates the analyze stdio MCP handle that is
shared between the background metrics poller and on-demand routes.
Populates mcp_handles with all three per-service handles so the
services route can read their degraded state.
Test: Used in build_router and directly in tests.
Sourcepub fn mcp_handles(&self) -> Arc<HashMap<String, Arc<McpServiceHandle>>>
pub fn mcp_handles(&self) -> Arc<HashMap<String, Arc<McpServiceHandle>>>
Access the per-service MCP handle map.
Why: The services route reads handles from this map to overlay connector
statuses with the tools/list probe result.
What: Returns a clone of the Arc<HashMap> (cheap).
Test: Used by apply_handle_overrides and the services handler.
Sourcepub fn analyze_handle(&self) -> Arc<McpServiceHandle>
pub fn analyze_handle(&self) -> Arc<McpServiceHandle>
Access the shared analyze MCP handle.
Why: On-demand routes (/api/console/metrics/analyze/indexes,
/api/console/metrics/analyze/visualize) call the analyze stdio MCP
without touching the analyze daemon HTTP directly (architecture: console
is a stdio MCP client only, per #1104).
What: Returns a clone of the Arc<McpServiceHandle> (cheap).
Test: Exercised by the analyze index and visualize route tests.
Sourcepub fn connectors(&self) -> Arc<Vec<Box<dyn ServiceConnector>>>
pub fn connectors(&self) -> Arc<Vec<Box<dyn ServiceConnector>>>
Access the shared connector list.
Why: The background poller and the fallback spawn_blocking path both
need the connector list.
What: Returns a clone of the Arc (cheap).
Test: Used by run_serve in main.rs.
Sourcepub fn poller_cache(&self) -> &PollerCache
pub fn poller_cache(&self) -> &PollerCache
Access the background poll cache.
Why: Routes read from the cache; the background task writes to it.
What: Returns a clone of the PollerCache handle (cheap — it’s an Arc).
Test: Used by services_handler and proxy_handler.
Sourcepub fn metrics_cache(&self) -> &MetricsCache
pub fn metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-analyze stdio MCP poller.
Why: The metrics poller writes ConsoleMetricsReports here; the
/api/console/metrics/analyze route reads from it.
What: Returns a reference to the MetricsCache handle.
Test: test_metrics_analyze_route_cold_cache_returns_503.
Sourcepub fn memory_metrics_cache(&self) -> &MetricsCache
pub fn memory_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-memory stdio MCP poller.
Why: Separate cache per service so memory and analyze reports can be
updated and served independently.
What: Returns a reference to the MetricsCache handle for memory.
Test: test_metrics_memory_route_cold_cache_returns_503.
Sourcepub fn search_metrics_cache(&self) -> &MetricsCache
pub fn search_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-search stdio MCP poller.
Why: Separate cache per service so search and analyze reports can be
updated and served independently.
What: Returns a reference to the MetricsCache handle for search.
Test: test_metrics_search_route_cold_cache_returns_503.
Sourcepub fn review_metrics_cache(&self) -> &MetricsCache
pub fn review_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-review stdio MCP poller.
Why: Separate cache per service so review reports can be updated and
served independently from the other service caches.
What: Returns a reference to the MetricsCache handle for review.
Test: test_metrics_review_route_cold_cache_returns_503.
Sourcepub fn http_client(&self) -> Arc<Client>
pub fn http_client(&self) -> Arc<Client>
Access the shared reqwest::Client.
Why: Re-using one client enables connection pooling across proxy requests.
What: Returns a clone of the Arc<reqwest::Client> (cheap).
Test: Used by proxy_handler.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more