diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index 9299242..7588b23 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -270,20 +270,31 @@ def cmd_sidechat_create(ws): - + button: [data-testid="hatch-chat-compose"] (SVG icon, no text) """ import time as _time - # Check if + button already present (panel open). If not, open via switcher. - # Fixed 2026-10-04: don't blindly click switcher, check state first. - has_plus = ev(ws, """(() => { - return !!document.querySelector('[data-testid="hatch-chat-compose"]'); - })()""") - if not has_plus: - # Panel closed, open via switcher trigger - sw_result = ev(ws, """(() => { + # Check if panel is open via exact 'Side chats' header text node. + # (Not innerText.includes - the switcher button text contains "Open chat and + # side chats" which is always true. Must check for the header element.) + # Then open via switcher if needed (loop up to 5 attempts). + # Fixed 2026-10-04 per chat panel investigation. + def _panel_open(): + return ev(ws, """(() => { + const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); + let n; + while (n = walker.nextNode()) { + if (n.textContent.trim() === 'Side chats') return true; + } + return false; + })()""") + + for _attempt in range(5): + if _panel_open(): + break + ev(ws, """(() => { const sw = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]'); if (sw) sw.click(); - return sw ? 'SWITCHER_CLICKED' : 'NO_SWITCHER'; })()""") - print(f"Switcher: {sw_result}", file=sys.stderr) - _time.sleep(2) # Wait for React render + _time.sleep(3) + else: + print("Warning: panel may not be open after 5 attempts", file=sys.stderr) # Find + button via data-testid (verified selector, SVG icon no text) result = ev(ws, """(() => { const btn = document.querySelector('[data-testid="hatch-chat-compose"]');