Jarvis-Brain 0.1.8.3__tar.gz → 0.1.8.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Jarvis_Brain
3
- Version: 0.1.8.3
3
+ Version: 0.1.8.5
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -52,11 +52,12 @@ def register_get_new_tab(mcp: FastMCP, browser_manager, client_manager: DPProxyC
52
52
 
53
53
  def register_pop_first_packet(mcp: FastMCP, browser_manager, client_manager: DPProxyClientManager):
54
54
  @mcp.tool(name="pop_first_packet",
55
- description="每调用一次就会弹出传入的tab页所监听到的数据包中的第一个packet_message,当一个packet_message的response body过长时会被切分成多个包,具体一个请求是否还有下一个包,可以参考body_completed字段")
56
- async def pop_first_packet(browser_port: int, tab_id: str) -> dict[str, Any]:
55
+ description="每调用一次就会弹出传入的tab页所监听到的数据包中的第一个packet_message,当一个packet_message的response body过长时会被切分成多个包,具体一个请求是否还有下一个包,可以参考body_completed字段"
56
+ "同时如果想要以域名对packet进行过滤,可以传入想要过滤的域名列表。")
57
+ async def pop_first_packet(browser_port: int, tab_id: str, domain_filter: list = None) -> dict[str, Any]:
57
58
  _browser = browser_manager.get_browser(browser_port)
58
59
  client = client_manager.get_client(tab_id)
59
- packet_message = client.pop_first_packet()
60
+ packet_message = client.pop_first_packet(domain_filter)
60
61
  message = f"tab页:【{tab_id}】,暂时没有监听到XHR数据包"
61
62
  if packet_message:
62
63
  message = f"tab页:【{tab_id}】,监听到XHR数据包",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "Jarvis_Brain" # 别人下载时用的名字,必须在 PyPI 上唯一
3
- version = "0.1.8.3"
3
+ version = "0.1.8.5"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
@@ -6,6 +6,7 @@ from DrissionPage._pages.chromium_tab import ChromiumTab
6
6
  from DrissionPage._units.listener import DataPacket
7
7
  from typing import Tuple, Optional
8
8
  import json
9
+ from urllib.parse import urlparse, urlunparse
9
10
 
10
11
  one_turn_max_token = 20000
11
12
 
@@ -28,7 +29,7 @@ class DPProxyClient:
28
29
  :return:
29
30
  """
30
31
  if start_listen:
31
- self.driver.listen.set_targets(res_type="XHR")
32
+ self.driver.listen.set_targets(targets="api|jsonp|callback", is_regex=True, res_type=('xhr', 'fetch'))
32
33
  self.driver.listen.start()
33
34
  self.thread = threading.Thread(target=self.start_listen, args=(count, timeout,))
34
35
  self.thread.start()
@@ -39,10 +40,18 @@ class DPProxyClient:
39
40
  pass
40
41
 
41
42
  # 每次调用函数,都从队列的左端弹出一个数据包
42
- def pop_first_packet(self):
43
+ def pop_first_packet(self, domain_filter: list):
43
44
  if self.packet_queue:
44
45
  result = self.packet_queue.popleft()
45
- return json.dumps(result, ensure_ascii=False)
46
+ packet_url = result["url"]
47
+ packet_domain = urlparse(packet_url).netloc
48
+ # 留两个路径和params的口子,万一后续需要加入这两个的过滤器可以参考domain过滤器的方式
49
+ packet_path = urlparse(packet_url).path
50
+ packet_param = urlparse(packet_url).params
51
+ # 如果没有给domain_filter或者给了domain_filter且包的domain在domain_filter中,都正常返回
52
+ if domain_filter is None or (domain_filter and packet_domain in domain_filter):
53
+ return json.dumps(result, ensure_ascii=False)
54
+ return None
46
55
  else:
47
56
  return None
48
57
 
File without changes
File without changes