dialoghelper 0.0.28__py3-none-any.whl → 0.0.30__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.28"
1
+ __version__ = "0.0.30"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -12,6 +12,7 @@ d = { 'settings': { 'branch': 'main',
12
12
  'dialoghelper.core.call_endp': ('core.html#call_endp', 'dialoghelper/core.py'),
13
13
  'dialoghelper.core.curr_dialog': ('core.html#curr_dialog', 'dialoghelper/core.py'),
14
14
  'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
15
+ 'dialoghelper.core.find_dname': ('core.html#find_dname', 'dialoghelper/core.py'),
15
16
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
16
17
  'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
17
18
  'dialoghelper.core.find_var': ('core.html#find_var', 'dialoghelper/core.py'),
dialoghelper/core.py CHANGED
@@ -1,9 +1,9 @@
1
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
2
2
 
3
3
  # %% auto 0
4
- __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'curr_dialog', 'find_msgs', 'find_msg_id', 'msg_idx', 'read_msg',
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']
4
+ __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'find_dname', 'find_msg_id', 'curr_dialog', 'find_msgs', 'msg_idx',
5
+ 'read_msg', 'add_html', 'del_msg', 'run_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file',
6
+ 'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
9
  import json, importlib, linecache
@@ -37,74 +37,90 @@ def find_var(var:str):
37
37
  raise ValueError(f"Could not find {var} in any scope")
38
38
 
39
39
  # %% ../nbs/00_core.ipynb
40
- def call_endp(path, json=False, raiseex=False, **data):
40
+ def call_endp(path, dname='', json=False, raiseex=False, **data):
41
+ if not dname: dname = find_dname()
42
+ data['dlg_name'] = dname
41
43
  res = xpost(f'http://localhost:5001/{path}', data=data)
42
44
  if raiseex: res.raise_for_status()
43
- return res.json() if json else res.text
45
+ try: return res.json() if json else res.text
46
+ except Exception as e: return str(e)
47
+
48
+ # %% ../nbs/00_core.ipynb
49
+ def find_dname():
50
+ "Get the message id by searching the call stack for __dialog_id."
51
+ return find_var('__dialog_name')
52
+
53
+ # %% ../nbs/00_core.ipynb
54
+ def find_msg_id():
55
+ "Get the message id by searching the call stack for __dialog_id."
56
+ return find_var('__msg_id')
44
57
 
45
58
  # %% ../nbs/00_core.ipynb
46
59
  def curr_dialog(
47
- with_messages:bool=False # Include messages as well?
60
+ with_messages:bool=False, # Include messages as well?
61
+ dname:str='' # Running dialog to get info for; defaults to current dialog
48
62
  ):
49
63
  "Get the current dialog info."
50
- return call_endp('curr_dialog_', json=True, with_messages=with_messages)
64
+ res = call_endp('curr_dialog_', dname, json=True, with_messages=with_messages)
65
+ if res: return {'name': res['name'], 'mode': res['mode']}
51
66
 
52
67
  # %% ../nbs/00_core.ipynb
53
68
  def find_msgs(
54
69
  re_pattern:str='', # Optional regex to search for (re.DOTALL+re.MULTILINE is used)
55
70
  msg_type:str=None, # optional limit by message type ('code', 'note', or 'prompt')
56
71
  limit:int=None, # Optionally limit number of returned items
57
- include_output:bool=True # Include output in returned dict?
72
+ include_output:bool=True, # Include output in returned dict?
73
+ dname:str='' # Running dialog to get info for; defaults to current dialog
58
74
  ):
59
75
  "Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `id` field."
60
- res = call_endp('find_msgs_', json=True, re_pattern=re_pattern, msg_type=msg_type, limit=limit)['msgs']
76
+ res = call_endp('find_msgs_', dname, json=True, re_pattern=re_pattern, msg_type=msg_type, limit=limit)['msgs']
61
77
  if not include_output:
62
78
  for o in res: o.pop('output', None)
63
79
  return res
64
80
 
65
- # %% ../nbs/00_core.ipynb
66
- def find_msg_id():
67
- "Get the message id by searching the call stack for __dialog_id."
68
- return find_var('__msg_id')
69
-
70
81
  # %% ../nbs/00_core.ipynb
71
82
  def msg_idx(
72
83
  msgid=None, # Message id to find (defaults to current message)
84
+ dname:str='' # Running dialog to get info for; defaults to current dialog
73
85
  ):
74
86
  "Get absolute index of message in dialog."
75
87
  if not msgid: msgid = find_msg_id()
76
- return call_endp('msg_idx_', json=True, msgid=msgid)['msgid']
88
+ return call_endp('msg_idx_', dname, json=True, msgid=msgid)['msgid']
77
89
 
78
90
  # %% ../nbs/00_core.ipynb
79
91
  def read_msg(
80
92
  n:int=-1, # Message index (if relative, +ve is downwards)
81
93
  msgid=None, # Message id to find (defaults to current message)
82
- relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
94
+ relative:bool=True, # Is `n` relative to current message (True) or absolute (False)?
95
+ dname:str='' # Running dialog to get info for; defaults to current dialog
83
96
  ):
84
97
  "Get the `Message` object indexed in the current dialog."
85
98
  if not msgid: msgid = find_msg_id()
86
- return call_endp('read_msg_', json=True, msgid=msgid, n=n, relative=relative)['msg']
99
+ return call_endp('read_msg_', dname, json=True, msgid=msgid, n=n, relative=relative)['msg']
87
100
 
88
101
  # %% ../nbs/00_core.ipynb
89
102
  def add_html(
90
103
  content:str, # The HTML to send to the client (generally should include hx-swap-oob)
104
+ dname:str='' # Running dialog to get info for; defaults to current dialog
91
105
  ):
92
106
  "Send HTML to the browser to be swapped into the DOM"
93
- call_endp('add_html_', content=to_xml(content))
107
+ call_endp('add_html_', dname, content=to_xml(content))
94
108
 
95
109
  # %% ../nbs/00_core.ipynb
96
110
  def del_msg(
97
111
  msgid:str=None, # id of message to delete
112
+ dname:str='' # Running dialog to get info for; defaults to current dialog
98
113
  ):
99
114
  "Delete a message from the dialog."
100
- call_endp('rm_msg_', raiseex=True, msid=msgid)
115
+ call_endp('rm_msg_', dname, raiseex=True, msid=msgid)
101
116
 
102
117
  # %% ../nbs/00_core.ipynb
103
118
  def run_msg(
104
119
  msgid:str=None, # id of message to execute
120
+ dname:str='' # Running dialog to get info for; defaults to current dialog
105
121
  ):
106
122
  "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)
123
+ return call_endp('add_runq_', dname, msgid=msgid, api=True)
108
124
 
109
125
  # %% ../nbs/00_core.ipynb
110
126
  Placements = str_enum('Placements', 'add_after', 'add_before', 'at_start', 'at_end')
@@ -123,11 +139,12 @@ def add_msg(
123
139
  o_collapsed: int | None = 0, # Collapse output?
124
140
  heading_collapsed: int | None = 0, # Collapse heading section?
125
141
  pinned: int | None = 0, # Pin to context?
142
+ dname:str='' # Running dialog to get info for; defaults to current dialog
126
143
  ):
127
144
  "Add/update a message to the queue to show after code execution completes."
128
145
  if placement not in ('at_start','at_end') and not msgid: msgid = find_msg_id()
129
146
  return call_endp(
130
- 'add_relative_', content=content, placement=placement, msgid=msgid, msg_type=msg_type, output=output,
147
+ 'add_relative_', dname, content=content, placement=placement, msgid=msgid, msg_type=msg_type, output=output,
131
148
  time_run=time_run, is_exported=is_exported, skipped=skipped, pinned=pinned,
132
149
  i_collapsed=i_collapsed, o_collapsed=o_collapsed, heading_collapsed=heading_collapsed)
133
150
 
@@ -143,8 +160,9 @@ def _add_msg_unsafe(
143
160
  """Add/update a message to the queue to show after code execution completes, and optionally run it. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change).
144
161
  *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
145
162
  if placement not in ('at_start','at_end') and not msgid: msgid = find_msg_id()
163
+ dname = kwargs.pop('dname')
146
164
  return call_endp(
147
- 'add_relative_', content=content, placement=placement, msgid=msgid, run=run, **kwargs)
165
+ 'add_relative_', dname, content=content, placement=placement, msgid=msgid, run=run, **kwargs)
148
166
 
149
167
  # %% ../nbs/00_core.ipynb
150
168
  def _umsg(
@@ -165,12 +183,13 @@ def _umsg(
165
183
  def update_msg(
166
184
  msgid:str=None, # id of message to update (if None, uses current message)
167
185
  msg:Optional[Dict]=None, # Dictionary of field keys/values to update
186
+ dname:str='', # Running dialog to get info for; defaults to current dialog
168
187
  **kwargs):
169
188
  """Update an existing message. Provide either `msg` OR field key/values to update.
170
189
  Use `content` param to update contents.
171
190
  Only include parameters to update--missing ones will be left unchanged."""
172
191
  if not msgid and not msg: raise TypeError("update_msg needs either a dict message or `msgid=`")
173
- return call_endp('add_relative_', placement='update', msgid=msgid, **kwargs)
192
+ return call_endp('add_relative_', dname, placement='update', msgid=msgid, **kwargs)
174
193
 
175
194
  # %% ../nbs/00_core.ipynb
176
195
  def load_gist(gist_id:str):
@@ -6,22 +6,22 @@
6
6
  __all__ = ['iife', 'load_screenshot_js', 'start_screen_share', 'stop_screen_share', 'capture_screen']
7
7
 
8
8
  # %% ../nbs/01_experimental.ipynb
9
+ import uuid,json
9
10
  from importlib import resources
10
- import uuid
11
- from fasthtml.common import Div, Script
12
- import json
11
+ from fasthtml.common import Div,Script
13
12
  from claudette import ToolResult
14
13
  from .core import *
15
14
  from httpx import post as xpost
16
15
 
17
16
  # %% ../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)
17
+ def _pop_data(data_id, timeout=20):
18
+ params = {'data_id': data_id, 'timeout':timeout}
19
+ result = xpost('http://localhost:5001/pop_data_blocking_', data=params, timeout=timeout+1)
20
+ if result.status_code==200 and result.text.strip():
21
+ if (data := result.json()): return data
22
+ # except json.JSONDecodeError as e: print(f"JSON decode error: {e}")
23
+ raise RuntimeError("No data received")
24
+ raise RuntimeError(result.status_code)
25
25
 
26
26
  # %% ../nbs/01_experimental.ipynb
27
27
  def iife(code: str) -> str:
@@ -40,13 +40,14 @@ def load_screenshot_js(force=False, timeout=5):
40
40
  "Load screenshot capability and wait for confirmation it's ready."
41
41
  global _js_loaded
42
42
  if _js_loaded and not force: return
43
- print("Loading screenshot.js ...")
43
+ # print("Loading screenshot.js ...")
44
44
  status_id = str(uuid.uuid4())
45
- js_content = (resources.files('dialoghelper') / 'screenshot.js').read_text()
45
+ js_content = (resources.files('dialoghelper')/'screenshot.js').read_text()
46
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.")
47
+ data = _pop_data(status_id, timeout)
48
+ if (stat:=data.get('js_status'))!='ready': raise RuntimeError(f"Failed to load screenshot.js: {stat}")
48
49
  _js_loaded = True
49
- print("Screenshot.js loaded and ready")
50
+ # print("Screenshot.js loaded and ready")
50
51
 
51
52
  # %% ../nbs/01_experimental.ipynb
52
53
  _screen_share_active = False
@@ -57,23 +58,23 @@ def start_screen_share(timeout=45):
57
58
  load_screenshot_js()
58
59
  status_id = str(uuid.uuid4())
59
60
  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.")
61
+ # print("Requesting screen share permission ...")
62
+ data = _pop_data(status_id, timeout)
62
63
  js_status = data.get('js_status')
63
- if js_status == 'ready':
64
+ if js_status=='ready':
64
65
  _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.")
66
+ # print("Screen share started successfully.")
67
+ elif js_status=='error': raise RuntimeError(f"Screen share failed: {data.get('error', 'Unknown error')}")
68
+ elif js_status=='connecting': raise RuntimeError("Screen share timed out after {timeout} seconds.")
68
69
 
69
70
  # %% ../nbs/01_experimental.ipynb
70
71
  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.")
72
+ "Stop persistent screen sharing session."
73
+ global _screen_share_active
74
+ load_screenshot_js()
75
+ iife('stopPersistentScreenShare();')
76
+ _screen_share_active = False
77
+ # print("Screen share stopped.")
77
78
 
78
79
  # %% ../nbs/01_experimental.ipynb
79
80
  def capture_screen():
@@ -81,13 +82,15 @@ def capture_screen():
81
82
  global _screen_share_active
82
83
  load_screenshot_js()
83
84
  if not _screen_share_active:
84
- print("🔄 No active screen share, starting one...")
85
+ # print("🔄 No active screen share, starting one...")
85
86
  result = start_screen_share()
86
87
  if not _screen_share_active: raise RuntimeError(f"Failed to start screen share: {result}")
87
88
  data_id = str(uuid.uuid4())
88
89
  screenshot_code = f'captureScreenFromStream("{data_id}");'
89
- print("📸 Capturing from persistent stream...")
90
+ # print("📸 Capturing from persistent stream...")
90
91
  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
+ data = _pop_data(data_id, timeout=45)
92
93
  if 'error' in data: raise RuntimeError(f"Screenshot failed: {data['error']}")
94
+ if not ('img_data' in data and 'img_type' in data):
95
+ raise RuntimeError("Screenshot capture failed, failed to retrieve data.")
93
96
  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.28
3
+ Version: 0.0.30
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,12 @@
1
+ dialoghelper/__init__.py,sha256=Y4J_58Un2NkktVq246vbfUB1fr9alL7LxlQNIsZE5ec,43
2
+ dialoghelper/_modidx.py,sha256=Au4FWcKVoSRyKPwVeiqCCKTL8cZ2vGPnjgk4FQfMlyg,4273
3
+ dialoghelper/core.py,sha256=c7wGjFYucWTCDfOYGex3QX728elUdqGR34FfxsspvsA,12319
4
+ dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
+ dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
6
+ dialoghelper/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
+ dialoghelper-0.0.30.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ dialoghelper-0.0.30.dist-info/METADATA,sha256=PhB6_-rVkKRmbPunN35xi7qJpZ1HeS7BQkjOXCGQpcY,2637
9
+ dialoghelper-0.0.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ dialoghelper-0.0.30.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
+ dialoghelper-0.0.30.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
+ dialoghelper-0.0.30.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- dialoghelper/__init__.py,sha256=8HrOWQMlI7GHrSa28WqtbTcHFu77JS0jXiRiXl5fL54,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/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
- dialoghelper-0.0.28.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- dialoghelper-0.0.28.dist-info/METADATA,sha256=z0v8195A4JF4fADbNVe7JYR3J8fo6NDmYcbpwAqumec,2637
9
- dialoghelper-0.0.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- dialoghelper-0.0.28.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
- dialoghelper-0.0.28.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
- dialoghelper-0.0.28.dist-info/RECORD,,