Fix multiple artifact in action list (#722)

This commit is contained in:
Kerem Yilmaz
2024-08-24 00:19:04 +03:00
committed by GitHub
parent 047e534194
commit ecea284284
2 changed files with 49 additions and 36 deletions

View File

@@ -2,19 +2,15 @@ import { artifactApiClient } from "@/api/AxiosClient";
import { ArtifactApiResponse } from "@/api/types"; import { ArtifactApiResponse } from "@/api/types";
import { Skeleton } from "@/components/ui/skeleton"; import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
import { useQuery } from "@tanstack/react-query"; import { useQueries } from "@tanstack/react-query";
import axios from "axios"; import axios from "axios";
type Props = { type Props = {
artifact: ArtifactApiResponse; artifacts: Array<ArtifactApiResponse>;
}; };
function JSONArtifact({ artifact }: Props) { function JSONArtifact({ artifacts }: Props) {
const { data, isFetching, isError, error } = useQuery< function fetchArtifact(artifact: ArtifactApiResponse) {
Record<string, unknown>
>({
queryKey: ["artifact", artifact.artifact_id],
queryFn: async () => {
if (artifact.uri.startsWith("file://")) { if (artifact.uri.startsWith("file://")) {
return artifactApiClient return artifactApiClient
.get(`/artifact/json`, { .get(`/artifact/json`, {
@@ -27,20 +23,37 @@ function JSONArtifact({ artifact }: Props) {
if (artifact.uri.startsWith("s3://") && artifact.signed_url) { if (artifact.uri.startsWith("s3://") && artifact.signed_url) {
return axios.get(artifact.signed_url).then((response) => response.data); return axios.get(artifact.signed_url).then((response) => response.data);
} }
}, }
const results = useQueries({
queries:
artifacts?.map((artifact) => {
return {
queryKey: ["artifact", artifact.artifact_id],
queryFn: () => fetchArtifact(artifact),
};
}) ?? [],
}); });
if (isFetching) { if (results.some((result) => result.isLoading)) {
return <Skeleton className="h-48 w-full" />; return <Skeleton className="h-48 w-full" />;
} }
return ( return (
<>
<Textarea <Textarea
className="w-full" className="w-full"
rows={15} rows={15}
value={isError ? JSON.stringify(error) : JSON.stringify(data, null, 2)} value={
results.some((result) => result.isError)
? JSON.stringify(results.find((result) => result.isError)?.error)
: results
.map((result) => JSON.stringify(result.data, null, 2))
.join(",\n")
}
readOnly readOnly
/> />
</>
); );
} }

View File

@@ -53,15 +53,15 @@ function StepArtifacts({ id, stepProps }: Props) {
(artifact) => artifact.artifact_type === ArtifactType.ActionScreenshot, (artifact) => artifact.artifact_type === ArtifactType.ActionScreenshot,
); );
const visibleElementsTree = artifacts?.find( const visibleElementsTree = artifacts?.filter(
(artifact) => artifact.artifact_type === ArtifactType.VisibleElementsTree, (artifact) => artifact.artifact_type === ArtifactType.VisibleElementsTree,
); );
const llmRequest = artifacts?.find( const llmRequest = artifacts?.filter(
(artifact) => artifact.artifact_type === ArtifactType.LLMRequest, (artifact) => artifact.artifact_type === ArtifactType.LLMRequest,
); );
const visibleElementsTreeTrimmed = artifacts?.find( const visibleElementsTreeTrimmed = artifacts?.filter(
(artifact) => (artifact) =>
artifact.artifact_type === ArtifactType.VisibleElementsTreeTrimmed, artifact.artifact_type === ArtifactType.VisibleElementsTreeTrimmed,
); );
@@ -70,7 +70,7 @@ function StepArtifacts({ id, stepProps }: Props) {
(artifact) => artifact.artifact_type === ArtifactType.LLMPrompt, (artifact) => artifact.artifact_type === ArtifactType.LLMPrompt,
); );
const llmResponseParsed = artifacts?.find( const llmResponseParsed = artifacts?.filter(
(artifact) => artifact.artifact_type === ArtifactType.LLMResponseParsed, (artifact) => artifact.artifact_type === ArtifactType.LLMResponseParsed,
); );
@@ -165,12 +165,12 @@ function StepArtifacts({ id, stepProps }: Props) {
</TabsContent> </TabsContent>
<TabsContent value="element_tree_trimmed"> <TabsContent value="element_tree_trimmed">
{visibleElementsTreeTrimmed ? ( {visibleElementsTreeTrimmed ? (
<JSONArtifact artifact={visibleElementsTreeTrimmed} /> <JSONArtifact artifacts={visibleElementsTreeTrimmed} />
) : null} ) : null}
</TabsContent> </TabsContent>
<TabsContent value="html_element_tree"> <TabsContent value="html_element_tree">
{visibleElementsTree ? ( {visibleElementsTree ? (
<JSONArtifact artifact={visibleElementsTree} /> <JSONArtifact artifacts={visibleElementsTree} />
) : null} ) : null}
</TabsContent> </TabsContent>
<TabsContent value="llm_prompt"> <TabsContent value="llm_prompt">
@@ -178,14 +178,14 @@ function StepArtifacts({ id, stepProps }: Props) {
</TabsContent> </TabsContent>
<TabsContent value="llm_response_parsed"> <TabsContent value="llm_response_parsed">
{llmResponseParsed ? ( {llmResponseParsed ? (
<JSONArtifact artifact={llmResponseParsed} /> <JSONArtifact artifacts={llmResponseParsed} />
) : null} ) : null}
</TabsContent> </TabsContent>
<TabsContent value="html_raw"> <TabsContent value="html_raw">
{htmlRaw ? <TextArtifact artifact={htmlRaw} /> : null} {htmlRaw ? <TextArtifact artifact={htmlRaw} /> : null}
</TabsContent> </TabsContent>
<TabsContent value="llm_request"> <TabsContent value="llm_request">
{llmRequest ? <JSONArtifact artifact={llmRequest} /> : null} {llmRequest ? <JSONArtifact artifacts={llmRequest} /> : null}
</TabsContent> </TabsContent>
</Tabs> </Tabs>
); );