'use client';
import { useHFJobStatus } from '@/hooks/useHFJobStatus';
import { ExternalLink, RefreshCw } from 'lucide-react';
import { Button } from '@headlessui/react';
interface HFJobStatusProps {
hfJobId: string;
hfJobUrl?: string;
hfJobNamespace?: string;
}
const extractNamespaceFromUrl = (url?: string) => {
if (!url) {
return undefined;
}
try {
const match = url.match(/\/jobs\/([^\/]+)\//);
return match?.[1];
} catch (error) {
console.warn('Failed to derive HF job namespace from URL:', error);
return undefined;
}
};
export default function HFJobStatus({ hfJobId, hfJobUrl, hfJobNamespace }: HFJobStatusProps) {
const derivedNamespace = hfJobNamespace || extractNamespaceFromUrl(hfJobUrl);
const { status, loading, error } = useHFJobStatus(hfJobId, derivedNamespace);
if (error) {
return (
Status Error
{hfJobUrl && (
)}
);
}
if (loading && !status) {
return (
Checking...
);
}
if (!status) {
return (
Unknown
{hfJobUrl && (
)}
);
}
const getStatusColor = (statusStage: string) => {
switch (statusStage.toUpperCase()) {
case 'RUNNING':
return 'text-blue-400';
case 'COMPLETED':
case 'SUCCESS':
return 'text-green-400';
case 'FAILED':
case 'ERROR':
return 'text-red-400';
case 'PENDING':
case 'QUEUED':
return 'text-yellow-400';
case 'CANCELLED':
case 'STOPPED':
return 'text-gray-400';
default:
return 'text-gray-400';
}
};
const getStatusLabel = (statusStage: string) => {
switch (statusStage.toUpperCase()) {
case 'RUNNING':
return 'Running';
case 'COMPLETED':
return 'Completed';
case 'FAILED':
return 'Failed';
case 'PENDING':
return 'Pending';
case 'QUEUED':
return 'Queued';
case 'CANCELLED':
return 'Cancelled';
case 'STOPPED':
return 'Stopped';
default:
return statusStage;
}
};
return (
{loading && }
{getStatusLabel(status.status)}
{hfJobUrl && (
)}
);
}