2026-04-17 00:25:28 +08:00
|
|
|
mod bridge;
|
2026-04-17 23:36:24 +08:00
|
|
|
mod command_support;
|
2026-04-16 22:01:51 +08:00
|
|
|
mod compat;
|
2026-04-19 21:03:25 +08:00
|
|
|
mod documents;
|
|
|
|
|
mod editor;
|
2026-04-29 12:24:44 +08:00
|
|
|
mod gateway;
|
2026-04-16 22:01:51 +08:00
|
|
|
mod health;
|
|
|
|
|
mod hermes;
|
|
|
|
|
mod kernel;
|
2026-04-29 12:24:44 +08:00
|
|
|
mod mindmap_shell;
|
2026-04-17 00:25:28 +08:00
|
|
|
mod query_support;
|
2026-04-29 12:24:44 +08:00
|
|
|
mod search;
|
|
|
|
|
mod session;
|
2026-04-18 05:43:49 +08:00
|
|
|
mod snapshot_support;
|
2026-04-16 22:01:51 +08:00
|
|
|
mod sse;
|
2026-04-18 05:43:49 +08:00
|
|
|
mod stream_support;
|
2026-04-17 23:36:24 +08:00
|
|
|
mod tree;
|
2026-04-29 12:24:44 +08:00
|
|
|
mod web_shell;
|
2026-04-16 22:01:51 +08:00
|
|
|
mod ws;
|
|
|
|
|
|
|
|
|
|
use crate::app::AppState;
|
2026-04-28 16:30:51 +08:00
|
|
|
use axum::routing::{get, post};
|
2026-04-29 12:24:44 +08:00
|
|
|
use axum::Router;
|
2026-04-16 22:01:51 +08:00
|
|
|
|
|
|
|
|
pub fn build_router(state: AppState) -> Router {
|
|
|
|
|
let hermes_base_path = state.config().hermes_base_path.clone();
|
|
|
|
|
let compat_next_base_path = state.config().compat_next_base_path.clone();
|
2026-04-23 07:38:34 +08:00
|
|
|
let enable_debug_shell_routes = state.config().enable_debug_shell_routes;
|
2026-04-16 22:01:51 +08:00
|
|
|
|
2026-04-23 07:38:34 +08:00
|
|
|
let mut router = Router::new()
|
2026-04-16 22:01:51 +08:00
|
|
|
.route("/health", get(health::health))
|
2026-04-29 12:24:44 +08:00
|
|
|
.route("/", get(gateway::root_entry))
|
|
|
|
|
.route("/auth", get(gateway::auth_entry).post(gateway::auth_entry))
|
|
|
|
|
.route("/search", get(search::shell))
|
|
|
|
|
.route(
|
|
|
|
|
"/mindmap/{doc_id}/{mindmap_id}",
|
|
|
|
|
get(mindmap_shell::mindmap_object_shell),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/documents/{document_id}",
|
|
|
|
|
get(web_shell::document_page_shell),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/api/page-aggregate/{document_id}",
|
|
|
|
|
get(web_shell::page_aggregate),
|
|
|
|
|
)
|
2026-04-29 14:36:24 +08:00
|
|
|
.route(
|
|
|
|
|
"/api/leptos-tiptap-runtime/manifest.json",
|
|
|
|
|
get(web_shell::leptos_tiptap_manifest),
|
|
|
|
|
)
|
|
|
|
|
.route(
|
|
|
|
|
"/api/leptos-tiptap-runtime/{*asset_path}",
|
|
|
|
|
get(web_shell::leptos_tiptap_asset),
|
|
|
|
|
)
|
2026-05-02 06:25:26 +08:00
|
|
|
.route(
|
|
|
|
|
"/api/editor/image-placeholder.svg",
|
|
|
|
|
get(web_shell::editor_image_placeholder_asset),
|
|
|
|
|
)
|
2026-04-29 12:24:44 +08:00
|
|
|
.route("/api/search/documents", post(search::documents))
|
|
|
|
|
.route("/api/gateway/health", get(gateway::gateway_health))
|
|
|
|
|
.route("/api/runtime/config", get(session::runtime_config))
|
|
|
|
|
.route("/api/auth/session", get(session::session))
|
|
|
|
|
.route("/api/auth/session/refresh", post(session::refresh_session))
|
2026-04-19 21:03:25 +08:00
|
|
|
.route("/api/documents/meta", get(documents::meta))
|
|
|
|
|
.route("/api/documents/content", get(documents::content))
|
2026-04-30 05:46:36 +08:00
|
|
|
.route("/api/documents/title", post(documents::title))
|
|
|
|
|
.route("/api/documents/options", post(documents::options))
|
2026-04-19 21:03:25 +08:00
|
|
|
.route("/api/documents/save", post(documents::save))
|
|
|
|
|
.route(
|
|
|
|
|
"/api/documents/runtime/transform",
|
|
|
|
|
post(editor::transform_runtime_snapshot),
|
|
|
|
|
)
|
2026-04-18 09:38:16 +08:00
|
|
|
.route(
|
|
|
|
|
"/api/tree/projections/sidebar",
|
|
|
|
|
get(kernel::project_tree_sidebar),
|
|
|
|
|
)
|
|
|
|
|
.route("/api/tree/projections/page", get(kernel::project_tree_page))
|
|
|
|
|
.route("/api/tree/projections/file", get(kernel::project_tree_file))
|
2026-04-17 00:25:28 +08:00
|
|
|
.route(
|
|
|
|
|
"/api/kernel/projections/sidebar",
|
|
|
|
|
get(kernel::project_sidebar),
|
|
|
|
|
)
|
2026-04-16 22:01:51 +08:00
|
|
|
.route("/api/kernel/subtree", get(kernel::subtree))
|
|
|
|
|
.route("/api/kernel/edges", get(kernel::edges))
|
|
|
|
|
.route("/api/kernel/graph", get(kernel::graph))
|
2026-04-17 23:36:24 +08:00
|
|
|
.route("/api/tree/commands", post(tree::tree_command))
|
2026-04-28 16:30:51 +08:00
|
|
|
.route(
|
|
|
|
|
"/api/tree/runtime/reduce",
|
|
|
|
|
post(tree::reduce_tree_shell_runtime),
|
|
|
|
|
)
|
2026-04-17 00:25:28 +08:00
|
|
|
.route("/api/bridge/workspace", get(bridge::workspace))
|
|
|
|
|
.route("/api/bridge/request", get(bridge::request))
|
|
|
|
|
.route("/api/bridge/trace", get(bridge::trace))
|
2026-04-29 12:24:44 +08:00
|
|
|
.route("/api/tree/events", get(sse::tree_events))
|
2026-04-16 22:01:51 +08:00
|
|
|
.route("/api/stream/events", get(sse::events))
|
|
|
|
|
.route("/api/realtime/ws", get(ws::socket))
|
|
|
|
|
.nest(
|
|
|
|
|
&hermes_base_path,
|
|
|
|
|
Router::new()
|
|
|
|
|
.route("/health", get(hermes::health))
|
|
|
|
|
.route("/bridge", post(hermes::bridge_runtime)),
|
|
|
|
|
)
|
|
|
|
|
.nest(
|
|
|
|
|
&compat_next_base_path,
|
2026-04-17 00:25:28 +08:00
|
|
|
Router::new()
|
|
|
|
|
.route("/ai-agent/run", post(compat::next_ai_agent_run))
|
|
|
|
|
.route("/sidebar", get(compat::next_sidebar)),
|
2026-04-29 12:24:44 +08:00
|
|
|
)
|
|
|
|
|
.fallback(gateway::legacy_next_proxy);
|
2026-04-23 07:38:34 +08:00
|
|
|
|
|
|
|
|
if enable_debug_shell_routes {
|
|
|
|
|
router = router
|
|
|
|
|
.route("/tree", get(tree::tree_shell))
|
|
|
|
|
.route("/document-debug", get(editor::document_editor_shell))
|
|
|
|
|
.route("/document", get(editor::document_editor_shell));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
router.with_state(state)
|
2026-04-16 22:01:51 +08:00
|
|
|
}
|