diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index 4e370da..af0e6d2 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -19,15 +19,15 @@ 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. +# Maps agent name -> (node, CDP URL). Agent == node == profile. ACCOUNTS = { - "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) + "muse": ("muse", "http://127.0.0.1:9410/json/list"), + "pip": ("pip", "http://127.0.0.1:9420/json/list"), } -def get_page(cdp_url): +def get_page(node, cdp_url): + # Run from within the node's netns via netvm-exec + # For now, assume we're already in the netns (called via netvm-exec.sh) with urllib.request.urlopen(cdp_url, timeout=5) as r: ts = json.load(r) pages = [t for t in ts if t.get('type') == 'page'] @@ -84,8 +84,10 @@ def main(): p.add_argument('arg', nargs='?', default=None) args = p.parse_args() - cdp_url = ACCOUNTS[args.account] - page = get_page(cdp_url) + node, cdp_url = ACCOUNTS[args.account] + # Note: Must be run via: netvm-exec.sh -- python3 muse-chat-api.py ... + # The node name matches the account name. + page = get_page(node, cdp_url) ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=15) try: