fix(server): fix missing /api/graph and task title mapping in dashboard
This commit is contained in:
1 parent
36674df176
commit
1f050b60b6
3 files changed
+90
-3
No files matched your search
@@ -137,7 +137,7 @@
|
|||||||
tasks.forEach(t => {
|
tasks.forEach(t => {
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = `task-card ${t.status === 'completed' ? 'completed' : ''}`;
|
card.className = `task-card ${t.status === 'completed' ? 'completed' : ''}`;
|
||||||
card.innerHTML = `<strong>${t.name}</strong><br>${t.description}`;
|
card.innerHTML = `<strong>${t.title}</strong><br>${t.description}`;
|
||||||
|
|
||||||
if (t.status === 'completed') {
|
if (t.status === 'completed') {
|
||||||
doneContainer.appendChild(card);
|
doneContainer.appendChild(card);
|
||||||
@@ -202,3 +202,4 @@
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
endpoints = """
|
||||||
|
.route("/api/graph", get({
|
||||||
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move || async move {
|
||||||
|
let graph = state_clone.get_full_graph();
|
||||||
|
axum::Json(graph)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.route("/api/tasks", get({
|
||||||
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move || async move {
|
||||||
|
let tasks = state_clone.tasks.read();
|
||||||
|
axum::Json(tasks.clone())
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.route("/api/search", get({
|
||||||
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move |axum::extract::Query(params): axum::extract::Query<std::collections::HashMap<String, String>>| async move {
|
||||||
|
if let Some(q) = params.get("q") {
|
||||||
|
if let Ok(idx) = state_clone.search_index.read() {
|
||||||
|
if let Ok(results) = idx.search(q, None) {
|
||||||
|
let mut formatted_results = Vec::new();
|
||||||
|
for (type_name, content) in results {
|
||||||
|
formatted_results.push(serde_json::json!({
|
||||||
|
"type_name": type_name,
|
||||||
|
"content": content,
|
||||||
|
"score": 1.0
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return axum::Json(serde_json::json!({ "results": formatted_results }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
axum::Json(serde_json::json!({ "results": [] }))
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
"""
|
||||||
|
|
||||||
|
filepath = "C:\\Users\\reazul.ashraf\\workspace\\rust\\mcp-memory\\server\\src\\main.rs"
|
||||||
|
with open(filepath, "r", encoding="utf-8") as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
# Replace the broken routes with the fixed ones
|
||||||
|
pattern = r'\.route\("/api/graph".*?\.route\("/api/stats"'
|
||||||
|
content = re.sub(pattern, endpoints.strip() + '\n .route("/api/stats"', content, flags=re.DOTALL)
|
||||||
|
|
||||||
|
with open(filepath, "w", encoding="utf-8") as f:
|
||||||
|
f.write(content)
|
||||||
+38
-2
@@ -268,8 +268,42 @@ fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>>
|
|||||||
"/",
|
"/",
|
||||||
get(|| async move { axum::response::Html(include_str!("dashboard.html")) }),
|
get(|| async move { axum::response::Html(include_str!("dashboard.html")) }),
|
||||||
)
|
)
|
||||||
.route(
|
.route("/api/graph", get({
|
||||||
"/api/stats",
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move || async move {
|
||||||
|
let graph = state_clone.get_full_graph();
|
||||||
|
axum::Json(graph)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.route("/api/tasks", get({
|
||||||
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move || async move {
|
||||||
|
let tasks = state_clone.tasks.read();
|
||||||
|
axum::Json(tasks.clone())
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.route("/api/search", get({
|
||||||
|
let state_clone = app_state.handler.state.clone();
|
||||||
|
move |axum::extract::Query(params): axum::extract::Query<std::collections::HashMap<String, String>>| async move {
|
||||||
|
if let Some(q) = params.get("q") {
|
||||||
|
if let Ok(idx) = state_clone.search_index.read() {
|
||||||
|
if let Ok(results) = idx.search(q, None) {
|
||||||
|
let mut formatted_results = Vec::new();
|
||||||
|
for (type_name, content) in results {
|
||||||
|
formatted_results.push(serde_json::json!({
|
||||||
|
"type_name": type_name,
|
||||||
|
"content": content,
|
||||||
|
"score": 1.0
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return axum::Json(serde_json::json!({ "results": formatted_results }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
axum::Json(serde_json::json!({ "results": [] }))
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.route("/api/stats",
|
||||||
get({
|
get({
|
||||||
let state_clone = app_state.handler.state.clone();
|
let state_clone = app_state.handler.state.clone();
|
||||||
move || async move {
|
move || async move {
|
||||||
@@ -716,3 +750,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
run_server(state)
|
run_server(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user