ciyidogan commited on
Commit
a87e993
·
verified ·
1 Parent(s): f61d734

Update state_orchestrator.py

Browse files
Files changed (1) hide show
  1. state_orchestrator.py +32 -0
state_orchestrator.py CHANGED
@@ -78,6 +78,10 @@ class StateOrchestrator:
78
 
79
  def _setup_event_handlers(self):
80
  """Subscribe to relevant events"""
 
 
 
 
81
  # Session lifecycle
82
  self.event_bus.subscribe(EventType.SESSION_STARTED, self._handle_session_started)
83
  self.event_bus.subscribe(EventType.SESSION_ENDED, self._handle_session_ended)
@@ -100,7 +104,35 @@ class StateOrchestrator:
100
 
101
  # Error events
102
  self.event_bus.subscribe(EventType.CRITICAL_ERROR, self._handle_critical_error)
 
 
 
 
 
 
 
 
 
 
 
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  async def _handle_session_started(self, event: Event):
105
  """Handle session start"""
106
  session_id = event.session_id
 
78
 
79
  def _setup_event_handlers(self):
80
  """Subscribe to relevant events"""
81
+
82
+ # Conversation events
83
+ event_bus.subscribe(EventType.CONVERSATION_STARTED, self._handle_conversation_started)
84
+
85
  # Session lifecycle
86
  self.event_bus.subscribe(EventType.SESSION_STARTED, self._handle_session_started)
87
  self.event_bus.subscribe(EventType.SESSION_ENDED, self._handle_session_ended)
 
104
 
105
  # Error events
106
  self.event_bus.subscribe(EventType.CRITICAL_ERROR, self._handle_critical_error)
107
+
108
+ async def _handle_conversation_started(self, event: Event) -> None:
109
+ """Handle conversation start within existing session"""
110
+ session_id = event.session_id
111
+ context = self.sessions.get(session_id)
112
+
113
+ if not context:
114
+ log_error(f"❌ Session not found for conversation start | session_id={session_id}")
115
+ return
116
+
117
+ log_info(f"🎤 Conversation started | session_id={session_id}")
118
 
119
+ # Welcome mesajını şimdi başlat
120
+ if context.project_config and context.project_config.get("welcome_enabled", True):
121
+ await self.transition_to(session_id, ConversationState.PREPARING_WELCOME)
122
+ await self._prepare_welcome_message(session_id)
123
+ else:
124
+ # Welcome yoksa direkt listening'e geç
125
+ await self.transition_to(session_id, ConversationState.LISTENING)
126
+
127
+ # Start STT
128
+ await self._event_bus.publish(
129
+ Event(
130
+ type=EventType.START_STT,
131
+ data={"session_id": session_id},
132
+ session_id=session_id
133
+ )
134
+ )
135
+
136
  async def _handle_session_started(self, event: Event):
137
  """Handle session start"""
138
  session_id = event.session_id