Skip to content

Automate browser based workflows with AI

feat: show downloaded files only for selected block (SKY-8856) (#5496)

Aaron Perez4220577eeb5b
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx
index f1bd45212..c57c391e5 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx
@@ -1,4 +1,7 @@
import { FileIcon } from "@radix-ui/react-icons";
+import { useEffect, useState } from "react";
+import { useSearchParams } from "react-router-dom";
+import { Button } from "@/components/ui/button";
import { CodeEditor } from "../components/CodeEditor";
import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";
import { useActiveWorkflowRunItem } from "./useActiveWorkflowRunItem";
@@ -13,24 +16,24 @@ import { Status } from "@/api/types";
import { AutoResizingTextarea } from "@/components/AutoResizingTextarea/AutoResizingTextarea";
import { isTaskVariantBlock } from "../types/workflowTypes";
import { statusIsAFailureType } from "@/routes/tasks/types";
+import { getBlockDownloadedFileUrls } from "./blockDownloadedFiles";
function WorkflowRunOutput() {
+ const [searchParams] = useSearchParams();
+ const hasExplicitSelection = searchParams.has("active");
const { data: workflowRunTimeline, isLoading: workflowRunTimelineIsLoading } =
useWorkflowRunTimelineQuery();
const [activeItem] = useActiveWorkflowRunItem();
const { data: workflowRun } = useWorkflowRunWithWorkflowQuery();
- if (workflowRunTimelineIsLoading) {
- return <div>Loading...</div>;
- }
-
- if (!workflowRunTimeline) {
- return null;
- }
+ // Local override so users on finalized runs (where there is no neutral
+ // timeline selection to return to) can still view the full workflow-level
+ // file list without clearing their block selection elsewhere on the page.
+ const [showAllFilesOverride, setShowAllFilesOverride] = useState(false);
- function getActiveBlock() {
+ const activeBlock = (() => {
if (!workflowRunTimeline) {
- return;
+ return undefined;
}
if (isWorkflowRunBlock(activeItem)) {
return activeItem;
@@ -41,9 +44,20 @@ function WorkflowRunOutput() {
activeItem.action_id,
);
}
+ return undefined;
+ })();
+ const activeBlockId = activeBlock?.workflow_run_block_id;
+ useEffect(() => {
+ setShowAllFilesOverride(false);
+ }, [activeBlockId]);
+
+ if (workflowRunTimelineIsLoading) {
+ return <div>Loading...</div>;
}
- const activeBlock = getActiveBlock();
+ if (!workflowRunTimeline) {
+ return null;
+ }
const showExtractedInformation =
activeBlock &&
@@ -57,7 +71,18 @@ function WorkflowRunOutput() {
activeBlock.status === Status.Canceled);
const outputs = workflowRun?.outputs;
- const fileUrls = workflowRun?.downloaded_file_urls ?? [];
+ const allFileUrls = workflowRun?.downloaded_file_urls ?? [];
+
+ // Scope to the surrounding block whenever the user explicitly selected a
+ // block or any action inside it, so drilling from a block into its child
+ // steps keeps the files section anchored to that block. The helper swaps
+ // expired block URLs for matching fresh run-level ones when available.
+ const userSelectedBlock = Boolean(hasExplicitSelection && activeBlock);
+ const showBlockFiles = userSelectedBlock && !showAllFilesOverride;
+ const fileUrls =
+ showBlockFiles && activeBlock
+ ? getBlockDownloadedFileUrls(activeBlock.output, allFileUrls)
+ : allFileUrls;
const observerOutput = workflowRun?.task_v2?.output;
const webhookFailureReasonData =
workflowRun?.task_v2?.webhook_failure_reason ??
@@ -153,7 +178,25 @@ function WorkflowRunOutput() {
</div>
<div className="rounded bg-slate-elevation2 p-6">
<div className="space-y-4">
- <h1 className="text-lg font-bold">Workflow Run Downloaded Files</h1>
+ <div className="flex items-center justify-between">
+ <h1 className="text-lg font-bold">
+ {showBlockFiles
+ ? "Block Downloaded Files"
+ : "Workflow Run Downloaded Files"}
+ </h1>
+ {userSelectedBlock ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-7 px-2.5 text-xs"
+ onClick={() => setShowAllFilesOverride((v) => !v)}
+ >
+ {showAllFilesOverride
+ ? "Show block files"
+ : "Show all workflow files"}
+ </Button>
+ ) : null}
+ </div>
<div className="space-y-2">
{fileUrls.length > 0 ? (
fileUrls.map((url) => {
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts
new file mode 100644
index 000000000..cff36a6f0
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts
@@ -0,0 +1,74 @@
+import { describe, expect, test } from "vitest";
+import { getBlockDownloadedFileUrls } from "./blockDownloadedFiles";
+
+describe("getBlockDownloadedFileUrls", () => {
+ test("returns [] when blockOutput is null/undefined/string/array", () => {
+ expect(getBlockDownloadedFileUrls(null, [])).toEqual([]);
+ expect(getBlockDownloadedFileUrls(undefined, [])).toEqual([]);
+ expect(getBlockDownloadedFileUrls("str", [])).toEqual([]);
+ expect(getBlockDownloadedFileUrls([1, 2], [])).toEqual([]);
+ });
+
+ test("returns [] when downloaded_file_urls is missing or not an array", () => {
+ expect(getBlockDownloadedFileUrls({}, [])).toEqual([]);
+ expect(
+ getBlockDownloadedFileUrls({ downloaded_file_urls: "nope" }, []),
+ ).toEqual([]);
+ });
+
+ test("filters non-string elements out of the persisted list", () => {
+ const output = {
+ downloaded_file_urls: [
+ "https://s3/a/f.pdf?sig=old",
+ null,
+ 42,
+ "https://s3/b/g.pdf?sig=old",
+ ],
+ };
+ expect(getBlockDownloadedFileUrls(output, [])).toEqual([
+ "https://s3/a/f.pdf?sig=old",
+ "https://s3/b/g.pdf?sig=old",
+ ]);
+ });
+
+ test("swaps expired block URLs for fresh run-level URLs by path", () => {
+ const output = {
+ downloaded_file_urls: [
+ "https://s3/a/f.pdf?sig=expired",
+ "https://s3/b/g.pdf?sig=expired",
+ ],
+ };
+ const fresh = [
+ "https://s3/a/f.pdf?sig=fresh",
+ "https://s3/b/g.pdf?sig=fresh",
+ "https://s3/c/unrelated.pdf?sig=fresh",
+ ];
+ expect(getBlockDownloadedFileUrls(output, fresh)).toEqual([
+ "https://s3/a/f.pdf?sig=fresh",
+ "https://s3/b/g.pdf?sig=fresh",
+ ]);
+ });
+
+ test("falls back to the persisted URL when no fresh match exists", () => {
+ const output = {
+ downloaded_file_urls: ["https://s3/a/f.pdf?sig=expired"],
+ };
+ expect(getBlockDownloadedFileUrls(output, [])).toEqual([
+ "https://s3/a/f.pdf?sig=expired",
+ ]);
+ });
+
+ test("preserves block order and scope even when fresh list has more entries", () => {
+ const output = {
+ downloaded_file_urls: ["https://s3/b/g.pdf?sig=old"],
+ };
+ const fresh = [
+ "https://s3/a/f.pdf?sig=fresh",
+ "https://s3/b/g.pdf?sig=fresh",
+ "https://s3/c/h.pdf?sig=fresh",
+ ];
+ expect(getBlockDownloadedFileUrls(output, fresh)).toEqual([
+ "https://s3/b/g.pdf?sig=fresh",
+ ]);
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts
new file mode 100644
index 000000000..5e4eebf34
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts
@@ -0,0 +1,44 @@
+// The workflow-run-level downloaded_file_urls is regenerated with fresh
+// presigned URLs on every API fetch, while a block's output.downloaded_file_urls
+// was persisted at execution time and will expire after PRESIGNED_URL_EXPIRATION.
+// For runs older than that TTL we swap each block URL for the matching run-level
+// one (keyed by the URL path before the signed query string), falling back to
+// the original if no match is found.
+function urlKey(url: string): string {
+ return url.split("?")[0] ?? url;
+}
+
+function getBlockDownloadedFileUrls(
+ blockOutput: object | Array<unknown> | string | null | undefined,
+ freshFallbackUrls: ReadonlyArray<string>,
+): Array<string> {
+ if (
+ !blockOutput ||
+ typeof blockOutput !== "object" ||
+ Array.isArray(blockOutput) ||
+ !("downloaded_file_urls" in blockOutput) ||
+ !Array.isArray(
+ (blockOutput as Record<string, unknown>).downloaded_file_urls,
+ )
+ ) {
+ return [];
+ }
+
+ const blockUrls = (
+ (blockOutput as Record<string, unknown>)
+ .downloaded_file_urls as Array<unknown>
+ ).filter((url): url is string => typeof url === "string");
+
+ if (blockUrls.length === 0) {
+ return [];
+ }
+
+ const freshByPath = new Map<string, string>();
+ for (const url of freshFallbackUrls) {
+ freshByPath.set(urlKey(url), url);
+ }
+
+ return blockUrls.map((url) => freshByPath.get(urlKey(url)) ?? url);
+}
+
+export { getBlockDownloadedFileUrls };