From 50ddecb02ed34120ee1558fabec3034d64e01194 Mon Sep 17 00:00:00 2001 From: operator-main Date: Sun, 4 Oct 2026 03:13:07 +0000 Subject: [PATCH] muse-chat-api.py: Get real thread ID after sidechat create\n\nSend system message to trigger ID assignment, poll for\n/thread/ instead of accepting /thread/new placeholder. --- bin/muse-chat-api.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index 9245b30..760009b 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -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/ + 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