Jarvis-Brain 0.1.11.2__tar.gz → 0.1.11.4__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.11.2
3
+ Version: 0.1.11.4
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -308,13 +308,15 @@ def register_scroll_action(mcp: FastMCP, browser_manager):
308
308
 
309
309
 
310
310
  def register_get_screenshot(mcp: FastMCP, browser_manager):
311
- @mcp.tool(name="get_tab_screenshot", description="尝试对传入tab页进行截图,并将截图压缩为1M大小png图片,会返回截图保存路径")
311
+ @mcp.tool(name="get_tab_screenshot",
312
+ description="尝试对传入tab页进行截图,并将截图压缩为1M大小png图片,会返回截图保存路径")
312
313
  async def get_tab_screenshot(browser_port: int, tab_id: str) -> dict[str, Any]:
313
314
  _browser = browser_manager.get_browser(browser_port)
314
315
  target_tab = _browser.get_tab(tab_id)
315
316
  if not os.path.exists(html_source_code_local_save_path):
316
317
  os.makedirs(html_source_code_local_save_path)
317
318
  timestamp = int(time.time() * 1000)
319
+ time.sleep(3)
318
320
  origin_png = target_tab.get_screenshot(as_bytes="png")
319
321
  compress_png = compress_image_bytes(origin_png)
320
322
  image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.png")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "Jarvis_Brain" # 别人下载时用的名字,必须在 PyPI 上唯一
3
- version = "0.1.11.2"
3
+ version = "0.1.11.4"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
@@ -11,84 +11,95 @@ from PIL import Image
11
11
  import io
12
12
 
