2024-07-11 03:08:52 -07:00
|
|
|
import { getClient } from "@/api/AxiosClient";
|
2024-09-24 11:54:20 -07:00
|
|
|
import {
|
|
|
|
|
Status,
|
|
|
|
|
TaskApiResponse,
|
|
|
|
|
WorkflowRunStatusApiResponse,
|
|
|
|
|
} from "@/api/types";
|
2024-07-11 03:08:52 -07:00
|
|
|
import { StatusBadge } from "@/components/StatusBadge";
|
2024-10-14 13:07:54 -07:00
|
|
|
import { ZoomableImage } from "@/components/ZoomableImage";
|
|
|
|
|
import { AspectRatio } from "@/components/ui/aspect-ratio";
|
2024-09-05 18:40:58 +03:00
|
|
|
import { Button } from "@/components/ui/button";
|
2024-11-19 10:54:38 -08:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogClose,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogTrigger,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2024-09-05 18:40:58 +03:00
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
import {
|
|
|
|
|
Pagination,
|
|
|
|
|
PaginationContent,
|
|
|
|
|
PaginationItem,
|
|
|
|
|
PaginationLink,
|
|
|
|
|
PaginationNext,
|
|
|
|
|
PaginationPrevious,
|
|
|
|
|
} from "@/components/ui/pagination";
|
2024-07-11 03:08:52 -07:00
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table";
|
2024-10-14 13:07:54 -07:00
|
|
|
import { toast } from "@/components/ui/use-toast";
|
|
|
|
|
import { useApiCredential } from "@/hooks/useApiCredential";
|
2024-07-11 03:08:52 -07:00
|
|
|
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
|
2024-10-14 13:07:54 -07:00
|
|
|
import { copyText } from "@/util/copyText";
|
|
|
|
|
import { apiBaseUrl, envCredential } from "@/util/env";
|
2024-11-11 13:03:40 -08:00
|
|
|
import {
|
2024-11-18 06:04:16 -08:00
|
|
|
localTimeFormatWithShortDate,
|
2024-11-11 13:03:40 -08:00
|
|
|
timeFormatWithShortDate,
|
|
|
|
|
} from "@/util/timeFormat";
|
2024-07-25 07:35:47 -07:00
|
|
|
import { cn } from "@/util/utils";
|
2024-10-14 13:07:54 -07:00
|
|
|
import {
|
|
|
|
|
CopyIcon,
|
2024-12-04 12:39:58 -08:00
|
|
|
FileIcon,
|
2024-10-14 13:07:54 -07:00
|
|
|
Pencil2Icon,
|
|
|
|
|
PlayIcon,
|
|
|
|
|
ReaderIcon,
|
2024-11-14 11:30:11 -08:00
|
|
|
ReloadIcon,
|
2024-10-14 13:07:54 -07:00
|
|
|
} from "@radix-ui/react-icons";
|
2024-11-11 07:47:31 -08:00
|
|
|
import {
|
|
|
|
|
keepPreviousData,
|
2024-11-14 11:30:11 -08:00
|
|
|
useMutation,
|
2024-11-11 07:47:31 -08:00
|
|
|
useQuery,
|
|
|
|
|
useQueryClient,
|
|
|
|
|
} from "@tanstack/react-query";
|
2024-10-14 13:07:54 -07:00
|
|
|
import fetchToCurl from "fetch-to-curl";
|
|
|
|
|
import { useEffect, useState } from "react";
|
2024-10-01 07:16:46 -07:00
|
|
|
import {
|
|
|
|
|
Link,
|
|
|
|
|
useNavigate,
|
|
|
|
|
useParams,
|
|
|
|
|
useSearchParams,
|
|
|
|
|
} from "react-router-dom";
|
2024-11-14 11:30:11 -08:00
|
|
|
import {
|
|
|
|
|
statusIsFinalized,
|
|
|
|
|
statusIsNotFinalized,
|
|
|
|
|
statusIsRunningOrQueued,
|
|
|
|
|
} from "../tasks/types";
|
2024-11-19 10:54:38 -08:00
|
|
|
import { WorkflowBlockCollapsibleContent } from "./WorkflowBlockCollapsibleContent";
|
2024-10-14 13:07:54 -07:00
|
|
|
import { CodeEditor } from "./components/CodeEditor";
|
2024-10-08 06:00:19 -07:00
|
|
|
import { useWorkflowQuery } from "./hooks/useWorkflowQuery";
|
2024-09-30 11:36:24 -07:00
|
|
|
|
|
|
|
|
type StreamMessage = {
|
|
|
|
|
task_id: string;
|
|
|
|
|
status: string;
|
|
|
|
|
screenshot?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let socket: WebSocket | null = null;
|
|
|
|
|
|
|
|
|
|
const wssBaseUrl = import.meta.env.VITE_WSS_BASE_URL;
|
2024-07-11 03:08:52 -07:00
|
|
|
|
|
|
|
|
function WorkflowRun() {
|
2024-07-25 07:35:47 -07:00
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
|
const page = searchParams.get("page") ? Number(searchParams.get("page")) : 1;
|
2024-07-11 03:08:52 -07:00
|
|
|
const { workflowRunId, workflowPermanentId } = useParams();
|
|
|
|
|
const credentialGetter = useCredentialGetter();
|
2024-09-30 11:36:24 -07:00
|
|
|
const [streamImgSrc, setStreamImgSrc] = useState<string>("");
|
2024-07-11 03:08:52 -07:00
|
|
|
const navigate = useNavigate();
|
2024-10-08 06:00:19 -07:00
|
|
|
const apiCredential = useApiCredential();
|
2024-11-11 07:47:31 -08:00
|
|
|
const queryClient = useQueryClient();
|
2024-10-08 06:00:19 -07:00
|
|
|
|
|
|
|
|
const { data: workflow, isLoading: workflowIsLoading } = useWorkflowQuery({
|
|
|
|
|
workflowPermanentId,
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-11 03:08:52 -07:00
|
|
|
const { data: workflowRun, isLoading: workflowRunIsLoading } =
|
|
|
|
|
useQuery<WorkflowRunStatusApiResponse>({
|
|
|
|
|
queryKey: ["workflowRun", workflowPermanentId, workflowRunId],
|
|
|
|
|
queryFn: async () => {
|
|
|
|
|
const client = await getClient(credentialGetter);
|
|
|
|
|
return client
|
|
|
|
|
.get(`/workflows/${workflowPermanentId}/runs/${workflowRunId}`)
|
|
|
|
|
.then((response) => response.data);
|
|
|
|
|
},
|
2024-09-24 11:54:20 -07:00
|
|
|
refetchInterval: (query) => {
|
2024-09-30 11:36:24 -07:00
|
|
|
if (!query.state.data) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (statusIsNotFinalized(query.state.data)) {
|
2024-09-24 11:54:20 -07:00
|
|
|
return 5000;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
placeholderData: keepPreviousData,
|
2024-10-24 07:12:53 -07:00
|
|
|
refetchOnMount: (query) => {
|
|
|
|
|
if (!query.state.data) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-11-11 07:47:31 -08:00
|
|
|
return statusIsRunningOrQueued(query.state.data) ? "always" : false;
|
2024-10-24 07:12:53 -07:00
|
|
|
},
|
|
|
|
|
refetchOnWindowFocus: (query) => {
|
|
|
|
|
if (!query.state.data) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return statusIsRunningOrQueued(query.state.data);
|
|
|
|
|
},
|
2024-07-11 03:08:52 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { data: workflowTasks, isLoading: workflowTasksIsLoading } = useQuery<
|
|
|
|
|
Array<TaskApiResponse>
|
|
|
|
|
>({
|
2024-07-25 07:35:47 -07:00
|
|
|
queryKey: ["workflowTasks", workflowRunId, page],
|
2024-07-11 03:08:52 -07:00
|
|
|
queryFn: async () => {
|
|
|
|
|
const client = await getClient(credentialGetter);
|
2024-07-25 07:35:47 -07:00
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
params.append("page", String(page));
|
2024-07-11 03:08:52 -07:00
|
|
|
return client
|
2024-07-25 07:35:47 -07:00
|
|
|
.get(`/tasks?workflow_run_id=${workflowRunId}`, { params })
|
2024-07-11 03:08:52 -07:00
|
|
|
.then((response) => response.data);
|
|
|
|
|
},
|
2024-09-24 11:54:20 -07:00
|
|
|
refetchInterval: () => {
|
|
|
|
|
if (workflowRun?.status === Status.Running) {
|
|
|
|
|
return 5000;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
placeholderData: keepPreviousData,
|
2024-11-11 07:47:31 -08:00
|
|
|
refetchOnMount: workflowRun?.status === Status.Running ? "always" : false,
|
|
|
|
|
refetchOnWindowFocus:
|
|
|
|
|
workflowRun?.status === Status.Running ? "always" : false,
|
2024-07-11 03:08:52 -07:00
|
|
|
});
|
|
|
|
|
|
2024-11-14 11:30:11 -08:00
|
|
|
const cancelWorkflowMutation = useMutation({
|
|
|
|
|
mutationFn: async () => {
|
|
|
|
|
const client = await getClient(credentialGetter);
|
|
|
|
|
return client
|
|
|
|
|
.post(`/workflows/runs/${workflowRunId}/cancel`)
|
|
|
|
|
.then((response) => response.data);
|
|
|
|
|
},
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["workflowRun", workflowRunId],
|
|
|
|
|
});
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["workflowRun", workflowPermanentId, workflowRunId],
|
|
|
|
|
});
|
|
|
|
|
toast({
|
|
|
|
|
variant: "success",
|
|
|
|
|
title: "Workflow Canceled",
|
|
|
|
|
description: "The workflow has been successfully canceled.",
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onError: (error) => {
|
|
|
|
|
toast({
|
|
|
|
|
variant: "destructive",
|
|
|
|
|
title: "Error",
|
|
|
|
|
description: error.message,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-14 13:07:54 -07:00
|
|
|
const currentRunningTask = workflowTasks?.find(
|
|
|
|
|
(task) => task.status === Status.Running,
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-30 11:36:24 -07:00
|
|
|
const workflowRunIsRunningOrQueued =
|
|
|
|
|
workflowRun && statusIsRunningOrQueued(workflowRun);
|
|
|
|
|
|
2024-11-14 11:30:11 -08:00
|
|
|
const workflowRunIsFinalized = workflowRun && statusIsFinalized(workflowRun);
|
|
|
|
|
|
2024-11-19 10:54:38 -08:00
|
|
|
const showStream = workflowRun && statusIsNotFinalized(workflowRun);
|
|
|
|
|
|
2024-09-30 11:36:24 -07:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!workflowRunIsRunningOrQueued) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
|
// Create WebSocket connection.
|
|
|
|
|
let credential = null;
|
|
|
|
|
if (credentialGetter) {
|
|
|
|
|
const token = await credentialGetter();
|
|
|
|
|
credential = `?token=Bearer ${token}`;
|
|
|
|
|
} else {
|
|
|
|
|
credential = `?apikey=${envCredential}`;
|
|
|
|
|
}
|
|
|
|
|
if (socket) {
|
|
|
|
|
socket.close();
|
|
|
|
|
}
|
|
|
|
|
socket = new WebSocket(
|
|
|
|
|
`${wssBaseUrl}/stream/workflow_runs/${workflowRunId}${credential}`,
|
|
|
|
|
);
|
|
|
|
|
// Listen for messages
|
|
|
|
|
socket.addEventListener("message", (event) => {
|
|
|
|
|
try {
|
|
|
|
|
const message: StreamMessage = JSON.parse(event.data);
|
|
|
|
|
if (message.screenshot) {
|
|
|
|
|
setStreamImgSrc(message.screenshot);
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
message.status === "completed" ||
|
|
|
|
|
message.status === "failed" ||
|
|
|
|
|
message.status === "terminated"
|
|
|
|
|
) {
|
|
|
|
|
socket?.close();
|
2024-11-11 07:47:31 -08:00
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["workflowRuns"],
|
|
|
|
|
});
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["workflowRun", workflowPermanentId, workflowRunId],
|
|
|
|
|
});
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["workflowTasks", workflowRunId],
|
|
|
|
|
});
|
2024-09-30 11:36:24 -07:00
|
|
|
if (
|
|
|
|
|
message.status === "failed" ||
|
|
|
|
|
message.status === "terminated"
|
|
|
|
|
) {
|
|
|
|
|
toast({
|
|
|
|
|
title: "Run Failed",
|
|
|
|
|
description: "The workflow run has failed.",
|
|
|
|
|
variant: "destructive",
|
|
|
|
|
});
|
|
|
|
|
} else if (message.status === "completed") {
|
|
|
|
|
toast({
|
|
|
|
|
title: "Run Completed",
|
|
|
|
|
description: "The workflow run has been completed.",
|
|
|
|
|
variant: "success",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error("Failed to parse message", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.addEventListener("close", () => {
|
|
|
|
|
socket = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
run();
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
if (socket) {
|
|
|
|
|
socket.close();
|
|
|
|
|
socket = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-11-11 07:47:31 -08:00
|
|
|
}, [
|
|
|
|
|
credentialGetter,
|
|
|
|
|
workflowRunId,
|
|
|
|
|
workflowRunIsRunningOrQueued,
|
|
|
|
|
queryClient,
|
|
|
|
|
workflowPermanentId,
|
|
|
|
|
]);
|
2024-09-30 11:36:24 -07:00
|
|
|
|
|
|
|
|
function getStream() {
|
|
|
|
|
if (workflowRun?.status === Status.Created) {
|
|
|
|
|
return (
|
2024-10-14 13:07:54 -07:00
|
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-8 rounded-md bg-slate-900 py-8 text-lg">
|
2024-09-30 11:36:24 -07:00
|
|
|
<span>Workflow has been created.</span>
|
|
|
|
|
<span>Stream will start when the workflow is running.</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (workflowRun?.status === Status.Queued) {
|
|
|
|
|
return (
|
2024-10-14 13:07:54 -07:00
|
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-8 rounded-md bg-slate-900 py-8 text-lg">
|
2024-09-30 11:36:24 -07:00
|
|
|
<span>Your workflow run is queued.</span>
|
|
|
|
|
<span>Stream will start when the workflow is running.</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (workflowRun?.status === Status.Running && streamImgSrc.length === 0) {
|
|
|
|
|
return (
|
2024-10-14 13:07:54 -07:00
|
|
|
<div className="flex h-full w-full items-center justify-center rounded-md bg-slate-900 py-8 text-lg">
|
2024-09-30 11:36:24 -07:00
|
|
|
Starting the stream...
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (workflowRun?.status === Status.Running && streamImgSrc.length > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="h-full w-full">
|
2024-10-14 13:07:54 -07:00
|
|
|
<ZoomableImage
|
|
|
|
|
src={`data:image/png;base64,${streamImgSrc}`}
|
|
|
|
|
className="rounded-md"
|
|
|
|
|
/>
|
2024-09-30 11:36:24 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 03:08:52 -07:00
|
|
|
function handleNavigate(event: React.MouseEvent, id: string) {
|
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
|
window.open(
|
|
|
|
|
window.location.origin + `/tasks/${id}/actions`,
|
|
|
|
|
"_blank",
|
|
|
|
|
"noopener,noreferrer",
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2024-07-11 09:02:22 -07:00
|
|
|
navigate(`/tasks/${id}/actions`);
|
2024-07-11 03:08:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parameters = workflowRun?.parameters ?? {};
|
|
|
|
|
|
2024-11-19 10:54:38 -08:00
|
|
|
const title = workflowIsLoading ? (
|
|
|
|
|
<Skeleton className="h-9 w-48" />
|
|
|
|
|
) : (
|
|
|
|
|
<h1 className="text-3xl">{workflow?.title}</h1>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const workflowFailureReason = workflowRun?.failure_reason ? (
|
|
|
|
|
<div
|
|
|
|
|
className="space-y-2 rounded-md border border-red-600 p-4"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: "rgba(220, 38, 38, 0.10)",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="font-bold">Workflow Failure Reason</div>
|
|
|
|
|
<div className="text-sm">{workflowRun.failure_reason}</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : null;
|
|
|
|
|
|
2024-11-19 12:46:56 -08:00
|
|
|
const skeleton = (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell className="w-10">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="w-1/5">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="w-1/6">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="w-1/4">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="w-1/8">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="w-1/5">
|
|
|
|
|
<Skeleton className="h-6 w-full" />
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
|
2024-12-04 12:39:58 -08:00
|
|
|
const fileUrls = workflowRun?.downloaded_file_urls ?? [];
|
|
|
|
|
|
2024-07-11 03:08:52 -07:00
|
|
|
return (
|
|
|
|
|
<div className="space-y-8">
|
2024-09-05 16:58:38 +03:00
|
|
|
<header className="flex justify-between">
|
2024-10-08 06:00:19 -07:00
|
|
|
<div className="space-y-3">
|
2024-10-14 13:07:54 -07:00
|
|
|
<div className="flex items-center gap-5">
|
2024-11-19 10:54:38 -08:00
|
|
|
{title}
|
2024-10-08 06:00:19 -07:00
|
|
|
{workflowRunIsLoading ? (
|
|
|
|
|
<Skeleton className="h-8 w-28" />
|
|
|
|
|
) : workflowRun ? (
|
|
|
|
|
<StatusBadge status={workflowRun?.status} />
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
2024-11-19 10:54:38 -08:00
|
|
|
<h2 className="text-2xl text-slate-400">{workflowRunId}</h2>
|
2024-09-05 16:58:38 +03:00
|
|
|
</div>
|
2024-10-08 06:00:19 -07:00
|
|
|
|
2024-10-01 07:16:46 -07:00
|
|
|
<div className="flex gap-2">
|
2024-10-08 06:00:19 -07:00
|
|
|
<Button
|
|
|
|
|
variant="secondary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!workflowRun) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const curl = fetchToCurl({
|
|
|
|
|
method: "POST",
|
|
|
|
|
url: `${apiBaseUrl}/workflows/${workflowPermanentId}/run`,
|
|
|
|
|
body: {
|
|
|
|
|
data: workflowRun?.parameters,
|
|
|
|
|
proxy_location: "RESIDENTIAL",
|
|
|
|
|
},
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"x-api-key": apiCredential ?? "<your-api-key>",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
copyText(curl).then(() => {
|
|
|
|
|
toast({
|
|
|
|
|
variant: "success",
|
|
|
|
|
title: "Copied to Clipboard",
|
|
|
|
|
description:
|
|
|
|
|
"The cURL command has been copied to your clipboard.",
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CopyIcon className="mr-2 h-4 w-4" />
|
2024-10-09 08:53:40 -07:00
|
|
|
cURL
|
2024-10-08 06:00:19 -07:00
|
|
|
</Button>
|
2024-10-01 07:16:46 -07:00
|
|
|
<Button asChild variant="secondary">
|
|
|
|
|
<Link to={`/workflows/${workflowPermanentId}/edit`}>
|
|
|
|
|
<Pencil2Icon className="mr-2 h-4 w-4" />
|
2024-10-09 07:02:59 -07:00
|
|
|
Edit
|
2024-10-01 07:16:46 -07:00
|
|
|
</Link>
|
|
|
|
|
</Button>
|
2024-11-14 11:30:11 -08:00
|
|
|
{workflowRunIsRunningOrQueued && (
|
|
|
|
|
<Dialog>
|
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
|
<Button variant="destructive">Cancel</Button>
|
|
|
|
|
</DialogTrigger>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Are you sure?</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
|
|
|
|
Are you sure you want to cancel this workflow run?
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<DialogClose asChild>
|
|
|
|
|
<Button variant="secondary">Back</Button>
|
|
|
|
|
</DialogClose>
|
|
|
|
|
<Button
|
|
|
|
|
variant="destructive"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
cancelWorkflowMutation.mutate();
|
|
|
|
|
}}
|
|
|
|
|
disabled={cancelWorkflowMutation.isPending}
|
|
|
|
|
>
|
|
|
|
|
{cancelWorkflowMutation.isPending && (
|
|
|
|
|
<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
)}
|
|
|
|
|
Cancel Workflow Run
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
)}
|
|
|
|
|
{workflowRunIsFinalized && (
|
|
|
|
|
<Button asChild>
|
|
|
|
|
<Link
|
|
|
|
|
to={`/workflows/${workflowPermanentId}/run`}
|
|
|
|
|
state={{
|
|
|
|
|
data: parameters,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<PlayIcon className="mr-2 h-4 w-4" />
|
|
|
|
|
Rerun
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2024-10-01 07:16:46 -07:00
|
|
|
</div>
|
2024-07-11 03:08:52 -07:00
|
|
|
</header>
|
2024-11-19 10:54:38 -08:00
|
|
|
{workflowFailureReason}
|
|
|
|
|
{showStream && (
|
2024-10-14 13:07:54 -07:00
|
|
|
<div className="flex gap-5">
|
|
|
|
|
<div className="w-3/4 shrink-0">
|
|
|
|
|
<AspectRatio ratio={16 / 9}>{getStream()}</AspectRatio>
|
|
|
|
|
</div>
|
2024-11-13 06:11:20 -08:00
|
|
|
<div className="flex w-full min-w-0 flex-col gap-4 rounded-md bg-slate-elevation1 p-4">
|
2024-10-14 13:07:54 -07:00
|
|
|
<header className="text-lg">Current Task</header>
|
|
|
|
|
{workflowRunIsLoading || !currentRunningTask ? (
|
|
|
|
|
<div>Waiting for a task to start...</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex h-full flex-col gap-2">
|
2024-11-05 09:25:16 -08:00
|
|
|
<div className="flex gap-2 rounded-sm bg-slate-elevation3 p-2">
|
2024-10-14 13:07:54 -07:00
|
|
|
<Label className="text-sm text-slate-400">ID</Label>
|
|
|
|
|
<span className="text-sm">{currentRunningTask.task_id}</span>
|
|
|
|
|
</div>
|
2024-11-05 09:25:16 -08:00
|
|
|
<div className="flex gap-2 rounded-sm bg-slate-elevation3 p-2">
|
2024-10-14 13:07:54 -07:00
|
|
|
<Label className="text-sm text-slate-400">URL</Label>
|
2024-11-13 06:11:20 -08:00
|
|
|
<span
|
|
|
|
|
className="truncate text-sm"
|
|
|
|
|
title={currentRunningTask.request.url}
|
|
|
|
|
>
|
2024-10-14 13:07:54 -07:00
|
|
|
{currentRunningTask.request.url}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-11-05 09:25:16 -08:00
|
|
|
<div className="flex items-center gap-2 rounded-sm bg-slate-elevation3 p-2">
|
2024-10-14 13:07:54 -07:00
|
|
|
<Label className="text-sm text-slate-400">Status</Label>
|
|
|
|
|
<span className="text-sm">
|
|
|
|
|
<StatusBadge status={currentRunningTask.status} />
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-11-05 09:25:16 -08:00
|
|
|
<div className="flex gap-2 rounded-sm bg-slate-elevation3 p-2">
|
2024-10-14 13:07:54 -07:00
|
|
|
<Label className="text-sm text-slate-400">Created</Label>
|
2024-11-13 06:11:20 -08:00
|
|
|
<span
|
|
|
|
|
className="truncate text-sm"
|
2024-11-18 06:04:16 -08:00
|
|
|
title={timeFormatWithShortDate(
|
|
|
|
|
currentRunningTask.created_at,
|
|
|
|
|
)}
|
2024-11-13 06:11:20 -08:00
|
|
|
>
|
2024-10-14 13:07:54 -07:00
|
|
|
{currentRunningTask &&
|
2024-11-18 06:04:16 -08:00
|
|
|
localTimeFormatWithShortDate(
|
|
|
|
|
currentRunningTask.created_at,
|
|
|
|
|
)}
|
2024-10-14 13:07:54 -07:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mt-auto flex justify-end">
|
|
|
|
|
<Button asChild>
|
|
|
|
|
<Link to={`/tasks/${currentRunningTask.task_id}/actions`}>
|
|
|
|
|
<ReaderIcon className="mr-2 h-4 w-4" />
|
|
|
|
|
View Actions
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="space-y-5">
|
2024-07-11 03:08:52 -07:00
|
|
|
<header>
|
2024-10-14 13:07:54 -07:00
|
|
|
<h2 className="text-2xl">
|
|
|
|
|
{workflowRunIsRunningOrQueued ? "Previous Blocks" : "Blocks"}
|
|
|
|
|
</h2>
|
2024-07-11 03:08:52 -07:00
|
|
|
</header>
|
|
|
|
|
<div className="rounded-md border">
|
|
|
|
|
<Table>
|
2024-11-19 10:54:38 -08:00
|
|
|
<TableHeader className="rounded-t-md bg-slate-elevation2">
|
2024-07-11 03:08:52 -07:00
|
|
|
<TableRow>
|
2024-11-19 12:46:56 -08:00
|
|
|
<TableHead className="w-10 rounded-tl-md"></TableHead>
|
|
|
|
|
<TableHead className="w-1/5 text-slate-400">
|
2024-11-19 10:54:38 -08:00
|
|
|
Task Title
|
2024-10-14 13:07:54 -07:00
|
|
|
</TableHead>
|
2024-11-19 12:46:56 -08:00
|
|
|
<TableHead className="w-1/6 text-slate-400">ID</TableHead>
|
2024-10-14 13:07:54 -07:00
|
|
|
<TableHead className="w-1/4 text-slate-400">URL</TableHead>
|
2024-11-19 12:46:56 -08:00
|
|
|
<TableHead className="w-1/8 text-slate-400">Status</TableHead>
|
|
|
|
|
<TableHead className="w-1/5 rounded-tr-md text-slate-400">
|
2024-10-14 13:07:54 -07:00
|
|
|
Created At
|
|
|
|
|
</TableHead>
|
2024-07-11 03:08:52 -07:00
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{workflowTasksIsLoading ? (
|
2024-11-19 12:46:56 -08:00
|
|
|
skeleton
|
2024-07-11 03:08:52 -07:00
|
|
|
) : workflowTasks?.length === 0 ? (
|
|
|
|
|
<TableRow>
|
2024-11-19 10:54:38 -08:00
|
|
|
<TableCell colSpan={6}>Could not find any tasks</TableCell>
|
2024-07-11 03:08:52 -07:00
|
|
|
</TableRow>
|
|
|
|
|
) : (
|
2024-10-14 13:07:54 -07:00
|
|
|
workflowTasks
|
|
|
|
|
?.filter(
|
|
|
|
|
(task) => task.task_id !== currentRunningTask?.task_id,
|
|
|
|
|
)
|
|
|
|
|
.map((task) => {
|
|
|
|
|
return (
|
2024-11-19 10:54:38 -08:00
|
|
|
<WorkflowBlockCollapsibleContent
|
|
|
|
|
key={task.task_id}
|
|
|
|
|
task={task}
|
|
|
|
|
onNavigate={handleNavigate}
|
|
|
|
|
/>
|
2024-10-14 13:07:54 -07:00
|
|
|
);
|
|
|
|
|
})
|
2024-07-11 03:08:52 -07:00
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
2024-07-25 07:35:47 -07:00
|
|
|
<Pagination className="pt-2">
|
|
|
|
|
<PaginationContent>
|
|
|
|
|
<PaginationItem>
|
|
|
|
|
<PaginationPrevious
|
|
|
|
|
className={cn({ "cursor-not-allowed": page === 1 })}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (page === 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
params.set("page", String(Math.max(1, page - 1)));
|
|
|
|
|
setSearchParams(params, { replace: true });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
<PaginationItem>
|
|
|
|
|
<PaginationLink>{page}</PaginationLink>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
<PaginationItem>
|
|
|
|
|
<PaginationNext
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
params.set("page", String(page + 1));
|
|
|
|
|
setSearchParams(params, { replace: true });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</PaginationItem>
|
|
|
|
|
</PaginationContent>
|
|
|
|
|
</Pagination>
|
2024-07-11 03:08:52 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-11-22 06:06:50 -08:00
|
|
|
{workflowRunIsFinalized && (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h2 className="text-lg font-semibold">Block Outputs</h2>
|
|
|
|
|
</header>
|
|
|
|
|
<CodeEditor
|
|
|
|
|
language="json"
|
|
|
|
|
value={JSON.stringify(workflowRun.outputs, null, 2)}
|
|
|
|
|
readOnly
|
|
|
|
|
minHeight="96px"
|
|
|
|
|
maxHeight="500px"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-12-04 12:39:58 -08:00
|
|
|
{workflowRunIsFinalized && (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
|
|
|
|
<h2 className="text-lg font-semibold">Downloaded Files</h2>
|
|
|
|
|
</header>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{fileUrls.length > 0 ? (
|
2024-12-09 05:28:49 -08:00
|
|
|
fileUrls.map((url, index) => {
|
2024-12-04 12:39:58 -08:00
|
|
|
return (
|
2024-12-09 05:28:49 -08:00
|
|
|
<div key={url} title={url} className="flex gap-2">
|
2024-12-04 12:39:58 -08:00
|
|
|
<FileIcon className="size-6" />
|
|
|
|
|
<a href={url} className="underline underline-offset-4">
|
2024-12-09 05:28:49 -08:00
|
|
|
<span>{`File ${index + 1}`}</span>
|
2024-12-04 12:39:58 -08:00
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
) : (
|
|
|
|
|
<div>No files downloaded</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-10-14 13:07:54 -07:00
|
|
|
{Object.entries(parameters).length > 0 && (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header>
|
2024-10-28 05:37:37 -07:00
|
|
|
<h2 className="text-lg font-semibold">Input Parameter Values</h2>
|
2024-10-14 13:07:54 -07:00
|
|
|
</header>
|
2024-10-28 05:37:37 -07:00
|
|
|
{Object.entries(parameters).length === 0 && (
|
|
|
|
|
<div>This workflow doesn't have any input parameters.</div>
|
|
|
|
|
)}
|
2024-10-14 13:07:54 -07:00
|
|
|
{Object.entries(parameters).map(([key, value]) => {
|
|
|
|
|
return (
|
|
|
|
|
<div key={key} className="flex flex-col gap-2">
|
|
|
|
|
<Label>{key}</Label>
|
2024-11-19 10:54:38 -08:00
|
|
|
{typeof value === "string" ||
|
|
|
|
|
typeof value === "number" ||
|
|
|
|
|
typeof value === "boolean" ? (
|
|
|
|
|
<Input value={String(value)} readOnly />
|
2024-10-14 13:07:54 -07:00
|
|
|
) : (
|
|
|
|
|
<CodeEditor
|
|
|
|
|
value={JSON.stringify(value, null, 2)}
|
2024-10-21 09:29:49 -07:00
|
|
|
readOnly
|
2024-10-14 13:07:54 -07:00
|
|
|
language="json"
|
|
|
|
|
minHeight="96px"
|
|
|
|
|
maxHeight="500px"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-07-11 03:08:52 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { WorkflowRun };
|