1use crate::api::openai_compat::AppState;
2use axum::extract::State;
3use axum::Json;
4use serde_json::json;
5
6fn derived_source_index(app: &crate::app::ResolvedApp) -> serde_json::Value {
7 json!({
8 "name": app.name,
9 "app_version": app.version,
10 "manifest_path": app.sources.manifest_path,
11 "config_path": app.sources.config_path,
12 "lock_path": app.sources.lock_path,
13 "trusted": true,
14 "signature": "builtin:app-source",
15 "source_authority": "product-package-instance",
16 "source_public_keys": [],
17 })
18}
19
20pub async fn list_apps(State(state): State<AppState>) -> Json<serde_json::Value> {
21 let apps = state.resolved_apps.read().await;
22 let values: Vec<_> = apps
23 .values()
24 .map(|app| {
25 serde_json::json!({
26 "name": app.name,
27 "version": app.version,
28 "display_name": app.display_name,
29 "description": app.description,
30 "capabilities": app.capabilities,
31 "enabled_features": app.enabled_features,
32 "bindings": app.bindings,
33 "validation_checks": app.validation_checks,
34 "config_path": app.config_path,
35 "status": app.status,
36 "errors": app.errors,
37 "sources": app.sources,
38 "source_index": derived_source_index(app),
39 })
40 })
41 .collect();
42 Json(serde_json::json!({ "apps": values }))
43}