ó
    °"³j‹&  ã                  óú  • % S r SSKJr  SSKJrJrJr  SSKJ	r	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JrJr  SS	KJrJrJr  \" S
S9 " S S5      5       r\" S
S9 " S S5      5       r\ " S S5      5       rSS jr\	\\-  \" S5      4   r S\!S'    \	\	\\" S5      4   \	\\" S5      4   -  \	\\" S5      4   -  \	\\" S5      4   -  \" \5      4   r"S\!S'    \ \"-  r# \" S
S9 " S S5      5       r$S S jr%g)!u  Deferred tool types.

The types here were originally in `tools.py`, but `tools.py` transitively
imports `_function_schema â†’ _run_context â†’ messages`, which means
`messages.py` cannot import from `tools.py` at module-load time.  This
module only depends on `messages`, `exceptions`, and `_utils`, so
`messages.py` can safely late-import from here (same pattern as
`_tool_search.py`).

`tools.py` re-exports every public name so that the external API
(`pydantic_ai.tools.DeferredToolRequests`, etc.) is unchanged.
é    )Úannotations)ÚKW_ONLYÚ	dataclassÚfield)Ú	AnnotatedÚAnyÚLiteralÚ	TypeAliasÚcast)ÚDiscriminatorÚ
StrictBoolÚTagé   )Ú_utils)Ú
ModelRetryÚ
ToolFailedÚ	UserError)ÚRetryPromptPartÚToolCallPartÚ
ToolReturnT)Úkw_onlyc                  ó¶   • \ rS rSr% Sr\" \\   S9rS\	S'    \" \\   S9r
S\	S'    \" \\\\\4   4   S9rS\	S'    S	S	S	S
S.         SS jjrSS jrSrg	)ÚDeferredToolRequestsé   a¬  Tool calls that require approval or external execution.

This can be used as an agent's `output_type` and will be used as the output of the agent run if the model called any deferred tools.

Results can be passed to the next agent run using a [`DeferredToolResults`][pydantic_ai.tools.DeferredToolResults] object with the same tool call IDs.

