From 43a2f66832d3e7a0c8e23193137df1d1aca6b443 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Tue, 1 Dec 2026 04:00:51 -0800 Subject: [PATCH] fix: tell the model a file it cannot read is still open in the side panel Co-Authored-By: Claude Opus 5.5 --- .../windmill-api/src/ai_session_tools/storage.rs | 14 +++++++++++++- .../lib/components/copilot/chat/storageTools.ts | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/windmill-api/src/ai_session_tools/storage.rs b/backend/windmill-api/src/ai_session_tools/storage.rs index dd2605cada..060710c6eb 100644 --- a/backend/windmill-api/src/ai_session_tools/storage.rs +++ b/backend/windmill-api/src/ai_session_tools/storage.rs @@ -252,7 +252,19 @@ async fn read_s3_file(ctx: &Ctx<'_>, args: &Value) -> ToolResult { fit_text(&mut out, content, length < size, csv_cut); } None => { - out.insert("preview_unavailable".into(), preview["msg"].clone()); + // The endpoint's "Preview is not available" reads to a model as if the user + // could not see the file either, even while it is open in the side panel. + let reason = match preview["msg"].as_str() { + Some(m) if m.starts_with("Preview is not available") => { + "it is not a text, table or image file" + } + Some(m) => m, + None => "the server returned no content", + }; + out.insert( + "content".into(), + format!("Not read by this tool: {reason}.").into(), + ); } } } diff --git a/frontend/src/lib/components/copilot/chat/storageTools.ts b/frontend/src/lib/components/copilot/chat/storageTools.ts index a77775b1b1..0e2f5c74c3 100644 --- a/frontend/src/lib/components/copilot/chat/storageTools.ts +++ b/frontend/src/lib/components/copilot/chat/storageTools.ts @@ -130,7 +130,9 @@ export function getStorageTools(): SessionTool<{}>[] { const openS3File = (helpers as GlobalToolHelpers | undefined)?.openS3File if (parsed.open_in_preview) { if (openS3File) openS3File(file) - result.side_panel = openS3File ? 'opened' : 'this chat has no side panel' + result.side_panel = openS3File + ? 'opened: the user now sees the file next to the chat' + : 'this chat has no side panel' } toolCallbacks.setToolStatus(toolId, { content: `Read ${s3}${storageLabel(storage)}`,