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
+21 -8
View File
@@ -18,6 +18,13 @@ Usage:
muse-chat-api.py --account <agent> upload <file> [--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');