§
    ÚŽ’jÛM  ã                   óª   — d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZmZmZmZmZmZmZmZ  G d
„ de¦  «        Z G d„ de¦  «        ZdS )ad  The xAI formatter module.

This formatter converts AgentScope ``Msg`` objects into the protobuf
``Message`` objects expected by the ``xai_sdk`` gRPC client.  Unlike every
other formatter, the ``format()`` method returns a list of
``chat_pb2.Message`` proto objects rather than plain dicts, because the
``xai_sdk`` chat API accepts proto messages directly.
é    N)ÚAnyÚList)ÚFieldé   )ÚFormatterBaseé   )Úlogger)	ÚMsgÚ	TextBlockÚThinkingBlockÚToolCallBlockÚToolResultBlockÚ	DataBlockÚ	URLSourceÚBase64SourceÚ	HintBlockc                   ó˜   — e Zd ZU dZ eg d¢d¬¦  «        Zee         ed<   dee	         de
dee
         fd	„Zd
ede
defd„Zde
defd„ZdS )ÚXAIChatFormattera•  Formatter for the xAI chat model.

    Converts ``Msg`` objects into ``xai_sdk`` protobuf ``Message`` objects
    that can be appended directly to a ``xai_sdk`` chat session.

    Unlike other formatters whose ``format()`` returns ``list[dict]``, this
    formatter returns ``list[chat_pb2.Message]``.  The type annotation is
    intentionally widened to ``list[Any]`` to accommodate this difference.
    ©z
text/plainz
image/jpegz	image/pngúUThe supported input types. Defaults to ``["text/plain", "image/jpeg", "image/png"]``.©ÚdefaultÚdescriptionÚinput_typesÚmsgsÚkwargsÚreturnc           
   ‹   ó¢  K  — ddl m}m}m}m}m}m} |                      |¦  «         g }	|D �]¡}
|
                     ¦   «         }d„ |D ¦   «         }|
j	        dk    r>d 
                    d„ |D ¦   «         ¦  «        }|	                      ||¦  «        ¦  «         Œl|
j	        dk    �rðg }|D �]Î}t          |t          ¦  «        rŒt          |t          ¦  «        r�|r|	                      ||Ž ¦  «         g }t          |j        t           ¦  «        r$|	                      ||j        ¦  «        ¦  «         Œˆ|                      |j        |¦  «        }|r|	                      ||Ž ¦  «         Œ¾t          |t$          ¦  «        r|                     |j        ¦  «         Œît          |t(          ¦  «        �r£|j        j                             d¦  «        �rbt          |j        t0          ¦  «        rôt!          |j        j        ¦  «        }|                     d	¦  «        r¦|                     d	¦  «        }t7          |d
¦  «        5 }t9          j        |                     ¦   «         ¦  «                             d¦  «        }ddd¦  «         n# 1 swxY w Y   |                      |d|j        j        › d|› �¦  «        ¦  «         �Œ|                      ||¦  «        ¦  «         �Œ2t          |j        t@          ¦  «        r8|                      |d|j        j        › d|j        j!        › �¦  «        ¦  «         �Œ†tE          j#        d|j        j        ¦  «         �Œ§tE          j#        dtI          |¦  «        j%        ¦  «         �ŒÐ|r|	                      ||Ž ¦  «         �Œh|
j	        dk    �rg }g }|D �]Ð}t          |tL          ¦  «        �r}|r÷| '                    ¦   «         }|j(         )                    d¦  «        |_	        |r?|j*         +                    ¦   «         }d 
                    d„ |D ¦   «         ¦  «        |_        g }|D ]h}|j,         +                    ¦   «         }|j-        |_-        |j.         )                    d¦  «        |_$        |j/        |j0        _/        |j1        |j0        _2        Œi|	                     |¦  «         g }nC|rAd 
                    d„ |D ¦   «         ¦  «        }|r|	                      ||¦  «        ¦  «         g }|  3                    |j4        ¦  «        }|	                      |||j-        ¬¦  «        ¦  «         �Œ–t          |tj          ¦  «        r|                     |¦  «         �ŒÂt          |t$          ¦  «        r|                     |¦  «         �Œît          |t          ¦  «        r�Œt          |t          ¦  «        �rµ|s|�r<|r÷| '                    ¦   «         }|j(         )                    d¦  «        |_	        |r?|j*         +                    ¦   «         }d 
                    d„ |D ¦   «         ¦  «        |_        g }|D ]h}|j,         +                    ¦   «         }|j-        |_-        |j.         )                    d¦  «        |_$        |j/        |j0        _/        |j1        |j0        _2        Œi|	                     |¦  «         g }nC|rAd 
                    d„ |D ¦   «         ¦  «        }|r|	                      ||¦  «        ¦  «         g }t          |j        t           ¦  «        r%|	                      ||j        ¦  «        ¦  «         �Œ›|                      |j        |¦  «        }|r|	                      ||Ž ¦  «         �ŒÒ|rö| '                    ¦   «         }|j(         )                    d¦  «        |_	        |r?|j*         +                    ¦   «         }d 
                    d„ |D ¦   «         ¦  «        |_        g }|D ]h}|j,         +                    ¦   «         }|j-        |_-        |j.         )                    d¦  «        |_$        |j/        |j0        _/        |j1        |j0        _2        Œi|	                     |¦  «         �ŒD|r?d 
                    d„ |D ¦   «         ¦  «        }|r|	                      ||¦  «        ¦  «         �Œ‡tE          j#        d|
