Now let me check if there's already a deep analysis in the DB so we can show the button conditionally in PHP:


   108→
   109→// Get saved AI responses for this thread from MongoDB
   110→$savedResponsesLimit = 5; // Initial load limit
   111→$savedResponses = $mongo->findAll('ai_query_responses',
   112→    ['thread_ids' => $threadId],
   113→    ['sort' => ['created_at' => -1], 'limit' => $savedResponsesLimit]
   114→);
   115→
   116→// Get total count of saved responses for this thread
   117→$totalSavedResponses = $mongo->count('ai_query_responses', ['thread_ids' => $threadId]);
   118→
   119→// Get first email's subject for page title
   120→$threadSubject = $emails[0]['subject'] ?? '(No Subject)';
   121→
   122→// Build participant map for displaying real names

// Get saved AI responses for this thread from MongoDB
$savedResponsesLimit = 5; // Initial load limit
$savedResponses = $mongo->findAll('ai_query_responses',
    ['thread_ids' => $threadId],
    ['sort' => ['created_at' => -1], 'limit' => $savedResponsesLimit]
);

// Get total count of saved responses for this thread
$totalSavedResponses = $mongo->count('ai_query_responses', ['thread_ids' => $threadId]);

// Get first email's subject for page title
$threadSubject = $emails[0]['subject'] ?? '(No Subject)';

// Build participant map for displaying real names


Add a check for deep analysis responses:


Edit

// Get total count of saved responses for this thread
$totalSavedResponses = $mongo->count('ai_query_responses', ['thread_ids' => $threadId]);

// Get first email's subject for page title

// Get total count of saved responses for this thread
$totalSavedResponses = $mongo->count('ai_query_responses', ['thread_ids' => $threadId]);

// Check if deep analysis exists for this thread
$hasDeepAnalysis = $mongo->count('ai_query_responses', [
    'thread_ids' => $threadId,
    'deep_analysis_pass' => ['$exists' => true]
]) > 0;

// Get first email's subject for page title