77import time
88import traceback
99import json
10- from typing import Any , Dict
10+ from typing import Any , Dict , Tuple
1111from botocore .exceptions import ClientError
1212from slack_sdk import WebClient
1313from app .core .config import (
3434# ================================================================
3535
3636
37- def cleanup_previous_unfeedback_qa (conversation_key , current_message_ts , session_data ):
37+ def cleanup_previous_unfeedback_qa (conversation_key : str , current_message_ts : str , session_data : Dict [ str , Any ] ):
3838 """Delete previous Q&A pair if no feedback received using atomic operation"""
3939 try :
4040 previous_message_ts = session_data .get ("latest_message_ts" )
@@ -57,7 +57,9 @@ def cleanup_previous_unfeedback_qa(conversation_key, current_message_ts, session
5757 logger .error ("Error cleaning up unfeedback Q&A" , extra = {"error" : traceback .format_exc ()})
5858
5959
60- def store_qa_pair (conversation_key , user_query , bot_response , message_ts , session_id , user_id ):
60+ def store_qa_pair (
61+ conversation_key : str , user_query : str , bot_response : str , message_ts : str , session_id : str , user_id : str
62+ ):
6163 """
6264 Store Q&A pair for feedback correlation
6365 """
@@ -79,7 +81,7 @@ def store_qa_pair(conversation_key, user_query, bot_response, message_ts, sessio
7981 logger .error ("Failed to store Q&A pair" , extra = {"error" : traceback .format_exc ()})
8082
8183
82- def _mark_qa_feedback_received (conversation_key , message_ts ):
84+ def _mark_qa_feedback_received (conversation_key : str , message_ts : str ):
8385 """
8486 Mark Q&A record as having received feedback to prevent deletion
8587 """
@@ -98,7 +100,7 @@ def _mark_qa_feedback_received(conversation_key, message_ts):
98100# ================================================================
99101
100102
101- def _extract_conversation_context (event : Dict [str , Any ]):
103+ def _extract_conversation_context (event : Dict [str , Any ]) -> Tuple [ str , str , str | None ] :
102104 """Extract conversation key and thread context from event"""
103105 channel = event ["channel" ]
104106 # Determine conversation context: DM vs channel thread
@@ -110,7 +112,15 @@ def _extract_conversation_context(event: Dict[str, Any]):
110112
111113
112114def _handle_session_management (
113- conversation_key , session_data , session_id , kb_response , user_id , channel , thread_ts , context_type , message_ts
115+ conversation_key : str ,
116+ session_data : Dict [str , Any ],
117+ session_id : str ,
118+ kb_response : Dict [str , Any ],
119+ user_id : str ,
120+ channel : str ,
121+ thread_ts : str ,
122+ context_type : str ,
123+ message_ts : str ,
114124):
115125 """Handle Bedrock session creation and cleanup"""
116126 # Handle conversation session management
@@ -131,7 +141,9 @@ def _handle_session_management(
131141 update_session_latest_message (conversation_key , message_ts )
132142
133143
134- def _create_feedback_blocks (response_text , conversation_key , channel , message_ts , thread_ts ):
144+ def _create_feedback_blocks (
145+ response_text : str , conversation_key : str , channel : str , message_ts : str , thread_ts : str
146+ ) -> list [dict [str , Any ]]:
135147 """Create Slack blocks with feedback buttons"""
136148 # Create compact feedback payload for button actions
137149 feedback_data = {"ck" : conversation_key , "ch" : channel , "mt" : message_ts }
@@ -281,14 +293,14 @@ def log_query_stats(user_query: str, event: Dict[str, Any], channel: str, client
281293
282294
283295def store_feedback (
284- conversation_key ,
285- feedback_type ,
286- user_id ,
287- channel_id ,
296+ conversation_key : str ,
297+ feedback_type : str ,
298+ user_id : str ,
299+ channel_id : str ,
288300 client : WebClient ,
289- thread_ts = None ,
290- message_ts = None ,
291- feedback_text = None ,
301+ thread_ts : str = None ,
302+ message_ts : str = None ,
303+ feedback_text : str = None ,
292304):
293305 """
294306 Store user feedback with reference to Q&A record
@@ -373,15 +385,15 @@ def store_feedback(
373385# ================================================================
374386
375387
376- def get_conversation_session (conversation_key ) :
388+ def get_conversation_session (conversation_key : str ) -> str | None :
377389 """
378390 Get existing Bedrock session for this conversation
379391 """
380392 session_data = get_conversation_session_data (conversation_key )
381393 return session_data .get ("session_id" ) if session_data else None
382394
383395
384- def get_conversation_session_data (conversation_key ) :
396+ def get_conversation_session_data (conversation_key : str ) -> Dict [ str , Any ] :
385397 """
386398 Get full session data for this conversation
387399 """
@@ -396,7 +408,7 @@ def get_conversation_session_data(conversation_key):
396408 return None
397409
398410
399- def get_latest_message_ts (conversation_key ) :
411+ def get_latest_message_ts (conversation_key : str ) -> str :
400412 """
401413 Get latest message timestamp from session
402414 """
@@ -411,7 +423,12 @@ def get_latest_message_ts(conversation_key):
411423
412424
413425def store_conversation_session (
414- conversation_key , session_id , user_id , channel_id , thread_ts = None , latest_message_ts = None
426+ conversation_key : str ,
427+ session_id : str ,
428+ user_id : str ,
429+ channel_id : str ,
430+ thread_ts : str = None ,
431+ latest_message_ts : str = None ,
415432):
416433 """
417434 Store new Bedrock session for conversation memory
@@ -440,7 +457,7 @@ def store_conversation_session(
440457 logger .error ("Error storing session" , extra = {"error" : traceback .format_exc ()})
441458
442459
443- def update_session_latest_message (conversation_key , message_ts ):
460+ def update_session_latest_message (conversation_key : str , message_ts : str ):
444461 """
445462 Update session with latest message timestamp
446463 """
0 commit comments