diff --git a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx b/skyvern-frontend/src/routes/tasks/detail/Artifact.tsx similarity index 65% rename from skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx rename to skyvern-frontend/src/routes/tasks/detail/Artifact.tsx index a28a18e4..f90985f4 100644 --- a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx +++ b/skyvern-frontend/src/routes/tasks/detail/Artifact.tsx @@ -1,7 +1,7 @@ import { artifactApiClient } from "@/api/AxiosClient"; import { ArtifactApiResponse } from "@/api/types"; import { Skeleton } from "@/components/ui/skeleton"; -import { Textarea } from "@/components/ui/textarea"; +import { CodeEditor } from "@/routes/workflows/components/CodeEditor"; import { useQueries } from "@tanstack/react-query"; import axios from "axios"; @@ -26,15 +26,38 @@ function format(html: string) { return result.substring(1, result.length - 3); } +function getFormattedResult(type: "json" | "html" | "text", result: unknown) { + switch (type) { + case "json": + return JSON.stringify(result, null, 2); + case "html": + return format(result as string); + case "text": + return result; + } +} + +function getEndpoint(type: "json" | "html" | "text") { + switch (type) { + case "json": + return "/artifact/json"; + case "html": + case "text": + return "/artifact/text"; + } +} + type Props = { + type: "json" | "html" | "text"; artifacts: Array; }; -function HTMLArtifact({ artifacts }: Props) { +function Artifact({ type, artifacts }: Props) { function fetchArtifact(artifact: ArtifactApiResponse) { if (artifact.uri.startsWith("file://")) { + const endpoint = getEndpoint(type); return artifactApiClient - .get(`/artifact/text`, { + .get(endpoint, { params: { path: artifact.uri.slice(7), }, @@ -61,17 +84,21 @@ function HTMLArtifact({ artifacts }: Props) { } return ( -