dialoghelper 0.0.23__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.

Files changed (22) hide show
  1. {dialoghelper-0.0.23/dialoghelper.egg-info → dialoghelper-0.0.25}/PKG-INFO +1 -1
  2. dialoghelper-0.0.25/dialoghelper/__init__.py +2 -0
  3. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper/_modidx.py +10 -4
  4. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper/core.py +12 -4
  5. dialoghelper-0.0.25/dialoghelper/experimental.py +93 -0
  6. {dialoghelper-0.0.23 → dialoghelper-0.0.25/dialoghelper.egg-info}/PKG-INFO +1 -1
  7. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/settings.ini +3 -3
  8. dialoghelper-0.0.23/dialoghelper/__init__.py +0 -2
  9. dialoghelper-0.0.23/dialoghelper/experimental.py +0 -68
  10. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/LICENSE +0 -0
  11. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/MANIFEST.in +0 -0
  12. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/README.md +0 -0
  13. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper/db_dc.py +0 -0
  14. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/SOURCES.txt +0 -0
  15. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/dependency_links.txt +0 -0
  16. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/entry_points.txt +0 -0
  17. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/not-zip-safe +0 -0
  18. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/requires.txt +0 -0
  19. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/dialoghelper.egg-info/top_level.txt +0 -0
  20. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/pyproject.toml +0 -0
  21. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/setup.cfg +0 -0
  22. {dialoghelper-0.0.23 → dialoghelper-0.0.25}/setup.py +0 -0
@@ -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,2 @@
1
+ __version__ = "0.0.25"
2
+ from .core import *
@@ -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')}}}
@@ -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.
@@ -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,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
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = dialoghelper
3
3
  lib_name = dialoghelper
4
- version = 0.0.23
4
+ version = 0.0.25
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -30,8 +30,8 @@ language = English
30
30
  status = 3
31
31
  user = AnswerDotAI
32
32
  readme_nb = index.ipynb
33
- allowed_metadata_keys =
34
- allowed_cell_metadata_keys =
33
+ allowed_metadata_keys = solveit_dialog_mode solveit_ver
34
+ allowed_cell_metadata_keys = skipped pinned solveit_ai
35
35
  jupyter_hooks = False
36
36
  clean_ids = True
37
37
  clear_all = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.23"
2
- from .core import *
@@ -1,68 +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__ = ['create_iife', '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
- _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
34
-
35
- # %% ../nbs/01_experimental.ipynb
36
- def create_iife(code: str) -> str:
37
- "Wrap javascript code string in an IIFE"
38
- return f'''
39
- (async () => {{
40
- {code}
41
- }})();
42
- '''
43
-
44
- # %% ../nbs/01_experimental.ipynb
45
- 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"
File without changes
File without changes
File without changes
File without changes
File without changes