import { useJobStore } from './jobStore'; /** * Waits for a server-sent event job to complete. * Manages the SSE connection lifecycle via the central jobStore. * * @param url The SSE endpoint URL for the job. * @param toastTitle Optional title for a loading toast notification. * @returns A promise that resolves when the job is 'completed', or rejects on 'error' or 'timeout'. */ export const waitForJob = async (url: string, toastTitle?: string): Promise => { // Directly call the store's subscribe method // The store now handles connection creation/reuse, timeouts, toasts, and promise resolution/rejection. return useJobStore.getState().subscribeToJob(url, toastTitle); };