vedana-backoffice 0.6.1__py3-none-any.whl → 0.6.3__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.
@@ -9,6 +9,9 @@ from vedana_core.app import VedanaApp, make_vedana_app
9
9
  vedana_app: VedanaApp | None = None
10
10
 
11
11
  EVAL_ENABLED = bool(os.environ.get("GRIST_TEST_SET_DOC_ID"))
12
+ DEBUG_MODE = os.environ.get("DEBUG", "").lower() in ("true", "1")
13
+ HAS_OPENAI_KEY = bool(os.environ.get("OPENAI_API_KEY"))
14
+ HAS_OPENROUTER_KEY = bool(os.environ.get("OPENROUTER_API_KEY"))
12
15
 
13
16
 
14
17
  async def get_vedana_app():
@@ -40,6 +43,48 @@ class MemLogger(logging.Logger):
40
43
  class AppVersionState(rx.State):
41
44
  version: str = f"`{os.environ.get('VERSION', 'unspecified_version')}`" # md-formatted
42
45
  eval_enabled: bool = EVAL_ENABLED
46
+ debug_mode: bool = DEBUG_MODE
47
+
48
+
49
+ class DebugState(rx.State):
50
+ """State for debug mode API key setup."""
51
+
52
+ debug_mode: bool = DEBUG_MODE
53
+ needs_api_key: bool = DEBUG_MODE and not HAS_OPENAI_KEY and not HAS_OPENROUTER_KEY
54
+ show_api_key_dialog: bool = False
55
+ api_key: str = ""
56
+ api_key_type: str = "openai" # "openai" or "openrouter"
57
+ api_key_saved: bool = False
58
+
59
+ def check_and_show_dialog(self) -> None:
60
+ """Called on app mount to show dialog if needed."""
61
+ if self.needs_api_key and not self.api_key_saved:
62
+ self.show_api_key_dialog = True
63
+
64
+ def set_api_key(self, value: str) -> None:
65
+ self.api_key = value
66
+
67
+ def set_api_key_type(self, value: str) -> None:
68
+ self.api_key_type = value
69
+
70
+ def save_api_key(self) -> None:
71
+ """Save the API key and close dialog."""
72
+ if self.api_key.strip() and self.debug_mode: # extra check for debug mode
73
+ self.api_key_saved = True
74
+ self.show_api_key_dialog = False
75
+ # Set environment variable so it's available throughout the app
76
+ if self.api_key_type == "openai":
77
+ os.environ["OPENAI_API_KEY"] = self.api_key.strip()
78
+ else:
79
+ os.environ["OPENROUTER_API_KEY"] = self.api_key.strip()
80
+
81
+ def close_dialog(self) -> None:
82
+ """Close dialog without saving."""
83
+ self.show_api_key_dialog = False
84
+
85
+ def open_dialog(self) -> None:
86
+ """Manually open the dialog to change API key."""
87
+ self.show_api_key_dialog = True
43
88
 
44
89
 
45
90
  class TelegramBotState(rx.State):
vedana_backoffice/ui.py CHANGED
@@ -5,7 +5,7 @@ from typing import Any
5
5
  import reflex as rx
6
6
 
7
7
  from vedana_backoffice.states.chat import ChatState
8
- from vedana_backoffice.states.common import AppVersionState, TelegramBotState
8
+ from vedana_backoffice.states.common import AppVersionState, DebugState, TelegramBotState
9
9
 
10
10
 
11
11
  def telegram_link_box() -> rx.Component:
@@ -36,44 +36,122 @@ def data_model_reload_btn() -> rx.Component:
36
36
  )
37
37
 
38
38
 
