From 2074145e220cd0536537bcd32a05d91983efe525 Mon Sep 17 00:00:00 2001 From: operator-main Date: Sun, 4 Oct 2026 03:15:07 +0000 Subject: [PATCH] muse-chat-api.py: Integrate sidechat_manager.ensure_sidebar\n\nUse robust sidebar opener with exponential backoff retry\ninstead of single-attempt click. Fixes flaky NOSIDEBAR errors. --- bin/muse-chat-api.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index 760009b..78ce144 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -18,6 +18,13 @@ Usage: muse-chat-api.py --account upload [--message txt] [--dry-run] """ import json, urllib.request, websocket, time, sys, argparse, importlib.util +import os +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +try: + from sidechat_manager import ensure_sidebar, log_sidechat_op + HAS_SIDECHAT_MANAGER = True +except ImportError: + HAS_SIDECHAT_MANAGER = False def _load_accounts(): @@ -257,15 +264,21 @@ def cmd_sidechat_list(ws): def cmd_sidechat_create(ws): """Create a new side chat via the 'New side chat' button. Returns the new thread URL.""" - # Ensure sidebar is open (same selector as cmd_sidechat_list: textContent) - ev(ws, """(() => { - const btn = [...document.querySelectorAll("button")].find(b => - b.textContent.includes("Open chat and side chats") - ); - if (btn) btn.click(); - })()""") + # Use robust sidebar opener with retry (fixes flaky NOSIDEBAR errors) import time as _time - _time.sleep(2) + if HAS_SIDECHAT_MANAGER: + if not ensure_sidebar(ws): + print("ERROR: Could not open sidebar after retries", file=sys.stderr) + sys.exit(1) + else: + # Fallback to old method + ev(ws, """(() => { + const btn = [...document.querySelectorAll("button")].find(b => + b.textContent.includes("Open chat and side chats") + ); + if (btn) btn.click(); + })()""") + _time.sleep(2) result = ev(ws, """(() => { const btn = [...document.querySelectorAll('button')].find(b => (b.getAttribute('aria-label')||'') === 'New side chat');