ó
    ±"³j‘$  ã                   óŽ   • S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SK	J
r
Jr  \S   \\S   \\   4   -  rS	\
S-  S
\S\4S jrg)é    N)ÚLiteral)Úassert_never)Ú	UserError)ÚModelRequestParameters)ÚModelSettingsÚToolOrOutput)ÚnoneÚautoÚrequired)r
   r   Úmodel_settingsÚmodel_request_parametersÚreturnc                 ó>  ^^• U =(       d    0 R                  S5      nTR                  =(       d    TR                  n[        TR                  R                  5       5      mSS.S[        [           S[        S[        [           4UU4S jjjnS[        [           S[        [           S	[        SS
4S jnUS;   a  U(       a  S$ S$ US/ 4;   a^  TR                   Vs1 s H  ofR                  iM     nnU(       a#  U(       a  SnX‡4$ TR                  (       a  SnX‡4$ gU(       a  g S5       eUS:X  aL  TR                  (       d  [        S5      e[        U4S jTR                   5       5      (       a  [        S5      eg[        U[        5      (       a&  [        U5      n	U" U	TSS9  U" U	5      n	U	T:X  a  gSU	4$ [        U[        5      (       a¸  TR                   Vs1 s H  ofR                  iM     nnUR                  (       d  U(       a  U(       a  SOSnX‡4$ g[        UR                  5      n
TR                   Vs1 s H  ofR                  iM     nnU" U
USS9  U" U
[        U5      S9n
X§-  nU(       a  SOSnUT:X  a  U$ XŒ4$ [!        U5        g
s  snf s  snf s  snf )aÔ  Resolve user-facing tool_choice into a canonical form for providers.

Pydantic AI distinguishes between function tools (e.g. user-registered via @agent.tool)
and output tools (framework-internal for structured output). The user-facing
`tool_choice` setting controls function tools only - this function resolves that
into a canonical form that providers can use, incorporating output tools as needed.

Args:
    model_settings: Optional settings containing the tool_choice value.
    model_request_parameters: Parameters describing available tools and output configuration.

Input behavior:

    - `None` / `'auto'`: Returns `'auto'` if direct output allowed, else `'required'`.
    - `'none'` / `[]`: Disables function tools. If output tools exist, returns them with
        appropriate mode. Otherwise returns `'none'`.
    - `'required'`: Requires function tool use. Raises if no function tools are defined.
    - `list[str]`: Restricts to specified tools with `'required'` mode. Validates tool names.
    - `ToolOrOutput`: Combines specified function tools with all output tools.
        Returns `'auto'` mode if direct output is allowed, otherwise `'required'`.

Raises:
    UserError: If tool_choice is incompatible with the available tools or output configuration.

Returns:
    A canonical tool_choice value for providers:

    - `'none'`: No tools should be called. Only valid when direct output (text/image) is allowed.
    - `'auto'`: Model chooses whether to use tools. Direct output is allowed.
    - `'required'`: Model must use a tool. Direct output is not allowed.
    - `('auto', tool_names)`: Only these tools are available, direct output is allowed.
    - `('required', tool_names)`: Only these tools are available, must use one.
Útool_choiceF)Úhas_output_fallbackÚchosen_tool_namesr   r   c                ó  >• TR                    Vs1 s H0  nTR                  UR                  5      S:X  d  M$  UR                  iM2     nnX-
  nU (       a)  UT-  (       d  U(       d  [        S[	        U 5       S35      eU$ s  snf )NÚwithheldz1No tool in `tool_choice` is currently available: zu. Hidden tools must be revealed with tool search, `load_capability`, or `ToolReturn.tools` before they can be forced.)Úfunction_toolsÚvisibility_ofÚnamer   Úsorted)r   r   ÚtoolÚwithheld_tool_namesÚfilteredÚknown_tool_namesr   s        €€Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/models/_tool_choice.pyÚ_filter_withheld_toolsÚ3resolve_tool_choice.<locals>._filter_withheld_tools<   s–   ø€ ð 1×?Ò?ó
â?�Ø'×5Ñ5°d·i±iÓ@ÀJÑNó ˆD�IŒIÙ?ð 	ð 
ð
 %Ñ:ˆö  hÐ1A×&AÖK^ÜØCÄFÐK\ÓD]ÐC^ð _@ð @óð ð
 ˆùò#
s
   �#A?·A?Úknown_toolsÚknown_labelNc          
      óÊ   • X-
  nU(       d  g X0:X  a  [        SU SU SU=(       d    S 35      e[        R                  " S[        U5       SU S[        U5       3[        SS9  g )Nz%Invalid tool names in `tool_choice`: z. z: r	   zMSome tools in `tool_choice` are not currently available and will be ignored: é   )Ú
stacklevel)r   ÚwarningsÚwarnr   ÚUserWarning)r   r    r!   Úinvalids       r   Ú_check_invalid_toolsÚ1resolve_tool_choice.<locals>._check_invalid_toolsU   sw   € Ø#Ñ1ˆÞØØÓ'ÜÐCÀGÀ9ÈBÈ{ÈmÐ[]Ð^i×^sÐmsÐ]tÐuÓvÐvô
 	�ŠØ[Ü�g‹Ð˜r + ¨b´¸Ó1DÐ0EðGäØó		
ó    )Nr
   r
   r   r	   zGEither output_tools or allow_text_output/allow_image_output must be setz‘`tool_choice` was set to "required", but no function tools are defined. Please define function tools or change `tool_choice` to "auto" or "none".c              3   ó`   >#   • U  H#  nTR                  UR                  5      S :H  v •  M%     g7f)r   N)r   r   )Ú.0r   r   s     €r   Ú	<genexpr>Ú&resolve_tool_choice.<locals>.<genexpr>…   s,   øé € ð 
â?�ð %×2Ñ2°4·9±9Ó=ÀÖKÚ?ùs   ƒ+.z¸`tool_choice` was set to "required", but every function tool is hidden until revealed. Reveal tools with tool search, `load_capability`, or `ToolReturn.tools`, or change `tool_choice`.zKnown tools)r!   zKnown function tools)ÚgetÚallow_text_outputÚallow_image_outputÚsetÚ	tool_defsÚkeysÚstrÚboolÚoutput_toolsr   r   r   ÚallÚ
isinstanceÚlistr   r   )r   r   Úfunction_tool_choiceÚallow_direct_outputr   r)   ÚtÚoutput_tool_namesÚmodeÚ
chosen_setÚchosen_function_setÚknown_function_tool_namesÚallowed_toolsr   s    `           @r   Úresolve_tool_choicerE      sÕ  ù€ ðJ +×0¨b×5Ñ5°mÓDÐà2×DÑD×sÐH`×HsÑHsÐô Ð3×=Ñ=×BÑBÓDÓEÐà[`ò ´#´c±(ð ÔTXð ÔehÔilÑem÷ ñ ð2
´´C±ð 
ÄsÌ3Áxð 
Ôadð 
Ðimô 
ð$ ˜~Ó-Þ,ˆvÐ<°*Ð<ð 
 &¨" Ó	-Ø-E×-RÒ-RÓSÒ-R¨ŸVœVÑ-RÐÐSæÞ"Ø4:�ð Ð,Ð,ð *×8×8Ø!�ð Ð,Ð,ð "ö Øð 	`Ð_Ó_ˆuð 
 Ó	+Ø'×6×6Üð\óð ô ô 
à0×?Ò?ó
÷ 
ñ 
ô ð+óð ð
 ô 
Ð(¬$×	/Ñ	/ÜÐ-Ó.ˆ
Ù˜ZÐ)9À}ÒUñ ,¨JÓ7ˆ
àÐ)Ó)Øà˜JÐ'Ð'ô 
Ð(¬,×	7Ñ	7Ø-E×-RÒ-RÓSÒ-R¨ŸVœVÑ-RÐÐSà#×2×2Þ Þ>Q±FÐWa�ØÐ0Ð0Øä!Ð"6×"EÑ"EÓFÐØ5M×5\Ò5\Ó$]Ò5\°§V¤VÑ5\Ð!Ð$]ÙØØ%Ø.ò	
ñ
 5Ð5HÔ^bÐctÓ^uÑvÐà+Ñ?ˆÞ6I©FÈzˆØÐ,Ó,ØˆKàÐ$Ð$äÐ)Õ*ùò[ Tùòj Tùò %^s   ÃJÇJÈ;J)r%   Útypingr   Útyping_extensionsr   Úpydantic_ai.exceptionsr   Úpydantic_ai.modelsr   Úpydantic_ai.settingsr   r   Útupler3   r6   ÚResolvedToolChoicerE   © r+   r   Ú<module>rN      sg   ðÛ Ý å *å ,Ý 5ß <àÐ7Ñ8¸5ÀÐI[ÑA\Ð^aÐbeÑ^fÐAfÑ;gÑgÐ ðl+Ø! DÑ(ðl+à4ðl+ð õl+r+   