import{Kt as e,Zt as t,nn as n}from"./branding-B7dW-jsD.js";import{t as r}from"./createLucideIcon-DRi237xT.js";var i=r(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),a=n(t(),1),o=[`run_created`,`run_status_changed`,`run_failed`,`step_completed`,`step_failed`,`approval_requested`,`approval_granted`,`approval_rejected`,`log_line`,`user_signed_in`,`user_signed_up`,`user_signed_out`];function s({runId:e,types:t,onEvent:n,enabled:r=!0}){let i=(0,a.useRef)(n);i.current=n;let s=t?[...t].sort().join(`,`):``,c=(0,a.useCallback)(()=>{let t=new URLSearchParams;e&&t.set(`run_id`,e),s&&t.set(`types`,s);let n=t.toString();return`/api/v1/events${n?`?${n}`:``}`},[e,s]);(0,a.useEffect)(()=>{if(!r)return;let e=null,t=null,n=!1;function a(){if(n)return;let r=c();e=new EventSource(r,{withCredentials:!0});let l=s?s.split(`,`):o;for(let t of l)e.addEventListener(t,e=>{let n=JSON.parse(e.data);i.current(t,n)});e.onerror=()=>{e?.close(),n||(t=setTimeout(a,3e3))}}return a(),()=>{n=!0,e?.close(),t&&clearTimeout(t)}},[r,c,s])}var c=[`run_created`,`run_status_changed`,`run_failed`,`step_completed`,`step_failed`,`approval_requested`,`approval_granted`,`approval_rejected`];function l({runId:t,types:n=c,enabled:r=!0}={}){let i=e(),o=(0,a.useRef)(i);o.current=i;let l=(0,a.useRef)(!1);(0,a.useEffect)(()=>{i.state===`idle`&&l.current&&(l.current=!1,i.revalidate())},[i]),s({runId:t,types:n,enabled:r,onEvent:()=>{let e=o.current;e.state===`idle`?e.revalidate():l.current=!0}})}export{s as n,i as r,l as t};