j	        ¦  «         �Œ£|	S )að  Convert a list of ``Msg`` objects to ``xai_sdk`` proto messages.

        Args:
            msgs (`list[Msg]`):
                A list of ``Msg`` objects representing the conversation.
            **kwargs (`Any`):
                Unused; retained for interface compatibility.

        Returns:
            `list[Any]`:
                A list of ``chat_pb2.Message`` proto objects, ready to be
                appended to a ``xai_sdk`` chat session via
                ``chat.append()``.
        r   )Ú	assistantÚimageÚsystemÚtool_resultÚuserÚchat_pb2c                 ó<   — g | ]}t          |t          ¦  «        ¯|‘ŒS © )Ú
isinstancer   ©Ú.0Úbs     úQC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\formatter\_xai_formatter.pyú
<listcomp>z+XAIChatFormatter.format.<locals>.<listcomp>U   s'   € ÐIÐIÐI µ
¸1½iÑ0HÔ0HÐI˜1ÐIÐIÐIó    r!   ú
c              3   ó$   K  — | ]}|j         V — Œd S ©N©Útextr(   s     r+   ú	<genexpr>z*XAIChatFormatter.format.<locals>.<genexpr>X   s$   è è € Ð =Ð =¨A ¤Ð =Ð =Ð =Ð =Ð =Ð =r-   r#   úimage/úfile://Úrbúutf-8Núdata:ú;base64,zoUnsupported media type %s for xAI API. Only image/jpeg and image/png are supported. This block will be skipped.z3Unsupported block type %s in user message, skipped.r   ÚROLE_ASSISTANTc              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>«   s5   è è € ð 3"ð 3"Ø/0 A¤Fð3"ð 3"ð 3"ð 3"ð 3"ð 3"r-   ÚTOOL_CALL_TYPE_CLIENT_SIDE_TOOLc              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>º   s$   è è € Ð,JÐ,J¸¨Q¬VÐ,JÐ,JÐ,JÐ,JÐ,JÐ,Jr-   )Útool_call_idc              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>Û   s5   è è € ð 7&ð 7&Ø34¨¬ð7&ð 7&ð 7&ð 7&ð 7&ð 7&r-   c              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>ì   s$   è è € Ð0NÐ0N¸A°´Ð0NÐ0NÐ0NÐ0NÐ0NÐ0Nr-   c              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>  s$   è è € Ð*HÐ*H°a¨1¬6Ð*HÐ*HÐ*HÐ*HÐ*HÐ*Hr-   c              3   ó$   K  — | ]}|j         V — Œd S r0   r1   r(   s     r+   r3   z*XAIChatFormatter.format.<locals>.<genexpr>  s$   è è € Ð$BÐ$B° Q¤VÐ$BÐ$BÐ$BÐ$BÐ$BÐ$Br-   z'Unsupported message role '%s', skipped.)6Úxai_sdk.chatr   r    r!   r"   r#   r$   Úassert_list_of_msgsÚget_content_blocksÚroleÚjoinÚappendr'   r   r   ÚhintÚstrÚ_xai_user_args_from_blocksr   r2   r   ÚsourceÚ
media_typeÚ
startswithr   ÚurlÚremoveprefixÚopenÚbase64Ú	b64encodeÚreadÚdecoder   Údatar	   ÚwarningÚtypeÚ__name__r   ÚMessageÚMessageRoleÚValueÚcontentÚaddÚ
tool_callsÚidÚToolCallTypeÚnameÚfunctionÚinputÚ	argumentsÚ_extract_result_textÚoutputr   )Úselfr   r   r   r    r!   r"   r#   r$   Úxai_messagesÚmsgÚblocksÚtext_blocksr2   Úcontent_argsÚblockÚ	hint_argsÚurl_strÚ
local_pathÚfÚencodedÚpending_textÚpending_tool_callsÚ	msg_protoÚcÚtcÚproto_tcÚoutput_texts                               r+   ÚformatzXAIChatFormatter.format2   sV
  è è € ð&	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	× Ò  Ñ&Ô&Ð&à"$ˆàð E	ñ E	ˆCØ×+Ò+Ñ-Ô-ˆFàIÐI fÐIÑIÔIˆKàŒx˜8Ò#Ð#Ø—y’yÐ =Ð =°Ð =Ñ =Ô =Ñ=Ô=�Ø×#Ò# F F¨4¡L¤LÑ1Ô1Ð1Ð1à”˜VÒ#Ñ#Ø%'�Ø#ð :ñ :�EÝ! %­Ñ7Ô7ð 9ØÝ# E­9Ñ5Ô5ð 7Ø'ð .Ø(×/Ò/°°°lÐ0CÑDÔDÐDØ+-˜LÝ% e¤jµ#Ñ6Ô6ð FØ(×/Ò/°°°U´ZÑ0@Ô0@ÑAÔAÐAÐAà(,×(GÒ(GØ %¤
