import{r as o,e as T,a0 as h}from"./index-DjCrtoJM.js";import{p as R,q as I}from"./question-004-sINsf4GQ.js";import{D as S}from"./watch-sse-pool-WsArg2kN.js";import{d as y}from"./decopilot-sse-pool-BemyIcDl.js";const b=()=>0;function D(s){const{orgSlug:e,taskId:n,enabled:t=!0,onStep:r,onFinish:u,onTaskStatus:f}=s,l=o.useRef({taskId:n,onStep:r,onFinish:u,onTaskStatus:f});l.current={taskId:n,onStep:r,onFinish:u,onTaskStatus:f};const i=o.useRef(null),p=o.useRef(t),d=o.useRef(e);(!i.current||p.current!==t||d.current!==e)&&(p.current=t,d.current=e,i.current=m=>{if(!t||!e)return()=>{};const E=k=>{let a;try{a=JSON.parse(k.data)}catch{return}const c=l.current;if(!(c.taskId&&a.subject!==c.taskId)){switch(a.type){case S.STEP:c.onStep?.(a);break;case S.FINISH:c.onFinish?.(a);break;case S.THREAD_STATUS:c.onTaskStatus?.(a);break}m()}};return y.subscribe(e,E)}),o.useSyncExternalStore(i.current,b,b)}const O=new Set(["completed","failed","requires_action"]);function q(s){const e=T.c(5),[n]=h();let t;e[0]!==n?(t=u=>{n.enableSounds&&O.has(u.data.status)&&R(I.dataUri).catch(_)},e[0]=n,e[1]=t):t=e[1];let r;e[2]!==s||e[3]!==t?(r={orgSlug:s,onTaskStatus:t},e[2]=s,e[3]=t,e[4]=r):r=e[4],D(r)}function _(s){console.warn("[status-sounds] playback failed:",s)}export{q as u};
