dialoghelper 0.0.26__tar.gz → 0.0.27__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.
Potentially problematic release.
This version of dialoghelper might be problematic. Click here for more details.
- {dialoghelper-0.0.26/dialoghelper.egg-info → dialoghelper-0.0.27}/PKG-INFO +1 -1
- dialoghelper-0.0.27/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper/experimental.py +29 -32
- {dialoghelper-0.0.26 → dialoghelper-0.0.27/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/settings.ini +1 -1
- dialoghelper-0.0.26/dialoghelper/__init__.py +0 -2
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/LICENSE +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/MANIFEST.in +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/README.md +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper/_modidx.py +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper/core.py +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper/db_dc.py +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/pyproject.toml +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/setup.cfg +0 -0
- {dialoghelper-0.0.26 → dialoghelper-0.0.27}/setup.py +0 -0
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
__all__ = ['iife', 'load_screenshot_js', 'start_screen_share', 'stop_screen_share', 'capture_screen']
|
|
7
7
|
|
|
8
8
|
# %% ../nbs/01_experimental.ipynb
|
|
9
|
-
import uuid,json
|
|
10
9
|
from importlib import resources
|
|
11
|
-
|
|
10
|
+
import uuid
|
|
11
|
+
from fasthtml.common import Div, Script
|
|
12
|
+
import json
|
|
12
13
|
from claudette import ToolResult
|
|
13
14
|
from .core import *
|
|
14
15
|
from httpx import post as xpost
|
|
15
16
|
|
|
16
17
|
# %% ../nbs/01_experimental.ipynb
|
|
17
|
-
def _pop_data(data_id, timeout=20):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (data := result.json()): return data
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
raise RuntimeError(result.status_code)
|
|
18
|
+
def _pop_data(data_id, timeout=20, condition=None, fail_msg = "`_pop_data` failed to return a value."):
|
|
19
|
+
result = xpost('http://localhost:5001/pop_data_blocking_', data={'data_id': data_id}, timeout=timeout)
|
|
20
|
+
if result.status_code == 200 and result.text.strip():
|
|
21
|
+
try:
|
|
22
|
+
if (data := result.json()) and (not condition or condition(data)): return data
|
|
23
|
+
except json.JSONDecodeError as e: print(f"JSON decode error: {e}")
|
|
24
|
+
raise RuntimeError(fail_msg)
|
|
25
25
|
|
|
26
26
|
# %% ../nbs/01_experimental.ipynb
|
|
27
27
|
def iife(code: str) -> str:
|
|
@@ -40,14 +40,13 @@ def load_screenshot_js(force=False, timeout=5):
|
|
|
40
40
|
"Load screenshot capability and wait for confirmation it's ready."
|
|
41
41
|
global _js_loaded
|
|
42
42
|
if _js_loaded and not force: return
|
|
43
|
-
|
|
43
|
+
print("Loading screenshot.js ...")
|
|
44
44
|
status_id = str(uuid.uuid4())
|
|
45
|
-
js_content = (resources.files('dialoghelper')/'screenshot.js').read_text()
|
|
45
|
+
js_content = (resources.files('dialoghelper') / 'screenshot.js').read_text()
|
|
46
46
|
iife(js_content + f'sendDataToServer("{status_id}", {{"js_status": "ready"}});')
|
|
47
|
-
data = _pop_data(status_id, timeout)
|
|
48
|
-
if (stat:=data.get('js_status'))!='ready': raise RuntimeError(f"Failed to load screenshot.js: {stat}")
|
|
47
|
+
data = _pop_data(status_id, timeout, condition=lambda d: d.get('js_status') == 'ready', fail_msg="Failed to load screenshot.js.")
|
|
49
48
|
_js_loaded = True
|
|
50
|
-
|
|
49
|
+
print("Screenshot.js loaded and ready")
|
|
51
50
|
|
|
52
51
|
# %% ../nbs/01_experimental.ipynb
|
|
53
52
|
_screen_share_active = False
|
|
@@ -58,23 +57,23 @@ def start_screen_share(timeout=45):
|
|
|
58
57
|
load_screenshot_js()
|
|
59
58
|
status_id = str(uuid.uuid4())
|
|
60
59
|
iife(f'startPersistentScreenShare("{status_id}");')
|
|
61
|
-
|
|
62
|
-
data = _pop_data(status_id, timeout)
|
|
60
|
+
print("Requesting screen share permission ...")
|
|
61
|
+
data = _pop_data(status_id, timeout, condition=lambda d: d.get('js_status') == 'ready', fail_msg="Screen share failed.")
|
|
63
62
|
js_status = data.get('js_status')
|
|
64
|
-
if js_status=='ready':
|
|
63
|
+
if js_status == 'ready':
|
|
65
64
|
_screen_share_active = True
|
|
66
|
-
|
|
67
|
-
elif js_status=='error': raise RuntimeError(f"Screen share failed: {data.get('error', 'Unknown error')}")
|
|
68
|
-
elif js_status=='connecting': raise RuntimeError("Screen share timed out after {timeout} seconds.")
|
|
65
|
+
print("Screen share started successfully.")
|
|
66
|
+
elif js_status == 'error': raise RuntimeError(f"Screen share failed: {data.get('error', 'Unknown error')}")
|
|
67
|
+
elif js_status == 'connecting': raise RuntimeError("Screen share timed out after {timeout} seconds.")
|
|
69
68
|
|
|
70
69
|
# %% ../nbs/01_experimental.ipynb
|
|
71
70
|
def stop_screen_share():
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
"Stop persistent screen sharing session."
|
|
72
|
+
global _screen_share_active
|
|
73
|
+
load_screenshot_js()
|
|
74
|
+
iife('stopPersistentScreenShare();')
|
|
75
|
+
_screen_share_active = False
|
|
76
|
+
print("Screen share stopped.")
|
|
78
77
|
|
|
79
78
|
# %% ../nbs/01_experimental.ipynb
|
|
80
79
|
def capture_screen():
|
|
@@ -82,15 +81,13 @@ def capture_screen():
|
|
|
82
81
|
global _screen_share_active
|
|
83
82
|
load_screenshot_js()
|
|
84
83
|
if not _screen_share_active:
|
|
85
|
-
|
|
84
|
+
print("🔄 No active screen share, starting one...")
|
|
86
85
|
result = start_screen_share()
|
|
87
86
|
if not _screen_share_active: raise RuntimeError(f"Failed to start screen share: {result}")
|
|
88
87
|
data_id = str(uuid.uuid4())
|
|
89
88
|
screenshot_code = f'captureScreenFromStream("{data_id}");'
|
|
90
|
-
|
|
89
|
+
print("📸 Capturing from persistent stream...")
|
|
91
90
|
iife(screenshot_code)
|
|
92
|
-
data = _pop_data(data_id, timeout=
|
|
91
|
+
data = _pop_data(data_id, timeout=5, condition=lambda d: 'img_data' in d and 'img_type' in d, fail_msg="Screenshot capture failed, failed to retrieve data.")
|
|
93
92
|
if 'error' in data: raise RuntimeError(f"Screenshot failed: {data['error']}")
|
|
94
|
-
if not ('img_data' in data and 'img_type' in data):
|
|
95
|
-
raise RuntimeError("Screenshot capture failed, failed to retrieve data.")
|
|
96
93
|
return ToolResult(data=data['img_data'], result_type=data['img_type'])
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|