@whoz-oss/coday-client 0.90.0 → 0.91.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.
package/browser/index.html
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
<style>:root{--color-bg:linear-gradient(135deg, #fafbfc 0%, #f5f6f8 100%);--color-bg-solid:#fafbfc;--color-bg-secondary:rgba(255, 255, 255, .7);--color-bg-secondary-rgb:255 255 255;--color-text:#1d1d1f;--color-text-secondary:#6e6e73;--color-text-inverse:#ffffff;--color-primary:#007aff;--color-primary-hover:#0051d5;--color-accent:#8b5cf6;--color-link:#007aff;--color-border:rgba(0, 0, 0, .1);--color-border-light:rgba(40, 40, 40, .08);--color-input-bg:rgba(255, 255, 255, .8);--color-success:#34c759;--color-error:#ff3b30;--color-warning:#ff9500;--color-info:#5ac8fa;--color-message-user:rgba(0, 122, 255, .1);--color-message-ai:rgba(255, 255, 255, .8);--color-code-bg:rgba(142, 142, 147, .12);--color-code-text:#ff375f;--color-bg-hover:rgba(0, 0, 0, .04);--glass-bg:rgba(255, 255, 255, .72);--glass-border:rgba(255, 255, 255, .18);--glass-shadow:0 8px 32px 0 rgba(31, 38, 135, .15);--glass-backdrop-blur:blur(20px);--color-shadow:rgba(0, 0, 0, .08);--color-overlay:rgba(0, 0, 0, .4)}@media print{html,body,app-root{height:auto!important;max-height:none!important;min-height:auto!important;overflow:visible!important;position:static!important}body{background:#fff!important;color:#000!important;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif!important;font-size:11pt;line-height:1.6;padding:1rem!important}*{animation:none!important;transition:none!important;box-shadow:none!important;text-shadow:none!important}}*{box-sizing:border-box}html{color-scheme:light;--mat-sys-background:light-dark(#faf9fd, #121316);--mat-sys-error:light-dark(#ba1a1a, #ffb4ab);--mat-sys-error-container:light-dark(#ffdad6, #93000a);--mat-sys-inverse-on-surface:light-dark(#f2f0f4, #2f3033);--mat-sys-inverse-primary:light-dark(#abc7ff, #005cbb);--mat-sys-inverse-surface:light-dark(#2f3033, #e3e2e6);--mat-sys-on-background:light-dark(#1a1b1f, #e3e2e6);--mat-sys-on-error:light-dark(#ffffff, #690005);--mat-sys-on-error-container:light-dark(#93000a, #ffdad6);--mat-sys-on-primary:light-dark(#ffffff, #002f65);--mat-sys-on-primary-container:light-dark(#00458f, #d7e3ff);--mat-sys-on-primary-fixed:light-dark(#001b3f, #001b3f);--mat-sys-on-primary-fixed-variant:light-dark(#00458f, #00458f);--mat-sys-on-secondary:light-dark(#ffffff, #283041);--mat-sys-on-secondary-container:light-dark(#3e4759, #dae2f9);--mat-sys-on-secondary-fixed:light-dark(#131c2b, #131c2b);--mat-sys-on-secondary-fixed-variant:light-dark(#3e4759, #3e4759);--mat-sys-on-surface:light-dark(#1a1b1f, #e3e2e6);--mat-sys-on-surface-variant:light-dark(#44474e, #e0e2ec);--mat-sys-on-tertiary:light-dark(#ffffff, #002f65);--mat-sys-on-tertiary-container:light-dark(#00458f, #d7e3ff);--mat-sys-on-tertiary-fixed:light-dark(#001b3f, #001b3f);--mat-sys-on-tertiary-fixed-variant:light-dark(#00458f, #00458f);--mat-sys-outline:light-dark(#74777f, #8e9099);--mat-sys-outline-variant:light-dark(#c4c6d0, #44474e);--mat-sys-primary:light-dark(#005cbb, #abc7ff);--mat-sys-primary-container:light-dark(#d7e3ff, #00458f);--mat-sys-primary-fixed:light-dark(#d7e3ff, #d7e3ff);--mat-sys-primary-fixed-dim:light-dark(#abc7ff, #abc7ff);--mat-sys-scrim:light-dark(#000000, #000000);--mat-sys-secondary:light-dark(#565e71, #bec6dc);--mat-sys-secondary-container:light-dark(#dae2f9, #3e4759);--mat-sys-secondary-fixed:light-dark(#dae2f9, #dae2f9);--mat-sys-secondary-fixed-dim:light-dark(#bec6dc, #bec6dc);--mat-sys-shadow:light-dark(#000000, #000000);--mat-sys-surface:light-dark(#faf9fd, #121316);--mat-sys-surface-bright:light-dark(#faf9fd, #38393c);--mat-sys-surface-container:light-dark(#efedf0, #1f2022);--mat-sys-surface-container-high:light-dark(#e9e7eb, #292a2c);--mat-sys-surface-container-highest:light-dark(#e3e2e6, #343537);--mat-sys-surface-container-low:light-dark(#f4f3f6, #1a1b1f);--mat-sys-surface-container-lowest:light-dark(#ffffff, #0d0e11);--mat-sys-surface-dim:light-dark(#dbd9dd, #121316);--mat-sys-surface-tint:light-dark(#005cbb, #abc7ff);--mat-sys-surface-variant:light-dark(#e0e2ec, #44474e);--mat-sys-tertiary:light-dark(#005cbb, #abc7ff);--mat-sys-tertiary-container:light-dark(#d7e3ff, #00458f);--mat-sys-tertiary-fixed:light-dark(#d7e3ff, #d7e3ff);--mat-sys-tertiary-fixed-dim:light-dark(#abc7ff, #abc7ff);--mat-sys-neutral-variant20:#2d3038;--mat-sys-neutral10:#1a1b1f;--mat-sys-level0:0px 0px 0px 0px rgba(0, 0, 0, .2), 0px 0px 0px 0px rgba(0, 0, 0, .14), 0px 0px 0px 0px rgba(0, 0, 0, .12);--mat-sys-level1:0px 2px 1px -1px rgba(0, 0, 0, .2), 0px 1px 1px 0px rgba(0, 0, 0, .14), 0px 1px 3px 0px rgba(0, 0, 0, .12);--mat-sys-level2:0px 3px 3px -2px rgba(0, 0, 0, .2), 0px 3px 4px 0px rgba(0, 0, 0, .14), 0px 1px 8px 0px rgba(0, 0, 0, .12);--mat-sys-level3:0px 3px 5px -1px rgba(0, 0, 0, .2), 0px 6px 10px 0px rgba(0, 0, 0, .14), 0px 1px 18px 0px rgba(0, 0, 0, .12);--mat-sys-level4:0px 5px 5px -3px rgba(0, 0, 0, .2), 0px 8px 10px 1px rgba(0, 0, 0, .14), 0px 3px 14px 2px rgba(0, 0, 0, .12);--mat-sys-level5:0px 7px 8px -4px rgba(0, 0, 0, .2), 0px 12px 17px 2px rgba(0, 0, 0, .14), 0px 5px 22px 4px rgba(0, 0, 0, .12);--mat-sys-body-large:400 1rem / 1.5rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-large-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-large-line-height:1.5rem;--mat-sys-body-large-size:1rem;--mat-sys-body-large-tracking:.031rem;--mat-sys-body-large-weight:400;--mat-sys-body-medium:400 .875rem / 1.25rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-medium-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-medium-line-height:1.25rem;--mat-sys-body-medium-size:.875rem;--mat-sys-body-medium-tracking:.016rem;--mat-sys-body-medium-weight:400;--mat-sys-body-small:400 .75rem / 1rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-small-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-body-small-line-height:1rem;--mat-sys-body-small-size:.75rem;--mat-sys-body-small-tracking:.025rem;--mat-sys-body-small-weight:400;--mat-sys-display-large:400 3.562rem / 4rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-large-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-large-line-height:4rem;--mat-sys-display-large-size:3.562rem;--mat-sys-display-large-tracking:-.016rem;--mat-sys-display-large-weight:400;--mat-sys-display-medium:400 2.812rem / 3.25rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-medium-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-medium-line-height:3.25rem;--mat-sys-display-medium-size:2.812rem;--mat-sys-display-medium-tracking:0;--mat-sys-display-medium-weight:400;--mat-sys-display-small:400 2.25rem / 2.75rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-small-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-display-small-line-height:2.75rem;--mat-sys-display-small-size:2.25rem;--mat-sys-display-small-tracking:0;--mat-sys-display-small-weight:400;--mat-sys-headline-large:400 2rem / 2.5rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-large-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-large-line-height:2.5rem;--mat-sys-headline-large-size:2rem;--mat-sys-headline-large-tracking:0;--mat-sys-headline-large-weight:400;--mat-sys-headline-medium:400 1.75rem / 2.25rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-medium-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-medium-line-height:2.25rem;--mat-sys-headline-medium-size:1.75rem;--mat-sys-headline-medium-tracking:0;--mat-sys-headline-medium-weight:400;--mat-sys-headline-small:400 1.5rem / 2rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-small-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-headline-small-line-height:2rem;--mat-sys-headline-small-size:1.5rem;--mat-sys-headline-small-tracking:0;--mat-sys-headline-small-weight:400;--mat-sys-label-large:500 .875rem / 1.25rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-large-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-large-line-height:1.25rem;--mat-sys-label-large-size:.875rem;--mat-sys-label-large-tracking:.006rem;--mat-sys-label-large-weight:500;--mat-sys-label-large-weight-prominent:700;--mat-sys-label-medium:500 .75rem / 1rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-medium-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-medium-line-height:1rem;--mat-sys-label-medium-size:.75rem;--mat-sys-label-medium-tracking:.031rem;--mat-sys-label-medium-weight:500;--mat-sys-label-medium-weight-prominent:700;--mat-sys-label-small:500 .688rem / 1rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-small-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-label-small-line-height:1rem;--mat-sys-label-small-size:.688rem;--mat-sys-label-small-tracking:.031rem;--mat-sys-label-small-weight:500;--mat-sys-title-large:400 1.375rem / 1.75rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-large-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-large-line-height:1.75rem;--mat-sys-title-large-size:1.375rem;--mat-sys-title-large-tracking:0;--mat-sys-title-large-weight:400;--mat-sys-title-medium:500 1rem / 1.5rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-medium-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-medium-line-height:1.5rem;--mat-sys-title-medium-size:1rem;--mat-sys-title-medium-tracking:.009rem;--mat-sys-title-medium-weight:500;--mat-sys-title-small:500 .875rem / 1.25rem -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-small-font:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Helvetica Neue", Arial, sans-serif;--mat-sys-title-small-line-height:1.25rem;--mat-sys-title-small-size:.875rem;--mat-sys-title-small-tracking:.006rem;--mat-sys-title-small-weight:500;--mat-sys-corner-extra-large:28px;--mat-sys-corner-extra-large-top:28px 28px 0 0;--mat-sys-corner-extra-small:4px;--mat-sys-corner-extra-small-top:4px 4px 0 0;--mat-sys-corner-full:9999px;--mat-sys-corner-large:16px;--mat-sys-corner-large-end:0 16px 16px 0;--mat-sys-corner-large-start:16px 0 0 16px;--mat-sys-corner-large-top:16px 16px 0 0;--mat-sys-corner-medium:12px;--mat-sys-corner-none:0;--mat-sys-corner-small:8px;--mat-sys-dragged-state-layer-opacity:.16;--mat-sys-focus-state-layer-opacity:.12;--mat-sys-hover-state-layer-opacity:.08;--mat-sys-pressed-state-layer-opacity:.12;--mat-snack-bar-container-shape:transparent;--mat-snack-bar-container-color:transparent;--mat-snack-bar-supporting-text-color:var(--color-text)}html,body{margin:0;padding:0;width:100%;height:100%}body{background:var(--color-bg);color:var(--color-text);font-family:-apple-system,BlinkMacSystemFont,SF Pro Display,Segoe UI,Helvetica Neue,Arial,sans-serif;transition:background .3s ease,color .3s ease;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}</style><link rel="stylesheet" href="styles-I3V5BO4R.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles-I3V5BO4R.css"></noscript></head>
|
|
14
14
|
<body>
|
|
15
15
|
<app-root></app-root>
|
|
16
|
-
<link rel="modulepreload" href="chunk-ODM275WP.js"><link rel="modulepreload" href="chunk-QITHUHCN.js"><link rel="modulepreload" href="chunk-Y5DXUE3H.js"><link rel="modulepreload" href="chunk-GBTE3TIN.js"><link rel="modulepreload" href="chunk-WG23DARU.js"><script src="polyfills-7R4CRVNH.js" type="module"></script><script src="main-
|
|
16
|
+
<link rel="modulepreload" href="chunk-ODM275WP.js"><link rel="modulepreload" href="chunk-QITHUHCN.js"><link rel="modulepreload" href="chunk-Y5DXUE3H.js"><link rel="modulepreload" href="chunk-GBTE3TIN.js"><link rel="modulepreload" href="chunk-WG23DARU.js"><script src="polyfills-7R4CRVNH.js" type="module"></script><script src="main-6PZ4G65W.js" type="module"></script></body>
|
|
17
17
|
</html>
|
|
@@ -333,7 +333,7 @@ Verify the memory system's overall health:
|
|
|
333
333
|
- List any remaining issues or concerns
|
|
334
334
|
- Provide recommendations for maintaining memory quality
|
|
335
335
|
|
|
336
|
-
This ensures the memory system stays efficient and valuable.`],createdBy:"system",createdAt:new Date("2024-01-01").toISOString(),webhookEnabled:!1,parameterFormat:""}];var GM=[Mi.type,ki.type,li.type,so.type,un.type,gn.type,zt.type,Ui.type];var $h={CONFLUENCE:[],GIT:[],GITLAB:[],JIRA:[],SLACK:[],ZENDESK:[],BASECAMP:[]},mT=Object.keys($h).filter(o=>$h[o]?.length===0);var Gi=class o{eventSource=null;eventsSubject=new D;connectionStatusSubject=new le({connected:!1,reconnectAttempts:0,maxAttempts:3});reconnectAttempts=0;MAX_RECONNECT_ATTEMPTS=3;RECONNECT_DELAY=2e3;events$=this.eventsSubject.asObservable();connectionStatus$=this.connectionStatusSubject.asObservable();ngZone=m(de);connectToThread(t,e){console.log("[SSE] Connecting to thread event stream:",t,e),this.eventSource&&(console.log("[SSE] Closing existing EventSource"),this.eventSource.close());let i=`/api/projects/${t}/threads/${e}/event-stream`;console.log("[SSE] EventSource URL:",i),this.eventSource=new EventSource(i),this.setupEventHandlers()}setupEventHandlers(){this.eventSource&&(this.eventSource.onmessage=t=>{this.ngZone.run(()=>{console.log("[SSE] Message received:",t.data.substring(0,100)),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0);try{let e=JSON.parse(t.data),i=oa(e);i?(console.log("[SSE] Event:",i.type),this.eventsSubject.next(i)):console.warn("[SSE] Failed to build event:",e.type)}catch(e){console.error("[SSE] Parse error:",e.message)}})},this.eventSource.onopen=()=>{this.ngZone.run(()=>{console.log("[SSE] Connection established"),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0)})},this.eventSource.onerror=t=>{this.ngZone.run(()=>{console.log("[SSE] EventSource error:",t),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 Si({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 Si({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(t,e){this.connectionStatusSubject.next({connected:t,reconnectAttempts:e,maxAttempts:this.MAX_RECONNECT_ATTEMPTS})}ngOnDestroy(){this.disconnect(),this.eventsSubject.complete(),this.connectionStatusSubject.complete()}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Yi=class o{http=m(Je);projectState=m(Te);getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/threads`}listThreads(){return this.http.get(this.getBaseUrl())}getThread(t){return this.http.get(`${this.getBaseUrl()}/${t}`)}createThread(t){let e=t?{name:t}:{};return this.http.post(this.getBaseUrl(),e)}updateThread(t,e){return this.http.put(`${this.getBaseUrl()}/${t}`,{name:e})}starThread(t){return this.http.post(`${this.getBaseUrl()}/${t}/star`,{})}unstarThread(t){return this.http.delete(`${this.getBaseUrl()}/${t}/star`)}deleteThread(t){return this.http.delete(`${this.getBaseUrl()}/${t}`)}stopThread(t){return this.http.post(`${this.getBaseUrl()}/${t}/stop`,{})}getThreadMessages(t){return this.http.get(`${this.getBaseUrl()}/${t}/messages`)}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Tt=class o{selectedThreadIdSubject=new le(null);isLoadingSubject=new le(!1);isLoadingThreadListSubject=new le(!1);refreshThreadListSubject=new D;threadListSubject=new le([]);hasLoadedOncePerProject=new Map;currentProjectName=null;isLoading$=this.isLoadingSubject.asObservable();isLoadingThreadList$=this.isLoadingThreadListSubject.asObservable();threadApi=m(Yi);projectStateService=m(Te);projectName$=this.projectStateService.selectedProject$.pipe(Oe(t=>t?.name),Sa());constructor(){Wn([this.projectName$,this.refreshThreadListSubject.asObservable().pipe(At(void 0))]).pipe(ht(([t])=>{t!==this.currentProjectName&&(console.log("[THREAD_STATE] Project changed, clearing thread list"),this.threadListSubject.next([]),this.currentProjectName=t),t?this.hasLoadedOncePerProject.get(t)?console.log("[THREAD_STATE] Refreshing thread list for project",t,"(no spinner)"):(console.log("[THREAD_STATE] Initial load for project",t,"- showing spinner"),this.isLoadingThreadListSubject.next(!0)):(console.log("[THREAD_STATE] No project selected, hiding spinner"),this.isLoadingThreadListSubject.next(!1))}),Un(([t])=>t?(console.log("[THREAD_STATE] Fetching threads for project:",t),this.threadApi.listThreads().pipe(Oe(e=>({threads:e,projectName:t})),$n(e=>(console.error("[THREAD_STATE] Error loading thread list:",e),Ot({threads:[],projectName:t}))))):(console.log("[THREAD_STATE] No project selected, returning empty list"),Ot({threads:[],projectName:null}))),ht(({threads:t,projectName:e})=>{console.log("[THREAD_STATE] Thread list loaded:",t.length,"threads for project",e),e&&this.hasLoadedOncePerProject.set(e,!0),this.isLoadingThreadListSubject.next(!1),this.threadListSubject.next(t)})).subscribe()}threadList$=this.threadListSubject.asObservable();selectedThread$=Wn([this.projectName$,this.selectedThreadIdSubject.pipe(Sa())]).pipe(ht(([t,e])=>{console.log("\u{1F43C} combineLatest emitted:",{projectName:t,threadId:e})}),Un(([t,e])=>!t||!e?(console.log("\u{1F43C} null"),Ot(null)):(console.log("\u{1F43C} loading thread:",e),this.isLoadingSubject.next(!0),this.threadApi.getThread(e).pipe(ht(i=>{console.log("\u{1F43C} loaded thread:",i?.id)}),Sr({bufferSize:1,refCount:!0})))),ht(()=>{console.log("\u{1F43C} finished loading"),this.isLoadingSubject.next(!1)}));selectThread(t){this.selectedThreadIdSubject.next(t)}getSelectedThreadId(){return this.selectedThreadIdSubject.value}getSelectedThreadIdOrThrow(){let t=this.selectedThreadIdSubject.value;if(!t)throw new Error("[THREAD_STATE] No thread selected");return t}clearSelection(){this.selectedThreadIdSubject.next(null)}stop(){let t=this.selectedThreadIdSubject.value;if(!t){console.error("[THREAD_STATE] Cannot stop: no thread selected");return}console.log("[THREAD_STATE] Stopping thread:",t),this.threadApi.stopThread(t).subscribe({next:e=>console.log("[THREAD_STATE] Stop signal sent:",e.message),error:e=>console.error("[THREAD_STATE] Error stopping thread:",e)})}refreshThreadList(){console.log("[THREAD_STATE] Manually refreshing thread list"),this.refreshThreadListSubject.next()}renameThread(t,e){let i=e.trim();return!i||i.length===0?(console.error("[THREAD_STATE] Cannot rename thread: name is empty after trimming"),wr(()=>new Error("Thread name cannot be empty"))):(console.log("[THREAD_STATE] Renaming thread:",t,"to:",i),this.threadApi.updateThread(t,i).pipe(ht(n=>{console.log("[THREAD_STATE] Thread renamed successfully:",n),this.refreshThreadList()}),$n(n=>(console.error("[THREAD_STATE] Error renaming thread:",n),wr(()=>n)))))}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Xo=class o{http=m(Je);projectState=m(Te);threadState=m(Tt);getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/threads/${this.threadState.getSelectedThreadIdOrThrow()}/messages`}getMessages(){return this.http.get(this.getBaseUrl())}sendMessage(t){return this.http.post(this.getBaseUrl(),t,{responseType:"text"})}getMessage(t){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(t)}`)}deleteMessage(t){return this.http.delete(`${this.getBaseUrl()}/${encodeURIComponent(t)}`)}getFormattedMessage(t){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(t)}/formatted`,{responseType:"text"})}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Yt=class o{destroy$=new D;currentProject=null;currentThread=null;messagesSubject=new le([]);isThinkingSubject=new le(!1);currentChoiceSubject=new le(null);projectTitleSubject=new le("Coday");currentInviteEventSubject=new le(null);messageToRestoreSubject=new le("");threadUpdateEventSubject=new le(null);currentChoiceEvent=null;thinkingTimeout=null;accumulatedChunks="";streamingTextSubject=new le("");subThreadEventsSubject=new D;subThreadEvents$=this.subThreadEventsSubject.asObservable();subThreadEventBuffers=new Map;getBufferedSubThreadEvents(t){return this.subThreadEventBuffers.get(t)??[]}messages$=this.messagesSubject.asObservable();streamingText$=this.streamingTextSubject.asObservable();isThinking$=this.isThinkingSubject.asObservable();currentChoice$=this.currentChoiceSubject.asObservable();currentInviteEvent$=this.currentInviteEventSubject.asObservable();messageToRestore$=this.messageToRestoreSubject.asObservable();threadUpdateEvent$=this.threadUpdateEventSubject.asObservable();connectionStatus$;tabTitleService=null;eventStream=m(Gi);messageApi=m(Xo);constructor(){this.connectionStatus$=this.eventStream.connectionStatus$,this.initializeEventHandling()}setTabTitleService(t){this.tabTitleService=t}connectToThread(t,e){this.currentProject=t,this.currentThread=e,this.eventStream.connectToThread(t,e),setTimeout(()=>this.processUnansweredInvites(),500)}processUnansweredInvites(){let t=this.messagesSubject.value,e=t.filter(i=>i.type==="text"&&i.parentKey===void 0&&i.invite!==void 0).filter(i=>!t.some(n=>n.type==="text"&&n.role==="user"&&n.parentKey===i.id));e.length>0&&console.log("[CODAY] Found",e.length,"unanswered invite(s)")}resetMessages(){this.messagesSubject.next([]),this.currentChoiceSubject.next(null),this.currentInviteEventSubject.next(null),this.currentChoiceEvent=null,this.accumulatedChunks="",this.streamingTextSubject.next(""),this.subThreadEventBuffers.clear(),this.stopThinking()}sendMessage(t){if(!this.currentProject||!this.currentThread){console.error("[CODAY] Cannot send message: no project or thread selected");return}this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive();let e=this.currentInviteEventSubject.value;if(e){let i=e.buildAnswer(t);this.currentInviteEventSubject.next(null),this.messageApi.sendMessage(i).subscribe({error:n=>{console.error("[CODAY] Send error:",n),this.stopThinking()}})}else{let i=new zt({answer:t});this.messageApi.sendMessage(i).subscribe({error:n=>{console.error("[CODAY] Send error:",n),this.stopThinking()}})}}sendChoice(t){if(!this.currentProject||!this.currentThread){console.error("[CODAY] Cannot send choice: no project or thread selected");return}if(this.currentChoiceEvent){this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive();let e=this.currentChoiceEvent.buildAnswer(t);this.currentChoiceSubject.next(null),this.currentChoiceEvent=null,this.messageApi.sendMessage(e).subscribe({next:()=>{},error:i=>{console.error("[CODAY-CHOICE] Choice error:",i),this.stopThinking()}})}else console.error("[CODAY-CHOICE] No choice event available for choice:",t)}deleteMessage(t){let e=this.messagesSubject.value.find(n=>n.id===t),i=this.extractTextContentFromMessage(e);return this.messageApi.deleteMessage(t).pipe(ht(n=>{n.success&&(this.removeMessagesFromIndex(t),i.trim()&&this.messageToRestoreSubject.next(i))}))}getCurrentProjectTitle(){return this.projectTitleSubject.value}getCurrentInviteEvent(){return this.currentInviteEventSubject.value}setThinkingForPendingMessage(){this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive()}initializeEventHandling(){this.eventStream.events$.pipe(N(this.destroy$)).subscribe({next:t=>this.handleEvent(t),error:t=>console.error("[CODAY] Event stream error:",t),complete:()=>console.log("[CODAY] Event stream completed")})}handleEvent(t){if(t.threadId&&t.threadId!==this.currentThread){let e=this.subThreadEventBuffers.get(t.threadId);e?e.push(t):this.subThreadEventBuffers.set(t.threadId,[t]),this.subThreadEventsSubject.next(t);return}t instanceof Mi?this.handleMessageEvent(t):t instanceof Fn?this.handleTextChunkEvent(t):t instanceof $i?this.handleTextEvent(t):t instanceof zt?this.handleAnswerEvent(t):t instanceof Si?this.handleErrorEvent(t):t instanceof ao?this.handleWarnEvent(t):t instanceof Nn?this.handleThinkingEvent(t):t instanceof ki?this.handleToolRequestEvent(t):t instanceof li?this.handleToolResponseEvent(t):t instanceof gn?this.handleChoiceEvent(t):t instanceof Go?this.handleHeartBeatEvent(t):t instanceof un?this.handleInviteEvent(t):t instanceof Yo?this.handleThreadUpdateEvent(t):t instanceof Ui?this.handleDelegationEvent(t):t instanceof Qo||t instanceof qi||console.warn("[CODAY] Unhandled event type:",t.type)}handleDelegationEvent(t){if(console.log("[CODAY] DelegationEvent received:",t.subThreadId,t.agentName),this.messagesSubject.value.findIndex(n=>n.subThreadId===t.subThreadId)===-1){let n={id:t.timestamp,role:"system",speaker:t.agentName,content:[{type:"text",content:""}],timestamp:new Date,type:"delegation",subThreadId:t.subThreadId,delegationAgentName:t.agentName};this.addMessage(n)}}handleThreadUpdateEvent(t){this.threadUpdateEventSubject.next(t)}handleMessageEvent(t){t.role==="assistant"&&this.accumulatedChunks&&(this.accumulatedChunks="",this.streamingTextSubject.next(""));let e={id:t.timestamp,role:t.role,speaker:t.name,content:t.content,timestamp:t.date,type:"text"};this.addMessage(e)}handleTextChunkEvent(t){this.accumulatedChunks+=t.chunk,this.streamingTextSubject.next(this.accumulatedChunks)}handleTextEvent(t){let e={id:t.timestamp,role:t.speaker?"assistant":"system",speaker:t.speaker??"System",content:[{type:"text",content:t.text}],timestamp:t.date,type:t.speaker?"text":"technical"};this.addMessage(e)}handleAnswerEvent(t){let e={id:t.timestamp,role:"user",speaker:"User",content:[{type:"text",content:t.answer}],timestamp:t.date,type:"text",parentKey:t.parentKey,invite:t.invite};this.addMessage(e)}handleErrorEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:`Error: ${JSON.stringify(t.error)}`}],timestamp:t.date,type:"error"};this.addMessage(e)}handleWarnEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:`Warning: ${JSON.stringify(t.warning)}`}],timestamp:t.date,type:"warning"};this.addMessage(e)}handleThinkingEvent(t){this.currentInviteEventSubject.value||this.currentChoiceEvent||(this.clearThinkingTimeout(),this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive(),this.thinkingTimeout=setTimeout(()=>{this.isThinkingSubject.next(!1),this.thinkingTimeout=null,this.tabTitleService?.setSystemInactive()},Nn.debounce+1e3))}handleToolRequestEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:t.toSingleLineString()}],timestamp:t.date,type:"technical",eventId:t.timestamp};this.addMessage(e)}handleToolResponseEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:t.toSingleLineString()}],timestamp:t.date,type:"technical",eventId:t.timestamp};this.addMessage(e)}handleChoiceEvent(t){this.stopThinking(),this.currentChoiceEvent=t,this.tabTitleService?.setSystemInactive();let e=t.options.map(n=>({value:n,label:n})),i=t.optionalQuestion?`${t.optionalQuestion} ${t.invite}`:t.invite;this.currentChoiceSubject.next({options:e,label:i,allowFreeText:t.allowFreeText})}handleHeartBeatEvent(t){}handleInviteEvent(t){this.stopThinking();let e=this.messagesSubject.value,i=e[e.length-1];if(!(!(t.invite===ad)&&i&&i.role==="assistant"&&i.content.some(a=>a.type==="text"&&a.content.includes(t.invite)))&&t.invite!==ad){let a={id:t.timestamp,role:"assistant",speaker:"Assistant",content:[{type:"text",content:t.invite}],timestamp:t.date,type:"text"};this.addMessage(a)}this.currentInviteEventSubject.next(t),this.tabTitleService?.setSystemInactive()}addMessage(t){let i=[...this.messagesSubject.value,t];this.messagesSubject.next(i)}removeMessagesFromIndex(t){let e=this.messagesSubject.value,i=e.findIndex(r=>r.id===t);if(i===-1||i===0)return;let n=e.slice(0,i);this.messagesSubject.next(n),this.stopThinking()}extractTextContentFromMessage(t){return t?t.content.filter(e=>e.type==="text").map(e=>e.content).join(`
|
|
336
|
+
This ensures the memory system stays efficient and valuable.`],createdBy:"system",createdAt:new Date("2024-01-01").toISOString(),webhookEnabled:!1,parameterFormat:""}];var GM=[Mi.type,ki.type,li.type,so.type,un.type,gn.type,zt.type,Ui.type];var $h={CONFLUENCE:[],GIT:[],GIT_WORKTREE:[],GITLAB:[],JIRA:[],SLACK:[],ZENDESK:[],BASECAMP:[]},mT=Object.keys($h).filter(o=>$h[o]?.length===0);var Gi=class o{eventSource=null;eventsSubject=new D;connectionStatusSubject=new le({connected:!1,reconnectAttempts:0,maxAttempts:3});reconnectAttempts=0;MAX_RECONNECT_ATTEMPTS=3;RECONNECT_DELAY=2e3;events$=this.eventsSubject.asObservable();connectionStatus$=this.connectionStatusSubject.asObservable();ngZone=m(de);connectToThread(t,e){console.log("[SSE] Connecting to thread event stream:",t,e),this.eventSource&&(console.log("[SSE] Closing existing EventSource"),this.eventSource.close());let i=`/api/projects/${t}/threads/${e}/event-stream`;console.log("[SSE] EventSource URL:",i),this.eventSource=new EventSource(i),this.setupEventHandlers()}setupEventHandlers(){this.eventSource&&(this.eventSource.onmessage=t=>{this.ngZone.run(()=>{console.log("[SSE] Message received:",t.data.substring(0,100)),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0);try{let e=JSON.parse(t.data),i=oa(e);i?(console.log("[SSE] Event:",i.type),this.eventsSubject.next(i)):console.warn("[SSE] Failed to build event:",e.type)}catch(e){console.error("[SSE] Parse error:",e.message)}})},this.eventSource.onopen=()=>{this.ngZone.run(()=>{console.log("[SSE] Connection established"),this.reconnectAttempts=0,this.updateConnectionStatus(!0,0)})},this.eventSource.onerror=t=>{this.ngZone.run(()=>{console.log("[SSE] EventSource error:",t),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 Si({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 Si({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(t,e){this.connectionStatusSubject.next({connected:t,reconnectAttempts:e,maxAttempts:this.MAX_RECONNECT_ATTEMPTS})}ngOnDestroy(){this.disconnect(),this.eventsSubject.complete(),this.connectionStatusSubject.complete()}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Yi=class o{http=m(Je);projectState=m(Te);getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/threads`}listThreads(){return this.http.get(this.getBaseUrl())}getThread(t){return this.http.get(`${this.getBaseUrl()}/${t}`)}createThread(t){let e=t?{name:t}:{};return this.http.post(this.getBaseUrl(),e)}updateThread(t,e){return this.http.put(`${this.getBaseUrl()}/${t}`,{name:e})}starThread(t){return this.http.post(`${this.getBaseUrl()}/${t}/star`,{})}unstarThread(t){return this.http.delete(`${this.getBaseUrl()}/${t}/star`)}deleteThread(t){return this.http.delete(`${this.getBaseUrl()}/${t}`)}stopThread(t){return this.http.post(`${this.getBaseUrl()}/${t}/stop`,{})}getThreadMessages(t){return this.http.get(`${this.getBaseUrl()}/${t}/messages`)}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Tt=class o{selectedThreadIdSubject=new le(null);isLoadingSubject=new le(!1);isLoadingThreadListSubject=new le(!1);refreshThreadListSubject=new D;threadListSubject=new le([]);hasLoadedOncePerProject=new Map;currentProjectName=null;isLoading$=this.isLoadingSubject.asObservable();isLoadingThreadList$=this.isLoadingThreadListSubject.asObservable();threadApi=m(Yi);projectStateService=m(Te);projectName$=this.projectStateService.selectedProject$.pipe(Oe(t=>t?.name),Sa());constructor(){Wn([this.projectName$,this.refreshThreadListSubject.asObservable().pipe(At(void 0))]).pipe(ht(([t])=>{t!==this.currentProjectName&&(console.log("[THREAD_STATE] Project changed, clearing thread list"),this.threadListSubject.next([]),this.currentProjectName=t),t?this.hasLoadedOncePerProject.get(t)?console.log("[THREAD_STATE] Refreshing thread list for project",t,"(no spinner)"):(console.log("[THREAD_STATE] Initial load for project",t,"- showing spinner"),this.isLoadingThreadListSubject.next(!0)):(console.log("[THREAD_STATE] No project selected, hiding spinner"),this.isLoadingThreadListSubject.next(!1))}),Un(([t])=>t?(console.log("[THREAD_STATE] Fetching threads for project:",t),this.threadApi.listThreads().pipe(Oe(e=>({threads:e,projectName:t})),$n(e=>(console.error("[THREAD_STATE] Error loading thread list:",e),Ot({threads:[],projectName:t}))))):(console.log("[THREAD_STATE] No project selected, returning empty list"),Ot({threads:[],projectName:null}))),ht(({threads:t,projectName:e})=>{console.log("[THREAD_STATE] Thread list loaded:",t.length,"threads for project",e),e&&this.hasLoadedOncePerProject.set(e,!0),this.isLoadingThreadListSubject.next(!1),this.threadListSubject.next(t)})).subscribe()}threadList$=this.threadListSubject.asObservable();selectedThread$=Wn([this.projectName$,this.selectedThreadIdSubject.pipe(Sa())]).pipe(ht(([t,e])=>{console.log("\u{1F43C} combineLatest emitted:",{projectName:t,threadId:e})}),Un(([t,e])=>!t||!e?(console.log("\u{1F43C} null"),Ot(null)):(console.log("\u{1F43C} loading thread:",e),this.isLoadingSubject.next(!0),this.threadApi.getThread(e).pipe(ht(i=>{console.log("\u{1F43C} loaded thread:",i?.id)}),Sr({bufferSize:1,refCount:!0})))),ht(()=>{console.log("\u{1F43C} finished loading"),this.isLoadingSubject.next(!1)}));selectThread(t){this.selectedThreadIdSubject.next(t)}getSelectedThreadId(){return this.selectedThreadIdSubject.value}getSelectedThreadIdOrThrow(){let t=this.selectedThreadIdSubject.value;if(!t)throw new Error("[THREAD_STATE] No thread selected");return t}clearSelection(){this.selectedThreadIdSubject.next(null)}stop(){let t=this.selectedThreadIdSubject.value;if(!t){console.error("[THREAD_STATE] Cannot stop: no thread selected");return}console.log("[THREAD_STATE] Stopping thread:",t),this.threadApi.stopThread(t).subscribe({next:e=>console.log("[THREAD_STATE] Stop signal sent:",e.message),error:e=>console.error("[THREAD_STATE] Error stopping thread:",e)})}refreshThreadList(){console.log("[THREAD_STATE] Manually refreshing thread list"),this.refreshThreadListSubject.next()}renameThread(t,e){let i=e.trim();return!i||i.length===0?(console.error("[THREAD_STATE] Cannot rename thread: name is empty after trimming"),wr(()=>new Error("Thread name cannot be empty"))):(console.log("[THREAD_STATE] Renaming thread:",t,"to:",i),this.threadApi.updateThread(t,i).pipe(ht(n=>{console.log("[THREAD_STATE] Thread renamed successfully:",n),this.refreshThreadList()}),$n(n=>(console.error("[THREAD_STATE] Error renaming thread:",n),wr(()=>n)))))}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Xo=class o{http=m(Je);projectState=m(Te);threadState=m(Tt);getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/threads/${this.threadState.getSelectedThreadIdOrThrow()}/messages`}getMessages(){return this.http.get(this.getBaseUrl())}sendMessage(t){return this.http.post(this.getBaseUrl(),t,{responseType:"text"})}getMessage(t){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(t)}`)}deleteMessage(t){return this.http.delete(`${this.getBaseUrl()}/${encodeURIComponent(t)}`)}getFormattedMessage(t){return this.http.get(`${this.getBaseUrl()}/${encodeURIComponent(t)}/formatted`,{responseType:"text"})}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Yt=class o{destroy$=new D;currentProject=null;currentThread=null;messagesSubject=new le([]);isThinkingSubject=new le(!1);currentChoiceSubject=new le(null);projectTitleSubject=new le("Coday");currentInviteEventSubject=new le(null);messageToRestoreSubject=new le("");threadUpdateEventSubject=new le(null);currentChoiceEvent=null;thinkingTimeout=null;accumulatedChunks="";streamingTextSubject=new le("");subThreadEventsSubject=new D;subThreadEvents$=this.subThreadEventsSubject.asObservable();subThreadEventBuffers=new Map;getBufferedSubThreadEvents(t){return this.subThreadEventBuffers.get(t)??[]}messages$=this.messagesSubject.asObservable();streamingText$=this.streamingTextSubject.asObservable();isThinking$=this.isThinkingSubject.asObservable();currentChoice$=this.currentChoiceSubject.asObservable();currentInviteEvent$=this.currentInviteEventSubject.asObservable();messageToRestore$=this.messageToRestoreSubject.asObservable();threadUpdateEvent$=this.threadUpdateEventSubject.asObservable();connectionStatus$;tabTitleService=null;eventStream=m(Gi);messageApi=m(Xo);constructor(){this.connectionStatus$=this.eventStream.connectionStatus$,this.initializeEventHandling()}setTabTitleService(t){this.tabTitleService=t}connectToThread(t,e){this.currentProject=t,this.currentThread=e,this.eventStream.connectToThread(t,e),setTimeout(()=>this.processUnansweredInvites(),500)}processUnansweredInvites(){let t=this.messagesSubject.value,e=t.filter(i=>i.type==="text"&&i.parentKey===void 0&&i.invite!==void 0).filter(i=>!t.some(n=>n.type==="text"&&n.role==="user"&&n.parentKey===i.id));e.length>0&&console.log("[CODAY] Found",e.length,"unanswered invite(s)")}resetMessages(){this.messagesSubject.next([]),this.currentChoiceSubject.next(null),this.currentInviteEventSubject.next(null),this.currentChoiceEvent=null,this.accumulatedChunks="",this.streamingTextSubject.next(""),this.subThreadEventBuffers.clear(),this.stopThinking()}sendMessage(t){if(!this.currentProject||!this.currentThread){console.error("[CODAY] Cannot send message: no project or thread selected");return}this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive();let e=this.currentInviteEventSubject.value;if(e){let i=e.buildAnswer(t);this.currentInviteEventSubject.next(null),this.messageApi.sendMessage(i).subscribe({error:n=>{console.error("[CODAY] Send error:",n),this.stopThinking()}})}else{let i=new zt({answer:t});this.messageApi.sendMessage(i).subscribe({error:n=>{console.error("[CODAY] Send error:",n),this.stopThinking()}})}}sendChoice(t){if(!this.currentProject||!this.currentThread){console.error("[CODAY] Cannot send choice: no project or thread selected");return}if(this.currentChoiceEvent){this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive();let e=this.currentChoiceEvent.buildAnswer(t);this.currentChoiceSubject.next(null),this.currentChoiceEvent=null,this.messageApi.sendMessage(e).subscribe({next:()=>{},error:i=>{console.error("[CODAY-CHOICE] Choice error:",i),this.stopThinking()}})}else console.error("[CODAY-CHOICE] No choice event available for choice:",t)}deleteMessage(t){let e=this.messagesSubject.value.find(n=>n.id===t),i=this.extractTextContentFromMessage(e);return this.messageApi.deleteMessage(t).pipe(ht(n=>{n.success&&(this.removeMessagesFromIndex(t),i.trim()&&this.messageToRestoreSubject.next(i))}))}getCurrentProjectTitle(){return this.projectTitleSubject.value}getCurrentInviteEvent(){return this.currentInviteEventSubject.value}setThinkingForPendingMessage(){this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive()}initializeEventHandling(){this.eventStream.events$.pipe(N(this.destroy$)).subscribe({next:t=>this.handleEvent(t),error:t=>console.error("[CODAY] Event stream error:",t),complete:()=>console.log("[CODAY] Event stream completed")})}handleEvent(t){if(t.threadId&&t.threadId!==this.currentThread){let e=this.subThreadEventBuffers.get(t.threadId);e?e.push(t):this.subThreadEventBuffers.set(t.threadId,[t]),this.subThreadEventsSubject.next(t);return}t instanceof Mi?this.handleMessageEvent(t):t instanceof Fn?this.handleTextChunkEvent(t):t instanceof $i?this.handleTextEvent(t):t instanceof zt?this.handleAnswerEvent(t):t instanceof Si?this.handleErrorEvent(t):t instanceof ao?this.handleWarnEvent(t):t instanceof Nn?this.handleThinkingEvent(t):t instanceof ki?this.handleToolRequestEvent(t):t instanceof li?this.handleToolResponseEvent(t):t instanceof gn?this.handleChoiceEvent(t):t instanceof Go?this.handleHeartBeatEvent(t):t instanceof un?this.handleInviteEvent(t):t instanceof Yo?this.handleThreadUpdateEvent(t):t instanceof Ui?this.handleDelegationEvent(t):t instanceof Qo||t instanceof qi||console.warn("[CODAY] Unhandled event type:",t.type)}handleDelegationEvent(t){if(console.log("[CODAY] DelegationEvent received:",t.subThreadId,t.agentName),this.messagesSubject.value.findIndex(n=>n.subThreadId===t.subThreadId)===-1){let n={id:t.timestamp,role:"system",speaker:t.agentName,content:[{type:"text",content:""}],timestamp:new Date,type:"delegation",subThreadId:t.subThreadId,delegationAgentName:t.agentName};this.addMessage(n)}}handleThreadUpdateEvent(t){this.threadUpdateEventSubject.next(t)}handleMessageEvent(t){t.role==="assistant"&&this.accumulatedChunks&&(this.accumulatedChunks="",this.streamingTextSubject.next(""));let e={id:t.timestamp,role:t.role,speaker:t.name,content:t.content,timestamp:t.date,type:"text"};this.addMessage(e)}handleTextChunkEvent(t){this.accumulatedChunks+=t.chunk,this.streamingTextSubject.next(this.accumulatedChunks)}handleTextEvent(t){let e={id:t.timestamp,role:t.speaker?"assistant":"system",speaker:t.speaker??"System",content:[{type:"text",content:t.text}],timestamp:t.date,type:t.speaker?"text":"technical"};this.addMessage(e)}handleAnswerEvent(t){let e={id:t.timestamp,role:"user",speaker:"User",content:[{type:"text",content:t.answer}],timestamp:t.date,type:"text",parentKey:t.parentKey,invite:t.invite};this.addMessage(e)}handleErrorEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:`Error: ${JSON.stringify(t.error)}`}],timestamp:t.date,type:"error"};this.addMessage(e)}handleWarnEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:`Warning: ${JSON.stringify(t.warning)}`}],timestamp:t.date,type:"warning"};this.addMessage(e)}handleThinkingEvent(t){this.currentInviteEventSubject.value||this.currentChoiceEvent||(this.clearThinkingTimeout(),this.isThinkingSubject.next(!0),this.tabTitleService?.setSystemActive(),this.thinkingTimeout=setTimeout(()=>{this.isThinkingSubject.next(!1),this.thinkingTimeout=null,this.tabTitleService?.setSystemInactive()},Nn.debounce+1e3))}handleToolRequestEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:t.toSingleLineString()}],timestamp:t.date,type:"technical",eventId:t.timestamp};this.addMessage(e)}handleToolResponseEvent(t){let e={id:t.timestamp,role:"system",speaker:"System",content:[{type:"text",content:t.toSingleLineString()}],timestamp:t.date,type:"technical",eventId:t.timestamp};this.addMessage(e)}handleChoiceEvent(t){this.stopThinking(),this.currentChoiceEvent=t,this.tabTitleService?.setSystemInactive();let e=t.options.map(n=>({value:n,label:n})),i=t.optionalQuestion?`${t.optionalQuestion} ${t.invite}`:t.invite;this.currentChoiceSubject.next({options:e,label:i,allowFreeText:t.allowFreeText})}handleHeartBeatEvent(t){}handleInviteEvent(t){this.stopThinking();let e=this.messagesSubject.value,i=e[e.length-1];if(!(!(t.invite===ad)&&i&&i.role==="assistant"&&i.content.some(a=>a.type==="text"&&a.content.includes(t.invite)))&&t.invite!==ad){let a={id:t.timestamp,role:"assistant",speaker:"Assistant",content:[{type:"text",content:t.invite}],timestamp:t.date,type:"text"};this.addMessage(a)}this.currentInviteEventSubject.next(t),this.tabTitleService?.setSystemInactive()}addMessage(t){let i=[...this.messagesSubject.value,t];this.messagesSubject.next(i)}removeMessagesFromIndex(t){let e=this.messagesSubject.value,i=e.findIndex(r=>r.id===t);if(i===-1||i===0)return;let n=e.slice(0,i);this.messagesSubject.next(n),this.stopThinking()}extractTextContentFromMessage(t){return t?t.content.filter(e=>e.type==="text").map(e=>e.content).join(`
|
|
337
337
|
|
|
338
338
|
`):""}clearThinkingTimeout(){this.thinkingTimeout&&(clearTimeout(this.thinkingTimeout),this.thinkingTimeout=null)}stopThinking(){this.clearThinkingTimeout(),this.isThinkingSubject.next(!1),this.tabTitleService&&this.tabTitleService.setSystemInactive()}ngOnDestroy(){this.clearThinkingTimeout(),this.destroy$.next(),this.destroy$.complete(),this.currentInviteEventSubject.complete(),this.messageToRestoreSubject.complete(),this.threadUpdateEventSubject.complete(),this.streamingTextSubject.complete(),this.eventStream.disconnect()}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var Ko=class o{http=m(Je);agentsCache=new Map;getAgents(t){let e=this.agentsCache.get(t);return e?Ot(e):this.http.get(`/api/projects/${t}/agents`).pipe(ht(i=>{this.agentsCache.set(t,i)}))}getAgentsAutocomplete(t,e){return this.getAgents(t).pipe(Oe(i=>{if(!e)return i;let n=e.toLowerCase();return i.filter(r=>{let a=r.name.toLowerCase(),c=r.description?.toLowerCase()||"";return a.includes(n)||c.includes(n)})}))}clearCache(t){this.agentsCache.delete(t)}clearAllCache(){this.agentsCache.clear()}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var ci=class o{http=m(Je);projectState=m(Te);promptsCache=new Map;getBaseUrl(){return`/api/projects/${this.projectState.getSelectedProjectIdOrThrow()}/prompts`}listPrompts(){return this.http.get(this.getBaseUrl())}getPromptsAutocomplete(t,e){let i=this.promptsCache.get(t);return i?Ot(this.filterPromptsForAutocomplete(i,e)):this.http.get(`/api/projects/${t}/prompts`).pipe(Oe(n=>(this.promptsCache.set(t,n),this.filterPromptsForAutocomplete(n,e))))}filterPromptsForAutocomplete(t,e){let i=e.toLowerCase();return t.filter(r=>r.name.toLowerCase().includes(i)||r.description.toLowerCase().includes(i)).map(r=>({name:r.name,description:r.description,parameterFormat:r.parameterFormat}))}clearCache(t){t?this.promptsCache.delete(t):this.promptsCache.clear()}getPrompt(t){return this.http.get(`${this.getBaseUrl()}/${t}`)}createPrompt(t){return this.http.post(this.getBaseUrl(),t).pipe(Oe(e=>(this.clearCache(this.projectState.getSelectedProjectId()??void 0),e)))}updatePrompt(t,e){return this.http.put(`${this.getBaseUrl()}/${t}`,e).pipe(Oe(i=>(this.clearCache(this.projectState.getSelectedProjectId()??void 0),i)))}deletePrompt(t){return this.http.delete(`${this.getBaseUrl()}/${t}`).pipe(Oe(e=>(this.clearCache(this.projectState.getSelectedProjectId()??void 0),e)))}enableWebhook(t){return this.http.post(`${this.getBaseUrl()}/${t}/webhook`,{})}disableWebhook(t){return this.http.delete(`${this.getBaseUrl()}/${t}/webhook`)}static \u0275fac=function(e){return new(e||o)};static \u0275prov=L({token:o,factory:o.\u0275fac,providedIn:"root"})};var $s=class o{sanitizer=m(Di);transform(t,e){if(!e||!t)return t;let i=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=new RegExp(`(${i})`,"gi"),r=t.replace(n,"<strong>$1</strong>");return this.sanitizer.bypassSecurityTrustHtml(r)}static \u0275fac=function(e){return new(e||o)};static \u0275pipe=dm({name:"highlight",type:o,pure:!0})};var Sb=["messageInput"],kb=["fileInput"],Mb=(o,t)=>t.name;function Tb(o,t){o&1&&(s(0,"div",3),A(1,"span",7),p(2," Recording... Click mic to stop "),l())}function Eb(o,t){if(o&1&&(s(0,"span",12),p(1),l()),o&2){let e=g().$implicit,i=g(2);d(),B(" "+(i.getParameterFormat(e)||""))}}function Pb(o,t){if(o&1){let e=T();s(0,"div",9),_("click",function(){let n=v(e).$index,r=g(2);return y(r.selectAutocompleteItemByClick(n))})("keydown.enter",function(){let n=v(e).$index,r=g(2);return y(r.selectAutocompleteItemByClick(n))})("keydown.space",function(){let n=v(e).$index,r=g(2);return y(r.selectAutocompleteItemByClick(n))})("mouseenter",function(){let n=v(e).$index,r=g(2);return y(r.selectedAutocompleteIndex=n)}),s(1,"div",10),A(2,"span",11),Xn(3,"highlight"),w(4,Eb,2,1,"span",12),l(),A(5,"div",13),Xn(6,"highlight"),l()}if(o&2){let e=t.$implicit,i=t.$index,n=g(2);I("selected",i===n.selectedAutocompleteIndex),Q("aria-selected",i===n.selectedAutocompleteIndex),d(2),C("innerHTML",Tr(3,6,n.autocompleteTrigger+e.name,n.getAutocompleteQuery()),Xt),d(2),S(n.hasParameterFormat(e)?4:-1),d(),C("innerHTML",Tr(6,9,e.description,n.getAutocompleteQuery()),Xt)}}function Ob(o,t){if(o&1&&(s(0,"div",4),Se(1,Pb,7,12,"div",8,Mb),l()),o&2){let e=g();d(),ke(e.autocompleteItems)}}function Ab(o,t){if(o&1){let e=T();s(0,"ds-icon-button",15),_("action",function(){v(e);let n=g(2);return y(n.onStopClick())}),l()}}function Ib(o,t){if(o&1){let e=T();s(0,"ds-icon-button",18),_("action",function(){v(e);let n=g(3);return y(n.triggerFileUpload())}),l(),s(1,"input",19,1),_("change",function(n){v(e);let r=g(3);return y(r.onFileInputChange(n))}),l()}if(o&2){let e=g(3);C("disabled",e.isDisabled||e.isLocallyDisabled)}}function Db(o,t){if(o&1){let e=T();s(0,"ds-icon-button",16),_("action",function(){v(e);let n=g(2);return y(n.sendMessage())}),l(),w(1,Ib,3,1),s(2,"ds-icon-button",17),_("action",function(){v(e);let n=g(2);return y(n.toggleRecording())}),l()}if(o&2){let e=g(2);I("hidden",e.isDisabled||!e.message.trim()||e.isLocallyDisabled)("active",!!e.message.trim()&&!e.isDisabled&&!e.isLocallyDisabled),C("title",e.getSendButtonTooltip())("disabled",e.isDisabled||!e.message.trim()||e.isLocallyDisabled),d(),S(e.showWelcome?-1:1),d(),I("recording",e.isRecording)("hidden",e.message.trim()),C("icon",e.isRecording?"fiber_manual_record":"mic")("title",e.isRecording?"Click to stop recording":"Click to start recording")}}function Rb(o,t){if(o&1&&w(0,Ab,1,0,"ds-icon-button",14)(1,Db,3,13),o&2){let e=g();S(e.isThinking?0:1)}}var Zo=class o{static MIN_TEXTAREA_LINES=2;static MAX_TEXTAREA_LINES=15;isDisabled=!1;showWelcome=!1;isThinking=!1;isStarting=!1;isSessionInitializing=!1;isStopping=!1;isLocallyDisabled=!1;filesPasted=new q;messageSubmitted=new q;voiceRecordingToggled=new q;heightChanged=new q;stopRequested=new q;messageInput;fileInput;message="";isRecording=!1;isFocused=!1;recognition=null;sessionHadTranscript=!1;pendingLineBreaksTimeout=null;useEnterToSend=!1;currentInvite="";subscriptions=[];thinkingPhrases=["Processing request...","Thinking...","Working on it..."];currentThinkingPhrase="Processing request...";thinkingPhraseIndex=0;thinkingInterval=null;autocompleteVisible=!1;autocompleteTrigger=null;autocompleteItems=[];selectedAutocompleteIndex=0;preferencesService=m(et);codayService=m(Yt);agentApiService=m(Ko);promptApiService=m(ci);projectStateService=m(Te);ngOnInit(){this.initializeVoiceInput(),this.useEnterToSend=this.preferencesService.getEnterToSend(),this.subscriptions.push(this.preferencesService.voiceLanguage$.subscribe(()=>this.updateRecognitionLanguage())),this.subscriptions.push(this.preferencesService.enterToSend$.subscribe(t=>{this.useEnterToSend=t})),this.subscribeToInviteEvents(),this.subscribeToMessageRestore()}ngAfterViewInit(){this.adjustTextareaHeight(),requestAnimationFrame(()=>{setTimeout(()=>this.focusTextarea(),200)})}ngOnChanges(t){t.isThinking&&(t.isThinking.currentValue?this.startThinkingAnimation():(this.stopThinkingAnimation(),this.isStopping=!1,this.isLocallyDisabled=!1,t.isThinking.previousValue&&(console.log("[CHAT-TEXTAREA] Thinking ended, scheduling focus"),requestAnimationFrame(()=>{setTimeout(()=>this.focusTextarea(),100)})))),t.isSessionInitializing&&!t.isSessionInitializing.currentValue&&t.isSessionInitializing.previousValue&&(console.log("[CHAT-TEXTAREA] Session initialization completed, scheduling focus"),this.isLocallyDisabled=!1,requestAnimationFrame(()=>{setTimeout(()=>this.focusTextarea(),100)})),t.isStarting&&!t.isStarting.currentValue&&t.isStarting.previousValue&&this.isThinking&&(this.thinkingPhraseIndex===0?(console.log("[CHAT-TEXTAREA] Transitioning from Starting to Thinking at index 0 - restarting animation"),this.stopThinkingAnimation(),this.startThinkingAnimation()):console.log("[CHAT-TEXTAREA] Transitioning from Starting to Thinking at index",this.thinkingPhraseIndex,"- continuing without restart"))}ngOnDestroy(){this.subscriptions.forEach(t=>t.unsubscribe()),this.subscriptions=[],this.clearPendingLineBreaks(),this.stopThinkingAnimation()}onKeyDown(t){if(this.autocompleteVisible)switch(t.key){case"ArrowDown":t.preventDefault(),this.selectedAutocompleteIndex=Math.min(this.selectedAutocompleteIndex+1,this.autocompleteItems.length-1),this.scrollSelectedItemIntoView();return;case"ArrowUp":t.preventDefault(),this.selectedAutocompleteIndex=Math.max(this.selectedAutocompleteIndex-1,0),this.scrollSelectedItemIntoView();return;case"Tab":case"Enter":if(!this.message.includes(" ")){t.preventDefault(),this.selectAutocompleteItem();return}break;case"Escape":t.preventDefault(),this.hideAutocomplete();return}t.key==="Enter"&&(this.useEnterToSend?!t.shiftKey&&!t.metaKey&&!t.ctrlKey&&(t.preventDefault(),this.sendMessage(!0)):(navigator.platform.toLowerCase().includes("mac")?t.metaKey:t.ctrlKey)&&!t.shiftKey&&(t.preventDefault(),this.sendMessage(!0)))}onInput(){this.adjustTextareaHeight(),this.checkForAutocomplete()}onPaste(t){let e=t.clipboardData?.items;if(!e)return;let i=Array.from(e).filter(r=>r.kind==="file");if(!i.length)return;t.preventDefault();let n=i.reduce((r,a)=>{let c=a.getAsFile();return c?[...r,c]:r},[]);n.length&&this.filesPasted.emit(n)}triggerFileUpload(){console.log("[CHAT-TEXTAREA] Triggering file upload"),this.fileInput?.nativeElement?.click()}onFileInputChange(t){let e=t.target,i=e.files;if(!i||i.length===0){console.log("[CHAT-TEXTAREA] No files selected");return}console.log("[CHAT-TEXTAREA] Files selected:",i.length);let n=Array.from(i);this.filesPasted.emit(n),e.value=""}onDocumentClick(t){if(!this.autocompleteVisible)return;let e=t.target,i=document.querySelector(".autocomplete-popup"),n=this.messageInput?.nativeElement;i&&!i.contains(e)&&n&&!n.contains(e)&&this.hideAutocomplete()}sendMessage(t=!1){let e=this.message.trim();!this.isDisabled&&!this.isLocallyDisabled&&(t||e)&&(this.isLocallyDisabled=!0,this.messageSubmitted.emit(e),this.message="",setTimeout(()=>this.adjustTextareaHeight(),0))}onStopClick(){this.isStopping=!0,this.stopRequested.emit()}toggleRecording(){this.isRecording?this.stopRecording():this.startRecording()}initializeVoiceInput(){let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(console.log("[SPEECH] speechRecognition",t),!t){console.warn("[SPEECH] Speech Recognition API not available");return}this.recognition=new t,this.recognition.continuous=!0,this.recognition.interimResults=!0,this.recognition.maxAlternatives=1,this.recognition.lang=this.getSelectedLanguage();try{"grammars"in this.recognition&&(this.recognition.serviceURI=void 0)}catch{console.log("[SPEECH] Advanced speech recognition parameters not supported")}this.recognition.onresult=e=>{let i="";for(let n=e.resultIndex;n<e.results.length;n++){let r=e.results[n][0].transcript;e.results[n].isFinal&&(i+=r)}if(i){let n=this.improveTranscriptPunctuation(i.trim());this.sessionHadTranscript=!0,console.log("[SPEECH] onresult ending, appending to textarea",this.isRecording),this.appendToTextarea(n)}},this.recognition.onend=()=>{console.log("[SPEECH] Recognition ended. Was recording:",this.isRecording),this.isRecording=!1,this.voiceRecordingToggled.emit(this.isRecording)},this.recognition.onerror=e=>{console.error("[SPEECH] Speech recognition error:",e.error),console.log("[SPEECH] Error details:",{error:e.error,message:e.message,timeStamp:e.timeStamp}),this.isRecording=!1,this.clearPendingLineBreaks(),this.voiceRecordingToggled.emit(this.isRecording)},this.recognition.onstart=()=>{console.log("[SPEECH] Recognition started successfully")},this.recognition.onspeechstart=()=>{console.log("[SPEECH] Speech detected")},this.recognition.onspeechend=()=>{console.log("[SPEECH] Speech ended")}}startRecording(){return ee(this,null,function*(){if(!(!this.recognition||this.isRecording))try{this.isRecording=!0,this.sessionHadTranscript=!1,this.clearPendingLineBreaks(),this.voiceRecordingToggled.emit(this.isRecording),this.recognition.start(),console.log("[SPEECH] Started recording")}catch(t){console.error("[SPEECH] Failed to start recording:",t),this.isRecording=!1,this.voiceRecordingToggled.emit(this.isRecording)}})}stopRecording(){if(!this.recognition||!this.isRecording){console.log("[SPEECH] stopRecording not recording");return}try{console.log("[SPEECH] stopRecording recognition stop"),this.recognition.stop(),this.schedulePendingLineBreaks()}catch(t){console.error("[SPEECH] Failed to stop recording:",t)}}getSelectedLanguage(){return this.preferencesService.getVoiceLanguage()}updateRecognitionLanguage(){if(this.recognition){let t=this.getSelectedLanguage();this.recognition.lang=t,console.log("[SPEECH] Language changed to:",t)}}improveTranscriptPunctuation(t){let e=t;return/[.!?]$/.test(e.trim())||(e=e.trim()+"."),e=e.charAt(0).toUpperCase()+e.slice(1),e=e.replace(/\s+/g," "),e=e+" ",e}appendToTextarea(t){let e=this.message;if(this.message=e?`${e}${t}`:t,this.messageInput?.nativeElement){this.messageInput.nativeElement.focus();let i=this.message.length;this.messageInput.nativeElement.setSelectionRange(i,i)}setTimeout(()=>this.adjustTextareaHeight(),0)}schedulePendingLineBreaks(){this.clearPendingLineBreaks(),this.pendingLineBreaksTimeout=window.setTimeout(()=>{this.sessionHadTranscript&&(console.log("[SPEECH] Adding line breaks after transcript session"),this.appendToTextarea(`
|
|
339
339
|
|