See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
©Údefault_factoryzlist[ToolCallPart]ÚcallsÚ	approvalsúdict[str, dict[str, Any]]ÚmetadataNF)r   r   r    Úapprove_allc               ó   • U(       a  [        U5      O0 nU(       a  [        U5      O0 nU R                   Vs1 s H  oUR                  iM     nnU R                   Vs1 s H  oUR                  iM     nn[	        U5      U-
  =n(       a  [        S[        U5       35      e[	        U5      U-
  =n	(       a  [        S[        U	5       35      eU(       a!  U[	        U5      -
   H  n
[        5       X'   M     [        XU=(       d    0 S9$ s  snf s  snf )a¡  Create a [`DeferredToolResults`][pydantic_ai.tools.DeferredToolResults] for these requests.

Args:
    approvals: Results for tool calls that required approval. Keys must match
        `tool_call_id`s in `self.approvals`.
    calls: Results for tool calls that required external execution. Keys must
        match `tool_call_id`s in `self.calls`.
    metadata: Per-call metadata, keyed by `tool_call_id`.
    approve_all: If `True`, every approval-requesting call not already listed in
        `approvals` is approved (with default `ToolApproved()`).

Raises:
    ValueError: If a key in `approvals`/`calls` doesn't match a pending request of
        the appropriate kind.
zQ`approvals` contains tool call IDs not in this `DeferredToolRequests.approvals`: zI`calls` contains tool call IDs not in this `DeferredToolRequests.calls`: ©r   r   r    )	Údictr   Útool_call_idr   ÚsetÚ
ValueErrorÚsortedÚToolApprovedÚDeferredToolResults)Úselfr   r   r    r!   ÚcÚapproval_idsÚcall_idsÚextra_approvalsÚextra_callsr%   s              ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/_deferred.pyÚbuild_resultsÚ"DeferredToolRequests.build_results,   sù   € ö. (1”D˜”O°bˆ	Þ$”�U”¨"ˆà04·²Ó?²¨1Ÿœ±ˆÐ?Ø,0¯JªJÓ7ªJ q—N”N©JˆÐ7ä! )›n¨|Ñ;Ð;ˆ?Õ;ÜØcÔdjÐkzÓd{Ðc|Ð}óð ô ˜e›* xÑ/Ð/ˆ;Õ/ÜØ[Ô\bÐcnÓ\oÐ[pÐqóð ö Ø ,¬s°9«~Ô =�Ü*6«.�	Ó'ñ !>ô #¨YÈhÏnÐZ\Ñ]Ð]ùò! @ùÚ7s   ·DÁDc           
     ó  • [        X5      n[        UR                  5      n[        UR                  5      nX#-  n[	        U R                   Vs/ s H  oUR
                  U;  d  M  UPM     snU R                   Vs/ s H  oUR
                  U;  d  M  UPM     snU R                  R                  5        VVs0 s H  u  pgXd;  d  M  Xg_M     snnS9nUR                  (       d  UR                  (       a  U$ S$ s  snf s  snf s  snnf )zMReturn unresolved requests after applying results, or `None` if all resolved.)r   r   r    N)Úfilter_deferred_resultsr&   r   r   r   r%   r    Úitems)	r+   ÚresultsÚcall_result_idsÚapproval_result_idsÚresolved_idsr,   ÚkÚvÚ	remainings	            r1   r=   ÚDeferredToolRequests.remainingX   sÏ   € ä)¨$Ó8ˆÜ˜gŸm™mÓ,ˆÜ! '×"3Ñ"3Ó4ÐØ&Ñ<ˆÜ(Ø"ŸjšjÓRšj˜¯N©NÀ/Ñ,Q—1™jÑRØ"&§.¢.Ó^¢.˜Q·N±NÐJ]Ñ4]—q¡.Ñ^Ø'+§}¡}×':Ñ':Ô'<ÔVÒ'<™t˜qÀÑ@U“d�a’dÑ'<ÒVñ
ˆ	ð
 &ŸOŸO¨y×/B×/BˆyÐLÈÐLùò	 SùÚ^ùÛVs$   ÁC7Á$C7Á:C<
ÂC<
Â6DÃD© )
r   z3dict[str, bool | DeferredToolApprovalResult] | Noner   z.dict[str, DeferredToolCallResult | Any] | Noner    z dict[str, dict[str, Any]] | Noner!   ÚboolÚreturnr*   )r7   r*   rA   zDeferredToolRequests | None)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úlistr   r   Ú__annotations__r   r$   Ústrr   r    r2   r=   Ú__static_attributes__r?   ó    r1   r   r      s´   ‡ ññ !&°d¸<Ñ6HÑ I€EÐÓIØ5Ù$)¸$¸|Ñ:LÑ$M€IÐ!ÓMØ=Ù*/ÀÀSÈ$ÈsÐTWÈxÉ.ÐEXÑ@YÑ*Z€HÐ'ÓZØDð
 JNØ@DØ59Ø!ñ*^ð Gð*^ð >ð	*^ð
 3ð*^ð ð*^ð 
õ*^÷XMrK   r   c                  ó8   • \ rS rSr% SrSrS\S'    SrS\S'   S	rg)
r)   éf   z[Indicates that a tool call has been approved and that the tool function should be executed.Nzdict[str, Any] | NoneÚoverride_argsztool-approvedzLiteral['tool-approved']Úkindr?   )	rB   rC   rD   rE   rF   rN   rH   rO   rJ   r?   rK   r1   r)   r)   f   s   ‡ áeà+/€MÐ(Ó/ØPà%4€DÐ
"Ö4rK   r)   c                  óB   • \ rS rSr% SrSrS\S'    S\S'   SrS	\S
'   Srg)Ú
ToolDeniedép   zeIndicates that a tool call has been denied and that a denial message should be returned to the model.zThe tool call was denied.rI   Úmessager   Ú_ztool-deniedzLiteral['tool-denied']rO   r?   N)	rB   rC   rD   rE   rF   rS   rH   rO   rJ   r?   rK   r1   rQ   rQ   p   s"   ‡ áoà.€GˆSÓ.Ø-àƒJà#0€DÐ
 Ö0rK   rQ   c                óÔ  • [        U [        5      (       a  g[        U [        5      (       a  g[        U [        5      (       aQ  [	        [        [
        [        4   U 5      nSU;   a  [	        [
        US   5      $ SU;   a  [	        [
        US   5      $  g [        U S5      (       a  [	        [
        U R                  5      $ [        U S5      (       a  [	        [
        U R                  5      $ g )Nútool-failedúmodel-retryrO   Ú	part_kind)
Ú
isinstancer   r   r$   r   rI   r   ÚhasattrrO   rX   )ÚxÚx_dicts     r1   Ú(_deferred_tool_call_result_discriminatorr]   |   sÁ   € Ü�!”Z× Ñ ØÜ	�A”z×	"Ñ	"ØÜ	�A”t×	Ñ	Ü”dœ3¤˜8‘n aÓ(ˆØ�VÓÜœ˜V F™^Ó,Ð,Ø˜FÓ"Üœ˜V KÑ0Ó1Ð1ð #ð ô	 �1�f×ÑÜœ˜QŸV™VÓ$Ð$Ü�Q˜×$Ñ$Üœ˜QŸ[™[Ó)Ð)ØrK   rO   r
   ÚDeferredToolApprovalResultztool-returnrV   rW   zretry-promptÚDeferredToolCallResultc                  óª   • \ rS rSr% Sr\" \\\\	-  4   S9r
S\S'    \" \\\\-  4   S9rS\S'    \" \\\\\	4   4   S9rS\S	'    SS
 jrSS jrSrg)r*   é�   aN  Results for deferred tool calls from a previous run that required approval or external execution.

The tool call IDs need to match those from the [`DeferredToolRequests`][pydantic_ai.tools.DeferredToolRequests] output object from the previous run.

See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
r   z'dict[str, DeferredToolCallResult | Any]r   z2dict[str, StrictBool | DeferredToolApprovalResult]r   r   r    c                óâ   • U R                   R                  UR                   5        U R                  R                  UR                  5        U R                  R                  UR                  5        g)zFUpdate this `DeferredToolResults` with entries from another, in-place.N)r   Úupdater   r    )r+   Úothers     r1   rc   ÚDeferredToolResults.update¯   sD   € à�‰×Ñ˜eŸo™oÔ.Ø�
‰
×Ñ˜%Ÿ+™+Ô&Ø�‰×Ñ˜UŸ^™^Õ,rK   c                ó¦  • 0 nU R                   R                  5        HT  u  p#USL a  [        5       nO;USL a  [        5       nO+[	        U[        [        45      (       d  [        SU< S35      eX1U'   MV     [        R                  " [        5      nU R                  R                  5        H$  u  p%[	        XT5      (       d  [        U5      nXQU'   M&     U$ )zÒConvert results into the internal per-call format used by the tool-execution pipeline.

Normalizes `True`/`False` approvals to `ToolApproved`/`ToolDenied`, and wraps
plain external-call values in `ToolReturn`.
TFz&Invalid approval result for tool call z2: expected `bool`, `ToolApproved`, or `ToolDenied`)r   r6   r)   rQ   rY   r   r   Úget_union_argsr_   r   r   )r+   Útool_call_resultsr%   ÚapprovalÚcall_result_typesÚcall_results         r1   Úto_tool_call_resultsÚ(DeferredToolResults.to_tool_call_resultsµ   sÓ   € ð <>ÐØ&*§n¡n×&:Ñ&:Ö&<Ñ"ˆLØ˜4ÒÜ'›>‘Ø˜UÒ"Ü%›<‘Ü ¬<¼Ð*D×EÑEÜØ<¸\Ñ<Lð MGð Góð ð /7˜lÓ+ñ '=ô #×1Ò1Ô2HÓIÐØ)-¯©×)9Ñ)9Ö);Ñ%ˆLÜ˜k×=Ñ=Ü(¨Ó5�Ø.9˜lÓ+ñ *<ð !Ð rK   r?   N)rd   r*   rA   ÚNone)rA   zdict[str, DeferredToolResult])rB   rC   rD   rE   rF   r   r$   rI   r_   r   r   rH   r   r^   r   r    rc   rl   rJ   r?   rK   r1   r*   r*   �   s�   ‡ ññ 6;È4ÐPSÐUkÐnqÑUqÐPqÑKrÑ5s€EÐ2ÓsØZÙDIØ˜S *Ð/IÑ"IÐIÑJñE€IÐAó ð cÙ*/ÀÀSÈ$ÈsÐTWÈxÉ.ÐEXÑ@YÑ*Z€HÐ'ÓZð Tô-÷!rK   r*   c           	     ó¼  • U R                    Vs1 s H  o"R                  iM     nnU R                   Vs1 s H  o"R                  iM     nn[        UR                   R	                  5        VVs0 s H  u  pVXS;   d  M  XV_M     snnUR                  R	                  5        VVs0 s H  u  pVXT;   d  M  XV_M     snnUR
                  S9$ s  snf s  snf s  snnf s  snnf )z?Keep results whose IDs belong to the matching request category.r#   )r   r%   r   r*   r6   r    )Úrequestsr7   Úcallr-   r.   r%   Úresults          r1   r5   r5   Ð   sÒ   € à2:×2DÒ2DÓEÒ2D¨$×%Ô%Ñ2D€LÐEØ.6¯nªnÓ=ªn d×!Ô!©n€HÐ=Üà=D×=NÑ=N×=TÑ=TÔ=Vô
Ú=VÑ%9 \ÐZfÑZvÓ ˆLÒ Ñ=Vò
ð AHÇÁ×@SÑ@SÔ@UÔrÒ@UÑ(<¨ÐYeÑYqÓ#ˆ|Ò#Ñ@UÒrØ×!Ñ!ñð ùò FùÚ=ùó
ùó ss"   �C´CÁ-C
Á<C
Â"CÂ1CN)r[   r   rA   z
str | None)rp   r   r7   r*   rA   r*   )&rF   Ú
__future__r   Ú_annotationsÚdataclassesr   r   r   Útypingr   r   r	   r
   r   Úpydanticr   r   r   Ú r   Ú
exceptionsr   r   r   Úmessagesr   r   r   r   r)   rQ   r]   r^   rH   r_   ÚDeferredToolResultr*   r5   r?   rK   r1   Ú<module>r|      si  ðòõ 3ç 1Ñ 1ß ;Õ ;ç 3Ñ 3å ß 9Ñ 9ß ?Ñ ?ñ �4Ñ÷HMð HMó ðHMñV �4Ñ÷5ð 5ó ð5ð ÷1ð 1ó ð1ôð& )2°,ÀÑ2KÉ]Ð[aÓMbÐ2bÑ(cÐ ˜IÓ cØ FØ$-Øˆj™#˜mÓ,Ð,Ñ-Ø�
™C Ó.Ð.Ñ/ñ0à�
™C Ó.Ð.Ñ/ñ0ð �¡ ^Ó!4Ð4Ñ5ñ6ñ Ð:Ó;ð	=ñ%Ð ˜	ó ð ?Ø/Ð2HÑHÐ Ø Jñ �4Ñ÷/!ð /!ó ð/!õd
rK   