Fix multiple artifact in action list (#722)
This commit is contained in:
@@ -2,45 +2,58 @@ 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>
|
if (artifact.uri.startsWith("file://")) {
|
||||||
>({
|
return artifactApiClient
|
||||||
queryKey: ["artifact", artifact.artifact_id],
|
.get(`/artifact/json`, {
|
||||||
queryFn: async () => {
|
params: {
|
||||||
if (artifact.uri.startsWith("file://")) {
|
path: artifact.uri.slice(7),
|
||||||
return artifactApiClient
|
},
|
||||||
.get(`/artifact/json`, {
|
})
|
||||||
params: {
|
.then((response) => response.data);
|
||||||
path: artifact.uri.slice(7),
|
}
|
||||||
},
|
if (artifact.uri.startsWith("s3://") && artifact.signed_url) {
|
||||||
})
|
return axios.get(artifact.signed_url).then((response) => response.data);
|
||||||
.then((response) => response.data);
|
}
|
||||||
}
|
}
|
||||||
if (artifact.uri.startsWith("s3://") && artifact.signed_url) {
|
|
||||||
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
|
<>
|
||||||
className="w-full"
|
<Textarea
|
||||||
rows={15}
|
className="w-full"
|
||||||
value={isError ? JSON.stringify(error) : JSON.stringify(data, null, 2)}
|
rows={15}
|
||||||
readOnly
|
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
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user