@whoz-oss/coday-client 0.125.3 → 0.126.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{a as _,i as D,t as B}from"./chunk-JG37UR26.js";import{b as m}from"./chunk-XIQ3L6H6.js";import{D as E,J as F,P as H,R as V,Rc as v,S as $,V as d,Z as a,a as O,b as C,ca as r,d as S,h as b,i as o,m as p,n as f,pa as U,t as L,u as I}from"./chunk-3JGMGRXW.js";var T=class i{selectedThreadIdSubject=new o(null);isLoadingSubject=new o(!1);isLoadingThreadListSubject=new o(!1);refreshThreadListSubject=new b;threadListSubject=new o([]);hasLoadedOncePerProject=new Map;currentProjectName=null;isLoading$=this.isLoadingSubject.asObservable();isLoadingThreadList$=this.isLoadingThreadListSubject.asObservable();threadApi=r(_);projectStateService=r(m);projectName$=this.projectStateService.selectedProject$.pipe(L(e=>e?.name),F());constructor(){I([this.projectName$,this.refreshThreadListSubject.asObservable().pipe(V(void 0))]).pipe(d(([e])=>{e!==this.currentProjectName&&(console.log("[THREAD_STATE] Project changed, clearing thread list"),this.threadListSubject.next([]),this.currentProjectName=e),e?this.hasLoadedOncePerProject.get(e)?console.log("[THREAD_STATE] Refreshing thread list for project",e,"(no spinner)"):(console.log("[THREAD_STATE] Initial load for project",e,"- showing spinner"),this.isLoadingThreadListSubject.next(!0)):(console.log("[THREAD_STATE] No project selected, hiding spinner"),this.isLoadingThreadListSubject.next(!1))}),$(([e])=>e?(console.log("[THREAD_STATE] Fetching threads for project:",e),this.threadApi.listThreads().pipe(L(t=>({threads:t,projectName:e})),E(t=>(console.error("[THREAD_STATE] Error loading thread list:",t),p({threads:[],projectName:e}))))):(console.log("[THREAD_STATE] No project selected, returning empty list"),p({threads:[],projectName:null}))),d(({threads:e,projectName:t})=>{console.log("[THREAD_STATE] Thread list loaded:",e.length,"threads for project",t),t&&this.hasLoadedOncePerProject.set(t,!0),this.isLoadingThreadListSubject.next(!1),this.threadListSubject.next(e)})).subscribe()}threadList$=this.threadListSubject.asObservable();refreshSelectedThreadSubject=new b;selectedThread$=I([this.projectName$,this.selectedThreadIdSubject.pipe(F()),this.refreshSelectedThreadSubject.pipe(V(void 0))]).pipe($(([e,t])=>!e||!t?p(null):(this.isLoadingSubject.next(!0),this.threadApi.getThread(t).pipe(H({bufferSize:1,refCount:!0})))),d(()=>{this.isLoadingSubject.next(!1)}));selectThread(e){this.selectedThreadIdSubject.next(e)}getSelectedThreadId(){return this.selectedThreadIdSubject.value}getSelectedThreadIdOrThrow(){let e=this.selectedThreadIdSubject.value;if(!e)throw new Error("[THREAD_STATE] No thread selected");return e}clearSelection(){this.selectedThreadIdSubject.next(null)}stop(){let e=this.selectedThreadIdSubject.value;if(!e){console.error("[THREAD_STATE] Cannot stop: no thread selected");return}console.log("[THREAD_STATE] Stopping thread:",e),this.threadApi.stopThread(e).subscribe({next:t=>console.log("[THREAD_STATE] Stop signal sent:",t.message),error:t=>console.error("[THREAD_STATE] Error stopping thread:",t)})}refreshThreadList(){console.log("[THREAD_STATE] Manually refreshing thread list"),this.refreshThreadListSubject.next()}updateStarLocal(e,t,n){let h=this.threadListSubject.value.map(c=>{if(c.id!==e)return c;let l=c.starring||[];return t&&!l.includes(n)?C(O({},c),{starring:[...l,n]}):!t&&l.includes(n)?C(O({},c),{starring:l.filter(u=>u!==n)}):c});this.threadListSubject.next(h)}refreshSelectedThread(){this.refreshSelectedThreadSubject.next()}updateThreadUsers(e,t){return this.threadApi.updateThreadUsers(e,t).pipe(d(()=>{this.refreshThreadList()}),E(n=>(console.error("[THREAD_STATE] Error updating thread users:",n),f(()=>n))))}renameThread(e,t){let n=t.trim();return!n||n.length===0?(console.error("[THREAD_STATE] Cannot rename thread: name is empty after trimming"),f(()=>new Error("Thread name cannot be empty"))):(console.log("[THREAD_STATE] Renaming thread:",e,"to:",n),this.threadApi.updateThread(e,n).pipe(d(s=>{console.log("[THREAD_STATE] Thread renamed successfully:",s),this.refreshThreadList()}),E(s=>(console.error("[THREAD_STATE] Error renaming thread:",s),f(()=>s)))))}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};var W=class i{http=r(v);usernameSubject=new o(null);authEnabledSubject=new o(!1);username$=this.usernameSubject.asObservable();authEnabled$=this.authEnabledSubject.asObservable();fetchCurrentUser(){return this.http.get("/api/user/me").pipe(d(e=>{this.usernameSubject.next(e.username),this.authEnabledSubject.next(e.authEnabled)}))}getUsername(){return this.usernameSubject.value}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};var j=class i{STORAGE_KEY="coday-preferences";isDesktopApp=!1;electronStorage=null;voiceLanguageSubject=new o("en-US");voiceLanguage$=this.voiceLanguageSubject.asObservable();voiceInputModeSubject=new o("browser");voiceInputMode$=this.voiceInputModeSubject.asObservable();enterToSendSubject=new o(!0);enterToSend$=this.enterToSendSubject.asObservable();voiceAnnounceEnabledSubject=new o(!1);voiceAnnounceEnabled$=this.voiceAnnounceEnabledSubject.asObservable();voiceModeSubject=new o("speech");voiceMode$=this.voiceModeSubject.asObservable();voiceReadFullTextSubject=new o(!1);voiceReadFullText$=this.voiceReadFullTextSubject.asObservable();voiceVolumeSubject=new o(.8);voiceVolume$=this.voiceVolumeSubject.asObservable();voiceRateSubject=new o(1.2);voiceRate$=this.voiceRateSubject.asObservable();selectedVoiceSubject=new o(null);selectedVoice$=this.selectedVoiceSubject.asObservable();printTechnicalMessagesSubject=new o(!1);printTechnicalMessages$=this.printTechnicalMessagesSubject.asObservable();hideTechnicalMessagesSubject=new o(!0);hideTechnicalMessages$=this.hideTechnicalMessagesSubject.asObservable();hideWarningMessagesSubject=new o(!1);hideWarningMessages$=this.hideWarningMessagesSubject.asObservable();agentNotificationEnabledSubject=new o(!1);agentNotificationEnabled$=this.agentNotificationEnabledSubject.asObservable();notificationSoundEnabledSubject=new o(!1);notificationSoundEnabled$=this.notificationSoundEnabledSubject.asObservable();browserNotificationEnabledSubject=new o(!1);browserNotificationEnabled$=this.browserNotificationEnabledSubject.asObservable();themeSubject=new o("light");theme$=this.themeSubject.asObservable();constructor(){console.log("[PREFERENCES] Initializing preferences service"),typeof window<"u"&&window.codayDesktop?.storage&&(this.isDesktopApp=!0,this.electronStorage=window.codayDesktop.storage,console.log("[PREFERENCES] Running in desktop app mode with persistent storage")),this.initializePreferences()}initializePreferences(){this.isDesktopApp?this.loadPreferencesAsync():this.loadPreferencesSync()}loadPreferencesSync(){let e=this.getPreferenceSync("voiceLanguage","en-US")??"en-US";this.voiceLanguageSubject.next(e),console.log("[PREFERENCES] Voice language initialized to:",e);let t=this.getPreferenceSync("useEnterToSend",!0)??!0;this.enterToSendSubject.next(t),console.log("[PREFERENCES] Enter to send initialized to:",t);let n=this.getPreferenceSync("voiceAnnounceEnabled",!1)??!1;this.voiceAnnounceEnabledSubject.next(n);let s=this.getPreferenceSync("voiceMode","speech")??"speech";this.voiceModeSubject.next(s);let h=this.getPreferenceSync("voiceReadFullText",!1)??!1;this.voiceReadFullTextSubject.next(h);let c=this.getPreferenceSync("voiceVolume",.8)??.8;this.voiceVolumeSubject.next(c);let l=this.getPreferenceSync("voiceRate",1.2)??1.2;this.voiceRateSubject.next(l);let u=this.getPreferenceSync("selectedVoice",null)??null;this.selectedVoiceSubject.next(u);let P=this.getPreferenceSync("printTechnicalMessages",!1)??!1;this.printTechnicalMessagesSubject.next(P);let y=this.getPreferenceSync("hideTechnicalMessages",!0)??!0;this.hideTechnicalMessagesSubject.next(y);let A=this.getPreferenceSync("hideWarningMessages",!1)??!1;this.hideWarningMessagesSubject.next(A);let w=this.getPreferenceSync("agentNotificationEnabled",!1)??!1;this.agentNotificationEnabledSubject.next(w);let R=this.getPreferenceSync("notificationSoundEnabled",!0)??!0;this.notificationSoundEnabledSubject.next(R);let M=this.getPreferenceSync("browserNotificationEnabled",!1)??!1;this.browserNotificationEnabledSubject.next(M);let x=this.getPreferenceSync("theme","light")??"light";this.themeSubject.next(x);let N=this.getPreferenceSync("voiceInputMode","browser")??"browser";this.voiceInputModeSubject.next(N),console.log("[PREFERENCES] All preferences initialized successfully")}loadPreferencesAsync(){return S(this,null,function*(){let e=(yield this.getPreferenceAsync("voiceLanguage","en-US"))??"en-US";this.voiceLanguageSubject.next(e),console.log("[PREFERENCES] Voice language initialized to:",e);let t=(yield this.getPreferenceAsync("useEnterToSend",!0))??!0;this.enterToSendSubject.next(t),console.log("[PREFERENCES] Enter to send initialized to:",t);let n=(yield this.getPreferenceAsync("voiceAnnounceEnabled",!1))??!1;this.voiceAnnounceEnabledSubject.next(n);let s=(yield this.getPreferenceAsync("voiceMode","speech"))??"speech";this.voiceModeSubject.next(s);let h=(yield this.getPreferenceAsync("voiceReadFullText",!1))??!1;this.voiceReadFullTextSubject.next(h);let c=(yield this.getPreferenceAsync("voiceVolume",.8))??.8;this.voiceVolumeSubject.next(c);let l=(yield this.getPreferenceAsync("voiceRate",1.2))??1.2;this.voiceRateSubject.next(l);let u=(yield this.getPreferenceAsync("selectedVoice",null))??null;this.selectedVoiceSubject.next(u);let P=(yield this.getPreferenceAsync("printTechnicalMessages",!1))??!1;this.printTechnicalMessagesSubject.next(P);let y=(yield this.getPreferenceAsync("hideTechnicalMessages",!0))??!0;this.hideTechnicalMessagesSubject.next(y);let A=(yield this.getPreferenceAsync("hideWarningMessages",!1))??!1;this.hideWarningMessagesSubject.next(A);let w=(yield this.getPreferenceAsync("agentNotificationEnabled",!1))??!1;this.agentNotificationEnabledSubject.next(w);let R=(yield this.getPreferenceAsync("notificationSoundEnabled",!0))??!0;this.notificationSoundEnabledSubject.next(R);let M=(yield this.getPreferenceAsync("browserNotificationEnabled",!1))??!1;this.browserNotificationEnabledSubject.next(M);let x=(yield this.getPreferenceAsync("theme","light"))??"light";this.themeSubject.next(x);let N=(yield this.getPreferenceAsync("voiceInputMode","browser"))??"browser";this.voiceInputModeSubject.next(N),console.log("[PREFERENCES] All preferences initialized successfully (async)")})}getPreference(e,t){return this.getPreferenceSync(e,t)}getPreferenceSync(e,t){try{let n=localStorage.getItem(this.STORAGE_KEY);if(!n)return t;let s=JSON.parse(n);return s[e]!==void 0?s[e]:t}catch(n){return t}}getPreferenceAsync(e,t){return S(this,null,function*(){if(!this.electronStorage)return this.getPreferenceSync(e,t);try{let n=yield this.electronStorage.get(this.STORAGE_KEY);if(!n)return t;let s=JSON.parse(n);return s[e]!==void 0?s[e]:t}catch(n){return t}})}setPreference(e,t){this.isDesktopApp?this.setPreferenceAsync(e,t):this.setPreferenceSync(e,t)}setPreferenceSync(e,t){try{let n=localStorage.getItem(this.STORAGE_KEY),s=n?JSON.parse(n):{};s[e]=t,localStorage.setItem(this.STORAGE_KEY,JSON.stringify(s)),this.updateSubject(e,t)}catch(n){console.error("Failed to set preference:",n)}}setPreferenceAsync(e,t){return S(this,null,function*(){if(!this.electronStorage){this.setPreferenceSync(e,t);return}try{let n=yield this.electronStorage.get(this.STORAGE_KEY),s=n?JSON.parse(n):{};s[e]=t,yield this.electronStorage.set(this.STORAGE_KEY,JSON.stringify(s)),this.updateSubject(e,t)}catch(n){console.error("Failed to set preference:",n)}})}updateSubject(e,t){e==="voiceLanguage"&&this.voiceLanguageSubject.next(t),e==="useEnterToSend"&&this.enterToSendSubject.next(t),e==="voiceAnnounceEnabled"&&this.voiceAnnounceEnabledSubject.next(t),e==="voiceMode"&&this.voiceModeSubject.next(t),e==="voiceReadFullText"&&this.voiceReadFullTextSubject.next(t),e==="voiceVolume"&&this.voiceVolumeSubject.next(t),e==="voiceRate"&&this.voiceRateSubject.next(t),e==="selectedVoice"&&this.selectedVoiceSubject.next(t),e==="printTechnicalMessages"&&this.printTechnicalMessagesSubject.next(t),e==="hideTechnicalMessages"&&this.hideTechnicalMessagesSubject.next(t),e==="hideWarningMessages"&&this.hideWarningMessagesSubject.next(t),e==="agentNotificationEnabled"&&this.agentNotificationEnabledSubject.next(t),e==="notificationSoundEnabled"&&this.notificationSoundEnabledSubject.next(t),e==="browserNotificationEnabled"&&this.browserNotificationEnabledSubject.next(t),e==="theme"&&this.themeSubject.next(t),e==="voiceInputMode"&&this.voiceInputModeSubject.next(t)}setVoiceLanguage(e){console.log("[PREFERENCES] Setting voice language to:",e),this.setPreference("voiceLanguage",e)}getVoiceLanguage(){return this.getPreference("voiceLanguage","en-US")??"en-US"}setVoiceInputMode(e){console.log("[PREFERENCES] Setting voice input mode to:",e),this.setPreference("voiceInputMode",e)}getVoiceInputMode(){return this.getPreference("voiceInputMode","browser")??"browser"}setEnterToSend(e){console.log("[PREFERENCES] Setting Enter to send to:",e),this.setPreference("useEnterToSend",e)}getEnterToSend(){return this.getPreference("useEnterToSend",!1)??!1}setVoiceAnnounceEnabled(e){console.log("[PREFERENCES] Setting voice announce enabled to:",e),this.setPreference("voiceAnnounceEnabled",e)}getVoiceAnnounceEnabled(){return this.getPreference("voiceAnnounceEnabled",!1)??!1}setVoiceMode(e){console.log("[PREFERENCES] Setting voice mode to:",e),this.setPreference("voiceMode",e)}getVoiceMode(){return this.getPreference("voiceMode","speech")??"speech"}setVoiceReadFullText(e){console.log("[PREFERENCES] Setting voice read full text to:",e),this.setPreference("voiceReadFullText",e)}getVoiceReadFullText(){return this.getPreference("voiceReadFullText",!1)??!1}setVoiceVolume(e){let t=Math.max(0,Math.min(1,e));console.log("[PREFERENCES] Setting voice volume to:",t),this.setPreference("voiceVolume",t)}getVoiceVolume(){return this.getPreference("voiceVolume",.8)??.8}setVoiceRate(e){let t=Math.max(.5,Math.min(2,e));console.log("[PREFERENCES] Setting voice rate to:",t),this.setPreference("voiceRate",t)}getVoiceRate(){return this.getPreference("voiceRate",1.2)??1.2}setSelectedVoice(e){console.log("[PREFERENCES] Setting selected voice to:",e),this.setPreference("selectedVoice",e)}getSelectedVoice(){return this.getPreference("selectedVoice",null)??null}setPrintTechnicalMessages(e){console.log("[PREFERENCES] Setting print technical messages to:",e),this.setPreference("printTechnicalMessages",e)}getPrintTechnicalMessages(){return this.getPreference("printTechnicalMessages",!1)??!1}setHideTechnicalMessages(e){console.log("[PREFERENCES] Setting hide technical messages to:",e),this.setPreference("hideTechnicalMessages",e)}getHideTechnicalMessages(){return this.getPreference("hideTechnicalMessages",!0)??!0}setHideWarningMessages(e){console.log("[PREFERENCES] Setting hide warning messages to:",e),this.setPreference("hideWarningMessages",e)}getHideWarningMessages(){return this.getPreference("hideWarningMessages",!1)??!1}setAgentNotificationEnabled(e){console.log("[PREFERENCES] Setting agent notification enabled to:",e),this.setPreference("agentNotificationEnabled",e)}getAgentNotificationEnabled(){return this.getPreference("agentNotificationEnabled",!1)??!1}setNotificationSoundEnabled(e){console.log("[PREFERENCES] Setting notification sound enabled to:",e),this.setPreference("notificationSoundEnabled",e)}getNotificationSoundEnabled(){return this.getPreference("notificationSoundEnabled",!0)??!0}setBrowserNotificationEnabled(e){console.log("[PREFERENCES] Setting browser notification enabled to:",e),this.setPreference("browserNotificationEnabled",e)}getBrowserNotificationEnabled(){return this.getPreference("browserNotificationEnabled",!1)??!1}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};var z=class i{eventSource=null;eventsSubject=new b;connectionStatusSubject=new o({connected:!1,reconnectAttempts:0,maxAttempts:3});reconnectAttempts=0;MAX_RECONNECT_ATTEMPTS=3;RECONNECT_DELAY=2e3;events$=this.eventsSubject.asObservable();connectionStatus$=this.connectionStatusSubject.asObservable();ngZone=r(U);connectToThread(e,t){console.log("[SSE] Connecting to thread event stream:",e,t),this.eventSource&&(console.log("[SSE] Closing existing EventSource"),this.eventSource.close());let n=`/api/projects/${e}/threads/${t}/event-stream`;console.log("[SSE] EventSource URL:",n),this.eventSource=new EventSource(n),this.setupEventHandlers()}setupEventHandlers(){this.eventSource&&(this.eventSource.onmessage=e=>{this.ngZone.run(()=>{console.log("[SSE] Message received:",e.data.substring(0,100)),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0);try{let t=JSON.parse(e.data),n=B(t);n?(console.log("[SSE] Event:",n.type),this.eventsSubject.next(n)):console.warn("[SSE] Failed to build event:",t.type)}catch(t){console.error("[SSE] Parse error:",t.message)}})},this.eventSource.onopen=()=>{this.ngZone.run(()=>{console.log("[SSE] Connection established"),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0)})},this.eventSource.onerror=e=>{this.ngZone.run(()=>{console.log("[SSE] EventSource error:",e),this.eventSource?.readyState===EventSource.CLOSED&&(console.log("[SSE] Connection closed"),this.updateConnectionStatus(!1,this.reconnectAttempts),this.reconnectAttempts<this.MAX_RECONNECT_ATTEMPTS?(console.log(`[SSE] Attempting reconnect ${this.reconnectAttempts+1}/${this.MAX_RECONNECT_ATTEMPTS}`),this.eventsSubject.next(new D({error:new Error(`Connection lost. Attempting to reconnect (${this.reconnectAttempts+1}/${this.MAX_RECONNECT_ATTEMPTS})...`)})),setTimeout(()=>{this.reconnectAttempts++,console.warn("[SSE] Reconnection may not work properly with thread-based connections")},this.RECONNECT_DELAY)):(console.log("[SSE] Max reconnection attempts reached"),this.eventsSubject.next(new D({error:new Error("Connection lost permanently. Please refresh the page.")}))))})})}disconnect(){this.eventSource&&(console.log("[SSE] Disconnecting EventSource"),this.eventSource.close(),this.eventSource=null,this.updateConnectionStatus(!1,0))}updateConnectionStatus(e,t){this.connectionStatusSubject.next({connected:e,reconnectAttempts:t,maxAttempts:this.MAX_RECONNECT_ATTEMPTS})}ngOnDestroy(){this.disconnect(),this.eventsSubject.complete(),this.connectionStatusSubject.complete()}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};var Y=class i{http=r(v);projectState=r(m);threadState=r(T);getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/threads/${this.threadState.getSelectedThreadIdOrThrow()}/messages`}getMessages(){return this.http.get(this.getBaseUrl())}sendMessage(e){return this.http.post(this.getBaseUrl(),e,{responseType:"text"})}sendFreeMessage(e){return this.http.post(this.getBaseUrl(),{message:e})}getMessage(e){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(e)}`)}deleteMessage(e){return this.http.delete(`${this.getBaseUrl()}/${encodeURIComponent(e)}`)}getFormattedMessage(e){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(e)}/formatted`,{responseType:"text"})}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};var G=class i{currentThemeSubject=new o("light");currentTheme$=this.currentThemeSubject.asObservable();preferences=r(j);subscription=null;constructor(){console.log("[THEME] Initializing theme service"),this.initializeTheme(),this.setupSystemThemeListener()}ngOnDestroy(){this.subscription?.unsubscribe()}initializeTheme(){this.subscription=this.preferences.theme$.subscribe(e=>{console.log("[THEME] Theme preference changed to:",e),this.applyTheme(e)})}setTheme(e){this.preferences.setPreference("theme",e),this.applyTheme(e)}getCurrentTheme(){return this.currentThemeSubject.value}applyTheme(e){if(console.log("[THEME] Applying theme:",e),this.currentThemeSubject.next(e),e==="system")if(typeof window<"u"&&window.matchMedia){let n=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";console.log("[THEME] System theme resolved to:",n),this.setDocumentTheme(n)}else console.log("[THEME] matchMedia not available, defaulting to light theme"),this.setDocumentTheme("light");else this.setDocumentTheme(e)}setDocumentTheme(e){console.log("[THEME] Setting document theme to:",e),typeof document<"u"&&document.documentElement&&(e==="dark"?document.documentElement.setAttribute("data-theme","dark"):document.documentElement.removeAttribute("data-theme"))}setupSystemThemeListener(){typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{this.getCurrentTheme()==="system"&&this.setDocumentTheme(e.matches?"dark":"light")})}static \u0275fac=function(t){return new(t||i)};static \u0275prov=a({token:i,factory:i.\u0275fac,providedIn:"root"})};export{T as a,W as b,j as c,z as d,Y as e,G as f};