Ø %ñ)ô )˜Ið  )ð FØ ,× 3Ò 3°D°D¸)Ð4DÑ EÔ EÐ EøÝ# E­9Ñ5Ô5ð *Ø$×+Ò+¨E¬JÑ7Ô7Ð7Ð7Ý# E­9Ñ5Ô5ñ (Ø œ<Ô2×=Ò=¸hÑGÔGñ !Ý)¨%¬,½	ÑBÔBð "Ý*-¨e¬lÔ.>Ñ*?Ô*? Ø#*×#5Ò#5°iÑ#@Ô#@ð !Hà18×1EÒ1EØ(1ñ2&ô 2& Jõ *.¨j¸$Ñ)?Ô)?ð %:À1Ý28Ô2BØ,-¯FªF©H¬Hñ3*ô 3*ç*0ª&°©/¬/ð )0ð%:ð %:ð %:ñ %:ô %:ð %:ð %:ð %:ð %:ð %:ð %:øøøð %:ð %:ð %:ð %:ð %1×$7Ò$7Ø(-¨ð-@°E´LÔ4Kð -@ð -@Ø6=ð-@ð -@ñ)*ô )*ñ%&ô %&ð %&ñ %&ð %1×$7Ò$7¸¸¸g¹¼Ñ$GÔ$GÐ$GÑ$GÝ!+¨E¬L½,Ñ!GÔ!Gð "Ø ,× 3Ò 3Ø$) Eð)F°´Ô0Gð )Fð )FØ27´,Ô2Cð)Fð )Fñ%&ô %&ñ!"ô !"ð !"ùõ #œNð!>ð !&¤Ô 7ñ	ô ð ñ õ œð'å  ™KœKÔ0ñô ð ñ ð  ð =Ø ×'Ò'¨¨¨lÐ(;Ñ<Ô<Ð<ùà”˜[Ò(Ñ(Ø02�Ø:<Ð"à#ð XFñ XF�EÝ! %­Ñ9Ô9ñ WFð .ð .Ø(0×(8Ò(8Ñ(:Ô(:˜IØ-5Ô-A×-GÒ-GØ 0ñ.ô .˜IœNð  ,ð 2Ø$-Ô$5×$9Ò$9Ñ$;Ô$; Ø)-¯ªð 3"ð 3"Ø4@ð3"ñ 3"ô 3"ñ *"ô *" ¤ð 02 Ø&8ð Gð G Ø+4Ô+?×+CÒ+CÑ+EÔ+E Ø.0¬e ¤Ø08Ô0E×0KÒ0KØ$Eñ1"ô 1" ¤ð :<¼ Ô 1Ô 6Ø>@¼h Ô 1Ô ;Ð ;Ø(×/Ò/°	Ñ:Ô:Ð:Ø13Ð.Ð.Ø)ð .Ø#'§9¢9Ð,JÐ,J¸\Ð,JÑ,JÔ,JÑ#JÔ#J˜DØ#ð EØ ,× 3Ò 3°I°I¸d±O´OÑ DÔ DÐ DØ+-˜Là&*×&?Ò&?Ø!œLñ'ô '˜ð %×+Ò+Ø'˜KØ +Ø-2¬Xðñ ô ñô ð ñ õ $ E­=Ñ9Ô9ð /FØ*×1Ò1°%Ñ8Ô8Ð8Ñ8å# E­9Ñ5Ô5ð ,FØ$×+Ò+¨EÑ2Ô2Ð2Ñ2å# E­=Ñ9Ô9ð )FÙå# E­9Ñ5Ô5ñ &FØ-ð 2°ñ 2Ø1ð 2Ø,4×,<Ò,<Ñ,>Ô,> 	Ø19Ô1E×1KÒ1KØ$4ñ2"ô 2" 	¤ð $0ð !6Ø(1Ô(9×(=Ò(=Ñ(?Ô(? AØ-1¯YªYð 7&ð 7&Ø8Dð7&ñ 7&ô 7&ñ .&ô .& A¤Fð 46 LØ*<ð 	!Kð 	!K BØ/8Ô/C×/GÒ/GÑ/IÔ/I HØ24´% H¤Kà(0Ô(=×(CÒ(CØ,Mñ)*ô )*ð %-¤Mð
 >@¼W HÔ$5Ô$:ØBDÄ( HÔ$5Ô$?Ð$?Ø ,× 3Ò 3°IÑ >Ô >Ð >Ø57Ð 2Ð 2Ø!-ð 2Ø'+§y¢yÐ0NÐ0NÀÐ0NÑ0NÔ0NÑ'NÔ'N Ø#'ð !IØ$0×$7Ò$7¸	¸	À$¹¼Ñ$HÔ$HÐ$HØ/1 Ý% e¤jµ#Ñ6Ô6ð FØ(×/Ò/°°°U´ZÑ0@Ô0@ÑAÔAÐAÑAà(,×(GÒ(GØ %¤
Ø %ñ)ô )˜Ið  )ð FØ ,× 3Ò 3°D°D¸)Ð4DÑ EÔ EÐ Eùà%ð =à (× 0Ò 0Ñ 2Ô 2�IØ%-Ô%9×%?Ò%?Ø(ñ&ô &�I”Nð $ð *Ø%Ô-×1Ò1Ñ3Ô3˜Ø!%§¢Ð*HÐ*H¸<Ð*HÑ*HÔ*HÑ!HÔ!H˜œØ')˜Ø0ð ?ð ?˜Ø#,Ô#7×#;Ò#;Ñ#=Ô#=˜Ø&(¤e˜œØ(0Ô(=×(CÒ(CØ=ñ)ô )˜œð 24´˜Ô)Ô.Ø68´h˜Ô)Ô3Ð3Ø ×'Ò'¨	Ñ2Ô2Ð2Ñ2Ø!ð =àŸ9š9Ð$BÐ$B°\Ð$BÑ$BÔ$BÑBÔB�DØð =Ø$×+Ò+¨I¨I°d©O¬OÑ<Ô<Ð<ùõ ”Ø=Ø”Hñô ð ñ ð
 Ðs   È9:I?É?JÊJrk   r    c           	      óâ  — g }|D �]è}t          |t          ¦  «        r|                     |j        ¦  «         Œ3t          |t          ¦  «        �rŸ|j        j                             d¦  «        s t          j	        d|j        j        ¦  «         Œˆt          |j        t          ¦  «        rôt          |j        j        ¦  «        }|                     d¦  «        r¦|                     d¦  «        }t          |d¦  «        5 }t          j        |                     ¦   «         ¦  «                             d¦  «        }ddd¦  «         n# 1 swxY w Y   |                      |d|j        j        › d|› �¦  «        ¦  «         �Œv|                      ||¦  «        ¦  «         �Œ–t          |j        t&          ¦  «        r8|                      |d|j        j        › d|j        j        › �¦  «        ¦  «         �Œê|S )	aÇ  Convert a list of ``TextBlock | DataBlock`` into the positional
        args expected by ``xai_sdk.chat.user(*args)``.

        DataBlocks that are not images (or use an unsupported media type)
        are dropped with a warning, matching the existing user-role
        DataBlock handling above.

        Args:
            blocks (`list`):
                The ``hint`` list from a :class:`HintBlock`.
            image (`Any`):
                The ``xai_sdk.chat.image`` constructor, passed in to keep
                the local import contract identical to ``format``.

        Returns:
            `list`:
                Positional args for ``user(*args)``; empty if nothing
                survived.
        r4   zxUnsupported media type %s for xAI API. Only image/jpeg and image/png are supported. This hint sub-block will be skipped.r5   r6   r7   Nr8   r9   )r'   r   rH   r2   r   rL   rM   rN   r	   rW   r   rJ   rO   rP   rQ   rR   rS   rT   rU   r   rV   )	rh   rk   r    ÚargsÚsubrp   rq   rr   rs   s	            r+   rK   z+XAIChatFormatter._xai_user_args_from_blocks  sG  € ð0 ˆØð "	ñ "	ˆCÝ˜#�yÑ)Ô)ð !Ø—’˜CœHÑ%Ô%Ð%Ð%Ý˜C¥Ñ+Ô+ñ Ø”zÔ,×7Ò7¸ÑAÔAð Ý”Nð?ð œ