13
13
  compress_html_js = """
14
- function getSimplifiedDOM(node) {
15
- // 1. 处理文本节点
16
- if (node.nodeType === Node.TEXT_NODE) {
17
- const text = node.textContent.trim();
18
- // 限制文本长度,避免大段文章消耗 token,保留前100个字符通常足够定位
19
- return text ? text.slice(0, 100) + (text.length > 100 ? '...' : '') : null;
20
- }
21
-
22
- // 2. 过滤无用标签
23
- const ignoreTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'IFRAME', 'SVG', 'LINK', 'META'];
24
- if (ignoreTags.includes(node.tagName)) return null;
25
- if (node.nodeType !== Node.ELEMENT_NODE) return null;
26
-
27
- // 3. 过滤不可见元素
28
- const style = window.getComputedStyle(node);
29
- if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') return null;
30
- // 过滤宽高太小的元素(往往是埋点空像素)
31
- const rect = node.getBoundingClientRect();
32
- if (rect.width === 0 || rect.height === 0) return null;
33
-
34
- // --- 开始构建标签字符串 ---
35
- const tagName = node.tagName.toLowerCase();
36
- let tagStr = tagName;
37
-
38
- // A. 基础标识符 (ID 和 Class)
39
- if (node.id) tagStr += `#${node.id}`;
40
- if (node.className && typeof node.className === 'string') {
41
- // 过滤掉 Tailwind 等太长且无语义的 class,保留有意义的业务 class
42
- // 这里简单处理,全部保留,让 LLM 自己判断
43
- const classes = node.className.trim().split(/\s+/);
44
- if (classes.length > 0) tagStr += `.${classes.join('.')}`;
45
- }
46
-
47
- // B. 关键属性白名单 (这是你指出问题的核心修复)
48
- const props = [];
49
-
50
- // 通用重要属性
51
- if (node.getAttribute('role')) props.push(`role="${node.getAttribute('role')}"`);
52
- if (node.getAttribute('aria-label')) props.push(`aria-label="${node.getAttribute('aria-label')}"`);
53
- if (node.getAttribute('title')) props.push(`title="${node.getAttribute('title')}"`);
54
-
55
- // 特定标签的特定属性
56
- if (tagName === 'a') {
57
- const href = node.getAttribute('href');
58
- // 只保留有意义的链接,忽略 javascript:;
59
- if (href && !href.startsWith('javascript')) props.push(`href="${href}"`);
60
- } else if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
61
- if (node.getAttribute('type')) props.push(`type="${node.getAttribute('type')}"`);
62
- if (node.getAttribute('name')) props.push(`name="${node.getAttribute('name')}"`);
63
- if (node.getAttribute('placeholder')) props.push(`placeholder="${node.getAttribute('placeholder')}"`);
64
- if (node.disabled) props.push('disabled');
65
- if (node.checked) props.push('checked');
66
- } else if (tagName === 'button') {
67
- if (node.getAttribute('type')) props.push(`type="${node.getAttribute('type')}"`);
68
- } else if (tagName === 'img') {
69
- if (node.getAttribute('alt')) props.push(`alt="${node.getAttribute('alt')}"`);
70
- }
71
-
72
- if (props.length > 0) {
73
- tagStr += ` ${props.join(' ')}`;
74
- }
75
-
76
- // 4. 递归子节点
77
- const children = Array.from(node.childNodes)
78
- .map(getSimplifiedDOM)
79
- .filter(n => n !== null);
80
-
81
- // 5. 组装输出
82
- // 如果没有子节点,也没有ID/Class,也不是输入框/图片/链接,那这个标签可能只是布局用的 div,可以考虑跳过它直接返回子节点内容
83
- // 但为了保持结构完整,我们暂时保留它
84
- if (children.length === 0) {
85
- // 自闭合标签或空标签
86
- return `<${tagStr} />`;
87
- }
88
- return `<${tagStr}>${children.join('')}</${tagName}>`; // 结束标签只保留 tagName 节省 token
14
+ function getSimplifiedDOM(node) {
15
+ // 1. 处理文本节点
16
+ if (node.nodeType === Node.TEXT_NODE) {
17
+ const text = node.textContent.trim();
18
+ return text ? text.slice(0, 100) + (text.length > 100 ? '...' : '') : null;
89
19
  }
90
20
 
91
- return getSimplifiedDOM(document.body);
21
+ // 2. 过滤无用标签
22
+ const ignoreTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'IFRAME', 'SVG', 'LINK', 'META'];
23
+ if (ignoreTags.includes(node.tagName)) return null;
24
+ if (node.nodeType !== Node.ELEMENT_NODE) return null;
25
+
26
+ // 3. 过滤不可见元素
27
+ // 【注意】这里声明了第一次 style
28
+ const style = window.getComputedStyle(node);
29
+
30
+ if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') return null;
31
+
32
+ // 过滤宽高太小的元素(往往是埋点空像素)
33
+ const rect = node.getBoundingClientRect();
34
+
35
+ // 【修复点】删除了这里重复的 const style = ... 代码
36
+ // 直接使用上面已经定义好的 style 变量即可
37
+
38
+ // 如果宽高为0,但溢出可见,说明可能有定位的子元素显示在外面
39
+ if ((rect.width === 0 || rect.height === 0) && style.overflow !== 'visible') return null;
40
+
41
+ // --- 开始构建标签字符串 ---
42
+ const tagName = node.tagName.toLowerCase();
43
+ let tagStr = tagName;
44
+
45
+ // A. 基础标识符 (ID 和 Class)
46
+ if (node.id) tagStr += `#${node.id}`;
47
+ if (node.className && typeof node.className === 'string') {
48
+ const classes = node.className.trim().split(/\s+/);
49
+ if (classes.length > 0) tagStr += `.${classes.join('.')}`;
50
+ }
51
+
52
+ // B. 关键属性白名单
53
+ const props = [];
54
+
55
+ // 通用重要属性
56
+ if (node.getAttribute('role')) props.push(`role="${node.getAttribute('role')}"`);
57
+ if (node.getAttribute('aria-label')) props.push(`aria-label="${node.getAttribute('aria-label')}"`);
58
+ if (node.getAttribute('title')) props.push(`title="${node.getAttribute('title')}"`);
59
+ // 建议增加这个,很多弹窗用这个属性
60
+ if (node.getAttribute('aria-modal')) props.push(`aria-modal="${node.getAttribute('aria-modal')}"`);
61
+
62
+ // 特定标签的特定属性
63
+ if (tagName === 'a') {
64
+ const href = node.getAttribute('href');
65
+ if (href && !href.startsWith('javascript')) props.push(`href="${href}"`);
66
+ } else if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
67
+ if (node.getAttribute('type')) props.push(`type="${node.getAttribute('type')}"`);
68
+ if (node.getAttribute('name')) props.push(`name="${node.getAttribute('name')}"`);
69
+ if (node.getAttribute('placeholder')) props.push(`placeholder="${node.getAttribute('placeholder')}"`);
70
+ if (node.disabled) props.push('disabled');
71
+ if (node.checked) props.push('checked');
72
+ } else if (tagName === 'button') {
73
+ if (node.getAttribute('type')) props.push(`type="${node.getAttribute('type')}"`);
74
+ } else if (tagName === 'img') {
75
+ if (node.getAttribute('alt')) props.push(`alt="${node.getAttribute('alt')}"`);
76
+ } else if (tagName === 'dialog') {
77
+ // 保留 open 属性
78
+ if (node.open) props.push('open');
79
+ }
80
+
81
+ if (props.length > 0) {
82
+ tagStr += ` ${props.join(' ')}`;
83
+ }
84
+
85
+ // 4. 递归子节点 (包含 Shadow DOM 处理)
86
+ let childNodes = Array.from(node.childNodes);
87
+ if (node.shadowRoot) {
88
+ childNodes = [...childNodes, ...Array.from(node.shadowRoot.childNodes)];
89
+ }
90
+
91
+ const children = childNodes
92
+ .map(getSimplifiedDOM)
93
+ .filter(n => n !== null);
94
+
95
+ // 5. 组装输出
96
+ if (children.length === 0) {
97
+ return `<${tagStr} />`;
98
+ }
99
+ return `<${tagStr}>${children.join('')}</${tagName}>`;
100
+ }
101
+
102
+ return getSimplifiedDOM(document.body);
92
103
  """
93
104
 
94
105
 
File without changes