Spaces:
Building
Building
Update flare-ui/src/app/services/conversation-manager.service.ts
Browse files
flare-ui/src/app/services/conversation-manager.service.ts
CHANGED
@@ -242,7 +242,7 @@ export class ConversationManagerService implements OnDestroy {
|
|
242 |
try {
|
243 |
switch (message.type) {
|
244 |
case 'transcription':
|
245 |
-
// SADECE final transcription'ları işle
|
246 |
if (message['is_final']) {
|
247 |
const messages = this.messagesSubject.value;
|
248 |
const lastMessage = messages[messages.length - 1];
|
@@ -250,7 +250,6 @@ export class ConversationManagerService implements OnDestroy {
|
|
250 |
this.addMessage('user', message['text']);
|
251 |
}
|
252 |
}
|
253 |
-
// Interim transcription'ları artık işlemiyoruz
|
254 |
break;
|
255 |
|
256 |
case 'assistant_response':
|
@@ -312,14 +311,18 @@ export class ConversationManagerService implements OnDestroy {
|
|
312 |
break;
|
313 |
|
314 |
case 'state_change':
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
this.
|
320 |
}
|
321 |
break;
|
322 |
-
|
|
|
|
|
|
|
|
|
323 |
}
|
324 |
} catch (error) {
|
325 |
console.error('Error handling message:', error);
|
@@ -332,6 +335,23 @@ export class ConversationManagerService implements OnDestroy {
|
|
332 |
}
|
333 |
}
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
private handleStateChange(from: string, to: string): void {
|
336 |
console.log(`📊 State: ${from} → ${to}`);
|
337 |
|
|
|
242 |
try {
|
243 |
switch (message.type) {
|
244 |
case 'transcription':
|
245 |
+
// SADECE final transcription'ları işle. Interim transcription'ları işlemiyoruz
|
246 |
if (message['is_final']) {
|
247 |
const messages = this.messagesSubject.value;
|
248 |
const lastMessage = messages[messages.length - 1];
|
|
|
250 |
this.addMessage('user', message['text']);
|
251 |
}
|
252 |
}
|
|
|
253 |
break;
|
254 |
|
255 |
case 'assistant_response':
|
|
|
311 |
break;
|
312 |
|
313 |
case 'state_change':
|
314 |
+
// Backend'den gelen state'i frontend state'ine map et
|
315 |
+
const backendState = message['to'] || message['state'];
|
316 |
+
const mappedState = this.mapBackendStateToFrontend(backendState);
|
317 |
+
if (mappedState) {
|
318 |
+
this.currentStateSubject.next(mappedState);
|
319 |
}
|
320 |
break;
|
321 |
+
|
322 |
+
case 'conversation_started':
|
323 |
+
// Conversation başladığında log at
|
324 |
+
console.log('📢 Conversation started:', message);
|
325 |
+
break;
|
326 |
}
|
327 |
} catch (error) {
|
328 |
console.error('Error handling message:', error);
|
|
|
335 |
}
|
336 |
}
|
337 |
|
338 |
+
private mapBackendStateToFrontend(backendState: string): ConversationState | null {
|
339 |
+
const stateMap: { [key: string]: ConversationState } = {
|
340 |
+
'idle': 'idle',
|
341 |
+
'initializing': 'idle',
|
342 |
+
'preparing_welcome': 'processing_tts',
|
343 |
+
'playing_welcome': 'playing_audio',
|
344 |
+
'listening': 'listening',
|
345 |
+
'processing_speech': 'processing_stt',
|
346 |
+
'preparing_response': 'processing_llm',
|
347 |
+
'playing_response': 'playing_audio',
|
348 |
+
'error': 'error',
|
349 |
+
'ended': 'idle'
|
350 |
+
};
|
351 |
+
|
352 |
+
return stateMap[backendState] || null;
|
353 |
+
}
|
354 |
+
|
355 |
private handleStateChange(from: string, to: string): void {
|
356 |
console.log(`📊 State: ${from} → ${to}`);
|
357 |
|