Ô-ñ	ô ð ð Ý˜cœj­)Ñ4Ô4ð Ý! #¤*¤.Ñ1Ô1�GØ×)Ò)¨)Ñ4Ô4ð 4Ø%,×%9Ò%9¸)Ñ%DÔ%D˜
Ý! *¨dÑ3Ô3ð °qÝ&,Ô&6°q·v²v±x´xÑ&@Ô&@×&GÒ&GØ 'ñ'ô '˜Gðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ŸšØ!˜Eð!4¨¬
Ô(=ð !4ð !4Ø*1ð!4ð !4ñô ñô ð ñ ð Ÿš E E¨'¡N¤NÑ3Ô3Ð3Ñ3Ý ¤
­LÑ9Ô9ð Ø—K’KØ˜ð8 C¤JÔ$9ð 8ð 8Ø&)¤j¤oð8ð 8ñô ñô ð ùð ˆs   Ã::E Å E	ÅE	rg   c                 ó²  — |€dS t          |t          ¦  «        r|S t          |t          ¦  «        r™g }|D ]}t          |t          ¦  «        r|                     |j        ¦  «         Œ2t          |t          ¦  «        r|                     |¦  «         Œ]|                     t          |¦  «        ¦  «         Œ€d                     |¦  «        S t          |¦  «        S )aU  Extract a plain-text string from a ``ToolResultBlock`` output.

        Args:
            output (`Any`):
                The raw output of a ``ToolResultBlock``, which may be a
                string, a list of blocks, or another type.

        Returns:
            `str`:
                A plain-text representation of the output.
        NÚ r.   )r'   rJ   Úlistr   rH   r2   rG   )rh   rg   ÚpartsÚitems       r+   rf   z%XAIChatFormatter._extract_result_textY  sÔ   € ð ˆ>Ø�2Ý�f�cÑ"Ô"ð 	ØˆMÝ�f�dÑ#Ô#ð 		$ØˆEØð ,ð ,�Ý˜d¥IÑ.Ô.ð ,Ø—L’L ¤Ñ+Ô+Ð+Ð+Ý ¥cÑ*Ô*ð ,Ø—L’L Ñ&Ô&Ð&Ð&à—L’L¥ T¡¤Ñ+Ô+Ð+Ð+Ø—9’9˜UÑ#Ô#Ð#Ý�6‰{Œ{Ðr-   N)rY   Ú
