muse-chat-api.py: unified agent naming (muse, pip)

This commit is contained in:
operator
2026-10-03 17:15:53 +00:00
parent ee7524d7f1
commit 7ab615901a
+18 -16
View File
@@ -1,26 +1,30 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
Multi-account muse.ai chat API. Multi-account muse.ai chat API. Unified naming.
Usage: Usage:
muse-chat-api.py --account <name> send "message" muse-chat-api.py --account <agent> send "message"
muse-chat-api.py --account <name> messages [n] muse-chat-api.py --account <agent> messages [n]
muse-chat-api.py --account <name> wait [timeout] muse-chat-api.py --account <agent> wait [timeout]
Accounts (configured on bl): The <agent> name matches the NetVM node, chrome-box profile, and
muse-agent : CDP 9410 (smoke node) - ltd.pixels.ltd@gmail.com the `agent` column in ACCOUNTS.md. No translation.
pip : CDP 9420 (phone-test node) - piparada (phone OTP)
646 : (not currently logged in - needs OTP)
The account maps to a CDP endpoint. The browser must be running Accounts:
with the account logged in. muse : CDP 9410 - ltd.pixels.ltd@gmail.com (email_otp) - ACTIVE
pip : CDP 9420 - piparada (phone_otp) - PENDING (needs re-auth)
646 : (not set up yet)
See ACCOUNTS.md for the full registry.
""" """
import json, urllib.request, websocket, time, sys, argparse import json, urllib.request, websocket, time, sys, argparse
# Maps agent name -> CDP URL. The agent name IS the node name.
# TODO: Rename smoke node to 'muse', phone-test to 'pip' for full unification.
# For now, map the unified names to the existing node CDP ports.
ACCOUNTS = { ACCOUNTS = {
"muse-agent": "http://127.0.0.1:9410/json/list", "muse": "http://127.0.0.1:9410/json/list", # node: smoke (TODO: rename to muse)
"pip": "http://127.0.0.1:9420/json/list", "pip": "http://127.0.0.1:9420/json/list", # node: phone-test (TODO: rename to pip)
# "646": "http://127.0.0.1:9430/json/list", # TODO: set up 646 node
} }
def get_page(cdp_url): def get_page(cdp_url):
@@ -41,7 +45,6 @@ def ev(ws, expr, await_p=False):
return resp.get('result', {}).get('result', {}).get('value') return resp.get('result', {}).get('result', {}).get('value')
def cmd_send(ws, message): def cmd_send(ws, message):
# Escape for JS
msg_esc = message.replace('\\', '\\\\').replace('`', '\\`').replace('$', '\\$') msg_esc = message.replace('\\', '\\\\').replace('`', '\\`').replace('$', '\\$')
result = ev(ws, f"""(async()=>{{ result = ev(ws, f"""(async()=>{{
const input = document.querySelector('[contenteditable="true"]') || const input = document.querySelector('[contenteditable="true"]') ||
@@ -70,14 +73,13 @@ def cmd_messages(ws, n=5):
def cmd_wait(ws, timeout=30): def cmd_wait(ws, timeout=30):
print(f"Waiting {timeout}s for response...") print(f"Waiting {timeout}s for response...")
# Simple: wait and then get messages
time.sleep(timeout) time.sleep(timeout)
cmd_messages(ws, 2) cmd_messages(ws, 2)
def main(): def main():
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
p.add_argument('--account', required=True, choices=list(ACCOUNTS.keys()), p.add_argument('--account', required=True, choices=list(ACCOUNTS.keys()),
help='Account to use') help='Agent name (matches node, profile, ACCOUNTS.md)')
p.add_argument('command', choices=['send', 'messages', 'wait']) p.add_argument('command', choices=['send', 'messages', 'wait'])
p.add_argument('arg', nargs='?', default=None) p.add_argument('arg', nargs='?', default=None)
args = p.parse_args() args = p.parse_args()