import { getClient } from "@/api/AxiosClient"; import { ProxyLocation } from "@/api/types"; import { StatusBadge } from "@/components/StatusBadge"; import { SwitchBarNavigation } from "@/components/SwitchBarNavigation"; import { Button } from "@/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Skeleton } from "@/components/ui/skeleton"; import { toast } from "@/components/ui/use-toast"; import { useApiCredential } from "@/hooks/useApiCredential"; import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { copyText } from "@/util/copyText"; import { apiBaseUrl } from "@/util/env"; import { CopyIcon, Pencil2Icon, PlayIcon, ReloadIcon, } from "@radix-ui/react-icons"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import fetchToCurl from "fetch-to-curl"; import { Link, Outlet, useParams, useSearchParams } from "react-router-dom"; import { statusIsFinalized, statusIsRunningOrQueued } from "../tasks/types"; import { useWorkflowQuery } from "./hooks/useWorkflowQuery"; import { useWorkflowRunQuery } from "./hooks/useWorkflowRunQuery"; import { WorkflowRunTimeline } from "./workflowRun/WorkflowRunTimeline"; import { useWorkflowRunTimelineQuery } from "./hooks/useWorkflowRunTimelineQuery"; import { findActiveItem } from "./workflowRun/workflowTimelineUtils"; function WorkflowRun() { const [searchParams, setSearchParams] = useSearchParams(); const active = searchParams.get("active"); const { workflowRunId, workflowPermanentId } = useParams(); const credentialGetter = useCredentialGetter(); const apiCredential = useApiCredential(); const queryClient = useQueryClient(); const { data: workflow, isLoading: workflowIsLoading } = useWorkflowQuery({ workflowPermanentId, }); const { data: workflowRun, isLoading: workflowRunIsLoading } = useWorkflowRunQuery(); const { data: workflowRunTimeline } = useWorkflowRunTimelineQuery(); 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, }); }, }); const workflowRunIsRunningOrQueued = workflowRun && statusIsRunningOrQueued(workflowRun); const workflowRunIsFinalized = workflowRun && statusIsFinalized(workflowRun); const selection = findActiveItem( workflowRunTimeline ?? [], active, !!workflowRunIsFinalized, ); const parameters = workflowRun?.parameters ?? {}; const proxyLocation = workflowRun?.proxy_location ?? ProxyLocation.Residential; const title = workflowIsLoading ? ( ) : (

{workflow?.title}

); const workflowFailureReason = workflowRun?.failure_reason ? (
Workflow Failure Reason
{workflowRun.failure_reason}
) : null; function handleSetActiveItem(id: string) { searchParams.set("active", id); setSearchParams(searchParams, { replace: true, }); } return (
{title} {workflowRunIsLoading ? ( ) : workflowRun ? ( ) : null}

{workflowRunId}

{workflowRunIsRunningOrQueued && ( Are you sure? Are you sure you want to cancel this workflow run? )} {workflowRunIsFinalized && ( )}
{workflowFailureReason}
{ handleSetActiveItem(item.action.action_id); }} onBlockItemSelected={(item) => { handleSetActiveItem(item.workflow_run_block_id); }} onLiveStreamSelected={() => { handleSetActiveItem("stream"); }} onObserverThoughtCardSelected={(item) => { handleSetActiveItem(item.thought_id); }} />
); } export { WorkflowRun };