@@ -273,26 +273,52 @@ class Agent(BaseResponse):
273
273
or (isinstance (f , Think ) and not f )
274
274
),
275
275
)
276
- speak : Speak = field (
277
- default_factory = Speak ,
278
- metadata = dataclass_config (
279
- exclude = lambda f : f is None
280
- or (isinstance (f , dict ) and not f )
281
- or (isinstance (f , Speak ) and not f )
282
- ),
283
- )
276
+ speak : Union [Speak , List [Speak ]] = field (default_factory = Speak )
284
277
greeting : Optional [str ] = field (
285
278
default = None , metadata = dataclass_config (exclude = lambda f : f is None )
286
279
)
287
280
281
+ def __post_init__ (self ):
282
+ """Handle conversion of dict/list data to proper Speak objects"""
283
+ # Handle listen conversion (existing pattern)
284
+ if (
285
+ not isinstance (self .listen , Listen )
286
+ and self .listen is not None
287
+ and not (isinstance (self .listen , dict ) and not self .listen )
288
+ ):
289
+ self .listen = Listen .from_dict (self .listen )
290
+
291
+ # Handle think conversion (existing pattern)
292
+ if (
293
+ not isinstance (self .think , Think )
294
+ and self .think is not None
295
+ and not (isinstance (self .think , dict ) and not self .think )
296
+ ):
297
+ self .think = Think .from_dict (self .think )
298
+
299
+ # Handle speak conversion (new OneOf pattern)
300
+ if isinstance (self .speak , list ):
301
+ # Convert list of dicts to list of Speak objects
302
+ self .speak = [
303
+ Speak .from_dict (item ) if isinstance (item , dict ) else item
304
+ for item in self .speak
305
+ ]
306
+ elif isinstance (self .speak , dict ):
307
+ # Convert single dict to Speak object
308
+ self .speak = Speak .from_dict (self .speak )
309
+ # If it's already a Speak object or None, leave it as is
310
+
288
311
def __getitem__ (self , key ):
289
312
_dict = self .to_dict ()
290
313
if "listen" in _dict and isinstance (_dict ["listen" ], dict ):
291
314
_dict ["listen" ] = Listen .from_dict (_dict ["listen" ])
292
315
if "think" in _dict and isinstance (_dict ["think" ], dict ):
293
316
_dict ["think" ] = Think .from_dict (_dict ["think" ])
294
- if "speak" in _dict and isinstance (_dict ["speak" ], dict ):
295
- _dict ["speak" ] = Speak .from_dict (_dict ["speak" ])
317
+ if "speak" in _dict :
318
+ if isinstance (_dict ["speak" ], list ):
319
+ _dict ["speak" ] = [Speak .from_dict (item ) for item in _dict ["speak" ]]
320
+ elif isinstance (_dict ["speak" ], dict ):
321
+ _dict ["speak" ] = Speak .from_dict (_dict ["speak" ])
296
322
return _dict [key ]
297
323
298
324
@@ -395,7 +421,19 @@ class UpdateSpeakOptions(BaseResponse):
395
421
"""
396
422
397
423
type : str = str (AgentWebSocketEvents .UpdateSpeak )
398
- speak : Speak = field (default_factory = Speak )
424
+ speak : Union [Speak , List [Speak ]] = field (default_factory = Speak )
425
+
426
+ def __post_init__ (self ):
427
+ """Handle conversion of dict/list data to proper Speak objects"""
428
+ if isinstance (self .speak , list ):
429
+ # Convert list of dicts to list of Speak objects
430
+ self .speak = [
431
+ Speak .from_dict (item ) if isinstance (item , dict ) else item
432
+ for item in self .speak
433
+ ]
434
+ elif isinstance (self .speak , dict ):
435
+ # Convert single dict to Speak object
436
+ self .speak = Speak .from_dict (self .speak )
399
437
400
438
401
439
# InjectAgentMessage
0 commit comments