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_history():
    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)
        
        # Screenshot
        shot_path = Path("04_Assets/muse_shot11_failure.png").resolve()
        page.screenshot(path=str(shot_path))
        print("Screenshot:", shot_path)
        
        # Print all assistant messages
        assistant_msgs = page.locator('[data-message-author="assistant"], [role="article"]')
        print("Count:", assistant_msgs.count())
        for i in range(assistant_msgs.count()):
            msg = assistant_msgs.nth(i).inner_text().strip()
            print(f"\n--- MSG {i} ---")
            print(msg[:400])

if __name__ == "__main__":
    inspect_chat_history()
