mito-ai 0.1.46__py3-none-any.whl → 0.1.49__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.
- mito_ai/_version.py +1 -1
- mito_ai/app_deploy/app_deploy_utils.py +28 -9
- mito_ai/app_deploy/handlers.py +123 -84
- mito_ai/app_deploy/models.py +19 -12
- mito_ai/completions/models.py +6 -1
- mito_ai/completions/prompt_builders/agent_execution_prompt.py +13 -1
- mito_ai/completions/prompt_builders/agent_system_message.py +63 -4
- mito_ai/completions/prompt_builders/chat_system_message.py +4 -0
- mito_ai/completions/prompt_builders/prompt_constants.py +1 -0
- mito_ai/completions/prompt_builders/utils.py +13 -0
- mito_ai/path_utils.py +70 -0
- mito_ai/streamlit_conversion/agent_utils.py +4 -201
- mito_ai/streamlit_conversion/prompts/prompt_constants.py +142 -152
- mito_ai/streamlit_conversion/prompts/streamlit_error_correction_prompt.py +3 -3
- mito_ai/streamlit_conversion/prompts/streamlit_finish_todo_prompt.py +2 -2
- mito_ai/streamlit_conversion/prompts/update_existing_app_prompt.py +2 -2
- mito_ai/streamlit_conversion/search_replace_utils.py +94 -0
- mito_ai/streamlit_conversion/streamlit_agent_handler.py +35 -46
- mito_ai/streamlit_conversion/streamlit_utils.py +13 -75
- mito_ai/streamlit_conversion/validate_streamlit_app.py +6 -21
- mito_ai/streamlit_preview/__init__.py +1 -2
- mito_ai/streamlit_preview/handlers.py +54 -85
- mito_ai/streamlit_preview/manager.py +11 -18
- mito_ai/streamlit_preview/utils.py +12 -28
- mito_ai/tests/deploy_app/test_app_deploy_utils.py +22 -4
- mito_ai/tests/message_history/test_message_history_utils.py +3 -0
- mito_ai/tests/streamlit_conversion/test_apply_search_replace.py +240 -0
- mito_ai/tests/streamlit_conversion/test_streamlit_agent_handler.py +40 -60
- mito_ai/tests/streamlit_conversion/test_streamlit_utils.py +26 -29
- mito_ai/tests/streamlit_conversion/test_validate_streamlit_app.py +25 -20
- mito_ai/tests/streamlit_preview/test_streamlit_preview_handler.py +87 -57
- mito_ai/tests/streamlit_preview/test_streamlit_preview_manager.py +27 -40
- mito_ai/user/handlers.py +15 -3
- mito_ai/utils/create.py +17 -1
- mito_ai/utils/error_classes.py +42 -0
- mito_ai/utils/message_history_utils.py +3 -1
- mito_ai/utils/telemetry_utils.py +78 -13
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/build_log.json +100 -100
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/package.json +2 -2
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/package.json.orig +1 -1
- mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.20f12766ecd3d430568e.js → mito_ai-0.1.49.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.8f1845da6bf2b128c049.js +3571 -1442
- mito_ai-0.1.49.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.8f1845da6bf2b128c049.js.map +1 -0
- mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.54126ab6511271265443.js → mito_ai-0.1.49.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.8b24b5b3b93f95205b56.js +24 -24
- mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.54126ab6511271265443.js.map → mito_ai-0.1.49.data/data/share/jupyter/labextensions/mito_ai/static/remoteEntry.8b24b5b3b93f95205b56.js.map +1 -1
- {mito_ai-0.1.46.dist-info → mito_ai-0.1.49.dist-info}/METADATA +1 -1
- {mito_ai-0.1.46.dist-info → mito_ai-0.1.49.dist-info}/RECORD +71 -69
- mito_ai/tests/streamlit_conversion/test_apply_patch_to_text.py +0 -368
- mito_ai/tests/streamlit_conversion/test_fix_diff_headers.py +0 -533
- mito_ai-0.1.46.data/data/share/jupyter/labextensions/mito_ai/static/lib_index_js.20f12766ecd3d430568e.js.map +0 -1
- /mito_ai/streamlit_conversion/{streamlit_system_prompt.py → prompts/streamlit_system_prompt.py} +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/etc/jupyter/jupyter_server_config.d/mito_ai.json +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/schemas/mito_ai/toolbar-buttons.json +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/node_modules_process_browser_js.4b128e94d31a81ebd209.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/style.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/style_index_js.5876024bb17dbd6a3ee6.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_apis_signOut_mjs-node_module-75790d.688c25857e7b81b1740f.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_auth_dist_esm_providers_cognito_tokenProvider_tokenProvider_-72f1c8.a917210f057fcfe224ad.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_dist_esm_index_mjs.6bac1a8c4cc93f15f6b7.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_aws-amplify_ui-react_dist_esm_index_mjs.4fcecd65bef9e9847609.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_react-dom_client_js-node_modules_aws-amplify_ui-react_dist_styles_css.b43d4249e4d3dac9ad7b.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_semver_index_js.3f6754ac5116d47de76b.js.map +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js +0 -0
- {mito_ai-0.1.46.data → mito_ai-0.1.49.data}/data/share/jupyter/labextensions/mito_ai/static/vendors-node_modules_vscode-diff_dist_index_js.ea55f1f9346638aafbcf.js.map +0 -0
- {mito_ai-0.1.46.dist-info → mito_ai-0.1.49.dist-info}/WHEEL +0 -0
- {mito_ai-0.1.46.dist-info → mito_ai-0.1.49.dist-info}/entry_points.txt +0 -0
- {mito_ai-0.1.46.dist-info → mito_ai-0.1.49.dist-info}/licenses/LICENSE +0 -0
|
@@ -15,11 +15,8 @@ from typing import Any
|
|
|
15
15
|
|
|
16
16
|
from mito_ai.streamlit_preview.manager import (
|
|
17
17
|
StreamlitPreviewManager,
|
|
18
|
-
PreviewProcess
|
|
19
|
-
get_preview_manager
|
|
18
|
+
PreviewProcess
|
|
20
19
|
)
|
|
21
|
-
from mito_ai.streamlit_preview.handlers import StreamlitPreviewHandler
|
|
22
|
-
from mito_ai.streamlit_conversion.streamlit_utils import get_app_path
|
|
23
20
|
|
|
24
21
|
|
|
25
22
|
class TestStreamlitPreviewManager:
|
|
@@ -81,25 +78,22 @@ st.write("Hello, World!")
|
|
|
81
78
|
mock_requests_get.return_value = mock_response
|
|
82
79
|
|
|
83
80
|
# Test
|
|
84
|
-
|
|
81
|
+
port = manager.start_streamlit_preview(app_directory, 'test-file-name.py', preview_id)
|
|
85
82
|
|
|
86
83
|
# Assertions
|
|
87
|
-
assert
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
# Cleanup
|
|
102
|
-
manager.stop_preview(preview_id)
|
|
84
|
+
assert isinstance(port, int)
|
|
85
|
+
assert port > 0
|
|
86
|
+
|
|
87
|
+
# Verify subprocess was called correctly
|
|
88
|
+
mock_popen.assert_called_once()
|
|
89
|
+
call_args = mock_popen.call_args
|
|
90
|
+
assert "streamlit" in call_args[0][0]
|
|
91
|
+
assert "run" in call_args[0][0]
|
|
92
|
+
assert "--server.headless" in call_args[0][0]
|
|
93
|
+
assert "--server.address" in call_args[0][0]
|
|
94
|
+
|
|
95
|
+
# Cleanup
|
|
96
|
+
manager.stop_preview(preview_id)
|
|
103
97
|
|
|
104
98
|
@pytest.mark.parametrize("exception_type,expected_message", [
|
|
105
99
|
(Exception("Temp dir creation failed"), "failed to start preview"),
|
|
@@ -108,13 +102,15 @@ st.write("Hello, World!")
|
|
|
108
102
|
])
|
|
109
103
|
def test_start_streamlit_preview_exceptions(self, manager, sample_app_code, exception_type, expected_message):
|
|
110
104
|
"""Test streamlit preview start with different exceptions."""
|
|
111
|
-
|
|
105
|
+
from mito_ai.utils.error_classes import StreamlitPreviewError
|
|
106
|
+
|
|
107
|
+
with patch('subprocess.Popen', side_effect=exception_type):
|
|
112
108
|
app_directory = "/tmp/test_dir"
|
|
113
|
-
success, message, port = manager.start_streamlit_preview(app_directory, "test_preview")
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
with pytest.raises(StreamlitPreviewError) as exc_info:
|
|
111
|
+
manager.start_streamlit_preview(app_directory, 'test-file-name.py', "test_preview")
|
|
112
|
+
|
|
113
|
+
assert expected_message in str(exc_info.value).lower()
|
|
118
114
|
|
|
119
115
|
@pytest.mark.parametrize("preview_id,expected_result", [
|
|
120
116
|
("existing_preview", True),
|
|
@@ -146,7 +142,7 @@ st.write("Hello, World!")
|
|
|
146
142
|
mock_open.return_value.__enter__.return_value = mock_file
|
|
147
143
|
mock_exists.return_value = True
|
|
148
144
|
|
|
149
|
-
manager.start_streamlit_preview(app_directory, preview_id)
|
|
145
|
+
manager.start_streamlit_preview(app_directory, 'test-file-name.py', preview_id)
|
|
150
146
|
|
|
151
147
|
@pytest.mark.parametrize("process_behavior,expected_kill_called", [
|
|
152
148
|
(subprocess.TimeoutExpired("cmd", 5), True),
|
|
@@ -179,7 +175,7 @@ st.write("Hello, World!")
|
|
|
179
175
|
mock_exists.return_value = True
|
|
180
176
|
|
|
181
177
|
# Start a preview
|
|
182
|
-
manager.start_streamlit_preview(app_directory, "test_preview")
|
|
178
|
+
manager.start_streamlit_preview(app_directory, 'test-file-name.py', "test_preview")
|
|
183
179
|
|
|
184
180
|
# Setup process behavior for stop
|
|
185
181
|
if process_behavior:
|
|
@@ -219,7 +215,7 @@ st.write("Hello, World!")
|
|
|
219
215
|
mock_open.return_value.__enter__.return_value = mock_file
|
|
220
216
|
mock_exists.return_value = True
|
|
221
217
|
|
|
222
|
-
manager.start_streamlit_preview("/tmp/test_dir", preview_id)
|
|
218
|
+
manager.start_streamlit_preview("/tmp/test_dir", 'test-file-name.py', preview_id)
|
|
223
219
|
|
|
224
220
|
preview = manager.get_preview(preview_id)
|
|
225
221
|
|
|
@@ -245,15 +241,7 @@ st.write("Hello, World!")
|
|
|
245
241
|
|
|
246
242
|
assert preview.proc == proc
|
|
247
243
|
assert preview.port == port
|
|
248
|
-
|
|
249
|
-
def test_get_preview_manager_singleton(self):
|
|
250
|
-
"""Test that get_preview_manager returns the same instance."""
|
|
251
|
-
manager1 = get_preview_manager()
|
|
252
|
-
manager2 = get_preview_manager()
|
|
253
|
-
|
|
254
|
-
assert manager1 is manager2
|
|
255
|
-
assert isinstance(manager1, StreamlitPreviewManager)
|
|
256
|
-
|
|
244
|
+
|
|
257
245
|
@pytest.mark.parametrize("num_previews", [1, 2, 3])
|
|
258
246
|
def test_concurrent_previews(self, manager, sample_app_code, num_previews):
|
|
259
247
|
"""Test managing multiple concurrent previews."""
|
|
@@ -284,8 +272,7 @@ st.write("Hello, World!")
|
|
|
284
272
|
|
|
285
273
|
# Start multiple previews
|
|
286
274
|
for preview_id in preview_ids:
|
|
287
|
-
|
|
288
|
-
assert success is True
|
|
275
|
+
port = manager.start_streamlit_preview("/tmp/test_dir", 'test-file-name.py', preview_id)
|
|
289
276
|
ports.append(port)
|
|
290
277
|
|
|
291
278
|
# Assertions
|
mito_ai/user/handlers.py
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import json
|
|
5
5
|
import tornado
|
|
6
|
+
from typing import Any, Optional
|
|
6
7
|
from jupyter_server.base.handlers import APIHandler
|
|
7
8
|
from mito_ai.utils.db import get_user_field, set_user_field
|
|
8
9
|
from mito_ai.utils.telemetry_utils import identify
|
|
10
|
+
from mito_ai.utils.version_utils import is_pro
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
class UserHandler(APIHandler):
|
|
@@ -13,7 +15,15 @@ class UserHandler(APIHandler):
|
|
|
13
15
|
|
|
14
16
|
@tornado.web.authenticated
|
|
15
17
|
def get(self, key: str) -> None:
|
|
16
|
-
value =
|
|
18
|
+
value: Optional[Any] = None
|
|
19
|
+
|
|
20
|
+
if key == "is_pro":
|
|
21
|
+
# Special case, since we don't store this key
|
|
22
|
+
# in the user.json file.
|
|
23
|
+
value = str(is_pro())
|
|
24
|
+
else:
|
|
25
|
+
value = get_user_field(key)
|
|
26
|
+
|
|
17
27
|
if value is None:
|
|
18
28
|
self.set_status(404)
|
|
19
29
|
self.finish(json.dumps({"error": f"User field with key '{key}' not found"}))
|
|
@@ -29,5 +39,7 @@ class UserHandler(APIHandler):
|
|
|
29
39
|
return
|
|
30
40
|
|
|
31
41
|
set_user_field(key, data["value"])
|
|
32
|
-
identify()
|
|
33
|
-
self.finish(
|
|
42
|
+
identify() # Log the new user
|
|
43
|
+
self.finish(
|
|
44
|
+
json.dumps({"status": "success", "key": key, "value": data["value"]})
|
|
45
|
+
)
|
mito_ai/utils/create.py
CHANGED
|
@@ -36,6 +36,17 @@ def is_user_json_exists_and_valid_json() -> bool:
|
|
|
36
36
|
except:
|
|
37
37
|
return False
|
|
38
38
|
|
|
39
|
+
def get_temp_user_id() -> Optional[str]:
|
|
40
|
+
"""
|
|
41
|
+
Looks for a temporary user ID, generated by the desktop app.
|
|
42
|
+
"""
|
|
43
|
+
temp_user_id_path = os.path.join(MITO_FOLDER, 'temp_user_id.txt')
|
|
44
|
+
|
|
45
|
+
if os.path.exists(temp_user_id_path):
|
|
46
|
+
with open(temp_user_id_path, 'r') as f:
|
|
47
|
+
return f.read()
|
|
48
|
+
|
|
49
|
+
return None
|
|
39
50
|
|
|
40
51
|
def try_create_user_json_file() -> None:
|
|
41
52
|
|
|
@@ -50,7 +61,12 @@ def try_create_user_json_file() -> None:
|
|
|
50
61
|
with open(USER_JSON_PATH, 'w+') as f:
|
|
51
62
|
f.write(json.dumps(USER_JSON_DEFAULT))
|
|
52
63
|
|
|
53
|
-
#
|
|
64
|
+
# Next, look for a temp user id
|
|
65
|
+
temp_user_id = get_temp_user_id()
|
|
66
|
+
if temp_user_id:
|
|
67
|
+
set_user_field(UJ_STATIC_USER_ID, temp_user_id)
|
|
68
|
+
|
|
69
|
+
# Finally, we take special care to put all the testing/CI environments
|
|
54
70
|
# (e.g. Github actions) under one ID and email
|
|
55
71
|
if is_running_test():
|
|
56
72
|
set_user_field(UJ_STATIC_USER_ID, GITHUB_ACTION_ID)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright (c) Saga Inc.
|
|
2
|
+
# Distributed under the terms of the GNU Affero General Public License v3.0 License.
|
|
3
|
+
|
|
4
|
+
from mito_ai.app_deploy.models import AppDeployError
|
|
5
|
+
|
|
6
|
+
class MitoAppError(Exception):
|
|
7
|
+
"""Exception raised for custom error in the application."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, error_code: int) -> None:
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.message = message
|
|
12
|
+
self.error_code = error_code
|
|
13
|
+
|
|
14
|
+
class StreamlitPreviewError(MitoAppError):
|
|
15
|
+
def __str__(self) -> str:
|
|
16
|
+
return f"[PreviewError]: {self.message} (Error Code: {self.error_code})"
|
|
17
|
+
|
|
18
|
+
class StreamlitConversionError(MitoAppError):
|
|
19
|
+
def __str__(self) -> str:
|
|
20
|
+
return f"[ConversionError]: {self.message} (Error Code: {self.error_code})"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class StreamlitDeploymentError(MitoAppError):
|
|
24
|
+
"""Raised when a deployment operation fails."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, error: AppDeployError):
|
|
27
|
+
self.error = error
|
|
28
|
+
self.error_type = error.error_type
|
|
29
|
+
self.message_id = getattr(error, "message_id", "ErrorMessageID")
|
|
30
|
+
self.error_code = getattr(error, "error_code", 500)
|
|
31
|
+
self.hint = getattr(error, "hint", "")
|
|
32
|
+
self.traceback = getattr(error, "traceback", "")
|
|
33
|
+
self.error_type = getattr(error, "error_type", "Error")
|
|
34
|
+
self.message = error.message
|
|
35
|
+
print(f"self_message: {self.message}")
|
|
36
|
+
super().__init__(self.message, self.error_code)
|
|
37
|
+
|
|
38
|
+
def __str__(self) -> str:
|
|
39
|
+
base = f"[DeploymentError]: {self.message} (Error Code: {self.error_code})"
|
|
40
|
+
if self.hint:
|
|
41
|
+
base += f"\nHint: {self.hint}"
|
|
42
|
+
return base
|
|
@@ -10,6 +10,7 @@ from mito_ai.completions.prompt_builders.prompt_constants import (
|
|
|
10
10
|
ACTIVE_CELL_OUTPUT_SECTION_HEADING,
|
|
11
11
|
GET_CELL_OUTPUT_TOOL_RESPONSE_SECTION_HEADING,
|
|
12
12
|
FILES_SECTION_HEADING,
|
|
13
|
+
STREAMLIT_APP_STATUS_SECTION_HEADING,
|
|
13
14
|
VARIABLES_SECTION_HEADING,
|
|
14
15
|
JUPYTER_NOTEBOOK_SECTION_HEADING,
|
|
15
16
|
CONTENT_REMOVED_PLACEHOLDER
|
|
@@ -31,7 +32,8 @@ def trim_sections_from_message_content(content: str) -> str:
|
|
|
31
32
|
JUPYTER_NOTEBOOK_SECTION_HEADING,
|
|
32
33
|
GET_CELL_OUTPUT_TOOL_RESPONSE_SECTION_HEADING,
|
|
33
34
|
ACTIVE_CELL_OUTPUT_SECTION_HEADING,
|
|
34
|
-
ACTIVE_CELL_ID_SECTION_HEADING
|
|
35
|
+
ACTIVE_CELL_ID_SECTION_HEADING,
|
|
36
|
+
STREAMLIT_APP_STATUS_SECTION_HEADING
|
|
35
37
|
]
|
|
36
38
|
|
|
37
39
|
for heading in section_headings:
|
mito_ai/utils/telemetry_utils.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
|
-
from typing import Any, Dict, Literal, Optional
|
|
6
|
+
from typing import Any, Dict, Literal, Optional, List
|
|
7
7
|
from mito_ai.utils.version_utils import MITOSHEET_HELPER_PRIVATE, is_pro
|
|
8
8
|
from mito_ai.utils.schema import UJ_AI_MITO_API_NUM_USAGES, UJ_MITOSHEET_TELEMETRY, UJ_STATIC_USER_ID, UJ_USER_EMAIL, UJ_FEEDBACKS_V2
|
|
9
9
|
from mito_ai.utils.db import get_user_field
|
|
@@ -190,7 +190,24 @@ def log(
|
|
|
190
190
|
|
|
191
191
|
if thread_id is not None:
|
|
192
192
|
final_params['thread_id'] = thread_id
|
|
193
|
-
|
|
193
|
+
|
|
194
|
+
# Process parameters that need chunking
|
|
195
|
+
params_to_remove = []
|
|
196
|
+
params_to_add = {}
|
|
197
|
+
|
|
198
|
+
for param_name, param_value in final_params.items():
|
|
199
|
+
if isinstance(param_value, str) and len(param_value) > 250:
|
|
200
|
+
# Mark for removal
|
|
201
|
+
params_to_remove.append(param_name)
|
|
202
|
+
# Get chunked parameters
|
|
203
|
+
chunked_params = chunk_param(param_value, param_name)
|
|
204
|
+
params_to_add.update(chunked_params)
|
|
205
|
+
|
|
206
|
+
# Apply the changes
|
|
207
|
+
for param_name in params_to_remove:
|
|
208
|
+
del final_params[param_name]
|
|
209
|
+
final_params.update(params_to_add)
|
|
210
|
+
|
|
194
211
|
# Finally, do the acutal logging. We do not log anything when tests are
|
|
195
212
|
# running, or if telemetry is turned off
|
|
196
213
|
if not is_running_test() and telemetry_turned_on(key_type):
|
|
@@ -368,7 +385,7 @@ def log_file_upload_failure(error: str) -> None:
|
|
|
368
385
|
log("mito_ai_file_upload_failure", params={"error_message": error})
|
|
369
386
|
|
|
370
387
|
def log_ai_completion_retry(key_type: Literal['mito_server_key', 'user_key'], thread_id: str, message_type: MessageType, error: BaseException) -> None:
|
|
371
|
-
log(MITO_AI_COMPLETION_RETRY, params={KEY_TYPE_PARAM: key_type, "message_type": message_type}, thread_id=thread_id, key_type=key_type, error=error)
|
|
388
|
+
log(MITO_AI_COMPLETION_RETRY, params={KEY_TYPE_PARAM: key_type, "message_type": message_type.value}, thread_id=thread_id, key_type=key_type, error=error)
|
|
372
389
|
|
|
373
390
|
def log_ai_completion_error(
|
|
374
391
|
key_type: Literal['mito_server_key', 'user_key'],
|
|
@@ -376,40 +393,88 @@ def log_ai_completion_error(
|
|
|
376
393
|
message_type: MessageType,
|
|
377
394
|
error: BaseException
|
|
378
395
|
) -> None:
|
|
379
|
-
log(MITO_AI_COMPLETION_ERROR, params={KEY_TYPE_PARAM: key_type, "message_type": message_type}, thread_id=thread_id, key_type=key_type, error=error)
|
|
396
|
+
log(MITO_AI_COMPLETION_ERROR, params={KEY_TYPE_PARAM: key_type, "message_type": message_type.value}, thread_id=thread_id, key_type=key_type, error=error)
|
|
380
397
|
|
|
381
398
|
def log_mito_server_free_tier_limit_reached(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType) -> None:
|
|
382
|
-
log(MITO_SERVER_FREE_TIER_LIMIT_REACHED, params={KEY_TYPE_PARAM: key_type, "message_type": message_type}, key_type=key_type)
|
|
399
|
+
log(MITO_SERVER_FREE_TIER_LIMIT_REACHED, params={KEY_TYPE_PARAM: key_type, "message_type": message_type.value}, key_type=key_type)
|
|
383
400
|
|
|
384
401
|
|
|
385
402
|
#################################
|
|
386
|
-
# Streamlit
|
|
403
|
+
# Streamlit Logs
|
|
387
404
|
#################################
|
|
388
405
|
|
|
389
|
-
|
|
406
|
+
###
|
|
407
|
+
# Converting Notebook into Streamlit App code
|
|
408
|
+
###
|
|
409
|
+
|
|
410
|
+
def log_streamlit_app_conversion_success(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, edit_prompt: str) -> None:
|
|
390
411
|
log(
|
|
391
|
-
"
|
|
412
|
+
"mito_ai_streamlit_app_conversion_success",
|
|
392
413
|
key_type=key_type,
|
|
393
414
|
params={
|
|
394
415
|
"edit_prompt": edit_prompt,
|
|
416
|
+
"message_type": message_type.value
|
|
395
417
|
}
|
|
396
418
|
)
|
|
397
419
|
|
|
398
|
-
def
|
|
420
|
+
def log_streamlit_app_validation_retry(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error: List[str]) -> None:
|
|
399
421
|
log(
|
|
400
|
-
"
|
|
422
|
+
"mito_ai_streamlit_app_conversion_retry",
|
|
401
423
|
params={
|
|
402
424
|
"error_message": error,
|
|
425
|
+
"message_type": message_type.value
|
|
403
426
|
},
|
|
404
427
|
key_type=key_type
|
|
405
428
|
)
|
|
406
429
|
|
|
407
|
-
def
|
|
430
|
+
def log_streamlit_app_conversion_error(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error_message: str, formatted_traceback: str, edit_prompt: str) -> None:
|
|
408
431
|
log(
|
|
409
|
-
"
|
|
432
|
+
"mito_ai_streamlit_app_conversion_error",
|
|
410
433
|
params={
|
|
411
|
-
"error_message":
|
|
434
|
+
"error_message": error_message,
|
|
435
|
+
"traceback": formatted_traceback,
|
|
412
436
|
"edit_prompt": edit_prompt,
|
|
437
|
+
"message_type": message_type.value
|
|
413
438
|
},
|
|
414
439
|
key_type=key_type
|
|
415
440
|
)
|
|
441
|
+
|
|
442
|
+
###
|
|
443
|
+
# Setting up Preview
|
|
444
|
+
###
|
|
445
|
+
|
|
446
|
+
def log_streamlit_app_preview_success(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, edit_prompt: str) -> None:
|
|
447
|
+
log(
|
|
448
|
+
"mito_ai_streamlit_app_preview_success",
|
|
449
|
+
key_type=key_type,
|
|
450
|
+
params={
|
|
451
|
+
"edit_prompt": edit_prompt,
|
|
452
|
+
"message_type": message_type.value
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
def log_streamlit_app_preview_failure(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error_message: str, formatted_traceback: str, edit_prompt: str) -> None:
|
|
457
|
+
log(
|
|
458
|
+
"mito_ai_streamlit_app_preview_failure",
|
|
459
|
+
key_type=key_type,
|
|
460
|
+
params={
|
|
461
|
+
"error_message": error_message,
|
|
462
|
+
"traceback": formatted_traceback,
|
|
463
|
+
"message_type": message_type.value,
|
|
464
|
+
"edit_prompt": edit_prompt
|
|
465
|
+
}
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
###
|
|
469
|
+
# Deploying Streamlit App
|
|
470
|
+
###
|
|
471
|
+
|
|
472
|
+
def log_streamlit_app_deployment_failure(key_type: Literal['mito_server_key', 'user_key'], message_type: MessageType, error: Dict) -> None:
|
|
473
|
+
log(
|
|
474
|
+
"mito_ai_streamlit_app_deployment_failure",
|
|
475
|
+
key_type=key_type,
|
|
476
|
+
params={
|
|
477
|
+
"error": error, # Contains all details in app_deploy.models.AppDeployError class
|
|
478
|
+
"message_type": message_type.value
|
|
479
|
+
}
|
|
480
|
+
)
|