Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(artifact): show real filename on workflow run download links (#6137)
Shuchang Zheng6c40f8dba49c
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.tsindex b5bc1f3c9..331ca9eaf 100644--- a/skyvern-frontend/src/api/types.ts+++ b/skyvern-frontend/src/api/types.ts@@ -1,5 +1,14 @@import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";+export type DownloadedFileInfo = {+ url: string;+ filename: string | null;+ checksum: string | null;+ file_size: number | null;+ modified_at: string | null;+ artifact_id: string | null;+};+export const ArtifactType = {Recording: "recording",ActionScreenshot: "screenshot_action",@@ -592,6 +601,7 @@ export type WorkflowRunStatusApiResponse = {failure_category: Array<FailureCategory> | null;webhook_failure_reason: string | null;downloaded_file_urls: Array<string> | null;+ downloaded_files: Array<DownloadedFileInfo> | null;total_steps: number | null;total_cost: number | null;credits_used: number;@@ -628,6 +638,7 @@ export type WorkflowRunStatusApiResponseWithWorkflow = {failure_category: Array<FailureCategory> | null;webhook_failure_reason: string | null;downloaded_file_urls: Array<string> | null;+ downloaded_files: Array<DownloadedFileInfo> | null;total_steps: number | null;total_cost: number | null;credits_used: number;diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsxindex d13c60069..110b879c9 100644--- a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx+++ b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx@@ -40,7 +40,7 @@ import { useWorkflowRunWithWorkflowQuery } from "./hooks/useWorkflowRunWithWorkfimport { WorkflowRunTimeline } from "./workflowRun/WorkflowRunTimeline";import { useWorkflowRunTimelineQuery } from "./hooks/useWorkflowRunTimelineQuery";import { findActiveItem } from "./workflowRun/workflowTimelineUtils";-import { filenameForDownloadedFileUrl } from "./workflowRun/blockDownloadedFiles";+import { pickDownloadedFileFilename } from "./workflowRun/blockDownloadedFiles";import { isBlockItem } from "./types/workflowRunTypes";import { Label } from "@/components/ui/label";import { CodeEditor } from "./components/CodeEditor";@@ -303,6 +303,16 @@ function WorkflowRun() {const fileUrls = hasFileUrls? (workflowRun.downloaded_file_urls as string[]): [];+ // Prefer the rich downloaded_files array (carries filename, checksum, size)+ // when the backend sends it; falls back to URL parsing otherwise.+ const filenameByUrl = new Map<string, string>();+ if (workflowRun?.downloaded_files) {+ for (const file of workflowRun.downloaded_files) {+ if (file.filename) {+ filenameByUrl.set(file.url, file.filename);+ }+ }+ }const showBoth =(hasSomeExtractedInformation || hasTaskv2Output) && hasFileUrls;@@ -547,7 +557,10 @@ function WorkflowRun() {<ScrollAreaViewport className="max-h-[250px] space-y-2">{fileUrls.length > 0 ? (fileUrls.map((url) => {- const filename = filenameForDownloadedFileUrl(url);+ const filename = pickDownloadedFileFilename(+ url,+ filenameByUrl,+ );return (<div key={url} title={url} className="flex gap-2"><FileIcon className="size-6" />diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsxindex 460f34fdd..4aef52f3f 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx@@ -18,7 +18,7 @@ import { SummarizeOutput } from "@/components/SummarizeOutput";import { isTaskVariantBlock } from "../types/workflowTypes";import { statusIsAFailureType } from "@/routes/tasks/types";import {- filenameForDownloadedFileUrl,+ pickDownloadedFileFilename,getBlockDownloadedFileUrls,} from "./blockDownloadedFiles";@@ -155,6 +155,15 @@ function WorkflowRunOutput() {const allFileUrls = workflowRun?.downloaded_file_urls ?? [];+ // Prefer the rich downloaded_files array (carries filename) when the backend+ // sends it; falls back to URL parsing otherwise.+ const filenameByUrl = new Map<string, string>();+ for (const file of workflowRun?.downloaded_files ?? []) {+ if (file.filename) {+ filenameByUrl.set(file.url, file.filename);+ }+ }+// 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@@ -347,7 +356,7 @@ function WorkflowRunOutput() {<div className="space-y-2">{fileUrls.length > 0 ? (fileUrls.map((url) => {- const filename = filenameForDownloadedFileUrl(url);+ const filename = pickDownloadedFileFilename(url, filenameByUrl);return (<div key={url} title={url} className="flex gap-2"><FileIcon className="size-6" />diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.tsindex 6514aa37b..56777d80e 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.test.ts@@ -2,6 +2,7 @@ import { describe, expect, test } from "vitest";import {filenameForDownloadedFileUrl,getBlockDownloadedFileUrls,+ pickDownloadedFileFilename,} from "./blockDownloadedFiles";describe("filenameForDownloadedFileUrl", () => {@@ -117,3 +118,23 @@ describe("getBlockDownloadedFileUrls", () => {]);});});++describe("pickDownloadedFileFilename", () => {+ test("prefers the map entry over URL parsing", () => {+ const url = "https://api.skyvern.com/v1/artifacts/a_1/content?sig=x";+ const map = new Map([[url, "invoice-2026.pdf"]]);+ expect(pickDownloadedFileFilename(url, map)).toBe("invoice-2026.pdf");+ });++ test("falls back to URL parsing when no map entry is present", () => {+ const url =+ "https://api.skyvern.com/v1/artifacts/a_1/content" ++ "?sig=x&artifact_name=from-url.pdf";+ expect(pickDownloadedFileFilename(url, new Map())).toBe("from-url.pdf");+ });++ test("falls back to 'download' label when URL has no usable filename", () => {+ const url = "https://api.skyvern.com/v1/artifacts/a_1/content?sig=x";+ expect(pickDownloadedFileFilename(url, new Map())).toBe("download");+ });+});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.tsindex 57fa476da..ee5a6b06e 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDownloadedFiles.ts@@ -46,6 +46,21 @@ function filenameForDownloadedFileUrl(url: string): string {}}+/**+ * Pick the filename for a downloaded-file URL, preferring the rich+ * ``downloaded_files`` map (carries the filename directly from the artifact+ * row) and falling back to URL parsing when the entry is missing.+ *+ * The map should be keyed by URL — callers typically iterate+ * ``workflowRun.downloaded_files`` once to build it.+ */+function pickDownloadedFileFilename(+ url: string,+ filenameByUrl: ReadonlyMap<string, string>,+): string {+ return filenameByUrl.get(url) ?? filenameForDownloadedFileUrl(url);+}+function getBlockDownloadedFileUrls(blockOutput: object | Array<unknown> | string | null | undefined,freshFallbackUrls: ReadonlyArray<string>,@@ -79,4 +94,8 @@ function getBlockDownloadedFileUrls(return blockUrls.map((url) => freshByPath.get(urlKey(url)) ?? url);}-export { filenameForDownloadedFileUrl, getBlockDownloadedFileUrls };+export {+ filenameForDownloadedFileUrl,+ getBlockDownloadedFileUrls,+ pickDownloadedFileFilename,+};diff --git a/skyvern/forge/sdk/artifact/manager.py b/skyvern/forge/sdk/artifact/manager.pyindex 86f7f509d..7ce6984e5 100644--- a/skyvern/forge/sdk/artifact/manager.py+++ b/skyvern/forge/sdk/artifact/manager.py@@ -1120,9 +1120,17 @@ class ArtifactManager:storage backend's presigned URL (S3 / Azure SAS / local URI)."""if _bundling_enabled() or artifact.bundle_key:+ # Frontend parses ``artifact_name`` out of the URL query for the+ # download-files display. Bundled members carry the in-ZIP filename+ # in ``bundle_key``; non-bundled artifacts have it as the URI+ # basename. Without this fallback the path basename is just+ # "content" and the UI falls back to a literal "download" label.+ artifact_name = artifact.bundle_key+ if artifact_name is None and artifact.uri:+ artifact_name = artifact.uri.rsplit("/", 1)[-1] or Nonereturn self._bundle_content_url(artifact.artifact_id,- artifact_name=artifact.bundle_key,+ artifact_name=artifact_name,artifact_type=artifact.artifact_type,expiry_seconds=expiry_seconds,)diff --git a/tests/unit/test_self_host_artifact_url_fallback.py b/tests/unit/test_self_host_artifact_url_fallback.pyindex 29470ad89..93dc56fbc 100644--- a/tests/unit/test_self_host_artifact_url_fallback.py+++ b/tests/unit/test_self_host_artifact_url_fallback.py@@ -85,6 +85,20 @@ class TestResolveShareUrl:assert bundle.call_args.kwargs["artifact_name"] == "screenshot_action_0.png"app.STORAGE.get_share_link.assert_not_awaited()+ @pytest.mark.asyncio+ async def test_keyring_set_non_bundled_derives_artifact_name_from_uri(self) -> None:+ """Frontend parses ?artifact_name= out of the URL. Non-bundled artifacts have+ no bundle_key, so we must fall back to the URI basename — otherwise the path+ basename is "content" and the UI falls back to a literal "download" label."""+ manager = ArtifactManager()+ artifact = _artifact("a_dl", uri="s3://bucket/downloads/o_1/wr_1/invoice-2026.pdf")+ with (+ patch.object(settings, "ARTIFACT_CONTENT_HMAC_KEYRING", _DUMMY_KEYRING_JSON),+ patch.object(manager, "_bundle_content_url", return_value="https://api/x") as bundle,+ ):+ await manager.resolve_share_url(artifact, expiry_seconds=3600)+ assert bundle.call_args.kwargs["artifact_name"] == "invoice-2026.pdf"+@pytest.mark.asyncioasync def test_keyring_unset_non_bundled_returns_storage_presigned(self) -> None:manager = ArtifactManager()