33from pydantic import BaseModel
44from typing import Any , Dict , List
55from pydivkit .core import Expr
6+ import structlog
7+
8+ from functions_to_format .functions .balance import (
9+ build_balance_ui ,
10+ build_home_balances_ui ,
11+ )
612from .general import Widget , add_ui_to_widget , WidgetInput
713from .general .utils import save_builder_output
814from models .build import BuildOutput
915from functions_to_format .functions .general .const_values import LanguageOptions
10- from conf import logger
1116from models .context import Context , LoggerContext
12- import structlog
17+
18+ # Import smarty_ui components
19+ from smarty_ui import (
20+ VStack ,
21+ HStack ,
22+ text_1 ,
23+ text_2 ,
24+ caption_1 ,
25+ caption_2 ,
26+ default_theme ,
27+ )
28+
29+ logger = structlog .get_logger (__name__ )
1330
1431
1532# Backend output schemas for activity reports
@@ -82,38 +99,48 @@ def _trigger_row(
8299 target_state : str ,
83100 log_id : str ,
84101) -> dv .DivContainer :
85- """Trigger row: message + chevron (like ReasoningTrigger). Tapping toggles state."""
102+ """Trigger row: message + chevron (like ReasoningTrigger). Tapping toggles state.
103+
104+ Uses smarty_ui HStack for horizontal layout.
105+ """
86106 set_state_url = f"div-action://set_state?state_id=0/{ state_id } /{ target_state } "
87- return dv .DivContainer (
88- orientation = dv .DivContainerOrientation .HORIZONTAL ,
89- background = [dv .DivSolidBackground (color = MESSAGE_BLOCK_BG )],
90- paddings = dv .DivEdgeInsets (
91- left = TRIGGER_PADDING_H ,
92- right = TRIGGER_PADDING_H ,
93- top = TRIGGER_PADDING_V ,
94- bottom = TRIGGER_PADDING_V ,
95- ),
96- border = dv .DivBorder (
97- corner_radius = TRIGGER_RADIUS ,
98- stroke = dv .DivStroke (color = "#4B5563" , width = 1 ),
99- ),
100- alignment_vertical = dv .DivAlignmentVertical .CENTER ,
101- items = [
102- dv .DivContainer (
103- orientation = dv .DivContainerOrientation .VERTICAL ,
104- width = dv .DivMatchParentSize (weight = 1 ),
105- margins = dv .DivEdgeInsets (right = GAP_MESSAGE_CHEVRON ),
106- items = [_message_glow_text (message )],
107- ),
108- dv .DivText (
109- text = chevron ,
110- font_size = 16 ,
111- text_color = CHEVRON_COLOR ,
112- ),
113- ],
114- action = dv .DivAction (log_id = log_id , url = set_state_url ),
107+
108+ # Message container with flex weight
109+ message_container = dv .DivContainer (
110+ orientation = dv .DivContainerOrientation .VERTICAL ,
111+ width = dv .DivMatchParentSize (weight = 1 ),
112+ items = [_message_glow_text (message )],
115113 )
116114
115+ # Chevron text
116+ chevron_text = dv .DivText (
117+ text = chevron ,
118+ font_size = 16 ,
119+ text_color = CHEVRON_COLOR ,
120+ )
121+
122+ # Use HStack for horizontal layout
123+ trigger = HStack (
124+ [message_container , chevron_text ],
125+ gap = GAP_MESSAGE_CHEVRON ,
126+ align_v = "center" ,
127+ padding_left = TRIGGER_PADDING_H ,
128+ padding_right = TRIGGER_PADDING_H ,
129+ padding_top = TRIGGER_PADDING_V ,
130+ padding_bottom = TRIGGER_PADDING_V ,
131+ background = MESSAGE_BLOCK_BG ,
132+ corner_radius = TRIGGER_RADIUS ,
133+ )
134+
135+ # Add border stroke and action manually (not supported by HStack helper)
136+ trigger .border = dv .DivBorder (
137+ corner_radius = TRIGGER_RADIUS ,
138+ stroke = dv .DivStroke (color = "#4B5563" , width = 1 ),
139+ )
140+ trigger .action = dv .DivAction (log_id = log_id , url = set_state_url )
141+
142+ return trigger
143+
117144
118145def _build_activity_message_holder (
119146 message : str ,
@@ -122,7 +149,10 @@ def _build_activity_message_holder(
122149 log_id : str ,
123150 action_url : str = "div-action://activity-report" ,
124151):
125- """Reasoning-like collapsible: trigger row (message + chevron) + expandable content (title + detail)."""
152+ """Reasoning-like collapsible: trigger row (message + chevron) + expandable content (title + detail).
153+
154+ Uses smarty_ui VStack for vertical layouts.
155+ """
126156 state_id = f"activity_{ log_id } "
127157
128158 # Collapsed: only trigger row with ▼ (expand)
@@ -134,56 +164,40 @@ def _build_activity_message_holder(
134164 log_id = log_id ,
135165 )
136166
137- # Expanded: trigger row with ▲ (collapse) + content below in a card
138- content_inner = dv .DivContainer (
139- orientation = dv .DivContainerOrientation .VERTICAL ,
140- items = [
141- dv .DivText (
142- text = title ,
143- font_size = 13 ,
144- text_color = CONTENT_TITLE_COLOR ,
145- font_weight = dv .DivFontWeight .MEDIUM ,
146- margins = dv .DivEdgeInsets (bottom = 8 ),
147- ),
148- dv .DivText (
149- text = detail_json ,
150- font_size = 11 ,
151- text_color = CONTENT_DETAIL_COLOR ,
152- line_height = 18 ,
153- ),
154- ],
167+ # Content inner using VStack
168+ title_text = caption_1 (title , color = CONTENT_TITLE_COLOR )
169+ detail_text = caption_2 (detail_json , color = CONTENT_DETAIL_COLOR )
170+
171+ content_inner = VStack (
172+ [title_text , detail_text ],
173+ gap = 8 ,
155174 )
156- content_block = dv .DivContainer (
157- orientation = dv .DivContainerOrientation .VERTICAL ,
158- margins = dv .DivEdgeInsets (top = SPACING_ABOVE_CONTENT ),
159- paddings = dv .DivEdgeInsets (
160- left = CONTENT_PADDING ,
161- right = CONTENT_PADDING ,
162- top = CONTENT_PADDING ,
163- bottom = CONTENT_PADDING ,
164- ),
165- background = [dv .DivSolidBackground (color = CONTENT_BLOCK_BG )],
166- border = dv .DivBorder (
167- corner_radius = CONTENT_RADIUS ,
168- stroke = dv .DivStroke (color = CONTENT_BLOCK_BORDER , width = 1 ),
169- ),
170- transition_in = dv .DivFadeTransition (duration = 200 , alpha = 0.5 ),
171- items = [content_inner ],
175+
176+ # Content block with styling
177+ content_block = VStack (
178+ [content_inner ],
179+ padding = CONTENT_PADDING ,
180+ background = CONTENT_BLOCK_BG ,
181+ corner_radius = CONTENT_RADIUS ,
182+ )
183+ content_block .margins = dv .DivEdgeInsets (top = SPACING_ABOVE_CONTENT )
184+ content_block .border = dv .DivBorder (
185+ corner_radius = CONTENT_RADIUS ,
186+ stroke = dv .DivStroke (color = CONTENT_BLOCK_BORDER , width = 1 ),
172187 )
188+ content_block .transition_in = dv .DivFadeTransition (duration = 200 , alpha = 0.5 )
189+
190+ # Expanded trigger
173191 expanded_trigger = _trigger_row (
174192 message = message ,
175193 chevron = "▲" ,
176194 state_id = state_id ,
177195 target_state = "collapsed" ,
178196 log_id = log_id ,
179197 )
180- expanded_div = dv .DivContainer (
181- orientation = dv .DivContainerOrientation .VERTICAL ,
182- items = [
183- expanded_trigger ,
184- content_block ,
185- ],
186- )
198+
199+ # Expanded div using VStack
200+ expanded_div = VStack ([expanded_trigger , content_block ])
187201
188202 state = dv .DivState (
189203 id = state_id ,
@@ -193,20 +207,33 @@ def _build_activity_message_holder(
193207 dv .DivStateState (state_id = "expanded" , div = expanded_div ),
194208 ],
195209 )
196- wrapper = dv .DivContainer (
197- orientation = dv .DivContainerOrientation .VERTICAL ,
198- margins = dv .DivEdgeInsets (left = 12 , right = 12 , top = 8 , bottom = 8 ),
199- items = [state ],
210+
211+ widgets = [state ]
212+
213+ # Wrapper using VStack
214+ wrapper = VStack (
215+ widgets ,
216+ padding_left = 12 ,
217+ padding_right = 12 ,
218+ padding_top = 8 ,
219+ padding_bottom = 8 ,
200220 )
221+
201222 return dv .make_div (wrapper )
202223
203224
204225def build_function_call_activity_widget (
205226 message : str ,
206227 function_name : str ,
207228 arguments : Dict [str , Any ],
229+ language : LanguageOptions = LanguageOptions .RUSSIAN ,
208230):
209231 """Builder for function_call activity: shows message and call details (function_name, arguments)."""
232+ logger .debug (
233+ "building_function_call_activity_widget" ,
234+ function_name = function_name ,
235+ message = message ,
236+ )
210237 title = f"Calling: { function_name } "
211238 detail_json = json .dumps (arguments , ensure_ascii = False , default = str )[:500 ]
212239 if len (detail_json ) >= 500 :
@@ -224,12 +251,19 @@ def build_function_response_activity_widget(
224251 message : str ,
225252 function_name : str ,
226253 response : Dict [str , Any ],
254+ language : LanguageOptions = LanguageOptions .RUSSIAN ,
227255):
228256 """Builder for function_response activity: shows message and response (function_name, response)."""
257+ logger .debug (
258+ "building_function_response_activity_widget" ,
259+ function_name = function_name ,
260+ message = message ,
261+ )
229262 title = f"Response from: { function_name } "
230263 detail_json = json .dumps (response , ensure_ascii = False , default = str )[:500 ]
231264 if len (detail_json ) >= 500 :
232265 detail_json += "..."
266+
233267 return _build_activity_message_holder (
234268 message = message ,
235269 title = title ,
@@ -240,20 +274,21 @@ def build_function_response_activity_widget(
240274
241275
242276def build_activity_indicator_widget (message : str ) -> ActivityIndicatorWidget :
243- container = dv .DivContainer (
244- id = "activity_report" ,
245- orientation = dv .DivContainerOrientation .VERTICAL ,
246- items = [
247- dv .DivText (text = message , font_size = 14 , text_color = "#F1F5F9" ),
248- ],
249- action = dv .DivAction (
250- log_id = "activity_report" ,
251- url = "div-action://activity-report" ,
252- payload = {
253- "message" : message ,
254- "link" : "http://10.212.134.3:8003/new_messages?idx=12341234" ,
255- },
256- ),
277+ """Build activity indicator widget using smarty_ui components."""
278+ logger .debug ("building_activity_indicator_widget" , message = message )
279+ # Use text_1 for the message text
280+ message_text = text_1 (message , color = "#F1F5F9" )
281+
282+ # Use VStack for vertical layout
283+ container = VStack ([message_text ])
284+ container .id = "activity_report"
285+ container .action = dv .DivAction (
286+ log_id = "activity_report" ,
287+ url = "div-action://activity-report" ,
288+ payload = {
289+ "message" : message ,
290+ "link" : "http://10.212.134.3:8003/new_messages?idx=12341234" ,
291+ },
257292 )
258293
259294 return dv .make_div (container )
@@ -267,7 +302,9 @@ def activity_indicator(context: Context) -> BuildOutput:
267302 language = context .language
268303 chat_id = context .logger_context .chat_id
269304 api_key = context .api_key
270- logger = context .logger_context .logger
305+ ctx_logger = context .logger_context .logger
306+
307+ ctx_logger .info ("activity_indicator_started" , llm_output = llm_output )
271308
272309 inp = {}
273310
@@ -291,5 +328,6 @@ def activity_indicator(context: Context) -> BuildOutput:
291328 widgets = [widget .model_dump (exclude_none = True ) for widget in widgets ],
292329 )
293330
331+ ctx_logger .info ("activity_indicator_completed" , widgets_count = len (widgets ))
294332 save_builder_output (context , output )
295333 return output
0 commit comments