dialoghelper 0.0.23__py3-none-any.whl → 0.0.24__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.23"
1
+ __version__ = "0.0.24"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -23,12 +23,18 @@ d = { 'settings': { 'branch': 'main',
23
23
  'dialoghelper.core.mk_toollist': ('core.html#mk_toollist', 'dialoghelper/core.py'),
24
24
  'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
25
25
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
26
+ 'dialoghelper.core.run_msg': ('core.html#run_msg', 'dialoghelper/core.py'),
26
27
  'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
27
28
  'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
28
29
  'dialoghelper.db_dc': {},
29
30
  'dialoghelper.experimental': { 'dialoghelper.experimental._load_screenshot_js': ( 'experimental.html#_load_screenshot_js',
30
31
  'dialoghelper/experimental.py'),
32
+ 'dialoghelper.experimental._wait_for_pop_data': ( 'experimental.html#_wait_for_pop_data',
33
+ 'dialoghelper/experimental.py'),
31
34
  'dialoghelper.experimental.capture_screen': ( 'experimental.html#capture_screen',
32
35
  'dialoghelper/experimental.py'),
33
- 'dialoghelper.experimental.create_iife': ( 'experimental.html#create_iife',
34
- 'dialoghelper/experimental.py')}}}
36
+ 'dialoghelper.experimental.iife': ('experimental.html#iife', 'dialoghelper/experimental.py'),
37
+ 'dialoghelper.experimental.start_screen_share': ( 'experimental.html#start_screen_share',
38
+ 'dialoghelper/experimental.py'),
39
+ 'dialoghelper.experimental.stop_screen_share': ( 'experimental.html#stop_screen_share',
40
+ 'dialoghelper/experimental.py')}}}
dialoghelper/core.py CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  # %% auto 0
4
4
  __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'curr_dialog', 'find_msgs', 'find_msg_id', 'msg_idx', 'read_msg',
5
- 'add_html', 'del_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
6
- 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
5
+ 'add_html', 'del_msg', 'run_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string',
6
+ 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
9
  import json, importlib, linecache
@@ -94,11 +94,18 @@ def add_html(
94
94
 
95
95
  # %% ../nbs/00_core.ipynb
96
96
  def del_msg(
97
- msgid:str=None, # id of message that placement is relative to (if None, uses current message)
97
+ msgid:str=None, # id of message to delete
98
98
  ):
99
- "Delete a message from the dialog. Be sure to pass a `sid`, not a `mid`."
99
+ "Delete a message from the dialog."
100
100
  call_endp('rm_msg_', raiseex=True, msid=msgid)
101
101
 
102
+ # %% ../nbs/00_core.ipynb
103
+ def run_msg(
104
+ msgid:str=None, # id of message to execute
105
+ ):
106
+ "Adds a message to the run queue. Use read_msg to see the output once it runs."
107
+ return call_endp('add_runq_', msgid=msgid, api=True)
108
+
102
109
  # %% ../nbs/00_core.ipynb
103
110
  Placements = str_enum('Placements', 'add_after', 'add_before', 'at_start', 'at_end')
104
111
 
@@ -240,6 +247,7 @@ def tool_info():
240
247
  - &`add_html`: Send HTML to the browser to be swapped into the DOM using hx-swap-oob.
241
248
  - &`find_msg_id`: Get the current message id.
242
249
  - &`find_msgs`: Find messages in current specific dialog that contain the given information.
250
+ - (solveit can often get this id directly from its context, and will not need to use this if the required information is already available to it.)
243
251
  - &`read_msg`: Get the message indexed in the current dialog.
244
252
  - &`del_msg`: Delete a message from the dialog.
245
253
  - &`add_msg`: Add/update a message to the queue to show after code execution completes.
@@ -3,7 +3,7 @@
3
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_experimental.ipynb.
4
4
 
5
5
  # %% auto 0
6
- __all__ = ['create_iife', 'capture_screen']
6
+ __all__ = ['iife', 'start_screen_share', 'stop_screen_share', 'capture_screen']
7
7
 
8
8
  # %% ../nbs/01_experimental.ipynb
9
9
  from importlib import resources
@@ -18,22 +18,46 @@ from .core import *
18
18
  from dataclasses import dataclass
19
19
  from httpx import get as xget, post as xpost
20
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
+
21
38
  # %% ../nbs/01_experimental.ipynb
22
39
  _js_loaded = False
23
40
 
24
- def _load_screenshot_js():
25
- "Load screenshot capability if not already present."
41
+ def _load_screenshot_js(timeout=10, retry_interval=1):
42
+ "Load screenshot capability and wait for confirmation it's ready."
26
43
  global _js_loaded
27
- if _js_loaded:
28
- print("screenshot.js already loaded")
29
- return
44
+ if _js_loaded: return True
30
45
  js_content = (resources.files('dialoghelper') / 'screenshot.js').read_text()
31
- add_html(Div(Script(js_content), hx_swap_oob='beforeend:#js-script'))
32
- print("Added screenshot.js")
33
- _js_loaded = True
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
34
58
 
35
59
  # %% ../nbs/01_experimental.ipynb
36
- def create_iife(code: str) -> str:
60
+ def iife(code: str) -> str:
37
61
  "Wrap javascript code string in an IIFE"
38
62
  return f'''
39
63
  (async () => {{
@@ -41,28 +65,51 @@ def create_iife(code: str) -> str:
41
65
  }})();
42
66
  '''
43
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
+
44
98
  # %% ../nbs/01_experimental.ipynb
45
99
  def capture_screen():
46
- "Capture current desktop returning the screenshot as a ToolImageResult."
47
- _load_screenshot_js()
48
- data_id = str(uuid.uuid4()) # Generate random ID for data communication
49
- screenshot_code = f'captureScreenAndUpload("{data_id}");'
50
- trigger_script = create_iife(screenshot_code)
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)
51
111
  add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
