Jarvis-Brain 0.1.11.3__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.
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/PKG-INFO +1 -1
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/pyproject.toml +1 -1
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/tools/tools.py +87 -76
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/.gitignore +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/README.md +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/mcp_tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/mcp_tools/dp_tools.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/mcp_tools/main.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/tools/browser_manager.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/tools/browser_proxy.py +0 -0
- {jarvis_brain-0.1.11.3 → jarvis_brain-0.1.11.4}/uv.lock +0 -0
|
@@ -11,84 +11,95 @@ from PIL import Image
|
|
|
11
11
|
import io
|
|
12
12
|
|
|
13
13
|
compress_html_js = """
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|