dialoghelper 0.0.24__py3-none-any.whl → 0.0.26__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 dialoghelper might be problematic. Click here for more details.
- dialoghelper/__init__.py +1 -1
- dialoghelper/_modidx.py +4 -4
- dialoghelper/experimental.py +55 -74
- {dialoghelper-0.0.24.dist-info → dialoghelper-0.0.26.dist-info}/METADATA +1 -1
- dialoghelper-0.0.26.dist-info/RECORD +11 -0
- dialoghelper-0.0.24.dist-info/RECORD +0 -11
- {dialoghelper-0.0.24.dist-info → dialoghelper-0.0.26.dist-info}/WHEEL +0 -0
- {dialoghelper-0.0.24.dist-info → dialoghelper-0.0.26.dist-info}/entry_points.txt +0 -0
- {dialoghelper-0.0.24.dist-info → dialoghelper-0.0.26.dist-info}/licenses/LICENSE +0 -0
- {dialoghelper-0.0.24.dist-info → dialoghelper-0.0.26.dist-info}/top_level.txt +0 -0
dialoghelper/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.26"
|
|
2
2
|
from .core import *
|
dialoghelper/_modidx.py
CHANGED
|
@@ -27,13 +27,13 @@ d = { 'settings': { 'branch': 'main',
|
|
|
27
27
|
'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
|
|
28
28
|
'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
|
|
29
29
|
'dialoghelper.db_dc': {},
|
|
30
|
-
'dialoghelper.experimental': { 'dialoghelper.experimental.
|
|
31
|
-
|
|
32
|
-
'dialoghelper.experimental._wait_for_pop_data': ( 'experimental.html#_wait_for_pop_data',
|
|
33
|
-
'dialoghelper/experimental.py'),
|
|
30
|
+
'dialoghelper.experimental': { 'dialoghelper.experimental._pop_data': ( 'experimental.html#_pop_data',
|
|
31
|
+
'dialoghelper/experimental.py'),
|
|
34
32
|
'dialoghelper.experimental.capture_screen': ( 'experimental.html#capture_screen',
|
|
35
33
|
'dialoghelper/experimental.py'),
|
|
36
34
|
'dialoghelper.experimental.iife': ('experimental.html#iife', 'dialoghelper/experimental.py'),
|
|
35
|
+
'dialoghelper.experimental.load_screenshot_js': ( 'experimental.html#load_screenshot_js',
|
|
36
|
+
'dialoghelper/experimental.py'),
|
|
37
37
|
'dialoghelper.experimental.start_screen_share': ( 'experimental.html#start_screen_share',
|
|
38
38
|
'dialoghelper/experimental.py'),
|
|
39
39
|
'dialoghelper.experimental.stop_screen_share': ( 'experimental.html#stop_screen_share',
|
dialoghelper/experimental.py
CHANGED
|
@@ -3,113 +3,94 @@
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_experimental.ipynb.
|
|
4
4
|
|
|
5
5
|
# %% auto 0
|
|
6
|
-
__all__ = ['iife', 'start_screen_share', 'stop_screen_share', 'capture_screen']
|
|
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
|
|
9
10
|
from importlib import resources
|
|
10
|
-
import
|
|
11
|
-
from fasthtml.common import Div, Script
|
|
12
|
-
from time import sleep
|
|
13
|
-
import base64
|
|
14
|
-
import json
|
|
15
|
-
import time
|
|
11
|
+
from fasthtml.common import Div,Script
|
|
16
12
|
from claudette import ToolResult
|
|
17
13
|
from .core import *
|
|
18
|
-
from
|
|
19
|
-
from httpx import get as xget, post as xpost
|
|
14
|
+
from httpx import post as xpost
|
|
20
15
|
|
|
21
16
|
# %% ../nbs/01_experimental.ipynb
|
|
22
|
-
def
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if condition and not condition(data):
|
|
31
|
-
time.sleep(retry_interval)
|
|
32
|
-
continue
|
|
33
|
-
return data
|
|
34
|
-
except json.JSONDecodeError: pass
|
|
35
|
-
time.sleep(retry_interval)
|
|
36
|
-
return None
|
|
37
|
-
|
|
38
|
-
# %% ../nbs/01_experimental.ipynb
|
|
39
|
-
_js_loaded = False
|
|
40
|
-
|
|
41
|
-
def _load_screenshot_js(timeout=10, retry_interval=1):
|
|
42
|
-
"Load screenshot capability and wait for confirmation it's ready."
|
|
43
|
-
global _js_loaded
|
|
44
|
-
if _js_loaded: return True
|
|
45
|
-
js_content = (resources.files('dialoghelper') / 'screenshot.js').read_text()
|
|
46
|
-
ready_id = str(uuid.uuid4())
|
|
47
|
-
js_with_ready = js_content + f'\n\n// Signal ready\nsendDataToServer("{ready_id}", {{"js_status": "ready"}});'
|
|
48
|
-
add_html(Div(Script(js_with_ready), hx_swap_oob='beforeend:#js-script'))
|
|
49
|
-
print("Loading screenshot.js ...")
|
|
50
|
-
data = _wait_for_pop_data(ready_id, timeout, retry_interval, condition=lambda d: d.get('js_status') == 'ready')
|
|
51
|
-
if data and data.get('js_status') == 'ready':
|
|
52
|
-
_js_loaded = True
|
|
53
|
-
print("Screenshot.js loaded and ready")
|
|
54
|
-
return True
|
|
55
|
-
else:
|
|
56
|
-
print("Failed to load screenshot.js")
|
|
57
|
-
return False
|
|
17
|
+
def _pop_data(data_id, timeout=20):
|
|
18
|
+
params = {'data_id': data_id, 'timeout':timeout}
|
|
19
|
+
result = xpost('http://localhost:5001/pop_data_blocking_', data=params, timeout=timeout+1)
|
|
20
|
+
if result.status_code==200 and result.text.strip():
|
|
21
|
+
if (data := result.json()): return data
|
|
22
|
+
# except json.JSONDecodeError as e: print(f"JSON decode error: {e}")
|
|
23
|
+
raise RuntimeError("No data received")
|
|
24
|
+
raise RuntimeError(result.status_code)
|
|
58
25
|
|
|
59
26
|
# %% ../nbs/01_experimental.ipynb
|
|
60
27
|
def iife(code: str) -> str:
|
|
61
|
-
"Wrap javascript code string in an IIFE"
|
|
62
|
-
|
|
28
|
+
"Wrap javascript code string in an IIFE and execute it via `add_html`"
|
|
29
|
+
trigger_script = f'''
|
|
63
30
|
(async () => {{
|
|
64
31
|
{code}
|
|
65
32
|
}})();
|
|
66
33
|
'''
|
|
34
|
+
add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
|
|
35
|
+
|
|
36
|
+
# %% ../nbs/01_experimental.ipynb
|
|
37
|
+
_js_loaded = False
|
|
38
|
+
|
|
39
|
+
def load_screenshot_js(force=False, timeout=5):
|
|
40
|
+
"Load screenshot capability and wait for confirmation it's ready."
|
|
41
|
+
global _js_loaded
|
|
42
|
+
if _js_loaded and not force: return
|
|
43
|
+
# print("Loading screenshot.js ...")
|
|
44
|
+
status_id = str(uuid.uuid4())
|
|
45
|
+
js_content = (resources.files('dialoghelper')/'screenshot.js').read_text()
|
|
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}")
|
|
49
|
+
_js_loaded = True
|
|
50
|
+
# print("Screenshot.js loaded and ready")
|
|
67
51
|
|
|
68
52
|
# %% ../nbs/01_experimental.ipynb
|
|
69
53
|
_screen_share_active = False
|
|
70
54
|
|
|
71
|
-
def start_screen_share(timeout=
|
|
55
|
+
def start_screen_share(timeout=45):
|
|
72
56
|
"Start persistent screen sharing session, waiting for confirmation."
|
|
73
57
|
global _screen_share_active
|
|
74
|
-
|
|
58
|
+
load_screenshot_js()
|
|
75
59
|
status_id = str(uuid.uuid4())
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
data = _wait_for_pop_data(status_id, timeout, retry_interval, condition=lambda d: d.get('js_status') == 'ready')
|
|
80
|
-
if not data: print(f"Screen share timed out after {timeout} seconds.")
|
|
60
|
+
iife(f'startPersistentScreenShare("{status_id}");')
|
|
61
|
+
# print("Requesting screen share permission ...")
|
|
62
|
+
data = _pop_data(status_id, timeout)
|
|
81
63
|
js_status = data.get('js_status')
|
|
82
|
-
if js_status
|
|
64
|
+
if js_status=='ready':
|
|
83
65
|
_screen_share_active = True
|
|
84
|
-
|
|
85
|
-
elif js_status
|
|
86
|
-
elif js_status
|
|
66
|
+
# print("Screen share started successfully.")
|
|
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.")
|
|
87
69
|
|
|
88
70
|
# %% ../nbs/01_experimental.ipynb
|
|
89
71
|
def stop_screen_share():
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
print("Screen share stopped.")
|
|
72
|
+
"Stop persistent screen sharing session."
|
|
73
|
+
global _screen_share_active
|
|
74
|
+
load_screenshot_js()
|
|
75
|
+
iife('stopPersistentScreenShare();')
|
|
76
|
+
_screen_share_active = False
|
|
77
|
+
# print("Screen share stopped.")
|
|
97
78
|
|
|
98
79
|
# %% ../nbs/01_experimental.ipynb
|
|
99
80
|
def capture_screen():
|
|
100
81
|
"Capture screenshot, automatically starting screen share if needed."
|
|
101
82
|
global _screen_share_active
|
|
102
|
-
|
|
83
|
+
load_screenshot_js()
|
|
103
84
|
if not _screen_share_active:
|
|
104
|
-
|
|
85
|
+
# print("🔄 No active screen share, starting one...")
|
|
105
86
|
result = start_screen_share()
|
|
106
|
-
if not _screen_share_active:
|
|
87
|
+
if not _screen_share_active: raise RuntimeError(f"Failed to start screen share: {result}")
|
|
107
88
|
data_id = str(uuid.uuid4())
|
|
108
89
|
screenshot_code = f'captureScreenFromStream("{data_id}");'
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if not data
|
|
114
|
-
|
|
90
|
+
# print("📸 Capturing from persistent stream...")
|
|
91
|
+
iife(screenshot_code)
|
|
92
|
+
data = _pop_data(data_id, timeout=45)
|
|
93
|
+
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.")
|
|
115
96
|
return ToolResult(data=data['img_data'], result_type=data['img_type'])
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
dialoghelper/__init__.py,sha256=T5uV0maF9yfgQ1UV0AAqQ9nk841BFYnEyutwUBFl41Q,43
|
|
2
|
+
dialoghelper/_modidx.py,sha256=haFiPtlNF3j0tsHG-ODfyiy85H1OTbbdjR3ojhP6K4U,4156
|
|
3
|
+
dialoghelper/core.py,sha256=U9FvC8ZR6-v7X_PoP-D2etYrZX_Agzed5xpyNFL6a-8,11160
|
|
4
|
+
dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
|
|
5
|
+
dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
|
|
6
|
+
dialoghelper-0.0.26.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
+
dialoghelper-0.0.26.dist-info/METADATA,sha256=wcsDAH-8E684pnHy9qxcxGY-A48558PeOerTkk0bus8,2590
|
|
8
|
+
dialoghelper-0.0.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
dialoghelper-0.0.26.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
|
|
10
|
+
dialoghelper-0.0.26.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
|
|
11
|
+
dialoghelper-0.0.26.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
dialoghelper/__init__.py,sha256=XceGW5BBYEHXaLYMK7w89BsJFYgkMux1YgdeR7Odp4A,43
|
|
2
|
-
dialoghelper/_modidx.py,sha256=agYQ9ims3OEGqX9xZZMHvnFP35Ks-tyqJ4yHAwbe7-M,4186
|
|
3
|
-
dialoghelper/core.py,sha256=U9FvC8ZR6-v7X_PoP-D2etYrZX_Agzed5xpyNFL6a-8,11160
|
|
4
|
-
dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
|
|
5
|
-
dialoghelper/experimental.py,sha256=cCH1ndJgj7cM6m5-074d7cJ0kFnjkPJPLO3E19Nquvs,4728
|
|
6
|
-
dialoghelper-0.0.24.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
-
dialoghelper-0.0.24.dist-info/METADATA,sha256=KAaLJ0bJXWsMvZ_GnYgJ-9VvCmczMeKGfQShaAKL2Mk,2590
|
|
8
|
-
dialoghelper-0.0.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
dialoghelper-0.0.24.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
|
|
10
|
-
dialoghelper-0.0.24.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
|
|
11
|
-
dialoghelper-0.0.24.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|