Skip to main content

systemprompt_api/routes/evaluation/
optimization_state.rs

1//! Router state for the evaluation admin surface: the application context plus
2//! the optimization orchestrator composed once from its repositories.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use std::sync::Arc;
8
9use axum::extract::FromRef;
10use systemprompt_runtime::AppContext;
11use systemprompt_runtime::optimization::SkillOptimizationOrchestrator;
12
13#[derive(Debug, Clone)]
14pub struct OptimizationState {
15    ctx: AppContext,
16    orchestrator: Arc<SkillOptimizationOrchestrator>,
17}
18
19impl OptimizationState {
20    pub fn new(ctx: AppContext) -> Self {
21        let orchestrator = Arc::new(SkillOptimizationOrchestrator::new(
22            ctx.managed_repository().as_ref().clone(),
23            ctx.evaluation_repositories().as_ref().clone(),
24        ));
25        Self { ctx, orchestrator }
26    }
27
28    pub fn orchestrator(&self) -> &SkillOptimizationOrchestrator {
29        &self.orchestrator
30    }
31
32    pub const fn ctx(&self) -> &AppContext {
33        &self.ctx
34    }
35}
36
37impl FromRef<OptimizationState> for AppContext {
38    fn from_ref(state: &OptimizationState) -> Self {
39        state.ctx.clone()
40    }
41}