-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔄 synced local 'skyvern-frontend/src/' with remote 'skyvern-frontend/…
…src/' <!-- ELLIPSIS_HIDDEN --> | 🚀 | This description was created by [Ellipsis](https://www.ellipsis.dev) for commit e3ddc5bda7d296d2e5e8b9eb02f3da105be0e2e1 | |--------|--------| ### Summary: This PR introduces a new artifact type `VisibleElementsTreeInPrompt` and a corresponding `HTMLArtifact` component to fetch and display formatted HTML data in the `StepArtifacts` component. **Key points**: - Added `VisibleElementsTreeInPrompt` to `ArtifactType` in `skyvern-frontend/src/api/types.ts`. - Created `HTMLArtifact` component in `skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx` to fetch and format HTML data. - Updated `StepArtifacts` in `skyvern-frontend/src/routes/tasks/detail/StepArtifacts.tsx` to use `HTMLArtifact` for `VisibleElementsTreeInPrompt` artifacts. ---- Generated with ❤️ by [ellipsis.dev](https://www.ellipsis.dev) <!-- ELLIPSIS_HIDDEN -->
- Loading branch information
Showing
3 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { artifactApiClient } from "@/api/AxiosClient"; | ||
import { ArtifactApiResponse } from "@/api/types"; | ||
import { Skeleton } from "@/components/ui/skeleton"; | ||
import { Textarea } from "@/components/ui/textarea"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import axios from "axios"; | ||
|
||
// https://stackoverflow.com/a/60338028 | ||
function format(html: string) { | ||
const tab = "\t"; | ||
let result = ""; | ||
let indent = ""; | ||
|
||
html.split(/>\s*</).forEach(function (element) { | ||
if (element.match(/^\/\w/)) { | ||
indent = indent.substring(tab.length); | ||
} | ||
|
||
result += indent + "<" + element + ">\r\n"; | ||
|
||
if (element.match(/^<?\w[^>]*[^/]$/) && !element.startsWith("input")) { | ||
indent += tab; | ||
} | ||
}); | ||
|
||
return result.substring(1, result.length - 3); | ||
} | ||
|
||
type Props = { | ||
artifact: ArtifactApiResponse; | ||
}; | ||
|
||
function HTMLArtifact({ artifact }: Props) { | ||
const { data, isFetching, isError, error } = useQuery<string>({ | ||
queryKey: ["artifact", artifact.artifact_id], | ||
queryFn: async () => { | ||
if (artifact.uri.startsWith("file://")) { | ||
return artifactApiClient | ||
.get(`/artifact/text`, { | ||
params: { | ||
path: artifact.uri.slice(7), | ||
}, | ||
}) | ||
.then((response) => response.data); | ||
} | ||
if (artifact.uri.startsWith("s3://") && artifact.signed_url) { | ||
return axios.get(artifact.signed_url).then((response) => response.data); | ||
} | ||
}, | ||
}); | ||
|
||
if (isFetching) { | ||
return <Skeleton className="h-48 w-full" />; | ||
} | ||
|
||
return ( | ||
<Textarea | ||
className="w-full" | ||
rows={15} | ||
value={isError ? JSON.stringify(error) : format(data ?? "")} | ||
readOnly | ||
/> | ||
); | ||
} | ||
|
||
export { HTMLArtifact }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters