dialoghelper 0.0.24__py3-none-any.whl → 0.0.25__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 CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.24"
1
+ __version__ = "0.0.25"
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._load_screenshot_js': ( 'experimental.html#_load_screenshot_js',
31
- 'dialoghelper/experimental.py'),
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',
@@ -3,95 +3,75 @@
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
9
  from importlib import resources
10
10
  import uuid
11
11
  from fasthtml.common import Div, Script
12
- from time import sleep
13
- import base64
14
12
  import json
15
- import time
16
13
  from claudette import ToolResult
17
14
  from .core import *
18
- from dataclasses import dataclass
19
- from httpx import get as xget, post as xpost
15
+ from httpx import post as xpost
20
16
 
21
17
  # %% ../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
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)
58
25
 
59
26
  # %% ../nbs/01_experimental.ipynb
60
27
  def iife(code: str) -> str:
61
- "Wrap javascript code string in an IIFE"
62
- return f'''
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, 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")
67
50
 
68
51
  # %% ../nbs/01_experimental.ipynb
69
52
  _screen_share_active = False
70
53
 
71
- def start_screen_share(timeout=30, retry_interval=1):
54
+ def start_screen_share(timeout=45):
72
55
  "Start persistent screen sharing session, waiting for confirmation."
73
56
  global _screen_share_active
74
- _load_screenshot_js()
57
+ load_screenshot_js()
75
58
  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'))
59
+ iife(f'startPersistentScreenShare("{status_id}");')
78
60
  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.")
61
+ data = _pop_data(status_id, timeout, condition=lambda d: d.get('js_status') == 'ready', fail_msg="Screen share failed.")
81
62
  js_status = data.get('js_status')
82
63
  if js_status == 'ready':
83
64
  _screen_share_active = True
84
65
  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.")
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.")
87
68
 
88
69
  # %% ../nbs/01_experimental.ipynb
89
70
  def stop_screen_share():
90
71
  "Stop persistent screen sharing session."
91
72
  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'))
73
+ load_screenshot_js()
74
+ iife('stopPersistentScreenShare();')
95
75
  _screen_share_active = False
96
76
  print("Screen share stopped.")
97
77
 
@@ -99,17 +79,15 @@ def stop_screen_share():
99
79
  def capture_screen():
100
80
  "Capture screenshot, automatically starting screen share if needed."
101
81
  global _screen_share_active
102
- _load_screenshot_js()
82
+ load_screenshot_js()
103
83
  if not _screen_share_active:
104
84
  print("🔄 No active screen share, starting one...")
105
85
  result = start_screen_share()
106
- if not _screen_share_active: return f"Failed to start screen share: {result}"
86
+ if not _screen_share_active: raise RuntimeError(f"Failed to start screen share: {result}")
107
87
  data_id = str(uuid.uuid4())
108
88
  screenshot_code = f'captureScreenFromStream("{data_id}");'
109
89
  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']}"
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']}")
115
93
  return ToolResult(data=data['img_data'], result_type=data['img_type'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.24
3
+ Version: 0.0.25
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -0,0 +1,11 @@
1
+ dialoghelper/__init__.py,sha256=vci5ju5-NTu05zsCK_eWhxXQOgjqapCa_vPXTExikTk,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=7kUcsYRMd30A1QSE1chyGgnREFrvCmmT5ZJM9Pg5oQY,3964
6
+ dialoghelper-0.0.25.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ dialoghelper-0.0.25.dist-info/METADATA,sha256=42RGQrioWi2XXlxOpkertpqcej7rPG3AgeCgNyvuqps,2590
8
+ dialoghelper-0.0.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ dialoghelper-0.0.25.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
10
+ dialoghelper-0.0.25.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
11
+ dialoghelper-0.0.25.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,,