39
- def app_header() -> rx.Component:
40
- return rx.box(
41
- rx.hstack(
42
- rx.hstack(
43
- rx.link("Vedana Backoffice", href="/", font_weight="bold", font_size="1.25em"),
44
- rx.markdown(AppVersionState.version), # type: ignore[operator]
45
- align="center",
46
- spacing="3",
39
+ def debug_badge() -> rx.Component:
40
+ """Red badge indicating debug mode is active. Clickable to open API key dialog."""
41
+ return rx.cond(
42
+ AppVersionState.debug_mode,
43
+ rx.tooltip(
44
+ rx.badge(
45
+ "DEBUG MODE",
46
+ color_scheme="red",
47
+ variant="solid",
48
+ size="2",
49
+ style={
50
+ "font_weight": "bold",
51
+ "text_transform": "uppercase",
52
+ "cursor": "pointer",
53
+ },
54
+ on_click=DebugState.open_dialog,
55
+ ),
56
+ content="Debug mode enabled! Some features are not for production use. Click to reset LLM API_KEY"
57
+ ),
58
+ rx.fragment(),
59
+ )
60
+
61
+
62
+ def api_key_setup_dialog() -> rx.Component:
63
+ """Dialog to prompt user for API key in debug mode when no keys are configured."""
64
+ return rx.dialog.root(
65
+ rx.dialog.content(
66
+ rx.dialog.title("API Key Setup"),
67
+ rx.dialog.description(
68
+ "Please provide an OpenAI or OpenRouter API key to use the chat functionality.",
69
+ margin_bottom="1em",
70
+ ),
71
+ rx.vstack(
72
+ rx.select(
73
+ ["openai", "openrouter"],
74
+ value=DebugState.api_key_type,
75
+ on_change=DebugState.set_api_key_type,
76
+ placeholder="Select API provider",
77
+ ),
78
+ rx.input(
79
+ placeholder="Enter your API key",
80
+ value=DebugState.api_key,
81
+ on_change=DebugState.set_api_key,
82
+ type="password",
83
+ width="100%",
84
+ ),
85
+ rx.hstack(
86
+ rx.dialog.close(
87
+ rx.button(
88
+ "Skip",
89
+ variant="soft",
90
+ color_scheme="gray",
91
+ on_click=DebugState.close_dialog,
92
+ ),
93
+ ),
94
+ rx.button(
95
+ "Save",
96
+ color_scheme="blue",
97
+ on_click=DebugState.save_api_key,
98
+ ),
99
+ justify="end",
100
+ spacing="3",
101
+ width="100%",
102
+ ),
103
+ spacing="4",
104
+ width="100%",
47
105
  ),
106
+ style={"max_width": "450px"},
107
+ ),
108
+ open=DebugState.show_api_key_dialog,
109
+ )
110
+
111
+
112
+ def app_header() -> rx.Component:
113
+ return rx.fragment(
114
+ rx.box(
48
115
  rx.hstack(
49
- data_model_reload_btn(),
50
- rx.link("ETL", href="/etl", font_size="1.1em"),
51
- rx.cond(
52
- AppVersionState.eval_enabled,
53
- rx.link("Eval", href="/eval", font_size="1.1em"),
54
- rx.fragment(),
116
+ rx.hstack(
117
+ rx.link("Vedana Backoffice", href="/", font_weight="bold", font_size="1.25em"),
118
+ rx.markdown(AppVersionState.version), # type: ignore[operator]
119
+ debug_badge(),
120
+ align="center",
121
+ spacing="3",
122
+ ),
123
+ rx.hstack(
124
+ data_model_reload_btn(),
125
+ rx.link("ETL", href="/etl", font_size="1.1em"),
126
+ rx.cond(
127
+ AppVersionState.eval_enabled,
128
+ rx.link("Eval", href="/eval", font_size="1.1em"),
129
+ rx.fragment(),
130
+ ),
131
+ rx.link("Chat", href="/chat", font_size="1.1em"),
132
+ rx.link("JIMS", href="/jims", font_size="1.1em"),
133
+ telegram_link_box(),
134
+ rx.color_mode.button(), # type: ignore[attr-defined]
135
+ spacing="6",
136
+ align="center",
55
137
  ),
56
- rx.link("Chat", href="/chat", font_size="1.1em"),
57
- rx.link("JIMS", href="/jims", font_size="1.1em"),
58
- telegram_link_box(),
59
- rx.color_mode.button(), # type: ignore[attr-defined]
60
- spacing="6",
138
+ justify="between",
61
139
  align="center",
140
+ width="100%",
62
141
  ),
63
- justify="between",
64
- align="center",
65
142
  width="100%",
143
+ padding="0.5em 1.25em",
144
+ border_bottom="1px solid #e5e7eb",
145
+ position="sticky",
146
+ top="0",
147
+ background_color=rx.color_mode_cond(light="white", dark="black"),
148
+ style={
149
+ "backdrop-filter": "blur(10px)", # enables non-transparent background
150
+ },
151
+ z_index="10",
152
+ on_mount=DebugState.check_and_show_dialog,
66
153
  ),
67
- width="100%",
68
- padding="0.5em 1.25em",
69
- border_bottom="1px solid #e5e7eb",
70
- position="sticky",
71
- top="0",
72
- background_color=rx.color_mode_cond(light="white", dark="black"),
73
- style={
74
- "backdrop-filter": "blur(10px)", # enables non-transparent background
75
- },
76
- z_index="10",
154
+ api_key_setup_dialog(),
77
155
  )
78
156
 
79
157
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vedana-backoffice
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: Reflex-based admin/backoffice UI for Vedana
5
5
  Author-email: Andrey Tatarinov <a@tatarinov.co>, Timur Sheydaev <tsheyd@epoch8.co>
6
6
  Requires-Python: >=3.12
@@ -3,7 +3,7 @@ vedana_backoffice/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
3
3
  vedana_backoffice/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  vedana_backoffice/start_services.py,sha256=94k2xrgIYXWhRfurR7XM-uMoXXL09RG0HFzyRRh9Nrs,974
5
5
  vedana_backoffice/state.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- vedana_backoffice/ui.py,sha256=yKPAwUJZ_8cYzswqCV7nUxihvcrHw_DszeI1lbTaTbM,3618
6
+ vedana_backoffice/ui.py,sha256=3Banuy-WT8U3sQOiQw2_UfWvkJjs_aUFDAyD4_c97mk,6463
7
7
  vedana_backoffice/util.py,sha256=RVN9ezjNkSnrlT3pBIrSvQQLyf-TZ2WzP_AYxRGks_Q,2209
8
8
  vedana_backoffice/vedana_backoffice.py,sha256=WlwF8hTBmkYOlgj9vE3k58MqDcj8FIbMNXZRsUXnjKg,1224
9
9
  vedana_backoffice/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -19,12 +19,12 @@ vedana_backoffice/pages/jims_thread_list_page.py,sha256=ZogjE7XQW2Zuyzcy4mod8qQE
19
19
  vedana_backoffice/pages/main_dashboard.py,sha256=odi4V5Bf-qukPLN9f8whgaYWikL6D7v5kzqB4rm3T10,21350
20
20
  vedana_backoffice/states/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  vedana_backoffice/states/chat.py,sha256=xZwnqhzVIhnfGRPAWPcgZg9_boM3Crvmu-gieh1QMfs,13980
22
- vedana_backoffice/states/common.py,sha256=wI3ZCDeuV4_pkVQ-Q_Z0lgC8TQPs_eIT2nPqD-5rtjs,1977
22
+ vedana_backoffice/states/common.py,sha256=ArFkK_A8yN0cpQtyK6CWSLj17dNxYbhN-ay59E_gYPs,3707
23
23
  vedana_backoffice/states/etl.py,sha256=1eLahWMm0Zd3oBDpOAJ_rfqHMPgRIJ_InwYzhm52hoo,68261
24
24
  vedana_backoffice/states/eval.py,sha256=nDfDL5ifL_q2vWWBEPwtWomUG_dhJxOMlIWOndOtjxM,76897
25
25
  vedana_backoffice/states/jims.py,sha256=gM0iZInD40-AebWY9gOzn5oJjAx7wyA_QliTluzMoZ8,19927
26
26
  vedana_backoffice/states/main_dashboard.py,sha256=9AcWo2nl5L-hTymxr-Stbu2s5nTGl9CVxTA9mHu8Rt4,32388
27
- vedana_backoffice-0.6.1.dist-info/METADATA,sha256=fWD47CYK9zRHd2_ej_NTcr5-_4cdtNrgbi_NeRqU8RI,341
28
- vedana_backoffice-0.6.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
29
- vedana_backoffice-0.6.1.dist-info/entry_points.txt,sha256=WyUmp5EmDq_dB9RjzEim4L-XmDhPDxYI7ptab4A1EJc,87
30
- vedana_backoffice-0.6.1.dist-info/RECORD,,
27
+ vedana_backoffice-0.6.3.dist-info/METADATA,sha256=uWKJRkWmGlBHkMpIJ9HtHuQ_iuyc2Ix6XR0jX2SZliw,341
28
+ vedana_backoffice-0.6.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
29
+ vedana_backoffice-0.6.3.dist-info/entry_points.txt,sha256=WyUmp5EmDq_dB9RjzEim4L-XmDhPDxYI7ptab4A1EJc,87
30
+ vedana_backoffice-0.6.3.dist-info/RECORD,,