Skip to main content

crw_server/routes/
capabilities.rs

1//! `GET /v1/capabilities` — surface what this opencore instance supports.
2//!
3//! SaaS / dashboard frontends call this on boot to decide which provider
4//! buttons / formats to surface. Closes the "SaaS UI shipped before
5//! opencore rollout" silent-failure mode by giving callers a way to ask
6//! "do you actually do this?" before making a real request.
7
8use axum::Json;
9use axum::extract::State;
10use serde::Serialize;
11
12use crate::state::AppState;
13
14#[derive(Debug, Serialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Capabilities {
17    pub version: &'static str,
18    pub llm: LlmCapabilities,
19    pub formats: FormatCapabilities,
20    pub search: SearchCapabilities,
21}
22
23#[derive(Debug, Serialize)]
24#[serde(rename_all = "camelCase")]
25pub struct LlmCapabilities {
26    /// Provider tags the server's dispatch knows about.
27    pub providers: Vec<&'static str>,
28    pub supports_base_url: bool,
29    /// True when a server-wide LLM key is configured (self-hosted /
30    /// no-SaaS deploys). SaaS-fronted deploys set
31    /// `CRW_DISABLE_SERVER_LLM_KEY=1` and rely on per-request BYOK.
32    pub server_key_configured: bool,
33    /// Configured server-side fan-out cap for LLM calls. 0 when no
34    /// server-side LLM config is present.
35    pub max_concurrency: usize,
36    /// Header name the server will look for on LLM-touching requests
37    /// (`None` means no header guard).
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub require_byok_header: Option<String>,
40}
41
42#[derive(Debug, Serialize)]
43#[serde(rename_all = "camelCase")]
44pub struct FormatCapabilities {
45    pub supported: Vec<&'static str>,
46}
47
48#[derive(Debug, Serialize)]
49#[serde(rename_all = "camelCase")]
50pub struct SearchCapabilities {
51    pub answer: bool,
52    pub summarize_results: bool,
53}
54
55pub async fn capabilities(State(state): State<AppState>) -> Json<Capabilities> {
56    let llm_cfg = state.config.extraction.llm.as_ref();
57    Json(Capabilities {
58        version: env!("CARGO_PKG_VERSION"),
59        llm: LlmCapabilities {
60            providers: vec![
61                "anthropic",
62                "openai",
63                "deepseek",
64                "openai-compatible",
65                "azure",
66            ],
67            supports_base_url: true,
68            server_key_configured: llm_cfg.map(|c| !c.api_key.is_empty()).unwrap_or(false),
69            max_concurrency: llm_cfg.map(|c| c.max_concurrency).unwrap_or(0),
70            require_byok_header: llm_cfg.and_then(|c| c.require_byok_header.clone()),
71        },
72        formats: FormatCapabilities {
73            supported: vec![
74                "markdown",
75                "html",
76                "rawHtml",
77                "plainText",
78                "links",
79                "json",
80                "summary",
81            ],
82        },
83        search: SearchCapabilities {
84            answer: true,
85            summarize_results: true,
86        },
87    })
88}