ciyidogan commited on
Commit
d750081
·
verified ·
1 Parent(s): 9f1dce5

Update flare-ui/src/app/components/chat/chat.component.ts

Browse files
flare-ui/src/app/components/chat/chat.component.ts CHANGED
@@ -16,7 +16,6 @@ import { Subscription } from 'rxjs';
16
 
17
  import { ApiService } from '../../services/api.service';
18
  import { EnvironmentService } from '../../services/environment.service';
19
- import { RealtimeChatComponent } from './realtime-chat.component';
20
  import { Router } from '@angular/router';
21
 
22
  interface ChatMessage {
@@ -42,8 +41,7 @@ interface ChatMessage {
42
  MatDividerModule,
43
  MatTooltipModule,
44
  MatProgressSpinnerModule,
45
- MatCheckboxModule,
46
- RealtimeChatComponent
47
  ],
48
  templateUrl: './chat.component.html',
49
  styleUrls: ['./chat.component.scss']
@@ -92,9 +90,6 @@ export class ChatComponent implements OnInit, OnDestroy, AfterViewChecked {
92
 
93
  // Initialize Audio Context
94
  this.audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
95
-
96
- // STT availability kontrolü
97
- this.checkSTTAvailability();
98
  }
99
 
100
  ngAfterViewChecked() {
@@ -166,32 +161,35 @@ export class ChatComponent implements OnInit, OnDestroy, AfterViewChecked {
166
  }
167
 
168
  private openRealtimeDialog(sessionId: string): void {
169
- const dialogRef = this.dialog.open(RealtimeChatComponent, {
170
- width: '90%',
171
- maxWidth: '900px',
172
- height: '85vh',
173
- maxHeight: '800px',
174
- disableClose: false,
175
- panelClass: 'realtime-chat-dialog',
176
- data: {
177
- sessionId: sessionId,
178
- projectName: this.selectedProject
179
- }
180
- });
181
-
182
- dialogRef.afterClosed().subscribe(result => {
183
- // Clean up session data
184
- localStorage.removeItem('current_session_id');
185
- localStorage.removeItem('current_project');
186
 
187
- // If session was active, we might want to end it
188
- if (result === 'session_active') {
189
- // Optionally end the session on backend
190
- this.api.endSession(sessionId).subscribe({
191
- next: () => console.log('Session ended'),
192
- error: (err) => console.error('Failed to end session:', err)
193
- });
194
- }
 
 
 
 
 
 
195
  });
196
  }
197
 
@@ -242,28 +240,6 @@ export class ChatComponent implements OnInit, OnDestroy, AfterViewChecked {
242
  }
243
  });
244
  }
245
-
246
- checkSTTAvailability(): void {
247
- const sub = this.environmentService.environment$.subscribe(env => {
248
- if (env) {
249
- this.sttAvailable = env.stt_engine !== 'no_stt';
250
- if (!this.sttAvailable) {
251
- this.useSTT = false;
252
- }
253
- }
254
- });
255
- this.subs.add(sub);
256
-
257
- // Also get current environment
258
- this.api.getEnvironment().subscribe({
259
- next: (env) => {
260
- this.sttAvailable = env.stt_engine !== 'no_stt';
261
- if (!this.sttAvailable) {
262
- this.useSTT = false;
263
- }
264
- }
265
- });
266
- }
267
 
268
  startChat(): void {
269
  if (!this.selectedProject) return;
@@ -478,29 +454,4 @@ export class ChatComponent implements OnInit, OnDestroy, AfterViewChecked {
478
  console.error('Scroll error:', err);
479
  }
480
  }
481
-
482
- startRealtimeChat(): void {
483
- if (!this.selectedProject) return;
484
-
485
- this.loading = true;
486
- this.error = '';
487
-
488
- const sub = this.api.startChat(this.selectedProject).subscribe({
489
- next: res => {
490
- // Store session ID for realtime component
491
- localStorage.setItem('current_session_id', res.session_id);
492
-
493
- // Navigate to realtime chat or open in dialog
494
- this.openRealtimeDialog(res.session_id);
495
-
496
- this.loading = false;
497
- },
498
- error: (err) => {
499
- this.error = err.error?.detail || 'Failed to start realtime session';
500
- this.loading = false;
501
- console.error('Start realtime chat error:', err);
502
- }
503
- });
504
- this.subs.add(sub);
505
- }
506
  }
 
16
 
17
  import { ApiService } from '../../services/api.service';
18
  import { EnvironmentService } from '../../services/environment.service';
 
19
  import { Router } from '@angular/router';
20
 
21
  interface ChatMessage {
 
41
  MatDividerModule,
42
  MatTooltipModule,
43
  MatProgressSpinnerModule,
44
+ MatCheckboxModule
 
45
  ],
46
  templateUrl: './chat.component.html',
47
  styleUrls: ['./chat.component.scss']
 
90
 
91
  // Initialize Audio Context
92
  this.audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
 
 
 
93
  }
94
 
95
  ngAfterViewChecked() {
 
161
  }
162
 
163
  private openRealtimeDialog(sessionId: string): void {
164
+ // Dinamik import kullan
165
+ import('./realtime-chat.component').then(module => {
166
+ const dialogRef = this.dialog.open(module.RealtimeChatComponent, {
167
+ width: '90%',
168
+ maxWidth: '900px',
169
+ height: '85vh',
170
+ maxHeight: '800px',
171
+ disableClose: false,
172
+ panelClass: 'realtime-chat-dialog',
173
+ data: {
174
+ sessionId: sessionId,
175
+ projectName: this.selectedProject
176
+ }
177
+ });
 
 
 
178
 
179
+ dialogRef.afterClosed().subscribe(result => {
180
+ // Clean up session data
181
+ localStorage.removeItem('current_session_id');
182
+ localStorage.removeItem('current_project');
183
+
184
+ // If session was active, we might want to end it
185
+ if (result === 'session_active') {
186
+ // Optionally end the session on backend
187
+ this.api.endSession(sessionId).subscribe({
188
+ next: () => console.log('Session ended'),
189
+ error: (err: any) => console.error('Failed to end session:', err)
190
+ });
191
+ }
192
+ });
193
  });
194
  }
195
 
 
240
  }
241
  });
242
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  startChat(): void {
245
  if (!this.selectedProject) return;
 
454
  console.error('Scroll error:', err);
455
  }
456
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  }