muse-chat-api: add navigate command for thread URLs
This commit is contained in:
+13
-1
@@ -3,7 +3,7 @@
|
||||
Usage:
|
||||
muse-chat-api.py send "hello" # send message to current chat
|
||||
muse-chat-api.py messages # print recent messages
|
||||
muse-chat-api.py wait [timeout] # wait for new response
|
||||
muse-chat-api.py wait [timeout] # wait for new response\n muse-chat-api.py navigate <url> # go to thread URL
|
||||
Requires: websocket-client (pip install --break-system-packages websocket-client)
|
||||
CDP relay must be up: http://10.201.87.2:9410/json/list
|
||||
"""
|
||||
@@ -58,6 +58,16 @@ Array.from(document.querySelectorAll('p')).slice(-{limit}).map(e=>e.innerText).j
|
||||
finally:
|
||||
ws.close()
|
||||
|
||||
def navigate(url):
|
||||
"""Navigate to a URL (e.g., a thread: https://muse.ai/thread/<id>)."""
|
||||
ws = connect()
|
||||
try:
|
||||
ws.send(json.dumps({"id":1,"method":"Page.navigate","params":{"url":url}}))
|
||||
r = json.loads(ws.recv())
|
||||
return r.get('result',{}).get('frameId','navigated')
|
||||
finally:
|
||||
ws.close()
|
||||
|
||||
def wait_for_response(timeout=60, poll=2):
|
||||
"""Wait for a new assistant message after sending."""
|
||||
ws = connect()
|
||||
@@ -87,6 +97,8 @@ if __name__ == "__main__":
|
||||
print(send_message(sys.argv[2]))
|
||||
elif cmd == "messages":
|
||||
print(get_messages(int(sys.argv[2]) if len(sys.argv)>2 else 10))
|
||||
elif cmd == "navigate" and len(sys.argv) > 2:
|
||||
print(navigate(sys.argv[2]))
|
||||
elif cmd == "wait":
|
||||
print(wait_for_response(int(sys.argv[2]) if len(sys.argv)>2 else 60))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user