ó
    ±"³jÀ„ ã            
      óâ"  • % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
JrJr  S SKJrJrJrJr  S SKJr  S SKJrJrJrJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(  S SK)J*r*  S SK+r+S SK,r,S SK-J.r/  S SK0J1r1  S SK2Jr3  S SK4J5r5J6r6J7r7  S SK8J9r9  SSK:J;r;J<r<  SSK=J>r?J@rAJBrCJDrEJFrGJHrIJJrKJLrMJNrOJPrQ  SSKRJSrSJTrT  SSK<JUrVJWrX  SSKYJZrZJ[r[J\r\  SSK]J^r^  \(       a  SSK_J`r`  Sra\" 5       rb\bRÇ                  5         \RÈ                   H6  re\RÌ                  RÏ                  \e5      (       d  M%  \bRÑ                  \e5        M8     \bRÓ                  SS5        \bRÓ                  SS5        \bRÓ                  SS 5        \bRÓ                  S!S"5        \bRÓ                  S!S#5        \bRÓ                  S$S%5        \bRÓ                  S&S'5        \bRÓ                  S(S)5        \bRÓ                  S*S+5        \bRÓ                  S,S-5        \bRÓ                  S.S/5        \bRÓ                  S0S15        \bRÓ                  S2S35        \bRÓ                  S4S55        \bRÓ                  S6S75        \bRÓ                  S8S95        \bRÓ                  S:S;5        \bRÓ                  S:S<5        \bRÓ                  S=S>5        \bRÓ                  S?S@5        \#SA   rjSB\kSC'   \#SD   rlSB\kSE'   \#SF   rmSB\kSG'   \#SH   rnSB\kSI'   \#SJ   roSB\kSK'   \#SL   rpSB\kSM'   \#SN   rqSB\kSO'   \#SP   rrSB\kSQ'   \#SR   rsSB\kSS'    \#ST   rtSB\kSU'    \#SV   ruSB\kSW'    \v\#SX   -  rwSB\kSY'        GS†SZ jrx\\y\z\ 4   \\y\z\ 4   S-  /\y\z\ 4   4   -  S-  \+Rö                  " \x\y\z\ 4   S-  S[S\94   r|SB\kS]'    \" S^S_9 " S` Sa5      5       r}GS‡Sb jr~\3" S^\+Rþ                  " ScSd9Se9 " Sf Sg\5      5       r€\3" S^\+Rþ                  " ScSd9Se9 " Sh Si\€5      5       r�\3" S^\+Rþ                  " ScSd9Se9 " Sj Sk\€5      5       r‚\3" S^\+Rþ                  " ScSd9Se9 " Sl Sm\€5      5       rƒ\3" S^\+Rþ                  " ScSd9Se9 " Sn So\€5      5       r„\" S^S_9 " Sp Sq5      5       r…\3" S^\+Rþ                  " SrSrSs9Se9 " St Su5      5       r†\3" S^\+Rþ                  " SrSrSs9Se9 " Sv Sw\†5      5       r‡\3" S^\+Rþ                  " SrSrSs9Se9 " Sx Sy\†5      5       rˆ\ " Sz S{5      5       r‰\#S|   rŠSB\kS}'    \3" S^\+Rþ                  " ScSd9Se9 " S~ S5      5       r‹\\ƒ\‚-  \„-  \�-  \\†\+GR                  " \†GR                  5      4   -  \‹-  \+GR                  " S€5      4   r� \ƒ\‚\„\�\†\‹4r�S�\kS‚'   \ƒGR"                  \‚GR"                  \„GR"                  \�GR"                  4r’Sƒ\kS„'    GSˆS… jr“\z\…-  \�-  \‰-  r”SB\kS†'    \z\…/\�Q\‰P7r•S�\kS‡'   Sˆr–\6" S‰\ SŠ9r— \" S^S_9 " S‹ SŒ\"\—   5      5       r˜S�SŽS�S�S‘S’S“S”S•SF.	r™S–\kS—'   S˜S™SšS›SœS�Sž.ršSŸ\kS '   S¡S¢S£S¤SD.r›S¥\kS¦'   S§S¨S©SªS«S¬S­S®SH.rœS¯\kS°'   S±S²S³S´.r�Sµ\kS¶'   GS‰S· jrž        GSŠS¸ jrŸ\" S^S_9 " S¹ Sº5      5       r S»r¡ \+GRD                  " \ \+Rþ                  " ScSrSrS¼9S½9r£S¾\kS¿'    " SÀ SÁ5      r¤ " SÂ SÃ5      r¥\(       a  \�\\    -  \\z\ 4   -  \ -  r¦SB\kSÄ'   O;\5" SÄ\\\z\¤4   \\�\¥4   -  \\zSÄ4   -  \SÄ   -  \ -  \+GRN                  " SÅSÆ94   5      r¦\+GRD                  " \¦\+Rþ                  " ScSÇ9S½9r¨SÈ\kSÉ'    \#SÊ   r©SB\kSË'    \'" \©5      rªSÌ\kSÍ'   GS‹SÎ jr«SÏr¬ GSŒSÐ jr­\" S^S_9 " SÑ SÒ5      5       r®\" S^S_9 " SÓ SÔ\®5      5       r¯\" S^S_9 " SÕ SÖ\®5      5       r°\+GRD                  " \±\,GRd                     \+Rþ                  " ScSÇ9S½9r³\" S^S_9 " S× SØ5      5       r´\" ScS^SÙ9 " SÚ SÛ5      5       rµ\" ScS^SÙ9 " SÜ SÝ5      5       r¶\" ScS^SÙ9 " SÞ Sß5      5       r·\µ\¶-  \·-  r¸SB\kSà'    \" ScS^SÙ9 " Sá Sâ5      5       r¹GS�Sã jrºGSŽSä jr»\\¹S-  \+GRx                  " \º5      \+Rö                  " \»\zS-  S[S\94   r½SB\kSå'    \" S^S_9 " Sæ Sç5      5       r¾\" S^ScSè9 " Sé Sê5      5       r¿\" S^S_9 " Së Sì5      5       rÀ\" S^S_9 " Sí Sî5      5       rÁ\" S^S_9 " Sï Sð5      5       rÂSñrÃ \" S^S_9 " Sò Só5      5       rÄ\" S^S_9 " Sô Sõ5      5       rÅ\" S^ScSè9 " Sö S÷5      5       rÆ\" S^S_9 " Sø Sù5      5       rÇ\" S^S_9 " Sú Sû\Ç5      5       rÈ\" S^S_9 " Sü Sý\Ç5      5       rÉ0 rÊSþ\kSÿ'   0 rËGS \kGS'   0 rÌGS\kGS'   0 rÍGS\kGS'   \6" GSSùGS9rÎ\6" GSSÒGS9rÏ        GS�GS	 jrÐ        GS�GS
 jrÑ0 rÒGS\kGS'    0 rÓGS\kGS'    SGSKÔJÕrÕJÖrÖ  SGSK×JØrØJÙrÙJÚrÚJÛrÛJÜrÜJÝrÝJÞrÞ  GS‘GS jrß\\\}\+GRÀ                  " GS5      4   \\ \+GRÀ                  " GS5      4   -  \\Æ\+GRÀ                  " GS5      4   -  \\Þ\+GRÀ                  " GS5      4   -  \\Ö\+GRÀ                  " GS5      4   -  \\¯\+GRÀ                  " GS5      4   -  \\´\+GRÀ                  " GS5      4   -  \\¿\+GRÀ                  " GS5      4   -  \+GR                  " \ß5      4   rá GS’GS jrâGS‘GS jrã\\\Á\+GRÀ                  " GS5      4   \\Û\+GRÀ                  " GS5      4   -  \\Õ\+GRÀ                  " GS5      4   -  \\È\+GRÀ                  " GS5      4   -  \\Ø\+GRÀ                  " GS 5      4   -  \\É\+GRÀ                  " GS!5      4   -  \\Ù\+GRÀ                  " GS"5      4   -  \\°\+GRÀ                  " GS#5      4   -  \\Â\+GRÀ                  " GS$5      4   -  \\Ä\+GRÀ                  " GS%5      4   -  \\Å\+GRÀ                  " GS&5      4   -  \\Æ\+GRÀ                  " GS5      4   -  \+GR                  " \ã5      4   rä \" S^S_9 " GS' GS(5      5       råGS“GS) jræ\\À\å-  \+GR                  " S€5      4   rç \+GRD                  " \±\ç   \+Rþ                  " ScSrSrS¼9S½9rè GS”GS* jréS^GS+.       GS•GS, jjrê      GS–GS- jrëGS—GS. jrìGS˜GS/ jríGS”GS0 jrî\6" GS1\€GS9rï GS”GS2 jrðScS^GS3GS4S^GS4GS5.               GS™GS6 jjrñ        GSšGS7 jrò                  GS›GS8 jró                GSœGS9 jrô        GS�GS: jrõ                GSžGS; jrö                GSŸGS< jr÷\" S^S_9 " GS= GS>5      5       rø\" S^ScSè9 " GS? GS@5      5       rù\" S^ScSè9 " GSA GSB5      5       rú\" S^ScSè9 " GSC GSD5      5       rû\\ø\ù-  \ú-  \û-  \+GR                  " GSE5      4   rü \" S^ScSè9 " GSF GSG5      5       rý\" S^ScSè9 " GSH GSI5      5       rþ\" S^ScSè9 " GSJ GSK5      5       rÿ\" S^ScSè9 " GSL GSM5      5       Gr \\ý\þ-  \ÿ-  G\ -  \+GR                  " GSN5      4   Gr \" S^ScSè9 " GSO GSP5      5       Gr\" S^S_9 " GSQ GSR5      5       Gr\" S^S_9 " GSS GSTG\5      5       Gr\" S^S_9 " GSU GSVG\5      5       Gr\" S^S_9 " GSW GSX5      5       Gr\" S^S_9 " GSY GSZG\5      5       Gr\" S^ScSè9 " GS[ GS\5      5       Gr\" S^S_9 " GS] GS^G\5      5       Gr	SGS_GK
GJGrGJGr  \" S^S_9 " GS` GSa5      5       Gr\" S^S_9 " GSb GSc5      5       Gr\" S^S_9 " GSd GSe5      5       Gr\" S^S_9 " GSf GSg5      5       Gr\" S^S_9 " GSh GSi5      5       Gr\" S^S_9 " GSj GSk5      5       Gr\" S^S_9 " GSl GSm5      5       Gr\" S^S_9 " GSn GSo5      5       Gr\" S^S_9 " GSp GSq5      5       Gr\" S^S_9 " GSr GSs5      5       Gr\" S^S_9 " GSt GSu5      5       Gr\G\G\-  G\-  G\-  G\	-  G\-  G\-  \+GR                  " GSN5      4   Gr \AG\GSv      " 5       GrGSw\kGSx'    \" S^ScSè9 " GSy GSv5      5       Gr\" S^ScSè9 " GSz GS{G\S^GS|95       GrG\" GS} \GR<                  " G\5       5       5      Gr \AG\GS~      " 5       Gr GS\kGS€'    GS GS� jGr!\" S^ScSè9 " GS‚ GS~5      5       Gr"\" S^ScSè9 " GSƒ GS„G\"S^GS|95       Gr#G\" GS… \GR<                  " G\#5       5       5      Gr$ \G\G\-  G\-  G\-  G\-  G\-  G\-  G\-  G\-  \+GR                  " GSN5      4   Gr% \G\G\-  G\-  G\%-  G\-  G\"-  \+GR                  " GSN5      4   Gr&g(¡  é    )ÚannotationsN)ÚABCÚabstractmethod)ÚCallableÚ
CollectionÚMappingÚSequence)Údeepcopy)ÚKW_ONLYÚ	dataclassÚfieldÚreplace)Údatetime)Ú	MimeTypes)ÚPathLike)ÚPath)ÚTYPE_CHECKINGÚ	AnnotatedÚAnyÚClassVarÚGenericÚLiteralÚ	TypeAliasÚ	TypeGuardÚcastÚget_argsÚoverload)Úurlparse)Útypes)Úto_snake)r   )ÚTypeAliasTypeÚTypeVarÚassert_never)Úcalculate_price_for_usageé   )Ú_otel_messagesÚ_utils)
ÚRESERVED_EVENT_TAGSÚEventRegistryÚevent_family_schemaÚguard_post_initÚinherited_namespaceÚinject_tag_fieldÚis_redefinitionÚkeeps_canonical_registrationÚshadowed_envelope_fieldsÚundecorated_field_base)Úredact_binary_contentÚserialize_any)Úgenerate_tool_call_idÚnow_utc)Ú
ModelRetryÚUnexpectedModelBehaviorÚ	UserError)ÚRequestUsage)ÚInstrumentationSettingsÚINVALID_JSONzapplication/rtfz.rtfúAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetz.xlsxúGapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentz.docxútext/markdownz.mdxz.mdztext/x-asciidocz	.asciidocú
image/webpz.webpú
video/3gppz	.three_gpúvideo/x-matroskaz.mkvúvideo/x-ms-wmvz.wmvúvideo/x-flvz.flvú	audio/aacz.aacú
audio/aiffz.aiffú
audio/flacz.flacú	audio/oggz.ogaú	audio/wavz.wavzapplication/yamlz.yamlz.ymlzapplication/tomlz.tomlzapplication/xmlz.xml)rH   ú
audio/mpegrG   rF   rE   rD   r   ÚAudioMediaType)z
image/jpegz	image/pngz	image/gifr?   ÚImageMediaType)	zapplication/pdfz
text/plainztext/csvr=   r<   z	text/htmlr>   zapplication/mswordzapplication/vnd.ms-excelÚDocumentMediaType)rA   zvideo/quicktimeú	video/mp4z
video/webmrC   z
video/mpegrB   r@   ÚVideoMediaType)ÚwavÚmp3ÚogaÚflacÚaiffÚaacÚAudioFormat)ÚjpegÚpngÚgifÚwebpÚImageFormat)	ÚcsvÚdocÚdocxÚhtmlÚmdÚpdfÚtxtÚxlsÚxlsxÚDocumentFormat)	ÚmkvÚmovÚmp4ÚwebmÚflvÚmpegÚmpgÚwmvÚthree_gpÚVideoFormat)ÚstopÚlengthÚcontent_filterÚ	tool_callÚerrorÚFinishReason)ÚcompleteÚ
incompleteÚ	suspendedÚinterruptedÚModelResponseState)ru   rx   ÚModelRequestStatezallow-localÚForceDownloadModec                ó(   • [        U 5      (       a  g U $ ©N)Úcallable©Úvalues    ÚQ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/messages.pyÚ!_serialize_provider_details_deltar‚   ½   s   € ô �‡�ØØ€Ló    Újson)Úreturn_typeÚ	when_usedÚProviderDetailsDeltaF)Úreprc                  óŠ   • \ rS rSr% SrS\S'    S\S'   \" \S9rS\S	'    S
r	S\S'    Sr
S\S'    SS jr\R                  rSrg
)ÚSystemPromptPartéÐ   zA system prompt, generally written by the application developer.

This gives the model context and guidance on how to respond.
ÚstrÚcontentr   Ú_©Údefault_factoryr   Ú	timestampNú
str | NoneÚdynamic_refúsystem-promptzLiteral['system-prompt']Ú	part_kindc                óx   • [         R                  " SSS0UR                  (       a  SU R                  0D6/$ 0 D6/$ )NÚtypeÚtextr�   © )r&   ÚTextPartÚinclude_contentr�   )ÚselfÚsettingss     r�   Úotel_message_partsÚ#SystemPromptPart.otel_message_partsè   s<   € Ü×'Ò'Ñu¨VÐuÐT\×Tl×Tl¸	À4Ç<Á<Ð7PÑuÐvÐvÐrtÑuÐvÐvrƒ   r™   ©r�   r:   Úreturnz list[_otel_messages.MessagePart])Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r   Ú_now_utcr‘   r“   r•   rž   r'   Údataclasses_no_defaults_reprÚ__repr__Ú__static_attributes__r™   rƒ   r�   rŠ   rŠ   Ð   sZ   ‡ ñð
 ƒLØ$àƒJá°Ñ9€IˆxÓ9Ø&à"€K�Ó"ðð
 +:€IÐ'Ó9ØRôwð ×2Ñ2ƒHrƒ   rŠ   c                óš   • [        U [        5      (       a  U R                  S5      n [        R                  " U SS9R                  5       SS $ )zqGenerate stable identifier for multi-modal content to help LLM in finding a specific file in tool call responses.zutf-8F)ÚusedforsecurityNé   )Ú
isinstancerŒ   ÚencodeÚhashlibÚsha1Ú	hexdigest)Ú
identifiers    r�   Ú_multi_modal_content_identifierrµ   î   s@   € ä�*œc×"Ñ"Ø×&Ñ& wÓ/ˆ
Ü�<Š<˜
°EÑ:×DÑDÓFÀrÈÐJÐJrƒ   T)Úvalidate_by_name)rˆ   Úconfigc                  óh  • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
rS\S'    \" SS
S9r	S\S'   \" SS
S9r
S\S'   S
S
SS
S
S
S.               SS jjr\R                  \SS j5       5       r\R                  \SS j5       5       r\SS j5       r\\SS j5       5       r\R*                  rSrg
)ÚFileUrléõ   z+Abstract base class for any URL-based file.rŒ   Úurlr   rŽ   Fr{   Úforce_downloadNúdict[str, Any] | NoneÚvendor_metadata©ÚcompareÚdefaultúUAnnotated[str | None, pydantic.Field(alias='media_type', default=None, exclude=True)]Ú_media_typeúUAnnotated[str | None, pydantic.Field(alias='identifier', default=None, exclude=True)]Ú_identifier)Ú
media_typer´   r¼   r¾   rÃ   rÅ   c               ó   • g r}   r™   )rœ   r»   rÆ   r´   r¼   r¾   rÃ   rÅ   s           r�   Ú__init__ÚFileUrl.__init__  s   € ð rƒ   c                óH   • U R                   =(       d    U R                  5       $ )zQReturn the media type of the file, based on the URL or the provided `media_type`.)rÃ   Ú_infer_media_type©rœ   s    r�   rÆ   ÚFileUrl.media_type)  s   € ð ×Ñ×; 4×#9Ñ#9Ó#;Ð;rƒ   c                óR   • U R                   =(       d    [        U R                  5      $ )aÅ  The identifier of the file, such as a unique ID.

This identifier can be provided to the model in a message to allow it to refer to this file in a tool call argument,
and the tool can look up the file in question by iterating over the message history and finding the matching `FileUrl`.

This identifier is only automatically passed to the model when the `FileUrl` is returned by a tool.
If you're passing the `FileUrl` as a user message, it's up to you to include a separate text part with the identifier,
e.g. "This is file <identifier>:" preceding the `FileUrl`.

It's also included in inline-text delimiters for providers that require inlining text documents, so the model can
distinguish multiple files.
)rÅ   rµ   r»   rÌ   s    r�   r´   ÚFileUrl.identifier/  s   € ð ×Ñ×LÔ#BÀ4Ç8Á8Ó#LÐLrƒ   c                ó   • [         e)z2Infer the media type of the file based on the URL.©ÚNotImplementedErrorrÌ   s    r�   rË   ÚFileUrl._infer_media_type@  s
   € ô "Ð!rƒ   c                ó   • [         e)zThe file format.rÑ   rÌ   s    r�   ÚformatÚFileUrl.formatE  s
   € ô "Ð!rƒ   r™   )r»   rŒ   rÆ   r’   r´   r’   r¼   r{   r¾   r½   rÃ   r’   rÅ   r’   r¡   ÚNone©r¡   rŒ   )r¢   r£   r¤   r¥   r¦   r§   r¼   r¾   r   rÃ   rÅ   rÈ   ÚpydanticÚcomputed_fieldÚpropertyrÆ   r´   r   rË   rÕ   r'   r©   rª   r«   r™   rƒ   r�   r¹   r¹   õ   sV  ‡ á5à	ƒHØàƒJà(-€NÐ%Ó-ðð .2€OÐ*Ó1ðñ joØ˜tñj€KÐfó ñ joØ˜tñj€KÐfó ð "&Ø!%Ø,1Ø15à"&Ø"&ñàðð ð	ð
 ðð *ðð /ðð  ðð  ðð 
õð ×ÑØó<ó ó ð<ð ×ÑØóMó ó ðMð ó"ó ð"ð Øó"ó ó ð"ð ×2Ñ2ƒHrƒ   r¹   c                  ó²   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
S
SS
SS
S
S.                 SS jjrSS jr\	SS j5       r
\	SS j5       rSrg
)ÚVideoUrliN  zA URL to a video.rŒ   r»   r   rŽ   ú	video-urlúLiteral['video-url']ÚkindNF©rÆ   r´   r¼   r¾   rà   rÃ   rÅ   c               ó   • g r}   r™   ©	rœ   r»   rÆ   r´   r¼   r¾   rà   rÃ   rÅ   s	            r�   rÈ   ÚVideoUrl.__init__\  ó   € ð rƒ   c                ó¤   • U R                   (       a  g[        R                  U R                  5      u  pUc  [	        SU R                   S35      eU$ )z5Return the media type of the video, based on the url.rM   z+Could not infer media type from video URL: ú,. Explicitly provide a `media_type` instead.)Ú
is_youtubeÚ_mime_typesÚ
guess_typer»   Ú
ValueError©rœ   Ú	mime_typerŽ   s      r�   rË   ÚVideoUrl._infer_media_typej  sP   € ð
 �?�?Øä"×-Ñ-¨d¯h©hÓ7‰ˆ	ØÑÜØ=¸d¿h¹h¸ZÐGsÐtóð ð Ðrƒ   c                óF   • [        U R                  5      R                  S;   $ )zÈTrue if the URL is on a YouTube host that models can resolve directly.

This is a specific set of hosts rather than every YouTube-owned domain, so
`music.youtube.com` is deliberately not one of them.
)zyoutu.bezyoutube.comzwww.youtube.comzm.youtube.com)r   r»   ÚhostnamerÌ   s    r�   rè   ÚVideoUrl.is_youtubey  s   € ô ˜Ÿ™Ó!×*Ñ*Ð.mÑmÐmrƒ   c                ó(   • [         U R                     $ )z‘The file format of the video.

The choice of supported formats were based on the Bedrock Converse API. Other APIs don't require to use a format.
)Ú_video_format_lookuprÆ   rÌ   s    r�   rÕ   ÚVideoUrl.format‡  ó   € ô $ D§O¡OÑ4Ð4rƒ   r™   )r»   rŒ   rÆ   r’   r´   r’   r¼   r{   r¾   r½   rà   rß   rÃ   r’   rÅ   r’   r¡   r×   rØ   ©r¡   Úbool)r¡   rn   )r¢   r£   r¤   r¥   r¦   r§   rà   rÈ   rË   rÛ   rè   rÕ   r«   r™   rƒ   r�   rÝ   rÝ   N  sÃ   ‡ áà	ƒHØàƒJà!,€DÐ
Ó,ØMð "&Ø!%Ø,1Ø15Ø%0à"&Ø"&ñàðð ð	ð
 ðð *ðð /ðð #ðð  ðð  ðð 
õôð ónó ðnð ó5ó ó5rƒ   rÝ   c                  óž   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
S
SS
SS
S
S.                 SS jjrSS jr\	SS j5       r
Srg
)ÚAudioUrli�  zA URL to an audio file.rŒ   r»   r   rŽ   ú	audio-urlúLiteral['audio-url']rà   NFrá   c               ó   • g r}   r™   rã   s	            r�   rÈ   ÚAudioUrl.__init__ž  rå   rƒ   c                ó€   • [         R                  U R                  5      u  pUc  [        SU R                   S35      eU$ )z�Return the media type of the audio file, based on the url.

References:
- Gemini: https://ai.google.dev/gemini-api/docs/audio#supported-formats
z+Could not infer media type from audio URL: rç   ©ré   rê   r»   rë   rì   s      r�   rË   ÚAudioUrl._infer_media_type¬  sF   € ô #×-Ñ-¨d¯h©hÓ7‰ˆ	ØÑÜØ=¸d¿h¹h¸ZÐGsÐtóð ð Ðrƒ   c                ó(   • [         U R                     $ )z"The file format of the audio file.)Ú_audio_format_lookuprÆ   rÌ   s    r�   rÕ   ÚAudioUrl.format¹  s   € ô $ D§O¡OÑ4Ð4rƒ   r™   )r»   rŒ   rÆ   r’   r´   r’   r¼   r{   r¾   r½   rà   rû   rÃ   r’   rÅ   r’   r¡   r×   rØ   )r¡   rU   ©r¢   r£   r¤   r¥   r¦   r§   rà   rÈ   rË   rÛ   rÕ   r«   r™   rƒ   r�   rù   rù   �  s­   ‡ á!à	ƒHØ$àƒJà!,€DÐ
Ó,ØMð "&Ø!%Ø,1Ø15Ø%0à"&Ø"&ñàðð ð	ð
 ðð *ðð /ðð #ðð  ðð  ðð 
õôð ó5ó ó5rƒ   rù   c                  óž   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
S
SS
SS
S
S.                 SS jjrSS jr\	SS j5       r
Srg
)ÚImageUrli¿  zA URL to an image.rŒ   r»   r   rŽ   ú	image-urlúLiteral['image-url']rà   NFrá   c               ó   • g r}   r™   rã   s	            r�   rÈ   ÚImageUrl.__init__Í  rå   rƒ   c                ó€   • [         R                  U R                  5      u  pUc  [        SU R                   S35      eU$ )z5Return the media type of the image, based on the url.z+Could not infer media type from image URL: rç   rÿ   rì   s      r�   rË   ÚImageUrl._infer_media_typeÛ  sD   € ä"×-Ñ-¨d¯h©hÓ7‰ˆ	ØÑÜØ=¸d¿h¹h¸ZÐGsÐtóð ð Ðrƒ   c                ó(   • [         U R                     $ )z‘The file format of the image.

The choice of supported formats were based on the Bedrock Converse API. Other APIs don't require to use a format.
)Ú_image_format_lookuprÆ   rÌ   s    r�   rÕ   ÚImageUrl.formatä  rõ   rƒ   r™   )r»   rŒ   rÆ   r’   r´   r’   r¼   r{   r¾   r½   rà   r  rÃ   r’   rÅ   r’   r¡   r×   rØ   )r¡   rZ   r  r™   rƒ   r�   r  r  ¿  s­   ‡ áà	ƒHØàƒJà!,€DÐ
Ó,ØMð "&Ø!%Ø,1Ø15Ø%0à"&Ø"&ñàðð ð	ð
 ðð *ðð /ðð #ðð  ðð  ðð 
õôð ó5ó ó5rƒ   r  c                  óž   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
S
SS
SS
S
S.                 SS jjrSS jr\	SS j5       r
Srg
)ÚDocumentUrlií  zThe URL of the document.rŒ   r»   r   rŽ   zdocument-urlúLiteral['document-url']rà   NFrá   c               ó   • g r}   r™   rã   s	            r�   rÈ   ÚDocumentUrl.__init__û  rå   rƒ   c                ó€   • [         R                  U R                  5      u  pUc  [        SU R                   S35      eU$ )z8Return the media type of the document, based on the url.z.Could not infer media type from document URL: rç   rÿ   rì   s      r�   rË   ÚDocumentUrl._infer_media_type	  sD   € ä"×-Ñ-¨d¯h©hÓ7‰ˆ	ØÑÜØ@ÀÇÁÀ
ÐJvÐwóð ð Ðrƒ   c                óp   • U R                   n [        U   $ ! [         a  n[        SU 35      UeSnAff = f)z”The file format of the document.

The choice of supported formats were based on the Bedrock Converse API. Other APIs don't require to use a format.
zUnknown document media type: N)rÆ   Ú_document_format_lookupÚKeyErrorrë   ©rœ   rÆ   Úes      r�   rÕ   ÚDocumentUrl.format  sF   € ð —_‘_ˆ
ð	RÜ*¨:Ñ6Ð6øÜó 	RÜÐ<¸Z¸LÐIÓJÐPQÐQûð	Rús   Ž —
5¡0°5r™   )r»   rŒ   rÆ   r’   r´   r’   r¼   r{   r¾   r½   rà   r  rÃ   r’   rÅ   r’   r¡   r×   rØ   )r¡   rd   r  r™   rƒ   r�   r  r  í  s¯   ‡ á"à	ƒHØ"àƒJà$2€DÐ
!Ó2ØMð "&Ø!%Ø,1Ø15Ø(6à"&Ø"&ñàðð ð	ð
 ðð *ðð /ðð &ðð  ðð  ðð 
õôð ó	Ró ó	Rrƒ   r  c                  óh   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
rS\S'    \R                  r
Srg)ÚTextContenti  zµString content that is tagged with additional metadata.

This is useful for including metadata that can be accessed programmatically by the application, but is not sent to the LLM.
rŒ   r�   r   rŽ   Nr   Úmetadataztext-contentzLiteral['text-content']rà   r™   )r¢   r£   r¤   r¥   r¦   r§   r  rà   r'   r©   rª   r«   r™   rƒ   r�   r  r    s@   ‡ ñð
 ƒLØ.àƒJà€HˆcÓðð %3€DÐ
!Ó2ØMà×2Ñ2ƒHrƒ   r  Úbase64)Úser_json_bytesÚval_json_bytesc                  ó¸  • \ rS rSr% SrS\S'    S\S'   S\S'    S	rS
\S'    \" SS	S9rS\S'   Sr	S\S'    S	S	SS	S.             S!S jjr
\S"S j5       r\S#S j5       r\S$S j5       r\R"                  \S%S j5       5       r\S%S j5       r\S%S j5       r\S&S j5       r\S&S j5       r\S&S j5       r\S&S j5       r\S%S j5       r\R8                  rS rg	)'ÚBinaryContenti9  z,Binary content, e.g. an audio or image file.ÚbytesÚdatar   rŽ   ú9AudioMediaType | ImageMediaType | DocumentMediaType | strrÆ   Nr½   r¾   Fr¿   rÄ   rÅ   ÚbinaryúLiteral['binary']rà   ©r´   r¾   rà   rÅ   c               ó   • g r}   r™   ©rœ   r&  rÆ   r´   r¾   rà   rÅ   s          r�   rÈ   ÚBinaryContent.__init__b  ó   € ð rƒ   c                ó�   • U R                   (       a4  [        U R                  U R                  U R                  U R
                  S9$ U $ )zINarrow the type of the `BinaryContent` to `BinaryImage` if it's an image.)r&  rÆ   r´   r¾   )Úis_imageÚBinaryImager&  rÆ   r´   r¾   )Úbcs    r�   Únarrow_typeÚBinaryContent.narrow_typen  s=   € ð �;�;ÜØ—W‘WØŸ=™=ØŸ=™=Ø "× 2Ñ 2ñ	ð ð ˆIrƒ   c                ó  • SnUR                  U5      (       d  [        S5      eU[        U5      S nSU;  a  [        S5      eUR                  SS5      u  pEU R	                  U " [
        R                  " U5      US95      $ )z)Create a `BinaryContent` from a data URI.údata:z Data URI must start with "data:"Nú;base64,z<Data URI must be base64-encoded (expected ";base64," marker)r%   ©r&  rÆ   )Ú
startswithrë   ÚlenÚsplitr3  r   Ú	b64decode)ÚclsÚdata_uriÚprefixÚbodyrÆ   r&  s         r�   Úfrom_data_uriÚBinaryContent.from_data_uri{  s~   € ð ˆØ×"Ñ" 6×*Ñ*ÜÐ?Ó@Ð@Øœ˜F›˜Ð&ˆØ˜TÓ!ÜÐ[Ó\Ð\ØŸ:™: j°!Ó4Ñˆ
Ø�‰™s¬×(8Ò(8¸Ó(>È:ÑVÓWÐWrƒ   c                óÞ   • [        U5      nUR                  5       (       d  [        SU 35      e[        R	                  U5      u  p#Uc  SnU R                  U " UR                  5       US95      $ )záCreate a `BinaryContent` from a path.

Defaults to 'application/octet-stream' if the media type cannot be inferred.

Raises:
    FileNotFoundError: if the file does not exist.
    PermissionError: if the file cannot be read.
zFile not found: úapplication/octet-streamr8  )r   ÚexistsÚFileNotFoundErrorré   rê   r3  Ú
read_bytes)r=  ÚpathrÆ   rŽ   s       r�   Ú	from_pathÚBinaryContent.from_path‡  se   € ô �D‹zˆØ�{‰{�}‰}Ü#Ð&6°t°fÐ$=Ó>Ð>Ü#×.Ñ.¨tÓ4‰ˆ
ØÑØ3ˆJà�‰™s¨¯©Ó(9ÀjÑQÓRÐRrƒ   c                óR   • U R                   =(       d    [        U R                  5      $ )aä  Identifier for the binary content, such as a unique ID.

This identifier can be provided to the model in a message to allow it to refer to this file in a tool call argument,
and the tool can look up the file in question by iterating over the message history and finding the matching `BinaryContent`.

This identifier is only automatically passed to the model when the `BinaryContent` is returned by a tool.
If you're passing the `BinaryContent` as a user message, it's up to you to include a separate text part with the identifier,
e.g. "This is file <identifier>:" preceding the `BinaryContent`.

It's also included in inline-text delimiters for providers that require inlining text documents, so the model can
distinguish multiple files.
)rÅ   rµ   r&  rÌ   s    r�   r´   ÚBinaryContent.identifierš  s   € ð ×Ñ×MÔ#BÀ4Ç9Á9Ó#MÐMrƒ   c                ó:   • SU R                    SU R                   3$ )z*Convert the `BinaryContent` to a data URI.r6  r7  )rÆ   r   rÌ   s    r�   r>  ÚBinaryContent.data_uri«  s    € ð �t—‘Ð' x°·±¨}Ð=Ð=rƒ   c                ó^   • [         R                  " U R                  5      R                  5       $ )zMReturn the binary data as a base64-encoded string. Default encoding is UTF-8.)r   Ú	b64encoder&  ÚdecoderÌ   s    r�   r   ÚBinaryContent.base64°  s"   € ô ×Ò §	¡	Ó*×1Ñ1Ó3Ð3rƒ   c                ó8   • U R                   R                  S5      $ )z1Return `True` if the media type is an audio type.úaudio/©rÆ   r9  rÌ   s    r�   Úis_audioÚBinaryContent.is_audioµ  ó   € ð �‰×)Ñ)¨(Ó3Ð3rƒ   c                ó8   • U R                   R                  S5      $ )z1Return `True` if the media type is an image type.úimage/rU  rÌ   s    r�   r0  ÚBinaryContent.is_imageº  rX  rƒ   c                ó8   • U R                   R                  S5      $ )z0Return `True` if the media type is a video type.úvideo/rU  rÌ   s    r�   Úis_videoÚBinaryContent.is_video¿  rX  rƒ   c                ó(   • U R                   [        ;   $ )z3Return `True` if the media type is a document type.)rÆ   r  rÌ   s    r�   Úis_documentÚBinaryContent.is_documentÄ  s   € ð �‰Ô"9Ñ9Ð9rƒ   c                óX  •  U R                   (       a  [        U R                     $ U R                  (       a  [        U R                     $ U R
                  (       a  [        U R                     $ [        U R                     $ ! [         a  n[        SU R                   35      UeSnAff = f)z&The file format of the binary content.úUnknown media type: N)
rV  r  rÆ   r0  r  r^  ró   r  r  rë   )rœ   r  s     r�   rÕ   ÚBinaryContent.formatÉ  s…   € ð
	NØ�}�}Ü+¨D¯O©OÑ<Ð<Ø——Ü+¨D¯O©OÑ<Ð<Ø——Ü+¨D¯O©OÑ<Ð<ä.¨t¯©Ñ?Ð?øÜó 	NÜÐ3°D·O±OÐ3DÐEÓFÈAÐMûð	Nús(   ‚#B ¦#B Á
#B Á.B Â
B)ÂB$Â$B)r™   )r&  r%  rÆ   r'  r´   r’   r¾   r½   rà   r)  rÅ   r’   r¡   r×   )r2  r$  r¡   zBinaryContent | BinaryImage)r>  rŒ   r¡   r$  )rH  zPathLike[str]r¡   r$  rØ   rö   )r¢   r£   r¤   r¥   r¦   r§   r¾   r   rÅ   rà   rÈ   Ústaticmethodr3  ÚclassmethodrA  rI  rÙ   rÚ   rÛ   r´   r>  r   rV  r0  r^  ra  rÕ   r'   r©   rª   r«   r™   rƒ   r�   r$  r$  9  s´  ‡ ñ 7à
ƒKðð
 ƒJàIÓIØ,à-1€OÐ*Ó1ðñ joØ˜tñj€KÐfó ð '€DÐ
Ó&ØMð "&Ø15Ø"*à"&ñ
àð
ð Nð	
ð
 ð
ð /ð
ð  ð
ð  ð
ð 
õ
ð ó
ó ð
ð ó	Xó ð	Xð óSó ðSð$ ×ÑØóNó ó ðNð ó>ó ð>ð ó4ó ð4ð ó4ó ð4ð ó4ó ð4ð ó4ó ð4ð ó:ó ð:ð óNó ðNð ×2Ñ2ƒHrƒ   r$  c                  óP   • \ rS rSrSrSSSSS.             S	S jjrS rSrg)
r1  iÛ  z0Binary content that's guaranteed to be an image.Nr(  r*  c               ó   • g r}   r™   r,  s          r�   rÈ   ÚBinaryImage.__init__ç  r.  rƒ   c                ó<   • U R                   (       d  [        S5      eg )Nz>`BinaryImage` must have a media type that starts with "image/")r0  rë   rÌ   s    r�   Ú__post_init__ÚBinaryImage.__post_init__ó  ó   € Ø�}�}ÜÐ]Ó^Ð^ð rƒ   r™   )r&  r%  rÆ   zImageMediaType | strr´   r’   r¾   r½   rà   r)  rÅ   r’   r¡   r×   ©r¢   r£   r¤   r¥   r¦   rÈ   rl  r«   r™   rƒ   r�   r1  r1  Û  sd   † ñ ;ð "&Ø15Ø"*à"&ñ
àð
ð )ð	
ð
 ð
ð /ð
ð  ð
ð  ð
ð 
õ
õ_rƒ   r1  c                  óP   • \ rS rSrSrSSSSS.             S	S jjrS rSrg)
ÚBinaryAudioiø  z-Binary content that's guaranteed to be audio.Nr(  r*  c               ó   • g r}   r™   r,  s          r�   rÈ   ÚBinaryAudio.__init__  r.  rƒ   c                ó<   • U R                   (       d  [        S5      eg )Nz>`BinaryAudio` must have a media type that starts with "audio/")rV  rë   rÌ   s    r�   rl  ÚBinaryAudio.__post_init__  rn  rƒ   r™   )r&  r%  rÆ   zAudioMediaType | strr´   r’   r¾   r½   rà   r)  rÅ   r’   r¡   r×   ro  r™   rƒ   r�   rq  rq  ø  sd   † ñ 8ð "&Ø15Ø"*à"&ñ
àð
ð )ð	
ð
 ð
ð /ð
ð  ð
ð  ð
ð 
õ
õ_rƒ   rq  c                  ó8   • \ rS rSr% SrSrS\S'    SrS\S'   S	rg
)Ú
CachePointi  a¯  A cache point marker for prompt caching.

Can be inserted into UserPromptPart.content to mark cache boundaries.
Models that don't support caching will filter these out.

Supported by:

- Anthropic
- Amazon Bedrock (Converse API)
- OpenAI (GPT-5.6 models)
- OpenRouter (Anthropic and Gemini models via `OpenRouterModel`, plus OpenAI GPT-5.6 models when
  using `OpenAIChatModel` or `OpenAIResponsesModel` with `OpenRouterProvider`)
zcache-pointzLiteral['cache-point']rà   Ú5mzLiteral['5m', '1h']Úttlr™   N)	r¢   r£   r¤   r¥   r¦   rà   r§   ry  r«   r™   rƒ   r�   rw  rw    s'   ‡ ñð $1€DÐ
 Ó0ØMà#€CÐ	Ó#òrƒ   rw  )Ú	anthropicÚopenaiÚgooglezgoogle-cloudz
google-glazgoogle-vertexÚbedrockÚxaiÚUploadedFileProviderNamec                  óZ  • \ rS rSr% SrS\S'    S\S'    S\S'   S	rS
\S'    \" SS	S9rS\S'   \" SS	S9r	S\S'   Sr
S\S'    S	S	S	SS	S	S.                 SS jjr\R                  \SS j5       5       r\R                  \SS j5       5       r\SS j5       r\R&                  rSrg	)ÚUploadedFileiF  aÊ  A reference to a file uploaded to a provider's file storage by ID.

This allows referencing files that have been uploaded via provider-specific file APIs
rather than providing the file content directly.

Supported by:

- [`AnthropicModel`][pydantic_ai.models.anthropic.AnthropicModel]
- [`OpenAIChatModel`][pydantic_ai.models.openai.OpenAIChatModel]
- [`OpenAIResponsesModel`][pydantic_ai.models.openai.OpenAIResponsesModel]
- [`BedrockConverseModel`][pydantic_ai.models.bedrock.BedrockConverseModel]
- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] (Gemini API: [Files API](https://ai.google.dev/gemini-api/docs/files) URIs, Google Cloud: GCS `gs://` URIs)
- [`XaiModel`][pydantic_ai.models.xai.XaiModel]
rŒ   Úfile_idr  Úprovider_namer   rŽ   Nr½   r¾   Fr¿   rÂ   rÃ   rÄ   rÅ   zuploaded-fileúLiteral['uploaded-file']rà   )rÆ   r¾   r´   rà   rÃ   rÅ   c               ó   • g r}   r™   )	rœ   r‚  rƒ  rÆ   r¾   r´   rà   rÃ   rÅ   s	            r�   rÈ   ÚUploadedFile.__init__‚  rå   rƒ   c                ó¶   • U R                   b  U R                   $ [        U R                  5      n[        R	                  UR
                  5      u  p#U=(       d    S$ )a›  Return the media type of the file, inferred from `file_id` if not explicitly provided.

Note: Inference relies on the file extension in `file_id`.
For opaque file IDs (e.g., `'file-abc123'`), the media type will default to `'application/octet-stream'`.
Inference relies on Python's `mimetypes` module, whose results may vary across platforms.

Required by some providers (e.g., Bedrock) for certain file types.
rD  )rÃ   r   r‚  ré   rê   rH  )rœ   Úparsedrí   rŽ   s       r�   rÆ   ÚUploadedFile.media_type�  sL   € ð ×ÑÑ'Ø×#Ñ#Ð#Ü˜$Ÿ,™,Ó'ˆÜ"×-Ñ-¨f¯k©kÓ:‰ˆ	Ø×6Ð6Ð6rƒ   c                óR   • U R                   =(       d    [        U R                  5      $ )aJ  The identifier of the file, such as a unique ID.

