muse-chat-api: Dont block sends on dialogs without IPs\n\ncheck_approvals was raising APPROVAL_NEEDED for false positives\n(dialogs without IP addresses, likely chat content misidentified).\nOnly IP-based permission dialogs should block. Others are ignored.
This commit is contained in:
+29
-19
@@ -102,6 +102,10 @@ def check_approvals(ws):
|
|||||||
# Extract IP if present
|
# Extract IP if present
|
||||||
import re
|
import re
|
||||||
ips = re.findall(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', d)
|
ips = re.findall(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', d)
|
||||||
|
# Only block for IP-based permission dialogs. Dialogs without IPs
|
||||||
|
# are likely false positives (chat content, UI text) - don't block.
|
||||||
|
if not ips:
|
||||||
|
continue
|
||||||
is_trusted = any(ip in TRUSTED_IPS for ip in ips)
|
is_trusted = any(ip in TRUSTED_IPS for ip in ips)
|
||||||
if is_trusted:
|
if is_trusted:
|
||||||
# Auto-approve: click "Allow once" or "Allow"
|
# Auto-approve: click "Allow once" or "Allow"
|
||||||
@@ -116,7 +120,7 @@ def check_approvals(ws):
|
|||||||
actions.append((d[:80], True, clicked))
|
actions.append((d[:80], True, clicked))
|
||||||
else:
|
else:
|
||||||
actions.append((d[:80], False, "APPROVAL_NEEDED"))
|
actions.append((d[:80], False, "APPROVAL_NEEDED"))
|
||||||
|
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
def cmd_approvals(ws):
|
def cmd_approvals(ws):
|
||||||
@@ -207,26 +211,32 @@ def cmd_sidechat_use(ws, chat_id):
|
|||||||
print(f"Navigated to: {result}")
|
print(f"Navigated to: {result}")
|
||||||
|
|
||||||
def cmd_sidechat_main(ws):
|
def cmd_sidechat_main(ws):
|
||||||
"""Navigate back to main chat by pressing the chat button."""
|
"""Navigate back to main chat via Ctrl+J keyboard shortcut."""
|
||||||
# The chat button (not the sidebar search) properly refocuses Main Chat.
|
# Ctrl+J (the Chat button shortcut) properly refocuses Main Chat.
|
||||||
|
# More reliable than DOM scraping for buttons/text.
|
||||||
# Do NOT navigate to https://muse.ai/ (landing page) - it restores the
|
# Do NOT navigate to https://muse.ai/ (landing page) - it restores the
|
||||||
# last-viewed chat which may be a side chat.
|
# last-viewed chat which may be a side chat.
|
||||||
js = (
|
import json as _json
|
||||||
"(async()=>{"
|
# Send Ctrl+J via Input.dispatchKeyEvent
|
||||||
# Find the chat button - it refocuses Main Chat when pressed
|
ws.send(_json.dumps({
|
||||||
"const btns=[...document.querySelectorAll('button')];"
|
"id": 10, "method": "Input.dispatchKeyEvent",
|
||||||
"const chatBtn=btns.find(b=>"
|
"params": {"type": "keyDown", "key": "j", "code": "KeyJ",
|
||||||
"b.textContent.includes('Open chat and side chats')||"
|
"ctrlKey": True, "modifiers": 2}
|
||||||
"b.getAttribute('aria-label')&&b.getAttribute('aria-label').toLowerCase().includes('chat')"
|
}))
|
||||||
");"
|
_json.loads(ws.recv())
|
||||||
"if(!chatBtn)return 'NOBUTTON';"
|
ws.send(_json.dumps({
|
||||||
"chatBtn.click();"
|
"id": 11, "method": "Input.dispatchKeyEvent",
|
||||||
"await new Promise(r=>setTimeout(r,4000));"
|
"params": {"type": "keyUp", "key": "j", "code": "KeyJ",
|
||||||
"return window.location.href;"
|
"ctrlKey": True, "modifiers": 2}
|
||||||
"})()"
|
}))
|
||||||
)
|
_json.loads(ws.recv())
|
||||||
result = ev(ws, js, True)
|
time.sleep(4)
|
||||||
print(f"Back to main chat: {result}")
|
# Get current URL to confirm navigation
|
||||||
|
ws.send(_json.dumps({"id": 12, "method": "Runtime.evaluate",
|
||||||
|
"params": {"expression": "window.location.href"}}))
|
||||||
|
resp = _json.loads(ws.recv())
|
||||||
|
url = resp.get("result", {}).get("result", {}).get("value", "unknown")
|
||||||
|
print(f"Back to main chat: {url}")
|
||||||
|
|
||||||
def cmd_sidechat_list(ws):
|
def cmd_sidechat_list(ws):
|
||||||
"""List side chats via DOM."""
|
"""List side chats via DOM."""
|
||||||
|
|||||||
Reference in New Issue
Block a user