Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for signed URL artifacts #197

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions skyvern-frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ArtifactApiResponse = {
step_id: string;
artifact_type: ArtifactType;
uri: string;
signed_url?: string | null;
organization_id: string;
};

Expand Down
27 changes: 17 additions & 10 deletions skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
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";

type Props = {
uri: string;
artifact: ArtifactApiResponse;
};

function JSONArtifact({ uri }: Props) {
function JSONArtifact({ artifact }: Props) {
const { data, isFetching, isError, error } = useQuery<
Record<string, unknown>
>({
queryKey: ["artifact", uri],
queryKey: ["artifact", artifact.artifact_id],
queryFn: async () => {
return artifactApiClient
.get(`/artifact/json`, {
params: {
path: uri.slice(7),
},
})
.then((response) => response.data);
if (artifact.uri.startsWith("file://")) {
return artifactApiClient
.get(`/artifact/json`, {
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);
}
},
});

Expand Down
78 changes: 37 additions & 41 deletions skyvern-frontend/src/routes/tasks/detail/StepArtifacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { Label } from "@/components/ui/label";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "react-router-dom";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { artifactApiBaseUrl } from "@/util/env";
import { ZoomableImage } from "@/components/ZoomableImage";
import { Skeleton } from "@/components/ui/skeleton";
import { JSONArtifact } from "./JSONArtifact";
import { TextArtifact } from "./TextArtifact";
import { getImageURL } from "./artifactUtils";

type Props = {
id: string;
Expand All @@ -40,46 +40,42 @@ function StepArtifacts({ id, stepProps }: Props) {
return <div>Error: {error?.message}</div>;
}

const llmScreenshotUris = artifacts
?.filter(
(artifact) => artifact.artifact_type === ArtifactType.LLMScreenshot,
)
.map((artifact) => artifact.uri);
const llmScreenshots = artifacts?.filter(
(artifact) => artifact.artifact_type === ArtifactType.LLMScreenshot,
);

const actionScreenshotUris = artifacts
?.filter(
(artifact) => artifact.artifact_type === ArtifactType.ActionScreenshot,
)
.map((artifact) => artifact.uri);
const actionScreenshots = artifacts?.filter(
(artifact) => artifact.artifact_type === ArtifactType.ActionScreenshot,
);

const visibleElementsTreeUri = artifacts?.find(
const visibleElementsTree = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.VisibleElementsTree,
)?.uri;
);

const visibleElementsTreeTrimmedUri = artifacts?.find(
const visibleElementsTreeTrimmed = artifacts?.find(
(artifact) =>
artifact.artifact_type === ArtifactType.VisibleElementsTreeTrimmed,
)?.uri;
);

const llmPromptUri = artifacts?.find(
const llmPrompt = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.LLMPrompt,
)?.uri;
);

const llmRequestUri = artifacts?.find(
const llmRequest = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.LLMRequest,
)?.uri;
);

const llmResponseRawUri = artifacts?.find(
const llmResponseRaw = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.LLMResponseRaw,
)?.uri;
);

const llmResponseParsedUri = artifacts?.find(
const llmResponseParsed = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.LLMResponseParsed,
)?.uri;
);

const htmlRawUri = artifacts?.find(
const htmlRaw = artifacts?.find(
(artifact) => artifact.artifact_type === ArtifactType.HTMLScrape,
)?.uri;
);

