Jarvis-Brain 0.1.11.5__tar.gz → 0.1.11.7__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.5
3
+ Version: 0.1.11.7
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -7,6 +7,7 @@ import os
7
7
  import time
8
8
  from typing import Any
9
9
 
10
+ import DrissionPage
10
11
  from fastmcp import FastMCP
11
12
 
12
13
  from tools.browser_manager import BrowserManager
@@ -162,13 +163,13 @@ def register_check_selector(mcp: FastMCP, browser_manager):
162
163
  attr_output = json.dumps(ele_attr_list, ensure_ascii=False)
163
164
  # 对attr_output逐个截断,截断的长度为:一轮最大token除以元素个数+3个点+两个引号和逗号
164
165
  return dp_mcp_message_pack(
165
- f"已完成tab页:【{tab_id}】对:【{css_selector}】的检查",
166
+ f"已完成tab页:【{tab_id}】对:【{css_selector}】的检查,当前选中了 {len(target_eles)} 个元素",
166
167
  tab_id=tab_id,
167
168
  selector=css_selector,
168
169
  selector_ele_exist=exist_flag,
169
170
  page_size=page_size,
170
171
  offset=offset,
171
- attr_output=attr_output
172
+ attr_output=attr_output,
172
173
  )
173
174
 
174
175
 
@@ -236,27 +237,33 @@ def register_assert_waf(mcp: FastMCP, browser_manager):
236
237
 
237
238
 
238
239
  def register_click_action(mcp: FastMCP, browser_manager):
239
- @mcp.tool(name="click_action", description="尝试点击tab页中的元素,返回元素是否可以被点击,以及是否点击成功。")
240
- async def click_action(browser_port: int, tab_id: str, css_selector: str) -> dict[str, Any]:
240
+ @mcp.tool(name="click_action",
241
+ description="尝试点击tab页中的元素,返回元素是否可以被点击,以及是否点击成功。"
242
+ "其中target_element_index默认为0,当传入的Selector可以定位到多个元素时,需要传入target_element_index指定具体点击目标 ")
243
+ async def click_action(browser_port: int, tab_id: str, css_selector: str, target_element_index: int = 0) -> dict[
244
+ str, Any]:
241
245
  _browser = browser_manager.get_browser(browser_port)
242
246
  target_tab = _browser.get_tab(tab_id)
243
247
  css_selector = css_selector
244
248
  if "css:" not in css_selector:
245
249
  css_selector = "css:" + css_selector
246
250
  target_eles = target_tab.eles(css_selector)
247
- click_success = False
248
- element_clickable = False
249
- if len(target_eles) == 1:
250
- target_element = target_eles[0]
251
- element_clickable = target_element.states.is_clickable
252
- try:
253
- target_element.click()
254
- click_success = True
255
- except Exception as e:
256
- click_success = False
257
- message = f"tab页:【{tab_id}】点击【{css_selector}】 {'成功' if click_success else '失败'} 了"
251
+ # click_success = False
252
+ # element_clickable = False
253
+ # if len(target_eles) == 1:
254
+ target_element = target_eles[target_element_index]
255
+ element_clickable = target_element.states.is_clickable
256
+ try:
257
+ target_element.click()
258
+ click_success = True
259
+ except Exception as e:
260
+ click_success = False
261
+ if target_element_index > 0:
262
+ message = f"tab页:【{tab_id}】点击【{css_selector}】【index={target_element_index}】的元素 {'成功' if click_success else '失败'} 了"
258
263
  else:
