From 30e25f589bc3b6c69340eb00845fd91f42a04b02 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 11 Mar 2026 12:43:35 +0000 Subject: [PATCH] api: convert tool_input JSON to YAML in execution log response --- src/api/workflows.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/api/workflows.rs b/src/api/workflows.rs index 317f85c..1cbd8d6 100644 --- a/src/api/workflows.rs +++ b/src/api/workflows.rs @@ -82,6 +82,29 @@ async fn create_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 = 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( State(state): State>, Path(workflow_id): Path, @@ -92,7 +115,10 @@ async fn list_steps( .bind(&workflow_id) .fetch_all(&state.db.pool) .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) }