muse-chat-api.py: Get real thread ID after sidechat create\n\nSend system message to trigger ID assignment, poll for\n/thread/<uuid> instead of accepting /thread/new placeholder.

This commit is contained in:
operator-main
2026-10-04 03:13:07 +00:00
parent 942f37e21c
commit 50ddecb02e
+28
View File
@@ -289,6 +289,34 @@ def cmd_sidechat_create(ws):
if not url or "/thread/" not in url:
print(f"ERROR: Sidechat creation did not navigate to thread URL (got: {url})", file=sys.stderr)
sys.exit(1)
# If we got /thread/new (placeholder), the real ID is assigned after
# the first message. Send a system message to trigger ID assignment,
# then re-read the URL.
if url.endswith("/thread/new"):
ev(ws, """(() => {
const input = document.querySelector('[contenteditable="true"]');
if (!input) return 'NO_INPUT';
input.focus();
document.execCommand('insertText', false, '[System: Side chat created]');
return 'READY';
})()""")
_time.sleep(1)
# Click send
ev(ws, """(() => {
const btn = [...document.querySelectorAll('button')].find(b =>
(b.getAttribute('aria-label')||'').toLowerCase().includes('send'));
if (btn) { btn.click(); return 'SENT'; }
return 'NO_BTN';
})()""")
# Poll for URL to change from /thread/new to /thread/<uuid>
for i in range(15):
_time.sleep(1)
url = ev(ws, "window.location.href")
if url and "/thread/" in url and not url.endswith("/thread/new"):
break
if not url or "/thread/" not in url or url.endswith("/thread/new"):
print(f"ERROR: Could not get real thread ID (got: {url})", file=sys.stderr)
sys.exit(1)
print(f"Created: {url}")
return url