import sys
import time
from pathlib import Path
sys.path.append(str(Path("05_Production_Pipeline").resolve()))
from invisible_playwright import InvisiblePlaywright
from muse_invpw_driver import sync_worker_profile, DEFAULT_PROFILE

def inspect_chat_container():
    sync_worker_profile()
    with InvisiblePlaywright(profile_dir=DEFAULT_PROFILE, headless=True) as ctx:
        page = ctx.pages[0] if ctx.pages else ctx.new_page()
        page.goto("https://muse.ai", wait_until="domcontentloaded", timeout=30000)
        time.sleep(3)
        
        # Check elements with role="log" or "main" or role="region" or div with chat
        main = page.locator("main")
        print(f"main count: {main.count()}")
        if main.count() > 0:
            print("MAIN innerText (first 500 chars):")
            print(main.first.inner_text()[:500])
            
        # Check messages
        # Look for assistant messages
        assistant_msgs = page.locator('[data-message-author="assistant"], [role="article"], .prose')
        print(f"Assistant/article messages count: {assistant_msgs.count()}")
        
        # Let's inspect where the latest message is located
        chat_area = page.locator('main, [role="main"]').first
        if chat_area.count() > 0:
            print("\nMAIN text sample:")
            print(chat_area.inner_text()[-500:])

if __name__ == "__main__":
    inspect_chat_container()
