"use client"; import { ReactNode, useMemo, useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "ui/dialog"; import { NodeRuntimeHistory } from "lib/ai/workflow/workflow.interface"; import { Badge } from "ui/badge"; import { CheckIcon, CopyIcon, Loader2Icon, TriangleAlertIcon, } from "lucide-react"; import JsonView from "ui/json-view"; import { useCopy } from "@/hooks/use-copy"; import { Button } from "ui/button"; import { cn, errorToString } from "lib/utils"; import { Alert, AlertDescription, AlertTitle } from "ui/alert"; import { useTranslations } from "next-intl"; export function NodeResultPopup({ history, children, disabled, }: { history: Pick< NodeRuntimeHistory, "name" | "status" | "startedAt" | "endedAt" | "error" | "result" >; children: ReactNode; disabled?: boolean; }) { const { copy, copied } = useCopy(); const t = useTranslations(); const [tab, setTab] = useState<"input" | "output">("output"); const duration = useMemo(() => { if (history.endedAt) { return `${((history.endedAt - history.startedAt) / 1000).toFixed(3)}s`; } return null; }, [history.endedAt, history.startedAt]); return ( {children} {history.name} {t("Common.result")}

{t("Common.status")}

{history.status === "fail" ? ( ) : history.status === "running" ? ( ) : ( )} {history.status}

{t("Common.startedAt")}

{new Date(history.startedAt).toLocaleString()}

{t("Common.duration")}

{history.status === "running" ? "N/A" : duration}

{tab == "output" && history.status === "fail" ? null : ( <> )} {tab == "output" && history.status === "fail" ? ( Error {errorToString(history.error)} ) : ( )}
); }