simplex 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of simplex might be problematic. Click here for more details.

simplex/simplex.py CHANGED
@@ -1,42 +1,35 @@
1
- from playwright.sync_api import Page, sync_playwright
1
+ from playwright.sync_api import Page, sync_playwright, Browser
2
2
  from PIL import Image
3
3
  import requests
4
4
  from typing import List
5
5
  import io
6
+ import time
6
7
 
7
8
  from .utils import center_bbox, screenshot_to_image
8
9
 
9
10
  BASE_URL = "https://u3mvtbirxf.us-east-1.awsapprunner.com"
10
11
 
11
12
  class Simplex:
12
- def __init__(self, api_key: str, driver: Page = None):
13
+ def __init__(self, api_key: str, browser: Browser = None):
13
14
  """
14
15
  Initialize Simplex instance
15
16
 
16
17
  Args:
17
18
  api_key (str): API key for authentication
18
- driver (playwright.sync_api.Page, optional): Playwright page object. If not provided,
19
- a new headless browser instance will be created.
19
+ browser (optional): Browser instance (for Hyperbrowser integration)
20
20
  """
21
21
  self.api_key = api_key
22
+ self.browser = browser
22
23
 
23
- if driver is None:
24
+ if browser is None:
24
25
  self.playwright = sync_playwright().start()
25
26
  self.browser = self.playwright.chromium.launch(headless=True)
26
- self.driver = self.browser.new_page()
27
27
  else:
28
- self.driver = driver
29
- self.browser = None
30
28
  self.playwright = None
29
+
30
+ self.driver = self.browser.new_page(viewport={"width": 1280, "height": 720})
31
31
 
32
- def __del__(self):
33
- """Cleanup Playwright resources"""
34
- if self.browser:
35
- self.browser.close()
36
- if self.playwright:
37
- self.playwright.stop()
38
-
39
- def find_element(self, element_description: str, state: Image.Image | None = None) -> List[int]:
32
+ def find_element(self, element_description: str, state: Image.Image | None = None, annotate: bool = False) -> List[int]:
40
33
  """
41
34
  Find an element in the screenshot using the element description
42
35
 
@@ -69,11 +62,41 @@ class Simplex:
69
62
  files=files
70
63
  )
71
64
 
65
+
72
66
  # Print the results
73
67
  print(f"Status Code: {response.status_code}")
74
68
  if response.status_code == 200:
75
69
  res = response.json()
76
70
  bbox = [int(res['x1']), int(res['y1']), int(res['x2']), int(res['y2'])]
71
+
72
+ # Add overlay directly to the page if driver exists
73
+ if hasattr(self, 'driver') and annotate:
74
+ # Create and inject overlay element
75
+ self.driver.evaluate("""
76
+ (bbox) => {
77
+ // Remove any existing overlay
78
+ const existingOverlay = document.getElementById('simplex-bbox-overlay');
79
+ if (existingOverlay) {
80
+ existingOverlay.remove();
81
+ }
82
+
83
+ // Create new overlay
84
+ const overlay = document.createElement('div');
85
+ overlay.id = 'simplex-bbox-overlay';
86
+ overlay.style.position = 'absolute';
87
+ overlay.style.border = '2px solid red';
88
+ overlay.style.left = bbox[0] + 'px';
89
+ overlay.style.top = bbox[1] + 'px';
90
+ overlay.style.width = (bbox[2] - bbox[0]) + 'px';
91
+ overlay.style.height = (bbox[3] - bbox[1]) + 'px';
92
+ overlay.style.pointerEvents = 'none';
93
+ overlay.style.zIndex = '10000';
94
+
95
+ document.body.appendChild(overlay);
96
+ }
97
+ """, bbox)
98
+ self.driver.wait_for_selector('#simplex-bbox-overlay')
99
+ time.sleep(5)
77
100
  return bbox
78
101
  else:
79
102
  print("Error:", response.text)
@@ -130,7 +153,7 @@ class Simplex:
130
153
  """
131
154
  self.driver.goto(url)
132
155
 