__module__Ú__qualname__Ú__doc__r   r   r�   rJ   Ú__annotations__r
   r   r   r{   rK   rf   r&   r-   r+   r   r      sï   € € € € € € ðð ð #˜UØ9Ð9Ð9ðIðñ ô €K��c”ð ð ñ ðgà�3Œiðgð ðgð 
ˆcŒð	gð gð gð gðR<àð<ð ð<ð 
ð	<ð <ð <ð <ð|¨3ð °3ð ð ð ð ð ð r-   r   c                   ó¸   — e Zd ZU dZ edd¬¦  «        Zeed<    eg d¢d¬¦  «        Ze	e         ed<   d	e	e
         d
edee         fd„Zd	e	e
         dedefd„ZdS )ÚXAIMultiAgentFormatteraÆ  Formatter for the xAI chat model in multi-agent conversations.

    Produces ``xai_sdk`` protobuf ``Message`` objects (same as
    :class:`XAIChatFormatter`).  Prior agent-to-agent messages are collapsed
    into a single ``user`` message with ``<history></history>`` tags; tool
    call / result sequences are delegated to :class:`XAIChatFormatter`.

    .. note:: ``format()`` returns ``list[Any]`` (protobuf messages), not
        ``list[dict]``.
    zg# Conversation History
The content between <history></history> tags contains your conversation history
z7The prompt to use for the conversation history section.r   Úconversation_history_promptr   r   r   r   r   r   c              ‹   óJ  K  — ddl m}m} |                      |¦  «         g }d}|rK|d         j        dk    r:|d                              ¦   «         }|                      ||¦  «        ¦  «         d}d}|                      ||d…         ¦  «        2 3 d{V —†\  }	}
|	dk    rB|                     t          | j
        ¬¦  «                             |
