dialoghelper 0.0.24__tar.gz → 0.0.25__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.24/dialoghelper.egg-info → dialoghelper-0.0.25}/PKG-INFO +1 -1
- dialoghelper-0.0.25/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper/_modidx.py +4 -4
- dialoghelper-0.0.25/dialoghelper/experimental.py +93 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/settings.ini +1 -1
- dialoghelper-0.0.24/dialoghelper/__init__.py +0 -2
- dialoghelper-0.0.24/dialoghelper/experimental.py +0 -115
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/LICENSE +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/MANIFEST.in +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/README.md +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper/core.py +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper/db_dc.py +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/pyproject.toml +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/setup.cfg +0 -0
- {dialoghelper-0.0.24 → dialoghelper-0.0.25}/setup.py +0 -0
|
@@ -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',
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Experimental `dialoghelper` capabilities."""
|
|
2
|
+
|
|
3
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_experimental.ipynb.
|
|
4
|
+
|
|
5
|
+
# %% auto 0
|
|
6
|
+
__all__ = ['iife', 'load_screenshot_js', 'start_screen_share', 'stop_screen_share', 'capture_screen']
|
|
7
|
+
|
|
8
|
+
# %% ../nbs/01_experimental.ipynb
|
|
9
|
+
from importlib import resources
|
|
10
|
+
import uuid
|
|
11
|
+
from fasthtml.common import Div, Script
|
|
12
|
+
import json
|
|
13
|
+
from claudette import ToolResult
|
|
14
|
+
from .core import *
|
|
15
|
+
from httpx import post as xpost
|
|
16
|
+
|
|
17
|
+
# %% ../nbs/01_experimental.ipynb
|
|
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
|
+
|
|
26
|
+
# %% ../nbs/01_experimental.ipynb
|
|
27
|
+
def iife(code: str) -> str:
|
|
28
|
+
"Wrap javascript code string in an IIFE and execute it via `add_html`"
|
|
29
|
+
trigger_script = f'''
|
|
30
|
+
(async () => {{
|
|
31
|
+
{code}
|
|
32
|
+
}})();
|
|
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, condition=lambda d: d.get('js_status') == 'ready', fail_msg="Failed to load screenshot.js.")
|
|
48
|
+
_js_loaded = True
|
|
49
|
+
print("Screenshot.js loaded and ready")
|
|
50
|
+
|
|
51
|
+
# %% ../nbs/01_experimental.ipynb
|
|
52
|
+
_screen_share_active = False
|
|
53
|
+
|
|
54
|
+
def start_screen_share(timeout=45):
|
|
55
|
+
"Start persistent screen sharing session, waiting for confirmation."
|
|
56
|
+
global _screen_share_active
|
|
57
|
+
load_screenshot_js()
|
|
58
|
+
status_id = str(uuid.uuid4())
|
|
59
|
+
iife(f'startPersistentScreenShare("{status_id}");')
|
|
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.")
|
|
62
|
+
js_status = data.get('js_status')
|
|
63
|
+
if js_status == 'ready':
|
|
64
|
+
_screen_share_active = True
|
|
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.")
|
|
68
|
+
|
|
69
|
+
# %% ../nbs/01_experimental.ipynb
|
|
70
|
+
def stop_screen_share():
|
|
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.")
|
|
77
|
+
|
|
78
|
+
# %% ../nbs/01_experimental.ipynb
|
|
79
|
+
def capture_screen():
|
|
80
|
+
"Capture screenshot, automatically starting screen share if needed."
|
|
81
|
+
global _screen_share_active
|
|
82
|
+
load_screenshot_js()
|
|
83
|
+
if not _screen_share_active:
|
|
84
|
+
print("🔄 No active screen share, starting one...")
|
|
85
|
+
result = start_screen_share()
|
|
86
|
+
if not _screen_share_active: raise RuntimeError(f"Failed to start screen share: {result}")
|
|
87
|
+
data_id = str(uuid.uuid4())
|
|
88
|
+
screenshot_code = f'captureScreenFromStream("{data_id}");'
|
|
89
|
+
print("📸 Capturing from persistent stream...")
|
|
90
|
+
iife(screenshot_code)
|
|
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.")
|
|
92
|
+
if 'error' in data: raise RuntimeError(f"Screenshot failed: {data['error']}")
|
|
93
|
+
return ToolResult(data=data['img_data'], result_type=data['img_type'])
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"""Experimental `dialoghelper` capabilities."""
|
|
2
|
-
|
|
3
|
-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_experimental.ipynb.
|
|
4
|
-
|
|
5
|
-
# %% auto 0
|
|
6
|
-
__all__ = ['iife', 'start_screen_share', 'stop_screen_share', 'capture_screen']
|
|
7
|
-
|
|
8
|
-
# %% ../nbs/01_experimental.ipynb
|
|
9
|
-
from importlib import resources
|
|
10
|
-
import uuid
|
|
11
|
-
from fasthtml.common import Div, Script
|
|
12
|
-
from time import sleep
|
|
13
|
-
import base64
|
|
14
|
-
import json
|
|
15
|
-
import time
|
|
16
|
-
from claudette import ToolResult
|
|
17
|
-
from .core import *
|
|
18
|
-
from dataclasses import dataclass
|
|
19
|
-
from httpx import get as xget, post as xpost
|
|
20
|
-
|
|
21
|
-
# %% ../nbs/01_experimental.ipynb
|
|
22
|
-
def _wait_for_pop_data(data_id, timeout=20, retry_interval=1, condition=None):
|
|
23
|
-
"Wait for data from pop endpoint with optional condition validation."
|
|
24
|
-
max_attempts = int(timeout / retry_interval)
|
|
25
|
-
for attempt in range(max_attempts):
|
|
26
|
-
result = xpost('http://localhost:5001/pop_data_', data={'data_id': data_id})
|
|
27
|
-
if result.status_code == 200 and result.text.strip():
|
|
28
|
-
try:
|
|
29
|
-
data = result.json()
|
|
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
|
|
58
|
-
|
|
59
|
-
# %% ../nbs/01_experimental.ipynb
|
|
60
|
-
def iife(code: str) -> str:
|
|
61
|
-
"Wrap javascript code string in an IIFE"
|
|
62
|
-
return f'''
|
|
63
|
-
(async () => {{
|
|
64
|
-
{code}
|
|
65
|
-
}})();
|
|
66
|
-
'''
|
|
67
|
-
|
|
68
|
-
# %% ../nbs/01_experimental.ipynb
|
|
69
|
-
_screen_share_active = False
|
|
70
|
-
|
|
71
|
-
def start_screen_share(timeout=30, retry_interval=1):
|
|
72
|
-
"Start persistent screen sharing session, waiting for confirmation."
|
|
73
|
-
global _screen_share_active
|
|
74
|
-
_load_screenshot_js()
|
|
75
|
-
status_id = str(uuid.uuid4())
|
|
76
|
-
trigger_script = iife(f'startPersistentScreenShare("{status_id}");')
|
|
77
|
-
add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
|
|
78
|
-
print("Requesting screen share permission ...")
|
|
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.")
|
|
81
|
-
js_status = data.get('js_status')
|
|
82
|
-
if js_status == 'ready':
|
|
83
|
-
_screen_share_active = True
|
|
84
|
-
print("Screen share started successfully.")
|
|
85
|
-
elif js_status == 'error': print(f"Screen share failed: {data.get('error', 'Unknown error')}")
|
|
86
|
-
elif js_status == 'connecting': print("Screen share timed out after {timeout} seconds.")
|
|
87
|
-
|
|
88
|
-
# %% ../nbs/01_experimental.ipynb
|
|
89
|
-
def stop_screen_share():
|
|
90
|
-
"Stop persistent screen sharing session."
|
|
91
|
-
global _screen_share_active
|
|
92
|
-
_load_screenshot_js()
|
|
93
|
-
trigger_script = iife('stopPersistentScreenShare();')
|
|
94
|
-
add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
|
|
95
|
-
_screen_share_active = False
|
|
96
|
-
print("Screen share stopped.")
|
|
97
|
-
|
|
98
|
-
# %% ../nbs/01_experimental.ipynb
|
|
99
|
-
def capture_screen():
|
|
100
|
-
"Capture screenshot, automatically starting screen share if needed."
|
|
101
|
-
global _screen_share_active
|
|
102
|
-
_load_screenshot_js()
|
|
103
|
-
if not _screen_share_active:
|
|
104
|
-
print("🔄 No active screen share, starting one...")
|
|
105
|
-
result = start_screen_share()
|
|
106
|
-
if not _screen_share_active: return f"Failed to start screen share: {result}"
|
|
107
|
-
data_id = str(uuid.uuid4())
|
|
108
|
-
screenshot_code = f'captureScreenFromStream("{data_id}");'
|
|
109
|
-
print("📸 Capturing from persistent stream...")
|
|
110
|
-
trigger_script = iife(screenshot_code)
|
|
111
|
-
add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
|
|
112
|
-
data = _wait_for_pop_data(data_id, timeout=10, retry_interval=1, condition=lambda d: 'img_data' in d and 'img_type' in d)
|
|
113
|
-
if not data: return "Screenshot capture timed out"
|
|
114
|
-
if 'error' in data: return f"Screenshot failed: {data['error']}"
|
|
115
|
-
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
|