This identifier can be provided to the model in a message to allow it to refer to this file in a tool call argument,
and the tool can look up the file in question by iterating over the message history and finding the matching `UploadedFile`.

This identifier is only automatically passed to the model when the `UploadedFile` is returned by a tool.
If you're passing the `UploadedFile` as a user message, it's up to you to include a separate text part with the identifier,
e.g. "This is file <identifier>:" preceding the `UploadedFile`.
)rÅ   rµ   r‚  rÌ   s    r�   r´   ÚUploadedFile.identifier¡  s   € ð ×Ñ×PÔ#BÀ4Ç<Á<Ó#PÐPrƒ   c                ó*  • U R                   n UR                  S5      (       a	  [        U   $ UR                  S5      (       a	  [        U   $ UR                  S5      (       a	  [        U   $ [
        U   $ ! [         a  n[        SU 35      UeSnAff = f)zèA general-purpose media-type-to-format mapping.

Maps media types to format strings (e.g. `'image/png'` -> `'png'`). Covers image, video,
audio, and document types. Currently used by Bedrock, which requires explicit format strings.
rZ  r]  rT  rd  N)rÆ   r9  r  ró   r  r  r  rë   r  s      r�   rÕ   ÚUploadedFile.format¯  s™   € ð —_‘_ˆ
ð
	IØ×$Ñ$ X×.Ñ.Ü+¨JÑ7Ð7Ø×&Ñ& x×0Ñ0Ü+¨JÑ7Ð7Ø×&Ñ& x×0Ñ0Ü+¨JÑ7Ð7ä.¨zÑ:Ð:øÜó 	IÜÐ3°J°<Ð@ÓAÀqÐHûð	Iús(   ŽA4 ­A4 ÁA4 Á+A4 Á4
BÁ>BÂBr™   )r‚  rŒ   rƒ  r  rÆ   r’   r¾   r½   r´   r’   rà   r„  rÃ   r’   rÅ   r’   r¡   r×   rØ   )r¢   r£   r¤   r¥   r¦   r§   r¾   r   rÃ   rÅ   rà   rÈ   rÙ   rÚ   rÛ   rÆ   r´   rÕ   r'   r©   rª   r«   r™   rƒ   r�   r�  r�  F  sY  ‡ ñð ƒLðð ,Ó+ðð ƒJà-1€OÐ*Ó1ðñ joØ˜tñj€KÐfó ñ joØ˜tñj€KÐfó ð &5€DÐ
"Ó4ØMð "&Ø15Ø!%Ø)8à"&Ø"&ñàðð 0ðð
 ðð /ðð ðð 'ðð  ðð  ðð 
õð ×ÑØó7ó ó ð7ð ×ÑØó
Qó ó ð
Qð óIó ðIð& ×2Ñ2ƒHrƒ   r�  rà   ztuple[type, ...]ÚMULTI_MODAL_CONTENT_TYPESztuple[str, ...]Ú_FILE_URL_KINDSc                ó"   • [        U [        5      $ )zBCheck if obj is a MultiModalContent type, enabling type narrowing.)r¯   rŽ  )Úobjs    r�   Úis_multi_modal_contentr’  Ú  s   € ä�cÔ4Ó5Ð5rƒ   ÚUserContentÚ_USER_CONTENT_TYPESz€Serialize the value yourself before passing it, e.g. with Pydantic (`pydantic_core.to_json()`) or `pydantic_ai.format_as_xml()`.Ú_ToolReturnValueT)rÁ   c                  ó†   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS
\S'    SrS\S'    Sr	S\S'   \
R                  rSrg)Ú
ToolReturniô  u  A structured tool return that separates the tool result from additional content sent to the model.

Can be parameterized with a type to enable return schema generation:
- `ToolReturn[User]` â€” generates a return schema for `User`
- `ToolReturn` (bare) â€” no return schema generated
ÚToolReturnContentÚreturn_valuer   rŽ   Nú"str | Sequence[UserContent] | Noner�   r   r  zlist[str] | NoneÚtoolsútool-returnúLiteral['tool-return']rà   r™   )r¢   r£   r¤   r¥   r¦   r§   r�   r  r›  rà   r'   r©   rª   r«   r™   rƒ   r�   r—  r—  ô  s^   ‡ ñð $Ó#Ø;àƒJà26€GÐ/Ó6ðð €HˆcÓØPà"€EÐÓ"ðð $1€DÐ
 Ó0à×2Ñ2ƒHrƒ   r—  r`   ra   r[   r]   rc   r^   r_   r\   rb   zdict[str, DocumentFormat]r  rP   rO   rR   rQ   rS   rT   )rI   rH   rF   rG   rE   rD   zdict[str, AudioFormat]r  rV   rW   rX   rY   zdict[str, ImageFormat]r  re   rf   rg   rh   ri   rj   rl   rm   zdict[str, VideoFormat]ró   ÚimageÚaudioÚvideo)r  rú   rÞ   z-dict[str, Literal['image', 'audio', 'video']]Ú_kind_to_modality_lookupc                óŽ   • U R                  S5      (       a  gU R                  S5      (       a  gU R                  S5      (       a  gg)zCInfer modality from media type for OTel GenAI semantic conventions.rZ  rž  rT  rŸ  r]  r   N)r9  )rÆ   s    r�   Ú_infer_modality_from_media_typer£  F  sA   € à×Ñ˜X×&Ñ&ØØ	×	Ñ	˜x×	(Ñ	(ØØ	×	Ñ	˜x×	(Ñ	(ØØrƒ   c                óR  • UR                   S:¼  aU  [        R                  " SU S9n[        U 5      nUb  XCS'   UR                  (       a  UR
                  (       a
  U" 5       US'   U$ [        R                  " SU S9nUR                  (       a  UR
                  (       a
  U" 5       US'   U$ )z=Convert binary content to OTel message part based on version.é   Úblob)r—   rí   Úmodalityr�   r(  )r—   rÆ   )Úversionr&   ÚBlobPartr£  r›   Úinclude_binary_contentÚBinaryDataPart)rÆ   Úbase64_contentr�   Ú	blob_partr§  Úconverted_parts         r�   Ú_convert_binary_to_otel_partr¯  Q  s—   € ð ×Ñ˜1ÓÜ"×+Ò+°À:ÑNˆ	Ü2°:Ó>ˆØÑØ$,�jÑ!Ø×#×#¨×(G×(GÙ#1Ó#3ˆI�iÑ ØÐä'×6Ò6¸HÐQ[Ñ\ˆØ×#×#¨×(G×(GÙ(6Ó(8ˆN˜9Ñ%ØÐrƒ   c                  ó„   • \ rS rSr% SrS\S'    S\S'   \" \S9rS\S	'    S
r	S\S'    SS jr
SS jr\R                  rSrg)ÚUserPromptPartid  a  A user prompt, generally written by the end user.

Content comes from the `user_prompt` parameter of [`Agent.run`][pydantic_ai.agent.AbstractAgent.run],
[`Agent.run_sync`][pydantic_ai.agent.AbstractAgent.run_sync], and [`Agent.run_stream`][pydantic_ai.agent.AbstractAgent.run_stream].
zstr | Sequence[UserContent]r�   r   rŽ   r�   r   r‘   úuser-promptzLiteral['user-prompt']r•   c           	     ó¢  • U R                   n[        U[        5      (       a  g [        U[        5      (       a  [        U[        [
        -  5      (       a(  [        S[        U5      R                   S[         35      e[        U5       HE  u  p#[        U[        5      (       a  M  [        SU S[        U5      R                   S[         35      e   g )NzT`UserPromptPart.content` must be a `str` or a sequence of `UserContent` items, got `z`. z`UserPromptPart.content[z&]` must be a `UserContent` item, got `)r�   r¯   rŒ   r	   r%  Ú	bytearrayrë   r—   r¢   Ú_NOT_USER_CONTENTÚ	enumerater”  )rœ   r�   ÚindexÚitems       r�   rl  ÚUserPromptPart.__post_init__w  sÅ   € ð —,‘,ˆÜ�gœs×#Ñ#Øô ˜'¤8×,Ñ,´
