api: convert tool_input JSON to YAML in execution log response

This commit is contained in:
Fam Zheng
2026-03-11 12:43:35 +00:00
parent 63bbbae17c
commit 30e25f589b

View File

@@ -82,6 +82,29 @@ async fn create_workflow(
Ok(Json(workflow)) Ok(Json(workflow))
} }
/// Convert a JSON string to a simple YAML-like representation for display.
/// Falls back to the original string if it's not a JSON object.
fn json_to_yaml(input: &str) -> String {
let obj: serde_json::Map<String, serde_json::Value> = match serde_json::from_str(input) {
Ok(v) => v,
Err(_) => return input.to_string(),
};
let mut lines = Vec::new();
for (k, v) in &obj {
match v {
serde_json::Value::String(s) if s.contains('\n') => {
lines.push(format!("{}: |", k));
for line in s.lines() {
lines.push(format!(" {}", line));
}
}
serde_json::Value::String(s) => lines.push(format!("{}: {}", k, s)),
other => lines.push(format!("{}: {}", k, other)),
}
}
lines.join("\n")
}
async fn list_steps( async fn list_steps(
State(state): State<Arc<AppState>>, State(state): State<Arc<AppState>>,
Path(workflow_id): Path<String>, Path(workflow_id): Path<String>,
@@ -92,7 +115,10 @@ async fn list_steps(
.bind(&workflow_id) .bind(&workflow_id)
.fetch_all(&state.db.pool) .fetch_all(&state.db.pool)
.await .await
.map(Json) .map(|entries| Json(entries.into_iter().map(|mut e| {
e.tool_input = json_to_yaml(&e.tool_input);
e
}).collect()))
.map_err(db_err) .map_err(db_err)
} }