1#![recursion_limit = "256"]
5#![allow(clippy::pedantic, clippy::all)]
12
13pub mod autonomy;
16pub mod bench;
17pub mod cli;
18pub mod color;
19pub mod config;
20pub mod curator;
21pub mod daemon_runtime;
22pub mod db;
23pub mod embeddings;
24pub mod errors;
25pub mod federation;
26pub mod handlers;
27pub mod hnsw;
28pub mod identity;
29pub mod llm;
30pub mod mcp;
31pub mod metrics;
32pub mod mine;
33pub mod models;
34pub mod replication;
35pub mod reranker;
36pub mod subscriptions;
37pub mod tls;
38pub mod toon;
39pub mod validate;
40
41#[cfg(feature = "sal")]
42pub mod migrate;
43
44#[cfg(feature = "sal")]
45pub mod store;
46
47pub fn build_router(
66 api_key_state: handlers::ApiKeyState,
67 app_state: handlers::AppState,
68) -> axum::Router {
69 use axum::{
70 extract::DefaultBodyLimit,
71 routing::{delete, get, post, put},
72 };
73 use tower_http::{cors::CorsLayer, trace::TraceLayer};
74
75 axum::Router::new()
76 .route("/api/v1/health", get(handlers::health))
77 .route("/metrics", get(handlers::prometheus_metrics))
81 .route("/api/v1/metrics", get(handlers::prometheus_metrics))
82 .route("/api/v1/memories", get(handlers::list_memories))
83 .route("/api/v1/memories", post(handlers::create_memory))
84 .route("/api/v1/memories/bulk", post(handlers::bulk_create))
85 .route("/api/v1/memories/{id}", get(handlers::get_memory))
86 .route("/api/v1/memories/{id}", put(handlers::update_memory))
87 .route("/api/v1/memories/{id}", delete(handlers::delete_memory))
88 .route(
89 "/api/v1/memories/{id}/promote",
90 post(handlers::promote_memory),
91 )
92 .route("/api/v1/search", get(handlers::search_memories))
93 .route("/api/v1/recall", get(handlers::recall_memories_get))
94 .route("/api/v1/recall", post(handlers::recall_memories_post))
95 .route("/api/v1/forget", post(handlers::forget_memories))
96 .route("/api/v1/consolidate", post(handlers::consolidate_memories))
97 .route(
98 "/api/v1/contradictions",
99 get(handlers::detect_contradictions),
100 )
101 .route("/api/v1/links", post(handlers::create_link))
102 .route("/api/v1/links", delete(handlers::delete_link))
103 .route("/api/v1/links/{id}", get(handlers::get_links))
104 .route(
110 "/api/v1/namespaces",
111 get(handlers::get_namespace_standard_qs),
112 )
113 .route(
114 "/api/v1/namespaces",
115 post(handlers::set_namespace_standard_qs),
116 )
117 .route(
118 "/api/v1/namespaces",
119 delete(handlers::clear_namespace_standard_qs),
120 )
121 .route(
122 "/api/v1/namespaces/{ns}/standard",
123 post(handlers::set_namespace_standard),
124 )
125 .route(
126 "/api/v1/namespaces/{ns}/standard",
127 get(handlers::get_namespace_standard),
128 )
129 .route(
130 "/api/v1/namespaces/{ns}/standard",
131 delete(handlers::clear_namespace_standard),
132 )
133 .route("/api/v1/taxonomy", get(handlers::get_taxonomy))
135 .route("/api/v1/check_duplicate", post(handlers::check_duplicate))
137 .route("/api/v1/entities", post(handlers::entity_register))
139 .route(
140 "/api/v1/entities/by_alias",
141 get(handlers::entity_get_by_alias),
142 )
143 .route("/api/v1/kg/timeline", get(handlers::kg_timeline))
145 .route("/api/v1/kg/invalidate", post(handlers::kg_invalidate))
147 .route("/api/v1/kg/query", post(handlers::kg_query))
149 .route("/api/v1/stats", get(handlers::get_stats))
150 .route("/api/v1/gc", post(handlers::run_gc))
151 .route("/api/v1/export", get(handlers::export_memories))
152 .route("/api/v1/import", post(handlers::import_memories))
153 .route("/api/v1/archive", get(handlers::list_archive))
154 .route("/api/v1/archive", post(handlers::archive_by_ids))
155 .route("/api/v1/archive", delete(handlers::purge_archive))
156 .route(
157 "/api/v1/archive/{id}/restore",
158 post(handlers::restore_archive),
159 )
160 .route("/api/v1/archive/stats", get(handlers::archive_stats))
161 .route("/api/v1/agents", get(handlers::list_agents))
162 .route("/api/v1/agents", post(handlers::register_agent))
163 .route("/api/v1/pending", get(handlers::list_pending))
164 .route(
165 "/api/v1/pending/{id}/approve",
166 post(handlers::approve_pending),
167 )
168 .route(
169 "/api/v1/pending/{id}/reject",
170 post(handlers::reject_pending),
171 )
172 .route("/api/v1/sync/push", post(handlers::sync_push))
174 .route("/api/v1/sync/since", get(handlers::sync_since))
175 .route("/api/v1/capabilities", get(handlers::get_capabilities))
177 .route("/api/v1/notify", post(handlers::notify))
178 .route("/api/v1/inbox", get(handlers::get_inbox))
179 .route("/api/v1/subscriptions", post(handlers::subscribe))
180 .route("/api/v1/subscriptions", delete(handlers::unsubscribe))
181 .route("/api/v1/subscriptions", get(handlers::list_subscriptions))
182 .route("/api/v1/session/start", post(handlers::session_start))
183 .layer(axum::middleware::from_fn_with_state(
184 api_key_state,
185 handlers::api_key_auth,
186 ))
187 .layer(TraceLayer::new_for_http())
188 .layer(DefaultBodyLimit::max(2 * 1024 * 1024))
189 .layer(CorsLayer::new())
190 .with_state(app_state)
191}