Jarvis-Brain 0.1.9.2__py3-none-any.whl → 0.1.9.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jarvis_brain-0.1.9.2.dist-info → jarvis_brain-0.1.9.3.dist-info}/METADATA +1 -1
- {jarvis_brain-0.1.9.2.dist-info → jarvis_brain-0.1.9.3.dist-info}/RECORD +6 -6
- mcp_tools/dp_tools.py +24 -12
- tools/browser_proxy.py +17 -16
- {jarvis_brain-0.1.9.2.dist-info → jarvis_brain-0.1.9.3.dist-info}/WHEEL +0 -0
- {jarvis_brain-0.1.9.2.dist-info → jarvis_brain-0.1.9.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
mcp_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
mcp_tools/dp_tools.py,sha256=
|
|
2
|
+
mcp_tools/dp_tools.py,sha256=78InuO5W28va6I0VkQdDAYpywiLHmYKDqM8DkArwqK8,16914
|
|
3
3
|
mcp_tools/main.py,sha256=84sv39oOw9vqr2MPxKy9pFVrevJ9nQJWFffpfg0s6iA,1098
|
|
4
4
|
tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
tools/browser_manager.py,sha256=zeYcWuzxoohMdnYUoZbRH7axFC_VtV8MsncfN8y0yw0,2023
|
|
6
|
-
tools/browser_proxy.py,sha256=
|
|
6
|
+
tools/browser_proxy.py,sha256=j4I8qaSxKp2GRnbbr8gVO2BhWvvAUO3pd4IjPj2TAhg,7569
|
|
7
7
|
tools/tools.py,sha256=TaWs-CNXy-py9BFmCnJrQ09ke938xXpImf-N2Qo_Rvc,4708
|
|
8
|
-
jarvis_brain-0.1.9.
|
|
9
|
-
jarvis_brain-0.1.9.
|
|
10
|
-
jarvis_brain-0.1.9.
|
|
11
|
-
jarvis_brain-0.1.9.
|
|
8
|
+
jarvis_brain-0.1.9.3.dist-info/METADATA,sha256=chnRYsrmrSo8W9ljXcRd4gaT9MHz0VAmMYcu4bCieno,241
|
|
9
|
+
jarvis_brain-0.1.9.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
10
|
+
jarvis_brain-0.1.9.3.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
|
|
11
|
+
jarvis_brain-0.1.9.3.dist-info/RECORD,,
|
mcp_tools/dp_tools.py
CHANGED
|
@@ -20,14 +20,22 @@ one_turn_max_token = 20000
|
|
|
20
20
|
|
|
21
21
|
def register_visit_url(mcp: FastMCP, browser_manager: BrowserManager, client_manager: DPProxyClientManager):
|
|
22
22
|
@mcp.tool(name="visit_url",
|
|
23
|
-
description="使用Drissionpage打开url访问某个网站,并开始监听初始tab页的所有的XHR
|
|
24
|
-
|
|
23
|
+
description="使用Drissionpage打开url访问某个网站,并开始监听初始tab页的所有的XHR请求"
|
|
24
|
+
"当需要使用手机版浏览器Ua时use_mobile_user_agent为True"
|
|
25
|
+
"如果想要以域名对packet进行过滤,可以传入想要过滤的域名列表。默认是:None。"
|
|
26
|
+
"如果想要以method对packet进行过滤,可以传入想要过滤的method列表,默认是:['GET', 'POST']")
|
|
27
|
+
async def visit_url(url: str, domain_filter: list = None, method_filter: list = ["GET", "POST"],
|
|
28
|
+
use_mobile_user_agent=False) -> dict[str, Any]:
|
|
25
29
|
mobile_user_agent = None
|
|
26
30
|
if use_mobile_user_agent:
|
|
27
31
|
mobile_user_agent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36"
|
|
28
32
|
port, _browser = browser_manager.create_browser(mobile_user_agent)
|
|
29
33
|
tab = _browser.get_tab()
|
|
30
|
-
|
|
34
|
+
packet_filter = {
|
|
35
|
+
"domain_filter": domain_filter,
|
|
36
|
+
"method_filter": method_filter,
|
|
37
|
+
}
|
|
38
|
+
client_manager.create_client(tab, packet_filter)
|
|
31
39
|
tab.get(url)
|
|
32
40
|
tab_id = tab.tab_id
|
|
33
41
|
return dp_mcp_message_pack(
|
|
@@ -39,11 +47,18 @@ def register_visit_url(mcp: FastMCP, browser_manager: BrowserManager, client_man
|
|
|
39
47
|
|
|
40
48
|
def register_get_new_tab(mcp: FastMCP, browser_manager, client_manager: DPProxyClientManager):
|
|
41
49
|
@mcp.tool(name="get_new_tab",
|
|
42
|
-
description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url,并开始监听新的tab页的所有XHR请求"
|
|
43
|
-
|
|
50
|
+
description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url,并开始监听新的tab页的所有XHR请求"
|
|
51
|
+
"如果想要以域名对packet进行过滤,可以传入想要过滤的域名列表。默认是:None。"
|
|
52
|
+
"如果想要以method对packet进行过滤,可以传入想要过滤的method列表,默认是:['GET', 'POST']")
|
|
53
|
+
async def get_new_tab(browser_port: int, url: str, domain_filter: list = None,
|
|
54
|
+
method_filter: list = ["GET", "POST"]) -> dict[str, Any]:
|
|
44
55
|
_browser = browser_manager.get_browser(browser_port)
|
|
45
56
|
tab = _browser.new_tab()
|
|
46
|
-
|
|
57
|
+
packet_filter = {
|
|
58
|
+
"domain_filter": domain_filter,
|
|
59
|
+
"method_filter": method_filter,
|
|
60
|
+
}
|
|
61
|
+
client_manager.create_client(tab, packet_filter)
|
|
47
62
|
tab.get(url)
|
|
48
63
|
_browser.activate_tab(tab)
|
|
49
64
|
tab_id = tab.tab_id
|
|
@@ -52,14 +67,11 @@ def register_get_new_tab(mcp: FastMCP, browser_manager, client_manager: DPProxyC
|
|
|
52
67
|
|
|
53
68
|
def register_pop_first_packet(mcp: FastMCP, browser_manager, client_manager: DPProxyClientManager):
|
|
54
69
|
@mcp.tool(name="pop_first_packet",
|
|
55
|
-
description="每调用一次就会弹出传入的tab页所监听到的数据包中的第一个packet_message,当一个packet_message的response body过长时会被切分成多个包,具体一个请求是否还有下一个包,可以参考body_completed字段"
|
|
56
|
-
|
|
57
|
-
"如果想要以method对packet进行过滤,可以传入想要过滤的method列表,默认是:['GET', 'POST']")
|
|
58
|
-
async def pop_first_packet(browser_port: int, tab_id: str, domain_filter: list = None,
|
|
59
|
-
method: list = ["GET", "POST"]) -> dict[str, Any]:
|
|
70
|
+
description="每调用一次就会弹出传入的tab页所监听到的数据包中的第一个packet_message,当一个packet_message的response body过长时会被切分成多个包,具体一个请求是否还有下一个包,可以参考body_completed字段")
|
|
71
|
+
async def pop_first_packet(browser_port: int, tab_id: str) -> dict[str, Any]:
|
|
60
72
|
_browser = browser_manager.get_browser(browser_port)
|
|
61
73
|
client = client_manager.get_client(tab_id)
|
|
62
|
-
current_queue_size, packet_message = client.pop_first_packet(
|
|
74
|
+
current_queue_size, packet_message = client.pop_first_packet()
|
|
63
75
|
message = f"tab页:【{tab_id}】,暂时没有监听到XHR数据包"
|
|
64
76
|
if packet_message:
|
|
65
77
|
message = f"tab页:【{tab_id}】,监听到XHR数据包,当前数据包队列中还剩 {current_queue_size} 条数据"
|
tools/browser_proxy.py
CHANGED
|
@@ -12,12 +12,12 @@ one_turn_max_token = 20000
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class DPProxyClient:
|
|
15
|
-
def __init__(self, driver: ChromiumTab, self_kill=False):
|
|
15
|
+
def __init__(self, driver: ChromiumTab, packet_filter: dict, self_kill=False):
|
|
16
16
|
self.tab_id = driver.tab_id
|
|
17
17
|
self.driver = ChromePageProxy(driver, self)
|
|
18
18
|
self.thread = None
|
|
19
19
|
self.self_kill = self_kill
|
|
20
|
-
|
|
20
|
+
self.packet_filter = packet_filter
|
|
21
21
|
self.packet_queue = deque()
|
|
22
22
|
|
|
23
23
|
def get_driver(self, start_listen, count=None, timeout=10) -> ChromiumTab:
|
|
@@ -40,21 +40,11 @@ class DPProxyClient:
|
|
|
40
40
|
pass
|
|
41
41
|
|
|
42
42
|
# 每次调用函数,都从队列的左端弹出一个数据包
|
|
43
|
-
def pop_first_packet(self
|
|
43
|
+
def pop_first_packet(self):
|
|
44
44
|
if self.packet_queue:
|
|
45
45
|
result = self.packet_queue.popleft()
|
|
46
46
|
current_queue_size = len(self.packet_queue)
|
|
47
|
-
|
|
48
|
-
packet_method = result["method"]
|
|
49
|
-
packet_domain = urlparse(packet_url).netloc
|
|
50
|
-
# 留两个路径和params的口子,万一后续需要加入这两个的过滤器可以参考domain过滤器的方式
|
|
51
|
-
packet_path = urlparse(packet_url).path
|
|
52
|
-
packet_param = urlparse(packet_url).params
|
|
53
|
-
# 如果没有给domain_filter或者给了domain_filter且包的domain在domain_filter中,都正常返回
|
|
54
|
-
if domain_filter is None or (domain_filter and packet_domain in domain_filter):
|
|
55
|
-
if packet_method in method:
|
|
56
|
-
return current_queue_size, json.dumps(result, ensure_ascii=False)
|
|
57
|
-
return current_queue_size, None
|
|
47
|
+
return current_queue_size, json.dumps(result, ensure_ascii=False)
|
|
58
48
|
else:
|
|
59
49
|
return 0, None
|
|
60
50
|
|
|
@@ -69,9 +59,10 @@ class DPProxyClientManager:
|
|
|
69
59
|
cls._instance.tab_pool = {}
|
|
70
60
|
return cls._instance
|
|
71
61
|
|
|
72
|
-
def create_client(self, tab: ChromiumTab, self_kill=False) -> Tuple[
|
|
62
|
+
def create_client(self, tab: ChromiumTab, packet_filter: dict, self_kill=False) -> Tuple[
|
|
63
|
+
str, DPProxyClient, ChromiumTab]:
|
|
73
64
|
"""创建新的tab页面代理实例"""
|
|
74
|
-
client = DPProxyClient(tab, self_kill=self_kill)
|
|
65
|
+
client = DPProxyClient(tab, packet_filter, self_kill=self_kill)
|
|
75
66
|
tab = client.get_driver(True, timeout=60 * 10)
|
|
76
67
|
tab_id = tab.tab_id
|
|
77
68
|
self.tab_pool[tab_id] = {"client": client, "driver": tab}
|
|
@@ -147,11 +138,21 @@ def check_data_packet(packet: DataPacket, client: DPProxyClient):
|
|
|
147
138
|
data = None
|
|
148
139
|
if packet.request.hasPostData:
|
|
149
140
|
data = packet.request.postData
|
|
141
|
+
domain = urlparse(url).netloc
|
|
150
142
|
body = packet.response.body
|
|
151
143
|
body_str = json.dumps(body, ensure_ascii=False)
|
|
152
144
|
body_str_list = [body_str[i:i + one_turn_max_token] for i in range(0, len(body_str), one_turn_max_token)]
|
|
153
145
|
body_completed = True
|
|
146
|
+
packet_filter = client.packet_filter
|
|
147
|
+
domain_filter = packet_filter.get("domain_filter", None)
|
|
148
|
+
method_filter = packet_filter.get("method_filter", ["GET", "POST"])
|
|
154
149
|
for index, body_str in enumerate(body_str_list):
|
|
150
|
+
# 如果给了domain_filter并且domain没有在domain_filter中时跳过该数据包
|
|
151
|
+
if domain_filter and domain not in domain_filter:
|
|
152
|
+
continue
|
|
153
|
+
# 如果method没有在method_filter中,则跳过该数据包
|
|
154
|
+
if method not in method_filter:
|
|
155
|
+
continue
|
|
155
156
|
if (index + 1) != len(body_str_list):
|
|
156
157
|
body_completed = False
|
|
157
158
|
temp_dict = {
|
|
File without changes
|
|
File without changes
|