Jarvis-Brain 0.1.5.8__tar.gz → 0.1.5.10__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.5.8
3
+ Version: 0.1.5.10
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -1,3 +1,4 @@
1
+ import hashlib
1
2
  import json
2
3
  import os
3
4
  from typing import Any
@@ -11,6 +12,8 @@ waf_status_code_dict = {
11
12
  412: "瑞数",
12
13
  521: "加速乐"
13
14
  }
15
+ # 一轮最大输入,以免单个html最大长度超过ai最大输入
16
+ ont_turn_max_token = 25000
14
17
 
15
18
 
16
19
  def register_visit_url(mcp: FastMCP, browser_manager):
@@ -33,16 +36,19 @@ def register_get_html(mcp: FastMCP, browser_manager):
33
36
  _browser = browser_manager.get_browser(browser_port)
34
37
  tab = _browser.get_tab(tab_id)
35
38
  file_name = str(tab.title).replace("/", "_").replace(":", "_")
36
- file_name = file_name + f"_{tab_id}.html"
37
39
  if not os.path.exists(html_source_code_local_save_path):
38
40
  os.makedirs(html_source_code_local_save_path)
39
- abs_path = os.path.join(html_source_code_local_save_path, file_name)
40
- tab.wait.doc_loaded()
41
- with open(abs_path, "w", encoding="utf-8") as f:
42
- min_html, compress_rate = compress_html(tab.html)
43
- f.write(min_html)
44
- return dp_mcp_message_pack(f"已保存tab页:【{tab_id}】的html源码", tab_id=tab_id, html_local_path=abs_path)
45
-
41
+ min_html, compress_rate = compress_html(tab.html)
42
+ html_str_list = [min_html[i:i + ont_turn_max_token] for i in range(0, len(min_html), ont_turn_max_token)]
43
+ html_file_list = []
44
+ for index, html_str in enumerate(html_str_list):
45
+ file_name = file_name + f"_{tab_id}_segment{index}.html"
46
+ abs_path = os.path.join(html_source_code_local_save_path, file_name)
47
+ with open(abs_path, "w", encoding="utf-8") as f:
48
+ f.write(html_str)
49
+ html_file_list.append(abs_path)
50
+ message = f"已保存tab页:【{tab_id}】的html源码片段共{len(html_file_list)}个"
51
+ return dp_mcp_message_pack(message, tab_id=tab_id, htmls_local_path=html_file_list)
46
52
 
47
53
  def register_get_new_tab(mcp: FastMCP, browser_manager):
48
54
  @mcp.tool(name="get_new_tab", description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url")
@@ -53,7 +59,6 @@ def register_get_new_tab(mcp: FastMCP, browser_manager):
53
59
  tab_id = tab.tab_id
54
60
  return dp_mcp_message_pack(f"已创建新的tab页,并打开链接:{url}", tab_id=tab_id)
55
61
 
56
-
57
62
  def register_switch_tab(mcp: FastMCP, browser_manager):
58
63
  @mcp.tool(name="switch_tab", description="根据传入的tab_id切换到对应的tab页", )
59
64
  async def switch_tab(browser_port: int, tab_id: str) -> dict[str, Any]:
@@ -61,7 +66,6 @@ def register_switch_tab(mcp: FastMCP, browser_manager):
61
66
  _browser.activate_tab(tab_id)
62
67
  return dp_mcp_message_pack(f"已将tab页:【{tab_id}】切换至最前端")
63
68
 
64
-
65
69
  def register_close_tab(mcp: FastMCP, browser_manager):
66
70
  @mcp.tool(name="close_tab", description="根据传入的tab_id关闭tab页", )
67
71
  async def close_tab(browser_port, tab_id) -> dict[str, Any]:
@@ -69,7 +73,6 @@ def register_close_tab(mcp: FastMCP, browser_manager):
69
73
  _browser.close_tabs(tab_id)
70
74
  return dp_mcp_message_pack(f"已将tab页:【{tab_id}】关闭")
71
75
 
72
-
73
76
  def register_check_selector(mcp: FastMCP, browser_manager):
74
77
  @mcp.tool(name="check_selector", description="查找tab页中是否包含元素,并返回元素attr_name所对应的值")
75
78
  async def check_selector(browser_port: int, tab_id: str, css_selector: str, attr_name: str = "text") -> dict[
@@ -96,7 +99,6 @@ def register_check_selector(mcp: FastMCP, browser_manager):
96
99
  attr_output=attr_output
97
100
  )
98
101
 
99
-
100
102
  def register_quit_browser(mcp: FastMCP, browser_manager):
101
103
  @mcp.tool(name="quit_browser", description="退出浏览器会话,关闭浏览器")
102
104
  async def quit_browser(browser_port: int) -> dict[str, Any]:
@@ -109,7 +111,6 @@ def register_quit_browser(mcp: FastMCP, browser_manager):
109
111
  quit_flag=flag
110
112
  )
111
113
 
112
-
113
114
  def register_assert_waf(mcp: FastMCP, browser_manager):
114
115
  @mcp.tool(name="assert_waf",
115
116
  description="通过对比requests、有头浏览器、无头浏览器获取到的html,判断网页是否使用了waf以及是否为动态渲染的网页")
@@ -159,7 +160,6 @@ def register_assert_waf(mcp: FastMCP, browser_manager):
159
160
  head_headless_rate_difference=h_hless_rate_diff
160
161
  )
161
162
 
162
-
163
163
  def register_highlight_element_captcha(mcp: FastMCP, browser_manager):
164
164
  @mcp.tool(name="highlight_element_captcha", description="将传入的Selector在页面上高亮,并截屏")
165
165
  async def highlight_element_captcha(browser_port: int, tab_id: str, css_selector: str) -> dict[str, Any]:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "Jarvis_Brain" # 别人下载时用的名字,必须在 PyPI 上唯一
3
- version = "0.1.5.8"
3
+ version = "0.1.5.10"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
File without changes