¦  «        ƒ d{V —†¦  «         ŒR|	d	k    r9|                      |
|¬
¦  «        }|r|                      ||¦  «        ¦  «         d}Œ’6 |S )aa  Convert a list of ``Msg`` objects to ``xai_sdk`` proto messages.

        Conversation history (non-tool messages) is collapsed into a single
        ``user`` protobuf message containing ``<history></history>`` tags.
        Tool sequences are formatted by :class:`XAIChatFormatter`.

        Args:
            msgs (`list[Msg]`):
                A list of ``Msg`` objects representing the conversation.
            **kwargs (`Any`):
                Unused; retained for interface compatibility.

        Returns:
            `list[Any]`:
                A list of ``chat_pb2.Message`` proto objects.
        r   )r!   r#   r!   r   TNÚtool_sequence)r   Úagent_message)Úis_firstF)rC   r!   r#   rD   rF   Úget_text_contentrH   Ú_group_messagesÚextendr   r   r{   Ú_build_history_text)rh   r   r   r!   r#   ri   Ústart_indexr2   Úis_first_agent_messageÚtypÚgroupÚhistory_texts               r+   r{   zXAIMultiAgentFormatter.format“  s¨  è è € ð* 	.Ð-Ð-Ð-Ð-Ð-Ð-Ð-à× Ò  Ñ&Ô&Ð&à"$ˆØˆàð 	�D˜”G”L HÒ,Ð,Ø˜”7×+Ò+Ñ-Ô-ˆDØ×Ò   t¡¤Ñ-Ô-Ð-ØˆKà!%ÐØ $× 4Ò 4°T¸+¸,¸,Ô5GÑ HÔ Hð 	/ð 	/ð 	/ð 	/ð 	/ð 	/ð 	/‘*�#�uØ�oÒ%Ð%Ø×#Ò#Ý*Ø$(Ô$4ðñ ô ç’f˜U‘m”mð$ð $ð $ð $ð $ð $ñô ð ð ð
 ˜Ò'Ð'Ø#×7Ò7ØØ3ð  8ñ  ô  �ð  ð <Ø ×'Ò'¨¨¨\Ñ(:Ô(:Ñ;Ô;Ð;Ø).Ð&øð !Ið  Ðs   ÂD"rŽ   c                ó–  — g }|D ]˜}g }|j         r|                     |j         › d�¦  «         |                     ¦   «         D ]1}t          |t          ¦  «        r|                     |j        ¦  «         Œ2|r(|                     d                     |¦  «        ¦  «         Œ™|sdS |r| j        nd}|dz   d                     |¦  «        z   dz   S )uÕ  Build a ``<history>â€¦</history>`` text block from agent messages.

        Args:
            msgs (`list[Msg]`):
                Non-tool messages to collapse into history.
            is_first (`bool`):
                When ``True``, prepend
                :attr:`conversation_history_prompt` before the tag.

        Returns:
            `str`:
                The formatted history string, or an empty string when there
                is no text content.
        ú:ú r€   z
