Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -656,8 +656,47 @@ def _sanitize_pkill_self_match(cmd: str) -> str:
|
|
| 656 |
return _PKILL_SELF_MATCH_RE.sub(_fix, cmd)
|
| 657 |
|
| 658 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
def run_raw_command(cmd: str, timeout: int = 60) -> dict:
|
| 660 |
cmd = _sanitize_pkill_self_match(cmd)
|
|
|
|
| 661 |
env = {**os.environ, "DISPLAY": DISPLAY_OF(),
|
| 662 |
"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
|
| 663 |
try:
|
|
@@ -1039,7 +1078,7 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 1039 |
|
| 1040 |
# โโ keyboard_type โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1041 |
elif action == "keyboard_type":
|
| 1042 |
-
text = data.get("text", "")
|
| 1043 |
if text:
|
| 1044 |
result = await type_text_smart(text)
|
| 1045 |
await send({"type": "ack", "action": "keyboard_type",
|
|
@@ -1102,12 +1141,12 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 1102 |
elif action == "open_app":
|
| 1103 |
app_cmd = data.get("cmd", "")
|
| 1104 |
if app_cmd:
|
| 1105 |
-
fixed_cmd = app_cmd
|
| 1106 |
# ุฅุตูุงุญ firefox-esr
|
| 1107 |
-
if "firefox-esr" in
|
| 1108 |
esr_check = await asyncio.to_thread(subprocess.run, ["which", "firefox-esr"], capture_output=True, text=True)
|
| 1109 |
if esr_check.returncode != 0:
|
| 1110 |
-
fixed_cmd =
|
| 1111 |
|
| 1112 |
# โโ ุญู
ุงูุฉ ุฅุถุงููุฉ: ุญุฐู ู
ููุงุช ููู Firefox ุงูู
ุชุจููุฉ ูุจู ูุชุญ ูุงูุฐุฉ ุฌุฏูุฏุฉ โโ
|
| 1113 |
# ูู
ูุน ุธููุฑ "Firefox is already running, but is not responding" ุญุชู ูู
|
|
@@ -1165,6 +1204,48 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 1165 |
# โโ start_stream / stop_stream: ุบูุฑ ู
ุณุชุฎุฏู
ุฉ ู
ู ุงููุงุฌูุฉ ุงูุญุงููุฉุ ุฃูุฒููุช ูู
ูุน
|
| 1166 |
# ุชุดุบูู ุญููุฉ ุชุตููุฑ ู
ุณุชู
ุฑุฉ ูู ุงูุฎูููุฉ ุจูุง ุฏุงุนู (ูุงูุช ุชุณุชููู ู
ูุงุฑุฏ ุญุชู ุจุนุฏ ุฅุบูุงู ุงูุงุชุตุงู) โโ
|
| 1167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1168 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1169 |
elif action == "screen_info":
|
| 1170 |
w, h = await asyncio.to_thread(_get_screen_size)
|
|
@@ -1198,7 +1279,7 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 1198 |
else:
|
| 1199 |
await send({
|
| 1200 |
"type": "error",
|
| 1201 |
-
"msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_browser, paste, simple_command, screen_info"
|
| 1202 |
})
|
| 1203 |
|
| 1204 |
|
|
|
|
| 656 |
return _PKILL_SELF_MATCH_RE.sub(_fix, cmd)
|
| 657 |
|
| 658 |
|
| 659 |
+
_BING_URL_RE = re.compile(r"https?://(?:www\.)?bing\.com[^\s'\"]*")
|
| 660 |
+
_DDG_URL_RE = re.compile(r"https?://(?:www\.)?duckduckgo\.com[^\s'\"]*")
|
| 661 |
+
_GOOGLE_URL_RE = re.compile(r"https?://(?:www\.)?google\.[a-z.]+[^\s'\"]*")
|
| 662 |
+
|
| 663 |
+
def _enforce_safesearch(text: str) -> str:
|
| 664 |
+
"""
|
| 665 |
+
ููุฑุถ ู
ุนุงู
ูุงุช SafeSearch ุงูุตุงุฑู
ุฉ ุชููุงุฆูุงู ุนูู ุฃู ุฑุงุจุท Bing ุฃู DuckDuckGo ุฃู Google
|
| 666 |
+
ู
ูุฌูุฏ ูู ุงููุตุ ุจุบุถ ุงููุธุฑ ุนู
ูุง ูุชุจู ุงูุฐูุงุก โ ุญู
ุงูุฉ ุฅูุฒุงู
ูุฉ ุนูู ู
ุณุชูู ุงูุณูุฑูุฑ
|
| 667 |
+
ูู
ูุน ุธููุฑ ู
ุญุชูู ุบูุฑ ูุงุฆู ูู ูุชุงุฆุฌ ุงูุจุญุซุ ู
ุณุชููุฉ ุนู ุชุนููู
ุงุช ุงูู prompt.
|
| 668 |
+
ุชุบุทู ุฃูุถุงู ุญุงูุฉ ุงููุตูู ูู Google ุจุดูู ุบูุฑ ู
ุจุงุดุฑ (ุนุจุฑ ุฑุงุจุท ู
ูุชูุจ ุตุฑูุญ ูู ุงูุฃู
ุฑ).
|
| 669 |
+
"""
|
| 670 |
+
def _fix_bing(m):
|
| 671 |
+
url = m.group(0)
|
| 672 |
+
if "adlt=" in url:
|
| 673 |
+
return re.sub(r"adlt=\w+", "adlt=strict", url)
|
| 674 |
+
sep = "&" if "?" in url else "?"
|
| 675 |
+
return url + f"{sep}adlt=strict"
|
| 676 |
+
|
| 677 |
+
def _fix_ddg(m):
|
| 678 |
+
url = m.group(0)
|
| 679 |
+
if "kp=" in url:
|
| 680 |
+
return re.sub(r"kp=\d", "kp=1", url)
|
| 681 |
+
sep = "&" if "?" in url else "?"
|
| 682 |
+
return url + f"{sep}kp=1"
|
| 683 |
+
|
| 684 |
+
def _fix_google(m):
|
| 685 |
+
url = m.group(0)
|
| 686 |
+
if "safe=" in url:
|
| 687 |
+
return re.sub(r"safe=\w+", "safe=strict", url)
|
| 688 |
+
sep = "&" if "?" in url else "?"
|
| 689 |
+
return url + f"{sep}safe=strict"
|
| 690 |
+
|
| 691 |
+
text = _BING_URL_RE.sub(_fix_bing, text)
|
| 692 |
+
text = _DDG_URL_RE.sub(_fix_ddg, text)
|
| 693 |
+
text = _GOOGLE_URL_RE.sub(_fix_google, text)
|
| 694 |
+
return text
|
| 695 |
+
|
| 696 |
+
|
| 697 |
def run_raw_command(cmd: str, timeout: int = 60) -> dict:
|
| 698 |
cmd = _sanitize_pkill_self_match(cmd)
|
| 699 |
+
cmd = _enforce_safesearch(cmd)
|
| 700 |
env = {**os.environ, "DISPLAY": DISPLAY_OF(),
|
| 701 |
"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
|
| 702 |
try:
|
|
|
|
| 1078 |
|
| 1079 |
# โโ keyboard_type โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1080 |
elif action == "keyboard_type":
|
| 1081 |
+
text = _enforce_safesearch(data.get("text", ""))
|
| 1082 |
if text:
|
| 1083 |
result = await type_text_smart(text)
|
| 1084 |
await send({"type": "ack", "action": "keyboard_type",
|
|
|
|
| 1141 |
elif action == "open_app":
|
| 1142 |
app_cmd = data.get("cmd", "")
|
| 1143 |
if app_cmd:
|
| 1144 |
+
fixed_cmd = _enforce_safesearch(app_cmd)
|
| 1145 |
# ุฅุตูุงุญ firefox-esr
|
| 1146 |
+
if "firefox-esr" in fixed_cmd:
|
| 1147 |
esr_check = await asyncio.to_thread(subprocess.run, ["which", "firefox-esr"], capture_output=True, text=True)
|
| 1148 |
if esr_check.returncode != 0:
|
| 1149 |
+
fixed_cmd = fixed_cmd.replace("firefox-esr", BROWSER)
|
| 1150 |
|
| 1151 |
# โโ ุญู
ุงูุฉ ุฅุถุงููุฉ: ุญุฐู ู
ููุงุช ููู Firefox ุงูู
ุชุจููุฉ ูุจู ูุชุญ ูุงูุฐุฉ ุฌุฏูุฏุฉ โโ
|
| 1152 |
# ูู
ูุน ุธููุฑ "Firefox is already running, but is not responding" ุญุชู ูู
|
|
|
|
| 1204 |
# โโ start_stream / stop_stream: ุบูุฑ ู
ุณุชุฎุฏู
ุฉ ู
ู ุงููุงุฌูุฉ ุงูุญุงููุฉุ ุฃูุฒููุช ูู
ูุน
|
| 1205 |
# ุชุดุบูู ุญููุฉ ุชุตููุฑ ู
ุณุชู
ุฑุฉ ูู ุงูุฎูููุฉ ุจูุง ุฏุงุนู (ูุงูุช ุชุณุชููู ู
ูุงุฑุฏ ุญุชู ุจุนุฏ ุฅุบูุงู ุงูุงุชุตุงู) โโ
|
| 1206 |
|
| 1207 |
+
# โโ open_tab โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1208 |
+
elif action == "open_tab":
|
| 1209 |
+
url = _enforce_safesearch(data.get("url", "") or "about:blank")
|
| 1210 |
+
await xdo(["key", "--clearmodifiers", "ctrl+t"])
|
| 1211 |
+
await asyncio.sleep(0.4)
|
| 1212 |
+
await xdo(["key", "--clearmodifiers", "ctrl+l"])
|
| 1213 |
+
await asyncio.sleep(0.2)
|
| 1214 |
+
await type_text_smart(url)
|
| 1215 |
+
await asyncio.sleep(0.2)
|
| 1216 |
+
await xdo(["key", "--clearmodifiers", "Return"])
|
| 1217 |
+
await send({"type": "ack", "action": "open_tab", "url": url})
|
| 1218 |
+
await auto_shot_grid("ุจุนุฏ ูุชุญ ุชุจููุจ ุฌุฏูุฏ", delay=1.5)
|
| 1219 |
+
|
| 1220 |
+
# โโ close_tab โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1221 |
+
elif action == "close_tab":
|
| 1222 |
+
await xdo(["key", "--clearmodifiers", "ctrl+w"])
|
| 1223 |
+
await send({"type": "ack", "action": "close_tab"})
|
| 1224 |
+
await auto_shot_grid("ุจุนุฏ ุฅุบูุงู ุงูุชุจููุจ", delay=0.5)
|
| 1225 |
+
|
| 1226 |
+
# โโ browser_back โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1227 |
+
elif action == "browser_back":
|
| 1228 |
+
await xdo(["key", "--clearmodifiers", "alt+Left"])
|
| 1229 |
+
await send({"type": "ack", "action": "browser_back"})
|
| 1230 |
+
await auto_shot_grid("ุจุนุฏ ุงูุฑุฌูุน", delay=0.8)
|
| 1231 |
+
|
| 1232 |
+
# โโ browser_forward โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1233 |
+
elif action == "browser_forward":
|
| 1234 |
+
await xdo(["key", "--clearmodifiers", "alt+Right"])
|
| 1235 |
+
await send({"type": "ack", "action": "browser_forward"})
|
| 1236 |
+
await auto_shot_grid("ุจุนุฏ ุงูุชูุฏู
", delay=0.8)
|
| 1237 |
+
|
| 1238 |
+
# โโ browser_search: ุงุฎุชุตุงุฑ ููุชุญ ุจุญุซ ู
ุจุงุดุฑุฉ ูู ุงูุชุจููุจ ุงูุญุงูู โโ
|
| 1239 |
+
elif action == "browser_search":
|
| 1240 |
+
url = _enforce_safesearch(data.get("url", "") or data.get("query", ""))
|
| 1241 |
+
await xdo(["key", "--clearmodifiers", "ctrl+l"])
|
| 1242 |
+
await asyncio.sleep(0.2)
|
| 1243 |
+
await type_text_smart(url)
|
| 1244 |
+
await asyncio.sleep(0.2)
|
| 1245 |
+
await xdo(["key", "--clearmodifiers", "Return"])
|
| 1246 |
+
await send({"type": "ack", "action": "browser_search", "url": url})
|
| 1247 |
+
await auto_shot_grid("ุจุนุฏ ุงูุจุญุซ", delay=1.5)
|
| 1248 |
+
|
| 1249 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1250 |
elif action == "screen_info":
|
| 1251 |
w, h = await asyncio.to_thread(_get_screen_size)
|
|
|
|
| 1279 |
else:
|
| 1280 |
await send({
|
| 1281 |
"type": "error",
|
| 1282 |
+
"msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_tab, close_tab, browser_back, browser_forward, browser_search, open_browser, paste, simple_command, screen_info"
|
| 1283 |
})
|
| 1284 |
|
| 1285 |
|