@@ -74,9 +74,10 @@ def _process_message_event(
7474 )
7575 self .messages [ev .message_id ] = msg
7676
77- # --- Handle content parts ---
77+ # --- Handle content parts (text, JSON, etc.) ---
7878 if ev .content_part :
7979 cp_event = ev .content_part
80+
8081 existing = next (
8182 (
8283 cp
@@ -86,27 +87,41 @@ def _process_message_event(
8687 None ,
8788 )
8889
89- if cp_event .start :
90+ # Start of a new content part
91+ if cp_event .start and not existing :
92+ new_cp = UiPathConversationContentPart (
93+ content_part_id = cp_event .content_part_id ,
94+ mime_type = cp_event .start .mime_type ,
95+ data = UiPathInlineValue (inline = "" ),
96+ citations = [],
97+ is_transcript = None ,
98+ is_incomplete = True ,
99+ )
100+ if msg .content_parts is None :
101+ msg .content_parts = []
102+ msg .content_parts .append (new_cp )
103+ existing = new_cp
104+
105+ # Chunk for an existing part (or backfill if start missing)
106+ if cp_event .chunk :
90107 if not existing :
108+ new_cp = UiPathConversationContentPart (
109+ content_part_id = cp_event .content_part_id ,
110+ mime_type = "text/plain" , # fallback if start missing
111+ data = UiPathInlineValue (inline = "" ),
112+ citations = [],
113+ is_transcript = None ,
114+ is_incomplete = True ,
115+ )
91116 if msg .content_parts is None :
92117 msg .content_parts = []
93- msg .content_parts .append (
94- UiPathConversationContentPart (
95- content_part_id = cp_event .content_part_id ,
96- mime_type = cp_event .start .mime_type ,
97- data = UiPathInlineValue (
98- inline = cp_event .chunk .data
99- if cp_event .chunk and cp_event .chunk .data
100- else ""
101- ),
102- citations = [],
103- is_transcript = None ,
104- is_incomplete = None ,
105- )
106- )
107- if cp_event .chunk and existing :
118+ msg .content_parts .append (new_cp )
119+ existing = new_cp
120+
108121 if isinstance (existing .data , UiPathInlineValue ):
109122 existing .data .inline += cp_event .chunk .data or ""
123+
124+ # End of a part
110125 if cp_event .end and existing :
111126 existing .is_incomplete = bool (cp_event .end .interrupted )
112127
@@ -122,43 +137,31 @@ def _process_message_event(
122137 None ,
123138 )
124139
140+ # Start of a tool call
125141 if tc_event .start :
126142 if not existing_tool_call :
127- # create new tool call
128143 new_tc = UiPathConversationToolCall (
129144 tool_call_id = tc_event .tool_call_id ,
130145 name = tc_event .start .tool_name ,
131- arguments = tc_event . start . arguments ,
146+ arguments = None , # args will arrive as JSON content part
132147 timestamp = tc_event .start .timestamp ,
133148 result = None ,
134149 )
135150 if msg .tool_calls is None :
136151 msg .tool_calls = []
137152 msg .tool_calls .append (new_tc )
153+ existing_tool_call = new_tc
138154 else :
139- # merge/update existing
140155 existing_tool_call .name = (
141156 tc_event .start .tool_name or existing_tool_call .name
142157 )
143- if tc_event .start .arguments :
144- # If Inline, append more data
145- if isinstance (
146- tc_event .start .arguments , UiPathInlineValue
147- ) and isinstance (
148- existing_tool_call .arguments , UiPathInlineValue
149- ):
150- existing_tool_call .arguments .inline += (
151- tc_event .start .arguments .inline or ""
152- )
153- else :
154- existing_tool_call .arguments = tc_event .start .arguments
155158 existing_tool_call .timestamp = (
156159 tc_event .start .timestamp or existing_tool_call .timestamp
157160 )
158161
162+ # End of a tool call
159163 if tc_event .end :
160164 if not existing_tool_call :
161- # Shouldn't happen, but initialize if end comes first
162165 existing_tool_call = UiPathConversationToolCall (
163166 tool_call_id = tc_event .tool_call_id ,
164167 name = "" , # unknown until start seen
@@ -177,7 +180,6 @@ def _process_message_event(
177180
178181 # --- Update timestamps ---
179182 msg .updated_at = self ._timestamp (ev )
180-
181183 return msg
182184
183185 def _timestamp (self , ev : UiPathConversationMessageEvent ) -> str :
0 commit comments