<history>
r.   z
</history>)rb   rH   rE   r'   r   r2   rG   rŠ   )rh   r   rŽ   Úlinesrj   r‚   rn   Úprefixs           r+   r’   z*XAIMultiAgentFormatter._build_history_textÇ  sè   € ð ˆØð 	.ð 	.ˆCØ!ˆEØŒxð -Ø—’ ¤˜^˜^˜^Ñ,Ô,Ð,Ø×/Ò/Ñ1Ô1ð -ð -�Ý˜e¥YÑ/Ô/ð -Ø—L’L ¤Ñ,Ô,Ð,øØð .Ø—’˜SŸXšX e™_œ_Ñ-Ô-Ð-øàð 	Ø�2à5=ÐE�Ô1Ð1À2ˆØ˜Ñ%¨¯	ª	°%Ñ(8Ô(8Ñ8¸>ÑIÐIr-   N)rY   r„   r…   r†   r   rŠ   rJ   r‡   r   r�   r
   r   r   r{   Úboolr’   r&   r-   r+   r‰   r‰   v  s   € € € € € € ð	ð 	ð (- uð*ð Nð(ñ (ô (Ð ð ð ñ ð #˜UØ9Ð9Ð9ðIðñ ô €K��c”ð ð ñ ð2à�3Œið2ð ð2ð 
ˆcŒð	2ð 2ð 2ð 2ðhJ¨¨S¬	ð JÀð JÈð Jð Jð Jð Jð Jð Jr-   r‰   )r†   rR   Útypingr   r   Úpydanticr   Ú_formatter_baser   Ú_loggingr	   Úmessager
   r   r   r   r   r   r   r   r   r   r‰   r&   r-   r+   ú<module>r£      sQ  ððð ð €€€Ø Ð Ð Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *Ø Ð Ð Ð Ð Ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ðUð Uð Uð Uð U�}ñ Uô Uð Uðp
oJð oJð oJð oJð oJ˜]ñ oJô oJð oJð oJð oJr-   