52
- max_attempts = 50
53
- for attempt in range(max_attempts):
54
- result = xpost('http://localhost:5001/pop_data_', data={'data_id': data_id})
55
- if result.status_code == 200:
56
- try:
57
- if not result.text.strip():
58
- time.sleep(0.5)
59
- continue
60
- data = result.json() # data is a dict
61
- if 'error' in data: return f"Screenshot failed: {data['error']}"
62
- if 'img_data' in data and 'img_type' in data:
63
- return ToolResult(data=data['img_data'], result_type=data['img_type'])
64
- return f"Screenshot data incomplete: {data}"
65
- except json.JSONDecodeError as e: print(f"JSON decode error: {e}, Raw text: '{result.text}'")
66
- except Exception as e: print(f"Error processing screenshot data: {e}")
67
- time.sleep(0.5)
68
- return "Screenshot capture timed out"
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'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.23
3
+ Version: 0.0.24
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=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,,
@@ -1,11 +0,0 @@
1
- dialoghelper/__init__.py,sha256=AqD8emlypM0LZM9Km2Wj1qvaXCNpm0U46JDDXPEy5d8,43
2
- dialoghelper/_modidx.py,sha256=dqZjsj-FkFgiTcIeiCB7rSCpUzStGILPMqC0NRt4jO4,3402
3
- dialoghelper/core.py,sha256=3zWfyFZPDkzHVIh2sjI4PESpezXhOKMnWNqOJ1zXXBA,10859
4
- dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
- dialoghelper/experimental.py,sha256=6tDnbY3JBA8MLdzMZ18uCHnT5BapgzH61sGxfUt8HQ8,2459
6
- dialoghelper-0.0.23.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
- dialoghelper-0.0.23.dist-info/METADATA,sha256=wQW5EBgPIq4cQbqNn7EqZ2Qm8nv4VxgAwUUEXvwRnbk,2590
8
- dialoghelper-0.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- dialoghelper-0.0.23.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
10
- dialoghelper-0.0.23.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
11
- dialoghelper-0.0.23.dist-info/RECORD,,