259
- message = f"tab页:【{tab_id}】传入的css_selector找到了{len(target_eles)}个元素,请确保传入的css_selector可以找到唯一的一个元素"
264
+ message = f"tab页:【{tab_id}】点击【{css_selector}】 {'成功' if click_success else '失败'}"
265
+ # else:
266
+ # message = f"tab页:【{tab_id}】传入的css_selector找到了{len(target_eles)}个元素,请确保传入的css_selector可以找到唯一的一个元素"
260
267
  return dp_mcp_message_pack(
261
268
  message=message,
262
269
  browser_port=browser_port,
@@ -313,10 +320,11 @@ def register_get_screenshot(mcp: FastMCP, browser_manager):
313
320
  async def get_tab_screenshot(browser_port: int, tab_id: str) -> dict[str, Any]:
314
321
  _browser = browser_manager.get_browser(browser_port)
315
322
  target_tab = _browser.get_tab(tab_id)
323
+ target_tab.wait.doc_loaded()
316
324
  if not os.path.exists(html_source_code_local_save_path):
317
325
  os.makedirs(html_source_code_local_save_path)
318
326
  timestamp = int(time.time() * 1000)
319
- time.sleep(3)
327
+ # time.sleep(1)
320
328
  origin_png = target_tab.get_screenshot(as_bytes="png")
321
329
  compress_png = compress_image_bytes(origin_png)
322
330
  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.5"
3
+ version = "0.1.11.7"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
@@ -140,7 +140,10 @@ def check_data_packet(packet: DataPacket, client: DPProxyClient):
140
140
  data = packet.request.postData
141
141
  domain = urlparse(url).netloc
142
142
  body = packet.response.body
143
- body_str = json.dumps(body, ensure_ascii=False, separators=(',', ':'))
143
+ if isinstance(body, dict):
144
+ body_str = json.dumps(body, ensure_ascii=False, separators=(',', ':'))
145
+ else:
146
+ body_str = str(body)
144
147
  body_str_list = [body_str[i:i + one_turn_max_token] for i in range(0, len(body_str), one_turn_max_token)]
145
148
  body_completed = True
146
149
  packet_filter = client.packet_filter
@@ -155,9 +158,9 @@ def check_data_packet(packet: DataPacket, client: DPProxyClient):
155
158
  continue
156
159
  if (index + 1) != len(body_str_list):
157
160
  body_completed = False
158
- if packet.response:
161
+ try:
159
162
  response_headers = packet.response.headers
160
- else:
163
+ except TypeError:
161
164
  response_headers = {}
162
165
  temp_dict = {
163
166
  "url": url,
@@ -172,17 +175,3 @@ def check_data_packet(packet: DataPacket, client: DPProxyClient):
172
175
 
173
176
 
174
177
  client_manager = DPProxyClientManager()
175
-
176
- # if __name__ == '__main__':
177
- # co = ChromiumOptions().set_user_agent(
178
- # "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")
179
- # tab = ChromiumPage(co).latest_tab
180
- # client = DPProxyClient(tab, self_kill=False)
181
- # # client = CaptchaClient(tab, self_kill=True)
182
- # tab = client.get_driver(True)
183
- # url = "https://api.toutiaoapi.com/feoffline/hotspot_and_local/html/hot_list/index.html?client_extra_params=%7B%22custom_log_pb%22%3A%22%7B%5C%22style_id%5C%22%3A%5C%2240030%5C%22%2C%5C%22entrance_hotspot%5C%22%3A%5C%22search%5C%22%2C%5C%22location%5C%22%3A%5C%22hot_board%5C%22%2C%5C%22category_name%5C%22%3A%5C%22hotboard_light%5C%22%7D%22%7D&count=50&log_pb=%7B%22style_id%22%3A%2240030%22%2C%22entrance_hotspot%22%3A%22search%22%2C%22location%22%3A%22hot_board%22%2C%22category_name%22%3A%22hotboard_light%22%7D&only_hot_list=1&tab_name=stream&enter_keyword=%23%E7%BE%8E%E5%9B%BD%E9%80%80%E5%87%BA66%E4%B8%AA%E5%9B%BD%E9%99%85%E7%BB%84%E7%BB%87%23"
184
- # tab.get(url)
185
- # for _ in range(5056):
186
- # new_packet = client.pop_first_packet()
187
- # print(new_packet, "23")
188
- # time.sleep(1)
File without changes