@@ -60,23 +60,35 @@ def _extract_event_id_from_interaction_event(
6060 event : 'InteractionSSEEvent' ,
6161) -> Optional [str ]:
6262 """Extract the SDK event identifier from an interactions SSE event."""
63- return getattr (event , 'event_id' , None ) or getattr (event , 'id' , None )
63+ event_id = getattr (event , 'event_id' , None )
64+ if isinstance (event_id , str ):
65+ return event_id
66+
67+ legacy_event_id = getattr (event , 'id' , None )
68+ if isinstance (legacy_event_id , str ):
69+ return legacy_event_id
70+
71+ return None
6472
6573
6674def _extract_interaction_id_from_event (
6775 event : 'InteractionSSEEvent' ,
6876) -> Optional [str ]:
6977 """Extract the interaction chain identifier from an SSE event."""
7078 interaction = getattr (event , 'interaction' , None )
71- if interaction and getattr (interaction , 'id' , None ):
72- return interaction .id
73-
74- interaction_id = getattr (event , 'interaction_id' , None )
75- if interaction_id :
79+ interaction_id = getattr (interaction , 'id' , None )
80+ if isinstance (interaction_id , str ):
7681 return interaction_id
7782
78- # Fall back to legacy field names when older SDK shapes are in play.
79- return getattr (event , 'id' , None )
83+ event_interaction_id = getattr (event , 'interaction_id' , None )
84+ if isinstance (event_interaction_id , str ):
85+ return event_interaction_id
86+
87+ legacy_interaction_id = getattr (event , 'id' , None )
88+ if isinstance (legacy_interaction_id , str ):
89+ return legacy_interaction_id
90+
91+ return None
8092
8193
8294def convert_part_to_interaction_content (part : types .Part ) -> Optional [dict ]:
@@ -177,12 +189,12 @@ def convert_part_to_interaction_content(part: types.Part) -> Optional[dict]:
177189 elif part .thought :
178190 # part.thought is a boolean indicating this is a thought part
179191 # ThoughtContentParam expects 'signature' (base64 encoded bytes)
180- result : dict [str , Any ] = {'type' : 'thought' }
192+ thought_content : dict [str , Any ] = {'type' : 'thought' }
181193 if part .thought_signature is not None :
182- result ['signature' ] = base64 .b64encode ( part . thought_signature ). decode (
183- 'utf-8'
184- )
185- return result
194+ thought_content ['signature' ] = base64 .b64encode (
195+ part . thought_signature
196+ ). decode ( 'utf-8' )
197+ return thought_content
186198 elif part .code_execution_result is not None :
187199 is_error = part .code_execution_result .outcome in (
188200 types .Outcome .OUTCOME_FAILED ,
0 commit comments