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.

This commit is contained in:
operator-main
2026-10-04 03:15:07 +00:00
parent 50ddecb02e
commit 2074145e22
+15 -2
View File
@@ -18,6 +18,13 @@ Usage:
muse-chat-api.py --account <agent> upload <file> [--message txt] [--dry-run] muse-chat-api.py --account <agent> upload <file> [--message txt] [--dry-run]
""" """
import json, urllib.request, websocket, time, sys, argparse, importlib.util 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(): def _load_accounts():
@@ -257,14 +264,20 @@ def cmd_sidechat_list(ws):
def cmd_sidechat_create(ws): def cmd_sidechat_create(ws):
"""Create a new side chat via the 'New side chat' button. Returns the new thread URL.""" """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) # Use robust sidebar opener with retry (fixes flaky NOSIDEBAR errors)
import time as _time
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, """(() => { ev(ws, """(() => {
const btn = [...document.querySelectorAll("button")].find(b => const btn = [...document.querySelectorAll("button")].find(b =>
b.textContent.includes("Open chat and side chats") b.textContent.includes("Open chat and side chats")
); );
if (btn) btn.click(); if (btn) btn.click();
})()""") })()""")
import time as _time
_time.sleep(2) _time.sleep(2)
result = ev(ws, """(() => { result = ev(ws, """(() => {
const btn = [...document.querySelectorAll('button')].find(b => const btn = [...document.querySelectorAll('button')].find(b =>