import{a as g}from"./chunk-RVF7SIMA.js";import{a as _}from"./chunk-EVUDSVHH.js";import{a as h}from"./chunk-Y5EXABYR.js";import{D as l,Jg as n,Og as v,P as u,Pg as m,Y as f,ea as E,g as o,ia as p,rd as c,vh as a,ya as d}from"./chunk-5YITAGFP.js";var w=(()=>{class s extends g{_workspaceService=p(h);_clusterChangeSubscription=void 0;_currentClusterId=null;_aiProcessEvent$=new o(5);_aiDeleteEvent$=new o(5);initialize(){this.initClusterChange()}getConfig(){return{namespace:_.MO_WEBSOCKET__NAMESPACE__AI_MANAGER_EVENT,serviceName:"AI WebSocket"}}setupEventHandlers(){this.socket?.on(n.AI_PROCESS_EVENT,t=>{let e=c.transformToDto(v,t),r=this.isInSelectedWorkspace(e);a.production||(console.log(`%c[AI Event] ${e.task?.state} | ${e.task?.referencingResource?.namespace}/${e.task?.referencingResource?.resourceName} | inWorkspace=${r}`,r?"color: #a855f7; font-weight: bold":"color: #ef4444; font-weight: bold"),r&&console.log("%c[AI Event Details]","color: #a855f7",e)),r&&this._aiProcessEvent$.next(e)}),this.socket?.on(n.AI_DELETE_EVENT,t=>{let e=c.transformToDto(m,t);a.production||console.log(`%c[AI Delete Event] taskId=${e.taskId}`,"color: #ef4444; font-weight: bold"),this._aiDeleteEvent$.next(e)})}getEventNames(){return[n.AI_PROCESS_EVENT,n.AI_DELETE_EVENT]}initClusterChange(){this._clusterChangeSubscription&&this._clusterChangeSubscription.unsubscribe(),this._clusterChangeSubscription=this.clusterService.selectedCluster$.pipe(f(this.clusterService.selectedCluster$.value),u((t,e)=>t?.id===e?.id),l(t=>{let e=t?.id||null;return this._currentClusterId===e?!1:(this._currentClusterId=e,!0)})).subscribe({next:()=>{this.disconnect()}})}ensureConnection(t){this.isConnected||!t||!this.clusterService.selectedCluster$.value||this.connect()}disconnect(){super.disconnect()}isInSelectedWorkspace(t){let e=this._workspaceService?.selectedWorkspace$?.value,r=t.task?.referencingResource?.namespace;return e?!e.resources||!r?!1:e.resources.some(i=>(i.type==="namespace"?i.id:i.namespace)===r):!0}get aiProcessEvent$(){return this._aiProcessEvent$.asObservable()}get aiDeleteEvent$(){return this._aiDeleteEvent$.asObservable()}static \u0275fac=(()=>{let t;return function(r){return(t||(t=d(s)))(r||s)}})();static \u0275prov=E({token:s,factory:s.\u0275fac,providedIn:"root"})}return s})();export{w as a}; //# sourceMappingURL=chunk-XMRZQFSW.js.map