muse-chat-api.py: unified agent naming (muse, pip)
This commit is contained in:
+18
-16
@@ -1,26 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Multi-account muse.ai chat API.
|
||||
Multi-account muse.ai chat API. Unified naming.
|
||||
|
||||
Usage:
|
||||
muse-chat-api.py --account <name> send "message"
|
||||
muse-chat-api.py --account <name> messages [n]
|
||||
muse-chat-api.py --account <name> wait [timeout]
|
||||
muse-chat-api.py --account <agent> send "message"
|
||||
muse-chat-api.py --account <agent> messages [n]
|
||||
muse-chat-api.py --account <agent> wait [timeout]
|
||||
|
||||
Accounts (configured on bl):
|
||||
muse-agent : CDP 9410 (smoke node) - ltd.pixels.ltd@gmail.com
|
||||
pip : CDP 9420 (phone-test node) - piparada (phone OTP)
|
||||
646 : (not currently logged in - needs OTP)
|
||||
The <agent> name matches the NetVM node, chrome-box profile, and
|
||||
the `agent` column in ACCOUNTS.md. No translation.
|
||||
|
||||
The account maps to a CDP endpoint. The browser must be running
|
||||
with the account logged in.
|
||||
Accounts:
|
||||
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
|
||||
|
||||
# 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 = {
|
||||
"muse-agent": "http://127.0.0.1:9410/json/list",
|
||||
"pip": "http://127.0.0.1:9420/json/list",
|
||||
# "646": "http://127.0.0.1:9430/json/list", # TODO: set up 646 node
|
||||
"muse": "http://127.0.0.1:9410/json/list", # node: smoke (TODO: rename to muse)
|
||||
"pip": "http://127.0.0.1:9420/json/list", # node: phone-test (TODO: rename to pip)
|
||||
}
|
||||
|
||||
def get_page(cdp_url):
|
||||
@@ -41,7 +45,6 @@ def ev(ws, expr, await_p=False):
|
||||
return resp.get('result', {}).get('result', {}).get('value')
|
||||
|
||||
def cmd_send(ws, message):
|
||||
# Escape for JS
|
||||
msg_esc = message.replace('\\', '\\\\').replace('`', '\\`').replace('$', '\\$')
|
||||
result = ev(ws, f"""(async()=>{{
|
||||
const input = document.querySelector('[contenteditable="true"]') ||
|
||||
@@ -70,14 +73,13 @@ def cmd_messages(ws, n=5):
|
||||
|
||||
def cmd_wait(ws, timeout=30):
|
||||
print(f"Waiting {timeout}s for response...")
|
||||
# Simple: wait and then get messages
|
||||
time.sleep(timeout)
|
||||
cmd_messages(ws, 2)
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
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('arg', nargs='?', default=None)
|
||||
args = p.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user