133
- def execute_action(self, action: List[List[str]], state: Image.Image | None = None) -> None:
156
+ def execute_action(self, action: List[List[str]], state: Image.Image | None = None, annotate: bool = False) -> None:
134
157
  """
135
158
  Execute an action with playwright driver
136
159
 
@@ -143,12 +166,12 @@ class Simplex:
143
166
 
144
167
  try:
145
168
  if action_type == "CLICK":
146
- bbox = self.find_element(description, state)
169
+ bbox = self.find_element(description, state, annotate)
147
170
  center_x, center_y = center_bbox(bbox)
148
171
  self.driver.mouse.click(center_x, center_y)
149
172
 
150
173
  elif action_type == "HOVER":
151
- bbox = self.find_element(description, state)
174
+ bbox = self.find_element(description, state, annotate)
152
175
  center_x, center_y = center_bbox(bbox)
153
176
  self.driver.mouse.move(center_x, center_y)
154
177
 
@@ -165,14 +188,14 @@ class Simplex:
165
188
  print(f"Error executing action: {e}")
166
189
  return None
167
190
 
168
- def do(self, step_description: str) -> None:
191
+ def do(self, step_description: str, annotate: bool = False) -> None:
169
192
  """
170
193
  Execute a step description
171
194
  """
172
195
  state = self.take_stable_screenshot()
173
196
  actions = self.step_to_action(step_description, state)
174
197
  for action in actions:
175
- self.execute_action(action)
198
+ self.execute_action(action, annotate)
176
199
 
177
200
  def take_stable_screenshot(self) -> Image.Image:
178
201
  """
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: simplex
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: Official Python SDK for Simplex API
5
5
  Home-page: https://github.com/shreyka/simplex-python
6
6
  Author: Simplex Labs, Inc.
@@ -21,6 +21,15 @@ Requires-Dist: rich>=13.0.0
21
21
  Requires-Dist: prompt_toolkit>=3.0.0
22
22
  Requires-Dist: playwright>=1.0.0
23
23
  Requires-Dist: Pillow>=9.0.0
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: requires-dist
31
+ Dynamic: requires-python
32
+ Dynamic: summary
24
33
 
25
34
  # Simplex AI Python SDK
26
35
 
@@ -0,0 +1,10 @@
1
+ simplex/__init__.py,sha256=1mbM4XUk0FNW161WOkM4ayC1s_QSsaBEls6PZ0iBScY,74
2
+ simplex/constants.py,sha256=nIXF2oVNNNknXweXAlmE-KBM9QjJtYw9osXVYjvloN0,59
3
+ simplex/simplex.py,sha256=27knVLuna8Aab_7km_40v6SDTLfMO8jl8d-qWR21amA,7551
4
+ simplex/utils.py,sha256=UrD4Ena3yk0POmxxyiqMszzPbTscTCJpMP4xZFDAuOc,339
5
+ simplex-1.1.0.dist-info/LICENSE,sha256=Xh0SJjYZfNI71pCNMB40aKlBLLuOB0blx5xkTtufFNQ,1075
6
+ simplex-1.1.0.dist-info/METADATA,sha256=BOck5V3dhKJbVd47mhX5BEwVVGieODpcQRxBbJuQy9o,1114
7
+ simplex-1.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ simplex-1.1.0.dist-info/entry_points.txt,sha256=3veL2w3c5vxb3dm8I_M8Fs-370n1ZnvD8uu1nSsL7z8,45
9
+ simplex-1.1.0.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
10
+ simplex-1.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.7.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- simplex/__init__.py,sha256=1mbM4XUk0FNW161WOkM4ayC1s_QSsaBEls6PZ0iBScY,74
2
- simplex/constants.py,sha256=nIXF2oVNNNknXweXAlmE-KBM9QjJtYw9osXVYjvloN0,59
3
- simplex/simplex.py,sha256=p3dGJFdyQReW2qHX-yFn9Vi6Bm8-QJ_x6RK66s1KkM8,6246
4
- simplex/utils.py,sha256=UrD4Ena3yk0POmxxyiqMszzPbTscTCJpMP4xZFDAuOc,339
5
- simplex-1.0.0.dist-info/LICENSE,sha256=Xh0SJjYZfNI71pCNMB40aKlBLLuOB0blx5xkTtufFNQ,1075
6
- simplex-1.0.0.dist-info/METADATA,sha256=4BL_hKn_yaVMoCpGSsUxTdVwwb2trncuwu7QyEFyE_M,917
7
- simplex-1.0.0.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
8
- simplex-1.0.0.dist-info/entry_points.txt,sha256=3veL2w3c5vxb3dm8I_M8Fs-370n1ZnvD8uu1nSsL7z8,45
9
- simplex-1.0.0.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
10
- simplex-1.0.0.dist-info/RECORD,,