// Live task event stream. One socket per task-detail view. export type TaskEventType = | 'run_started' | 'account_started' | 'account_test' | 'progress' | 'account_done' | 'error' | 'run_done' | string export interface TaskEvent { type: TaskEventType task_id: number data: unknown } export function connectTaskWS(taskId: number, onEvent: (ev: TaskEvent) => void): () => void { const proto = location.protocol === 'https:' ? 'wss' : 'ws' const ws = new WebSocket(`${proto}://${location.host}/ws?task_id=${taskId}`) ws.onmessage = (m) => { try { onEvent(JSON.parse(m.data)) } catch { // ignore malformed frames } } return () => ws.close() }