¸7ÄEÌIÑDU×0VÑ0VÜðÜ˜W›×.Ñ.Ð/¨sÔ3DÐ2EðGóð ô % WÖ-‰KˆEÜ˜dÔ$7×8Ó8Ü Ø.¨u¨gð 6Ü  ›J×/Ñ/Ð0°Ô4EÐ3FðHóð ò .rƒ   c           	     óÔ  • / n[        U R                  [        5      (       a  U R                  /OU R                  nU GH•  n[        U[        [        -  5      (       aa  [        U[        5      (       a  UOUR                  nUR	                  [
        R                  " SSS0UR                  (       a  SU0O0 D65        M�  [        U[        [        -  [        -  [        -  5      (       aá  UR                  S:¼  a~  [
        R                  " SS9n[        R                  UR                   5      nUb  XvS'    UR"                  US'   UR                  (       a  UR&                  US'   UR	                  U5        GM9  UR	                  [
        R(                  " SSUR                   0UR                  (       a  S	UR&                  0O0 D65        GMŒ  [        U[*        5      (       a-  UR	                  [-        UR"                  U4S
 jU5      5        GMÎ  [        U[.        5      (       a}  UR"                  R1                  SS5      S   nUS;   a  UnOSn[
        R2                  " SXtR"                  S9n	UR                  (       a  UR4                  U	S'   UR	                  U	5        GM`  [        U[6        5      (       a  GMx  UR	                  SUR                   05        GM˜     U$ ! [$         a     GN¤f = f)Nr—   r˜   r�   r¥  Úuri)r—   r§  rí   r»   c                ó   • U R                   $ r}   ©r   ©Úps    r�   Ú<lambda>Ú3UserPromptPart.otel_message_parts.<locals>.<lambda>¯  s   € ÐZ[×ZbÒZbrƒ   Ú/r%   r   )rž  rŸ  r   ÚdocumentÚfile)r—   r§  rí   r‚  r™   )r¯   r�   rŒ   r  Úappendr&   rš   r›   r  rù   r  rÝ   r¨  ÚUriPartr¡  Úgetrà   rÆ   rë   r»   ÚMediaUrlPartr$  r¯  r�  r;  ÚFilePartr‚  rw  )
rœ   r�   Úpartsr�   ÚpartÚcontent_strÚuri_partr§  ÚcategoryÚ	file_parts
             r�   rž   Ú!UserPromptPart.otel_message_parts�  sX  € Ø24ˆÜ;EÀdÇlÁlÔTW×;XÑ;X¨$¯,©,©Ð^b×^jÑ^jˆÜˆDÜ˜$¤¤kÑ 1×2Ñ2Ü&0°´s×&;Ñ&;™dÀÇÁ�Ø—‘Ü"×+Ò+ñ Ø#ðØDL×D\×D\¨°KÑ(@Ðbdñöô
 ˜D¤(¬XÑ"5¼Ñ"CÄhÑ"N×OÑOØ×#Ñ# qÓ(Ü-×5Ò5¸5ÑA�HÜ7×;Ñ;¸D¿I¹IÓF�HØÑ+Ø/7 Ñ,ðØ04·±˜ Ñ-ð  ×/×/Ø*.¯(©(˜ ™Ø—L‘L ×*à—L‘LÜ&×3Ò3ñ Ø!%§¡ðà3;×3K×3K˜u d§h¡hÑ/ÐQSñ÷ô ˜D¤-×0Ñ0Ø—‘Ô9¸$¿/¹/ÐTXÓKbÐdlÓm×nÜ˜D¤,×/Ñ/ð  Ÿ?™?×0Ñ0°°aÓ8¸Ñ;�ØÐ:Ó:Ø'‘Hà)�HÜ*×3Ò3¸È(×^mÑ^mÑn�	Ø×+×+Ø+/¯<©<�I˜iÑ(Ø—‘˜Y×'Ü˜D¤*×-Ñ-âà—‘˜f d§i¡iÐ0×1ñ] ð^ ˆøô? &ó Úðús   Ä3KË
K'Ë&K'r™   N©r¡   r×   r    )r¢   r£   r¤   r¥   r¦   r§   r   r¨   r‘   r•   rl  rž   r'   r©   rª   r«   r™   rƒ   r�   r±  r±  d  sO   ‡ ñð )Ó(Ø$àƒJá°Ñ9€IˆxÓ9Ø&à(5€IÐ%Ó5ØRôô02ðh ×2Ñ2ƒHrƒ   r±  r™  )Údefer_buildr!  r"  )r·   zpydantic.TypeAdapter[Any]Útool_return_tac                  ó8   • \ rS rSrSr\      SS j5       rSrg)Ú_StrPassthroughiÎ  uÞ  The `str` arm of `ToolReturnContent`, matched entirely in Rust in both validation modes.

Strings dominate the node count of a typical structured tool return, and every node of one
crosses this union, so `str` is checked before the container arms. It is not a micro-optimisation:
without it a string falls through all four remaining arms, measured at ~14x slower in
`validate_python`. That figure is Rust-side arm-walking, so no frame count can pin it; what guards
the arm against deletion is the `dump_json` leg of
`test_tool_return_content_json_paths_make_no_per_node_python_calls`.

`is_instance_schema` leaves `str` subclasses (a `StrEnum` returned by a tool, say) as they are,
where pydantic's `str` validator would coerce them to a plain `str`; it can't run against JSON,
where a strict `str` schema is exact anyway.

Not `pydantic.InstanceOf[str]`, which builds the same validator but also attaches a wrap
serializer â€” reintroducing a Python call per string node on the dump path.
c                ó¶   • [         R                  R                  [         R                  R                  SS9[         R                  R	                  [
        5      S9$ )NT)Ústrict©Újson_schemaÚpython_schema)Úpydantic_coreÚcore_schemaÚjson_or_python_schemaÚ
str_schemaÚis_instance_schemarŒ   )r=  Ú_source_typeÚ_handlers      r�   Ú__get_pydantic_core_schema__Ú,_StrPassthrough.__get_pydantic_core_schema__à  sM   € ô ×(Ñ(×>Ñ>Ü%×1Ñ1×<Ñ<ÀDÐ<ÐIÜ'×3Ñ3×FÑFÄsÓKð ?ð 
ð 	
rƒ   r™   N)rà  r   rá  úpydantic.GetCoreSchemaHandlerr¡   úpydantic_core.CoreSchema)r¢   r£   r¤   r¥   r¦   rg  râ  r«   r™   rƒ   r�   rÕ  rÕ  Î  s3   † ñð" ð
Øð
Ø*Gð
à	!ó
ó ó
rƒ   rÕ  c                  óL   • \ rS rSrSr\      SS j5       r\SS j5       rSr	g)	Ú_RequireUrlMediaTypeiê  u,  The `MultiModalContent` arm of `ToolReturnContent`, with an explicit `media_type` required of its URL items.

A tool return is arbitrary user data, so this arm has to separate a multimodal item we serialized
from a mapping a tool happened to build. For the four [`FileUrl`][pydantic_ai.messages.FileUrl]
kinds, `media_type` draws that line, because those are the items whose media type the URL alone
cannot always supply: `FileUrl.media_type` infers one from the URL when it was given none, and a
URL with no usable extension raises `Could not infer media type` â€” on the *dump*, not on the load
that built the object, so a history that had loaded cleanly could no longer be saved
([issue #4190](https://github.com/pydantic/pydantic-ai/issues/4190)). An item reconstructed here
brings its own media type and never reaches that inference, and a URL mapping without one was
never dumped by us: it stays a plain `Mapping` and reaches the caller with the keys its tool put
in it.

Nothing is required of the other two kinds, which cannot fail that way and so keep rehydrating
from the fields they declare: `media_type` is a required field on `BinaryContent`, and
`UploadedFile.media_type` falls back to `application/octet-stream` instead of raising.

The requirement is a *non-empty* string. `FileUrl` infers whenever `_media_type` is falsy, so `''`
would reconstruct an item that raises on dump after all, and no dump of ours writes one.

The check is chained onto each URL choice of the tagged union rather than written as a validator,
because any Python callable on this union is called once per node of the decoded payload â€” the cost
[issue #7472](https://github.com/pydantic/pydantic-ai/issues/7472) was about. Chained inside the
union it costs nothing measurable: the discriminator has already read `kind` in Rust, so only a
mapping claiming one of the four URL kinds pays for it. The same check chained ahead of the union
runs on every mapping node instead, measured at 1.29x on a dict-heavy payload.

In python mode the check also admits an instance of ours, which reaches the choice as itself rather
than as a mapping, carrying whatever media type it was built with.

Making `_media_type` a required field on a copy of each dataclass schema would say the same thing
with no wrapper at all, and does not work: two core schemas for one dataclass do not reliably build
two validators, and the copy's requirement is dropped outright when no pydantic plugin is installed.

`handler` hands back the tagged union `UserContent` also uses, so the copy is what keeps the
requirement off a user prompt, which still accepts a file whose media type is inferred. The asserts
guard the two shapes the surgery reads: that the union is still discriminated on a literal tag, and
that each URL tag carries a schema of its own rather than a string aliasing another tag's.
c                ó  • [        U" U5      5      nUS   S:X  d
   US   5       e[         H\  nUS   U   n[        U[        5      (       d   U5       e[        R
                  R                  U R                  5       U/5      US   U'   M^     U$ )Nr—   ztagged-unionÚchoices)r
   r�  r¯   ÚdictrÛ  rÜ  Úchain_schemaÚ_names_a_media_type)r=  Úsource_typeÚhandlerÚschemarà   Úchoices         r�   râ  Ú1_RequireUrlMediaType.__get_pydantic_core_schema__  s•   € ô ™' +Ó.Ó/ˆØ�f‰~ Ó/Ð?°¸±Ó?Ð/ß#ˆDØ˜IÑ& tÑ,ˆFÜ˜f¤d×+Ñ+Ð3¨VÓ3Ð+Ü&3×&?Ñ&?×&LÑ&LÈc×NeÑNeÓNgÐioÐMpÓ&qˆF�9Ñ˜dÓ#ñ $ð ˆrƒ   c            	     ól  • [         R                  R                  S[         R                  R                  [         R                  R	                  SS95      0SS9n [         R                  R                  U [         R                  R                  U [         R                  R                  [        5      /SS9S9$ )	NrÆ   r%   )Ú
min_lengthÚallow)Úextra_behaviorÚleft_to_right©ÚmoderØ  )	rÛ  rÜ  Útyped_dict_schemaÚtyped_dict_fieldrÞ  rÝ  Úunion_schemarß  r¹   )Úmapping_naming_its_media_types    r�   rì  Ú(_RequireUrlMediaType._names_a_media_type  s´   € ä(5×(AÑ(A×(SÑ(Sàœm×7Ñ7×HÑHÜ!×-Ñ-×8Ñ8ÀAÐ8ÐFóðð
 #ð )Tð )
Ð%ô ×(Ñ(×>Ñ>Ø5ä'×3Ñ3×@Ñ@à1Ü!×-Ñ-×@Ñ@ÄÓIðð %ð Að ð ?ð 

ð 
	
rƒ   r™   N)rí  r   rî  rä  r¡   rå  )r¡   rå  )
r¢   r£   r¤   r¥   r¦   rg  râ  rf  rì  r«   r™   rƒ   r�   rç  rç  ê  sH   † ñ&ðP ð	Øð	Ø(Eð	à	!ó	ó ð	ð ó
ó ó
rƒ   rç  r˜  rö  )Ú
union_mode)rÒ  z'pydantic.TypeAdapter[ToolReturnContent]Útool_return_content_ta)ztool-searchzcapability-loadÚToolPartKindztuple[ToolPartKind, ...]Ú_TOOL_PART_KINDSc                ó8   ^ • [        U 4S j[         5       S5      $ )a:  Return `value` if it's a known [`ToolPartKind`][pydantic_ai.messages.ToolPartKind], else `None`.

UI adapters call this at the wire boundary to validate an untrusted client-supplied `tool_kind`
string before setting it on a part, so an unknown value degrades to `None` rather than asserting a
bogus discriminator.
c              3  ó6   >#   • U  H  oT:X  d  M
  Uv •  M     g 7fr}   r™   )Ú.0rà   r€   s     €r�   Ú	<genexpr>Ú"parse_tool_kind.<locals>.<genexpr>r  s   øé € ÐDÒ"2˜$¸e±m—‘Ò"2ùs   ƒ	�	N)Únextr  r   s   `r�   Úparse_tool_kindr  k  s   ø€ ô ÔDÕ"2ÓDÀdÓKÐKrƒ   z;The tool call was interrupted before a result was produced.c                ó–   • S[         R                  " U 5       S[         R                  " U5       S[         R                  " U5       S3S4$ )uu  The open and close tags framing one tool-produced file that has to travel on the user channel.

A provider whose tool result channel is text-only can only deliver a tool's multimodal output on
the user channel â€” the same one the end user's own uploads travel on â€” which leaves the model
unable to tell a tool attachment from something the person it is talking to attached. The tags
name the call the media came from, so tool output, which may be attacker-influenced, is no longer
presented at user trust level. `Model.prepare_messages` frames a `SystemPromptPart` a provider
can't send natively as `<system>...</system>` for the same reason.

Each file is framed on its own so that `file_id` carries the same identifier the tool result text
cross-references as "See file <identifier>.", which one set of tags around a whole call's files
could not name.

They identify rather than prove. This is prompt text like any other, so a tool can emit the
closing tag and a user can type the opening one; the attribute values are escaped, and a provider
that accepts media in its tool result channel sends it there and never renders these at all.
z<tool_result tool_name="z" tool_call_id="z" file_id="z">z</tool_result>)r^   Úescape)Ú	tool_nameÚtool_call_idÚfile_identifiers      r�   Ú_tool_result_provenance_tagsr  {  sP   € ð& #¤4§;¢;¨yÓ#9Ð":Ð:JÌ4Ï;Ê;ÐWcÓKdÐJeð fÜ—[’[ Ó1Ð2°"ð	6àðð rƒ   c                  ó¬  • \ rS rSr% SrS\S'    S\S'    \" \S9rS\S'    S	\S
'   Sr	S\S'    Sr
S\S'    \" \S9rS\S'    SrS\S'    S(S jrS)S jr\S*S j5       r\SS.S+S jj5       r\SS.S,S jj5       r\SS.     S-S jj5       rSSS.     S.S  jjrSS.S/S! jjrSS.S0S" jjrS1S# jrSS.S2S$ jjrS3S% jrS4S& jr\R6                  rS'rg)5ÚBaseToolReturnParti”  z!Base class for tool return parts.rŒ   r  r˜  r�   r�   r  r   rŽ   NúToolPartKind | NoneÚ	tool_kindr   r  r   r‘   Úsuccessz5Literal['success', 'failed', 'denied', 'interrupted']Úoutcomec                óR  • [        U R                  5      (       a  / U R                  /S4$ [        U R                  [        5      (       aO  / n/ nU R                   H7  n[        U5      (       a  UR	                  U5        M&  UR	                  U5        M9     XS4$ U R                  // S4$ )z¸Split content into non-file and file parts.

Returns:
    A 3-tuple of (`data_parts`, `file_parts`, `was_list`) where `was_list` indicates
    whether the original content was a list.
FT)r’  r�   r¯   ÚlistrÅ  )rœ   Ú	non_filesÚfilesr¿  s       r�   Ú_split_contentÚ!BaseToolReturnPart._split_contentË  s•   € ô " $§,¡,×/Ñ/Ø˜Ÿ™�~ uÐ,Ð,Ü˜Ÿ™¤d×+Ñ+Ø#%ˆIØ-/ˆEð —\”\�Ü)¨!×,Ñ,Ø—L‘L –Oà×$Ñ$ QÖ'ñ	 "ð
  TÐ)Ð)Ø—‘ˆ~˜r 5Ð(Ð(rƒ   c                óž   • U R                  5       u  pnU(       d  SU4$ [        U5      S:X  a  U(       a  [        U5      (       a  US   U4$ X4$ )zÓSplit content and unwrap single-item data lists.

Returns the unwrapped data value (or None if empty) and the file parts.
Single-item lists are unwrapped when content was scalar or when files were filtered out.
Nr%   r   )r  r:  r÷   )rœ   r&  r  Úwas_lists       r�   Ú_unwrap_dataÚBaseToolReturnPart._unwrap_dataá  sQ   € ð !%× 3Ñ 3Ó 5Ñˆ�XÞØ˜�;Ðô ˆt‹9˜‹>¦8¬t°E¯{©{Ø˜‘7˜E�>Ð!Øˆ{Ðrƒ   c                ó,   • U R                  5       u  pnU$ )znThe multimodal file parts from `content` (`ImageUrl`, `AudioUrl`, `DocumentUrl`, `VideoUrl`, `BinaryContent`).)r  )rœ   rŽ   r  s      r�   r  ÚBaseToolReturnPart.filesð  s   € ð ×)Ñ)Ó+‰ˆ�!Øˆrƒ   Úrawr÷  c               ó   • g r}   r™   )rœ   rø  s     r�   Úcontent_itemsÚ BaseToolReturnPart.content_itemsö  s   € ØY\rƒ   T©Úwrap_if_errorc               ó   • g r}   r™   ©rœ   rø  r&  s      r�   r#  r$  ù  s   € Øsvrƒ   c               ó   • g r}   r™   r(  s      r�   r#  r$  ü  s   € ð ),rƒ   ©rø  r&  c          	     ó†  • [        U R                  [        5      (       a  U R                  nOU R                  /nUS:X  a  U$ U(       aE  U R                  S:X  a5  US:X  a  U R	                  5       OU R                  5       nU/U R                  Q$ / nU H«  n[        U5      (       a  UR                  U5        M&  [        U[        5      (       a  UR                  U5        MN  US:X  a3  UR                  [        R                  USS9R                  5       5        M‡  UR                  [        R                  USSS95        M­     U$ )aØ  Return content as a flat list for iteration, with optional serialization.

Args:
    mode: Controls serialization of non-file items:
        - `'raw'`: No serialization. Returns items as-is.
        - `'str'`: Non-file items are serialized to strings via `tool_return_ta`.
          File items (`MultiModalContent`) pass through unchanged.
        - `'jsonable'`: Non-file items are serialized to JSON-compatible Python objects
          via `tool_return_ta`. File items pass through unchanged.
    wrap_if_error: Whether to wrap failed tool returns in an `{"error": ...}` object (ignored in
        `'raw'` mode). When `True` (the default), a failed return's non-file data collapses into a
        single wrapped error item so providers without a native error channel still see the failure
        explicitly; files pass through unchanged. Set this to `False` when the provider has a native
        error channel (e.g. Anthropic `is_error`) and should receive the content unwrapped.
r!  ÚfailedrŒ   T©Úby_aliasr„   ©rø  r.  )r¯   r�   r  r  Úmodel_response_strÚmodel_response_objectr  r’  rÅ  rŒ   rÓ  Ú	dump_jsonrQ  Údump_python)rœ   rø  r&  ÚitemsÚwrappedÚresultr¸  s          r�   r#  r$    s  € ô& �d—l‘l¤D×)Ñ)Ø—L‘L‰Eà—\‘\�NˆEà�5‹=ØˆLæ˜TŸ\™\¨XÓ5Ø37¸5³=�d×-Ñ-Ô/Àd×F`ÑF`ÓFbˆGØÐ)˜dŸj™jÐ)Ð)àPRˆÛˆDÜ% d×+Ñ+Ø—‘˜dÖ#Ü˜D¤#×&Ñ&Ø—‘˜dÖ#Ø˜“Ø—‘œn×6Ñ6°tÀdÐ6ÐK×RÑRÓTÖUà—‘œn×8Ñ8¸ÀFÐUYÐ8ÐZÖ[ñ ð ˆrƒ   c               ó"  • U R                  5       u  p#Uc  SnO:[        U[        5      (       a  UnO"[        R	                  USS9R                  5       nU(       a5  U R                  S:X  a%  [        R	                  SU05      R                  5       $ U$ )a1  Return a string representation of the data content for the model.

This excludes multimodal files - use `.files` to get those separately.

Args:
    wrap_if_error: Whether to wrap failed tool returns in an `{"error": ...}` object.
        Set this to `False` when the provider has a native error channel.
Ú Tr-  r,  rs   )r  r¯   rŒ   rÓ  r2  rQ  r  )rœ   r&  r€   rŽ   Úresponses        r�   r0  Ú%BaseToolReturnPart.model_response_str,  s€   € ð ×$Ñ$Ó&‰ˆØ‰=Ø‰HÜ˜œs×#Ñ#Ø‰Hä%×/Ñ/°ÀÐ/ÐE×LÑLÓNˆHæ˜TŸ\™\¨XÓ5Ü!×+Ñ+¨W°hÐ,?Ó@×GÑGÓIÐIØˆrƒ   c               óô   • U(       a!  U R                   S:X  a  SU R                  SS90$ U R                  5       u  p#Uc  0 $ [        R	                  USSS9n[
        R                  " U5      (       a  U$ [        U0$ )a·  Return a dictionary representation of the data content, wrapping non-dict types appropriately.

This excludes multimodal files - use `.files` to get those separately.
Gemini supports JSON dict return values, but no other JSON types, hence we wrap anything else in a dict.

Args:
    wrap_if_error: Whether to wrap failed tool returns in an `{"error": ...}` object.
        Set this to `False` when the provider has a native error channel.
r,  rs   Fr%  r„   Tr/  )r  r0  r  rÓ  r3  r'   Úis_str_dictÚRETURN_VALUE_KEY)rœ   r&  r€   rŽ   Újson_contents        r�   r1  Ú(BaseToolReturnPart.model_response_objectA  s~   € ö ˜TŸ\™\¨XÓ5Ø˜T×4Ñ4À5Ð4ÐIÐJÐJà×$Ñ$Ó&‰ˆØ‰=ØˆIÜ%×1Ñ1°%¸fÈtÐ1ÐTˆÜ×Ò˜l×+Ñ+ØÐä$ lÐ3Ð3rƒ   c                ó  • U R                   n[        U[        5      (       a   [        R                  " U5      n[        U[        5      (       a  [        SU5      $ [        U[        5      (       a  [        SU5      $ g! [
         a     gf = f)a�  Return `content` as structured JSON data (a `dict` or `list`), or `None` if it has none.

A JSON string is parsed; already-structured content is returned as-is; a plain/non-JSON
string, scalar, or multimodal content yields `None` (there is no structured payload). A
read-side companion to [`files`][pydantic_ai.messages.BaseToolReturnPart.files] and
[`model_response_object`][pydantic_ai.messages.BaseToolReturnPart.model_response_object]; some
UI wire formats (e.g. AG-UI) transmit tool results as JSON strings, so
[`narrow_type`][pydantic_ai.messages.ToolReturnPart.narrow_type] uses it to recover the
structured payload a typed return subclass expects.
Núdict[str, Any]z	list[Any])	r�   r¯   rŒ   rÛ  Ú	from_jsonrë   rê  r   r  )rœ   r�   s     r�   Ústructured_contentÚ%BaseToolReturnPart.structured_contentW  s}   € ð —,‘,ˆÜ�gœs×#Ñ#ðÜ'×1Ò1°'Ó:�ô �gœt×$Ñ$ÜÐ(¨'Ó2Ð2Ü�gœt×$Ñ$Ü˜ WÓ-Ð-Øøô ó Ùðús   £A< Á<
B	ÂB	c               ó  • U R                  5       u  p#nU(       d  U R                  US9/ 4$ / n/ nU R                  SSS9 Hœ  n[        U5      (       aa  UR	                  SUR
                   S35        [        U R                  U R                  UR
                  5      u  p‰UR                  X‡U	/5        Mt  [        U[        5      (       d  M‹  UR	                  U5        Mž     U(       ai  U R                  S:X  aY  SU R                  SS90n
U Vs/ s H  nSUR
                   S3PM     nn[        R                  U
/UQ5      R                  5       U4$ U(       a%  [        R                  U5      R                  5       U4$ US	   U4$ s  snf )
aZ  Build a text-only tool result with multimodal files extracted for a trailing user message.

For providers whose tool result API only accepts text. Multimodal files are referenced
by identifier in the tool result text ('See file {id}.') and included in full in the
returned file content list.

Each file is framed by `_tool_result_provenance_tags` so the model can tell it from the
user's own uploads, which travel on the same channel.

Args:
    wrap_if_error: Whether to wrap failed tool returns in an `{"error": ...}` object.
        Set this to `False` when the provider has a native error channel.
r%  rŒ   Fr*  z	See file Ú.r,  rs   r   )r  r0  r#  r’  rÅ  r´   r  r  r  Úextendr¯   rŒ   r  rÓ  r2  rQ  )rœ   r&  rŽ   r  r  Útool_content_partsÚfile_contentr¸  Úopen_tagÚ	close_tagrs   rÄ  Úfile_referencess                r�   Ú#model_response_str_and_user_contentÚ6BaseToolReturnPart.model_response_str_and_user_contentn  s~  € ð "×0Ñ0Ó2Ñˆ�(ÞØ×*Ñ*¸Ð*ÐGÈÐKÐKà(*ÐØ*,ˆà×&Ñ&¨EÀÐ&ÓGˆDÜ% d×+Ñ+Ø"×)Ñ)¨I°d·o±oÐ5FÀaÐ*HÔIÜ&BÀ4Ç>Á>ÐSW×SdÑSdÐfj×fuÑfuÓ&vÑ#�Ø×#Ñ# X°YÐ$?Ö@Ü˜D¤#×&Ó&Ø"×)Ñ)¨$Ö/ñ Hö ˜TŸ\™\¨XÓ5Ø˜d×5Ñ5ÀEÐ5ÐJÐKˆEÙJOÓPÊ%À$ ¨4¯?©?Ð*;¸1Ó=É%ˆOÐPÜ!×+Ñ+¨UÐ,E°_Ð,EÓF×MÑMÓOÐQ]Ð]Ð]ÞÜ!×+Ñ+Ð,>Ó?×FÑFÓHÈ,ÐVÐVð " !Ñ$ lÐ2Ð2ùò Qs   ÄFc                óÜ   • [         R                  " SU R                  U R                  S9nUR                  (       a/  U R
                  b"  [        [        U R
                  U5      5      US'   U/$ )NÚtool_call_response©r—   ÚidÚnamer6  )r&   ÚToolCallResponsePartr  r  r›   r�   r3   r2   ©rœ   r�   rË  s      r�   rž   Ú%BaseToolReturnPart.otel_message_parts•  sZ   € Ü×2Ò2Ø%Ø× Ñ Ø—‘ñ
ˆð ×#×#¨¯©Ñ(@Ü*Ô+@ÀÇÁÈxÓ+XÓYˆD�‰Nàˆvˆrƒ   c                ó   • U R                   SL$ )z-Return `True` if the tool return has content.N©r�   rÌ   s    r�   Úhas_contentÚBaseToolReturnPart.has_content¡  s   € à�|‰| 4Ð'Ð'rƒ   r™   )r¡   z/tuple[list[Any], list[MultiModalContent], bool])r¡   z#tuple[Any, list[MultiModalContent]])r¡   zlist[MultiModalContent])rø  zLiteral['raw']r¡   zlist[ToolReturnContent])rø  zLiteral['str']r&  r÷   r¡   zlist[str | MultiModalContent])rø  zLiteral['jsonable']r&  r÷   r¡   zlist[Any | MultiModalContent])rø  z!Literal['raw', 'str', 'jsonable']r&  r÷   r¡   zWlist[ToolReturnContent] | list[str | MultiModalContent] | list[Any | MultiModalContent])r&  r÷   r¡   rŒ   )r&  r÷   r¡   rA  )r¡   z!dict[str, Any] | list[Any] | None)r&  r÷   r¡   ztuple[str, list[UserContent]]r    rö   )r¢   r£   r¤   r¥   r¦   r§   r   Ú_generate_tool_call_idr  r  r  r¨   r‘   r  r  r  rÛ   r  r   r#  r0  r1  rC  rM  rž   rY  r'   r©   rª   r«   r™   rƒ   r�   r  r  ”  sG  ‡ á+àƒNØ/àÓØFáÐ.DÑE€L�#ÓEðð
 ƒJà%)€IÐ"Ó)ð
ð €HˆcÓØPá°Ñ9€IˆxÓ9Ø0àEN€GÐBÓNðô")ô,ð óó ðð
 Ø6;Ö\ó Ø\àØKOÖvó ØvààBFñ,Ø*ð,Ø;?ð,à	&ô,ó ð,ð
 <AÐX\ñ)Ø8ð)ØQUð)à	`õ)ðV ;?÷ ð* >B÷ 4ô,ð. LP÷ %3ôN
ô(ð ×2Ñ2ƒHrƒ   r  c                  óP   • \ rS rSr% SrS\S'   SrS\S'    \SS	.SS
 jj5       rSr	g)ÚToolReturnParti¨  zAA tool return message, this encodes the result of running a tool.r   rŽ   rœ  r�  r•   N©r  c               ó$   • [        U [        U5      $ )u#  Promote a base `ToolReturnPart` to its typed subclass when its `tool_kind` is registered.

Best-effort: returns the part unchanged when the `tool_kind` (kwarg or on the part) resolves to
no registered subclass, and strips an unsubstantiated `tool_kind` when the part's data doesn't
validate against that subclass â€” keeping it on a base part would break a
[`ModelMessagesTypeAdapter`][pydantic_ai.messages.ModelMessagesTypeAdapter] round-trip. For
direct construction; Pydantic deserialization promotes automatically via the discriminated union.
)Ú_narrow_returnÚ_TOOL_RETURN_NARROWERS©rË  r  s     r�   r3  ÚToolReturnPart.narrow_type±  s   € ô ˜dÔ$:¸IÓFÐFrƒ   r™   )rË  r]  r  r  r¡   r]  ©
r¢   r£   r¤   r¥   r¦   r§   r•   rf  r3  r«   r™   rƒ   r�   r]  r]  ¨  s/   ‡ áKàƒJà(5€IÐ%Ó5ØRàØNRö 	Gó ó	Grƒ   r]  c                  óp   • \ rS rSr% SrS\S'   SrS\S'    SrS\S	'    S
rS\S'    \	SS.SS jj5       r
Srg)ÚNativeToolReturnParti¾  a]  A tool return message from a native tool.

For native tools with a stable cross-provider shape (currently `tool_search`), a
`NativeToolReturnPart` may be promoted to a typed subclass like
[`NativeToolSearchReturnPart`][pydantic_ai.messages.NativeToolSearchReturnPart]
with a narrowed `content` `TypedDict`. See `NativeToolCallPart` for the pattern.
r   rŽ   Nr’   rƒ  r½   Úprovider_detailsúbuiltin-tool-returnzLiteral['builtin-tool-return']r•   r^  c               ó$   • [        U [        U5      $ )u)  Promote a base `NativeToolReturnPart` to its typed subclass when its `tool_kind` is registered.

Best-effort: returns the part unchanged when the `tool_kind` (kwarg or on the part) resolves to
no registered subclass, and strips an unsubstantiated `tool_kind` when the part's data doesn't
validate against that subclass â€” keeping it on a base part would break a
[`ModelMessagesTypeAdapter`][pydantic_ai.messages.ModelMessagesTypeAdapter] round-trip. For
direct construction; Pydantic deserialization promotes automatically via the discriminated union.
)r`  Ú_NATIVE_RETURN_NARROWERSrb  s     r�   r3  Ú NativeToolReturnPart.narrow_typeÙ  s   € ô ˜dÔ$<¸iÓHÐHrƒ   r™   )rË  rf  r  r  r¡   rf  )r¢   r£   r¤   r¥   r¦   r§   rƒ  rg  r•   rf  r3  r«   r™   rƒ   r�   rf  rf  ¾  sY   ‡ ñð ƒJà $€M�:Ó$ðð
 /3ÐÐ+Ó2ðnð
 1F€IÐ-ÓEØRàØTXö 	Ió ó	Irƒ   rf  c                  óØ   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    \" \S
9r	S\S'    \" \
S
9rS\S'    SrS\S'    \SSS.       SS jj5       rSS jrSS jr\R$                  rSrg)ÚRetryPromptPartié  a–  A message back to a model asking it to try again.

This can be sent for a number of reasons:

* Pydantic validation of tool arguments failed, here content is derived from a Pydantic
  [`ValidationError`][pydantic_core.ValidationError]
* a tool raised a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception
* no tool was found for the tool name
* the model returned plain text when a structured response was expected
* Pydantic validation of a structured response failed, here content is derived from a Pydantic
  [`ValidationError`][pydantic_core.ValidationError]
* an output validator raised a [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] exception
z&list[pydantic_core.ErrorDetails] | strr�   r   rŽ   Nr’   r  r�   rŒ   r  r   r‘   úretry-promptzLiteral['retry-prompt']r•   )r  r  c               ó¢   • [        U[        R                  5      (       a  UR                  SSS9OUR                  nU " XBS9nU(       a  X5l        U$ )a   Build the retry prompt for a failed tool call or output validation.

This is the exact message the model receives when the error is handled by the agent loop,
so anything else presenting the failure (e.g. instrumentation spans) must build it the same way.
F)Úinclude_urlÚinclude_context)r�   r  )r¯   rÛ  ÚValidationErrorÚerrorsÚmessager  )r=  rs   r  r  r�   rË  s         r�   Ú
from_errorÚRetryPromptPart.from_error  sO   € ô ˜%¤×!>Ñ!>×?Ñ?ð �L‰L U¸EˆLÑBà—‘ð 	ñ
 ˜7Ñ8ˆÞØ ,ÔØˆrƒ   c                ó†  • [        U R                  [        5      (       a*  U R                  c  SU R                   3nOûU R                  nOîU R                  cO  [	        U R                  5       VVs0 s H,  u  p#U[        UR                  SS5      5      S::  a  SS1OS1_M.     nnnOSS10n[        R                  U R                  USS	9n[        U R                  [        5      =(       a    [        U R                  5      S:g  n[        U R                  5       S
U(       a  SOS SUR                  5        S3nU S3$ s  snnf )z>Return a string message describing why the retry is requested.zValidation feedback:
Úlocr™   r%   ÚctxÚinputÚ__all__é   )ÚexcludeÚindentz validation errorÚsr8  z
:
```json
z
```z

Fix the errors and try again.)r¯   r�   rŒ   r  r¶  r:  rÇ  Úerror_details_tar2  r  rQ  )rœ   ÚdescriptionÚir  r}  Újson_errorsÚplurals          r�   Úmodel_responseÚRetryPromptPart.model_response(  s/  € ä�d—l‘l¤C×(Ñ(Ø�~‰~Ñ%Ø 6°t·|±|°nÐE‘à"Ÿl™l‘ð
 �~‰~Ñ%ä_hÐim×iuÑiuÔ_vôÚ_vÑW[ÐWX�A¬3¨q¯u©u°U¸BÓ/?Ó+@ÀAÓ+E˜˜wÑ'ÈEÈ7ÒRÑ_vð ñ �ð % u gÐ.�Ü*×4Ñ4°T·\±\È7Ð[\Ð4Ð]ˆKÜ §¡¬dÓ3×N¼¸D¿L¹LÓ8IÈQÑ8NˆFä�t—|‘|Ó$Ð%Ð%6¾f±sÈ"Ð6MÈ\ÐZe×ZlÑZlÓZnÐYoÐotÐuð ð �Ð?Ð@Ð@ùós   Á/3D=c                ó<  • U R                   c?  [        R                  " SSS0UR                  (       a  SU R	                  5       0D6/$ 0 D6/$ [        R
                  " SU R                  U R                   S9nUR                  (       a  U R	                  5       US'   U/$ )Nr—   r˜   r�   rP  rQ  r6  r™   )r  r&   rš   r›   r…  rT  r  rU  s      r�   rž   Ú"RetryPromptPart.otel_message_parts@  s¥   € Ø�>‰>Ñ!ä×'Ò'ñ ØðØJR×Jb×Jb Y°×0CÑ0CÓ0EÐ$Fñðð àhjñðð ô "×6Ò6Ø)Ø×$Ñ$Ø—^‘^ñˆDð ×'×'Ø!%×!4Ñ!4Ó!6��X‘à�6ˆMrƒ   r™   )rs   z*pydantic_core.ValidationError | ModelRetryr  r’   r  r’   r¡   rm  rØ   r    )r¢   r£   r¤   r¥   r¦   r§   r  r   r[  r  r¨   r‘   r•   rg  ru  r…  rž   r'   r©   rª   r«   r™   rƒ   r�   rm  rm  é  s·   ‡ ñð 4Ó3ðð ƒJà €IˆzÓ Ø7áÐ.DÑE€L�#ÓEðñ
  °Ñ9€IˆxÓ9Ø6à)7€IÐ&Ó7ØRàð
 !%Ø#'ñà9ðð ð	ð
 !ðð 
ôó ðô,Aô0ð& ×2Ñ2ƒHrƒ   rm  )Úfrozenrˆ   c                  ó:   • \ rS rSrSrSS jr\R                  rSr	g)ÚAgentInstructionSourcei\  zYThe agent's own instructions.

There is exactly one agent in scope, so it carries no id.
c                ó   • g)NÚagentr™   rÌ   s    r�   Ú__str__ÚAgentInstructionSource.__str__c  s   € Ørƒ   r™   NrØ   )
r¢   r£   r¤   r¥   r¦   rŽ  r'   r©   rª   r«   r™   rƒ   r�   r‹  r‹  \  s   † ñô
ð ×2Ñ2ƒHrƒ   r‹  c                  óF   • \ rS rSr% SrS\S'   SS jr\R                  r	Sr
g)	ÚToolsetInstructionSourceii  zA toolset with an `id`.rŒ   rR  c                ó    • SU R                    3$ )Nztoolset:©rR  rÌ   s    r�   rŽ  Ú ToolsetInstructionSource.__str__o  s   € Ø˜$Ÿ'™'˜Ð#Ð#rƒ   r™   NrØ   ©r¢   r£   r¤   r¥   r¦   r§   rŽ  r'   r©   rª   r«   r™   rƒ   r�   r‘  r‘  i  s   ‡ á!àƒGô$ð ×2Ñ2ƒHrƒ   r‘  c                  óF   • \ rS rSr% SrS\S'   SS jr\R                  r	Sr
g)	ÚCapabilityInstructionSourceiu  zA capability with an `id`.rŒ   rR  c                ó    • SU R                    3$ )Nzcapability:r“  rÌ   s    r�   rŽ  Ú#CapabilityInstructionSource.__str__{  s   € Ø˜TŸW™W˜IÐ&Ð&rƒ   r™   NrØ   r•  r™   rƒ   r�   r—  r—  u  s   ‡ á$àƒGô'ð ×2Ñ2ƒHrƒ   r—  ÚInstructionSourcec                  ób   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SS
 jr\R                  r
Srg)ÚInstructionIdi…  z`The key an instruction part is addressed by: who contributed it, and which of their parts it is.rš  Úsourcer   rŽ   Nr’   rS  c                ó|   • U R                   b  U R                   SU R                    3$ [        U R                  5      $ )NÚ:)rS  r�  rŒ   rÌ   s    r�   rŽ  ÚInstructionId.__str__‘  s2   € Ø/3¯y©yÑ/D�$—+‘+�˜a §	¡	˜{Ð+ÐZÌ#ÈdÏkÉkÓJZÐZrƒ   r™   rØ   )r¢   r£   r¤   r¥   r¦   r§   rS  rŽ  r'   r©   rª   r«   r™   rƒ   r�   rœ  rœ  …  s3   ‡ ájàÓØdàƒJà€Dˆ*ÓØgô[ð ×2Ñ2ƒHrƒ   rœ  c                ó¶  • [        U [        5      (       d  U $ U S:X  a  [        [        5       5      $ U R	                  S5      (       a!  [        [        5       U R                  S5      S9$ S[        4S[        44 H^  u  pU S3nU R	                  U5      (       d  M"  U R                  U5      R                  S5      u  pEn[        U" U5      U(       a  UOSS9s  $    g)zìRebuild a key from the string it renders to.

A namespace this version doesn't know can only come from a newer one, whose keys it has no way to
address anyway, so it reads as unaddressable rather than failing the message it arrived on.
r�  zagent:©rS  ÚtoolsetÚ
capabilityrŸ  N)	r¯   rŒ   rœ  r‹  r9  Úremoveprefixr‘  r—  Ú	partition)r€   Ú	namespacerí  r?  Ú	source_idÚ	separatorrS  s          r�   Ú_deserialize_instruction_idrª  —  sÕ   € ô �eœS×!Ñ!ØˆØ�ÓÜÔ3Ó5Ó6Ð6Ø×Ñ˜×!Ñ!ÜÔ3Ó5¸E×<NÑ<NÈxÓ<XÑYÐYà	Ô,Ð-Ø	Ô2Ð3ó#Ñˆ	ð �;˜a�ˆØ×Ñ˜F×#Ó#Ø).×);Ñ);¸FÓ)C×)MÑ)MÈcÓ)RÑ&ˆI $Ü ¡¨YÓ!7Æi¹dÐUYÑZÒZñ#ð rƒ   c                ó"   • U b  [        U 5      $ S $ r}   )rŒ   r   s    r�   Ú_serialize_instruction_idr¬  ®  s   € ØÑ*Œ3ˆu‹:Ð4°Ð4rƒ   ÚSerializedInstructionIdc                  ó°   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    S
rS\S'    S
rS\S'    Sr	S\S'    \
SS j5       r\
SS j5       r\R                  rSrg
)ÚInstructionPartiº  u”  A single instruction part with metadata about its origin.

Instructions are composed of one or more parts, each of which can be static (from a literal string)
or dynamic (from a function, template, or toolset). This distinction allows model implementations
to make intelligent caching decisions â€” e.g. Anthropic's prompt caching can cache the static prefix
while leaving dynamic instructions uncached.
rŒ   r�   r   rŽ   Fr÷   ÚdynamicNr’   rS  r­  rR  ÚinstructionzLiteral['instruction']r•   c                ó`   • SR                  S U  5       5      R                  5       =(       d    S$ )zJJoin instruction parts into a single string, separated by double newlines.ú

c              3  ó8   #   • U  H  oR                   v •  M     g 7fr}   rX  )r  r¿  s     r�   r  Ú'InstructionPart.join.<locals>.<genexpr>÷  s   é € Ð4ªe¨Ÿ9ž9ªeùó   ‚N)ÚjoinÚstrip©rÊ  s    r�   r·  ÚInstructionPart.joinô  s'   € ð �{‰{Ñ4©eÓ4Ó4×:Ñ:Ó<×DÀÐDrƒ   c                ó   • [        U S S9$ )z_Sort instruction parts with static (`dynamic=False`) before dynamic, preserving relative order.c                ó   • U R                   $ r}   )r°  r¾  s    r�   rÀ  Ú(InstructionPart.sorted.<locals>.<lambda>ü  s   € ¨1¯9ª9rƒ   ©Úkey)Úsortedr¹  s    r�   rÀ  ÚInstructionPart.sortedù  s   € ô �eÑ!4Ñ5Ð5rƒ   r™   )rÊ  úSequence[InstructionPart]r¡   r’   )rÊ  rÂ  r¡   zlist[InstructionPart])r¢   r£   r¤   r¥   r¦   r§   r°  rS  rR  r•   rf  r·  rÀ  r'   r©   rª   r«   r™   rƒ   r�   r¯  r¯  º  s�   ‡ ñð ƒLØ4àƒJà€GˆTÓðð €Dˆ*Óð	ð #'€BÐÓ&ðð& )6€IÐ%Ó5ØLàóEó ðEð ó6ó ð6ð ×2Ñ2ƒHrƒ   r¯  )rˆ   Úkw_onlyc                  óv   • \ rS rSr% Sr\" S S9rS\S'    SrS\S	'    S
r	S\S'    SS jr
\R                  rSrg)ÚToolAvailabilityDeltaParti  u?  Records that the set of tools available to the model changed at this point.

Additions only. Withdrawing a tool is not supported yet, because no provider can be told about one
without also invalidating the prompt cache this part exists to protect: Anthropic rejects a
reference to a tool the request doesn't declare, so a withdrawn tool has to leave the `tools`
array, and that is itself the invalidation. The name says *availability* rather than *addition* so
removals can join once they can be done cache-safely â€” see
https://github.com/pydantic/pydantic-ai/issues/6985.
c                 ó   • / $ r}   r™   r™   rƒ   r�   rÀ  Ú"ToolAvailabilityDeltaPart.<lambda>  s   € ¡brƒ   r�   zdAnnotated[list[str], pydantic.Field(validation_alias=pydantic.AliasChoices('tools_added', 'added'))]Útools_addedNr’   r  útool-availability-deltaz"Literal['tool-availability-delta']r•   c                óx   • SR                  S U R                   5       5      n[        R                  " SSU 3S9/$ )a  Render the change as trace content.

Tool names are recorded regardless of `include_content`: they aren't user content, they're
already visible in the request's tool definitions, and a run where the model suddenly can
call something is unreadable without them.
z, c              3  ó,   #   • U  H
  nS U 3v •  M     g7f)Ú+Nr™   )r  rS  s     r�   r  Ú?ToolAvailabilityDeltaPart.otel_message_parts.<locals>.<genexpr>$  s   é € ÐDÒ3C¨4˜a ˜v�JÒ3Cùó   ‚r˜   zTool availability changed: )r—   r�   )r·  rÈ  r&   rš   )rœ   r�   Úchangess      r�   rž   Ú,ToolAvailabilityDeltaPart.otel_message_parts  s>   € ð —)‘)ÑD°4×3CÒ3CÓDÓDˆÜ×'Ò'¨VÐ?ZÐ[bÐZcÐ=dÑeÐfÐfrƒ   r™   r    )r¢   r£   r¤   r¥   r¦   r   rÈ  r§   r  r•   rž   r'   r©   rª   r«   r™   rƒ   r�   rÅ  rÅ    sU   ‡ ññ 	™jÑ)ð ð ó *ðð  $€L�*Ó#Ø;à4M€IÐ1ÓMØRôgð ×2Ñ2ƒHrƒ   rÅ  c                  óÞ   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS
