import { useCopy } from "@/hooks/use-copy"; import { VercelAIWorkflowToolStreamingResult } from "app-types/workflow"; import equal from "lib/equal"; import { AlertTriangleIcon, Check, Copy, Loader2, XIcon } from "lucide-react"; import { memo, useEffect, useMemo, useRef } from "react"; import { Alert, AlertDescription, AlertTitle } from "ui/alert"; import { Button } from "ui/button"; import JsonView from "ui/json-view"; import { NodeResultPopup } from "../workflow/node-result-popup"; import { cn } from "lib/utils"; import { NodeIcon } from "../workflow/node-icon"; import { TextShimmer } from "ui/text-shimmer"; interface WorkflowInvocationProps { result: VercelAIWorkflowToolStreamingResult; } function PureWorkflowInvocation({ result }: WorkflowInvocationProps) { const { copied, copy } = useCopy(); const savedResult = useRef(result); const output = useMemo(() => { if (result.status == "running") return null; if (result.status == "fail") return ( {result?.error?.name || "ERROR"} {result.error?.message} ); if (!result.result) return null; return (
Response
{copied ? ( ) : ( )}
); }, [result.status, result.error, result.result, copied]); useEffect(() => { if (result.status == "running") { savedResult.current = result; } }, [result]); return (
{result.history.map((item, i) => { const result = item.result || savedResult.current.history[i]?.result; return (
{item.status == "running" ? ( {`${item.name} Running...`} ) : ( {item.name} )} {item.status != "running" && ((item.endedAt! - item.startedAt!) / 1000).toFixed(2)} {item.status == "success" ? ( ) : item.status == "fail" ? ( ) : ( )}
); })}
{output}
); } function areEqual( prev: WorkflowInvocationProps, next: WorkflowInvocationProps, ) { if (prev.result.status != next.result.status) return false; if (prev.result.error?.message != next.result.error?.message) return false; if (prev.result.result != next.result.result) return false; if (!equal(prev.result.history, next.result.history)) return false; if (!equal(prev.result.result, next.result.result)) return false; return true; } export const WorkflowInvocation = memo(PureWorkflowInvocation, areEqual);