@@ -111,7 +111,14 @@ def _build_source(self, id_: str | None, display_name: str | None, source: str |
111111
112112 async def message_response (self ) -> Message :
113113 # First convert the input to string if needed
114- text = self .convert_to_string ()
114+ text_or_generator = self .convert_to_string ()
115+
116+ # ✅ Handle Generator case properly
117+ if isinstance (text_or_generator , Generator ):
118+ # For streaming responses, consume the generator
119+ text = "" .join (str (chunk ) for chunk in text_or_generator )
120+ else :
121+ text = text_or_generator
115122
116123 # Get source properties
117124 source , _ , display_name , source_id = self .get_properties_from_source_component ()
@@ -132,17 +139,26 @@ async def message_response(self) -> Message:
132139 message .sender_name = self .sender_name
133140 # Preserve session_id from incoming message, or use component/graph session_id
134141 message .session_id = (
135- self .session_id or existing_session_id or (self .graph .session_id if hasattr (self , "graph" ) else None ) or ""
142+ self .session_id or existing_session_id or
143+ (self .graph .session_id if hasattr (self , "graph" ) else None ) or ""
136144 )
137145 message .context_id = self .context_id
138146 message .flow_id = self .graph .flow_id if hasattr (self , "graph" ) else None
139147 message .properties .source = self ._build_source (source_id , display_name , source )
140148
141149 # Store message if needed
142150 if message .session_id and self .should_store_message :
143- stored_message = await self .send_message (message )
144- self .message .value = stored_message
145- message = stored_message
151+ try :
152+ stored_message = await self .send_message (message )
153+ # ✅ Check if self.message exists before accessing it
154+ if hasattr (self , "message" ) and self .message is not None :
155+ self .message .value = stored_message
156+ message = stored_message
157+ except Exception as e :
158+ # Log the error but don't fail the entire component
159+ if hasattr (self , "log" ):
160+ self .log (f"Failed to store message: { e } " )
161+ # Continue with the original message
146162
147163 self .status = message
148164 return message
0 commit comments