Expand description
Reusable HTTP/gRPC host infrastructure for Agent Factory services.
ApiError— JSON error envelope carrying the request id.middleware::request_id/middleware::latency_slo— request-id propagation and the API latency SLO (warn pastmiddleware::SLO_BUDGET_MS).with_standard_middleware— wrap anyRouterwith the standard stack.health— a ready-made health handler.metrics— a minimal Prometheus-compatible liveness metric.
A service composes its product routes and wraps them:
ⓘ
let app = with_standard_middleware(
Router::new().route("/health", get(health)).merge(product_routes),
);Re-exports§
pub use error::ApiError;pub use middleware::latency_slo;pub use middleware::rate_limit;pub use middleware::request_id;pub use middleware::RateLimiter;pub use middleware::SLO_BUDGET_MS;
Modules§
- error
- JSON error envelope. Port of the reusable shape of
agent_core/api/errors.py. - middleware
- Cross-cutting middleware. Ports the reusable concerns of
agent_core/api/: request-id propagation (request_id) and the API latency SLO (latency_slo).
Structs§
- Edge
Config - Production edge limits shared by reference hosts.
- Readiness
- Mutable readiness signal; liveness remains independent.
- Request
Id - Transport request identity used for tracing and idempotency.
Functions§
- base_
router - A
Routerpreseeded withGET /health. Services merge their routes onto it. - health
- Standard health endpoint payload.
- join_
tasks - Joins background tasks within a bounded shutdown grace period.
- liveness
- Liveness endpoint; success means the process event loop is responsive.
- metrics
- Baseline metric shared by reference hosts. Products merge their own metric families into the same endpoint when they need richer observability.
- operations_
router - Router exposing separate process liveness and dependency readiness.
- readiness
- Readiness endpoint backed by the host’s dependency state.
- resolve_
tonic_ context - Resolves verified caller context from tonic metadata for every gRPC service.
- shutdown_
signal - Waits for SIGINT/SIGTERM and cancels all host tasks.
- supervise_
tasks - Fails readiness and cancels sibling workers if any host task exits early. Returns true only for a requested shutdown with all workers drained.
- with_
edge_ middleware - Applies bounded production edge controls. CORS is deny-by-default.
- with_
standard_ middleware - Wrap a router with the standard middleware stack: latency SLO (outermost, so it times everything) over request-id (so the id exists for SLO logs).