MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / node_payload

Function node_payload

src/dashboard/lcm_service.rs:535–626  ·  view source on GitHub ↗
(
    state: &DashboardState,
    node_id: &str,
)

Source from the content-addressed store, hash-verified

533}
534
535pub(crate) async fn node_payload(
536 state: &DashboardState,
537 node_id: &str,
538) -> LcmServiceResult<Map<String, Value>> {
539 let mut payload = json_object(json!({
540 "path": state.lcm_db_path,
541 "storage_scope": state.lcm_scope,
542 "exists": state.lcm_conn.is_some(),
543 "node_id": node_id,
544 "node": null,
545 "sources": { "type": null, "ids": [], "messages": [], "nodes": [] },
546 }));
547 let Some(conn) = state.lcm_conn.as_ref() else {
548 return Ok(payload);
549 };
550 ensure_valid_summary_metadata(state, conn, "node").await?;
551
552 let Some(node_row) =
553 map_query_error("node lookup", lcm_queries::node_row(conn, node_id).await)?
554 else {
555 return Err((
556 StatusCode::NOT_FOUND,
557 Json(http_detail(&format!("summary node not found: {node_id}"))),
558 ));
559 };
560 payload.insert("node".into(), node_row);
561
562 let source_rows = map_query_error(
563 "node sources",
564 lcm_queries::node_source_rows(conn, node_id).await,
565 )?;
566 let mut message_ids: Vec<i64> = Vec::new();
567 let mut child_node_ids: Vec<String> = Vec::new();
568 for row in &source_rows {
569 let kind = row.get("source_kind").and_then(Value::as_str).unwrap_or("");
570 let id = row.get("source_id").and_then(Value::as_str).unwrap_or("");
571 match kind {
572 "raw_message" => {
573 if let Ok(store_id) = id.parse::<i64>() {
574 message_ids.push(store_id);
575 }
576 }
577 "summary_node" => child_node_ids.push(id.to_string()),
578 _ => {}
579 }
580 }
581
582 let source_type = if child_node_ids.is_empty() {
583 "messages"
584 } else {
585 "nodes"
586 };
587 let ids: Vec<Value> = if source_type == "nodes" {
588 child_node_ids.iter().map(|id| json!(id)).collect()
589 } else {
590 message_ids.iter().map(|id| json!(id)).collect()
591 };
592

Callers 2

nodeFunction · 0.70
nodeFunction · 0.70

Calls 13

json_objectFunction · 0.85
map_query_errorFunction · 0.85
http_detailFunction · 0.85
node_source_rowsFunction · 0.85
child_summary_nodesFunction · 0.85
source_messagesFunction · 0.85
parse_summary_node_idsFunction · 0.85
insertMethod · 0.80
pushMethod · 0.80
collectMethod · 0.80
node_rowFunction · 0.70

Tested by

no test coverage detected