\S'    SrS\S'    Sr	S
\S'    Sr
S
\S'    SrS\S'    SrS\S'    SS jr\SS.SS jj5       r\R"                  rSrg)ÚModelRequesti*  zmA request generated by Pydantic AI and sent to a model, e.g. a message from the Pydantic AI app to the model.úSequence[ModelRequestPart]rÊ  r   rŽ   Nzdatetime | Noner‘   r’   ÚinstructionsÚrequestzLiteral['request']rà   Úrun_idÚconversation_idr½   r  ru   rz   Ústatec                óª   • U R                    HC  n[        U[        5      (       d  M  UR                  S:w  d  M,  [	        SUR                  < 35      e   g )NÚuserzE`SpeechPart` in `ModelRequest.parts` must have `speaker='user'`, got ©rÊ  r¯   Ú
SpeechPartÚspeakerrë   ©rœ   rË  s     r�   rl  ÚModelRequest.__post_init__T  sI   € Ø—J”JˆDÜ˜$¤
×+Ó+°·±ÀÕ0Fô !Ø[Ð\`×\hÑ\hÑ[kÐlóð ò	 rƒ   )rÔ  c               ó$   • U " [        U5      /US9$ )z:Create a `ModelRequest` with a single user prompt as text.)rÊ  rÔ  )r±  )r=  Úuser_promptrÔ  s      r�   Úuser_text_promptÚModelRequest.user_text_prompt]  s   € ñ œ.¨Ó5Ð6À\ÑRÐRrƒ   r™   rÑ  )rá  rŒ   rÔ  r’   r¡   rÒ  )r¢   r£   r¤   r¥   r¦   r§   r‘   rÔ  rà   rÖ  r×  r  rØ  rl  rg  râ  r'   r©   rª   r«   r™   rƒ   r�   rÒ  rÒ  *  s¤   ‡ áwà%Ó%Ø(àƒJð "&€IˆÓ%Ø?à#€L�*Ó#Ø_à(€DÐ
Ó(ØUà€FˆJÓØRà"&€O�ZÓ&ðð '+€HÐ#Ó*Ønà)€EÐÓ)ðôð ØNRö Só ðSð ×2Ñ2ƒHrƒ   rÒ  c                  ó’   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    SS jr
\R                  rSrg)rš   ie  z#A plain text response from a model.rŒ   r�   r   rŽ   Nr’   rR  rƒ  r½   rg  r˜   úLiteral['text']r•   c                ó,   • [        U R                  5      $ )z/Return `True` if the text content is non-empty.©r÷   r�   rÌ   s    r�   rY  ÚTextPart.has_content„  ó   € ä�D—L‘LÓ!Ð!rƒ   r™   rö   ©r¢   r£   r¤   r¥   r¦   r§   rR  rƒ  rg  r•   rY  r'   r©   rª   r«   r™   rƒ   r�   rš   rš   e  sf   ‡ á-àƒLØ+àƒJà€Bˆ
Óðð
 !%€M�:Ó$ðð
 /3ÐÐ+Ó2ðð "(€IˆÓ'ØRô"ð ×2Ñ2ƒHrƒ   rš   c                  ó¢   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    Sr
S\S'    SS jr\R                  rSrg)ÚThinkingParti‹  z!A thinking response from a model.rŒ   r�   r   rŽ   Nr’   rR  Ú	signaturerƒ  r½   rg  ÚthinkingúLiteral['thinking']r•   c                ó,   • [        U R                  5      $ )z3Return `True` if the thinking content is non-empty.rç  rÌ   s    r�   rY  ÚThinkingPart.has_content¸  ré  rƒ   r™   rö   )r¢   r£   r¤   r¥   r¦   r§   rR  rí  rƒ  rg  r•   rY  r'   r©   rª   r«   r™   rƒ   r�   rì  rì  ‹  sx   ‡ á+àƒLØ/àƒJà€Bˆ
Óðð
 !€IˆzÓ ð
ð !%€M�:Ó$ðð /3ÐÐ+Ó2ðð &0€IÐ"Ó/ØRô"ð ×2Ñ2ƒHrƒ   rì  Ú#pydantic_ai_standing_prompt_plantedc                  ó–   • \ rS rSr% SrSrS\S'    S\S'   SrS\S'    SrS\S	'    Sr	S
\S'    Sr
S\S'    SS jr\R                  rSrg)ÚCompactionPartiÈ  a¢  A compaction part that summarizes previous conversation history.

Compaction parts contain an opaque or readable summary of prior messages,
produced by provider-specific compaction mechanisms. They must be round-tripped
back to the same provider in subsequent requests.

For Anthropic, `content` contains a readable text summary.
For OpenAI, `content` is `None` and the encrypted data is stored in `provider_details`.
Nr’   r�   r   rŽ   rR  rƒ  r½   rg  Ú
compactionzLiteral['compaction']r•   c                ó,   • [        U R                  5      $ )z5Return `True` if the compaction content is non-empty.rç  rÌ   s    r�   rY  ÚCompactionPart.has_contentô  ré  rƒ   r™   rö   )r¢   r£   r¤   r¥   r¦   r�   r§   rR  rƒ  rg  r•   rY  r'   r©   rª   r«   r™   rƒ   r�   rô  rô  È  st   ‡ ñð €GˆZÓðð ƒJà€Bˆ
Óðð
 !%€M�:Ó$ðð /3ÐÐ+Ó2ðð (4€IÐ$Ó3ØRô"ð ×2Ñ2ƒHrƒ   rô  c                  ó’   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    SS jr
\R                  rSrg)rÉ  iû  zA file response from a model.zLAnnotated[BinaryContent, pydantic.AfterValidator(BinaryContent.narrow_type)]r�   r   rŽ   Nr’   rR  rƒ  r½   rg  rÄ  zLiteral['file']r•   c                ó@   • [        U R                  R                  5      $ )z/Return `True` if the file content is non-empty.)r÷   r�   r&  rÌ   s    r�   rY  ÚFilePart.has_content	  s   € ä�D—L‘L×%Ñ%Ó&Ð&rƒ   r™   rö   rê  r™   rƒ   r�   rÉ  rÉ  û  sg   ‡ á'àYÓYØ+àƒJà€Bˆ
Óðð
 !%€M�:Ó$ðð
 /3ÐÐ+Ó2ðð "(€IˆÓ'ØRô'ð ×2Ñ2ƒHrƒ   rÉ  c                  óÖ   • \ rS rSr% SrS\S'    SrS\S'    SrS\S	'    SrS
\S'    Sr	S\S'    Sr
S\S'    SrS\S'    SrS\S'    \SS j5       rSS jrSS jr\R$                  rSrg)rÜ  i!	  a  Spoken audio exchanged during a realtime session, paired with its transcript.

This part is a member of both [`ModelRequestPart`][pydantic_ai.messages.ModelRequestPart] and
[`ModelResponsePart`][pydantic_ai.messages.ModelResponsePart], distinguished by `speaker`:
in `ModelRequest.parts` the speaker is always `'user'`; in `ModelResponse.parts` it is always
`'assistant'`. This invariant is enforced at runtime when a message is constructed.

Standard (non-realtime) models can't consume this part directly; when history containing it is
used in an agent run, [`Model.prepare_messages`][pydantic_ai.models.Model.prepare_messages]
converts user-speaker parts to [`UserPromptPart`][pydantic_ai.messages.UserPromptPart]s and
assistant-speaker parts to [`TextPart`][pydantic_ai.messages.TextPart]s.
zLiteral['user', 'assistant']rÝ  Nr’   Ú
transcriptzBinaryContent | NonerŸ  ú
int | NoneÚinterrupted_at_msrR  rƒ  r½   rg  ÚspeechúLiteral['speech']r•   c                ó,   • U R                   =(       d    S$ )zÝThe transcript, or an empty string if transcription was unavailable.

Mirrors [`TextPart.content`][pydantic_ai.messages.TextPart.content] so code that renders
message parts generically can treat spoken content like text.
r8  )rü  rÌ   s    r�   r�   ÚSpeechPart.contentX	  s   € ð �‰×$ "Ð$rƒ   c                ó$  ^• / nU R                   bF  UR                  [        R                  " SSS0UR                  (       a  SU R                   0O0 D65        U R
                  =mb*  UR                  [        TR                  U4S jU5      5        U$ )Nr—   r˜   r�   c                 ó   >• T R                   $ r}   r½  )rŸ  s   €r�   rÀ  Ú/SpeechPart.otel_message_parts.<locals>.<lambda>j	  s   ø€ ÐPU×P\ÒP\rƒ   r™   )rü  rÅ  r&   rš   r›   rŸ  r¯  rÆ   )rœ   r�   rÊ  rŸ  s      @r�   rž   ÚSpeechPart.otel_message_partsa	  s„   ø€ Ø24ˆØ�?‰?Ñ&Ø�L‰LÜ×'Ò'ñ ØðØDL×D\×D\ Y°·±Ñ$@Ðbdñôð
 —Z‘ZÐˆEÑ,Ø�L‰LÔ5°e×6FÑ6FÔH\Ð^fÓgÔhØˆrƒ   c                óV   • [        U R                  5      =(       d    U R                  SL$ )z=Return `True` if the part has a transcript or retained audio.N)r÷   rü  rŸ  rÌ   s    r�   rY  ÚSpeechPart.has_contentm	  s   € ä�D—O‘OÓ$×>¨¯
©
¸$Ð(>Ð>rƒ   r™   rØ   r    rö   )r¢   r£   r¤   r¥   r¦   r§   rü  rŸ  rþ  rR  rƒ  rg  r•   rÛ   r�   rž   rY  r'   r©   rª   r«   r™   rƒ   r�   rÜ  rÜ  !	  s«   ‡ ñð *Ó)ØGà!€J�
Ó!ØOà"&€EÐÓ&ðð %)Ð�zÓ(ðð €Bˆ
ÓØaà $€M�:Ó$ðð
 /3ÐÐ+Ó2ðð $,€IÐ Ó+ØRàó%ó ð%ô
ô?ð ×2Ñ2ƒHrƒ   rÜ  c                  óà   • \ rS rSr% SrS\S'    SrS\S'    \" \S9r	S\S	'    S
\S'   Sr
S\S'    SrS\S'    SrS\S'    SrS\S'    SS jrSS.SS jjrSS jrSS jr\R&                  rSrg)ÚBaseToolCallPartit	  úA tool call from a model.rŒ   r  Nústr | dict[str, Any] | NoneÚargsr�   r  r   rŽ   r  r  r’   rR  rƒ  r½   rg  c                ó   • S U l         g r}   ©Úotel_metadatarÌ   s    r�   rl  ÚBaseToolCallPart.__post_init__¥	  s   € ð
 NRˆÕrƒ   F)Úraise_if_invalidc               ó’  • U R                   (       d  0 $ [        U R                   [        5      (       a  U R                   $  [        R                  " U R                   5      n[        U[        5      (       d   S5       e[        [        [        [        4   U5      $ ! [        [        4 a    U(       a  e [        U R                   0s $ f = f)aö  Return the arguments as a Python dictionary.

This is just for convenience with models that require dicts as input.

Args:
    raise_if_invalid: If `True`, a `ValueError` or `AssertionError`
        caused by malformed or non-object JSON in `args` will be re-raised.  When
        `False` (the default), such JSON is handled gracefully by
        returning `{'INVALID_JSON': '<raw args>'}` so that the value
        can still be sent to a model API (e.g. during a retry flow)
        without crashing.
zargs should be a dict)r  r¯   rê  rÛ  rB  r   rŒ   r   rë   ÚAssertionErrorÚINVALID_JSON_KEY)rœ   r  r  s      r�   Úargs_as_dictÚBaseToolCallPart.args_as_dict¬	  s›   € ð �y�yØˆIÜ�d—i‘i¤×&Ñ&Ø—9‘9Ðð	1Ü ×*Ò*¨4¯9©9Ó5ˆDÜ˜d¤D×)Ñ)ÐBÐ+BÓBÐ)ÜœœS¤#˜X™¨Ó-Ð-øÜœNÐ+ó 	1ÞØÜ$ d§i¡iÐ0Ò0ð	1ús   Á AB Â*CÃCc                ój  • U R                   (       d  g[        U R                   [        5      (       aA   [        [        R                  " U R                   5      [
        5      (       a  U R                   $  [        R                  " U R                  5       5      R                  5       $ ! [         a     N>f = f)aÐ  Return the arguments as a JSON string.

This is just for convenience with models that require JSON strings as input.

JSON that's malformed or doesn't represent an object is handled gracefully by returning
`'{"INVALID_JSON":"<raw args>"}'`, matching [`args_as_dict`][pydantic_ai.messages.BaseToolCallPart.args_as_dict],
so that the value can still be sent to a model API (e.g. during a retry flow) instead of being rejected
by one that requires an object.

Because of that, this is not the way to render args that are still streaming in: a partial fragment
that only becomes valid JSON once the following deltas are concatenated would be degraded to the
wrapper. Emit those verbatim instead, as the UI event streams do.
z{})
r  r¯   rŒ   rÛ  rB  rê  rë   Úto_jsonr  rQ  rÌ   s    r�   Úargs_as_json_strÚ!BaseToolCallPart.args_as_json_strÆ	  s‹   € ð �y�yØÜ�d—i‘i¤×%Ñ%ðÜœm×5Ò5°d·i±iÓ@Ä$×GÑGð  Ÿ9™9Ð$ð Hô ×$Ò$ T×%6Ñ%6Ó%8Ó9×@Ñ@ÓBÐBøô ó Ùðús   ³>B% Â%
B2Â1B2c                ó&   • U R                   S0 S4;  $ )z+Return `True` if the tool call has content.r8  N©r  rÌ   s    r�   rY  ÚBaseToolCallPart.has_contentà	  s   € à�y‰y  R¨ Ñ.Ð.rƒ   r  rÑ  )r  r÷   r¡   rA  rØ   rö   )r¢   r£   r¤   r¥   r¦   r§   r  r   r[  r  r  rR  rƒ  rg  rl  r  r  rY  r'   r©   rª   r«   r™   rƒ   r�   r
  r
  t	  s¨   ‡ á#àƒNØ'à(,€DÐ
%Ó,ðñ
 Ð.DÑE€L�#ÓEðð
 ƒJà%)€IÐ"Ó)ðð €Bˆ
Óðð !%€M�:Ó$ðð /3ÐÐ+Ó2ðôRð 8=÷ 1ô4Cô4/ð ×2Ñ2ƒHrƒ   r
  c                  óP   • \ rS rSr% SrS\S'   SrS\S'    \SS	.SS
 jj5       rSr	g)ÚToolCallPartiç	  r  r   rŽ   ú	tool-callzLiteral['tool-call']r•   Nr^  c               ó$   • [        U [        U5      $ )u!  Promote a base `ToolCallPart` to its typed subclass when its `tool_kind` is registered.

Best-effort: returns the part unchanged when the `tool_kind` (kwarg or on the part) resolves to
no registered subclass, and strips an unsubstantiated `tool_kind` when the part's data doesn't
validate against that subclass â€” keeping it on a base part would break a
[`ModelMessagesTypeAdapter`][pydantic_ai.messages.ModelMessagesTypeAdapter] round-trip. For
direct construction; Pydantic deserialization promotes automatically via the discriminated union.
)Ú_narrow_callÚ_TOOL_CALL_NARROWERSrb  s     r�   r3  ÚToolCallPart.narrow_typeð	  s   € ô ˜DÔ"6¸	ÓBÐBrƒ   r™   )rË  r   r  r  r¡   r   rd  r™   rƒ   r�   r   r   ç	  s2   ‡ á#àƒJà&1€IÐ#Ó1ð YàØLPö 	Có ó	Crƒ   r   c                  óP   • \ rS rSr% SrS\S'   SrS\S'    \SS	.SS
 jj5       rSr	g)ÚNativeToolCallPartiý	  a  A tool call to a native tool.

For native tools with a stable cross-provider shape (currently `tool_search`), this base
class can be promoted to a typed subclass with a narrowed `args` `TypedDict`. See
[`NativeToolSearchCallPart`][pydantic_ai.messages.NativeToolSearchCallPart] for the
canonical example.

Adding a typed subclass for a future native tool (see `pydantic_ai._tool_search` for
a worked example):

1. Add a sibling `pydantic_ai/_<name>.py` module that defines the cross-provider
   `TypedDict`s, the `NativeToolCallPart` / `NativeToolReturnPart` subclasses,
   and registers their narrowers into `_NATIVE_CALL_NARROWERS` /
   `_NATIVE_RETURN_NARROWERS` keyed by `tool_kind`. Subclass overrides
   `tool_kind: Literal['<emitter>']` to match the emitting
   [`AbstractNativeTool.kind`][pydantic_ai.native_tools.AbstractNativeTool.kind],
   and shadows `args` / `content` with a narrower type.
2. Late-import the new module from this file (alongside the existing tool-search
   import) so registration runs whenever `pydantic_ai.messages` is imported.
3. Add the subclass to `ModelResponsePart`'s discriminated union and to
   `_model_response_part_discriminator` so Pydantic deserialization auto-promotes
   on `model_validate` / `model_validate_json`.

Dispatch is by `tool_kind`, not `tool_name`. This protects users whose tools happen to
share a name with one of ours from accidentally getting their parts promoted (and
failing shape validation against the typed `args`/`content`).

The `provider_details` field carries genuinely non-portable provider extras
(e.g. Anthropic's `strategy: 'bm25' | 'regex'` for tool search). Promote a field
to a typed slot in `args` / `content` only when at least two of OpenAI, Anthropic,
and Google support it (cf. [issue #3885](https://github.com/pydantic/pydantic-ai/issues/3885)).

MCP server tools land here with `tool_kind='mcp_server'` (label stays in
`tool_name='mcp_server:<label>'`); typed-subclass work for MCP is tracked by
[issue #3561](https://github.com/pydantic/pydantic-ai/issues/3561).
r   rŽ   úbuiltin-tool-callzLiteral['builtin-tool-call']r•   Nr^  c               ó$   • [        U [        U5      $ )u'  Promote a base `NativeToolCallPart` to its typed subclass when its `tool_kind` is registered.

Best-effort: returns the part unchanged when the `tool_kind` (kwarg or on the part) resolves to
no registered subclass, and strips an unsubstantiated `tool_kind` when the part's data doesn't
validate against that subclass â€” keeping it on a base part would break a
[`ModelMessagesTypeAdapter`][pydantic_ai.messages.ModelMessagesTypeAdapter] round-trip. For
direct construction; Pydantic deserialization promotes automatically via the discriminated union.
)r#  Ú_NATIVE_CALL_NARROWERSrb  s     r�   r3  ÚNativeToolCallPart.narrow_type)
  s   € ô ˜DÔ"8¸)ÓDÐDrƒ   r™   )rË  r'  r  r  r¡   r'  rd  r™   rƒ   r�   r'  r'  ý	  s4   ‡ ñ#ðJ ƒJà.A€IÐ+ÓAØRàØRVö 	Eó ó	Erƒ   r'  z=dict[str, Callable[[NativeToolCallPart], NativeToolCallPart]]r*  zAdict[str, Callable[[NativeToolReturnPart], NativeToolReturnPart]]rj  z1dict[str, Callable[[ToolCallPart], ToolCallPart]]r$  z5dict[str, Callable[[ToolReturnPart], ToolReturnPart]]ra  Ú
_CallPartT)ÚboundÚ_ReturnPartTc                óÖ   • Ub  UOU R                   nUb  UR                  U5      OSnUc  U $  U" U 5      $ ! [        R                   a    U R                   b  [	        U SS9s $ U s $ f = f)zdBest-effort promotion shared by the call-part `narrow_type` methods. See `ToolCallPart.narrow_type`.Nr^  )r  rÇ  rÙ   rr  r   )rË  Ú	narrowersr  rà   Únarrowers        r�   r#  r#  G
  sw   € ð "Ñ-‰9°4·>±>€DØ&*Ñ&6ˆy�}‰}˜TÔ"¸D€HØÑØˆðUÙ˜‹~ÐøÜ×#Ñ#ó UØ04·±Ñ0JŒw�t tÑ,ÒTÐPTÒTðUús   ®6 ¶+A(Á#A(Á'A(c                ó.  • Ub  UOU R                   nUb  UR                  U5      OSnUc  U $ U R                  5       nUb  XPR                  La	  [	        XS9OU n U" U5      $ ! [
        R                   a    U R                   b  [	        U SS9s $ U s $ f = f)zhBest-effort promotion shared by the return-part `narrow_type` methods. See `ToolReturnPart.narrow_type`.NrX  r^  )r  rÇ  rC  r�   r   rÙ   rr  )rË  r0  r  rà   r1  Ú
structuredÚnarrow_inputs          r�   r`  r`  U
  s¨   € ð "Ñ-‰9°4·>±>€DØ&*Ñ&6ˆy�}‰}˜TÔ"¸D€HØÑØˆð ×(Ñ(Ó*€Jà-7Ñ-CÈ
×ZfÑZfÒHfŒ�Ò)Ðlpð ðUÙ˜Ó%Ð%øÜ×#Ñ#ó UØ04·±Ñ0JŒw�t tÑ,ÒTÐPTÒTðUús   ÁA" Á"+BÂBÂBzdict[tuple[str, str], str]Ú_TYPED_PART_TAGSzdict[type, str]Ú_TYPED_PART_TAGS_BY_TYPE)ÚLoadCapabilityCallPartÚLoadCapabilityReturnPart)ÚNativeToolSearchCallPartÚNativeToolSearchReturnPartÚToolSearchArgsÚToolSearchCallPartÚToolSearchMatchÚToolSearchReturnContentÚToolSearchReturnPartc                óâ  • [        U [        5      (       a�  [        [        [        [        4   U 5      nUR                  S5      nUR                  S5      n[        U[        5      (       a0  [        U[        5      (       a  [        R                  X#45      nUb  U$ [        U[        5      (       a  U$ S$ [        R                  5        H  u  pT[        X5      (       d  M  Us  $    [        U SS5      $ )uQ  Callable discriminator for [`ModelRequestPart`][pydantic_ai.messages.ModelRequestPart].

Typed subclasses register their `(part_kind, tool_kind) â†’ Tag` entries in
`_TYPED_PART_TAGS` (for dict-deserialization) and `_TYPED_PART_TAGS_BY_TYPE`
(for already-constructed instances). Falls through to the base `part_kind`
when no typed-subclass tag is registered.

Dispatching by `tool_kind` rather than `tool_name` means a user's regular tool
that happens to share a `tool_name` with a framework-emitted one deserializes
safely as a base part (no accidental promotion / shape-validation failure).
r•   r  N©
r¯   rê  r   rŒ   r   rÇ  r5  r6  r4  Úgetattr©ÚvÚv_dictrà   r  Útagr=  s         r�   Ú!_model_request_part_discriminatorrG  �
  óÄ   € ô �!”T×ÑÜ”dœ3¤˜8‘n aÓ(ˆØ�z‰z˜+Ó&ˆØ—J‘J˜{Ó+ˆ	Ü�dœC× Ñ ¤Z°	¼3×%?Ñ%?Ü"×&Ñ&¨Ð'8Ó9ˆCØ‰Ø�
Ü! $¬×,Ñ,ˆtÐ6°$Ð6Ü,×2Ñ2Ö4‰ˆÜ�a×ÓØŠJñ 5ô �1�k 4Ó(Ð(rƒ   r”   r²  rÿ  ztool-search-returnzcapability-load-returnrœ  rn  rÉ  c                óB   • [        U [        [        -  5      (       a  S$ S$ )zäStable-sort key placing the parts that answer tool calls ahead of a request's other parts.

Providers such as Anthropic require every tool result answering an assistant turn to lead the
next message, ahead of any other content.
r   r%   )r¯   r]  rm  ©rË  s    r�   Ú_tool_results_first_sort_keyrK  ¸
  s    € ô ˜4¤´/Ñ!A×BÑBˆ1ÐIÈÐIrƒ   c                óâ  • [        U [        5      (       a�  [        [        [        [        4   U 5      nUR                  S5      nUR                  S5      n[        U[        5      (       a0  [        U[        5      (       a  [        R                  X#45      nUb  U$ [        U[        5      (       a  U$ S$ [        R                  5        H  u  pT[        X5      (       d  M  Us  $    [        U SS5      $ )uS  Callable discriminator for [`ModelResponsePart`][pydantic_ai.messages.ModelResponsePart].

Typed subclasses register their `(part_kind, tool_kind) â†’ Tag` entries in
`_TYPED_PART_TAGS` (for dict-deserialization) and `_TYPED_PART_TAGS_BY_TYPE`
(for already-constructed instances). Falls through to the base `part_kind`
when no typed-subclass tag is registered.

Dispatching by `tool_kind` rather than `tool_name` means a user's regular tool
that happens to share a `tool_name` with a framework-emitted one deserializes
safely as a base part (no accidental promotion / shape-validation failure).
r•   r  NrA  rC  s         r�   Ú"_model_response_part_discriminatorrM  Á
  rH  rƒ   r˜   ztool-search-callzcapability-load-callr!  zbuiltin-tool-search-callr(  zbuiltin-tool-search-returnrh  rî  rõ  rÄ  c                  ó¾  • \ rS rSr% SrS\S'    S\S'   \" \S9rS\S	'    S
r	S\S'    \" \
S9rS\S'    SrS\S'    S
rS\S'    S
rS\S'    S
rS\S'    S
rS\S'    S
rS\S'    S
rS\S'    S
rS\S'    S
rS\S'    SrS\S '    S+S! jr\S,S" j5       r\S,S# j5       r\S-S$ j5       r\S.S% j5       r\S/S& j5       r\S0S' j5       rS1S( jrS2S) jr\ RB                  r"S*r#g
)3ÚModelResponseiî
  zNA response from a model, e.g. a message from the model to the Pydantic AI app.úSequence[ModelResponsePart]rÊ  r   rŽ   r�   r9   ÚusageNr’   Ú
model_namer   r‘   r9  zLiteral['response']rà   rƒ  Úprovider_urlz~Annotated[dict[str, Any] | None, pydantic.Field(validation_alias=pydantic.AliasChoices('provider_details', 'vendor_details'))]rg  zrAnnotated[str | None, pydantic.Field(validation_alias=pydantic.AliasChoices('provider_response_id', 'vendor_id'))]Úprovider_response_idzFinishReason | NoneÚfinish_reasonrÖ  r×  r½   r  ru   ry   rØ  c                óª   • U R                    HC  n[        U[        5      (       d  M  UR                  S:w  d  M,  [	        SUR                  < 35      e   g )NÚ	assistantzK`SpeechPart` in `ModelResponse.parts` must have `speaker='assistant'`, got rÛ  rÞ  s     r�   rl  ÚModelResponse.__post_init__@  sI   € Ø—J”JˆDÜ˜$¤
×+Ó+°·±ÀÕ0Kô !ØaÐbf×bnÑbnÑaqÐróð ò	 rƒ   c                óX  • / nSnU R                    H~  n[        U[        5      (       d&  [        U[        5      (       aO  UR                  (       a>  U(       a  US==   UR                  -  ss'   OUR                  UR                  5        SnM|  SnM€     U(       d  gSR                  U5      $ )zJGet the text in the response, including the transcript of anything spoken.FéÿÿÿÿTNr³  )rÊ  r¯   rš   rÜ  r�   rÅ  r·  )rœ   ÚtextsÚadjacentrË  s       r�   r˜   ÚModelResponse.textI  s…   € ð ˆØˆØ—J”JˆDô ˜$¤×)Ñ)¬j¸¼z×.JÑ.JÈtÏ|Ï|ö Ø˜"“I §¡Ñ-”Ià—L‘L §¡Ô.Ø’à ’ñ ö Øà�{‰{˜5Ó!Ð!rƒ   c                ó¸   • U R                    Vs/ s H&  n[        U[        5      (       d  M  UR                  PM(     nnU(       d  gSR	                  U5      $ s  snf )z!Get the thinking in the response.Nr³  )rÊ  r¯   rì  r�   r·  )rœ   rË  Úthinking_partss      r�   rî  ÚModelResponse.thinking`  sG   € ð 48·:²:Ó`²:¨4ÄÈDÔR^×A_›,˜$Ÿ,œ,±:ˆÐ`ÞØØ�{‰{˜>Ó*Ð*ùò as
   �A¬Ac                óˆ   • U R                    Vs/ s H&  n[        U[        5      (       d  M  UR                  PM(     sn$ s  snf )zGet the files in the response.)rÊ  r¯   rÉ  r�   rÞ  s     r�   r  ÚModelResponse.filesh  s/   € ð *.¯ªÓRª ´zÀ$Ì×7Q“�—”©ÑRÐRùÒRs   �?¬?c                ót   • U R                    Vs/ s H  n[        U[        5      (       d  M  UPM     sn$ s  snf )zGet the images in the response.)r  r¯   r1  )rœ   rÄ  s     r�   ÚimagesÚModelResponse.imagesm  s)   € ð "&§¢ÓM¢˜¬z¸$Ä×/L—¡ÑMÐMùÒMó   �5¬5c                ót   • U R                    Vs/ s H  n[        U[        5      (       d  M  UPM     sn$ s  snf )z#Get the tool calls in the response.)rÊ  r¯   r   rÞ  s     r�   Ú
tool_callsÚModelResponse.tool_callsr  s)   € ð "&§¢ÓN¢˜¬z¸$Ä×/M—¡ÑNÐNùÒNrf  c                óz  • U R                    Vs/ s H  n[        U[        5      (       d  M  UPM     nnU(       d  / $ U R                    Vs0 s H'  n[        U[        5      (       d  M  UR                  U_M)     nnU Vs/ s H%  nUR                  U;   d  M  XCUR                     4PM'     sn$ s  snf s  snf s  snf )z6Get the native tool calls and results in the response.)rÊ  r¯   r'  rf  r  )rœ   rË  ÚcallsÚreturns_by_idÚ	call_parts        r�   Únative_tool_callsÚModelResponse.native_tool_callsw  s°   € ð #'§*¢*ÓU¢*˜$´
¸4ÔAS×0T—¡*ˆÐUÞØˆIØ=A¿ZºZÓrºZ°TÌ:ÐVZÔ\p×KqÓ0˜×*Ñ*¨DÒ0¹ZˆÐrñ #ó
â"�	Ø×%Ñ%¨Ñ6ó ?ˆY i×&<Ñ&<Ñ=Ó>Ù"ñ
ð 	
ùò	 Vùò sùò
s"   �B.¬B.ÁB3Á(B3Á?B8ÂB8c                ó°   • U R                   (       d   S5       e[        U R                  U R                   U R                  U R                  U R
                  S9$ )zcCalculate the cost of the usage.

Uses [`genai-prices`](https://github.com/pydantic/genai-prices).
z)Model name is required to calculate price)rR  Úprovider_api_urlrƒ  Úgenai_request_timestamp)rR  r$   rQ  rS  rƒ  r‘   rÌ   s    r�   ÚcostÚModelResponse.cost„  sJ   € ð
 ��ÐKÐ KÓKˆÜ(Ø�J‰JØ—‘Ø!×.Ñ.Ø×,Ñ,Ø$(§N¡Nñ
ð 	
rƒ   c           	     ól  • / nU R                    GH   n[        U[        5      (       aH  UR                  [        R                  " S
SS0UR
                  (       a  SUR                  0O0 D65        Ma  [        U[        5      (       aH  UR                  [        R                  " S
SS0UR
                  (       a  SUR                  0O0 D65        M¾  [        U[        5      (       a7  UR                  [        UR                  R                  U4S jU5      5        GM
  [        U[        5      (       a  UR                  [        X15      5        GM<  [        U[        5      (       a  [        R                  " SUR                  UR                   SS9nUR
                  (       a/  UR                  b"  [#        [%        UR                  U5      5      US	'   UR                  U5        GMÐ  [        U[&        5      (       a#  UR)                  UR+                  U5      5        GM  [        U[,        5      (       d  GM   GM#     U$ )Nr—   r˜   r�   rî  c                ó.   • U R                   R                  $ r}   )r�   r   r¾  s    r�   rÀ  Ú2ModelResponse.otel_message_parts.<locals>.<lambda>¥  s   € ÐYZ×YbÑYb×YiÒYirƒ   rP  T)r—   rR  rS  Úbuiltinr6  r™   )rÊ  r¯   rš   rÅ  r&   r›   r�   rì  rÉ  r¯  rÆ   r
  Ú_tool_call_otel_partrf  rT  r  r  r3   r2   rÜ  rG  rž   rô  )rœ   r�   rÊ  rË  Úreturn_parts        r�   rž   Ú ModelResponse.otel_message_parts’  sµ  € Ø24ˆØ—J•JˆDÜ˜$¤×)Ñ)Ø—‘Ü"×+Ò+ñ Ø#ðà8@×8P×8P˜I t§|¡|Ñ4ÐVXñöô ˜D¤,×/Ñ/Ø—‘Ü"×/Ò/ñ Ø'ðà8@×8P×8P˜I t§|¡|Ñ4ÐVXñöô ˜D¤(×+Ñ+Ø—‘Ü0°·±×1HÑ1HÐSWÓJiÐksÓt÷ô ˜DÔ"2×3Ñ3Ø—‘Ô1°$ÓA×BÜ˜DÔ"6×7Ñ7Ü,×AÒAØ-Ø×(Ñ(ØŸ™Ø ñ	�ð ×+×+°·±Ñ0HÜ,9Ô:OÐPT×P\ÑP\Ð^fÓ:gÓ,h�K Ñ)à—‘˜[×)Ü˜D¤*×-Ñ-Ø—‘˜T×4Ñ4°XÓ>×?Ü˜D¤.×1Ô1âñI ðJ ˆrƒ   r™   rÑ  )r¡   r’   )r¡   zlist[BinaryContent])r¡   zlist[BinaryImage])r¡   zlist[ToolCallPart])r¡   z5list[tuple[NativeToolCallPart, NativeToolReturnPart]])r¡   zgenai_types.PriceCalculationr    )$r¢   r£   r¤   r¥   r¦   r§   r   r9   rQ  rR  r¨   r‘   rà   rƒ  rS  rg  rT  rU  rÖ  r×  r  rØ  rl  rÛ   r˜   rî  r  rd  rh  rn  rs  rž   r'   r©   rª   r«   r™   rƒ   r�   rO  rO  î
  s�  ‡ áXà&Ó&Ø)àƒJá°Ñ=€Eˆ<Ó=ðð "€J�
Ó!Ø<á°Ñ9€IˆxÓ9ðð !+€DÐ
Ó*ØUà $€M�:Ó$ØCà#€L�*Ó#ØGð 	ð	 ð ó ð
 \ð 	ð	 ð ó ð
 và)-€MÐ&Ó-Ø`à€FˆJÓØRà"&€O�ZÓ&ðð '+€HÐ#Ó*Ønà *€EÐÓ*ðôð ó"ó ð"ð, ó+ó ð+ð óSó ðSð óNó ðNð óOó ðOð ó

ó ð

ô
ô'ðR ×2Ñ2ƒHrƒ   rO  c                óh  • [         R                  " SU R                  U R                  S9n[	        U [
        5      (       a  SUS'   U R                  (       aL  U R                  R                  S5      =n(       a  X2S'   U R                  R                  S5      =n(       a  XBS'   UR                  (       ay  U R                  bl  [	        U R                  [        5      (       a  U R                  US'   U$ U R                  R                  5        VVs0 s H  u  pVU[        U5      _M     snnUS'   U$ s  snnf )zbConvert a tool-call part to its OTel `ToolCallPart`, including native/code metadata and arguments.rr   rQ  Trx  Úcode_arg_nameÚcode_arg_languageÚ	arguments)r&   r   r  r  r¯   r'  r  rÇ  r›   r  rŒ   r4  r3   )rË  r�   rm  r}  r~  ÚkrD  s          r�   ry  ry  ¾  s
  € ä×+Ò+°À×ARÑARÐY]×YgÑYgÑh€IÜ�$Ô*×+Ñ+Ø#ˆ	�)ÑØ××Ø ×.Ñ.×2Ñ2°?ÓCÐCˆ=ÕCØ)6�oÑ&Ø $× 2Ñ 2× 6Ñ 6Ð7JÓ KÐKÐÕKØ->Ð)Ñ*Ø×× D§I¡IÑ$9Ü�d—i‘i¤×%Ñ%Ø%)§Y¡YˆI�kÑ"ð Ðð GKÇiÁiÇoÁoÔFWÔ%XÒFW¹d¸a a¬°qÓ)9Ò&9ÑFWÒ%XˆI�kÑ"ØÐùó &Ys   ÄD.c           
     ó¸  ^ • [        [        T 5      S-
  SS5       H²  nT U   n[        U[        5      (       d  M  [        [        UR                  5      S-
  SS5       Hl  n[        UR                  U   [
        5      (       d  M'  [        U[        UR                  US 5      S9/U 4S j[        US-   [        T 5      5       5       Qs  s  $    M´     [        T 5      $ )uí  The messages from the latest [`CompactionPart`][pydantic_ai.messages.CompactionPart] onward.

After compaction, the summary replaces everything before it, so this window is what the model
effectively works from â€” at part-level precision: within the response that carries the
compaction part, parts before it are excluded and parts after it are kept. With no compaction
part in the history, the whole history is returned (as a new list).

This is the boundary rule Pydantic AI itself uses when deriving model-visible state from
history (discovered tools, loaded capabilities). Capability and toolset authors should apply
the same rule to their own derived state â€” anything the model needs to have *seen*
(announcements, disclosures, catalogs) should be recomputed from this window rather than
remembered in instance attributes, so it self-heals when compaction replaces the history that
carried it.

Deliberately provider-agnostic, unlike the wire-level trim, which is provider-specific
because it must be exact for the one request it renders. This window feeds run-level state
(`RunContext.discovered_tool_names`, loaded capabilities) that must stay valid across
[`FallbackModel`][pydantic_ai.models.fallback.FallbackModel] failover and mid-run model
switches â€” at parse time there is no "current" provider to resolve against, so the boundary
has to be the conservative intersection: a compaction part another provider would skip on the
wire still counts.

The execution-availability gate separately anchors its evidence to the provider that served the
response being dispatched. Re-disclosure, instruction building, search ranking, and catalogs
continue to use this conservative provider-agnostic window because they feed a future request
whose provider may differ.
r%   rZ  Nr¹  c              3  ó.   >#   • U  H
  nTU   v •  M     g 7fr}   r™   ©r  r‚  Úmessagess     €r�   r  Ú)post_compaction_window.<locals>.<genexpr>   ó   øé € ÐWÒ/V¨!˜( 1ž+Ò/Vùó   ƒ)Úranger:  r¯   rO  rÊ  rô  r   r  )r„  Úmessage_indexrt  Ú
part_indexs   `   r�   Úpost_compaction_windowr‹  Ú  s¿   ø€ ô8 œs 8›}¨qÑ0°"°bÖ9ˆØ˜=Ñ)ˆÜ�gœ}×-Ó-Ü#¤C¨¯©Ó$6¸Ñ$:¸BÀÖC�
Ü˜gŸm™m¨JÑ7¼×HÓHô
   ¬t°G·M±MÀ*À+Ð4NÓ/OÑPðäW¬u°]ÀQÑ5FÌÈHËÔ/VÓWðô ó Dñ :ô �‹>Ðrƒ   )Úrequires_encrypted_contentc               ó    • U R                   U:w  a  gU R                  (       a  SU R                  ;   a  gU(       + =(       a    U R                  SL$ )u
  Whether `provider_name` would honor `part` as a compaction boundary on the wire.

A part is only ever a boundary for the provider that produced it â€” compaction data round-trips
to its own provider â€” and only while it still carries the payload that provider renders. A part
carrying neither payload is a failed compaction, a documented no-op, and a boundary for nobody.

`requires_encrypted_content` is the caller's own render condition, not something derivable from
history: the OpenAI Responses adapter sends only the encrypted item, so a part holding just a
plaintext summary is unrenderable *for it* even though the same part is perfectly renderable for
a text-mode provider. Adapters pass it because they alone know what they will emit; trimming at
a part the request then declines to send would drop the history with no summary standing in for
it. It is a parameter rather than a lookup on `provider_name` because one adapter serves many
provider names â€” an Azure-backed `OpenAIResponsesModel` reports `'azure'` â€” so a name table
would silently mistreat every alias.

The default is the history-only reading used by the execution-availability gate, which has no
adapter to ask: any payload at all counts. The two can disagree for a part stamped with an
encrypted-mode provider that carries only plaintext, where the gate treats it as a boundary the
adapter would skip. That errs toward refusing a call rather than toward admitting an unseen
tool, and unifying the two properly wants a declared per-model compaction mode (see #7255).
FÚencrypted_contentTN)rƒ  rg  r�   )rË  rƒ  rŒ  s      r�   Ú!_compaction_part_is_wire_boundaryr�    sF   € ð0 ×Ñ˜]Ó*ØØ××Ð!4¸×8MÑ8MÓ!MØØ)Ô)×F¨d¯l©lÀ$Ð.FÐFrƒ   c           
     ó†  ^ ^• TR                   c  [        T 5      $ [        U U4S j[        [	        T 5      S-
  SS5       5       S5      nUc   S5       e[        US-
  SS5       HÑ  nT U   n[        U[        5      (       d  M  [        [	        UR                  5      S-
  SS5       H‹  nUR                  U   n[        U[        5      (       d  M)  [        UTR                   5      (       d  MF  [        U[        UR                  US 5      S9/U 4S j[        US-   [	        T 5      5       5       Qs  s  $    MÓ     [        T 5      $ )a  The provider-exact evidence window for calls in `serving_response`.

Only boundaries strictly before the serving response are eligible: a provider can emit a
compaction part and continue generating a call in the same response, but that response was not
part of the request whose tools the model saw. A response without provider provenance falls
back to the provider-agnostic window.
Nc              3  ó<   >#   • U  H  nTU   TL d  M  Uv •  M     g 7fr}   r™   )r  r‚  r„  Úserving_responses     €€r�   r  Ú7_post_compaction_window_for_response.<locals>.<genexpr>1  s"   øé € ÐiÒ%E ÈÐRSÉÐXhÐIhŸ!™!Ò%Eùs   ƒ“	r%   rZ  z0`serving_response` must be present in `messages`r¹  c              3  ó.   >#   • U  H
  nTU   v •  M     g 7fr}   r™   rƒ  s     €r�   r  r“  =  r†  r‡  )rƒ  r‹  r  rˆ  r:  r¯   rO  rÊ  rô  r�  r   r  )r„  r’  Úserving_indexr‰  rt  rŠ  rË  s   ``     r�   Ú$_post_compaction_window_for_responser–  $  s'  ù€ ð ×%Ñ%Ñ-Ü% hÓ/Ð/äÕi¤U¬3¨x«=¸1Ñ+<¸bÀ"Ô%EÓiÐkoÓp€MØÑ$ÐXÐ&XÓXÐ$Ü˜}¨qÑ0°"°bÖ9ˆØ˜=Ñ)ˆÜ�gœ}×-Ó-Ü#¤C¨¯©Ó$6¸Ñ$:¸BÀÖC�
Ø—}‘} ZÑ0�Ü˜d¤N×3Ó3Ô8YØÐ*×8Ñ8÷9ó 9ô   ¬t°G·M±MÀ*À+Ð4NÓ/OÑPðäW¬u°]ÀQÑ5FÌÈHËÔ/VÓWðô ó Dñ :ô �‹>Ðrƒ   c                ó  • [        U [        5      (       a  [        R                  U 5      $ [        U [        5      (       a  [        R                  U 5      $ [        U [        5      (       a  [        R                  U 5      $ U $ r}   )r¯   r'  r3  rf  r   rJ  s    r�   Ú_narrow_response_partr˜  B  sc   € Ü�$Ô*×+Ñ+Ü!×-Ñ-¨dÓ3Ð3Ü�$Ô,×-Ñ-Ü#×/Ñ/°Ó5Ð5Ü�$œ×%Ñ%Ü×'Ñ'¨Ó-Ð-Ø€Krƒ   c                óZ   • [        U [        5      (       a  [        R                  U 5      $ U $ r}   )r¯   r]  r3  rJ  s    r�   Ú_narrow_request_partrš  L  s%   € Ü�$œ×'Ñ'Ü×)Ñ)¨$Ó/Ð/Ø€Krƒ   c                ó   • / nU  Hû  n[        U[        5      (       aY  UR                   Vs/ s H  n[        U5      PM     nn[	        S [        XBR                  5       5       5      (       a	  [        X$S9nOy[        U[        5      (       aY  UR                   Vs/ s H  n[        U5      PM     nn[	        S [        XRR                  5       5       5      (       a	  [        X%S9nO[        U5        UR                  U5        Mý     U$ s  snf s  snf )u2  Promote each tool call/return part across `messages` to its typed subclass via its `tool_kind`.

Best-effort and idempotent: a part whose `tool_kind` resolves to a registered typed subclass and
whose data validates against it is promoted; a part with no `tool_kind`, an unregistered one, or
shape-invalid data is left a base part (an unsubstantiated `tool_kind` is stripped â€” see
[`ToolCallPart.narrow_type`][pydantic_ai.messages.ToolCallPart.narrow_type]).

UI adapters reconstruct base parts from the wire format with `tool_kind` set from client-echoed
metadata, then call this once instead of narrowing each part inline. Pydantic deserialization of a
`ModelMessage` performs the same promotion via its discriminated-union dispatch; this is the
direct-construction equivalent for callers that build parts by hand.
c              3  ó,   #   • U  H
  u  pXLv •  M     g 7fr}   r™   ©r  ÚnewÚolds      r�   r  Ú'narrow_message_parts.<locals>.<genexpr>c  s   é € ÐYÒ2X¡h c�3•>Ò2XùrÎ  r¹  c              3  ó,   #   • U  H
  u  pXLv •  M     g 7fr}   r™   r�  s      r�   r  r   g  s   é € ÐXÒ2W¡h c�3•>Ò2WùrÎ  )r¯   rO  rÊ  r˜  ÚanyÚzipr   rÒ  rš  r#   rÅ  )r„  Únarrowedrt  rË  Únew_response_partsÚnew_request_partss         r�   Únarrow_message_partsr§  R  sÞ   € ð $&€HÛˆÜ�gœ}×-Ñ-ØJQÏ-Ê-Ó!XÊ-À$Ô"7¸Ö"=É-ÐÐ!XÜÑY´#Ð6HÏ-É-Ô2XÓY×YÑYÜ! 'ÑD�øÜ˜¤×.Ñ.ØHOÏÊÓ VÊÀÔ!5°dÖ!;ÉÐÐ VÜÑX´#Ð6GÏÉÔ2WÓX×XÑXÜ! 'ÑC�øä˜Ô!Ø�‰˜Ö ñ ð €Oùò "Yùò !Ws   «DÂDÚ	_FileUrlTc                ó`  • / nU  H   n[        U[        5      (       aw  [        S UR                   5       5      (       aV  UR                   Vs/ s H  n[        U[        5      (       a  M  UPM     nnU(       a  UR                  [        X$S95        M�  M�  UR                  U5        M¢     U$ s  snf )uÀ  Drop client-supplied compaction parts from untrusted messages that follow trusted history.

A compaction part is the latest history boundary: provider adapters trim everything before it
from the request, and [`post_compaction_window`][pydantic_ai.messages.post_compaction_window]
derives model-visible state from it. When trusted server-side history precedes the untrusted
messages, honoring a client-supplied boundary would let the client hide that trusted prefix
from the model, replacing it with the client's own summary or blob â€” so only the server's own
boundaries are kept. With no server-side history, the client-transmitted messages are the
entire conversation, boundaries included, and its compaction parts should be honored. A
response left with no parts is dropped entirely. Shared by
`sanitize_messages(strip_compaction_parts=True)` and the UI adapters' handling of runs that
combine server-side `message_history` with client-submitted messages.
c              3  óB   #   • U  H  n[        U[        5      v •  M     g 7fr}   )r¯   rô  )r  rË  s     r�   r  Ú)_drop_compaction_parts.<locals>.<genexpr>„  s   é € Ð5qÒcpÐ[_´jÀÄ~×6VÐ6VÒcpùs   ‚r¹  )r¯   rO  r¢  rÊ  rô  rÅ  r   )r„  r6  rt  rË  rÊ  s        r�   Ú_drop_compaction_partsr¬  t  sŒ   € ð "$€FÛˆÜ�gœ}×-Ñ-´#Ñ5qÐcj×cpÒcpÓ5q×2qÑ2qØ&-§m¢mÓ\¢m˜d¼:ÀdÌN×;[—T¡mˆEÐ\ÞØ—‘œg gÑ;Ö<ñ ð �M‰M˜'Ö"ñ ð €Mùò ]s   ÁB+Á)B+)ÚhttpÚhttpsr™   )Ústrip_system_promptsÚstrip_compaction_partsÚallowed_file_url_schemesÚallowed_file_url_force_downloadÚallow_uploaded_filesÚresolved_tool_call_idsc               ó˜  • U(       a  [        U 5      n U Vs1 s H  owR                  5       iM     nn[        U5      n	[        U5      n
Sn[        5       n[        5       n[        5       n/ n/ nU  HÁ  n[        U[        5      (       aL  [        UR                  UUU	UUUUS9u  nnU=(       d    UnU(       a  UR                  [        UUS95        Mb  Md  [        U[        5      (       a=  [        UR                  UU	UUUUS9nU(       a  UR                  [        UUS95        M´  M¶  [        U5        MÃ     [        UX¯5        U(       a  [        R                  " S[        SS9  U(       a5  [        R                  " S[!        U5      < S	[!        U5      < S
3[        SS9  U(       a;  [        R                  " S[!        U["        S9< S[!        U	["        S9< S3[        SS9  U(       a(  [        R                  " S[!        U5      < S3[        SS9  U(       a1  [        R                  " S[!        [        U5      5      < S3[        SS9  U$ s  snf )u£  Strip message parts that aren't safe to honor from untrusted input.

This is the same default sanitization the [UI adapters](../ui/overview.md) apply to
client-submitted messages before they're passed to an agent. Use it when loading
`message_history` from a source the application does not fully trust, such as a browser request.

By default it strips:

- [`SystemPromptPart`][pydantic_ai.messages.SystemPromptPart]s (disable with
  `strip_system_prompts=False`). The system prompt is the server's to own; a client that can
  inject one can override the agent's behavior. If stripping leaves a `ModelRequest` with no
  parts, the request is dropped from history entirely.
- [`FileUrl`][pydantic_ai.messages.FileUrl] parts whose URL scheme is not in
  `allowed_file_url_schemes` (default `http`/`https`). Non-HTTP schemes like `s3://` or `gs://`
  cause the model provider to fetch the object using the server-side IAM role, so they should
  only be accepted from trusted clients.
- [`FileUrl.force_download`][pydantic_ai.messages.FileUrl.force_download] values other than
  `False` that aren't in `allowed_file_url_force_download`, resetting them to `False`. Both
  `True` and `'allow-local'` are reset by default. Applies to file URLs in user content and
  those nested in tool return parts.
- [`UploadedFile`][pydantic_ai.messages.UploadedFile] items unless `allow_uploaded_files=True`.
  Like a non-HTTP `FileUrl`, an `UploadedFile` references an object the model provider fetches
  using the server-side IAM role. Applies to uploaded files in user content and those nested in
  tool return parts.
- [`ToolCallPart`][pydantic_ai.messages.ToolCallPart]s at the end of the history that aren't in
  `resolved_tool_call_ids`. An unresolved tool call at the end of client-supplied history doesn't
  correspond to a paused agent run and shouldn't be executed.
  [`NativeToolCallPart`][pydantic_ai.messages.NativeToolCallPart]s are left in place: the provider
  executes them server-side and pairs each with a
  [`NativeToolReturnPart`][pydantic_ai.messages.NativeToolReturnPart] in the same response, and the
  agent loop never dispatches them, so they aren't a client-injection risk. If stripping leaves the
  final response with no parts, the response is dropped from history entirely.
- The compaction provenance stamp from [`CompactionPart.provider_details`][pydantic_ai.messages.CompactionPart.provider_details].
  This ensures a client-supplied OpenAI Responses compaction item is never trusted to already
  carry the leading [`SystemPromptPart`][pydantic_ai.messages.SystemPromptPart]s: they are
  re-sent to the model even where the provider's own compaction state would normally let them
  be skipped.
- [`CompactionPart`][pydantic_ai.messages.CompactionPart]s, when `strip_compaction_parts=True`
  (off by default). Everything before a compaction part is hidden from the model, so pass
  `True` whenever you combine the sanitized history with trusted server-side
  `message_history` â€” a client-supplied compaction part would hide that server-side history.
  The [UI adapters](../ui/overview.md) apply this rule automatically when a run combines
  server-side `message_history` with client-submitted messages.

Args:
    messages: Messages to sanitize.
    strip_system_prompts: Whether to strip
        [`SystemPromptPart`][pydantic_ai.messages.SystemPromptPart]s.
    strip_compaction_parts: Whether to drop
        [`CompactionPart`][pydantic_ai.messages.CompactionPart]s entirely. Off by default, for
        when the untrusted input is the entire conversation; pass `True` when the sanitized
        history is combined with trusted server-side history.
    allowed_file_url_schemes: URL schemes allowed for [`FileUrl`][pydantic_ai.messages.FileUrl]
        parts. Defaults to `http` and `https`.
    allowed_file_url_force_download: Additional
        [`FileUrl.force_download`][pydantic_ai.messages.FileUrl.force_download] values to allow.
        `False` is always allowed. Defaults to no additional values.
    allow_uploaded_files: Whether to honor [`UploadedFile`][pydantic_ai.messages.UploadedFile] items
        from the untrusted input. Off by default, since an uploaded file references an object the model
        provider fetches using the server-side IAM role.
    resolved_tool_call_ids: Tool call IDs to preserve when the final response ends with tool calls.
        Use this for human-in-the-loop resumption when matching tool results are being submitted
        with the same request.
F)r¯  r±  r²  r³  Údisallowed_schemesÚreset_force_download_valuesÚdropped_uploaded_file_providersr¹  )r±  r²  r³  r¶  r·  r¸  zÂClient-submitted system prompts were stripped. Pass `strip_system_prompts=False` only when the client is trusted to own the system prompt, or set `manage_system_prompt='client'` on a UI adapter.r|  )Ú
stacklevelz*Client-submitted file URLs with scheme(s) zU were dropped because those schemes are not in `allowed_file_url_schemes` (currently zÜ). Non-HTTP schemes like `s3://` or `gs://` are fetched by the model provider using the server-side IAM role, so they should only be accepted from trusted clients. To allow a scheme, add it to `allowed_file_url_schemes`.z:Client-submitted file URLs with `force_download` value(s) r¾  zd were reset to `False` because those values are not in `allowed_file_url_force_download` (currently a@  ). `'allow-local'` opts the URL out of the SSRF private-IP block and `True` makes the server fetch the file itself, so neither should be accepted from untrusted clients. To allow a value, add it to `allowed_file_url_force_download`, or set it only on trusted server-side `message_history` passed directly to `Agent.run`.z2Client-submitted uploaded file(s) for provider(s) a    were dropped because `allow_uploaded_files` is `False` (the default). Like a non-HTTP file URL, an uploaded file references an object the model provider fetches using the server-side IAM role or service account, so it should only be accepted from trusted clients. To keep uploaded files from the client, set `allow_uploaded_files=True`, or pass them on trusted server-side `message_history` directly to `Agent.run`.z<Client-submitted history ended with unresolved tool call(s) a[  , which were stripped. Tool calls are produced by the model on the server side, so an unresolved tool call at the end of client-supplied history does not correspond to a paused agent run. For human-in-the-loop resumption, pass matching tool call IDs to `resolved_tool_call_ids`, or pass matching `deferred_tool_results` to a UI adapter run method.)r¬  ÚlowerÚsetr¯   rÒ  Ú_sanitize_request_partsrÊ  rÅ  r   rO  Ú_sanitize_response_partsr#   Ú_strip_dangling_tail_tool_callsÚwarningsÚwarnÚUserWarningrÀ  rˆ   )r„  r¯  r°  r±  r²  r³  r´  ÚschemeÚallowed_schemesÚallowed_force_downloadÚresolved_idsÚstripped_system_promptÚdisallowed_url_schemesr·  r¸  Údangling_tool_call_namesÚ	sanitizedrt  r¦  Úrequest_stripped_system_promptr¥  s                        r�   Úsanitize_messagesrË  �  sj  € öT Ü)¨(Ó3ˆá4LÓMÒ4L¨&—|‘|–~Ñ4L€OÐMÜ Ð!@ÓAÐÜÐ-Ó.€Là"ÐÜ'*£uÐÜ:=»%ÐÜ03³Ð#Ø*,Ðà$&€IÛˆÜ�gœ|×,Ñ,Ü@WØ—‘Ø%9Ø)8Ø0FØ%9Ø#9Ø,GØ0Oñ	AÑ=ÐÐ=ð &<×%]Ð?]Ð"Þ Ø× Ñ ¤¨Ð8IÑ!JÖKñ !ô ˜¤×/Ñ/Ü!9Ø—‘Ø)8Ø0FØ%9Ø#9Ø,GØ0Oñ"Ðö "Ø× Ñ ¤¨Ð8JÑ!KÖLñ "ô
 ˜Ö!ñA ôD $ I¨|ÔVæÜ�ŠðräØò		
ö Ü�ŠØ8¼Ð@VÓ9WÑ8Zð [ä  Ó1Ñ4ð 5*ð+ô Øò		
ö #Ü�ŠØHÜÐ1´tÑ<Ñ?ð @ä Ð!7¼TÑBÑEð F_ð`ô Øò	
ö 'Ü�ŠØ@ÄÐHgÓAhÑ@kð l9ð :ô Øò		
ö  Ü�ŠØJÜ”cÐ2Ó3Ó4Ñ7ð 8SðTô Øò		
ð ÐùòS Ns   —Ic                óð  • U (       aï  [        U S   =n[        5      (       aÔ  / nUR                   HV  n[        U[        5      (       a-  UR                  U;  a  UR                  UR                  5        ME  UR                  U5        MX     [        U5      [        UR                  5      :X  a  gU(       a  [        X4S9U S'   gU R                  5         U (       a  [        U S   =n[        5      (       a  MÒ  gggg)a;  Strip unresolved (dangling) tool calls from the surviving tail of already-sanitized history.

The tail is only known once empty messages have been dropped: a trailing `ModelRequest` that
sanitized to empty (e.g. a client-supplied system prompt) is gone, which can re-expose an earlier
[`ModelResponse`][pydantic_ai.messages.ModelResponse] whose tool calls a promptless run would
dispatch directly. Anchoring on the pre-drop index would miss that re-exposed response. Walks
back over trailing responses so several dropped messages can't hide a dangling call, keeping
calls in `resolved_tool_call_ids` so a same-request human-in-the-loop resume still works.

Only user-executed `ToolCallPart`s are stripped;
[`NativeToolCallPart`][pydantic_ai.messages.NativeToolCallPart]s are left in place since the
provider resolves them server-side (paired with a
[`NativeToolReturnPart`][pydantic_ai.messages.NativeToolReturnPart]) and the agent loop never
dispatches them.

Mutates `sanitized` (dropping/rewriting trailing responses) and appends stripped tool names to
`dangling_names` in place.
rZ  r¹  N)
r¯   rO  rÊ  r   r  rÅ  r  r:  r   Úpop)rÉ  r´  Údangling_namesÚtailÚ
kept_partsrË  s         r�   r¾  r¾  F  sÁ   € ö. œ
¨9°R©=Ð#8 4¼-×HÑHØ.0ˆ
Ø—J”JˆDÜ˜$¤×-Ñ-°$×2CÑ2CÐKaÓ2aØ×%Ñ% d§n¡nÖ5à×!Ñ! $Ö'ñ	 ô
 ˆz‹?œc $§*¡*›oÓ-ØÞÜ# DÑ;ˆI�b‰MØØ�‰Œö œ
¨9°R©=Ð#8 4¼-×HÔHˆ)ÐHˆ)rƒ   c          
     ó  • Sn/ n	U  GH   n
U(       a  [        U
[        5      (       a  SnM$  [        U
[        5      (       aT  [        U
R                  [        5      (       d5  [        U
R                  UUUUUU5      nU	R                  [        X«S95        M�  [        U
[        5      (       aM  U
R                  c@  [        U
R                  UUUUUU5      u  pÍU	R                  [        X¬(       a  UOSS95        Mï  U	R                  U
5        GM     X˜4$ )a±  Sanitize the parts of an untrusted [`ModelRequest`][pydantic_ai.messages.ModelRequest].

`disallowed_schemes`, `reset_force_download_values`, and `dropped_uploaded_file_providers` are
updated in place with any non-allowlisted file URL schemes, `force_download` values, and dropped
uploaded file providers encountered.
Returns the kept parts and whether any [`SystemPromptPart`][pydantic_ai.messages.SystemPromptPart]s
were stripped.
FTrX  N)r¯   rŠ   r±  r�   rŒ   Ú_filter_user_contentrÅ  r   r  r  Ú_sanitize_tool_return_content)rÊ  r¯  r±  r²  r³  r¶  r·  r¸  rÆ  Ú	new_partsrË  Úfiltered_contentÚkeep_contentÚsanitized_contents                 r�   r¼  r¼  l  sþ   € ð& #ÐØ(*€IÜˆÞ¤J¨tÔ5E×$FÑ$FØ%)Ð"ÙÜ�dœN×+Ñ+´J¸t¿|¹|ÌS×4QÑ4QÜ3Ø—‘Ø(Ø/Ø$Ø"Ø+Ø/ó Ðð ×ÑœW TÑDÖEÜ˜Ô0×1Ñ1°d·n±nÑ6Lô /LØ—‘Ø(Ø/Ø$Ø"Ø+Ø/ó/Ñ+ˆLð ×ÑœW TÍÑ3DÐZ^Ñ_Ö`à×Ñ˜T×"ñ= ð> Ð,Ð,rƒ   c                óŒ  • / nU  H»  n[        U[        5      (       aY  [        UR                  5      R                  R                  5       n	U	(       a  X‘;  a  UR                  U	5        Md  [        X‚U5      nO9[        U[        5      (       a$  U(       d  UR                  UR                  5        Mª  UR                  U5        M½     U$ )a#  Sanitize untrusted file references (file URLs and uploaded files) in user content.

Drops file URLs whose scheme isn't in the allowlist, and resets `force_download` values that
aren't `False` and aren't in `allowed_file_url_force_download` on kept items to `False`. Drops
uploaded files unless `allow_uploaded_files` is set.

`disallowed_schemes`, `reset_force_download_values`, and `dropped_uploaded_file_providers` are
updated in place with any disallowed schemes, reset `force_download` values, and dropped uploaded
file providers encountered.
)r¯   r¹   r   r»   rÂ  rº  ÚaddÚ_sanitize_file_urlr�  rƒ  rÅ  )
r�   r±  r²  r³  r¶  r·  r¸  Úfilteredr¸  rÂ  s
             r�   rÒ  rÒ  £  s�   € ð& #%€HÛˆÜ�dœG×$Ñ$Ü˜dŸh™hÓ'×.Ñ.×4Ñ4Ó6ˆFÞ˜&Ó@Ø"×&Ñ& vÔ.ÙÜ% dÐMhÓi‰DÜ˜œl×+Ñ+Ö4HØ+×/Ñ/°×0BÑ0BÔCÙØ�‰˜Öñ ð €Orƒ   c                óŽ   • U R                   SLa5  U R                   U;  a%  UR                  U R                   5        [        U SS9$ U $ )zºReset a [`FileUrl`][pydantic_ai.messages.FileUrl]'s `force_download` if it's not allowlisted.

`reset_force_download_values` is updated in place with the original value when it's reset.
F)r¼   )r¼   rÙ  r   )Úfile_urlr²  r·  s      r�   rÚ  rÚ  Å  sF   € ð ×Ñ eÒ+°×0GÑ0GÐOnÓ0nØ#×'Ñ'¨×(?Ñ(?Ô@Ü�x°Ñ6Ð6Ø€Orƒ   c           
     óþ  • [        U [        5      (       a\  [        U R                  5      R                  R                  5       nU(       a  Xq;  a  UR                  U5        SU 4$ S[        XU5      4$ [        U [        5      (       a*  U(       d  UR                  U R                  5        SU 4$ SU 4$ [        U [        5      (       aA  U n0 n	UR                  5        H%  u  p«[        UUUUUUU5      u  pÍU(       d  M!  XÙU
'   M'     SU	4$ [        U [        5      (       a_  [        U [        [        [         45      (       d?  U n/ nU H1  n[        UUUUUUU5      u  nnU(       d  M   UR#                  U5        M3     SU4$ SU 4$ )uË  Recursively sanitize file references (file URLs and uploaded files) nested in tool return content.

Tool return content is an arbitrarily nested structure of files, sequences, and mappings,
so any `FileUrl` or `UploadedFile` it contains â€” including those introduced by multimodal tool
returns â€” is walked and sanitized the same way file references in user content are: file URL
schemes and `force_download` are checked, and uploaded files are dropped unless `allow_uploaded_files`
is set.

`disallowed_schemes`, `reset_force_download_values`, and `dropped_uploaded_file_providers` are
updated in place with any disallowed schemes, reset `force_download` values, and dropped uploaded
file providers encountered.
FT)r¯   r¹   r   r»   rÂ  rº  rÙ  rÚ  r�  rƒ  r   r4  rÓ  r	   rŒ   r%  r´  rÅ  )r�   r±  r²  r³  r¶  r·  r¸  rÂ  ÚmappingÚsanitized_mappingr¿  r€   ÚkeepÚsanitized_valueÚsequenceÚsanitized_sequencer¸  Úsanitized_items                     r�   rÓ  rÓ  Ô  s‹  € ô* �'œ7×#Ñ#Ü˜'Ÿ+™+Ó&×-Ñ-×3Ñ3Ó5ˆÞ�fÓ<Ø×"Ñ" 6Ô*Ø˜'�>Ð!ØÔ'¨ÐRmÓnÐnÐnÜ�'œ<×(Ñ(Þ#Ø+×/Ñ/°×0EÑ0EÔFØ˜'�>Ð!Ø�Wˆ}Ðô �'œ7×#Ñ#Ø3:ˆØ:<ÐØ!Ÿ-™-ž/‰JˆCÜ$AØØ(Ø/Ø$Ø"Ø+Ø/ó%Ñ!ˆD÷ ˆtØ)8 #Ó&ñ *ð Ð&Ð&Ð&Ü�'œ8×$Ñ$¬Z¸Ä#ÄuÌiÐAX×-YÑ-YØ07ˆØ68ÐÛˆDÜ#@ØØ(Ø/Ø$Ø"Ø+Ø/ó$Ñ ˆD�.÷ ˆtØ"×)Ñ)¨.Ö9ñ ð Ð'Ð'Ð'Ø�ˆ=Ðrƒ   c          
     ó&  • / nU  GH  n[        U[        5      (       au  UR                  bh  [        UR                  ;   aT  UR                  R	                  5        V	V
s0 s H  u  pšU	[        :w  d  M  Xš_M     nn	n
UR                  [        X‹S95        MŽ  [        U[        5      (       aM  UR                  c@  [        UR                  UUUUUU5      u  pÍUR                  [        XŒ(       a  UOSS95        Mð  UR                  U5        GM     U$ s  sn
n	f )a  Sanitize unsafe metadata and file references in an untrusted response's parts.

Strips compaction provenance stamps from `CompactionPart.provider_details`. Drops
non-allowlisted schemes and resets non-allowlisted `force_download` values on
[`FileUrl`][pydantic_ai.messages.FileUrl]s nested in tool return parts, and drops
[`UploadedFile`][pydantic_ai.messages.UploadedFile]s nested in tool return parts unless
`allow_uploaded_files` is set. Unresolved (dangling) tool calls are stripped separately, from
the surviving tail, by `sanitize_messages`.

`disallowed_schemes`, `reset_force_download_values`, and `dropped_uploaded_file_providers` are
updated in place with any disallowed schemes, reset `force_download` values, and dropped uploaded
file providers encountered.
N©rg  rX  )r¯   rô  rg  ÚSTANDING_PROMPT_PLANTED_KEYr4  rÅ  r   r  r  rÓ  r�   )rÊ  r±  r²  r³  r¶  r·  r¸  rÔ  rË  r¿  r€   rg  rÖ  r×  s                 r�   r½  r½    s  € ð. *,€IÜˆä�tœ^×,Ñ,Ø×%Ñ%Ñ1Ü+¨t×/DÑ/DÓDð .2×-BÑ-B×-HÑ-HÔ-Jô Ú-J™z˜sÈcÔUpÑNp“
�’
Ñ-Jð ñ  ð ×ÑœW TÑMÖNÜ˜Ô0×1Ñ1°d·n±nÑ6Lô /LØ—‘Ø(Ø/Ø$Ø"Ø+Ø/ó/Ñ+ˆLð ×ÑœW TÍÑ3DÐZ^Ñ_Ö`à×Ñ˜T×"ñ3 ð4 Ðùó) s   ÁDÁ0Dc                  ó‚   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS
\S'    SrS\S'    SS jr	\
R                  rSrg)ÚTextPartDeltaiN  zEA partial update (delta) for a `TextPart` to append new text content.rŒ   Úcontent_deltar   rŽ   Nr’   rƒ  r½   rg  r˜   rå  Úpart_delta_kindc                ó(  • [        U[        5      (       d  [        S5      e[        UUR                  U R
                  -   U R                  =(       d    UR                  0 UR                  =(       d    0 EU R                  =(       d    0 E=(       d    SS9$ )zòApply this text delta to an existing `TextPart`.

Args:
    part: The existing model response part, which must be a `TextPart`.

Returns:
    A new `TextPart` with updated text content.

Raises:
    ValueError: If `part` is not a `TextPart`.
z,Cannot apply TextPartDeltas to non-TextPartsN)r�   rƒ  rg  )r¯   rš   rë   r   r�   rë  rƒ  rg  rÞ  s     r�   ÚapplyÚTextPartDelta.applyh  s}   € ô ˜$¤×)Ñ)ÜÐKÓLÐLÜØØ—L‘L 4×#5Ñ#5Ñ5Ø×,Ñ,×B°×0BÑ0BØ_ ×!6Ñ!6×!<¸"Ð_À$×BWÑBW×B]Ð[]Ð_×gÐcgñ	
ð 	
rƒ   r™   )rË  ÚModelResponsePartr¡   rš   )r¢   r£   r¤   r¥   r¦   r§   rƒ  rg  rì  rî  r'   r©   rª   r«   r™   rƒ   r�   rê  rê  N  sV   ‡ áOàÓØQàƒJà $€M�:Ó$ðð
 /3ÐÐ+Ó2ðð (.€O�_Ó-Ø>ô
ð* ×2Ñ2ƒHrƒ   rê  c                  ó´   • \ rS rSr% SrSrS\S'    SrS\S'    SrS\S'    Sr	S\S	'    S
r
S\S'    \SS j5       r\SS j5       rSS jr\R                  rSrg)ÚThinkingPartDeltai€  zMA partial update (delta) for a `ThinkingPart` to append new thinking content.Nr’   rë  Úsignature_deltarƒ  r‡   rg  rî  rï  rì  c                ó   • g r}   r™   rÞ  s     r�   rî  ÚThinkingPartDelta.apply£  s   € Ø>Arƒ   c                ó   • g r}   r™   rÞ  s     r�   rî  rõ  ¦  s   € Øfirƒ   c                óÐ  ^
^^• [        U[        5      (       aù  U R                  (       a  UR                  U R                  -   OUR                  nU R                  b  U R                  OUR
                  nU R                  b  U R                  OUR                  n[        U R                  5      (       a  U R                  UR                  5      OU R                  n0 UR                  =(       d    0 EU=(       d    0 E=(       d    Sn[        UUUUUS9$ [        U[        5      (       Ga¬  U R                  c  U R                  c  [        S5      eU R                  b)  [        XR                  =(       d    SU R                  -   S9nU R                  b  [        XR                  S9nU R                  b  [        XR                  S9nU R                  Gb  [        U R                  5      (       a\  [        UR                  5      (       a,  UR                  m
U R                  mSU
U4S jjn[        XS	9nU$ [        XR                  S	9n U$ [        UR                  5      (       a,  UR                  m
U R                  mSU
U4S
 jjn[        XS	9nU$ [        UR                  [        5      (       a  UR                  O0 n	[        U0 U	EU R                  ES	9nU$ [        SU< SU < S35      e)a
  Apply this thinking delta to an existing `ThinkingPart`.

Args:
    part: The existing model response part, which must be a `ThinkingPart`.

Returns:
    A new `ThinkingPart` with updated thinking content.

Raises:
    ValueError: If `part` is not a `ThinkingPart`.
N)r�   rí  rƒ  rg  z;Cannot apply ThinkingPartDelta with no content or signaturer8  )rë  )ró  ©rƒ  c                ó    >• T" T" U 5      5      $ r}   r™   )ÚdÚexisting_fnÚnew_fns    €€r�   Úchained_bothÚ-ThinkingPartDelta.apply.<locals>.chained_bothÖ  s   ø€ Ù#)©+°a«.Ó#9Ð9rƒ   rç  c                ó   >• 0 T" U 5      ETE$ r}   r™   )rú  rû  Únew_dicts    €€r�   Úchained_dictÚ-ThinkingPartDelta.apply.<locals>.chained_dictà  s   ø€ Ø=¡+¨a£.Ð=°HÐ=Ð=rƒ   zUCannot apply ThinkingPartDeltas to non-ThinkingParts or non-ThinkingPartDeltas (part=ú, self=Ú))rú  r½   r¡   rA  )r¯   rì  rë  r�   ró  rí  rƒ  r~   rg  r   rò  rë   rê  )rœ   rË  Únew_contentÚnew_signatureÚnew_provider_nameÚresolved_detailsÚnew_provider_detailsrý  r  Úexistingrû  r   rü  s             @@@r�   rî  rõ  ©  s·  ú€ ô �dœL×)Ñ)Ø?C×?Q×?Q˜$Ÿ,™,¨×);Ñ);Ò;ÐW[×WcÑWcˆKØ48×4HÑ4HÑ4T˜D×0Ò0ÐZ^×ZhÑZhˆMØ6:×6HÑ6HÑ6T × 2Ò 2ÐZ^×ZlÑZlÐô ˜D×1Ñ1×2Ñ2ð ×%Ñ% d×&;Ñ&;Ô<à×*Ñ*ð ð
 $a t×'<Ñ'<×'BÀÐ#`ÐHX×H^Ð\^Ð#`×#hÐdhÐ ÜØØ#Ø'Ø/Ø!5ñð ô ˜Ô/×0Ò0Ø×!Ñ!Ñ)¨d×.BÑ.BÑ.JÜ Ð!^Ó_Ð_Ø×!Ñ!Ñ-Ü˜t×4FÑ4F×4LÈ"ÐPT×PbÑPbÑ3bÑc�Ø×#Ñ#Ñ/Ü˜t×5IÑ5IÑJ�Ø×!Ñ!Ñ-Ü˜t×3EÑ3EÑF�Ø×$Ñ$Ò0Ü˜D×1Ñ1×2Ñ2Ü × 5Ñ 5×6Ñ6Ø&*×&;Ñ&;˜Ø!%×!6Ñ!6˜÷:ð :ô  ' tÑK˜ð ˆKô  ' t×>SÑ>SÑT™ð ˆKô ˜d×3Ñ3×4Ñ4Ø"&×"7Ñ"7�KØ#×4Ñ4�H÷>ð >ô # 4ÑG�Dð ˆKô 9CÀ4×CXÑCXÔZ^×8_Ñ8_˜t×4Ò4Ðeg�HÜ" 4Ð:_¸XÐ:_È×I^ÑI^Ð:_Ñ`�DØˆKÜØdÐ_cÑ^eÐemÐhlÑgnÐnoÐpó
ð 	
rƒ   r™   )rË  rð  r¡   rì  )rË  z%ModelResponsePart | ThinkingPartDeltar¡   z ThinkingPart | ThinkingPartDelta)r¢   r£   r¤   r¥   r¦   rë  r§   ró  rƒ  rg  rì  r   rî  r'   r©   rª   r«   r™   rƒ   r�   rò  rò  €  s†   ‡ áWà $€M�:Ó$ØYà"&€O�ZÓ&ðð
 !%€M�:Ó$ðð .2ÐÐ*Ó1ð	nð ,6€OÐ(Ó5Ø>àÛAó ØAàÛió ØiôA
ðF ×2Ñ2ƒHrƒ   rò  c                  óò   • \ rS rSr% SrSrS\S'    SrS\S'    SrS\S'    Sr	S\S	'    Sr
S
\S'    SrS\S'    SS jr\SS j5       r\    SS j5       r    SS jrSS jrSS jr\R$                  rSrg)ÚToolCallPartDeltaiï  z^A partial update (delta) for a `ToolCallPart` to modify tool name, arguments, or tool call ID.Nr’   Útool_name_deltar  Ú
args_deltar  rƒ  r½   rg  rr   zLiteral['tool_call']rì  c                ó¾   • U R                   c  g[        U R                   U R                  U R                  =(       d
    [	        5       U R
                  U R                  S9$ )z¨Convert this delta to a fully formed `ToolCallPart` if possible, otherwise return `None`.

Returns:
    A `ToolCallPart` if `tool_name_delta` is set, otherwise `None`.
N©rƒ  rg  )r  r   r  r  r[  rƒ  rg  rÌ   s    r�   Úas_partÚToolCallPartDelta.as_part  sT   € ð ×ÑÑ'ØäØ× Ñ Ø�O‰OØ×Ñ×9Ô!7Ó!9Ø×,Ñ,Ø!×2Ñ2ñ
ð 	
rƒ   c                ó   • g r}   r™   rÞ  s     r�   rî  ÚToolCallPartDelta.apply%  s   € ØSVrƒ   c                ó   • g r}   r™   rÞ  s     r�   rî  r  (  s	   € ð ADrƒ   c                óÄ   • [        U[        [        -  5      (       a  U R                  U5      $ [        U[        5      (       a  U R                  U5      $ [        SU 35      e)aÐ  Apply this delta to a part or delta, returning a new part or delta with the changes applied.

Args:
    part: The existing model response part or delta to update.

Returns:
    Either a new `ToolCallPart` or `NativeToolCallPart`, or an updated `ToolCallPartDelta`.

Raises:
    ValueError: If `part` is neither a `ToolCallPart`, `NativeToolCallPart`, nor a `ToolCallPartDelta`.
    UnexpectedModelBehavior: If applying JSON deltas to dict arguments or vice versa.
zdCan only apply ToolCallPartDeltas to ToolCallParts, NativeToolCallParts, or ToolCallPartDeltas, not )r¯   r   r'  Ú_apply_to_partr  Ú_apply_to_deltarë   rÞ  s     r�   rî  r  -  s`   € ô �dœLÔ+=Ñ=×>Ñ>Ø×&Ñ& tÓ,Ð,ä�dÔ-×.Ñ.Ø×'Ñ'¨Ó-Ð-äØrÐswÐrxÐyó
ð 	
rƒ   c                ó:  • U R                   (       a+  UR                   =(       d    SU R                   -   n[        XS9n[        U R                  [        5      (       a_  [        UR                  [
        5      (       a  [        SU< SU < S35      eUR                  =(       d    SU R                  -   n[        XS9nO~[        U R                  [
        5      (       a_  [        UR                  [        5      (       a  [        SU< SU < S35      e0 UR                  =(       d    0 EU R                  En[        XS9nU R                  (       a  [        XR                  S9nU R                  (       a  [        XR                  S	9nU R                  (       a,  0 UR                  =(       d    0 EU R                  En[        XS
9nUR                   bP  [        UR                   UR                  UR                  =(       d
    [        5       UR                  UR                  S9$ U$ )z5Internal helper to apply this delta to another delta.r8  )r  z;Cannot apply JSON deltas to non-JSON tool arguments (delta=r  r  )r  z;Cannot apply dict deltas to non-dict tool arguments (delta=©r  rø  rç  r  )r  r   r¯   r  rŒ   rê  r7   r  rƒ  rg  r   r[  )rœ   ÚdeltaÚupdated_tool_name_deltaÚupdated_args_deltaÚmerged_provider_detailss        r�   r  Ú!ToolCallPartDelta._apply_to_deltaF  sÏ  € à××à',×'<Ñ'<×'BÀÀd×FZÑFZÑ&ZÐ#Ü˜EÑKˆEä�d—o‘o¤s×+Ñ+Ü˜%×*Ñ*¬D×1Ñ1Ü-ØRÈEÉ8ÐS[ÐVZÑU\Ð\]Ð^óð ð #(×"2Ñ"2×"8°b¸D¿O¹OÑ!KÐÜ˜EÑA‰EÜ˜Ÿ™¬×.Ñ.Ü˜%×*Ñ*¬C×0Ñ0Ü-ØRÈEÉ8ÐS[ÐVZÑU\Ð\]Ð^óð ð "Q U×%5Ñ%5×%;¸Ð!PÀÇÁÐ!PÐÜ˜EÑAˆEà××Ü˜E×0AÑ0AÑBˆEà××Ü˜E×1CÑ1CÑDˆEà× × Ø&a¨%×*@Ñ*@×*FÀBÐ&aÈ4×K`ÑK`Ð&aÐ#Ü˜EÑLˆEð × Ñ Ñ,ÜØ×%Ñ%Ø× Ñ Ø×"Ñ"×>Ô&<Ó&>Ø#×1Ñ1Ø!&×!7Ñ!7ñð ð ˆrƒ   c                ón  • U R                   (       a"  UR                  U R                   -   n[        XS9n[        U R                  [
        5      (       a_  [        UR                  [        5      (       a  [        SU< SU < S35      eUR                  =(       d    SU R                  -   n[        XS9nO~[        U R                  [        5      (       a_  [        UR                  [
        5      (       a  [        SU< SU < S35      e0 UR                  =(       d    0 EU R                  En[        XS9nU R                  (       a  [        XR                  S9nU R                  (       a  [        XR                  S	9nU R                  (       a,  0 UR                  =(       d    0 EU R                  En[        XS
9nU$ )zYInternal helper to apply this delta directly to a `ToolCallPart` or `NativeToolCallPart`.)r  z:Cannot apply JSON deltas to non-JSON tool arguments (part=r  r  r8  r  z:Cannot apply dict deltas to non-dict tool arguments (part=r  rø  rç  )r  r  r   r¯   r  rŒ   r  rê  r7   r  rƒ  rg  )rœ   rË  r  Úupdated_jsonÚupdated_dictr  s         r�   r  Ú ToolCallPartDelta._apply_to_partr  s_  € à××àŸ™¨×)=Ñ)=Ñ=ˆIÜ˜4Ñ5ˆDä�d—o‘o¤s×+Ñ+Ü˜$Ÿ)™)¤T×*Ñ*Ü-Ð0kÐfjÑelÐltÐosÑnuÐuvÐ.wÓxÐxØ ŸI™IŸO¨¨t¯©Ñ>ˆLÜ˜4Ñ3‰DÜ˜Ÿ™¬×.Ñ.Ü˜$Ÿ)™)¤S×)Ñ)Ü-Ð0kÐfjÑelÐltÐosÑnuÐuvÐ.wÓxÐxØC˜tŸy™yŸ¨BÐC°4·?±?ÐCˆLÜ˜4Ñ3ˆDà××Ü˜4×.?Ñ.?Ñ@ˆDà××Ü˜4×/AÑ/AÑBˆDà× × Ø&`¨$×*?Ñ*?×*EÀ2Ð&`È$×J_ÑJ_Ð&`Ð#Ü˜4ÑJˆDàˆrƒ   r™   )r¡   zToolCallPart | None)rË  rð  r¡   ú!ToolCallPart | NativeToolCallPart)rË  z%ModelResponsePart | ToolCallPartDeltar¡   ú5ToolCallPart | NativeToolCallPart | ToolCallPartDelta)r  r  r¡   r%  )rË  r$  r¡   r$  )r¢   r£   r¤   r¥   r¦   r  r§   r  r  rƒ  rg  rì  r  r   rî  r  r  r'   r©   rª   r«   r™   rƒ   r�   r  r  ï  sÏ   ‡ áhà"&€O�ZÓ&ØDà.2€JÐ+Ó2ðð  $€L�*Ó#ð?ð
 !%€M�:Ó$ðð
 /3ÐÐ+Ó2ðð -8€OÐ)Ó7Øyô
ð" ÛVó ØVàðDØ9ðDà	>óDó ðDð
Ø9ð
à	>ô
ô2*ôXð< ×2Ñ2ƒHrƒ   r  c                  óŒ   • \ rS rSr% SrSrS\S'    SrS\S'    SrS\S'    Sr	S	\S
'    Sr
S\S'    SS jr\R                  rSrg)ÚSpeechPartDeltai“  zXA partial update (delta) for a `SpeechPart` to append transcript text and/or audio data.Nz#Literal['user', 'assistant'] | NonerÝ  r’   Útranscript_deltarü  zbytes | NoneÚaudio_chunkrÿ  r   rì  c                ót  • [        U[        5      (       d  [        S5      eUR                  nU R                  b  U R                  nO)U R                  (       a  U=(       d    SU R                  -   nUR
                  nU R                  (       a#  Ub   [        X3R                  U R                  -   S9n[        XUS9$ )ué  Apply this delta to an existing `SpeechPart`.

`transcript` replaces the part's transcript when set, which is how a provider's revision of
what it already transcribed is applied; otherwise `transcript_delta` is appended (a part with
`transcript=None` gets `transcript=transcript_delta`). `audio_chunk` is appended to the part's
retained audio data, but only if the part already has `audio` set: a part with `audio=None` is
not retaining audio, so the chunk is intentionally not stored â€” it remains available on the
delta itself for live playback.

Args:
    part: The existing model response part, which must be a `SpeechPart`.

Returns:
    A new `SpeechPart` with the delta applied.

Raises:
    ValueError: If `part` is not a `SpeechPart`.
z0Cannot apply SpeechPartDeltas to non-SpeechPartsr8  ©r&  )rü  rŸ  )	r¯   rÜ  rë   rü  r(  rŸ  r)  r   r&  )rœ   rË  rü  rŸ  s       r�   rî  ÚSpeechPartDelta.applyÃ  s”   € ô& ˜$¤
×+Ñ+ÜÐOÓPÐPØ—_‘_ˆ
Ø�?‰?Ñ&ØŸ™‰JØ×"×"Ø$×*¨¨d×.CÑ.CÑCˆJØ—
‘
ˆØ×× Ñ 1Ü˜E¯
©
°T×5EÑ5EÑ(EÑFˆEÜ�t¸%Ñ@Ð@rƒ   r™   )rË  rð  r¡   rÜ  )r¢   r£   r¤   r¥   r¦   rÝ  r§   r(  rü  r)  rì  rî  r'   r©   rª   r«   r™   rƒ   r�   r'  r'  “  sl   ‡ ábà37€GÐ0Ó7ðð $(Ð�jÓ'ð
ð "€J�
Ó!ðð !%€K�Ó$ðð *2€OÐ&Ó1Ø>ôAð> ×2Ñ2ƒHrƒ   r'  rì  c                  ój   • \ rS rSr% SrS\S'    S\S'    SrS\S	'    S
rS\S'    \R                  r
Srg)ÚPartStartEventiì  z An event indicating that a new part has started.

If multiple `PartStartEvent`s are received with the same index,
the new one should fully replace the old one.
Úintr·  rð  rË  Nú{Literal['text', 'thinking', 'tool-call', 'builtin-tool-call', 'builtin-tool-return', 'compaction', 'file', 'speech'] | NoneÚprevious_part_kindÚ
part_startzLiteral['part_start']Ú
event_kindr™   )r¢   r£   r¤   r¥   r¦   r§   r1  r3  r'   r©   rª   r«   r™   rƒ   r�   r.  r.  ì  sN   ‡ ñð ƒJØGà
ÓØ0ð 	ð ð
	óðð
 )5€JÐ%Ó4Ø9à×2Ñ2ƒHrƒ   r.  c                  óZ   • \ rS rSr% SrS\S'    S\S'    SrS\S	'    \R                  r	S
r
g)ÚPartDeltaEventi  z8An event indicating a delta update for an existing part.r/  r·  ÚModelResponsePartDeltar  Ú
part_deltazLiteral['part_delta']r3  r™   N©r¢   r£   r¤   r¥   r¦   r§   r3  r'   r©   rª   r«   r™   rƒ   r�   r5  r5    s/   ‡ áBàƒJØGà!Ó!Ø3à(4€JÐ%Ó4Ø9à×2Ñ2ƒHrƒ   r5  c                  ój   • \ rS rSr% SrS\S'    S\S'    SrS\S	'    S
rS\S'    \R                  r
Srg)ÚPartEndEventi"  z,An event indicating that a part is complete.r/  r·  rð  rË  Nr0  Únext_part_kindÚpart_endzLiteral['part_end']r3  r™   )r¢   r£   r¤   r¥   r¦   r§   r;  r3  r'   r©   rª   r«   r™   rƒ   r�   r:  r:  "  sJ   ‡ á6àƒJØGà
ÓØ+ð 	ð ð
	óðð
 '1€JÐ#Ó0Ø9à×2Ñ2ƒHrƒ   r:  c                  óZ   • \ rS rSr% SrS\S'    S\S'    SrS\S'    \R                  r	S	r
g
)ÚFinalResultEventiD  zrAn event indicating the response to the current model request matches the output schema and will produce a result.r’   r  r  Úfinal_resultzLiteral['final_result']r3  r™   Nr8  r™   rƒ   r�   r>  r>  D  s0   ‡ á|àÓØuØÓØHØ*8€JÐ'Ó8Ø9à×2Ñ2ƒHrƒ   r>  r3  c                  óZ   • \ rS rSr% SrS\S'    S\S'    SrS\S	'    \R                  r	S
r
g)ÚEnqueuedMessagesEventiX  u  An event indicating that messages enqueued via [`enqueue`][pydantic_ai.tools.RunContext.enqueue] were delivered into the run's message history.

Emitted at delivery time, carrying the delivered message objects themselves â€” the same objects
held in the run's message history, exactly as they landed there (with `timestamp` / `run_id` /
`conversation_id` stamped). A history processor that replaces history with new message objects
does not affect the event, but in-place mutation of a delivered message will be visible through it.
rŒ   Ú
enqueue_idztuple[ModelMessage, ...]r„  Úenqueued_messageszLiteral['enqueued_messages']r3  r™   Nr8  r™   rƒ   r�   rA  rA  X  s3   ‡ ñð ƒOØlà&Ó&Ø@à/B€JÐ,ÓBØ9à×2Ñ2ƒHrƒ   rA  c                  ól   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    \SS
 j5       r\	R                  rSrg)ÚToolCallEventin  a  Base class for events emitted when a tool call is about to be invoked.

Match against this in a `case` to handle [`FunctionToolCallEvent`][pydantic_ai.messages.FunctionToolCallEvent]
and [`OutputToolCallEvent`][pydantic_ai.messages.OutputToolCallEvent] together.
r   rË  r   rŽ   Núbool | NoneÚ
args_validc                ó.   • U R                   R                  $ )z=An ID used for matching details about the call to its result.©rË  r  rÌ   s    r�   r  ÚToolCallEvent.tool_call_id„  ó   € ð �y‰y×%Ñ%Ð%rƒ   r™   rØ   )r¢   r£   r¤   r¥   r¦   r§   rG  rÛ   r  r'   r©   rª   r«   r™   rƒ   r�   rE  rE  n  sG   ‡ ñð ÓØ àƒJà"€J�Ó"ðð ó&ó ð&ð ×2Ñ2ƒHrƒ   rE  c                  ó(   • \ rS rSr% SrSrS\S'   Srg)ÚFunctionToolCallEventiŒ  z;An event indicating the start to a call to a function tool.Úfunction_tool_callzLiteral['function_tool_call']r3  r™   N©r¢   r£   r¤   r¥   r¦   r3  r§   r«   r™   rƒ   r�   rM  rM  Œ  s   ‡ áEà0D€JÐ-ÓDÚ9rƒ   rM  c                  ó(   • \ rS rSr% SrSrS\S'   Srg)ÚOutputToolCallEventi”  zcAn event indicating the start of a call to an output tool (the model's "submit final answer" call).Úoutput_tool_callzLiteral['output_tool_call']r3  r™   NrO  r™   rƒ   r�   rQ  rQ  ”  s   ‡ ámà.@€JÐ+Ó@Ú9rƒ   rQ  c                  óR   • \ rS rSr% SrS\S'    \SS j5       r\R                  r
Srg)	ÚToolResultEventiœ  a  Base class for events emitted when a tool call has been completed.

Match against this in a `case` to handle [`FunctionToolResultEvent`][pydantic_ai.messages.FunctionToolResultEvent]
and [`OutputToolResultEvent`][pydantic_ai.messages.OutputToolResultEvent] together.
z ToolReturnPart | RetryPromptPartrË  c                ó.   • U R                   R                  $ )z4An ID used to match the result to its original call.rI  rÌ   s    r�   r  ÚToolResultEvent.tool_call_id§  rK  rƒ   r™   NrØ   )r¢   r£   r¤   r¥   r¦   r§   rÛ   r  r'   r©   rª   r«   r™   rƒ   r�   rT  rT  œ  s1   ‡ ñð +Ó*ØCàó&ó ð&ð ×2Ñ2ƒHrƒ   rT  c                  óB   • \ rS rSr% SrS\S'   SrS\S'    SrS	\S
'   Srg)ÚFunctionToolResultEventi¯  z7An event indicating the result of a function tool call.r   rŽ   Nrš  r�   Úfunction_tool_resultzLiteral['function_tool_result']r3  r™   )	r¢   r£   r¤   r¥   r¦   r§   r�   r3  r«   r™   rƒ   r�   rX  rX  ¯  s&   ‡ áAàƒJà26€GÐ/Ó6Ø^à2H€JÐ/ÓHÚ9rƒ   rX  c                  óN   • \ rS rSr% SrS\S'    SrS\S'    \R                  r	Sr
g	)
ÚToolAvailabilityDeltaEventi¼  au  An event indicating tools were made available mid-run, carrying the recorded delta part.

This is request-side because the delta is created while executing a tool, after response-part
streaming has finished. It records the post-dedup change, while `ToolReturnPart.tools` preserves
the caller's pre-dedup intent, and is emitted for capability loads as well as tool returns.
rÅ  rË  Útool_availability_deltaz"Literal['tool_availability_delta']r3  r™   Nr8  r™   rƒ   r�   r[  r[  ¼  s+   ‡ ñð $Ó#ØTà5N€JÐ2ÓNØ9à×2Ñ2ƒHrƒ   r[  c                  ó(   • \ rS rSr% SrSrS\S'   Srg)ÚOutputToolResultEventiÎ  z6An event indicating the result of an output tool call.Úoutput_tool_resultzLiteral['output_tool_result']r3  r™   NrO  r™   rƒ   r�   r^  r^  Î  s   ‡ á@à0D€JÐ-ÓDÚ9rƒ   r^  )ÚDeferredToolRequestsÚDeferredToolResultsc                  óX   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    \R                  r	S
r
g)ÚDeferredToolRequestsEventiß  a  An event indicating that tool calls require approval or external execution before the run can continue.

Each deferred call also emits its own [`FunctionToolCallEvent`][pydantic_ai.messages.FunctionToolCallEvent];
this event additionally carries the batched [`DeferredToolRequests`][pydantic_ai.tools.DeferredToolRequests]
so stream consumers can tell which calls are paused waiting for interaction, e.g. to notify a frontend.

It is emitted before any [`HandleDeferredToolCalls`][pydantic_ai.capabilities.HandleDeferredToolCalls]
handler runs. If no handler resolves all of the requests, the run ends with the pending requests as its
[`DeferredToolRequests`][pydantic_ai.tools.DeferredToolRequests] output.

See [deferred tools docs](../deferred-tools.md) for more information.
r`  Úrequestsr   rŽ   Údeferred_tool_requestsz!Literal['deferred_tool_requests']r3  r™   Nr8  r™   rƒ   r�   rc  rc  ß  s0   ‡ ñð #Ó"ØNàƒJà4L€JÐ1ÓLØ9à×2Ñ2ƒHrƒ   rc  c                  óX   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    \R                  r	S
r
g)ÚDeferredToolResultsEventiù  a-  An event indicating that deferred tool calls were resolved by a [`HandleDeferredToolCalls`][pydantic_ai.capabilities.HandleDeferredToolCalls] handler.

The resolved calls are then executed through the regular tool-execution pipeline, emitting a
[`FunctionToolResultEvent`][pydantic_ai.messages.FunctionToolResultEvent] for each result.

This event is not emitted when results are instead provided to a new run via `deferred_tool_results`,
as in that case the caller already knows them.

See [deferred tools docs](../deferred-tools.md) for more information.
ra  Úresultsr   rŽ   Údeferred_tool_resultsz Literal['deferred_tool_results']r3  r™   Nr8  r™   rƒ   r�   rg  rg  ù  s0   ‡ ñ	ð !Ó ØIàƒJà3J€JÐ0ÓJØ9à×2Ñ2ƒHrƒ   rg  c                  óL   • \ rS rSr% SrS\S'   SrS\S'    \R                  r	Sr
g	)
ÚRealtimeTurnCompleteEventi  au  The model exchange is over: generation and tool work are complete.

It is synthesized by the session once no tool calls are still running and no further response is
in flight. Input transcription can finish after this event. On WebRTC sidebands, provider playback
can also continue until [`RealtimeOutputSpeechEndEvent`][pydantic_ai.realtime.RealtimeOutputSpeechEndEvent].
r   rŽ   Úrealtime_turn_completez!Literal['realtime_turn_complete']r3  r™   Nr8  r™   rƒ   r�   rk  rk    s'   ‡ ñð ƒJà4L€JÐ1ÓLØ9à×2Ñ2ƒHrƒ   rk  c                  ó\   • \ rS rSr% SrS\S'   SrS\S'    SrS	\S
'    \R                  r
Srg)ÚRealtimeInputSpeechStartEventi"  a  The provider detected that the user started speaking.

Useful for barge-in: stop playing any buffered model audio when this arrives, since the model's
in-progress turn is being interrupted.

Reported by OpenAI, Azure OpenAI, and xAI. Gemini Live does not report speech onset.
r   rŽ   Nr’   Úitem_idÚrealtime_input_speech_startz&Literal['realtime_input_speech_start']r3  r™   ©r¢   r£   r¤   r¥   r¦   r§   ro  r3  r'   r©   rª   r«   r™   rƒ   r�   rn  rn  "  s4   ‡ ñð ƒJà€GˆZÓØ[à9V€JÐ6ÓVØ9à×2Ñ2ƒHrƒ   rn  c                  óL   • \ rS rSr% SrS\S'   SrS\S'    \R                  r	Sr
g	)
Ú RealtimeResponseInterruptedEventi7  a  The provider cut the model's in-progress response short.

Arrives as soon as the provider interrupts, ahead of its response terminal, so it's the point at
which to flush buffered model audio.

Reported by Gemini Live, which interrupts server-side when it hears the user speak. The other
providers report the user's speech onset as
[`RealtimeInputSpeechStartEvent`][pydantic_ai.realtime.RealtimeInputSpeechStartEvent] and leave the cancellation
to [`interrupt`][pydantic_ai.realtime.RealtimeSession.interrupt], so they never report this.
r   rŽ   Úrealtime_response_interruptedz(Literal['realtime_response_interrupted']r3  r™   Nr8  r™   rƒ   r�   rs  rs  7  s'   ‡ ñ	ð ƒJà;Z€JÐ8ÓZØ9à×2Ñ2ƒHrƒ   rs  c                  ó\   • \ rS rSr% SrS\S'   SrS\S'    SrS	\S
'    \R                  r
Srg)ÚRealtimeInputSpeechEndEventiL  z˜The provider detected that the user stopped speaking.

Useful as a 'processing' indicator: the user's turn has ended and the model is about to respond.
r   rŽ   Nr’   ro  Úrealtime_input_speech_endz$Literal['realtime_input_speech_end']r3  r™   rq  r™   rƒ   r�   rv  rv  L  s9   ‡ ñð
 ƒJà€GˆZÓðð 8S€JÐ4ÓRØ9à×2Ñ2ƒHrƒ   rv  c                  óL   • \ rS rSr% SrS\S'   SrS\S'    \R                  r	Sr
g	)
ÚRealtimeOutputSpeechStartEventib  u…  The provider started playing the model's audio to the listener.

Only reported where the provider, rather than your code, holds the audio on its way to the
listener: on a [WebRTC sideband](../realtime/deployment.md#browser-webrtc-server-sideband) the media flows
browser â†” provider, so the session never sees audio and this is its only signal that the model has
become audible. An ordinary session owns the audio and knows when it starts playing it, so no
provider reports this there.

This is about *playback*, not generation: the provider produces audio faster than it plays it, so
this can arrive well after the audio itself was generated.
r   rŽ   Úrealtime_output_speech_startz'Literal['realtime_output_speech_start']r3  r™   Nr8  r™   rƒ   r�   ry  ry  b  s'   ‡ ñ
ð ƒJà:X€JÐ7ÓXØ9à×2Ñ2ƒHrƒ   ry  c                  óL   • \ rS rSr% SrS\S'   SrS\S'    \R                  r	Sr
g	)
ÚRealtimeOutputSpeechEndEventix  aê  The provider stopped playing the model's audio to the listener.

The counterpart to
[`RealtimeOutputSpeechStartEvent`][pydantic_ai.realtime.RealtimeOutputSpeechStartEvent], and the
honest end of a spoken turn: because the provider generates audio far ahead of playing it, it is
still talking long after
[`RealtimeTurnCompleteEvent`][pydantic_ai.realtime.RealtimeTurnCompleteEvent] reports the response
finished. Drive a "speaking" indicator from this pair rather than from turn completion.
r   rŽ   Úrealtime_output_speech_endz%Literal['realtime_output_speech_end']r3  r™   Nr8  r™   rƒ   r�   r|  r|  x  s'   ‡ ñð ƒJà8T€JÐ5ÓTØ9à×2Ñ2ƒHrƒ   r|  c                  ó˜   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    Sr
S\S'    \R                  rSrg)Ú$RealtimeInputTranscriptionErrorEventiŒ  z©The provider failed to transcribe a user audio input turn, but the session continues.

This is recoverable; `item_id` and `content_index` locate the affected user turn.
rŒ   rt  r   rŽ   Nr’   r—   Úcodero  rý  Úcontent_indexÚ"realtime_input_transcription_errorz-Literal['realtime_input_transcription_error']r3  r™   )r¢   r£   r¤   r¥   r¦   r§   r—   r€  ro  r�  r3  r'   r©   rª   r«   r™   rƒ   r�   r  r  Œ  sc   ‡ ñð
 ƒLØ'àƒJà€Dˆ*ÓØ*Ø€Dˆ*ÓØ&Ø€GˆZÓØSØ $€M�:Ó$ØFà@d€JÐ=ÓdØ9à×2Ñ2ƒHrƒ   r  c                  ó\   • \ rS rSr% SrS\S'   SrS\S'    SrS	\S
'    \R                  r
Srg)ÚRealtimeSessionReconnectEventi§  a©  The connection dropped and was automatically re-established; inspect `state_restored` for continuity.

Session configuration (instructions, tools, voice, ...) is restored on every reconnect.
Conversation state is restored either by the provider's native session resumption (Gemini Live
when enabled, xAI Grok Voice) or by the session replaying its local history into the fresh
server-side conversation (OpenAI/Azure OpenAI).
r   rŽ   Fr÷   Ústate_restoredÚrealtime_session_reconnectz%Literal['realtime_session_reconnect']r3  r™   N)r¢   r£   r¤   r¥   r¦   r§   r…  r3  r'   r©   rª   r«   r™   rƒ   r�   r„  r„  §  s9   ‡ ñð ƒJà €N�DÓ ðð 9U€JÐ5ÓTØ9à×2Ñ2ƒHrƒ   r„  c                  óˆ   • \ rS rSr% SrS\S'    S\S'   SrS\S	'    SrS\S
'    SrS\S'    Sr	S\S'    \
R                  rSrg)ÚRealtimeSessionErrorEventiÈ  z2A provider-reported error occurred in the session.rŒ   rt  r   rŽ   Nr’   r—   r€  Tr÷   ÚrecoverableÚrealtime_session_errorz!Literal['realtime_session_error']r3  r™   )r¢   r£   r¤   r¥   r¦   r§   r—   r€  r‰  r3  r'   r©   rª   r«   r™   rƒ   r�   rˆ  rˆ  È  sR   ‡ á<àƒLØ'àƒJà€Dˆ*ÓØRØ€Dˆ*ÓØ&Ø€K�ÓØkà4L€JÐ1ÓLØ9à×2Ñ2ƒHrƒ   rˆ  ÚCustomEventzdict[str, type[CustomEvent]]ÚCUSTOM_EVENT_TYPESc                  ó  ^ • \ rS rSr% SrSrS\S'    SrS\S'    SrS\S	'    S
r	S\S'    \
R                  rSrS\S'    SrS\S'    SrS\S'    SS jrSSSSS.           SU 4S jjjrSS jr\      SS j5       rSrU =r$ )r‹  iô  a¢  An application-defined event emitted into the agent's event stream.

Emit these from tools or code driving [`Agent.iter`][pydantic_ai.agent.AbstractAgent.iter]
via [`RunContext.emit`][pydantic_ai.tools.RunContext.emit] or
[`AgentRun.emit`][pydantic_ai.run.AgentRun.emit] to surface progress updates, intermediate
results, or status information to consumers of the stream without adding to the model's context.

Define an event by subclassing this class with typed fields carrying the payload:

```python
from dataclasses import dataclass

from pydantic_ai import CustomEvent


@dataclass(kw_only=True)
class OperationProgressEvent(CustomEvent):
    done: int
    total: int
```

Subclasses must be dataclasses. Each subclass registers itself under its `name` -- derived from
the class name (`OperationProgressEvent` -> `'operation_progress'`) unless overridden with a `name` class
argument -- so instances round-trip through serialization back to the subclass, and consumers can
use `isinstance` checks instead of matching name strings. Deserializing an event whose name isn't
registered in the current process yields an [`UnknownCustomEvent`][pydantic_ai.messages.UnknownCustomEvent].
r8  rŒ   rS  Nr’   r  r  ÚcustomzLiteral['custom']r3  úClassVar[str | None]Ú_registered_nameFúClassVar[bool]Ú	_abstractTÚuic           	     ó<  • [        U 5      [        L a  [        S5      e[        U 5      R                  R	                  S5      (       a"  [        S[        U 5      R
                   S35      eS[        U 5      R                  ;  a"  [        S[        U 5      R                   S35      eU R                  (       d  [        S5      e[        U 5      R                  =nbE  U R                  U:w  a4  [        S[        U 5      R                   S	U< S
U R                  < S35      eg g )NzU`CustomEvent` is a base class; define a dataclass subclass with typed payload fields.r’  Ú`zn` is declared `abstract=True`, so it has no event name to serialize under; emit one of its subclasses instead.Ú__dataclass_fields__zCustom event subclass `ú&` must be decorated with `@dataclass`.z!A custom event requires a `name`.z'` serializes under its registered name z. and cannot override `name` per instance (got ú).)	r—   r‹  r8   Ú__dict__rÇ  r¤   r¢   rS  r�  ©rœ   Ú
registereds     r�   rl  ÚCustomEvent.__post_init__S  s  € Ü�‹:œÒ$ÜÐsÓtÐtÜ�‹:×Ñ×"Ñ" ;×/Ñ/ÜØ”D˜“J×+Ñ+Ð,ð -=ð >óð ð "¬¨d«×)<Ñ)<Ó<ô Ð5´d¸4³j×6IÑ6IÐ5JÐJpÐqÓrÐrð �y�yÜÐ?Ó@Ð@Ü˜t›*×5Ñ5Ð5ˆJÑBÀtÇyÁyÐT^ÓG^ÜØ”D˜“J×'Ñ'Ð(Ð(OÐPZÉ~ð ^5Ø59·Y±Y±MÀðEóð ð H_ÐBrƒ   )rS  r“  ÚabstractÚ	_registerc          	     ó‚  >• [         TU ]  " S0 UD6  [        U [        R                  5        Ub  X l        [        U [        5      =n(       a&  [        SU R                   SUR                   S35      eU(       a  SU l	        U R                  R                  S5      (       d  U(       d  g Uc  U R                  R                  S5      OS nU=(       d-    U=(       d$    [        U R                  R                  S5      5      nU(       d&  [        SU R                   SU R                   S	35      eU[        ;   a  [        S
U< S35      e[         R                  U5      n	U	b=  Uc:  [#        X�5      (       d*  [        SU< SU	R                   SU R                   S35      e[%        U [&        S1-
  5      =n
(       a  [        SU R                   SU
 S35      e[%        U [)        S15      5      (       a&  [        SU R                   SU R                   S35      eU	b  [+        5       (       d	  U [         U'   X€l        [/        U SU5        g )NzCustom event ú inherits from úš, which declares fields but is not a dataclass, so those fields would be silently dropped from every payload. Decorate it with `@dataclass(kw_only=True)`.Tr’  r�  ÚEventzN derives an empty name from its class name; pass an explicit one, e.g. `class z(CustomEvent, name='...')`.zCustom event name z is reserved.zDuplicate custom event name ú: already registered by ú%. Pass an explicit name, e.g. `class zÞ(CustomEvent, name='...')`. Events defined by libraries should use a dotted prefix (`name='mylib.progress'`) -- or, more likely, be `CapabilityEvent`s on a capability -- so they cannot collide with application event names.rS  ú4 declares field(s) reserved for the event envelope: rF  r“  z« declares a `ui` attribute, which would shadow the flag that decides whether UI adapters forward the event. Rename the field, and set the flag as a class argument: `class z(CustomEvent, ui=False)`.r™   )ÚsuperÚ__init_subclass__Ú_guard_post_initr‹  rl  r“  Ú_undecorated_field_baser8   r¤   r’  r™  rÇ  r    r¢   ÚremovesuffixÚ_RESERVED_EVENT_TAGSrŒ  Ú_is_redefinitionÚ_shadowed_envelope_fieldsÚ_CUSTOM_EVENT_ENVELOPE_FIELDSÚ	frozensetÚ_keeps_canonical_registrationr�  Ú_inject_tag_field)r=  rS  r“  r�  rž  ÚkwargsÚbaseÚrecreated_nameÚ
event_namer
  ÚshadowedÚ	__class__s              €r�   r§  ÚCustomEvent.__init_subclass__i  s]  ø€ ô 	‰Ò!Ñ+ FÒ+ô 	˜œk×7Ñ7Ô8Ø‰>ØŒFÜ*¨3´Ó<Ð<ˆ4Õ<ÜØ × 0Ñ 0Ð1°À×ARÑARÐ@Sð T6ð 7óð ö
 ð !ˆCŒMØ�<‰<×Ñ˜K×(Ñ(¶	Øð NRÉ\ S§\¡\×%5Ñ%5Ð6HÔ%IÐ_cˆØ#×[ t×[¬x¸¿¹×8QÑ8QÐRYÓ8ZÓ/[ˆ
ÞÜØ × 0Ñ 0Ð1ð 25Ø58·\±\°NÐB]ð_óð ð Ô-Ó-ÜÐ0°±¸mÐLÓMÐMÜ%×)Ñ)¨*Ó5ˆØÑ NÑ$:ÔCSÐT\×CbÑCbÜØ.¨z©nÐ<TÐU]×UjÑUjÐTkð l6Ø69·l±l°^ð Dmðnóð ô 1°Ô6SÐW]ÐV^Ñ6^Ó_Ð_ˆ8Õ_ÜØ × 0Ñ 0Ð1Ð1eÐfnÐeoÐopÐqóð ô % S¬)°T°FÓ*;×<Ñ<ô Ø × 0Ñ 0Ð1ð 2/à/2¯|©|¨nÐ<UðWóð ð ÑÔ#@×#BÑ#BØ-0Ô˜zÑ*Ø)Ôä˜#˜v zÕ2rƒ   c                óÂ   • [         R                  " U 5       Vs0 s H9  nUR                  [        ;  d  M  UR                  [	        XR                  5      _M;     sn$ s  snf )u‹  The event's payload: the subclass's own typed fields.

This is what the UI adapters send to the frontend (AG-UI `CustomEvent.value`, Vercel AI `data-{name}`
chunk data), with the same shape whether or not the event was emitted from inside a tool call.
Override to customize the payload shape â€” e.g. to include `self.tool_call_id` when the frontend
needs to attribute the event to a tool call.
)ÚdataclassesÚfieldsrS  r®  rB  )rœ   Úfs     r�   Ú
to_payloadÚCustomEvent.to_payload­  sU   € ô !×'Ò'¨Ô-ó
â-�Ø�v‰vÔ:Ñ:ó *ˆA�F‰F”G˜D§&¡&Ó)Ò)Ù-ñ
ð 	
ùò 
s
   ™Aµ$Ac                óV   • U [         La  U" U5      $ [        U[        S[        [        S9$ )a$  Build this family's tagged union, instead of the plain dataclass schema pydantic would infer.

The set of event classes isn't known when this module is imported -- applications and
capabilities register their own by defining them -- so the union can't be written down as a
static `Annotated[... , Field(discriminator=...)]` the way the closed event types are. This
override builds it from the registry each time a schema is generated, and routes a tag no
class has registered to [`UnknownCustomEvent`][pydantic_ai.messages.UnknownCustomEvent], so an event from a process that
imported a module this one didn't still round-trips instead of failing validation.

Only the family base builds the union; a subclass gets its own dataclass schema, so
annotating a concrete event type validates just that event.
rS  ©ÚregistryÚ	tag_fieldÚunknown_typeÚenvelope_fields)r‹  Ú_event_family_schemarŒ  ÚUnknownCustomEventr®  ©r=  r�  rî  s      r�   râ  Ú(CustomEvent.__get_pydantic_core_schema__»  s2   € ð  ”kÒ!Ù˜6“?Ð"Ü#ØÜ'ØÜ+Ü9ñ
ð 	
rƒ   r™   rÑ  )rS  r’   r“  rF  r�  r÷   rž  r÷   r²  r   r¡   r×   )r¡   r   ©r�  r   rî  rä  r¡   z$pydantic_core.core_schema.CoreSchema)r¢   r£   r¤   r¥   r¦   rS  r§   r  r  r3  r'   r©   rª   r�  r’  r“  rl  r§  r½  rg  râ  r«   Ú__classcell__©r·  s   @r�   r‹  r‹  ô  s  ø‡ ñð8 €Dˆ#ƒNðð
  $€L�*Ó#ðð !€IˆzÓ Øbà$,€JÐ!Ó,Ø9à×2Ñ2€Hà-1ÐÐ*Ó1Øhà %€Iˆ~Ó%ðð €BˆÓðô@ð2  ØØØñB3ð ðB3ð ð	B3ð
 ðB3ð ðB3ð ðB3ð 
÷B3ð B3ôH
ð ð
Øð
Ø#@ð
à	-ó
ó ö
rƒ   c                  ó4   • \ rS rSr% SrSrS\S'    SS jrSrg)	rÆ  iÖ  aw  A typed custom event whose `name` isn't registered in this process.

Produced when deserializing an event emitted by a process that had the defining module imported
(e.g. across a durable execution boundary). The payload fields ride in `data`, and serialization
re-flattens them, so a downstream consumer that does have the defining module imported recovers
the typed event.
Nr½   r&  c                ó   • U R                   $ )zFThe event's payload: the original event's fields, preserved in `data`.r+  rÌ   s    r�   r½  ÚUnknownCustomEvent.to_payloadç  s   € à�y‰yÐrƒ   r™   )r¡   r½   )	r¢   r£   r¤   r¥   r¦   r&  r§   r½  r«   r™   rƒ   r�   rÆ  rÆ  Ö  s   ‡ ñð #'€DÐ
Ó&ð÷rƒ   rÆ  )rž  c              #  ó8   #   • U  H  oR                   v •  M     g 7fr}   r¢  ©r  r¼  s     r�   r  r  ì  s   é € Ð)aÒ:`°Q¯&®&Ò:`ùr¶  ÚCapabilityEventz dict[str, type[CapabilityEvent]]ÚCAPABILITY_EVENT_TYPESc                óŠ   • U(       a  [        UR                  S5      5      (       d  [        SU R                   SU< S35      eg)zºReject an unusable capability event namespace.

An empty namespace, or one with an empty dotted segment, produces a kind that can't be split back
into the namespace a subclass inherits.
rF  úCapability event z has an invalid namespace N)Úallr;  r8   r¤   )r=  r§  s     r�   Ú_validate_capability_namespacerÖ  ÷  sE   € ö œC 	§¡°Ó 4×5Ñ5ÜÐ+¨C×,<Ñ,<Ð+=Ð=WÐXaÑWdÐdeÐfÓgÐgð 6rƒ   c                  ó.  ^ • \ rS rSr% SrSrS\S'    SrS\S'    S	rS
\S'    S	r	S
\S'    S	r
S
\S'    SrS\S'    S	rS\S'    SrS\S'    S	rS\S'    \R                   rSS jrS	S	S	SSS.             SU 4S jjjr\      SS j5       rSrU =r$ ) rÑ  i  a»  A typed event emitted by a capability into the agent's event stream.

Capability authors define dataclass subclasses with a namespace shared by their event family.
The emitting capability's run id is stamped by [`RunContext.emit`][pydantic_ai.tools.RunContext.emit].

Events dispatch at their stream position by default. Decision events can instead pass
`dispatch='immediate'` as a class argument so listeners run before
[`RunContext.emit`][pydantic_ai.tools.RunContext.emit] returns:

```python
from dataclasses import dataclass

from pydantic_ai import CapabilityEvent


@dataclass(kw_only=True)
class CheckpointStartEvent(CapabilityEvent, namespace='checkpoint', dispatch='immediate'):
    cancelled: bool = False
    cancel_reason: str | None = None

    def cancel(self, reason: str | None = None) -> None:
        self.cancelled = True
        self.cancel_reason = reason
```

The dispatch mode is inherited by subclasses of a concrete event class.
Ústreamz(ClassVar[Literal['stream', 'immediate']]Úevent_dispatchr8  rŒ   rà   Nr’   Úcapability_idr  r  r¤  zLiteral['capability']r3  r�  Ú_registered_kindFr‘  r’  Ú_abstract_namespacec           	     ó  • [        U 5      [        L a  [        S5      e[        U 5      R                  R	                  S5      (       a"  [        S[        U 5      R
                   S35      eS[        U 5      R                  ;  a"  [        S[        U 5      R                   S35      e[        U 5      R                  =nbE  U R                  U:w  a4  [        S[        U 5      R                   SU< S	U R                  < S
35      eg g )NzR`CapabilityEvent` is a base class; define a dataclass subclass with a `namespace`.r’  r•  zn` is declared `abstract=True`, so it has no event kind to serialize under; emit one of its subclasses instead.r–  zCapability event subclass `r—  z'` serializes under its registered kind z. and cannot override `kind` per instance (got r˜  )	r—   rÑ  r8   r™  rÇ  r¤   r¢   rÛ  rà   rš  s     r�   rl  ÚCapabilityEvent.__post_init__D  sþ   € Ü�‹:œÒ(ÜÐpÓqÐqÜ�‹:×Ñ×"Ñ" ;×/Ñ/ÜØ”D˜“J×+Ñ+Ð,ð -=ð >óð ð "¬¨d«×)<Ñ)<Ó<ô Ð9¼$¸t»*×:MÑ:MÐ9NÐNtÐuÓvÐvÜ˜t›*×5Ñ5Ð5ˆJÑBÀtÇyÁyÐT^ÓG^ÜØ”D˜“J×'Ñ'Ð(Ð(OÐPZÉ~ð ^5Ø59·Y±Y±MÀðEóð ð H_ÐBrƒ   T)r§  rS  Údispatchr�  rž  c               ó   >• [         TU ]  " S0 UD6  [        U [        R                  5        US;  a  [        S5      eUb  X0l        [        U [        5      =n(       a&  [        SU R                   SUR                   S35      eU(       a  SU l	        Ub  [        X5        Xl        U R                  R                  S5      (       d  U(       d  g Uc  Uc  U R                  R                  S5      OS nUb  Un	O›Uc  [        U [        5      nUc&  [        SU R                   S	U R                   S
35      e[        X5        U=(       d$    [!        U R                  R#                  S5      5      n
U
(       d  [        SU R                   S35      eU SU
 3n	[$        R                  U	5      nUbA  Uc>  ['        X°5      (       d.  [        SU	< SUR                   SU R                   SU< S3	5      e[)        U [*        S1-
  5      =n(       a  [        SU R                   SU S35      eUb  [-        5       (       d	  U [$        U	'   X�l        [1        U SU	5        g )N)NrØ  Ú	immediatez2`dispatch` must be either 'stream' or 'immediate'.rÔ  r   r¡  Tr’  rÛ  z# requires a namespace, e.g. `class z.(CapabilityEvent, namespace='my_capability')`.r¢  zD derives an empty name from its class name; pass an explicit `name`.rF  z Duplicate capability event kind r£  r¤  z(CapabilityEvent, namespace=z, name='...')`.rà   r¥  r™   )r¦  r§  r¨  rÑ  rl  r8   rÙ  r©  r¤   r’  rÖ  rÜ  r™  rÇ  Ú_inherited_namespacer¢   r    rª  rÒ  r¬  r­  Ú!_CAPABILITY_EVENT_ENVELOPE_FIELDSr°  rÛ  r±  )r=  r§  rS  rß  r�  rž  r²  r³  Úrecreated_kindr3  rµ  r
  r¶  r·  s                €r�   r§  Ú!CapabilityEvent.__init_subclass__V  s‰  ø€ ô 	‰Ò!Ñ+ FÒ+ô 	˜œo×;Ñ;Ô<ØÐ8Ó8ÜÐPÓQÐQØÑØ!)ÔÜ*¨3´Ó@Ð@ˆ4Õ@ÜØ# C×$4Ñ$4Ð#5°_ÀT×EVÑEVÐDWð X6ð 7óð ö
 ð !ˆCŒMØÑ$Ü.¨sÔ>Ø*3Ô'Ø�<‰<×Ñ˜K×(Ñ(¶	Øð 5>Ñ4EÈ$É,ˆC�L‰L×ÑÐ/Ô0Ð\`ð 	ð Ñ%Ø'‰JàÑ Ü0°´oÓF�	ØÑ ÜØ'¨×(8Ñ(8Ð'9ð :Ø!Ÿl™l˜^Ð+Yð[óð ô +¨3Ô:Ø×M¤¨#¯,©,×*CÑ*CÀGÓ*LÓ!MˆJÞÜØ'¨×(8Ñ(8Ð'9ð :/ð 0óð ð &˜; a¨
 |Ð4ˆJÜ)×-Ñ-¨jÓ9ˆØÑ NÑ$:ÔCSÐT\×CbÑCbÜØ2°:±.Ð@XÐYa×YnÑYnÐXoð p6Ø69·l±l°^ÐC_Ð`iÑ_lÐl{ð}óð ô 1°Ô6WÐ[aÐZbÑ6bÓcÐcˆ8ÕcÜØ# C×$4Ñ$4Ð#5Ð5iÐjrÐisÐstÐuóð ð ÑÔ#@×#BÑ#BØ14Ô" :Ñ.Ø)ÔÜ˜#˜v zÕ2rƒ   c                óV   • U [         La  U" U5      $ [        U[        S[        [        S9$ )a,  Build this family's tagged union, instead of the plain dataclass schema pydantic would infer.

The set of event classes isn't known when this module is imported -- applications and
capabilities register their own by defining them -- so the union can't be written down as a
static `Annotated[... , Field(discriminator=...)]` the way the closed event types are. This
override builds it from the registry each time a schema is generated, and routes a tag no
class has registered to [`UnknownCapabilityEvent`][pydantic_ai.messages.UnknownCapabilityEvent], so an event from a process that
imported a module this one didn't still round-trips instead of failing validation.

Only the family base builds the union; a subclass gets its own dataclass schema, so
annotating a concrete event type validates just that event.
rà   rÀ  )rÑ  rÅ  rÒ  ÚUnknownCapabilityEventrã  rÇ  s      r�   râ  Ú,CapabilityEvent.__get_pydantic_core_schema__ž  s2   € ð  ”oÒ%Ù˜6“?Ð"Ü#ØÜ+ØÜ/Ü=ñ
ð 	
rƒ   r™   rÑ  )r§  r’   rS  r’   rß  z%Literal['stream', 'immediate'] | Noner�  r÷   rž  r÷   r²  r   r¡   r×   rÉ  )r¢   r£   r¤   r¥   r¦   rÙ  r§   rà   rÚ  r  r  r3  rÛ  r’  rÜ  r'   r©   rª   rl  r§  rg  râ  r«   rÊ  rË  s   @r�   rÑ  rÑ    s5  ø‡ ñð8 @H€NÐ<ÓGØFà€Dˆ#ƒNØVà $€M�:Ó$ðð  $€L�*Ó#ØUà €IˆzÓ ØRà(4€JÐ%Ó4Ø9à-1ÐÐ*Ó1Øhà %€Iˆ~Ó%ðð 15ÐÐ-Ó4Øpà×2Ñ2€Hôð* !%ØØ:>ØØñF3ð ðF3ð ð	F3ð
 8ðF3ð ðF3ð ðF3ð ðF3ð 
÷F3ð F3ðP ð
Øð
Ø#@ð
à	-ó
ó ö
rƒ   c                  ó(   • \ rS rSr% SrSrS\S'   Srg)rç  i¹  aP  A typed capability event whose `kind` isn't registered in this process.

Produced when deserializing an event emitted by a process that had the defining module imported.
The payload fields ride in `data`, and serialization re-flattens them, so a downstream consumer
that does have the defining module imported recovers the typed event.
Nr½   r&  r™   )r¢   r£   r¤   r¥   r¦   r&  r§   r«   r™   rƒ   r�   rç  rç  ¹  s   ‡ ñð #'€DÐ
Ó&ÚHrƒ   rç  c              #  ó8   #   • U  H  oR                   v •  M     g 7fr}   r¢  rÐ  s     r�   r  r  Æ  s   é € Ð-iÒ>h¸¯f®fÒ>hùr¶  )r€   zIdict[str, Any] | Callable[[dict[str, Any] | None], dict[str, Any]] | Noner¡   r½   )r´   zstr | bytesr¡   rŒ   )r‘  r   r¡   zTypeGuard[MultiModalContent])rÆ   rŒ   r¡   z)Literal['image', 'audio', 'video'] | None)rÆ   rŒ   r¬  zCallable[[], str]r�   r:   r¡   z7_otel_messages.BlobPart | _otel_messages.BinaryDataPart)r€   rŒ   r¡   r  )r  rŒ   r  rŒ   r  rŒ   r¡   ztuple[str, str])r€   zstr | InstructionId | Noner¡   úInstructionId | None)r€   rë  r¡   r’   )rË  r,  r0  z-dict[str, Callable[[_CallPartT], _CallPartT]]r  r  r¡   r,  )rË  r.  r0  z1dict[str, Callable[[_ReturnPartT], _ReturnPartT]]r  r  r¡   r.  )rD  r   r¡   r’   )rË  ÚModelRequestPartr¡   r/  )rË  r
  r�   r:   r¡   z_otel_messages.ToolCallPart)r„  úSequence[ModelMessage]r¡   úlist[ModelMessage])rË  rô  rƒ  rŒ   rŒ  r÷   r¡   r÷   )r„  rí  r’  rO  r¡   rî  )rË  rð  r¡   rð  )rË  rì  r¡   rì  )r„  rí  r¯  r÷   r°  r÷   r±  úCollection[str]r²  zCollection[ForceDownloadMode]r³  r÷   r´  rï  r¡   rî  )rÉ  rî  r´  úset[str]rÎ  z	list[str]r¡   r×   )rÊ  rÓ  r¯  r÷   r±  rð  r²  úset[ForceDownloadMode]r³  r÷   r¶  rð  r·  rñ  r¸  rð  r¡   z#tuple[list[ModelRequestPart], bool])r�   zSequence[UserContent]r±  rð  r²  rñ  r³  r÷   r¶  rð  r·  rñ  r¸  rð  r¡   zlist[UserContent])rÝ  r¨  r²  rñ  r·  rñ  r¡   r¨  )r�   r˜  r±  rð  r²  rñ  r³  r÷   r¶  rð  r·  rñ  r¸  rð  r¡   ztuple[bool, ToolReturnContent])rÊ  rP  r±  rð  r²  rñ  r³  r÷   r¶  rð  r·  rñ  r¸  rð  r¡   zlist[ModelResponsePart])r=  r—   r§  rŒ   r¡   r×   ('  Ú
__future__r   Ú_annotationsr   rº  r±   r^   Ú	mimetypesÚosr¿  Úabcr   r   Úcollections.abcr   r   r   r	   Úcopyr
   r   r   r   r   r   r   r   Úpathlibr   Útypingr   r   r   r   r   r   r   r   r   r   r   Úurllib.parser   rÙ   rÛ  Úgenai_pricesr   Úgenai_typesÚpydantic.alias_generatorsr    Úpydantic.dataclassesÚpydantic_dataclassÚtyping_extensionsr!   r"   r#   Úpydantic_ai._genai_pricesr$   r8  r&   r'   Ú_event_registryr(   r«  r)   Ú_EventRegistryr*   rÅ  r+   r¨  r,   râ  r-   r±  r.   r¬  r/   r°  r0   r­  r1   r©  Ú_instrumentationr2   r3   r4   r[  r5   r¨   Ú
exceptionsr6   r7   r8   rQ  r9   Úmodels.instrumentedr:   r  ré   Úread_windows_registryÚ
knownfilesrÄ  rH  ÚisfileÚreadÚadd_typerJ   r§   rK   rL   rN   rU   rZ   rd   rn   rt   ry   rz   r÷   r{   r‚   rê  rŒ   ÚPlainSerializerr‡   rŠ   rµ   Ú
ConfigDictr¹   rÝ   rù   r  r  r  r$  r1  rq  rw  r  r�  ÚAfterValidatorr3  ÚDiscriminatorÚMultiModalContentrŽ  rà   r�  r’  r“  r”  rµ  r•  r—  r  r  r  ró   r¡  r£  r¯  r±  r=  ÚTypeAdapterrÓ  rÕ  rç  r˜  ÚFieldrÿ  r   r  r  ÚINTERRUPTED_TOOL_RETURN_CONTENTr  r  r]  rf  r  ÚErrorDetailsr€  rm  r‹  r‘  r—  rš  rœ  rª  r¬  ÚBeforeValidatorr­  r¯  rÅ  rÒ  rš   rì  rè  rô  rÉ  rÜ  r
  r   r'  r*  rj  r$  ra  r,  r.  r#  r`  r5  r6  Ú_deferred_capabilitiesr7  r8  Ú_tool_searchr9  r:  r;  r<  r=  r>  r?  rG  ÚTagrì  rK  rM  rð  rO  ry  ÚModelMessageÚModelMessagesTypeAdapterr‹  r�  r–  r˜  rš  r§  r¨  r¬  rË  r¾  r¼  rÒ  rÚ  rÓ  r½  rê  rò  r  r'  r6  r.  r5  r:  r>  ÚModelResponseStreamEventrA  rE  rM  rQ  rT  rX  r[  r^  Ú	_deferredr`  ra  rc  rg  rk  rn  rs  rv  ry  r|  r  r„  rˆ  ÚHandleResponseEventr—   rŒ  r‹  rÆ  r¯  r»  r®  rÒ  rÖ  rÑ  rç  rã  ÚRealtimeSessionEventÚAgentStreamEventr™   rƒ   r�   Ú<module>r!     s½  ðÞ 2ã Û Û Û Û Û 	Û ß #ß CÓ CÝ ß :Ó :Ý Ý Ý Ý ÷÷ ÷ ñ õ "ã Û Ý -Ý .Ý @ß BÑ Bå ?ç $÷÷ ÷ ÷ Cß Xß FÑ FÝ æÝ<ð "Ð á‹k€à × !Ñ !Ô #Ø× Ô €DØ	‡w�w‡~�~�d×ÓØ×Ñ˜Öñ !ð × Ñ Ð&¨Ô /Ø × Ñ ÐXÐZaÔ bØ × Ñ Ð^Ð`gÔ hØ × Ñ �_ fÔ -Ø × Ñ �_ eÔ ,Ø × Ñ Ð&¨Ô 4ð × Ñ �\ 7Ô +ð × Ñ �\ ;Ô /Ø × Ñ Ð'¨Ô 0Ø × Ñ Ð% vÔ .Ø × Ñ �] FÔ +ð × Ñ �[ &Ô )Ø × Ñ �\ 7Ô +Ø × Ñ �\ 7Ô +Ø × Ñ �[ &Ô )Ø × Ñ �[ &Ô )ð × Ñ Ð'¨Ô 1Ø × Ñ Ð'¨Ô 0à × Ñ Ð'¨Ô 1ð × Ñ Ð&¨Ô /ð $Ð$sÑt€�	Ó tØ#Ð$XÑY€�	Ó YØ&ð ñ
 Ð �9ó 
ð $ðñ	€�	ó 	ð !Ð!KÑL€ˆYÓ LØ Ð!=Ñ>€ˆYÓ >Ø#Ð$cÑd€�	Ó dØ Ð!eÑf€ˆYÓ fà!ðñ€ˆió ðð !(Ð(\Ñ ]Ð �IÓ ]ðð(  'Ð'@ÑAÐ �9Ó AØ )à# g¨mÑ&<Ñ<Ð �9Ó <ðð	ØTð	àõ	ð #,Øˆˆcˆ�N�X˜t C¨ H™~°Ñ4Ð5°t¸CÀ¸H±~ÐEÑFÑFÈÑMØ×ÒÐ>ÈDÐQTÐVYÐQYÉNÐ]aÑLaÐmsÑtðvñ#Ð �ió ð mñ �Ñ÷3ð 3ó ð3õ:Kñ ˜ x×':Ò':ÈDÑ'QÑRôU3ˆcó U3ó SðU3ñp ˜ x×':Ò':ÈDÑ'QÑRô>5ˆwó >5ó Sð>5ñB ˜ x×':Ò':ÈDÑ'QÑRô+5ˆwó +5ó Sð+5ñ\ ˜ x×':Ò':ÈDÑ'QÑRô*5ˆwó *5ó Sð*5ñZ ˜ x×':Ò':ÈDÑ'QÑRô.R�'ó .Ró Sð.Rñb �Ñ÷3ð 3ó ð3ñ2 Ø	Ø×ÒØØññ÷X3ð X3óðX3ñv Ø	Ø×ÒØØññô_�-ó _óð_ñ, Ø	Ø×ÒØØññô_�-ó _óð_ð, ÷ð ó ðð< '.ðñ	'Ð ˜)ó 	ðñ ˜ x×':Ò':ÈDÑ'QÑR÷|3ð |3ó Sð|3ð~ ØØñàñð ñð �˜x×6Ó6°}×7PÒ7PÓQÐQÑRñ	Sð
 ñð ×Ó˜6Ó"ð$ñÐ ð [ð 08¸À;ÐPXÐZgÐiuÐ.vÐ Ð+Ó và$,§M¢M°8·=²=À+×BRÒBRÐT\×TaÒTaÐ#b€�Ó bð)õ
6ð
 ˜{Ñ*Ð->Ñ>ÀÑK€ˆYÓ Kð ]ð *-¨kÐ(bÐ<UÐ(bÐWaÑ(bÐ Ð%Ó bð(ð ñ Ð/¸Ñ=Ð ðñ �Ñô#3�Ð*Ñ+ó #3ó ð#3ðN ØØØOUØIOØØØØ %ñ
6Ð Ð2ó 
ð ØØØØØñ0Ð Ð,ó ð ØØØñ	0Ð Ð,ó ð ØØØØØØØñ	0Ð Ð,ó 	ð ØØñKÐ ÐGó õðØðØ%6ðØBYðà<õñ& �Ñ÷^3ð ^3ó ð^3ðB "Ð Ø Pà,4×,@Ó,@Ø�×#Ò#°ÀXÐ^fÑgñ-€Ð)ó ÷

ñ 
÷8I
ñ I
öX à#4°xÀ±}Ñ#DÀwÈsÐTWÈxÑGXÑ#XÐ[^Ñ#^Ð�yÔ^ñ &ØØØ�c˜?Ð*Ñ+ØÐ)Ð+?Ð?Ñ@ñAà�cÐ.Ð.Ñ/ñ0ð Ð*Ñ+ñ,ð ñ	ð
 �N‹N oÑ6ð8ñ	
ó
Ðð CK×BVÓBVØ˜h×1Ò1¸dÑCñCÐ Ð?ó ðDð
 "Ð"BÑC€ˆiÓ Cð	ñ .6°lÓ-CÐ Ð*Ó CõLð #`Ð ð?õ
ñ2 �Ñ÷P3ð P3ó ðP3ñf �ÑôGÐ'ó Gó ðGñ* �Ñô$IÐ-ó $Ió ð$IðN ×'Ó'¨¨]×-GÒ-GÑ(HÐQY×QdÒQdÐquÑQvÑwÐ ñ �Ñ÷i3ð i3ó ði3ñd �$˜UÑ#÷	3ð 	3ó $ð	3ñ �$˜UÑ#÷3ð 3ó $ð3ñ �$˜UÑ#÷3ð 3ó $ð3ð  6Ð8PÑPÐSnÑnÐ �9Ó nØ 3ñ �$˜UÑ#÷3ð 3ó $ð3õ"õ.5ð &/Ø�DÑØ×ÓÐ8Ó9Ø×ÒÐ6ÀCÈ$ÁJÐZ`Ñaðcñ&Ð ˜ó ð
 jñ �Ñ÷C3ð C3ó ðC3ñL �˜tÑ$÷%3ð %3ó %ð%3ñP �Ñ÷73ð 73ó ð73ñt �Ñ÷"3ð "3ó ð"3ñJ �Ñ÷03ð 03ó ð03ðf DÐ ð ñ �Ñ÷/3ð /3ó ð/3ñd �Ñ÷"3ð "3ó ð"3ñJ �˜tÑ$÷O3ð O3ó %ðO3ñd �Ñ÷o3ð o3ó ðo3ñd �ÑôCÐ#ó Có ðCñ* �Ñô5EÐ)ó 5Eó ð5Eðt Y[Ð ÐUÓ ZØ^`Ð Ñ[Ô `ð KMÐ ÑGÔ LØPRÐ ÑMÔ Rñ ‘\Ð);Ò<€
Ù‘~Ð-AÒB€ðUØ
ðUØ!NðUØ[nðUàöUðUØ
ðUØ#TðUØatðUàöUð( 02Ð Ñ,Ô 1ðð -/Ð ™/Ô .ð÷ð ÷÷ ò ö)ð6 ØÐ §£©_Ó =Ð=Ñ>Ø� §£©]Ó ;Ð;Ñ<ñ=à�
˜HŸL›L©Ó2Ð2Ñ3ñ4ð Ð$ h§l£lÑ3GÓ&HÐHÑIñJð Ð(¨(¯,«,Ñ7OÓ*PÐPÑQñ	Rð
 � §£©]Ó ;Ð;Ñ<ñ=ð � §£©nÓ!=Ð=Ñ>ñ?ð Ð)¨8¯<«<Ñ8QÓ+RÐRÑSñTð ×ÓÐ<Ó=ð?ñ
Ð ð 5öJö)ð6 Øˆh˜Ÿ›¡VÓ,Ð,Ñ-ØÐ" H§L£LÑ1CÓ$DÐDÑEñFàÐ&¨¯«Ñ5KÓ(LÐLÑMñNð �˜hŸl›l©;Ó7Ð7Ñ8ñ9ð Ð(¨(¯,«,Ñ7QÓ*RÐRÑSñ	Tð
 Ð" H§L£LÑ1DÓ$EÐEÑFñGð Ð*¨H¯L«LÑ9UÓ,VÐVÑWñXð Ð$ h§l£lÑ3HÓ&IÐIÑJñKð �˜hŸl›l©:Ó6Ð6Ñ7ñ8ð � §£©\Ó :Ð:Ñ;ñ	<ð �˜(Ÿ,›,¡vÓ.Ð.Ñ/ñ
0ð �
˜HŸL›L©Ó2Ð2Ñ3ñ4ð ×ÓÐ=Ó>ð@ñÐ ð *ñ �Ñ÷L3ò L3ó ðL3ö^ð$ ˜¨Ñ5°x×7MÓ7MÈfÓ7UÐUÑV€Ø 1ð $×/Ó/ØˆÑ˜x×2Ò2¸tÐT\ÐmuÑvñÐ ð `ö(ðX UZòGØ
ðGØ),ðGØMQðGà	÷Gð>Ø$ðØ8Eðàöö<ööñ: ‘K wÒ/€	ðJöð8 "&Ø#(Ù0AÙEGØ!&Ù.0òvØ$ðvð ðvð !ð	vð
 .ðvð &Cðvð ðvð ,ðvð ÷vðr#Ø!ð#à$ð#ð ð#ð 
ö	#ðL4-Ø%ð4-ð ð4-ð 'ð	4-ð
 &<ð4-ð ð4-ð !ð4-ð "8ð4-ð &.ð4-ð )ö4-ðnØ"ðà&ðð &<ðð ð	ð
 !ðð "8ðð &.ðð öðDØðà%;ðð "8ðð ö	ðBØðBà&ðBð &<ðBð ð	Bð
 !ðBð "8ðBð &.ðBð $öBðJ2Ø&ð2ð 'ð2ð &<ð	2ð
 ð2ð !ð2ð "8ð2ð &.ð2ð ö2ñj �Ñ÷.3ò .3ó ð.3ñb �˜tÑ$÷k3ò k3ó %ðk3ñ\ �˜tÑ$÷`3ò `3ó %ð`3ñF �˜tÑ$÷N3ò N3ó %ðN3ðb #ØÐ%Ñ%Ð(9Ñ9¸OÑKØ×ÓÑ,Ó-ð/ñÐ ð <ñ �˜tÑ$÷"3ò "3ó %ð"3ñJ �˜tÑ$÷3ò 3ó %ð3ñ �˜tÑ$÷3ò 3ó %ð3ñB �˜tÑ$÷
3ò 
3ó %ñ
3ð %Ø�^Ñ# lÑ2Ñ5EÑEÀx×G]ÓG]Ñ^jÓGkÐkñÑ ð fñ �˜tÑ$÷3ò 3ó %ñ3ñ* �Ñ÷3ò 3ó ñ3ñ: �Ñö:™Mó :ó ñ:ñ �Ñö:™-ó :ó ñ:ñ �Ñ÷3ò 3ó ñ3ñ$ �Ñö	:™oó 	:ó ñ	:ñ �˜tÑ$÷3ò 3ó %ñ3ñ" �Ñö:™Oó :ó ñ:÷õ ñ �Ñ÷3ò 3ó ñ3ñ2 �Ñ÷3ò 3ó ñ3ñ. �Ñ÷3ò 3ó ñ3ñ  �Ñ÷3ò 3ó ñ3ñ( �Ñ÷3ò 3ó ñ3ñ( �Ñ÷3ò 3ó ñ3ñ* �Ñ÷3ò 3ó ñ3ñ* �Ñ÷3ò 3ó ñ3ñ& �Ñ÷3ò 3ó ñ3ñ4 �Ñ÷3ò 3ó ñ3ñ@ �Ñ÷3ò 3ó ñ3ð*  ÙÙñá ñ!ñ ññ ñ	ñ
  ñ ñ ñð ×Ó™<Ó(ð*ñ	Ñ ð Zð 4BÁ$Á}ÑBUÒ3VÓ3XÑ Ñ0Ô Xðñ �˜tÑ$÷^
ò ^
ó %ñ^
ñB �˜tÑ$ö™°ò ó %ñò* !*Ò)a¸+×:LÓ:LÑM_Ô:`Ó)aÓ aÑ ðð <JÉ$ÑO`ÑJaÒ;bÓ;dÑ Ñ8Ô dØ h÷hñ �˜tÑ$÷t
ò t
ó %ñt
ñn �˜tÑ$ö	I™_¸ò 	Ió %ñ	Iò %.Ò-i¸k×>PÓ>PÑQgÔ>hÓ-iÓ$iÑ !ðð !ÙÙ#ñ$á!ñ"ñ %ñ%ñ #ñ	#ñ
 'ñ'ñ +ñ+ñ $ñ$ñ  ñ ð ×Ó™<Ó(ð	*ñÑ ð =àÙÙñáññ ññ ñ	ñ
 ñð ×Ó™<Ó(ð*ñÑ ð ;rƒ   