ó
    ±"³j´÷ ã                  ó  • S r 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	J
r
Jr  SSKJrJrJrJrJr  SSKJrJr  SSKJrJrJr  SSKJrJr  SS	KJr  SS
KJr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+  SSK,r,SSK-J.r.J/r/J0r0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7J8r8  SSK9J:r:J;r;  SSK<J=r=  SSK>J?r?  SSK@JArA  SSKBJCrC  SSKDJErE  SSKFJGrG  SSKHJIrIJJrJJKrKJLrLJMrMJNrNJOrOJPrPJQrQJRrRJSrSJTrTJUrUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^J_r_J`r`JaraJbrbJcrcJdrdJereJfrfJgrgJhrhJiriJjrjJkrk  SSKlJmrmJnrn  SSKoJprpJqrq  SSKrJsrsJtrtJuru  SSKvJwrwJxrxJyryJzrzJ{r{J|r|J}r}J~r~  SSKJ€r€J�r�J‚r‚Jƒrƒ  SSK„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�  \#(       a  SS%K�J‘r‘  SS&K’J“r“  SS'KŠJ”r”  O\;b  \;GR"                  O\•r‘S(r– \(" S)5      r—\SjS* j5       r˜\/" S+\'S,   5      r™\/" S-\'S.   5      rš\'S/   r› \" S0S1S29 " S3 S45      5       rœ\" S1S59 " S6 S75      5       r�\" S1S1S89 " S9 S:\&\—   5      5       rž\" S1S1S89 " S; S<\ž\—   5      5       rŸ " S= S>\�\&\€   5      r \ " S? S@\
5      5       r¡ " SA SB\¡5      r¢S1q£ SkSC jr¤\SlSD j5       r¥SmSE jr¦SnSoSF jjr§      SpSG jr¨SqSH jr©\‚4     SrSI jjrª\:SJSK.SsSL jjr«\(" SM\¬\­5      r® " SN SO\0\&\®   5      r¯\+ St       SuSP jj5       r°\+ St       SvSQ jj5       r°  Sw       SxSR jjr°\SySS j5       r±SzST jr²      S{SU jr³SSSV.         S|SW jjr´      S}SX jrµS~SY jr¶SSZ jr·S€S[ jr¸S0S0S\.         S�S] jjr¹S1S^.S‚S_ jjrºSƒS` jr»S„Sa jr¼S„Sb jr½Scr¾       S…Sd jr¿S†Se jrÀS‡Sf jrÁ      SˆSg jrÂ      S‰Sh jrÃ      S‰Si jrÄg)Šz¹Logic related to making requests to an LLM.

The aim here is to make a common interface for different LLMs, so that the rest of the code can be agnostic to the
specific LLM being used.
é    )ÚannotationsN)ÚABCÚabstractmethod)ÚAsyncGeneratorÚAsyncIteratorÚCallableÚ	GeneratorÚSequence)ÚasynccontextmanagerÚcontextmanager)Ú	dataclassÚfieldÚreplace)ÚdatetimeÚ	timedelta)Úget_close_matches)ÚcacheÚcached_property)ÚTracebackType)	ÚTYPE_CHECKINGÚAnyÚClassVarÚGenericÚLiteralÚTypeVarÚcastÚget_argsÚoverload)ÚSelfÚTypeAliasTypeÚ	TypedDictÚ
deprecated)Úget_literal_valuesé   )Ú_utils)Úlookup_context_windowÚpreload_pricing_data)ÚDEFAULT_HTTP_TIMEOUTÚlegacy_httpx)ÚJsonSchemaTransformer)ÚStructuredTextOutputSchema)ÚModelResponsePartsManager)Ú
RunContext)ÚPydanticAIDeprecationWarning©Ú	UserError)#ÚSTANDING_PROMPT_PLANTED_KEYÚBaseToolCallPartÚBaseToolReturnPartÚBinaryImageÚCompactionPartÚFilePartÚFileUrlÚFinalResultEventÚFinishReasonÚInstructionPartÚModelMessageÚModelRequestÚModelRequestPartÚModelResponseÚModelResponsePartÚModelResponseStateÚModelResponseStreamEventÚNativeToolSearchReturnPartÚPartEndEventÚPartStartEventÚRetryPromptPartÚ
SpeechPartÚSystemPromptPartÚTextPartÚThinkingPartÚToolAvailabilityDeltaPartÚToolCallPartÚToolReturnPartÚToolSearchCallPartÚToolSearchReturnPartÚUploadedFileÚUserPromptPartÚVideoUrlÚ!_compaction_part_is_wire_boundaryÚ_tool_results_first_sort_key)ÚSUPPORTED_NATIVE_TOOLSÚAbstractNativeTool)ÚTOOL_SEARCH_FUNCTION_TOOL_NAMEÚToolSearchTool)Ú
OutputModeÚOutputObjectDefinitionÚStructuredOutputMode)ÚDEFAULT_PROFILEÚ DEFAULT_PROMPTED_OUTPUT_TEMPLATEÚModelProfileÚModelProfileSpecÚToolAdditionModeÚToolDeferralModeÚ_translate_legacy_profile_keysÚmerge_profile)ÚInterfaceClientÚProviderÚinfer_providerÚinfer_provider_class)ÚModelSettingsÚThinkingLevelÚmerge_model_settings)ÚToolDefinition)ÚRequestUsageé   )ÚAbstractModel)ÚKnownModelName)ÚAsyncClient)ÚAbstractAgent)ÚRunUsagei   ÚModelContextDepsTc                 óD   • [        [        [        R                  SS95      $ )ad  Return every model name known to [`KnownModelName`][pydantic_ai.models.KnownModelName].

This is the public, stable way to enumerate the known model ids. Prefer it over introspecting
the `KnownModelName` type alias directly (e.g. `get_args(KnownModelName.__value__)`), which is
not part of the public API and would break if the alias were ever recomposed.
Úeager)Úunpack_type_aliases)Útupler#   rn   Ú	__value__© ó    ÚX/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/models/__init__.pyÚknown_model_namesr{   p   s   € ô Ô#¤N×$<Ñ$<ÐRYÑZÓ[Ð[ry   ÚOpenAIChatCompatibleProvider)ÚalibabaÚazureÚcerebrasÚcrusoeÚdeepseekÚ	fireworksÚgithubúgithub-copilotÚherokuÚlitellmÚ
moonshotaiÚnebiusÚollamaÚ
openrouterÚovhcloudÚ	sambanovaÚ	snowflakeÚtogetherÚvercelÚvllmÚzaiÚ!OpenAIResponsesCompatibleProvider)	r~   r�   r‚   rˆ   úopenai-codexrŠ   r‹   rŒ   rŽ   )ÚvisibleÚdeferredÚwithheldÚvia_historyFT)ÚreprÚkw_onlyc                  ó   • \ rS rSr% Sr\" \\   S9rS\	S'   \" \\
   S9rS\	S'   SrS	\	S
'    \" \\   SS9rS\	S'    \" \\   SS9rS\	S'    S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'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r\ RB                  r"S&r#g),ÚModelRequestParametersé±   zcConfiguration for an agent's request to a model, specifically related to tools and output handling.)Údefault_factoryúlist[ToolDefinition]Úfunction_toolszlist[AbstractNativeTool]Únative_toolsNz dict[str, ToolVisibility] | NoneÚtool_visibilityF)r�   r˜   zset[str]Úrevealed_tool_namesÚdeferred_capability_idsÚtextrX   Úoutput_modezOutputObjectDefinition | NoneÚoutput_objectÚoutput_toolszstr | Literal[False] | NoneÚprompted_output_templateTÚboolÚallow_text_outputÚallow_image_outputúlist[InstructionPart] | NoneÚinstruction_partszThinkingLevel | NoneÚthinkingc                óÂ   • U R                   =(       d    0 R                  U5      =n(       a  U$ U R                  R                  U5      nUb  UR                  (       a  S$ S$ )a4  The resolved [`ToolVisibility`][pydantic_ai.models.ToolVisibility] for `tool_name`.

For parameters constructed directly rather than resolved by [`Model.prepare_request`][pydantic_ai.models.Model.prepare_request],
deferred function tools default to `'withheld'` and every other name defaults to `'visible'`.
r–   r”   )r¡   ÚgetÚ	tool_defsÚdefer_loading)ÚselfÚ	tool_nameÚ
visibilityÚtool_defs       rz   Úvisibility_ofÚ$ModelRequestParameters.visibility_ofó   sZ   € ð ×.Ñ.×4°"×9Ñ9¸)ÓDÐDˆ:ÕDØÐð —>‘>×%Ñ% iÓ0ˆØ%Ñ1°h×6L×6LˆzÐ[ÐR[Ð[ry   c                óv   • / U R                   QU R                  Q Vs0 s H  oR                  U_M     sn$ s  snf ©N)rŸ   r§   Úname©r³   r¶   s     rz   r±   Ú ModelRequestParameters.tool_defs   s:   € à8b¸$×:MÑ:MÐ8bÐPT×PaÑPaÑ8bÓcÒ8b¨H—‘˜xÒ'Ñ8bÑcÐcùÒcó   �6c                óv   • / U R                   QU R                  Q Vs0 s H  oR                  U_M     sn$ s  snf )a'  Definitions represented in the provider's ordinary `tools` collection.

