mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
fix: tidy the mcp show tool text fallbacks (#12713)
* fix: address cubic nits on the mcp show tool texts * fix: mark a live log line that starts mid-line
This commit is contained in:
@@ -2195,17 +2195,6 @@ pub(super) async fn show_deploy_review(ctx: &Ctx<'_>, args: &Value) -> ToolResul
|
||||
" Only the first {MAX_REVIEW_ITEMS} of {total} are shown."
|
||||
));
|
||||
}
|
||||
let rest: Vec<&str> = items
|
||||
.iter()
|
||||
.filter(|item| item.get("digest").is_none())
|
||||
.filter_map(|item| item.get("name").unwrap_or(&item["path"]).as_str())
|
||||
.collect();
|
||||
if !rest.is_empty() {
|
||||
text.push_str(&format!(
|
||||
" Nothing to deploy for {} (no change, or not deployable this way).",
|
||||
rest.join(", ")
|
||||
));
|
||||
}
|
||||
for line in item_lines {
|
||||
text.push_str(&format!("\n{line}"));
|
||||
}
|
||||
|
||||
@@ -2369,14 +2369,22 @@ async fn read_run(ctx: &Ctx<'_>, args: &Value, card: bool) -> ToolResult {
|
||||
.filter_map(|e| e["job_id"].as_str())
|
||||
.last();
|
||||
let live = match running {
|
||||
Some(step) => log_tail(ctx, step, 400).await.map(|(tail, _)| tail),
|
||||
None => logs.map(|(tail, _)| tail),
|
||||
Some(step) => log_tail(ctx, step, 400).await,
|
||||
None => logs,
|
||||
};
|
||||
if let Some(line) = live
|
||||
.as_deref()
|
||||
.and_then(|l| l.lines().rev().find(|l| !l.trim().is_empty()))
|
||||
{
|
||||
details.insert("live_log".into(), js_head(line.trim(), 300).into());
|
||||
if let Some((tail, tail_cut)) = &live {
|
||||
let lines: Vec<&str> = tail.lines().collect();
|
||||
let last = lines.iter().rposition(|l| !l.trim().is_empty());
|
||||
if let Some((i, line)) = last.map(|i| (i, lines[i])) {
|
||||
// The tail's first line starts where the read did, often mid-line.
|
||||
let lead = if *tail_cut && i == 0 { "…" } else { "" };
|
||||
let line = line.trim();
|
||||
let head = js_head(line, 300);
|
||||
if head.len() < line.len() {
|
||||
details.insert("live_log_cut".into(), true.into());
|
||||
}
|
||||
details.insert("live_log".into(), format!("{lead}{head}").into());
|
||||
}
|
||||
}
|
||||
}
|
||||
match big_image_result(ctx, id, job, entries.first()).await {
|
||||
@@ -2577,10 +2585,13 @@ fn run_text(run: &Map<String, Value>) -> String {
|
||||
};
|
||||
if let Some((label, value)) = preview {
|
||||
let head = js_head(value, TEXT_PREVIEW_CHARS);
|
||||
let flag = |key: &str| run.get(key) == Some(&Value::Bool(true));
|
||||
let cut = head.len() < value.len()
|
||||
|| (finished
|
||||
&& value != TOO_BIG_TEXT
|
||||
&& run.get("result_cut") == Some(&Value::Bool(true)));
|
||||
|| if finished {
|
||||
value != TOO_BIG_TEXT && flag("result_cut")
|
||||
} else {
|
||||
flag("live_log_cut")
|
||||
};
|
||||
lines.push(format!("{label}: {head}{}", if cut { "…" } else { "" }));
|
||||
}
|
||||
if let Some(url) = text("url") {
|
||||
@@ -2605,7 +2616,11 @@ fn runs_text(runs: &[Value]) -> String {
|
||||
}
|
||||
}
|
||||
let counts: Vec<String> = counts.iter().map(|(s, n)| format!("{n} {s}")).collect();
|
||||
let mut lines = vec![format!("{} run(s): {}.", runs.len(), counts.join(", "))];
|
||||
let mut lines = vec![if counts.is_empty() {
|
||||
"0 run(s).".to_string()
|
||||
} else {
|
||||
format!("{} run(s): {}.", runs.len(), counts.join(", "))
|
||||
}];
|
||||
for run in runs {
|
||||
let what = run["path"]
|
||||
.as_str()
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) fn definitions() -> [(&'static str, &'static str, Value); 5] {
|
||||
),
|
||||
(
|
||||
"show_run",
|
||||
"Show a run to the user as a live card in the conversation: status, result, steps and logs, refreshing until it finishes, with a link to it in Windmill and a button to cancel it while it runs. Call it after starting a run the user asked for, or when they ask to see one, and once per run: the card refreshes itself. Do not call it for runs you start to check your own work: read those with get_run.",
|
||||
"Show a run to the user as a live card in the conversation: status, result, steps and logs, refreshing until it finishes, with a link to it in Windmill and a button to cancel it while it runs. Call it after starting a run the user asked for, or when they ask to see one. Do not call it again to follow a run, and do not call it for runs you start to check your own work: read those with get_run.",
|
||||
json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1721,6 +1721,9 @@ pub(super) async fn show_item(ctx: &Ctx<'_>, args: &Value) -> ToolResult {
|
||||
if let Some(edit_url) = edit_url.as_ref().filter(|e| Some(*e) != page_url.as_ref()) {
|
||||
text.push_str(&format!("\nEdit: {edit_url}"));
|
||||
}
|
||||
if let Some(runs_url) = &runs_url {
|
||||
text.push_str(&format!("\nWhat it runs: {runs_url}"));
|
||||
}
|
||||
text.push_str(&format!("\n{}", super::views::CARD_NOTE));
|
||||
ctx.set_view(
|
||||
"windmill/item",
|
||||
|
||||
Reference in New Issue
Block a user