@@ -99,10 +99,13 @@ async def chat(
9999 yield event
100100 logger .info (f"Chat with session { session_id } completed" )
101101
102- async def get_session (self , session_id : str , user_id : str ) -> Optional [Session ]:
102+ async def get_session (self , session_id : str , user_id : Optional [ str ] = None ) -> Optional [Session ]:
103103 """Get a session by ID, ensuring it belongs to the user"""
104104 logger .info (f"Getting session { session_id } for user { user_id } " )
105- session = await self ._session_repository .find_by_id_and_user_id (session_id , user_id )
105+ if not user_id :
106+ session = await self ._session_repository .find_by_id (session_id )
107+ else :
108+ session = await self ._session_repository .find_by_id_and_user_id (session_id , user_id )
106109 if not session :
107110 logger .error (f"Session { session_id } not found for user { user_id } " )
108111 return session
@@ -209,12 +212,60 @@ async def file_view(self, session_id: str, file_path: str, user_id: str) -> File
209212 return FileViewResponse (** result .data )
210213 else :
211214 raise RuntimeError (f"Failed to read file: { result .message } " )
215+
216+ async def is_session_shared (self , session_id : str ) -> bool :
217+ """Check if a session is shared"""
218+ logger .info (f"Checking if session { session_id } is shared" )
219+ session = await self ._session_repository .find_by_id (session_id )
220+ if not session :
221+ logger .error (f"Session { session_id } not found" )
222+ raise RuntimeError ("Session not found" )
223+ return session .is_shared
212224
213- async def get_session_files (self , session_id : str , user_id : str ) -> List [FileInfo ]:
225+ async def get_session_files (self , session_id : str , user_id : Optional [ str ] = None ) -> List [FileInfo ]:
214226 """Get files for a session, ensuring it belongs to the user"""
215227 logger .info (f"Getting files for session { session_id } for user { user_id } " )
228+ session = await self .get_session (session_id , user_id )
229+ return session .files
230+
231+ async def get_shared_session_files (self , session_id : str ) -> List [FileInfo ]:
232+ """Get files for a shared session"""
233+ logger .info (f"Getting files for shared session { session_id } " )
234+ session = await self ._session_repository .find_by_id (session_id )
235+ if not session or not session .is_shared :
236+ logger .error (f"Shared session { session_id } not found or not shared" )
237+ raise RuntimeError ("Session not found" )
238+ return session .files
239+
240+ async def share_session (self , session_id : str , user_id : str ) -> None :
241+ """Share a session, ensuring it belongs to the user"""
242+ logger .info (f"Sharing session { session_id } for user { user_id } " )
243+ # First verify the session belongs to the user
216244 session = await self ._session_repository .find_by_id_and_user_id (session_id , user_id )
217245 if not session :
218246 logger .error (f"Session { session_id } not found for user { user_id } " )
219247 raise RuntimeError ("Session not found" )
220- return session .files
248+
249+ await self ._session_repository .update_shared_status (session_id , True )
250+ logger .info (f"Session { session_id } shared successfully" )
251+
252+ async def unshare_session (self , session_id : str , user_id : str ) -> None :
253+ """Unshare a session, ensuring it belongs to the user"""
254+ logger .info (f"Unsharing session { session_id } for user { user_id } " )
255+ # First verify the session belongs to the user
256+ session = await self ._session_repository .find_by_id_and_user_id (session_id , user_id )
257+ if not session :
258+ logger .error (f"Session { session_id } not found for user { user_id } " )
259+ raise RuntimeError ("Session not found" )
260+
261+ await self ._session_repository .update_shared_status (session_id , False )
262+ logger .info (f"Session { session_id } unshared successfully" )
263+
264+ async def get_shared_session (self , session_id : str ) -> Optional [Session ]:
265+ """Get a shared session by ID (no user authentication required)"""
266+ logger .info (f"Getting shared session { session_id } " )
267+ session = await self ._session_repository .find_by_id (session_id )
268+ if not session or not session .is_shared :
269+ logger .error (f"Shared session { session_id } not found or not shared" )
270+ return None
271+ return session
0 commit comments