return (
<Tabs defaultValue="info" className="w-full">
Expand Down Expand Up @@ -128,12 +124,12 @@ function StepArtifacts({ id, stepProps }: Props) {
</div>
</TabsContent>
<TabsContent value="screenshot_llm">
{llmScreenshotUris && llmScreenshotUris.length > 0 ? (
{llmScreenshots && llmScreenshots.length > 0 ? (
<div className="grid grid-cols-3 gap-4 p-4">
{llmScreenshotUris.map((uri, index) => (
{llmScreenshots.map((artifact, index) => (
<ZoomableImage
key={index}
src={`${artifactApiBaseUrl}/artifact/image?path=${uri.slice(7)}`}
src={getImageURL(artifact)}
className="object-cover w-full h-full"
alt="action-screenshot"
/>
Expand All @@ -150,12 +146,12 @@ function StepArtifacts({ id, stepProps }: Props) {
)}
</TabsContent>
<TabsContent value="screenshot_action">
{actionScreenshotUris && actionScreenshotUris.length > 0 ? (
{actionScreenshots && actionScreenshots.length > 0 ? (
<div className="grid grid-cols-3 gap-4 p-4">
{actionScreenshotUris.map((uri, index) => (
{actionScreenshots.map((artifact, index) => (
<ZoomableImage
key={index}
src={`${artifactApiBaseUrl}/artifact/image?path=${uri.slice(7)}`}
src={getImageURL(artifact)}
className="object-cover w-full h-full"
alt="action-screenshot"
/>
Expand All @@ -172,31 +168,31 @@ function StepArtifacts({ id, stepProps }: Props) {
)}
</TabsContent>
<TabsContent value="element_tree">
{visibleElementsTreeUri ? (
<JSONArtifact uri={visibleElementsTreeUri} />
{visibleElementsTree ? (
<JSONArtifact artifact={visibleElementsTree} />
) : null}
</TabsContent>
<TabsContent value="element_tree_trimmed">
{visibleElementsTreeTrimmedUri ? (
<JSONArtifact uri={visibleElementsTreeTrimmedUri} />
{visibleElementsTreeTrimmed ? (
<JSONArtifact artifact={visibleElementsTreeTrimmed} />
) : null}
</TabsContent>
<TabsContent value="llm_prompt">
{llmPromptUri ? <TextArtifact uri={llmPromptUri} /> : null}
{llmPrompt ? <TextArtifact artifact={llmPrompt} /> : null}
</TabsContent>
<TabsContent value="llm_request">
{llmRequestUri ? <JSONArtifact uri={llmRequestUri} /> : null}
{llmRequest ? <JSONArtifact artifact={llmRequest} /> : null}
</TabsContent>
<TabsContent value="llm_response_raw">
{llmResponseRawUri ? <JSONArtifact uri={llmResponseRawUri} /> : null}
{llmResponseRaw ? <JSONArtifact artifact={llmResponseRaw} /> : null}
</TabsContent>
<TabsContent value="llm_response_parsed">
{llmResponseParsedUri ? (
<JSONArtifact uri={llmResponseParsedUri} />
{llmResponseParsed ? (
<JSONArtifact artifact={llmResponseParsed} />
) : null}
</TabsContent>
<TabsContent value="html_raw">
{htmlRawUri ? <TextArtifact uri={htmlRawUri} /> : null}
{htmlRaw ? <TextArtifact artifact={htmlRaw} /> : null}
</TabsContent>
</Tabs>
);
Expand Down
12 changes: 3 additions & 9 deletions skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
AccordionTrigger,
} from "@/components/ui/accordion";
import { StatusBadge } from "@/components/StatusBadge";
import { artifactApiBaseUrl } from "@/util/env";
import { Button } from "@/components/ui/button";
import { ReloadIcon } from "@radix-ui/react-icons";
import { basicTimeFormat } from "@/util/timeFormat";
import { StepArtifactsLayout } from "./StepArtifactsLayout";
import Zoom from "react-medium-image-zoom";
import { AspectRatio } from "@/components/ui/aspect-ratio";
import { getRecordingURL, getScreenshotURL } from "./artifactUtils";

function TaskDetails() {
const { taskId } = useParams();
Expand Down Expand Up @@ -63,10 +63,7 @@ function TaskDetails() {
{task.recording_url ? (
<div className="flex">
<Label className="w-32">Recording</Label>
<video
src={`${artifactApiBaseUrl}/artifact/recording?path=${task.recording_url.slice(7)}`}
controls
/>
<video src={getRecordingURL(task)} controls />
</div>
) : null}
<div className="flex items-center">
Expand Down Expand Up @@ -142,10 +139,7 @@ function TaskDetails() {
{task.screenshot_url ? (
<Zoom zoomMargin={16}>
<AspectRatio ratio={16 / 9}>
<img
src={`${artifactApiBaseUrl}/artifact/image?path=${task.screenshot_url.slice(7)}`}
alt="screenshot"
/>
<img src={getScreenshotURL(task)} alt="screenshot" />
</AspectRatio>
</Zoom>
) : (
Expand Down
27 changes: 17 additions & 10 deletions skyvern-frontend/src/routes/tasks/detail/TextArtifact.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
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";

type Props = {
uri: string;
artifact: ArtifactApiResponse;
};

function TextArtifact({ uri }: Props) {
function TextArtifact({ artifact }: Props) {
const { data, isFetching, isError, error } = useQuery<string>({
queryKey: ["artifact", uri],
queryKey: ["artifact", artifact.artifact_id],
queryFn: async () => {
return artifactApiClient
.get(`/artifact/text`, {
params: {
path: uri.slice(7),
},
})
.then((response) => response.data);
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);
}
},
});

Expand Down
31 changes: 31 additions & 0 deletions skyvern-frontend/src/routes/tasks/detail/artifactUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ArtifactApiResponse, TaskApiResponse } from "@/api/types";
import { artifactApiBaseUrl } from "@/util/env";

export function getImageURL(artifact: ArtifactApiResponse): string {
if (artifact.uri.startsWith("file://")) {
return `${artifactApiBaseUrl}/artifact/image?path=${artifact.uri.slice(7)}`;
} else if (artifact.uri.startsWith("s3://") && artifact.signed_url) {
return artifact.signed_url;
}
return artifact.uri;
}

export function getScreenshotURL(task: TaskApiResponse) {
if (!task.screenshot_url) {
return;
}
if (task.screenshot_url?.startsWith("file://")) {
return `${artifactApiBaseUrl}/artifact/image?path=${task.screenshot_url.slice(7)}`;
}
return task.screenshot_url;
}

export function getRecordingURL(task: TaskApiResponse) {
if (!task.recording_url) {
return;
}
if (task.recording_url?.startsWith("file://")) {
return `${artifactApiBaseUrl}/artifact/recording?path=${task.recording_url.slice(7)}`;
}
return task.recording_url;
}
Loading