The visibility filter applies to function tools only: output tools are always plain
`tools` entries, so they are included unconditionally rather than keyed through a
name-indexed filter a hidden function tool could shadow.
)Údeclared_function_toolsr§   r»   r¼   s     rz   Údeclared_tool_defsÚ)ModelRequestParameters.declared_tool_defs  s=   € ð 9l¸$×:VÑ:VÐ8kÐY]×YjÑYjÑ8kÓlÒ8k¨H—‘˜xÒ'Ñ8kÑlÐlùÒlr¾   c                ó†   • U R                    Vs/ s H%  oR                  UR                  5      S;  d  M#  UPM'     sn$ s  snf )zIFunction tools represented in the provider's ordinary `tools` collection.)r–   r—   )rŸ   r·   r»   )r³   Útools     rz   rÀ   Ú.ModelRequestParameters.declared_function_tools  sA   € ð "×0Ò0ó
Ú0�T×4FÑ4FÀtÇyÁyÓ4QÐYtÑ4t�DÑ0ñ
ð 	
ùò 
s   �">µ>c                óž   • U R                   (       a<  U R                  (       a+  [        R                  " U R                   U R                  5      $ g rº   )r¨   r¦   r+   Úbuild_instructions©r³   s    rz   Úprompted_output_instructionsÚ3ModelRequestParameters.prompted_output_instructions  s6   € à×(×(¨T×-?×-?Ü-×@Ò@À×A^ÑA^Ð`d×`rÑ`rÓsÐsØry   c                ó@   • U R                   S:w  a  U $ [        XUS;   S9$ )u0  Set the default output mode if the current mode is 'auto', atomically updating allow_text_output.

No-op if the current output_mode is not 'auto'. This ensures the two fields stay in sync â€”
output_mode='tool' implies allow_text_output=False, while 'native' and 'prompted' imply
allow_text_output=True.
Úauto©ÚnativeÚprompted)r¥   rª   )r¥   r   )r³   r¥   s     rz   Úwith_default_output_modeÚ/ModelRequestParameters.with_default_output_mode  s*   € ð ×Ñ˜vÓ%ØˆKÜ�tÈÐWmÑHmÑnÐnry   rx   )r´   ÚstrÚreturnÚToolVisibility)rÓ   zdict[str, ToolDefinition])rÓ   rž   ©rÓ   ú
str | None)r¥   rZ   rÓ   r›   )$Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úlistrj   rŸ   Ú__annotations__rU   r    r¡   ÚsetrÒ   r¢   r£   r¥   r¦   r§   r¨   rª   r«   r­   r®   r·   r   r±   rÁ   rÀ   rÉ   rÐ   r%   Údataclasses_no_defaults_reprÚ__repr__Ú__static_attributes__rx   ry   rz   r›   r›   ±   sX  ‡ ámá+0ÀÀnÑAUÑ+V€NÐ(ÓVÙ-2À4ÐHZÑC[Ñ-\€LÐ*Ó\Ø8<€OÐ5Ó<ðñ %*¸#¸c¹(ÈÑ$OÐ˜ÓOðñ ).¸cÀ#¹hÈUÑ(SÐ˜XÓSð
ð %€K�Ó$Ø37€MÐ0Ó7Ù).¸tÀNÑ?SÑ)T€LÐ&ÓTØ<@ÐÐ9Ó@Ø"Ð�tÓ"Ø$Ð˜Ó$à6:ÐÐ3Ó:ðð &*€HÐ"Ó)ðô\ð ódó ðdð ómó ðmð ó
ó ð
ð óó ðô
	oð ×2Ñ2ƒHry   r›   )r™   c                  ób   • \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'    SrS\S'    SrS\S'   Srg)ÚModelRequestContexti)  uÄ  Context for model request hooks.

Wrapping these parameters in a dataclass instead of a tuple makes the signature
future-proof: new fields can be added without breaking existing implementations.

A [`before_model_request`][pydantic_ai.capabilities.AbstractCapability.before_model_request] hook
returns a context, so modifying one is normally `dataclasses.replace(request_context, ...)`. Every
field is therefore settable through `replace()`, including `model_id` and `streaming`: the agent
graph sets those two immediately before calling the hook, and `replace()` re-initializes any
`init=False` field to its default, so declaring them that way silently zeroed both for any hook
that copied its context â€” costing a streamed run its `streaming` flag and a durable-execution
worker the selection token it re-resolves an aliased model from. They are still set by the graph
rather than by a caller; passing either to a fresh `ModelRequestContext` is not meaningful.
ÚModelÚmodelúlist[ModelMessage]ÚmessagesúModelSettings | NoneÚmodel_settingsr›   Úmodel_request_parametersNrÖ   Úmodel_idFr©   Ú	streamingrx   )	r×   rØ   rÙ   rÚ   rÛ   rÝ   rë   rì   rá   rx   ry   rz   rã   rã   )  sG   ‡ ñð ƒLØ Ó Ø(Ó(à4Ó4ð	ð  €HˆjÓðð €IˆtÓòry   rã   )Úfrozenr™   c                  ó0   • \ rS rSr% SrS\S'    S\S'   Srg)	ÚModelResolutionContextie  zÚContext used to resolve a model ID before a model is available.

This is narrower than [`RunContext`][pydantic_ai.tools.RunContext] because model
resolution happens before a run context can contain its resolved model.
z%AbstractAgent[ModelContextDepsT, Any]Úagentrr   Údepsrx   N©r×   rØ   rÙ   rÚ   rÛ   rÝ   rá   rx   ry   rz   rï   rï   e  s   ‡ ñð 1Ó0Ø2à
ÓÚ1ry   rï   c                  óH   • \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'   Srg)ÚModelSelectionContextit  zDContext used by a capability to select the model for a request step.zModel | Nonerå   ÚintÚrun_stepræ   rç   rq   Úusagerx   Nrò   rx   ry   rz   rô   rô   t  s'   ‡ áNàÓØbàƒMØ;à Ó ØAàƒOÚ@ry   rô   c                  óÖ  • \ rS rSr% Sr\" 5       rS\S'    \" 5       rS\S'    Sr	S\S	'    Sr
S\S
'    S\S'   SrS\S'   SrS\S'   SSS.     S2S jjr\S3S j5       rS4S jr        S5S jr\S6S j5       rS7S jr\    S8S j5       r\S9S j5       r\S:S j5       rSS.     S;S jjr\        S<S j5       r        S=S jrSS .     S>S! jjr\ S?         S@S" jj5       rSAS# jrSBS$ jr SCS% jr!      SDS& jr" S?     SES' jjr#      SES( jr$SFS) jr%SGS* jr&SHS+ jr'\(SIS, j5       r)\SJS- j5       r*\+SKS. j5       r,SLS/ jr-\      SMS0 j5       r.S1r/g)Nrä   i…  zAbstract class for a model.z%ClassVar[frozenset[ToolDeferralMode]]Úsupported_tool_deferral_modesz%ClassVar[frozenset[ToolAdditionMode]]Úsupported_tool_addition_modesFzClassVar[bool]Ú%compaction_requires_encrypted_contentÚ"compaction_retains_standing_promptzProvider[InterfaceClient]Ú	_providerNúModelProfileSpec | NoneÚ_profilerè   Ú	_settings)ÚsettingsÚprofilec               ó0   • Xl         X l        [        5         g)z»Initialize the model with optional settings and profile.

Args:
    settings: Model-specific settings that will be used as defaults for this model.
    profile: The model profile to use.
N)r   rÿ   r'   )r³   r  r  s      rz   Ú__init__ÚModel.__init__«  s   € ð "ŒØŒÜÕry   c                ó   • [        U SS5      $ )z$The provider for this model, if any.rý   N)ÚgetattrrÈ   s    rz   ÚproviderÚModel.provider»  s   € ô �t˜[¨$Ó/Ð/ry   c              ƒ  óp   #   • U R                   b"  U R                   R                  5       I Sh  v•N   U $  N7f)zXEnter the model context, delegating to the provider to manage its HTTP client lifecycle.N)r  Ú
__aenter__rÈ   s    rz   r  ÚModel.__aenter__À  s/   é € à�=‰=Ñ$Ø—-‘-×*Ñ*Ó,×,Ð,Øˆñ -ùs   ‚+6­4®6c              ƒ  ót   #   • U R                   b%  U R                   R                  XU5      I Sh  v•N   gg N7f)zJExit the model context, closing the provider's HTTP client if it owns one.N)r  Ú	__aexit__)r³   Úexc_typeÚexc_valÚexc_tbs       rz   r  ÚModel.__aexit__Æ  s3   é € ð �=‰=Ñ$Ø—-‘-×)Ñ)¨(¸VÓD×DÑDð %ÙDùs   ‚-8¯6°8c                ó   • U R                   $ )zGet the model settings.)r   rÈ   s    rz   r  ÚModel.settingsÐ  s   € ð �~‰~Ðry   c                ó   • g)a  Resolve prompt cache retention requested by provider-specific model settings.

The model's default settings are merged with the per-request `model_settings`. Only provider-specific settings
are currently considered; a future unified cache setting is not yet an input. If multiple active settings
request different retention periods, the longest period wins because any longer-lived cache breakpoint can
keep the corresponding prompt prefix available. Models without a provider-specific retention setting return
`None`.
Nrx   )r³   ré   s     rz   Úresolve_prompt_cache_retentionÚ$Model.resolve_prompt_cache_retentionÕ  s   € ð ry   c                 óT   • SU ;   a	  [        SS9$ [        U 5      (       a	  [        SS9$ g )NÚ1hrl   )Úhoursé   )Úminutes)r   Úany)Úcache_settingss    rz   Ú_max_prompt_cache_retentionÚ!Model._max_prompt_cache_retentionà  s0   € ð �>Ó!Ü 1Ñ%Ð%Üˆ~×ÑÜ QÑ'Ð'Øry   c                ó^   • U R                   R                  S5      nXR                  ;   a  U$ S$ )zTThe effective schema-deferral mode: the profile's claim, if this adapter renders it.Útool_deferral_modeN)r  r°   rù   ©r³   Úmodes     rz   r"  ÚModel.tool_deferral_modeê  ó/   € ð �|‰|×ÑÐ 4Ó5ˆØ×AÑAÓAˆtÐKÀtÐKry   c                ó^   • U R                   R                  S5      nXR                  ;   a  U$ S$ )zRThe effective tool-addition mode: the profile's claim, if this adapter renders it.Útool_addition_modeN)r  r°   rú   r#  s     rz   r(  ÚModel.tool_addition_modeð  r&  ry   )Ústanding_prompt_retainedc               ód   • [        UU R                  U R                  Uc  U R                  S9$ US9$ )us  Drop history before the latest compaction boundary this adapter's API honors.

Called only by adapters that render `CompactionPart`s on the wire, and the one place their
declared `compaction_*` facts are turned into trim behavior â€” so an adapter states what its
API does rather than what to do about it. See `_trim_messages_before_compaction` for what
the trim preserves.

`standing_prompt_retained` defaults to `compaction_retains_standing_prompt`. A caller passes
an explicit value where its window is not an ordinary one: re-compaction plants the standing
prompt afresh, since retention decays across a second compaction.
©Úrequires_encrypted_contentr*  )Ú _trim_messages_before_compactionÚsystemrû   rü   )r³   rç   r*  s      rz   Ú_trim_before_compactionÚModel._trim_before_compactionö  sD   € ô" 0ØØ�K‰KØ'+×'QÑ'Qà'Ñ/ð &*×%LÑ%Lñ	
ð 	
ð *ñ
ð 	
ry   c              ƒ  ó   #   • [        5       e7f)z{Make a request to the model.

This is ultimately called by `pydantic_ai._agent_graph.ModelRequestNode._make_request(...)`.
©ÚNotImplementedError©r³   rç   ré   rê   s       rz   ÚrequestÚModel.request  s   é € ô "Ó#Ð#ùó   ‚c              ƒ  óN   #   • [        SU R                  R                   35      e7f)z0Make a request to the model for counting tokens.z8Token counting ahead of the request is not supported by ©r4  Ú	__class__r×   r5  s       rz   Úcount_tokensÚModel.count_tokens  s(   é € ô "Ð$\Ð]a×]kÑ]k×]tÑ]tÐ\uÐ"vÓwÐwùó   ‚#%)Úinstructionsc             ƒ  óN   #   • [        SU R                  R                   35      e7f)zçCompact messages to reduce conversation context size.

This method is optional and only supported by specific providers
(e.g. OpenAI Responses API). Providers that support compaction
override this method with their implementation.
z'Message compaction is not supported by r:  )r³   Úrequest_contextr?  s      rz   Úcompact_messagesÚModel.compact_messages'  s%   é € ô "Ð$KÈDÏNÉN×LcÑLcÐKdÐ"eÓfÐfùr>  c               óN   #   • [        SU R                  R                   35      e7f)z<Make a request to the model and return a streaming response.z(Streamed requests not supported by this r:  )r³   rç   ré   rê   Úrun_contexts        rz   Úrequest_streamÚModel.request_stream5  s%   é € ô "Ð$LÈTÏ^É^×MdÑMdÐLeÐ"fÓgÐgùr>  c              ƒ  ó   #   • g7f)zéCancel a server-side suspended/background response (e.g. an OpenAI background job).

Called when a continuation is abandoned via cancellation or error. No-op by default;
model classes with cancellable server-side jobs override this.
Nrx   ©r³   Úresponses     rz   Úcancel_suspended_responseÚModel.cancel_suspended_responseD  s
   é € ð ùó   ‚c                ó   • g)a`  Seconds to wait before continuing a suspended response, or `None` to continue immediately.

Called between the segments of a suspended turn. `None` by default (e.g. Anthropic `pause_turn`
continues immediately); a model that polls a server-side job (e.g. OpenAI background mode)
overrides this to return a poll interval so the graph doesn't busy-poll.
Nrx   rI  s     rz   Úcontinuation_delayÚModel.continuation_delayL  s   € ð ry   c                óP  • U R                   R                  S5      =n(       ay  [        UUR                   Vs/ s H  n[	        X#5      PM     snUR
                   Vs/ s H  n[	        X#5      PM     snS9nUR                  =n(       a  [        U[        X$5      S9nU$ s  snf s  snf )a0  Customize the request parameters for the model.

This method can be overridden by subclasses to modify the request parameters before sending them to the model.
In particular, this method can be used to make modifications to the generated tool JSON schemas if necessary
for vendor/model-specific reasons.
Újson_schema_transformer)rŸ   r§   ©r¦   )r  r°   r   rŸ   Ú_customize_tool_defr§   r¦   Ú_customize_output_object)r³   rê   ÚtransformerÚtr¦   s        rz   Úcustomize_request_parametersÚ"Model.customize_request_parametersU  s§   € ð Ÿ,™,×*Ñ*Ð+DÓEÐEˆ;ÕEÜ'.Ø(ØMe×MtÒMtÓuÒMtÈÔ 3°KÖ CÑMtÑuØKc×KpÒKpÓqÒKpÀaÔ1°+ÖAÑKpÑqñ(Ð$ð
 !9× FÑ FÐFˆ}ÕFÜ+2Ø,Ü":¸;Ó"Vñ,Ð(ð
 (Ð'ùò  vùÚqs   ·B
ÁB#c           
     ór  • [        U R                  U5      nU R                  U5      n[        X0R                  R                  SS5      S9nU(       a«  SU;   a¥  US   nU R                  R                  SS5      nU R                  R                  SS5      nU(       d  U(       a  USL a  U(       d	  [        X4S9nUR                  5        VVs0 s H  u  pxUS:w  d  M  Xx_M     n	nnU	(       a  [        [        U	5      OSnUR                  =n
(       a<  [        U[        U
 Vs0 s H  o»R                  U_M     snR                  5       5      S	9nUR                  U R                  R                  S
S5      5      nUR                  (       a  UR                   S:w  a
  [        U/ S9nUR"                  (       a  UR                   S;  a
  [        USS9nUR$                  (       a  UR                   S;  a
  [        USS9nUR                   S:X  d1  UR                   S:X  aV  U R                  R                  SS5      (       a5  UR$                  c(  [        UU R                  R                  S[&        5      S9nUR(                  =n(       a>  / UR*                  =(       d    / Q[-        US9Pn[        U[,        R.                  " U5      S9nUR                   S:X  a,  U R                  R                  SS5      (       d  [1        S5      eUR                   S:X  a,  U R                  R                  SS5      (       d  [1        S5      eUR2                  (       a,  U R                  R                  SS5      (       d  [1        S5      eUR4                  (       a,  U R                  R                  SS5      (       d  [1        S5      eUR                  (       d!  [7        S  UR8                   5       5      (       a  U R;                  U5      nX4$ [        UUR8                   Vs0 s H  oîR<                  S!_M     snS"9nX4$ s  snnf s  snf s  snf )#aù  Prepare request inputs before they are passed to the provider.

This merges the given `model_settings` with the model's own `settings` attribute and ensures
`customize_request_parameters` is applied to the resolved
[`ModelRequestParameters`][pydantic_ai.models.ModelRequestParameters]. Subclasses can override this method if
they need to customize the preparation flow further, but most implementations should simply call
`self.prepare_request(...)` at the start of their `request` (and related) methods.
Úsupports_tool_return_schemaF)r[  r®   Úsupports_thinkingÚthinking_always_enabled)r®   N)r    Údefault_structured_output_moderÄ   )r§   rÍ   rS  )rÏ   rÎ   )r¨   rÏ   rÎ   Ú-native_output_requires_schema_in_instructionsr¨   ©Úcontent)r­   Úsupports_json_schema_outputz8Native structured output is not supported by this model.Úsupports_toolsTz+Tool output is not supported by this model.Úsupports_text_outputz¢Text output is not supported by this model. Give the agent one structured `output_type`, such as a `BaseModel`, without `str`, `NativeOutput` or `PromptedOutput`.Úsupports_image_outputz,Image output is not supported by this model.c              3  ó„   #   • U  H6  oR                   =(       d    UR                  =(       d    UR                  v •  M8     g 7frº   ©Úunless_nativeÚwith_nativer²   ©Ú.0rW  s     rz   Ú	<genexpr>Ú(Model.prepare_request.<locals>.<genexpr>¿  s+   é € ð &
ÚI^ÀA�O‰O×?˜qŸ}™}×?°·±Ô?ÒI^ùó   ‚>A r”   )r¡   )ri   r  rX  Úprepare_return_schemasr  r°   r   Úitemsr   rg   r    rÜ   Ú	unique_idÚvaluesrÐ   r§   r¥   r¦   r¨   r\   rÉ   r­   r:   Úsortedr0   rª   r«   r  rŸ   Ú_resolve_request_toolsr»   )r³   ré   rê   ÚparamsÚthinking_valuer\  r]  ÚkÚvÚstrippedr    rÄ   Úoutput_instrÚpartsrW  s                  rz   Úprepare_requestÚModel.prepare_requestj  sÅ  € ô .¨d¯m©m¸^ÓLˆà×2Ñ2Ð3KÓLˆÜ'Ø·±×0@Ñ0@ÐA^Ð`eÓ0fñ
ˆö
 ˜j¨NÓ:Ø+¨JÑ7ˆNØ $§¡× 0Ñ 0Ð1DÀeÓ LÐØ&*§l¡l×&6Ñ&6Ð7PÐRWÓ&XÐ#Þ Ö$;Ø&¨%Ò/Ö4KÜ$ VÑE�FØ)7×)=Ñ)=Ô)?ÔSÒ)?¡ À1È
Á?›˜šÑ)?ˆHÑSÞ>FœT¤-°Ô:ÈDˆNà!×.Ñ.Ð.ˆ<Õ.äØÜ!ÁLÓ"QÂL¸D§>¡>°4Ò#7ÁLÑ"Q×"XÑ"XÓ"ZÓ[ñˆFð
 ×0Ñ0°·±×1AÑ1AÐBbÐdjÓ1kÓlˆð ×× 6×#5Ñ#5¸Ó#?Ü˜V°"Ñ5ˆFØ×× F×$6Ñ$6Ð>TÓ$TÜ˜V°4Ñ8ˆFØ×*×*¨v×/AÑ/AÐI_Ó/_Ü˜V¸dÑCˆFð ×Ñ *Ó,à×"Ñ" hÓ.Ø—L‘L×$Ñ$Ð%TÐV[×\Ñ\à×-Ñ-Ñ5ÜØØ)-¯©×)9Ñ)9Ð:TÔVvÓ)wñˆFð "×>Ñ>Ð>ˆ<Õ>Ø^�v×/Ñ/×5°2Ð^¼ÐP\Ñ8]Ð^ˆEÜ˜V´×7MÒ7MÈeÓ7TÑUˆFð ×Ñ Ó)°$·,±,×2BÑ2BÐC`Ðbg×2hÑ2hÜÐVÓWÐWØ×Ñ Ó'°·±×0@Ñ0@ÐAQÐSW×0XÑ0XÜÐIÓJÐJØ×#×#¨D¯L©L×,<Ñ,<Ð=SÐUY×,ZÑ,ZÜð\óð ð ×$×$¨T¯\©\×-=Ñ-=Ð>UÐW\×-]Ñ-]ÜÐJÓKÐKð ××¤#ñ &
ØIO×I^ÒI^ó&
÷ #
ñ #
ð ×0Ñ0°Ó8ˆFð Ð%Ð%ô ØØ<B×<QÒ<QÓ RÒ<Q°q§¡¨Ò!2Ñ<QÑ RñˆFð
 Ð%Ð%ùóM Tùò #Rùòx !Ss   ÃP)ÃP)ÄP/ÐP4
c           	     ó&  • [        XR                  R                  SS5      S9nU R                  SLnU R	                  X5      nU VVs/ s HG  n[        U[        5      (       d  M  UR                    H  n[        U[        5      (       d  M  UPM     MI     nnn[        U R                  R                  S[        5      ;   nU(       ar  U(       dk  Ub9  UR                   Vs1 s H!  oˆR                  (       d  M  UR                  iM#     snOSn	U R                  U5      (       a  [        X5      nO[!        X5      nSSKJn
  U(       a  U R&                  OSnU
" XS9nU R                  R                  S	S5      (       d  [)        U5      nU$ s  snnf s  snf )
aŸ  Pre-process the message history before it's handed to the adapter's message-prep step.

Translates typed `NativeToolSearch*Part` instances carried over from a
different provider (e.g. Anthropic to OpenAI Responses), or any native
provider when the active model doesn't support `ToolSearchTool`, into the
local-shape `ToolSearch*Part` instances. This splits the single
`ModelResponse(call+return)` carrying the inline server-side result into
`ModelResponse(call) + ModelRequest(return)` so the adapter can render the
provider-agnostic exchange.

Also wraps non-leading `SystemPromptPart`s as `<system>`-tagged `UserPromptPart`s when
the profile's `supports_inline_system_prompts` is `False`, and converts
`SpeechPart`s from realtime session history into `UserPromptPart`s /
`TextPart`s that any model can consume.

Subclasses normally don't need to override this; the framework calls it on the
agent's behalf in `_agent_graph._make_request` so per-adapter message-prep code
sees a homogeneous shape regardless of which provider produced the prior turn.

Args:
    messages: The history to pre-process.
    model_request_parameters: The parameters this history will be sent with. Optional, and
        only needed to render a `ToolAvailabilityDeltaPart` on a model with no native way to
        express one: whether that reveal has to be a mechanism or can just be a statement
        depends on whether any tool actually goes on the wire with its schema withheld, which
        the profile alone can't answer. Omitting it falls back to the adapter's effective mode,
        which differs only for a corpus mixing capability-gated and standalone deferred tools.
        Framework callers pass it.
Úsupports_audio_inputF)Úinclude_audioNÚsupported_native_toolsr$   )Ú%synthesize_local_tool_search_messages)Útarget_provider_nameÚsupports_inline_system_prompts)Ú_convert_speech_partsr  r°   r(  Ú_translate_legacy_tool_revealsÚ
isinstancer<   r{  rJ   rW   rT   rŸ   r²   r»   Ú_hides_deferred_schemasÚ,_synthesize_tool_availability_delta_messagesÚ*_announce_tool_availability_delta_messagesÚ_tool_searchr‚  r/  Ú _wrap_non_leading_system_prompts)r³   rç   rê   Úsupports_tool_additionÚmessageÚpartÚdelta_partsÚsupports_native_tool_searchrÄ   Údeferred_tool_namesr‚  rƒ  s               rz   Úprepare_messagesÚModel.prepare_messagesÎ  so  € ôD )¨ÇÁ×AQÑAQÐRhÐjoÓApÑqˆà!%×!8Ñ!8ÀÐ!DÐØ×6Ñ6°xÓZˆñ $ô
â#�Ü˜'¤<×0ó ð  Ÿ��Ü˜$Ô 9×:÷	 ñ &ñ Ù#ð 	ñ 
ô '5¸¿¹×8HÑ8HØ$Ô&<ó9
ñ '
Ð#ö Ö5ð ,Ñ7ð (@×'NÒ'NÓeÒ'N˜t×RdÕRd“�—”Ñ'NÒeàð  ð0 ×+Ñ+Ð,D×EÑEÜGÈÓf‘äEÀhÓd�åHæ.I˜tŸ{š{ÈtÐÙ8¸Ñmˆà�|‰|×ÑÐ @À%×HÑHÜ7¸ÓAˆHàˆùóo
ùò& fs   ÁFÁ%#FÂ
FÃFÃ7Fc                ód   • Ub  U R                   c  U$ [        X5      nU(       d  U$ [        X5      $ )uF  Upgrade framework-fabricated legacy reveal exchanges onto this model's reveal channel.

Pre-delta lazy-capability code stored a fabricated `search_tools` exchange after each
`load_capability` call. Where this model has a native reveal channel, that fabrication is
upgraded to the availability delta it always represented, and renders as `tool_addition` /
`additional_tools`. On a channel-less target the exchange already replays byte-stably as
plain tool parts and the revealed tool reaches the wire regardless (deferred entry or
visible definition), so it is left alone â€” translating would change the replayed prefix
for no gain. Deciding on the adapter's effective mode alone also keeps this from resolving native tools
here, which would preempt `prepare_request`'s more specific unsupported-tool errors.

Genuine search exchanges â€” native or local, from any provider â€” are never rewritten: a
real search is evidence of what the model did, and the cross-provider local-search
projection already carries its reveal. This changes only the outgoing copy; stored history
remains untouched.
)r(  Ú&_legacy_fabricated_tool_search_revealsÚ*_replace_tool_search_exchanges_with_deltas)r³   rç   rê   Útranslated_call_idss       rz   r†  Ú$Model._translate_legacy_tool_reveals-  s8   € ð* $Ñ+¨t×/FÑ/FÑ/NØˆOäDÀXÓhÐÞ"ØˆOä9¸(ÓXÐXry   c                ó2  • Uc  U R                   S:H  $ UR                  (       d"  [        S UR                   5       5      (       d  gUR                  b  UOU R                  U5      n[        S UR                  =(       d    0 R                  5        5       5      $ )zFWhether this request puts a tool on the wire with its schema withheld.Ú
standalonec              3  ó„   #   • U  H6  oR                   =(       d    UR                  =(       d    UR                  v •  M8     g 7frº   rg  rj  s     rz   rl  Ú0Model._hides_deferred_schemas.<locals>.<genexpr>S  s)   é € ÐfÒPeÈ1—?‘?×F a§m¡m×F°q·±ÔFÒPeùrn  Fc              3  ó*   #   • U  H	  oS :H  v •  M     g7f)r•   Nrx   )rk  rµ   s     rz   rl  r�  Y  s   é € ÐhÒ>g°
 Ö+Ò>gùs   ‚)r"  r    r  rŸ   r¡   rt  rr  )r³   ru  Úresolveds      rz   rˆ  ÚModel._hides_deferred_schemasK  s„   € à‰>Ø×*Ñ*¨lÑ:Ð:ð ××ÜÑfÐPV×PeÒPeÓf×fÑfàð $×3Ñ3Ñ?‘6ÀT×E`ÑE`ÐagÓEhˆÜÑh¸x×?WÑ?W×?]Ð[]×>eÑ>eÔ>gÓhÓhÐhry   c                ó~   • [        UU R                  R                  S[        5      U R                  U R
                  S9$ )zYResolve native tools, their local fallbacks, and deferred-tool visibility for this model.r�  ©Úcan_withhold_tool_schemasr(  )Úresolve_request_toolsr  r°   rT   Ú_can_withhold_tool_schemasr(  )r³   ru  s     rz   rt  ÚModel._resolve_request_tools[  s:   € ä$ØØ�L‰L×ÑÐ5Ô7MÓNØ&*×&EÑ&EØ#×6Ñ6ñ	
ð 	
ry   c                óZ   • U R                   nUS:X  a  gUS:X  a  [        S U 5       5      $ g)aS  Whether this request can declare a function tool while withholding its schema.

`'standalone'` always permits it. `'with_tool_search'` permits it only when a
[`ToolSearchTool`][pydantic_ai.native_tools.ToolSearchTool] survives request resolution.
The result feeds the single `tool_visibility` decision table; `defer_loading` is unchanged.
r›  TÚwith_tool_searchc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   ©r‡  rW   rj  s     rz   rl  Ú3Model._can_withhold_tool_schemas.<locals>.<genexpr>o  s   é € ÐKºl¸”z !¤^×4Ð4ºlùó   ‚F)r"  r  )r³   r    r"  s      rz   r¥  Ú Model._can_withhold_tool_schemasd  s8   € ð "×4Ñ4ÐØ Ó-ØØÐ!3Ó3ÜÑK¹lÓKÓKÐKØry   c                ó   • [        5       $ )zËReturn the set of native tool types this model class can handle.

Subclasses should override this to reflect their actual capabilities.
Default is empty set - subclasses must explicitly declare support.
)Ú	frozenset)Úclss    rz   r�  ÚModel.supported_native_toolsr  s   € ô ‹{Ðry   c                ó8   • U R                   R                  S5      $ )z\The resolved profile's [`context_window`][pydantic_ai.profiles.ModelProfile.context_window].Úcontext_window)r  r°   rÈ   s    rz   r³  ÚModel.context_window{  s   € ð �|‰|×ÑÐ 0Ó1Ð1ry   c                óX  • 0 nU R                   =nb$  UR                  U R                  5      =(       d    0 n[        [        U5      nU R
                  nSU;   =(       d'    USL=(       a    [        U5      (       + =(       a    SU;   nU(       d!  [        U 5      nUb  [        U[        US95      nUc  O-[        U5      (       a  [        U" U5      5      nO[        X45      nU R                  R                  5       nUR                  S[        5      nX‡-  n	X˜:w  a  [        U[        U	S95      nU$ )u=  The model profile.

Resolution order (later layers override earlier ones):
  1. `DEFAULT_PROFILE` â€” base values for every key in `ModelProfile`.
  2. The provider's `model_profile(model_name)` result â€” provider-specific defaults
     for this model.
  3. A best-effort `context_window` value from
     [genai-prices](https://github.com/pydantic/genai-prices), unless the provider or a
     partial user profile explicitly set the field (including to `None`).
  4. The user's `profile=` argument â€” partial dict merged on top, OR a callable
     `(default) -> profile` for full control.

After resolution we compute the intersection of the profile's `supported_native_tools`
and the model class's implemented tools, ensuring `model.profile['supported_native_tools']`
is the single source of truth for what's actually usable.
Nr³  ©r³  r�  )r�  )r  Úmodel_profileÚ
model_namerb   r[   rÿ   Úcallabler&   r]   ra   r;  r�  r°   rT   )
r³   Úprovider_profiler  rŸ  ÚuserÚcontext_window_setr³  Úmodel_supportedÚprofile_supportedÚeffective_toolss
             rz   r  ÚModel.profile€  s  € ð& *,ÐØŸ™Ð%ˆHÑ2Ø'×5Ñ5°d·o±oÓF×LÈ"ÐÜ ¤Ð2BÓCˆð �}‰}ˆØ-Ð1AÑA÷ 
Ø˜Ð×P¤X¨d£^Ô!3×PÐ8HÈDÑ8Pð 	ö "Ü2°4Ó8ˆNØÑ)Ü(¨´<È~Ñ3^Ó_�ð ‰<ØÜ�d�^‰^ô 6±d¸8³nÓE‰Hô % XÓ4ˆHð Ÿ.™.×?Ñ?ÓAˆØ$ŸL™LÐ)AÔCYÓZÐØ+Ñ=ˆØÓ/Ü$ X¬|ÐSbÑ/cÓdˆHàˆry   c                óh   • [         R                  " XR                  [        U 5      R                  S9  g)zWRaise `UserError` if an `UploadedFile` references a different provider than this model.)r/  Úmodel_type_nameN)r%   Úvalidate_uploaded_file_providerr/  Útyper×   )r³   Úitems     rz   Ú _validate_uploaded_file_providerÚ&Model._validate_uploaded_file_provider¶  s#   € ä×.Ò.¨t¿K¹KÔY]Ð^bÓYc×YlÑYlÓmry   c                óÞ  • UR                   b  UR                   =(       d    S$ / n[        U 5       H_  n[        U[        5      (       d  M  UR	                  U5        [        U5      S:X  a    O'UR                  c  MK  [        UR                  S9/s  $    [        U5      S:X  aL  US   nUS   n[        S UR                   5       5      (       a!  UR                  b  [        UR                  S9/$ g)a$  Get structured instruction parts for the current request.

Uses `model_request_parameters.instruction_parts` when set (normal agent flow).
Falls back to synthesizing from `ModelRequest.instructions` in message history
when `instruction_parts` is `None` (e.g. direct `model.request()` calls).
Nr$   r`  r   rl   c              3  ój   #   • U  H)  oR                   S :H  =(       d    UR                   S:H  v •  M+     g7f)ztool-returnzretry-promptN)Ú	part_kind©rk  Úps     rz   rl  Ú/Model._get_instruction_parts.<locals>.<genexpr>Ø  s+   é € ÐmÒ[lÐVW—K‘K =Ñ0×Q°A·K±KÀ>Ñ4QÔQÒ[lùs   ‚13)
r­   Úreversedr‡  r<   ÚappendÚlenr?  r:   Úallr{  )rç   rê   Úlast_two_requestsrŽ  Úmost_recentÚseconds         rz   Ú_get_instruction_partsÚModel._get_instruction_partsº  sã   € ð $×5Ñ5ÑAØ+×=Ñ=×EÀÐEð 13ÐÜ Ö)ˆGÜ˜'¤<×0Ó0Ø!×(Ñ(¨Ô1ÜÐ(Ó)¨QÓ.ÙØ×'Ñ'Ó3Ü+°G×4HÑ4HÑIÐJÒJñ *ô Ð Ó! QÓ&Ø+¨AÑ.ˆKØ& qÑ)ˆFäÑmÐ[f×[lÒ[lÓm×mÑmØ×'Ñ'Ñ3ä'°×0CÑ0CÑDÐEÐEàry   )rÿ   r   )r  rè   r  rþ   rÓ   ÚNone)rÓ   z Provider[InterfaceClient] | None)rÓ   r   )r  ztype[BaseException] | Noner  zBaseException | Noner  zTracebackType | NonerÓ   úbool | None)rÓ   rè   )ré   rè   rÓ   útimedelta | None)r  z!bool | Literal['5m', '1h'] | NonerÓ   rÙ  )rÓ   zToolDeferralMode | None)rÓ   úToolAdditionMode | None)rç   ræ   r*  rØ  rÓ   ræ   )rç   ræ   ré   rè   rê   r›   rÓ   r>   )rç   ræ   ré   rè   rê   r›   rÓ   rk   )rA  rã   r?  rÖ   rÓ   r>   rº   )
rç   ræ   ré   rè   rê   r›   rE  zRunContext[Any] | NonerÓ   z AsyncGenerator[StreamedResponse])rJ  r>   rÓ   r×  )rJ  r>   rÓ   úfloat | None)rê   r›   rÓ   r›   )ré   rè   rê   r›   rÓ   z3tuple[ModelSettings | None, ModelRequestParameters])rç   ræ   rê   úModelRequestParameters | NonerÓ   ræ   )ru  rÜ  rÓ   r©   )ru  r›   rÓ   r›   )r    zSequence[AbstractNativeTool]rÓ   r©   )rÓ   ú#frozenset[type[AbstractNativeTool]])rÓ   z
int | None)rÓ   r]   )rÅ  rO   rÓ   r×  )rç   zSequence[ModelMessage]rê   r›   rÓ   r¬   )0r×   rØ   rÙ   rÚ   rÛ   r¯  rù   rÝ   rú   rû   rü   rÿ   r   r  Úpropertyr  r  r  r  r  Ústaticmethodr  r"  r(  r0  r   r6  r<  rB  r   rF  rK  rO  rX  r|  r“  r†  rˆ  rt  r¥  Úclassmethodr�  r³  r   r  rÆ  rÕ  rá   rx   ry   rz   rä   rä   …  sV  ‡ Ù%áKTË;Ð!Ð#HÓVðñ LUË;Ð!Ð#HÓVØnØ<AÐ)¨>ÓAð
;ð :?Ð&¨Ó>ðeð )Ó(Ø(,€HÐ%Ó,Ø&*€IÐ#Ó*ð
 *.Ø+/ñ	ð 'ðð )ð	ð
 
õð  ó0ó ð0ôðEà,ðEð &ðEð %ð	Eð
 
ôEð óó ðô	ð ðØ:ðà	óó ðð óLó ðLð
 óLó ðLð 15ñ	
à$ð
ð #.ð	
ð
 
õ
ð4 ð
$à$ð
$ð -ð
$ð #9ð	
$ð
 
ó
$ó ð
$ðxà$ðxð -ðxð #9ð	xð
 
ôxð $(ñ	gà,ðgð !ð	gð
 
õgð ð /3ðà$ðð -ðð #9ð	ð
 ,ðð 
*ôó ðôôô(ð*b&à,ðb&ð #9ðb&ð 
=ô	b&ðN CGð]à$ð]ð #@ð]ð 
õ	]ð~Yà$ðYð #@ðYð 
ô	Yô<iô 
ôð óó ðð ó2ó ð2ð ó3ó ð3ôjnð ð"Ø(ð"ØDZð"à	%ó"ó ó"ry   rä   c                  ó4  • \ rS rSr% SrS\S'   \" SSS9rS\S	'   \" SSS9rS
\S'   \" SSS9r	S\S'   \" SSS9r
S\S'   \" SSS9rS\S'    \" SSS9rS\S'   \" SSS9rS\S'   \" \SS9rS\S'   \" SSS9rS\S'   \" SSS9rS\S'   \" SSS9rS\S'    \S-S j5       rS.S jrS/S  jrS0S! jrS/S" jr\S.S# j5       rS1S$ jr\S2S% j5       r\\S3S& j5       5       r\\S4S' j5       5       r\\S4S( j5       5       r \\S5S) j5       5       r!\S6S* j5       r"S7S+ jr#S,r$g)8ÚStreamedResponseià  z2Streamed response from an LLM when calling a tool.r›   rê   NF)ÚdefaultÚinitúFinalResultEvent | NoneÚfinal_result_eventrÖ   Úprovider_response_idzdict[str, Any] | NoneÚprovider_detailszFinishReason | NoneÚfinish_reasonÚcompleter@   ÚstateÚmetadataz.AsyncIterator[ModelResponseStreamEvent] | NoneÚ_event_iterator)r�   rä  rk   Ú_usager©   Ú
_cancelledÚ	_finishedrÛ  Ú_first_chunk_monotonicc                ó(   • [        U R                  S9$ )N)rê   )r,   rê   rÈ   s    rz   Ú_parts_managerÚStreamedResponse._parts_manager÷  s   € ô )À$×B_ÑB_Ñ`Ð`ry   c                óÌ   ^ • T R                   cK      SU 4S jjn    SU 4S jjn    SU 4S jjnU" U" U" T R                  5       5      5      5      T l         T R                   $ )aX  Stream the response as an async iterable of [`ModelResponseStreamEvent`][pydantic_ai.messages.ModelResponseStreamEvent]s.

This proxies the `_event_iterator()` and emits all events, while also checking for matches
on the result schema and emitting a [`FinalResultEvent`][pydantic_ai.messages.FinalResultEvent] if/when the
first match is found.
c               ó²   >#   • U   S h  v•N nU7v •  [        UTR                  5      =n c  M*  UTl        U7v •    U   S h  v•N nU7v •  M   ND
 N N
 g 7frº   )Ú_get_final_result_eventrê   ræ  )ÚiteratorÚeventræ  r³   s      €rz   Úiterator_with_final_eventÚ=StreamedResponse.__aiter__.<locals>.iterator_with_final_event	  sh   øé € ñ $,÷ ˜%Ø“Kä.EÀeÈT×MjÑMjÓ.kÐkÐ*Ø!ó"ð 3E˜Ô/Ø0Ó0Øñ $,÷  ˜%Ø•Kñ¡8ñ ¡8ùsM   ƒA†AŠA‹AŽA°A¿AÁAÁAÁAÁAÁAÁAÁAc               ó*  >^#   • S mSSUU4S jjjnU   S h  v•N n[        U[        5      (       aB  T(       a9  U" UR                  5      nU(       a  U7v •  TR                  R                  Ul        UmU7v •  Mg   Nb
 U" 5       nU(       a  U7v •  g g 7f)Nc                óî   >• T(       d  g TR                   nTR                  R                  5       U   n[        U[        [
        -  [        -  5      (       d  g [        UUU (       a  U R                  S9$ S S9$ )N)Úindexr�  Únext_part_kind)	rþ  ró  Ú	get_partsr‡  rH   rI   r2   rC   rÊ  )Ú	next_partrþ  r�  Úlast_start_eventr³   s      €€rz   Úpart_end_eventÚRStreamedResponse.__aiter__.<locals>.iterator_with_part_end.<locals>.part_end_event  sw   ø€ Þ+Ø#à,×2Ñ2�EØ×.Ñ.×8Ñ8Ó:¸5ÑA�DÜ% d¬H´|Ñ,CÔFVÑ,V×WÑWà#ä'Ø#Ø!Þ>G y×':Ñ':ñð ð NRñð ry   rº   )r  zModelResponsePart | NonerÓ   zPartEndEvent | None)r‡  rD   r�  rÊ  Úprevious_part_kind)rø  r  rù  Ú	end_eventr  r³   s       @€rz   Úiterator_with_part_endÚ:StreamedResponse.__aiter__.<locals>.iterator_with_part_end  s‡   ùé € ð ;?Ð ÷ò ñ  $,÷ 
 ˜%Ü! %¬×8Ñ8Þ+Ù(6°u·z±zÓ(B˜IÞ(Ø&/£à7G×7LÑ7L×7VÑ7V˜EÔ4Ø+0Ð(à•Kñ
  8ñ +Ó,�	ÞØ#”Oð ùs&   „B”A=˜A;™A=œABÁ;A=Á=Bc               ó  >#   •  U   S h  v•N nTR                   c  [        R                  " 5       Tl         U7v •  M7   N2
 TR                  (       d  STl        g g ! TR                  5        a    TR                  (       d  e  g f = f7f©NT)rñ  ÚtimeÚperf_counterrï  rð  Úget_stream_cancel_errorsÚ	cancelled)rø  rù  r³   s     €rz   Úiterator_with_cancel_guardÚ>StreamedResponse.__aiter__.<locals>.iterator_with_cancel_guard?  s{   øé € ð.Ù'/÷ $˜eØ×6Ñ6Ñ>ä:>×:KÒ:KÓ:M˜DÔ7Ø#�ñ	$ xð(  Ÿ?Ÿ?Ø)-˜�ð +øð ×4Ñ4Ó6ó ØŸ>Ÿ>Øñ *ðüsF   ƒB…A ‡A ‹>ŒA �/A ¾A Á A ÁBÁ&BÂBÂBÂB)rø  ú'AsyncIterator[ModelResponseStreamEvent]rÓ   r  )rí  Ú_get_event_iterator)r³   rú  r  r  s   `   rz   Ú	__aiter__ÚStreamedResponse.__aiter__   s…   ø€ ð ×ÑÑ'ð ØAð à8÷ ð"#$ØAð#$à8÷#$ðJ.ØAð.à8÷.ñ> $>Ù&Ñ'@À×AYÑAYÓA[Ó'\Ó]ó$ˆDÔ ð ×#Ñ#Ð#ry   c              ƒ  ó–   #   • U R                   (       a  gSU l        U R                  (       a  gU R                  5       I Sh  v•N   g N7f)a)  Cancel local stream consumption and request provider shutdown.

Sets `self._cancelled = True` before delegating to `close_stream()`
so the flag is visible to any iterator that observes the transport error
raised when the underlying connection is torn down, even if
`close_stream()` itself raises.
NT)r  rï  rð  Úclose_streamrÈ   s    rz   ÚcancelÚStreamedResponse.cancelc  s6   é € ð �>�>ØØˆŒð �>�>ØØ×ÑÓ!×!Ó!ùs   ‚?A	ÁAÁA	c                óØ   •  SSK n[        R                  [        R                  UR                  UR                  4$ ! [         a#    [        R                  [        R                  4s $ f = f)aŽ  Return transport errors caused by `cancel()` tearing down the stream.

The default covers model classes whose SDKs iterate HTTP responses
directly (Anthropic, OpenAI, Groq, Mistral, Google GenAI, and HuggingFace),
since they let bare `httpx2` (or legacy `httpx`) errors propagate from
chunk reads. Model classes that use other transports (for example gRPC or
botocore) should override this method.
r   N)ÚhttpxÚImportErrorÚhttpx2ÚStreamErrorÚTransportError)r³   r  s     rz   r  Ú)StreamedResponse.get_stream_cancel_errorst  s[   € ð	?Ûô ×"Ñ"¤F×$9Ñ$9¸5×;LÑ;LÈe×NbÑNbÐcÐcøô ó 	?Ü×&Ñ&¬×(=Ñ(=Ð>Ò>ð	?ús   ‚< ¼*A)Á(A)c              ƒ  óN   #   • [        S[        U 5      R                   S35      e7f)a/  Close the provider stream and any exposed HTTP or gRPC transport.

Model classes must override this to close the local stream and, where the
provider SDK exposes one, its transport. Integrations that cannot support
local cancellation should leave the default implementation so `cancel()`
fails clearly.
z+Stream cancellation is not implemented for zT. This model class must override `close_stream()` to support streaming cancellation.)r4  rÄ  r×   rÈ   s    rz   r  ÚStreamedResponse.close_stream„  s3   é € ô "Ø9¼$¸t»*×:MÑ:MÐ9Nð Oað aó
ð 	
ùr>  c               ó   #   • [        5       e7f)aY  Return an async iterator of [`ModelResponseStreamEvent`][pydantic_ai.messages.ModelResponseStreamEvent]s.

This method should be implemented by subclasses to translate the vendor-specific stream of events into
pydantic_ai-format events.

It should use the `_parts_manager` to handle deltas, and should update the `_usage` attributes as it goes.
r3  rÈ   s    rz   r  Ú$StreamedResponse._get_event_iterator’  s   é € ô "Ó#Ð#ùr8  c                ó¦  • U R                   S:X  a  SnO:U R                  (       a  U R                   S:w  a  SnOU R                  (       a  SnOSn[        U R                  R                  5       U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  UU R                  S9$ )zlBuild a [`ModelResponse`][pydantic_ai.messages.ModelResponse] from the data received from the stream so far.Ú	suspendedÚ
incompleterê  Úinterrupted)r{  r¸  Ú	timestampr÷   Úprovider_nameÚprovider_urlrç  rè  ré  rë  rì  )rë  rð  rï  r>   ró  r   r¸  r(  rî  r)  r*  rç  rè  ré  rì  )r³   rë  s     rz   r°   ÚStreamedResponse.getŸ  s¨   € ð �:‰:˜Ó$Ø‰EØ�^�^ §
¡
¨lÓ :Ø‰EØ�_�_Ø!‰Eà ˆEÜØ×%Ñ%×/Ñ/Ó1Ø—‘Ø—n‘nØ—+‘+Ø×,Ñ,Ø×*Ñ*Ø!%×!:Ñ!:Ø!×2Ñ2Ø×,Ñ,ØØ—]‘]ñ
ð 	
ry   c                ó   • U R                   $ )zeGet the usage of the response so far. This will not be the final usage until the stream is exhausted.)rî  rÈ   s    rz   r÷   ÚStreamedResponse.usage½  s   € ð �{‰{Ðry   c                ó   • [        5       e)z#Get the model name of the response.r3  rÈ   s    rz   r¸  ÚStreamedResponse.model_nameÂ  ó   € ô "Ó#Ð#ry   c                ó   • [        5       e)zGet the provider name.r3  rÈ   s    rz   r)  ÚStreamedResponse.provider_nameÈ  r0  ry   c                ó   • [        5       e)zGet the provider base URL.r3  rÈ   s    rz   r*  ÚStreamedResponse.provider_urlÎ  r0  ry   c                ó   • [        5       e)z"Get the timestamp of the response.r3  rÈ   s    rz   r(  ÚStreamedResponse.timestampÔ  r0  ry   c                ó   • U R                   $ )z5Whether the stream has been cancelled via `cancel()`.)rï  rÈ   s    rz   r  ÚStreamedResponse.cancelledÚ  s   € ð �‰Ðry   c                ó,   • U R                   nUb  X!-
  $ S$ )aù  Seconds from `request_start` to the first chunk surfaced to the consumer, or `None` if nothing was yielded.

`request_start` must be a `time.perf_counter()` reading taken when the request was issued.
The first-chunk instant is stamped on the first `async for` pull, so the result reflects when
the consumer *received* the first event: it includes any consumer-side iteration delay
(debouncing, batching, or awaiting other work) on top of the chunk's transit time, which for
eager consumers is negligible.
N)rñ  )r³   Úrequest_startÚfirst_chunks      rz   Útime_to_first_chunkÚ$StreamedResponse.time_to_first_chunkß  s"   € ð ×1Ñ1ˆØ.9Ñ.Eˆ{Ñ*ÐOÈ4ÐOry   )rï  rí  rð  rñ  ræ  )rÓ   r,   ©rÓ   r  ©rÓ   r×  )rÓ   ztuple[type[BaseException], ...]©rÓ   r>   ©rÓ   rk   ©rÓ   rÒ   rÕ   ©rÓ   r   )rÓ   r©   )r:  ÚfloatrÓ   rÛ  )%r×   rØ   rÙ   rÚ   rÛ   rÝ   r   ræ  rç  rè  ré  rë  rì  rí  rk   rî  rï  rð  rñ  r   ró  r  r  r  r  r   r  r°   rÞ  r÷   r¸  r)  r*  r(  r  r<  rá   rx   ry   rz   râ  râ  à  s¿  ‡ á<à4Ó4á27ÀÈ5Ñ2QÐÐ/ÓQá',°TÀÑ'FÐ˜*ÓFÙ.3¸DÀuÑ.MÐÐ+ÓMÙ).°tÀ%Ñ)H€MÐ&ÓHÙ %¨j¸uÑ E€EÐÓEØ*Ù&+°D¸uÑ&E€HÐ#ÓEáFKÐTXÐ_dÑFe€OÐCÓeÙ °ÀEÑJ€FˆLÓJÙ U°Ñ7€J�Ó7Ù E°Ñ6€IˆtÓ6Ù+0¸ÀEÑ+JÐ˜LÓJðPð óaó ðaôa$ôF"ô"dô 
ð ó
ó ð
ô
ð< óó ðð Øó$ó ó ð$ð Øó$ó ó ð$ð Øó$ó ó ð$ð Øó$ó ó ð$ð óó ð÷
Pry   râ  c                  óî  ^ • \ rS rSrSr\SS.       SS jj5       r\\" S5      SS.       SS jj5       5       r\\" S5      SS	.       SS
 jj5       5       r\\" S5      SS	.       SS jj5       5       r S\R                  SS.       SU 4S jjjjrS U 4S jjr
S!S jrS S jrS"S jrS#U 4S j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SrU =r$ )(ÚCompletedStreamedResponseiì  uÊ  A `StreamedResponse` that wraps an already-completed `ModelResponse`.

Used when a [`StreamedResponse`][pydantic_ai.models.StreamedResponse] is needed but no
live stream is available â€” for example, when an agent run is short-circuited by
[`SkipModelRequest`][pydantic_ai.exceptions.SkipModelRequest], when a capability's
[`wrap_model_request`][pydantic_ai.capabilities.AbstractCapability.wrap_model_request]
short-circuits without calling the handler, or when a durable-execution capability drains
the real stream inside an activity/step/task and only surfaces the final
[`ModelResponse`][pydantic_ai.messages.ModelResponse] to the workflow.

What the stream yields is controlled by `replay_events`:

- `False` (default): yield no events â€” the response is complete and no streaming
  consumer needs to observe it.
- `True`: synthesize `PartStartEvent` + `PartDeltaEvent` sequences from the response
  parts, so streaming consumers (`event_stream_handler`, `run_stream_events`, ...)
  keep working when only a complete `ModelResponse` exists.
- a list of events: replay events that were captured off the live stream elsewhere
  (e.g. inside a durable-execution activity/step/task), preserving the real
  event granularity.
F)Úreplay_eventsc               ó   • g rº   rx   )r³   rJ  rê   rG  s       rz   r  Ú"CompletedStreamedResponse.__init__  s   € ð ry   zMPass the response first and `model_request_parameters` as a keyword argument.c              ó   • g rº   rx   )r³   rê   rJ  rG  s       rz   r  rI    ó   € ð ry   z(Use `replay_events` instead of `events`.)Úeventsc               ó   • g rº   rx   )r³   rJ  rê   rL  s       rz   r  rI    s   € ð ry   c              ó   • g rº   rx   )r³   rê   rJ  rL  s       rz   r  rI  !  rK  ry   N)rG  rL  c               óÊ  >• Ub;  [         R                  " S[        SS9  [        U[        R
                  5      (       a  Un[        U[        R
                  5      (       a  Sn[        U[        5      (       a+  [         R                  " S[        SS9  [        [        U5      Up![        U[        5      (       d   e[        TU ])  U5        Xl        UR                  U l        X0l        g )Nz4`events` is deprecated; use `replay_events` instead.r$   ©Ú
stacklevelFzá`CompletedStreamedResponse(model_request_parameters, response)` is deprecated; pass the response first and `model_request_parameters` as a keyword argument: `CompletedStreamedResponse(response, model_request_parameters=...)`.)ÚwarningsÚwarnr.   r‡  r%   ÚUnsetr›   r   r>   Úsuperr  rJ  rë  Ú_replay_events)r³   rJ  rê   rG  rL  r;  s        €rz   r  rI  ,  sÄ   ø€ ð ÑÜ�MŠMØFÜ,Øòô ˜-¬¯©×6Ñ6Ø &�Ü�m¤V§\¡\×2Ñ2Ø!ˆMä�hÔ 6×7Ñ7ô �MŠMðWô -Øòô 26´mÐE]Ó1^Ð`hÐ.ÜÐ2Ô4J×KÑKÐKÐKÜ‰ÑÐ1Ô2Ø ŒØ—^‘^ˆŒ
Ø+Õry   c                óÐ   >• [        U R                  [        5      (       d  [        TU ]  5       $ U R
                  c   U R                  U R                  5      U l        U R
                  $ rº   )r‡  rV  rÜ   rU  r  rí  Ú_iter_buffered©r³   r;  s    €rz   r  Ú#CompletedStreamedResponse.__aiter__R  sW   ø€ Ü˜$×-Ñ-¬t×4Ñ4Ü‘7Ñ$Ó&Ð&ð ×ÑÑ'Ø#'×#6Ñ#6°t×7JÑ7JÓ#KˆDÔ Ø×#Ñ#Ð#ry   c               ól   #   • U H#  nU R                   R                  U5        U7v •  M%     SU l        g 7fr
  )ró  Úapply_eventrð  )r³   rL  rù  s      rz   rX  Ú(CompletedStreamedResponse._iter_buffered\  s1   é € ÛˆEØ×Ñ×+Ñ+¨EÔ2Ø�Kñ ð ˆ�ùs   ‚24c               óÒ   #   • U R                   SL a  g U R                  R                   H9  nU R                  R	                  S US9n[        U[        5      (       d   eU7v •  M;     g 7f)NF)Úvendor_part_idr�  )rV  rJ  r{  ró  Úhandle_partr‡  rD   )r³   r�  Ústart_events      rz   r  Ú-CompletedStreamedResponse._get_event_iteratorb  sc   é € ð ×Ñ %Ò'ØØ—M‘M×'Ô'ˆDð ×-Ñ-×9Ñ9ÈÐTXÐ9ÐYˆKÜ˜k¬>×:Ñ:Ð:Ð:ØÕò (ùs   ‚A%A'c              ƒ  ó   #   • g 7frº   rx   rÈ   s    rz   r  Ú&CompletedStreamedResponse.close_streams  s   é € àùrM  c                óà   >• [        U R                  [        5      (       aC  [        U R                  U R
                  R                  5       [        TU ]!  5       R                  S9$ U R                  $ )N)r{  rë  )
r‡  rV  rÜ   r   rJ  ró  r   rU  r°   rë  rY  s    €rz   r°   ÚCompletedStreamedResponse.getw  sW   ø€ Ü�d×)Ñ)¬4×0Ñ0ÜØ—‘Ø×)Ñ)×3Ñ3Ó5Ü‘g‘k“m×)Ñ)ñð ð
 �}‰}Ðry   c                ó.   • U R                   R                  $ rº   )rJ  r÷   rÈ   s    rz   r÷   ÚCompletedStreamedResponse.usage€  s   € à�}‰}×"Ñ"Ð"ry   c                ó@   • U R                   R                  =(       d    S$ )NÚ )rJ  r¸  rÈ   s    rz   r¸  Ú$CompletedStreamedResponse.model_name„  s   € à�}‰}×'Ñ'×-¨2Ð-ry   c                ó.   • U R                   R                  $ rº   )rJ  r)  rÈ   s    rz   r)  Ú'CompletedStreamedResponse.provider_nameˆ  s   € à�}‰}×*Ñ*Ð*ry   c                ó.   • U R                   R                  $ rº   )rJ  r*  rÈ   s    rz   r*  Ú&CompletedStreamedResponse.provider_urlŒ  s   € à�}‰}×)Ñ)Ð)ry   c                ó.   • U R                   R                  $ rº   )rJ  r(  rÈ   s    rz   r(  Ú#CompletedStreamedResponse.timestamp�  s   € à�}‰}×&Ñ&Ð&ry   )rí  rð  rV  rJ  rë  )rJ  r>   rê   r›   rG  ú%bool | list[ModelResponseStreamEvent]rÓ   r×  )rê   r›   rJ  r>   rG  rr  rÓ   r×  )rJ  r>   rê   r›   rL  rr  rÓ   r×  )rê   r›   rJ  r>   rL  rr  rÓ   r×  rº   )rJ  z&ModelResponse | ModelRequestParametersrê   z-ModelRequestParameters | ModelResponse | NonerG  z4bool | list[ModelResponseStreamEvent] | _utils.UnsetrL  z,bool | list[ModelResponseStreamEvent] | Noner>  )rL  zlist[ModelResponseStreamEvent]rÓ   r  r?  r@  rA  rB  rÕ   rC  )r×   rØ   rÙ   rÚ   rÛ   r   r  r"   r%   ÚUNSETr  rX  r  r  r°   rÞ  r÷   r¸  r)  r*  r(  rá   Ú__classcell__)r;  s   @rz   rF  rF  ì  sý  ø† ñð, ð @Eñàðð #9ð	ð
 =ðð 
ôó ðð ÙÐ_Ó`ð @Eñà"8ðð  ðð =ðð 
ôó aó ðð ÙÐ:Ó;ð 9>ñàðð #9ð	ð
 6ðð 
ôó <ó ðð ÙÐ:Ó;ð 9>ñà"8ðð  ðð 6ðð 
ôó <ó ðð SWð$,ð
 OUÏlÉlØ?Cñ$,à8ð$,ð #Pð$,ð
 Lð$,ð =÷$,ñ $,÷L$ôôô"÷ð ó#ó ð#ð ó.ó ð.ð ó+ó ð+ð ó*ó ð*ð ó'ó ö'ry   rF  c                 ó0   • [         (       d  [        S5      eg)u¸  Check if model requests are allowed.

If you're defining your own models that have costs or latency associated with their use, you should call this at the
top of each method that sends a request to the provider: [`Model.request`][pydantic_ai.models.Model.request],
[`Model.request_stream`][pydantic_ai.models.Model.request_stream],
[`Model.count_tokens`][pydantic_ai.models.Model.count_tokens],
[`Model.compact_messages`][pydantic_ai.models.Model.compact_messages],
[`EmbeddingModel.embed`][pydantic_ai.embeddings.EmbeddingModel.embed],
[`EmbeddingModel.count_tokens`][pydantic_ai.embeddings.EmbeddingModel.count_tokens] and
[`ImageGenerationModel.generate`][pydantic_ai.images.ImageGenerationModel.generate].

Methods that produce their result locally don't need it â€” for example
[`OpenAIEmbeddingModel`][pydantic_ai.embeddings.openai.OpenAIEmbeddingModel]'s `count_tokens`, which tokenizes with
`tiktoken` and never calls the provider. Neither does
[`Model.cancel_suspended_response`][pydantic_ai.models.Model.cancel_suspended_response], which deliberately omits it
so an already-started job can still be cancelled after the flag is flipped.

Raises:
    RuntimeError: If model requests are not allowed.
zCModel requests are not allowed, since ALLOW_MODEL_REQUESTS is FalseN)ÚALLOW_MODEL_REQUESTSÚRuntimeErrorrx   ry   rz   Úcheck_allow_model_requestsrx  ¤  s   € ÷*  ÒÜÐ`ÓaÐað  ry   c              #  ó8   #   • [         nU q  Sv •  Uq g! Uq f = f7f)zÀContext manager to temporarily override [`ALLOW_MODEL_REQUESTS`][pydantic_ai.models.ALLOW_MODEL_REQUESTS].

Args:
    allow_model_requests: Whether to allow model requests within the context.
N)rv  )Úallow_model_requestsÚ	old_values     rz   Úoverride_allow_model_requestsr|  ½  s&   é € ô %€IØ/Ðð)Ûà(Ñø˜yÑüs   ‚	Œ �“—c                ó@   • SU ;   a  U R                  SSS9u  pX4$ SU 4$ )aZ  Parse a model id string into its provider and model name components.

Args:
    model: A model identifier string in the form `provider:model_name`.

Returns:
    A tuple of `(provider_name, model_name)`. If the model string contains no
    `provider:` prefix, returns `(None, model)` so callers can decide how to
    handle the unknown provider.
Ú:rl   ©ÚmaxsplitN)Úsplit)rå   r)  r¸  s      rz   Úparse_model_idr‚  Í  s3   € ð ˆeƒ|Ø$)§K¡K°¸a KÐ$@Ñ!ˆØÐ(Ð(à�ˆ;Ðry   c                óÜ  ^• Uc
  [        5       n[        US S9nU Vs/ s H  nSU;   d  M  UR                  SSS5      PM      nnU R                  SSS5      n[        XeSSS9=m(       a  [	        U4S jU 5       5      $ U Vs/ s H  nSU;   d  M  UR                  SSS	9S   PM      nn[        XSS
S9mT(       d  [        XgSSS9mT(       a  [	        U4S jU 5       5      $ g s  snf s  snf )Nc                ó(   • U R                  S5      U 4$ )Núgateway/)Ú
startswith)r»   s    rz   Ú<lambda>Ú+_suggest_known_model_name.<locals>.<lambda>â  s   € ¸$¿/¹/È*Ó:UÐW[Ñ9\ry   ©Úkeyr~  Ú-rl   gÍÌÌÌÌÌì?)ÚnÚcutoffc              3  ó^   >#   • U  H"  oR                  S SS5      TS   :X  d  M  Uv •  M$     g7f)r~  r‹  rl   r   N)r   ©rk  Úknown_idÚmatchess     €rz   rl  Ú,_suggest_known_model_name.<locals>.<genexpr>æ  s0   øé € ÐfªY ×:JÑ:JÈ3ÐPSÐUVÓ:WÐ[bÐcdÑ[eÑ:e—H‘HªYùs   ƒ-¤	-r  gš™™™™™é?gffffffæ?c              3  ób   >#   • U  H$  oR                  S TS    35      (       d  M   Uv •  M&     g7f)r~  r   N)Úendswithr�  s     €rz   rl  r’  í  s,   øé € Ð^ªY ×:KÑ:KÈaÐPWÐXYÑPZÈ|ÐL\×:]—H‘HªYùs   ƒ/¦	/)r{   rs  r   r   Únextr�  )	rå   r¸  Úknown_model_idsÚ	known_idsr�  Únormalized_idsÚnormalized_modelÚknown_namesr‘  s	           @rz   Ú_suggest_known_model_namer›  ß  sþ   ø€ ØÑÜ+Ó-ˆÜ�Ñ,\Ñ]€IÙOXÓ lÊyÀ8Ð\_ÐckÑ\kÓ!> ×!1Ñ!1°#°s¸AÖ!>Éy€NÐ lØ—}‘} S¨#¨qÓ1ÐÜ#Ð$4ÈÐRUÑVÐV€wÕVÜÔf©YÓfÓfÐfáQZÓnÒQZÀXÐ^aÐemÑ^mÓ@˜hŸn™n¨S¸1˜nÐ=¸aÔ@ÑQZ€KÐnÜ 
¸1ÀSÑI€GÞÜ#Ð$4ÀQÈsÑSˆÞÜÔ^©YÓ^Ó^Ð^Øùò !mùò
 os   ž
C$¬C$Â
C)ÂC)c                ó°   • U  SU 3nU  S3n[        5        Vs/ s H  oDR                  U5      (       d  M  UPM     nn[        X!U5      nXb:w  a  U$ S$ s  snf )u  The closest known model ID for a name the provider itself rejected, or `None`.

The result rides on `ModelHTTPError.suggested_model_id` rather than a dedicated exception type.
Only some model classes carry a not-found signal at all â€” `MistralModel`, `CohereModel`,
`HuggingFaceModel` and `XaiModel` map their errors without one â€” so a distinct type would assert
a taxonomy that holds for part of the matrix only. A hint that is sometimes absent degrades
harmlessly; an exception type that is sometimes absent misclassifies.
r~  N)r{   r†  r›  )Úmodel_id_namespacer¸  rë   Úprovider_prefixr»   r–  Ú
suggestions          rz   Ú+_suggest_known_model_id_from_provider_errorr   ñ  sf   € ð %Ð% Q z lÐ3€HØ+Ð,¨AÐ.€OÜ(9Ô(;Ó`Ò(; ¿¹È×?_—tÑ(;€OÐ`Ü*¨8ÀÓQ€JØ#Ó/ˆ:Ð9°TÐ9ùò as
   ™A¶Ac                ó”  • [        U 5      u  pUc  [        $ UR                  S5      (       a  SSKJn  U" U5      n [        U5      n UR                  U5      nU=(       d    [        nSU=(       d    0 ;  a  [        X!S9nUb  [        U[        US95      nU$ ! [         a	    [        s $ f = f! [        [        4 a	    [        s $ f = f)au  Infer the model profile from a model id string without constructing a provider.

Uses `Provider.model_profile` to look up the profile for the given model, then fills an unset
`context_window` from genai-prices when available.
Returns `DEFAULT_PROFILE` for unknown or unrecognized providers.

Note: This returns the raw provider profile **without** intersecting with
`Model.supported_native_tools()`, unlike `Model.profile`. This means the returned
profile may claim support for native tools that a specific `Model` subclass doesn't
implement. This is acceptable for best-effort scenarios (e.g. `TemporalModel` with
unregistered model strings) where the actual `Model` class isn't available.

Args:
    model: A model identifier string (e.g. `'openai:gpt-5'`, `'anthropic:claude-sonnet-4-5'`).

Returns:
    The inferred `ModelProfile`, or `DEFAULT_PROFILE` if the provider is unknown.
r…  r$   ©Únormalize_gateway_providerr³  )r)  r¶  )r‚  r[   r†  Úproviders.gatewayr£  rf   Ú
ValueErrorr·  r0   r&   rb   r]   )rå   r  r¸  r£  Úprovider_classrº  r  r³  s           rz   Úinfer_model_profiler§    sÕ   € ô& *¨%Ó0Ñ€HØÑÜÐØ×Ñ˜:×&Ñ&õ 	Cá-¨hÓ7ˆðÜ-¨hÓ7ˆðØ)×7Ñ7¸
ÓCÐð ×1¤/€GàÐ 0× 6°BÓ7Ü.¨zÑRˆØÑ%Ü# G¬\ÈÑ-XÓYˆGØ€Nøô ó ÜÒðûô
 œ	Ð"ó ÜÒðús#   ¼B ÁB. ÂB+Â*B+Â.CÃCc                ót  • [        U [        5      (       a  U $ U S:X  a  SSKJn  U" 5       $ [	        U 5      u  p4Uc+  SU  3n[        X5      =n(       a	  USU S3-  n[        U5      eU[        L a   [        U5        U" U5      nUnUR                  S5      (       a  S	S
KJn	  U	" U5      nUS:X  aR  S	SKJn
Jn  SSKJnJn  [        Xz5      (       d  [        S5      eU" U5      R'                  S5      S:X  a  U" XGS9$ U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSKJn  U" XGS9$ US:X  a  SSK J!n  U" XGS9$ US :X  a  SS!K"J#n  U" XGS9$ US";   a  SS#K$J%n  U" XGS9$ US$/[M        [N        RP                  5      Q7;   a  SS%K$J)n  U" XGS9$ US&;   a  SS'K*J+n  U" XGS9$ US(:X  a  SS)K,J-n  U" XGS9$ US*:X  a  SS+K.J/n  U" XGS9$ US,:X  a  SS-K0J1n  U" XGS9$ US.:X  a  SS/K2J3n  U" XGS9$ US0:X  a  SS1K4J5n  U" XGS9$ US2:X  a  SS3K6J7n  U" XGS9$ US4:X  a  SS5K8J9n  U" XGS9$ US6:X  a  SS7K:J;n   U " XGS9$ [        SU  35      e! [         a-    SU  3n[        X5      =n(       a	  USU S3-  n[        U5      Sef = f)8aS  Infer the model from the name.

Args:
    model:
        Model name to instantiate, in the format of `provider:model`. Use the string "test" to instantiate TestModel.
    provider_factory:
        Function that instantiates a provider object. The provider name is passed into the function parameter. Defaults to `provider.infer_provider`.
Útestrl   )Ú	TestModelNzUnknown model: z. Did you mean 'z'?r…  r$   r¢  zbedrock-mantle)ÚBedrockMantleProviderÚbedrock_mantle_model_profile)ÚBedrockMantleChatModelÚBedrockMantleResponsesModelz8Bedrock Mantle models require a `BedrockMantleProvider`.Úbedrock_mantle_interfaceÚchat)r  rŠ   )ÚOpenRouterModelr   )ÚCerebrasModelr€   )ÚCrusoeModelr�   )ÚSnowflakeModelr‰   )ÚOllamaModelr‘   )ÚZaiModelr„   )ÚGitHubCopilotModelr“   )ÚOpenAICodexModel)Úopenaizopenai-responseszazure-responses)ÚOpenAIResponsesModelzopenai-chat)ÚOpenAIChatModel)Úgooglezgoogle-cloud)ÚGoogleModelÚgroq)Ú	GroqModelÚcohere)ÚCohereModelÚmistral)ÚMistralModelÚtypesafe)ÚTypeSafeModelÚ	anthropic)ÚAnthropicModelÚbedrock)ÚBedrockConverseModelÚhuggingface)ÚHuggingFaceModelÚxai)ÚXaiModel)<r‡  rä   r©  rª  r‚  r›  r0   re   rf   r¥  r†  r¤  r£  Úproviders.bedrock_mantler«  r¬  Úbedrock_mantler­  r®  r°   rŠ   r±  r   r²  r€   r³  r�   r´  r‰   rµ  r‘   r¶  Úgithub_copilotr·  Úopenai_codexr¸  r¹  rº  r   r|   rw   r»  r¼  r½  r¾  r¿  rÀ  rÁ  rÂ  rÃ  rÄ  rÅ  rÆ  rÇ  rÈ  rÉ  rÊ  rË  rÌ  rÍ  )!rå   Úprovider_factoryrª  r)  r¸  rŽ  Úsuggested_namer  Ú
model_kindr£  r«  r¬  r­  r®  r±  r²  r³  r´  rµ  r¶  r·  r¸  rº  r»  r½  r¿  rÁ  rÃ  rÅ  rÇ  rÉ  rË  rÍ  s!                                    rz   Úinfer_modelrÕ  2  s0  € ô �%œ×ÑØˆØ	�&‹Ý#á‹{Ðä .¨uÓ 5Ñ€MØÑØ# E 7Ð+ˆÜ6°uÓIÐIˆ>ÕIØÐ)¨.Ð)9¸Ð<Ñ<ˆGÜ˜Ó Ð àœ>Ò)ð	/Ü  Ô/ñ   Ó.€Hà€JØ×Ñ˜Z×(Ñ(ÝBá/°
Ó;ˆ
àÐ(Ó(ßbßWä˜(×:Ñ:ÜÐVÓWÐWñ (¨
Ó3×7Ñ7Ð8RÓSÐW]Ó]Ù)¨*ÑHÐHÙ*¨:ÑIÐIð
 �\Ó!Ý/á˜zÑ=Ð=Ø	�zÓ	!Ý+á˜ZÑ;Ð;Ø	�xÓ	Ý'á˜:Ñ9Ð9Ø	�{Ó	"Ý-á˜jÑ<Ð<Ø	�xÓ	Ý'á˜:Ñ9Ð9Ø	�uÓ	Ý!á˜
Ñ6Ð6Ø	Ð'Ó	'Ý6á! *Ñ@Ð@Ø	�~Ó	%Ý2á 
Ñ>Ð>Ø	ÐHÓ	HÝ0á# JÑBÐBØ	˜ÐY¬Ô1M×1WÑ1WÓ(XÑYÓ	YÝ+á˜zÑ=Ð=Ø	Ð1Ó	1Ý'á˜:Ñ9Ð9Ø	�vÓ	Ý#á˜Ñ7Ð7Ø	�xÓ	Ý'á˜:Ñ9Ð9Ø	�yÓ	 Ý)á˜JÑ:Ð:Ø	�zÓ	!Ý+á˜ZÑ;Ð;Ø	�{Ó	"Ý-á˜jÑ<Ð<Ø	�yÓ	 Ý1á# JÑBÐBØ	�}Ó	$Ý1á 
Ñ>Ð>Ø	�uÓ	Ý!á˜
Ñ6Ð6ä˜/¨%¨Ð1Ó2Ð2øôU ó 	/Ø'¨ wÐ/ˆGÜ!:¸5Ó!MÐMˆ~ÕMØÐ-¨nÐ-=¸RÐ@Ñ@�Ü˜GÓ$¨$Ð.ð		/ús   Á0J  Ê 7J7r  ©ÚtimeoutÚconnectc                ó–   •  SSK nUR                  UR                  XS9S[	        5       0S9$ ! [         a  n[        S5      UeSnAff = f)u`  Create a legacy HTTPX async client.

This factory serves the providers whose SDKs still require a legacy `httpx.AsyncClient`;
providers migrated to `httpx2` build their own `httpx2.AsyncClient` instead.

Each call creates a new client instance. When used via a [`Provider`][pydantic_ai.providers.Provider],
the client's lifecycle is managed automatically â€” it will be closed when the provider (or agent) exits.

The default timeouts match those of OpenAI,
see <https://github.com/openai/openai-python/blob/v1.54.4/src/openai/_constants.py#L9>.

Raises:
    ImportError: If legacy `httpx` is not installed.
r   Nu   Please install `httpx` to create a legacy HTTPX client with this factory, you can use the `retries` optional group â€” `pip install "pydantic-ai-slim[retries]"`. Providers otherwise build their own `httpx2.AsyncClient`, which you can also pass in yourself.rÖ  z
User-Agent)r×  Úheaders)r  r  ro   ÚTimeoutÚget_user_agent)r×  rØ  r  Ú_import_errors       rz   Úcreate_async_http_clientrÞ  »  sg   € ðÛð ×ÑØ—‘ g�Ð?Øœ~Ó/Ð0ð ð ð øô ó Üðmó
ð ð		ûðús   ‚- ­
A·AÁAÚDataTc                  ó0   • \ rS rSr% SrS\S'    S\S'   Srg)	ÚDownloadedItemiÜ  z!The downloaded data and its type.rß  ÚdatarÒ   Ú	data_typerx   Nrò   rx   ry   rz   rá  rá  Ü  s   ‡ Ù+à
ƒKØàƒNòry   rá  c              ƒ  ó   #   • g 7frº   rx   ©rÅ  Údata_formatÚtype_formats      rz   Údownload_itemrè  é  s
   é € ð
  ùrM  c              ƒ  ó   #   • g 7frº   rx   rå  s      rz   rè  rè  ñ  s
   é € ð
 ùrM  c              ƒ  óÀ  #   • [        U [        5      (       a  U R                  (       a  [        S5      eSSKJn  U R                  S:H  nU" U R                  U[        S9I Sh  v•N nUR                  R                  S5      =n(       a  UR                  S5      S	   nUS
:X  a  SnU=(       d    U R                  nUnUS:X  a  U R                  nUR                  n	US;   aD  [        R                   " U	5      R#                  S5      n	US:X  a  SU SU	 3n	[$        [&           " X˜S9$ US:X  a!  [$        [&           " U	R#                  S5      US9$ [$        [(           " X˜S9$  Nù7f)a­  Download an item by URL and return the content as a bytes object or a (base64-encoded) string.

This function includes SSRF (Server-Side Request Forgery) protection:
- Only http:// and https:// protocols are allowed
- Private/internal IP addresses are blocked by default
- Cloud metadata endpoints (169.254.169.254) are always blocked
- Hostnames are resolved before requests to prevent DNS rebinding
- Response bodies are limited to 50 MiB

Set `item.force_download='allow-local'` to allow private IP addresses.

Args:
    item: The item to download.
    data_format: The format to return the content in:
        - `bytes`: The raw bytes of the content.
        - `base64`: The base64-encoded content.
        - `base64_uri`: The base64-encoded content as a data URI.
        - `text`: The content as a string.
    type_format: The format to return the media type in:
        - `mime`: The media type as a MIME type.
        - `extension`: The media type as an extension.

Raises:
    UserError: If the URL points to a YouTube video.
    ValueError: If the URL uses an unsupported protocol or targets a private/internal
        IP address (unless allow-local is set), or the body exceeds 50 MiB.
z,Downloading YouTube videos is not supported.r$   )Úsafe_downloadzallow-local)Úallow_localÚ	max_bytesNzcontent-typeÚ;r   zapplication/octet-streamÚ	extension)Úbase64Ú
base64_urizutf-8rñ  zdata:z;base64,)râ  rã  r¤   )r‡  rQ   Ú
is_youtuber0   Ú_ssrfrë  Úforce_downloadÚurlÚ_MAX_FILE_URL_DOWNLOAD_BYTESrÚ  r°   r�  Ú
media_typeÚformatra  rð  Ú	b64encodeÚdecoderá  rÒ   Úbytes)
rÅ  ræ  rç  rë  rì  rJ  Úcontent_typer÷  rã  râ  s
             rz   rè  rè  ù  sE  é € ô@ �$œ×!Ñ! d§o§oÜÐFÓGÐGå%à×%Ñ%¨Ñ6€KÙ" 4§8¡8¸ÔPlÑm×m€Hà×'Ñ'×+Ñ+¨NÓ;Ð;€|Õ;Ø#×)Ñ)¨#Ó.¨qÑ1ˆØÐ5Ó5ØˆLà×0 §¡€Jà€IØ�kÓ!Ø—K‘Kˆ	à×Ñ€DØÐ.Ó.Ü×Ò Ó%×,Ñ,¨WÓ5ˆØ˜,Ó&Ø˜:˜, h¨t¨fÐ5ˆDÜœcÒ"¨ÑBÐBØ	˜Ó	ÜœcÒ"¨¯©°GÓ(<È	ÑRÐRäœeÒ$¨$ÑDÐDñ- nùs   ‚A EÁ"EÁ#C:Ec                 ó   • SSK Jn   SU  3$ )z.Get the user agent string for the HTTP client.r$   ©Ú__version__zpydantic-ai/)rj  rÿ  rþ  s    rz   rÜ  rÜ  8  s   € õ à˜+˜Ð'Ð'ry   c                ó¸   • U " UR                   UR                  S9nUR                  5       n[        UUUR                  c  UR                  S9$ UR                  S9$ )z£Customize the tool definition using the given transformer.

If the tool definition has `strict` set to None, the strictness will be inferred from the transformer.
©Ústrict)Úparameters_json_schemar  )r  r  Úwalkr   Úis_strict_compatible)rV  r¶   Úschema_transformerr  s       rz   rT  rT  @  sg   € ñ
 % X×%DÑ%DÈXÏ_É_Ñ]ÐØ/×4Ñ4Ó6ÐÜØØ5Ø:B¿/¹/Ñ:QÐ!×6Ñ6ñð ð X`×WfÑWfñð ry   c                ó¸   • U " UR                   UR                  S9nUR                  5       n[        UUUR                  c  UR                  S9$ UR                  S9$ )Nr  )Újson_schemar  )r  r  r  r   r  )rV  r¦   r  r  s       rz   rU  rU  N  sj   € ñ % ]×%>Ñ%>À}×G[ÑG[Ñ\ÐØ$×)Ñ)Ó+€KÜØØØ:G×:NÑ:NÑ:VÐ!×6Ñ6ñð ð ]j×\pÑ\pñð ry   r¢  c          	     óX  • U R                    Vs/ s H!  n[        U[        U5      5      (       d  M  UPM#     nnU R                    Vs/ s H!  n[        U[        U5      5      (       a  M  UPM#     nnU Vs1 s H  oDR                  iM     nnU Vs1 s H  oDR                  iM     nnU Vs1 s H!  oDR                  (       d  M  UR                  iM#     n	nU R
                   Vs1 s H!  oDR                  (       d  M  UR                  iM#     n
nXŠ-
  U	-
  nU(       ac  U Vs/ s H)  oDR                  U;   d  M  [        U5      R                  PM+     nnU Vs/ s H  oDR                  PM     nn[        SU SU S35      eU R
                   Vs1 s H!  oDR                  (       d  M  UR                  iM#     nnU Vs/ s H=  n[        U[        5      (       a#  UR                  (       a  UR                  U;   d  M;  UPM?     nnU Vs1 s H  oDR                  iM     nnUb  U" U5      OSn[        S U 5       5      n/ n0 nU R
                   GH  nUR                  (       a  UR                  U;   a  M'  UR                  (       a  UR                  U;  a
  [        USS9nUR                  (       d  SnO”UR                  U R                   ;   nUR                  SL=(       a    UR                  U;   nU(       a
  U(       a  S	nOFU(       a  US
:X  a  SnO6U(       a  S	nO,SnO)U(       a  SnOU(       a  SnOUS
:X  a  SnOU(       a  S	nOSnUR#                  U5        UUUR                  '   GM     [        U UUUS9$ s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf )uX  Resolve native tools, their local fallbacks, and deferred-tool visibility for the given supported-native-tool set.

Three rules drive the per-tool filter:

1. `unless_native` matches a supported native tool â†’ drop from wire.
2. `with_native` matches an *unsupported* native tool â†’ shed `with_native`. The tool is
   a member of a corpus the native tool would have managed; with that native tool absent
   the membership means nothing, and an adapter deriving a wire flag from it would emit
   the flag unpaired and earn a rejection.
3. `defer_loading` remains authored intent; this function resolves its provider representation
   into `tool_visibility` exactly once. A caller without a `can_withhold_tool_schemas` answer
   (the realtime session path) can't withhold schemas at all.

On top of the filter, two narrower drops apply, kept independent:

* `optional=True` only governs the *unsupported-on-this-model* path: an unsupported
  optional native tool is silently dropped (no error raised). It does NOT govern the
  corpus-empty drop.
* The corpus-empty drop is specific to the framework-managed tool-search native tool's
  corpus-management role: an *optional* `ToolSearchTool` is dropped when nothing is
  searchable, since sending it with no corpus to search would waste a tool slot. A
  non-optional `ToolSearchTool` stays â€” the user asked explicitly. Other native tools
  don't have a corpus and aren't subject to this drop, so making `optional` a base-class
  field doesn't accidentally cause e.g. `WebSearchTool(optional=True)` to be dropped here.

This is a module-level function rather than a `Model` method so both the classic agent-run
path (via `Model._resolve_request_tools`, which passes its profile-derived
`_can_withhold_tool_schemas` and `tool_addition_mode`) and the realtime session path can
share it â€” `RealtimeModel` is not a `Model` subclass.
zNative tool(s) z) not supported by this model. Supported: a„  . To use these tools with this model, provide a local fallback via NativeOrLocalTool(native=..., local=...) or the `local` parameter of the capability (e.g. WebSearch(local='duckduckgo'), WebFetch(local=True), MCP(local=True), ImageGeneration(local=my_func)). Some capabilities require an optional install group for the local fallback (e.g. `pip install "pydantic-ai-slim[mcp]"` for MCP).NFc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   rª  )rk  rÎ   s     rz   rl  Ú(resolve_request_tools.<locals>.<genexpr>¦  s   é € ÐaÒO`ÀVœj¨´×@Ð@ÒO`ùr¬  )ri  r”   r•   Úwith_definitionsr—   r–   )r    rŸ   r¡   )r    r‡  rv   rq  ÚoptionalrŸ   rh  rÄ  r×   r0   ri  rW   r  r   r²   r»   r¢   rÏ  )ru  Úsupported_typesr£  r(  rW  Úsupported_nativesÚunsupported_nativesÚsupported_idsÚunsupported_idsÚoptional_idsÚfallback_idsÚwithout_fallbackÚunsupported_namesÚsupported_namesÚ
corpus_idsÚ	can_deferÚtool_search_on_wirerŸ   Úvisibility_by_namerµ   ÚrevealedÚcorpus_members                         rz   r¤  r¤  Z  sD  € ðJ %+×$7Ò$7ÓaÒ$7˜q¼:ÀaÌÈÓI_×;`ŸÑ$7ÐÐaØ&,×&9Ò&9ÓgÒ&9 ÄÈAÌuÐUdÓOe×AfŸ1Ñ&9ÐÐgá*;Ó<Ò*; Q—[”[Ñ*;€MÐ<Ù,?Ó@Ò,? q—{”{Ñ,?€OÐ@Ù)<ÓKÒ)< AÇ
Å
“K�A—K”KÑ)<€LÐKØ-3×-BÒ-BÓVÒ-B¨ÇoÅo“O�A—O”OÑ-B€LÐVà&Ñ5¸ÑDÐÞÙ7JÓnÒ7J°!ÏkÉkÐ]mÑNmÓ-œT !›W×-Ô-Ñ7JÐÐnÙ/>Ó?ª¨!Ÿ:œ:©ˆÐ?ÜØÐ/Ð0ð 1Ø)Ð*ð +DðEó	
ð 		
ð" *0×)>Ò)>ÓPÒ)> AÇ-Å-“-�!—-”-Ñ)>€JÐPá$óÚ$ˆa¬Z¸¼>×-JÑ-JÈqÏzÏzÐ^_×^iÑ^iÐmwÑ^w�Ñ$ð ð ñ +<Ó<Ò*; Q—[”[Ñ*;€MÐ<à@YÑ@eÑ)Ð*;Ô<Ðkp€IÜÑaÑO`ÓaÓaÐà+-€NØ46ÐØ×"Õ"ˆà�?�?˜qŸ™°-Ó?Ùà�=�=˜QŸ]™]°-Ó?Ü˜ tÑ,ˆAØ��Ø"‰Jà—v‘v ×!;Ñ!;Ñ;ˆHØŸM™M°Ð5×X¸!¿-¹-È=Ñ:XˆMÞ¦Ø'‘
ÞØ%Ð);Ó;Ø!.‘JÞØ!+‘Jà!*‘JÞØ'‘
Þ$ð (‘
Ø#Ð'9Ó9Ø'‘
Þð (‘
à'�
Ø×Ñ˜aÔ Ø%/Ð˜1Ÿ6™6Ô"ñK #ôN ØØ&Ø%Ø*ñ	ð ùòe bùÚgùâ<ùÚ@ùÚKùÚVùò oùÚ?ùò$ Qùòùò =sj   �M5±M5ÁM:Á)M:Á5M?ÂNÂ+N	ÃN	Ã#NÃ;NÄNÄ6NÅNÆNÆ$NÆ::N"Ç8N"ÈN'c               óÐ  • U(       + n/ nSnU R                    GH9  nUR                  (       d  UR                  b  [        USS9nSnOùUR                  (       aG  UR                  (       d6  [        R
                  " SUR                  < S3[        SS9  [        USS9nSnO¡U(       aš  UR                  (       a‰  / nUR                  (       a  UR                  UR                  5        UR                  S	5        UR                  [        R                  " UR                  S
S95        [        USR                  U5      SS9nSnUR                  U5        GM<     U(       a	  [        XS9$ U $ )un  Resolve return schemas: clear on tools that haven't opted in, inject into descriptions for non-native models.

For tools with `include_return_schema=True` and a non-empty schema, models that natively support
return schemas keep the schema as-is; other models get it injected into the tool description.
Tools that haven't opted in have their `return_schema` cleared.

A module-level function taking the profile flag rather than a `Model` method so both the classic
path (via `Model.prepare_request`) and the realtime session path can share it â€” `RealtimeModel` is
not a `Model` subclass and carries its own profile type.
FN)Úreturn_schemaTzTool zœ has `include_return_schema` enabled but no meaningful return schema was generated. Set `include_return_schema=False` on this tool to suppress this warning.rl   rP  zReturn schema:r$   )Úindentz

)Údescriptionr  )rŸ   )rŸ   Úinclude_return_schemar  r   rR  rS  r»   ÚUserWarningr!  rÏ  ÚjsonÚdumpsÚjoin)ru  r[  ÚinjectrŸ  ÚchangedÚtdr{  s          rz   ro  ro  Ù  s&  € ð -Ô,€FØ%'€HØ€GØ×#Õ#ˆØ×'×'¨B×,<Ñ,<Ñ,HÜ˜¨4Ñ0ˆBØ‰GØ×%×%¨b×.>×.>Ü�MŠMØ˜Ÿ™‘{ð #kð läØò	ô ˜¨4Ñ0ˆBØ‰GÞ˜×(×(Ø!ˆEØ�~�~Ø—‘˜RŸ^™^Ô,Ø�L‰LÐ)Ô*Ø�L‰LœŸš B×$4Ñ$4¸QÑ?Ô@Ü˜¨¯©°UÓ);È4ÑPˆBØˆGØ�‰˜×ñ+ $ö, Ü�vÑ7Ð7Ø€Mry   c                óL  • [        U [        5      (       Ga  U R                  n[        U[        5      (       a  UR                  (       dE  [        U[
        5      (       a:  UR                  (       a)  [        UR                  [        5      (       a
  [        SSS9$ [        U[        5      (       aw  UR                  R                  UR                  5      =n(       aJ  UR                  S:X  a  [        UR                  UR                  S9$ UR                   (       a
  [        SSS9$ gggg)zeReturn an appropriate FinalResultEvent if `e` corresponds to a part that will produce a final result.N)r´   Útool_call_idÚoutput)r‡  rD   r�  rH   rª   r6   r«   ra  r4   r8   rK   r±   r°   r´   Úkindr+  Údefer)Úeru  Únew_partr¶   s       rz   r÷  r÷    sß   € ä�!”^×$Ò$Ø—6‘6ˆÜ�x¤×*Ñ*¨v×/G×/GÜ�x¤×*Ñ*¨v×/H×/HÌZÐX`×XhÑXhÔju×MvÑMvä#¨dÀÑFÐFÜ˜¤,×/Ñ/À×AQÑAQ×AUÑAUÐV^×VhÑVhÓAiÐ5i°XÕ5iØ�}‰} Ó(Ü'°(×2DÑ2DÐS[×ShÑShÑiÐiØ——Ü'°$ÀTÑJÐJð  ð 6jÐ/ð %ry   c          	     óz  • [        S U  5       5      (       d  U $ / nU  GH  n[        U[        5      (       aÎ  / nUR                   H™  n[        U[        5      (       ap  U(       a2  UR
                  b%  UR                  [        UR
                  /S95        MQ  UR                  (       a$  UR                  [        UR                  S95        M†  Mˆ  UR                  U5        M›     U(       a  UR                  [        X4S95        Må  Mç  [        S [        UR                  5       5       SS9n/ n[        UR                  5       HÐ  u  p…[        U[        5      (       a¥  UR                  (       a  UR                  /O/ n	UR                  b   U	R                  SUR                   S35        O&UR                  S	:X  a  X†:X  a  U	R                  S
5        U	(       a)  UR                  [        SR                  U	5      S95        M½  M¿  UR                  U5        MÒ     U(       d  GM   UR                  [        X7S95        GM     U$ )a  Convert `SpeechPart`s from realtime session history into parts any model can consume.

User-speaker parts become `UserPromptPart`s carrying the retained audio (when `include_audio` is
`True` and audio was retained) or the transcript text; assistant-speaker parts become `TextPart`s
carrying the transcript. Parts without usable content are dropped, as are messages left without
parts. Returns the original list when nothing changed so the identity check in `_make_request`
can skip the redundant `_clean_message_history` pass.
c              3  óh   #   • U  H(  oR                     H  n[        U[        5      v •  M     M*     g 7frº   )r{  r‡  rF   )rk  rŽ  r�  s      rz   rl  Ú(_convert_speech_parts.<locals>.<genexpr>  s(   é € Ð^º8°×P]ÕP]ÈŒz˜$¤
×+Ð+ÑP]Ñ+º8ùs   ‚02Nr`  ©r{  c              3  óX   #   • U  H   u  p[        U[        5      (       d  M  Uv •  M"     g 7frº   )r‡  rF   )rk  rþ  r�  s      rz   rl  r3  4  s!   é € ÐcÒ*B™;˜5ÄjÐQUÔWa×Fb—‘Ò*Bùó   ‚*¡	*)rã  z[Interrupted after z ms]r'  z[Interrupted]Ú
)r  r‡  r<   r{  rF   ÚaudiorÏ  rP   Ú
transcriptr   ÚmaxÚ	enumerateÚinterrupted_at_msrë  rH   r&  )
rç   r€  Únew_messagesrŽ  Úrequest_partsr�  Úlast_speechÚresponse_partsrþ  Úliness
             rz   r…  r…    sÇ  € ô Ñ^¹8Ó^×^Ñ^Øˆà')€LÜˆÜ�gœ|×,Ñ,Ø46ˆMØŸœ�Ü˜d¤J×/Ñ/Þ$¨¯©Ñ)?Ø%×,Ñ,¬^ÀTÇZÁZÀLÑ-QÖRØŸŸØ%×,Ñ,¬^ÀDÇOÁOÑ-TÖUñ )ð "×(Ñ(¨Ö.ñ &ö Ø×#Ñ#¤G¨GÑ$IÖJñ ô Ùc¬)°G·M±MÔ*BÓcØñˆKð 79ˆNÜ(¨¯©Ö7‘�Ü˜d¤J×/Ñ/Ø15··˜TŸ_™_Ñ-Àb�EØ×-Ñ-Ñ9ØŸ™Ð':¸4×;QÑ;QÐ:RÐRVÐ%WÕXØ Ÿ™¨-Ó7¸EÓ<PàŸ™ _Ô5ÞØ&×-Ñ-¬h¸t¿y¹yÈÓ?OÑ.PÖQñ ð #×)Ñ)¨$Ö/ñ  8÷ ‰~Ø×#Ñ#¤G¨GÑ$J×KñM ðN Ðry   c                ój   • SnU R                    H   n[        U[        5      (       d    U$ US-  nM"     U$ )uî  How many of a request's opening parts belong to the run's standing system prompt.

The standing prompt is authored before the run starts, so it is whatever `SystemPromptPart`s the
first request *opens* with. One sitting after a user prompt or a tool return in that same request
got there later: enqueued mid-run, or carried in from its own `ModelRequest` when
`_clean_message_history` merged two adjacent requests that no assistant turn separated. Position
is the only thing that tells them apart, and it is worth getting right â€” hoisting a
mid-conversation instruction into the provider's top-level system parameter rewrites the first
cache section of every later request, which is the exact invalidation that leaving it in place
exists to avoid.
r   rl   )r{  r‡  rG   )r6  Úcountr�  s      rz   Ú_standing_system_prompt_countrD  J  s?   € ð €EØ—”ˆÜ˜$Ô 0×1Ñ1Øà€Lð 	�‰
Šñ ð €Lry   r,  c               ó.  • [        [        U 5      S-
  SS5       H÷  nX   n[        U[        5      (       d  M  [        [        UR                  5      S-
  SS5       H²  nUR                  U   n[        U[
        5      (       a  [        XqUS9(       d  M8  [        XUR                  US S9/XS-   S QnU=(       a;    [        UR                  =(       a    UR                  R                  [        5      5      n	/ [        U SU U	(       + S9QUQs  s  $    Mù     U $ )u¢
  Drop history before the latest same-provider compaction part the request will send.

Reached through [`Model._trim_before_compaction`][pydantic_ai.models.Model._trim_before_compaction],
which derives both flags from the adapter's declarations; adapters call that from their own
message-prep step, since where in a request build the trim belongs is provider mechanics.
Anthropic ignores (and doesn't bill) pre-boundary blocks,
so there the trim only saves request size; the OpenAI Responses API processes and bills
replayed items that precede a compaction item (live-verified), so there it is what makes
compaction actually compact. `requires_encrypted_content` is this caller's own render condition,
passed to the shared wire-boundary predicate: a part the adapter would omit must not act as a
boundary either, or the history is dropped with nothing sent to stand in for it.

The standing prompt survives via `_standing_prompt_request`; nothing else from the prefix does.
`standing_prompt_retained` mirrors where the calling API carries the standing prompt: on
Anthropic the top-level `system` parameter is rebuilt from the opening `SystemPromptPart`s on
every request, so they must be re-inserted (`False`, the default) or the standing prompt is
silently dropped from all subsequent requests. On OpenAI Responses those parts render as
`system` input items *inside* the compacted window, and the compaction item demonstrably
retains them â€” a latent directive that never fired before the boundary still governs
post-compaction replies without the item being re-sent (live-verified) â€” so ordinary requests
pass `True` and skip re-sending what the model would receive twice. `True` is honored only for
a boundary part stamped with `STANDING_PROMPT_PLANTED_KEY`: retention presumes the compacted
window contained the standing prompt, which only our own compact call guarantees â€” an
externally produced or spliced-in item gets the standing prompt re-inserted as before.
Retention is also only reliable for a single hop: a directive carried solely by a previous
compaction item decayed when compacted again (live-verified), so the re-compaction call itself
passes `False` to plant the standing prompt explicitly in every freshly built window (and
stamps the result). Recovered instructions are re-sent either way â€” they travel as a
per-request parameter, never inside the window.
The Messages API accepts a request whose messages start with the assistant compaction block
(live-verified), and keeping e.g. the original first user message can 400 when it carries a
`tool_result` whose `tool_use` was trimmed away â€” validation runs even on ignored content.
Idempotent: re-applying to an already-trimmed list is a no-op.
rl   éÿÿÿÿ)r-  Nr4  ©Úinclude_system_parts)ÚrangerÐ  r‡  r>   r{  r5   rR   r   r©   rè  r°   r1   Ú_standing_prompt_request)
rç   r/  r-  r*  Úmessage_indexrŽ  Ú
part_indexr�  ÚtailÚretaineds
             rz   r.  r.  ^  s  € ôR œs 8›}¨qÑ0°"°bÖ9ˆØÑ)ˆÜ˜'¤=×1Ñ1ÙÜ¤ G§M¡MÓ 2°QÑ 6¸¸BÖ?ˆJØ—=‘= Ñ,ˆDÜ˜d¤N×3Ñ3Ô;\ØÐ9S÷<ñ Ü˜G¯=©=¸¸Ð+EÑFÐgÈÐbcÑRcÐReÐIfÐgˆDØ/÷ ´DØ×%Ñ%×`¨$×*?Ñ*?×*CÑ*CÔD_Ó*`ó5ˆHðÜ)¨(°>°MÐ*BÐ]eÔYeÑfðàðô ó @ñ	 :ð$ €Ory   rG  c               óð   • [        S U  5       S5      nU(       a  U(       a  UR                  S[        U5       O/ n[        S [        U 5       5       S5      nU(       d  Uc  / $ [	        [        U5      US9/$ )uE  The standing prompt from a trimmed-away prefix, as a request of its own.

System parts come from the first `ModelRequest` wherever it appears (a history may open with a
`ModelResponse`), sliced by `_standing_system_prompt_count` â€” the same opening-parts rule the
hoisting adapters use; they are skipped entirely when the caller's compaction carrier already
retains them (see `_trim_messages_before_compaction`). Instructions come from the latest prefix
request that carried any: what the instruction fallback for direct `Model.request()` callers
would otherwise have recovered from the dropped history; a kept-tail request with its own
instructions still wins, being more recent. Mid-conversation `SystemPromptPart`s render inline
as conversation content, which the compaction summary replaces, so they are deliberately not
preserved.
c              3  óT   #   • U  H  n[        U[        5      (       d  M  Uv •  M      g 7frº   ©r‡  r<   ©rk  Úms     rz   rl  Ú+_standing_prompt_request.<locals>.<genexpr>©  s   é € ÐK¢V ¬z¸!¼\×/JŸ!™!¢Vùs   ‚(Ÿ	(Nc              3  ó†   #   • U  H7  n[        U[        5      (       d  M  UR                  c  M)  UR                  v •  M9     g 7frº   )r‡  r<   r?  rR  s     rz   rl  rT  °  s,   é € ÐpÒ!1˜A´ZÀÄ<×5P‹ÐUV×UcÑUc‹ˆ�ŽÒ!1ùs   ‚AŸA®A)r{  r?  )r•  r{  rD  rÎ  r<   rÜ   )ÚprefixrH  Úfirst_requestÚopeningr?  s        rz   rJ  rJ  œ  s~   € ô ÑK¡VÓKÈTÓR€Mö Ö1ð 	×ÑÐJÔ;¸MÓJÑKàð ô
 Ùp¤¨&Ô!1ÓpØó€Lö �|Ñ+Øˆ	Üœt G›}¸<ÑHÐIÐIry   c           
     ó˜  • [        S [        U 5       5       S5      nUc  U $ [        U SU 5      nSn[        XS 5       Hø  u  pEUS:X  a   [        U[        5      (       a  [        U5      OSn[        U[        5      (       a¥  [        S UR                  US  5       5      (       a�  [        UR                  5       VVs/ s HC  u  pxXv:¼  a7  [        U[        5      (       a"  [        SUR                   S3UR                  S9OUPME     n	nnUR                  [        XYS	95        S
nMç  UR                  U5        Mú     U(       a  U$ U $ s  snnf )a¹  Wrap mid-conversation `SystemPromptPart`s as `<system>`-tagged `UserPromptPart`s.

The run's standing system prompt is left alone; the provider's `_map_messages` hoists it. Which
parts those are is `_standing_system_prompt_count`'s
question, and it is not simply "everything in the first request".

Returns the original list when nothing changed so the identity check in `_make_request` can skip the
redundant `_clean_message_history` pass.
c              3  óX   #   • U  H   u  p[        U[        5      (       d  M  Uv •  M"     g 7frº   rQ  )rk  ÚirS  s      rz   rl  Ú3_wrap_non_leading_system_prompts.<locals>.<genexpr>Ã  s   é € ÐJÒ*‰tˆq¬j¸¼L×.I�‰Ò*ùr6  NFr   c              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   )r‡  rG   rË  s     rz   rl  r\  Í  s   é € Ð0lÒZkÐUV´¸AÔ?O×1PÐ1PÒZkùr¬  z<system>z	</system>)ra  r(  r4  T)r•  r;  rÜ   r‡  r<   rD  r  r{  rG   rP   ra  r(  rÏ  r   )
rç   Úfirst_request_idxr=  r(  ÚoffsetÚmsgÚstartrþ  r�  Ú	new_partss
             rz   rŒ  rŒ  ¸  sN  € ô ÙJ”y Ô*ÓJØóÐð Ñ Øˆä'+¨HÐ5GÐ6GÐ,HÓ'I€LØ€GÜ  Ð*<Ð!=Ö>‰ˆØ6<À³kÄjÐQTÔVb×FcÑFcÔ-¨cÔ2ÐijˆÜ�cœ<×(Ñ(¬SÑ0lÐZ]×ZcÑZcÐdiÐdjÑZkÓ0l×-lÑ-lô
 $-¨S¯Y©YÔ#7ô	ò $8‘K�Eð “>¤j°Ô7G×&HÑ&Hô ¨°$·,±,°¸yÐ'IÐUY×UcÑUcÒdàòñ $8ð	 ñ ð ×Ñ¤¨Ñ =Ô>ØŠGà×Ñ Ö$ñ ?ö #ˆ<Ð0¨Ð0ùós   Â=A
Ec                 ó   • [        S5      $ )a€  The error for a `ToolAvailabilityDeltaPart` that reached an adapter with no way to render it.

`prepare_messages` projects every delta to the local tool-search exchange unless the profile
advertises native support, so an adapter that doesn't support the part natively only sees one
when that projection didn't run. Running a model through an agent always runs it, but
[`Model.request`][pydantic_ai.models.Model.request] and
[`Model.count_tokens`][pydantic_ai.models.Model.count_tokens] are public and don't, so a caller
driving a model directly can reach this with a history that is otherwise perfectly valid. Hence
a `UserError` naming the missing step, rather than an assertion about an internal invariant.

Raising beats dropping the part: silently discarding it would tell the model nothing about the
tools that appeared, and it would then fail to call a tool it was supposed to have gained.
u;  `ToolAvailabilityDeltaPart` cannot be rendered by this model. Call `model.prepare_messages(messages)` first and pass the result â€” that projects the part into the tool-search exchange every model understands. `Agent` does this for you; a direct `Model.request()` or `Model.count_tokens()` call has to do it itself.r/   rx   ry   rz   Ú,_unsynthesized_tool_availability_delta_errorrd  Ü  s   € ô ð	Póð ry   c                 ó   • [        S5      $ )u7  The error for a realtime `SpeechPart` that reached an adapter unconverted.

`prepare_messages` turns every `SpeechPart` from realtime session history into the
`UserPromptPart`s / `TextPart`s any model can consume, so an adapter only sees one when that
conversion didn't run. Running a model through an agent always runs it, but
[`Model.request`][pydantic_ai.models.Model.request] and
[`Model.count_tokens`][pydantic_ai.models.Model.count_tokens] are public and don't, so a caller
driving a model directly can reach this with a history that is otherwise perfectly valid. Hence
a `UserError` naming the missing step, rather than an assertion about an internal invariant.

Raising beats dropping the part: silently discarding it would erase the turn's speech â€” possibly
the entire user message â€” from what the model sees.
u5  `SpeechPart` cannot be sent to this model as-is. Call `model.prepare_messages(messages)` first and pass the result â€” that converts realtime speech into the text and audio parts every model understands. `Agent` does this for you; a direct `Model.request()` or `Model.count_tokens()` call has to do it itself.r/   rx   ry   rz   Ú_unconverted_speech_part_errorrf  ò  s   € ô ð	Wóð ry   z0The following tool(s) are now available: {names}c                ó>  • [        U 5      n0 n/ UR                  QUR                  Q HO  nUR                  c  M  UR	                  UR                  [        5       5      R                  UR                  5        MQ     0 n[        U 5       GH  u  pgUS:  d.  [        U[        5      (       a  [        UR                  5      S:w  a  M<  UR                  S   n[        U[        5      (       a  UR                  [        :w  a  Mv  UR                   n	U	R#                  [$        R&                  5      (       d  M¨  XS-
     n
XS-
     n[        U
[(        5      (       aŸ  [        U
R                  5      S:w  d†  [        U
R                  S   [*        5      (       ad  U
R                  S   R                  [        :w  dC  U
R                  S   R                   U	:w  d&  [        U[        5      (       a  UR                  (       d  GMm  UR                  S   n[        U[        5      (       a  UR                  S:w  a  GM¤  UR-                  UR                   5      nUb  UR-                  U5      OSnU(       d  GMß  [/        U5      nUc  GMð  U(       d  GMú  [        U5      U::  d  GM  XõU	'   GM     U$ )zõRecognize pre-delta framework-fabricated `search_tools` exchanges.

All three confidence signals are required: a framework-prefixed id, direct adjacency to a
`load_capability` return, and discoveries confined to that capability's current tools.
Nr$   rl   r   rF  Úload_capability)Ú_load_capability_ids_by_callrŸ   r§   Úcapability_idÚ
setdefaultrÞ   Úaddr»   r;  r‡  r<   rÐ  r{  rL   r´   rV   r+  r†  r%   ÚTOOL_CALL_ID_PREFIXr>   rK   r°   Ú_search_return_discovered_names)rç   rê   Úcapability_by_load_call_idÚtools_by_capabilityrÄ   Ú
recognizedrþ  rŽ  Úsearch_returnr+  Úsearch_call_messageÚload_return_messageÚload_returnrj  Úcapability_toolsÚ
discovereds                   rz   r–  r–  	  s7  € ô ">¸hÓ!GÐØ/1ÐØbÐ*×9Ñ9ÐbÐ<T×<aÑ<aÓbˆØ×ÑÓ)Ø×*Ñ*¨4×+=Ñ+=¼s»uÓE×IÑIÈ$Ï)É)ÖTñ cð (*€JÜ# H×-‰ˆØ�1‹9œJ w´×=Ñ=ÄÀWÇ]Á]ÓASÐWXÓAXÙØŸ™ aÑ(ˆÜ˜-¬×8Ñ8¸M×<SÑ<SÔWuÓ<uÙØ$×1Ñ1ˆØ×&Ñ&¤v×'AÑ'A×BÑBÙà&¨q¡yÑ1ÐØ&¨q¡yÑ1ÐäÐ.´×>Ñ>ÜÐ&×,Ñ,Ó-°Ó2ÜÐ1×7Ñ7¸Ñ:¼L×IÑIØ"×(Ñ(¨Ñ+×5Ñ5Ô9WÓWØ"×(Ñ(¨Ñ+×8Ñ8¸LÓHÜÐ1´<×@Ñ@Ø&×,×,âØ)×/Ñ/°Ñ3ˆÜ˜+¤~×6Ñ6¸+×:OÑ:OÐSdÓ:dÚØ2×6Ñ6°{×7OÑ7OÓPˆØERÑE^Ð.×2Ñ2°=ÔAÐdhÐÞÚä4°]ÓCˆ
ØÑÚß‰:œ#˜j›/Ð-=Ö=Ø'1�|Ô$ñE .ðH Ðry   c                óx  • 0 nU  Hš  n[        U[        5      (       d  M  UR                   Hp  n[        U[        5      (       a  UR                  S:w  a  M*   UR                  SS9nUR                  S5      n[        U[        5      (       d  Mb  XQUR                  '   Mr     Mœ     U$ ! [        [        4 a     M�  f = f)Nrh  T)Úraise_if_invalidÚid)r‡  r>   r{  rK   r´   Úargs_as_dictÚAssertionErrorr¥  r°   rÒ   r+  )rç   Úcapability_by_call_idrŽ  r�  Úargsrj  s         rz   ri  ri  I	  s¯   € Ø,.ÐÛˆÜ˜'¤=×1Ñ1ÙØ—M”MˆDÜ˜d¤L×1Ñ1°T·^±^ÐGXÓ5XÙðØ×(Ñ(¸$Ð(Ð?�ð !ŸH™H T›NˆMÜ˜-¬×-Ó-Ø;H d×&7Ñ&7Ó8ó "ñ ð !Ð øô #¤JÐ/ó Úðús   ÁB%Â%B9Â8B9c                óp  • [        U [        5      (       a  U R                   Vs/ s H  oS   PM	     sn$ U R                  nUb  UR	                  S5      OS n[        U[
        5      (       d  g [        [
        [           U5      n[        S U 5       5      (       d  g [        [
        [           U5      $ s  snf )Nr»   Údiscovered_toolsc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   )r‡  rÒ   ©rk  r»   s     rz   rl  Ú2_search_return_discovered_names.<locals>.<genexpr>c	  s   é € Ð8²¨Œz˜$¤×$Ð$²ùr¬  )
r‡  rN   r€  rì  r°   rÜ   r   r   rÑ  rÒ   )r�  Úmatchrì  rw  rr  s        rz   rn  rn  [	  s™   € Ü�$Ô,×-Ñ-Ø+/×+@Ò+@ÓAÒ+@ %�f”Ñ+@ÑAÐAØ�}‰}€HØ5=Ñ5I�—‘Ð0Ô1Èt€JÜ�j¤$×'Ñ'ØÜ”$”s‘)˜ZÓ(€FÜÑ8±Ó8×8Ñ8ØÜ””S‘	˜6Ó"Ð"ùò Bs   ¤B3c           	     ó:  • / nU  GH  n[        U[        5      (       aX  UR                   Vs/ s H@  n[        U[        5      (       a&  UR                  [
        :X  a  UR                  U;   a  M>  UPMB     nnOuUR                   Vs/ s H^  n[        U[        5      (       aD  UR                  [
        :X  a0  UR                  U;   a   [        XR                     UR                  S9OUPM`     nnU(       d  Mï  UR                  [        X5S95        GM
     U$ s  snf s  snf )zMReplace selected search call/return pairs with wire-only availability deltas.)Útools_addedr+  r4  )r‡  r>   r{  rK   r´   rV   r+  rL   rJ   rÏ  r   )rç   r˜  ÚtransformedrŽ  r�  r{  s         rz   r—  r—  h	  s  € ð ')€KÜˆÜ�gœ}×-Ñ-ð $ŸMšMóâ)�Dä˜t¤\×2Ñ2ØŸ™Ô*HÓHØ×)Ñ)Ð-@Ñ@÷ Ù)ð ð ˆEð( $ŸMšMóò *�Dô ˜t¤^×4Ñ4ØŸ™Ô*HÓHØ×)Ñ)Ð-@Ó@ô *Ø 3×4EÑ4EÑ FÐUY×UfÑUfòð òñ *ð ð ÷ ˆ5Ø×Ñœw wÑ<×=ñ3 ð4 Ðùò1ùòs   ¬=DÁ-DÂA%Dc                ó  • / nSnSnU  GHo  n[        U[        5      (       d  UR                  U5        M,  [        S UR                   5       5      (       d  UR                  U5        SnMb  Sn/ nUR                   H˜  n[        U[
        5      (       d  UR                  U5        M+  UR                   Vs/ s H  o�b  X�;   d  M  UPM     n	nU	(       d  MY  UR                  [        [        R                  SR                  S U	 5       5      S9S95        Mš     U(       d  GM  [        XVS	9n
U(       a  [        U
5      OS
nUSU XkS pÜUR                  [        S9  UR                  [        U
/ UQUQS	95        SnGMr     U(       a  U$ U $ s  snf )uo  Render tool availability changes as a mid-conversation system instruction.

Providers with a native way to say "these tools just appeared" get it rendered natively. The rest
used to get a fabricated `search_tools` call/return pair, which told the model it had run a search
it never ran. That was wrong in three ways, and all three go away by stating the fact instead:

* It attributed an action to the model. In a mixed corpus â€” some tools searchable, some gated
  behind a capability â€” a capability load rendered as a search claims the wrong cause.
* It could reference a `search_tools` tool that isn't on the wire, since the corpus-empty drop
  removes it when nothing is searchable. Some providers reject a history naming an undeclared tool.
* It had to fabricate a `tool_call_id`, and two deltas over the same tool names produced the same
  one â€” duplicate ids in a history that providers requiring uniqueness reject.

A `SystemPromptPart` also stays inside the delta's own message, where the pair had to be spliced
across two messages: the fabricated `ModelResponse` went in ahead of the rebuilt `ModelRequest`,
so a delta sharing a request with a user prompt put the assistant's turn before it and reordered
the conversation. Within that message the announcements render after the request's tool results.

On a model that takes a mid-conversation system message this lands as a real one, carrying the
operator authority the statement deserves; elsewhere `_wrap_non_leading_system_prompts` â€” which
runs after this â€” degrades it to `<system>`-tagged user text. Either way it's append-only, so the
cached prefix ahead of it survives.
FTc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   ©r‡  rJ   ©rk  r�  s     rz   rl  Ú=_announce_tool_availability_delta_messages.<locals>.<genexpr>®	  s   é € ÐYÊ=À4”:˜dÔ$=×>Ð>Ê=ùr¬  Nz, c              3  ó.   #   • U  H  nS U S 3v •  M     g7f)Ú`Nrx   r‚  s     rz   rl  rŒ  ¾	  s    é € ÐUtÒnsÐfjÐXYÐZ^ÐY_Ð_`ÕVaÒnsùs   ‚)Únamesr`  r4  r   r‰  )r‡  r<   rÏ  r  r{  rJ   r†  rG   ÚTOOL_AVAILABILITY_ANNOUNCEMENTrø  r&  r   rD  ÚsortrS   )rç   r’  r‡  r(  Úis_first_kept_requestrŽ  Úreplacement_partsr�  r»   Úaddedr6  ÚkeepÚheadrM  s                 rz   rŠ  rŠ  Š	  s‚  € ð: ')€KØ€GØ ÐÜˆÜ˜'¤<×0Ñ0Ø×Ñ˜wÔ'ÙÜÑYÈ7Ï=Ê=ÓY×YÑYØ×Ñ˜wÔ'Ø$)Ð!ÙàˆØ46ÐØ—M”MˆDÜ˜dÔ$=×>Ñ>Ø!×(Ñ(¨Ô.Ùà&*×&6Ò&6ÓuÒ&6˜dÑ:UÐY]ÑYt—TÑ&6ˆEÐußˆuØ!×(Ñ(Ü$Ü >× EÑ EÈDÏIÉIÑUtÑnsÓUtÓLtÐ EÐ uñöñ "÷ Ñô ˜gÑ?ˆGÞ=RÔ0°Ô9ÐXYˆDØ*¨5¨DÐ1Ð3DÀUÐ3K�$Ø�I‰IÔ6ˆIÑ7Ø×Ñœw w°n¸°n¸t°nÑEÔFØ$)Ó!ñI öL "ˆ;Ð/ xÐ/ùò- vs   Â4FÃFc                ó¶  ^• / nSnSn[        5       nU  VVs1 s HH  nUR                    H4  n[        U[        [        -  [
        -  5      (       d  M(  UR                  iM6     MJ     nnnSS jmU  GHK  n[        U[        5      (       a!  [        S UR                   5       5      (       d  UR                  U5        MM  Sn[        U4S j[        UR                  5       5       [        UR                  5      5      n	UR                  SU	 n
/ [        U
S S	9QUR                  U	S Qn/ nU GHj  n[        U[        5      (       d  UR                  U5        M,  UR                   Vs/ s H  oÑb  XÑ;   d  M  UPM     nnU(       d  MZ  UR                  nUb
  Xõ;   d  Xø;   at   [         R"                  " S
R%                  ['        U5      /UQ5      R)                  5       SSS9R+                  5       nUS-  n[,        R.                   U 3nXõ;  a  Xø;  a  OMs  UR1                  U5        U(       a  UR                  [3        XlS95        / nUR                  [5        [7        SU0US9/S95        UR                  [9        SU Vs/ s H  nSU0PM	     sn0US95        GMm     U(       d  GM3  UR                  [3        XlS95        GMN     U(       a  U$ U $ s  snnf s  snf s  snf )uã  Render tool availability changes as the local tool-search exchange.

For a model that can withhold a tool's schema, this exchange is the mechanism rather than the
news: the return is what Anthropic renders as the `tool_reference` block that unhides the schema
`defer_loading` is holding shut. A model without that ability gets
`_announce_tool_availability_delta_messages` instead, which states the change without claiming
the model ran a search.

The exchange spans a turn boundary â€” an assistant call, then its return â€” so a request holding
other parts alongside the delta has to be split around it. When parallel tool results and deltas
are interleaved, all results stay together before the synthetic exchanges. No other parts move.
Fr   c                óz   • [        U [        5      =(       d%    [        U [        5      =(       a    U R                  S L$ rº   )r‡  rL   rE   r´   ©r�  s    rz   Úis_tool_resultÚD_synthesize_tool_availability_delta_messages.<locals>.is_tool_resultü	  s-   € ä˜$¤Ó/×u´J¸tÄ_Ó4U×4tÐZ^×ZhÑZhÐptÐZtÐury   c              3  óB   #   • U  H  n[        U[        5      v •  M     g 7frº   rŠ  r‹  s     rz   rl  Ú?_synthesize_tool_availability_delta_messages.<locals>.<genexpr>
  s   é € ð <
ÚDQ¸DŒJ�tÔ6×7Ð7ÂMùr¬  Tc              3  óx   >#   • U  H/  u  p[        U[        5      (       a  M  T" U5      (       a  M+  Uv •  M1     g 7frº   rŠ  )rk  rþ  r�  rš  s      €rz   rl  r�  
  s5   øé € ð â#;‘K�EÜ! $Ô(A×Bó áKYÐZ^×K_÷ ‘Ú#;ùs   ƒ:¢:±	:Nc                ó"   • [        U [        5      $ rº   rŠ  r™  s    rz   r‡  Ú>_synthesize_tool_availability_delta_messages.<locals>.<lambda>
  s   € ¤¨DÔ2KÔ!Lry   r‰  Ú é   )Údigest_sizeÚusedforsecurityrl   r4  Úqueries)r~  r+  r€  r»   )ra  r+  )r�  r=   rÓ   r©   )rÞ   r{  r‡  r2   r3   rE   r+  r<   r  rÏ  r•  r;  rÐ  rs  rJ   r†  ÚhashlibÚblake2sr&  rÒ   ÚencodeÚ	hexdigestr%   rm  rl  r   r>   rM   rN   )rç   r’  r‡  r(  Úsynthesized_countÚsynthesized_idsrŽ  r�  Úhistory_call_idsÚfirst_unrelated_part_indexÚparallel_results_and_deltasr{  r>  r»   r”  r+  Údigestrš  s                    @rz   r‰  r‰  Ó	  sô  ø€ ð ')€KØ€Gð ÐÜ #£€Oñ  ôâˆGØ—M•MˆDÜ�dÔ,Ô/AÑAÄOÑS×Tó 	ˆ×Ôá!ñ 	Ùð ñ ôvô ˆÜ˜'¤<×0Ñ0¼ñ <
ØDKÇMÂMó<
÷ 9
ñ 9
ð ×Ñ˜wÔ'Ùàˆô &*ôä#,¨W¯]©]Ô#;óô
 �—‘Óó&
Ð"ð '.§m¡mÐ4OÐ5OÐ&PÐ#ð
ÜØ+ÙLñð
ð
 �]‰]Ð5Ð6Ð7ð
ˆð 13ˆÜˆDÜ˜dÔ$=×>Ñ>Ø×$Ñ$ TÔ*ÙØ&*×&6Ò&6ÓuÒ&6˜dÑ:UÐY]ÑYt—TÑ&6ˆEÐuÞÙà×,Ñ,ˆLØÑ# |Ó'FÈ,ÓJjØÜ$Ÿ_š_ØŸ™¤SÐ):Ó%;Ð$D¸eÐ$DÓE×LÑLÓNØ$%Ø(-ñ÷  ‘i“kð	 ð
 &¨Ñ*Ð%Ü&,×&@Ñ&@Ð%AÀ&ÀÐ#J�Lð $Ó:¸|Ó?cØñ ð ×Ñ Ô-ÞØ×"Ñ"¤7¨7Ñ#HÔIØ "�Ø×ÑÜÔ%7¸iÈÐ=OÐ^jÑ%kÐ$lÑmôð × Ñ Ü$Ø/ÉUÓ1SÊUÀT°6¸4³.ÉUÑ1SÐTØ!-ñ÷ñ= ÷H ‰=Ø×Ñœw wÑD×EñE öH "ˆ;Ð/ xÐ/ùó_ùòX vùò8 2Ts   —7KÁKÅ$KÅ3KÉ;K)rÓ   ztuple[str, ...]r?  )rz  r©   rÓ   zGenerator[None])rå   rÒ   rÓ   ztuple[str | None, str]rº   )rå   rÒ   r¸  rÒ   r–  zSequence[str] | NonerÓ   rÖ   )r�  rÒ   r¸  rÒ   rÓ   rÖ   )rå   rÒ   rÓ   r]   )rå   zModel | KnownModelName | strrÒ  zCallable[[str], Provider[Any]]rÓ   rä   )r×  rõ   rØ  rõ   rÓ   ro   )Úmime)rÅ  r7   ræ  zLiteral['bytes']rç  úLiteral['mime', 'extension']rÓ   zDownloadedItem[bytes])rÅ  r7   ræ  z'Literal['base64', 'base64_uri', 'text']rç  r±  rÓ   zDownloadedItem[str])rû  r°  )rÅ  r7   ræ  z0Literal['bytes', 'base64', 'base64_uri', 'text']rç  r±  rÓ   z+DownloadedItem[str] | DownloadedItem[bytes]rB  )rV  útype[JsonSchemaTransformer]r¶   rj   rÓ   rj   )rV  r²  r¦   rY   rÓ   rY   )
ru  r›   r  rÝ  r£  z5Callable[[Sequence[AbstractNativeTool]], bool] | Noner(  rÚ  rÓ   r›   )ru  r›   r[  r©   rÓ   r›   )r/  rA   ru  r›   rÓ   rå  )rç   ræ   r€  r©   rÓ   ræ   )r6  r<   rÓ   rõ   )
rç   ræ   r/  rÒ   r-  r©   r*  r©   rÓ   ræ   )rV  ræ   rH  r©   rÓ   zlist[ModelRequest])rç   ræ   rÓ   ræ   )rÓ   r0   )rç   ræ   rê   r›   rÓ   údict[str, list[str]])rç   ræ   rÓ   zdict[str, str])r�  rL   rÓ   zlist[str] | None)rç   ræ   r˜  r³  rÓ   ræ   )rç   ræ   r’  zset[str] | NonerÓ   ræ   )ÅrÛ   Ú
__future__r   Ú_annotationsrð  r¦  r$  r  rR  Úabcr   r   Úcollections.abcr   r   r   r	   r
   Ú
contextlibr   r   Údataclassesr   r   r   r   r   Údifflibr   Ú	functoolsr   r   Útypesr   Útypingr   r   r   r   r   r   r   r   r   r  Útyping_extensionsr   r    r!   r"   Útyping_inspection.introspectionr#   rj  r%   Ú_genai_pricesr&   r'   Ú_httpr(   r)   Ú_json_schemar*   Ú_outputr+   ró  r,   Ú_run_contextr-   Ú	_warningsr.   Ú
exceptionsr0   rç   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r    rT   rU   Únative_tools._tool_searchrV   rW   r,  rX   rY   rZ   Úprofilesr[   r\   r]   r^   r_   r`   ra   rb   Ú	providersrc   rd   re   rf   r  rg   rh   ri   Útoolsrj   r÷   rk   Ú	_abstractrm   Ú_known_model_namesrn   r  ro   Úagent.abstractrp   rq   Úobjectrö  rr   r{   r|   r’   rÔ   r›   rã   rï   rô   rä   râ  rF  rv  rx  r|  r‚  r›  r   r§  rÕ  rÞ  rÒ   rû  rß  rá  rè  rÜ  rT  rU  r¤  ro  r÷  r…  rD  r.  rJ  rŒ  rd  rf  r�  r–  ri  rn  r—  rŠ  r‰  rx   ry   rz   Ú<module>rÏ     sK  ðñõ 3ã Û Û Û Û ß #ß XÕ Xß :ß 1Ñ 1ß (Ý %ß ,Ý ß d× dÕ dã ß HÓ HÝ >å ß Gß NÝ 0Ý 0Ý 6Ý %Ý TÝ "÷$÷ $÷ $÷ $÷ $÷ $÷ $÷ $÷ $ñ $÷J Fß Vß MÑ M÷	÷ 	ó 	÷ XÓ Wß IÑ IÝ "Ý  Ý 5Ý @æÝ!å.Þ ð
 /;Ñ.F�,×*Ó*ÈF€Kà/Ð Ø fñ Ð/Ó0Ð ð ó\ó ð\ñ  -Ø"Øð	ñó Ð ñ4 %2Ø'Øð	ñ
ó%Ð !ð ÐIÑJ€ð	Fñ �˜tÑ$÷t3ð t3ó %ðt3ñn �4Ñ÷8ð 8ó ð8ñv �$ Ñ%ô2˜WÐ%6Ñ7ó 2ó &ð2ñ �$ Ñ%ôAÐ2Ð3DÑEó Aó &ðAô X	ˆM˜7 ?Ñ3ô X	ðv ôHP�só HPó ðHPôVf'Ð 0ô f'ðR Ð ðôbð2 ó)ó ð)ôö$ð$:Øð:Ø),ð:àô:ô$,ð` ]kðF3Ø'ðF3Ø;YðF3à
õF3ðR 0DÐTU÷ ñ< 	�˜˜eÓ$€ô
�Y ¨¡ô 
ð 
ð 17ð Ø
ð à!ð ð .ð ð ô	 ó 
ð ð 
ð 17ðØ
ðà8ðð .ðð ô	ó 
ðð ELØ06ð<EØ
ð<EàAð<Eð .ð<Eð 1õ	<Eð~ ó(ó ð(ôð	Ø,ð	Ø=Sð	àô	ð  X\Ø26ñ|Ø"ð|à8ð|ð  Uð	|ð
 0ð|ð õ|ð~(Ø"ð(ØDHð(àô(ôVKô4ônð0 (-Ø%*ñ;Ø ð;àð;ð !%ð	;ð
 #ð;ð õ;ð| Z^÷ Jô8!1ôHô,ð, "TÐ ðð3Ø ð3Ø<Rð3àô3ôl!ô$
#ðØ ðØ7KðàôðDF0Ø ðF0Ø7FðF0àôF0ðRq0Ø ðq0Ø7Fðq0àõq0ry   