dialoghelper 0.0.23__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.23"
1
+ __version__ = "0.0.25"
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
- 'dialoghelper.experimental': { 'dialoghelper.experimental._load_screenshot_js': ( 'experimental.html#_load_screenshot_js',
30
- 'dialoghelper/experimental.py'),
30
+ 'dialoghelper.experimental': { 'dialoghelper.experimental._pop_data': ( 'experimental.html#_pop_data',
31
+ 'dialoghelper/experimental.py'),
31
32
  'dialoghelper.experimental.capture_screen': ( 'experimental.html#capture_screen',
32
33
  'dialoghelper/experimental.py'),
33
- 'dialoghelper.experimental.create_iife': ( 'experimental.html#create_iife',
34
- 'dialoghelper/experimental.py')}}}
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
+ '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,66 +3,91 @@
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', '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
- _js_loaded = False
23
-
24
- def _load_screenshot_js():
25
- "Load screenshot capability if not already present."
26
- global _js_loaded
27
- if _js_loaded:
28
- print("screenshot.js already loaded")
29
- return
30
- 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
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)
34
25
 
35
26
  # %% ../nbs/01_experimental.ipynb
36
- def create_iife(code: str) -> str:
37
- "Wrap javascript code string in an IIFE"
38
- return f'''
27
+ def iife(code: str) -> str:
28
+ "Wrap javascript code string in an IIFE and execute it via `add_html`"
29
+ trigger_script = f'''
39
30
  (async () => {{
40
31
  {code}
41
32
  }})();
42
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.")
43
77
 
44
78
  # %% ../nbs/01_experimental.ipynb
45
79
  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)
51
- 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"
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.23
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=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,,