dialoghelper 0.0.22__tar.gz → 0.0.24__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.22/dialoghelper.egg-info → dialoghelper-0.0.24}/PKG-INFO +1 -1
  2. dialoghelper-0.0.24/dialoghelper/__init__.py +2 -0
  3. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper/_modidx.py +8 -2
  4. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper/core.py +12 -4
  5. dialoghelper-0.0.24/dialoghelper/experimental.py +115 -0
  6. {dialoghelper-0.0.22 → dialoghelper-0.0.24/dialoghelper.egg-info}/PKG-INFO +1 -1
  7. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/settings.ini +3 -3
  8. dialoghelper-0.0.22/dialoghelper/__init__.py +0 -2
  9. dialoghelper-0.0.22/dialoghelper/experimental.py +0 -68
  10. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/LICENSE +0 -0
  11. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/MANIFEST.in +0 -0
  12. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/README.md +0 -0
  13. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper/db_dc.py +0 -0
  14. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/SOURCES.txt +0 -0
  15. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/dependency_links.txt +0 -0
  16. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/entry_points.txt +0 -0
  17. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/not-zip-safe +0 -0
  18. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/requires.txt +0 -0
  19. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/dialoghelper.egg-info/top_level.txt +0 -0
  20. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/pyproject.toml +0 -0
  21. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/setup.cfg +0 -0
  22. {dialoghelper-0.0.22 → dialoghelper-0.0.24}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.22
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,2 @@
1
+ __version__ = "0.0.24"
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
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')}}}
@@ -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,115 @@
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'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.22
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
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = dialoghelper
3
3
  lib_name = dialoghelper
4
- version = 0.0.22
4
+ version = 0.0.24
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.22"
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