ó
    ±"³j„<  ã                  ó  • 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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JrJrJrJr  S S	KJr  S S
KJr  S SKJr  SSK J!r!J"r"  SSK#J$r$  SSK%J&r&  \" S\S9r'\" SS9 " S S\&\   5      5       r(g)é    )Úannotations)Ú	AwaitableÚCallableÚSequence)Ú	dataclassÚfieldÚreplace)ÚAnyÚTypeVarÚcast)Úreplace_no_init)Ú	UserError)ÚAbstractNativeTool)Ú
AgentDepsTÚAgentNativeToolÚ
RunContextÚToolÚToolDefinition)ÚAbstractToolset)ÚFunctionToolset)ÚPreparedToolseté   )Úmerge_capability_fieldsÚmerge_field_values)Úresolve_native_tool)ÚAbstractCapabilityÚ_NativeToolT)ÚboundF)Úinitc                  ó*  • \ rS rSr% SrSrS\S'    SrS\S'    SSSS	SS
.           SS jjr\	" S	S	S	SS9r
S\S'    \	" S	S	S	SS9rS\S'    SS jrSS jrSS jrS S jrS!S jrS"S jrS!S jrS#S jrS$S jr\S%S j5       r      S&S jrSrg)'ÚNativeOrLocalToolé   aø  Capability that pairs a provider-native tool with a local fallback.

When the model supports the native tool, the local fallback is removed.
When the model doesn't support the native tool, it is removed and the local tool stays.

Can be used directly:

```python {test="skip" lint="skip"}
from pydantic_ai.capabilities import NativeOrLocalTool

cap = NativeOrLocalTool(native=WebSearchTool(), local=my_search_func)
```

Or subclassed to set defaults by overriding `_default_native`, `_default_local`,
`_has_local_fallback`, and `_requires_native`.
The built-in [`WebSearch`][pydantic_ai.capabilities.WebSearch],
[`WebFetch`][pydantic_ai.capabilities.WebFetch], and
[`ImageGeneration`][pydantic_ai.capabilities.ImageGeneration] capabilities
are all subclasses.
Tú"AgentNativeTool[AgentDepsT] | boolÚnativeNúWstr | Tool[AgentDepsT] | Callable[..., Any] | AbstractToolset[AgentDepsT] | bool | NoneÚlocalF)r$   r&   ÚidÚdefer_loadingÚdescriptionc               ó`   • X0l         XPl        X@l        Xl        X l        U R                  5         g ©N)r'   r)   r(   r$   r&   Ú__post_init__)Úselfr$   r&   r'   r(   r)   s         Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/capabilities/native_or_local.pyÚ__init__ÚNativeOrLocalTool.__init__D   s+   € ð ŒØ&ÔØ*ÔØŒØŒ
Ø×ÑÕó    )r   ÚreprÚcompareÚdefaultz)AgentNativeTool[AgentDepsT] | bool | NoneÚ_declared_nativeÚ_declared_localc                ód  • [         R                  U SU R                  5        [         R                  U SU R                  5        U R                  SL a0  U R                  SL a!  [	        [        U 5      R                   S35      eU R                  SL a:  U R                  5       nUc!  [	        [        U 5      R                   S35      eXl        U R                  c  U R                  5       U l        O¸U R                  SL d  [        U R                  [        5      (       a!  U R                  U R                  5      U l        OiU R                  SL a  OY[        U R                  5      (       a?  [        U R                  [        [        45      (       d  [        U R                  5      U l        U R                  SL a6  U R                  5       (       a!  [	        [        U 5      R                   S35      eU R                  SL a7  U R!                  5       (       d!  [	        [        U 5      R                   S35      eg g )	Nr5   r6   Fz+: both `native` and `local` cannot be FalseTzw: native=True requires a subclass that overrides `_default_native()`, or pass an `AbstractNativeTool` instance directlyz=: constraint fields require the native tool, but native=Falseu�   (native=False) requires an explicit local tool â€” pass `local=...` (e.g. a strategy string, `True`, a callable, or a `Tool`/`AbstractToolset`).)ÚobjectÚ__setattr__r$   r&   r   ÚtypeÚ__name__Ú_default_nativeÚ_default_localÚ
isinstanceÚstrÚ_resolve_local_strategyÚcallabler   r   Ú_requires_nativeÚ_has_local_fallback)r-   r4   s     r.   r,   ÚNativeOrLocalTool.__post_init__d   sÑ  € ô 	×Ñ˜4Ð!3°T·[±[ÔAÜ×Ñ˜4Ð!2°D·J±JÔ?Ø�;‰;˜%Ò D§J¡J°%Ò$7Üœt D›z×2Ñ2Ð3Ð3^Ð_Ó`Ð`ð �;‰;˜$ÒØ×*Ñ*Ó,ˆGØ‰ÜÜ˜D“z×*Ñ*Ð+ð ,]ð ^óð ð "ŒKð �:‰:ÑØ×,Ñ,Ó.ˆD�JØ�Z‰Z˜4Ò¤:¨d¯j©j¼#×#>Ñ#>Ø×5Ñ5°d·j±jÓAˆD�JØ�Z‰Z˜5Ò ØÜ�d—j‘j×!Ñ!¬*°T·Z±ZÄ$ÌÐAX×*YÑ*YÜ˜dŸj™jÓ)ˆDŒJð
 �;‰;˜%Ò D×$9Ñ$9×$;Ñ$;Üœt D›z×2Ñ2Ð3Ð3pÐqÓrÐrð �;‰;˜%Ò¨×(@Ñ(@×(BÑ(BÜÜ˜“:×&Ñ&Ð'ð (pð póð ð )CÐr1   c                ó   • g)z¯Create the default native tool instance.

Override in subclasses. Returns None by default (direct use requires
passing an explicit `AbstractNativeTool` instance as `native`).
N© ©r-   s    r.   r<   Ú!NativeOrLocalTool._default_native’   s   € ð r1   c                óž   • U R                   n[        U[        5      (       a  UR                  $ [	        [        U 5      R                   S35      e)z°The unique_id used for `unless_native` on local tool definitions.

By default, derived from the native tool's `unique_id` property.
Override in subclasses for custom behavior.
uT   : cannot derive native unique_id â€” override `_native_unique_id()` in your subclass)r$   r>   r   Ú	unique_idr   r:   r;   )r-   r$   s     r.   Ú_native_unique_idÚ#NativeOrLocalTool._native_unique_idš   sJ   € ð —‘ˆÜ�fÔ0×1Ñ1Ø×#Ñ#Ð#ÜÜ�D‹z×"Ñ"Ð#Ð#wÐxó
ð 	
r1   c                ó   • g)zCAuto-detect a local fallback. Override in subclasses that have one.NrF   rG   s    r.   r=   Ú NativeOrLocalTool._default_local§   s   € àr1   c                ó   • U R                   SL$ )u“  Whether a local fallback is configured, once `local` has been resolved.

`local` is where one lives here, so the default reads that field. Override in a subclass
that builds its local tool from a field of its own â€”
[`ImageGeneration`][pydantic_ai.capabilities.ImageGeneration] derives `generate_image` from
`fallback_image_model` â€” so `native=False` beside it reads as configured rather than as the
silent no-op capability `__post_init__` rejects.

An override owes the other half of that: `get_toolset` still yields nothing while `local` is
unset, so it has to produce the tool too. `ImageGeneration` resolves the generator onto
`local` on a copy there.
N)r&   rG   s    r.   rC   Ú%NativeOrLocalTool._has_local_fallback«   s   € ð �z‰z Ð%Ð%r1   c                óL   • [        [        U 5      R                   SU< S35      e)z¾Resolve a named local strategy (e.g. `'duckduckgo'`) or `local=True` to a concrete tool.

Override in subclasses that expose named strategies. The default implementation raises
`UserError`.
z	: `local=zK` is not supported. Pass a `Tool`, `AbstractToolset`, or callable directly.)r   r:   r;   )r-   Únames     r.   r@   Ú)NativeOrLocalTool._resolve_local_strategyº   s3   € ô Ü�D‹z×"Ñ"Ð# 9¨T©Hð 5Fð Fó
ð 	
r1   c                ó   • g)uX  Return True if capability-level constraint fields require the native tool.

When True, the local fallback is suppressed. If the model doesn't support
the native tool, `UserError` is raised â€” preventing silent constraint violation.

Override in subclasses that expose native-only constraint fields
(e.g. `allowed_domains`, `blocked_domains`).
FrF   rG   s    r.   rB   Ú"NativeOrLocalTool._requires_nativeÅ   s   € ð r1   c                ó€   • U R                   SL a  / $ [        U R                   [        5      (       a   eU R                   /$ )NF)r$   r>   ÚboolrG   s    r.   Úget_native_toolsÚ"NativeOrLocalTool.get_native_toolsÒ   s6   € Ø�;‰;˜%ÒØˆIä˜dŸk™k¬4×0Ñ0Ð0Ð0Ø—‘ˆ}Ðr1   c                ót  ^• U R                   nUb  USL d  U R                  5       (       a  g [        U[        5      (       a  [	        [        [
           U5      O)[        [	        [        [
           U5      /U R                  S9nU R                  SLa'  U R                  5       m      SU4S jjn[        X#S9$ U$ )NF)r'   c              “  óL   >#   • U Vs/ s H  n[        UTS9PM     sn$ s  snf 7f)N)Úunless_native)r	   )ÚctxÚ	tool_defsÚdÚuids      €r.   Ú_add_unless_nativeÚ9NativeOrLocalTool.get_toolset.<locals>._add_unless_nativeë   s)   øé € ñ @IÓIºy¸!œ °Ô5¹yÑIÐIùÒIùs   ƒ$ˆœ$)ÚwrappedÚprepare_func)r]   úRunContext[AgentDepsT]r^   úlist[ToolDefinition]Úreturnrf   )r&   rB   r>   r   r   r   r   r   r'   r$   rK   r   )r-   r&   Útoolsetra   r`   s       @r.   Úget_toolsetÚNativeOrLocalTool.get_toolsetÙ   s¹   ø€ Ø—
‘
ˆØ‰=˜E UšN¨d×.CÑ.C×.EÑ.EØô ˜%¤×1Ñ1ô ”¤Ñ,¨eÔ4ä ¤$¤t¬JÑ'7¸Ó"?Ð!@ÀTÇWÁWÑMð 	ð �;‰;˜eÒ#Ø×(Ñ(Ó*ˆCðJØ+ðJØ8LðJà%÷Jô
 #¨7ÑTÐTØˆr1   c           
     ó¢  • U Vs/ s H  n[        U[        5      (       d  M  UPM     nn[        U5      [        U5      :X  d   e[        U5      n[        X@5      (       d   e[	        U[        U Vs/ s H  o"R                  PM     snSS9[        U Vs/ s H  o"R                  PM     snSS9S9nUR                  5         U$ s  snf s  snf s  snf )a„  Merge the declared configuration, then rebuild the native tool from the result.

`__post_init__` copies this capability's configuration into the native tool it builds, and
that tool -- not the capability -- is what reaches the provider. Merging the capability's
fields alone would leave a merged `allowed_domains` beside a native tool still carrying one
instance's, so a composed restriction would read as applied while the request went out
without it. Anything `_default_native` produced is therefore produced again from the merged
configuration.

A native tool the user passed in is left alone: it states its own configuration, and
rebuilding would discard it. Two of those take the later, like any other value the merge
cannot reconcile.

The merged instance is validated the way a constructed one is. `replace_no_init` skips
`__post_init__`, and a merge can reach a combination no constructor would accept -- a
`native=False` instance beside one carrying native-only constraints leaves a capability that
contributes neither the native tool nor a local fallback. Re-running the check turns that
into the same `UserError` writing it by hand would raise.
r$   )Ú
field_namer&   )r$   r&   )	r>   r!   Úlenr   r   r   r5   r6   r,   )ÚclsÚcapabilitiesÚ
capabilityÚnol_capabilitiesÚmergeds        r.   ÚcombineÚNativeOrLocalTool.combineó   sÕ   € ñ* :FÓsº¨:ÌÐT^Ô`q×IrŸJ¹ÐÐsÜÐ#Ó$¬¨LÓ(9Ó9Ð9Ð9Ü(¨Ó6ˆÜ˜&×&Ñ&Ð&Ð&ô !ØÜ%Ù?OÓPÒ?O°×,Ô,Ñ?OÑPÐ]eñô %Ù>NÓOÒ>N°
×+Ô+Ñ>NÑOÐ\cññ
ˆð 	×ÑÔØˆùò# tùò Qùò Ps   …C¢CÁ0CÂCc                óp  ^^^• [        U R                  T5      (       a)  T(       a  [        U R                  40 TD6$ U R                  $ U R                  SL a  T" S0 TD6$ U R                  m[        T5      (       d1  [	        [        U 5      R                   STR                   ST< 35      eSUUU4S jjnU$ )um  Resolve the native tool for the fallback subagent, with capability-level overrides applied.

Handles every `native` shape reaching here: an instance (overridden via
`dataclasses.replace`), `False` (a default instance with overrides), or a factory (wrapped
so its resolved result is overridden the same way). `True` never arrives â€” `__post_init__`
has already resolved it to an instance. A factory that returns `None` raises `UserError`
rather than substituting a default instance, and anything else raises too.

Only the `fallback_subagent_model` path reaches here: `__post_init__` calls `_default_local()`, which
returns early when `fallback_subagent_model` is unset, so a capability configured without one never
runs this check. Validating in `__post_init__` instead would reject configurations that
construct fine today for users who never opted into a fallback subagent.
FzC: `native` must be `True`, `False`, a callable, or an instance of `z`, not c              “  ód   >#   • [        TTU 5      I S h  v•N nT(       a  [        U40 TD6$ U$  N7fr+   )r   r	   )r]   Únative_toolÚnative_factoryÚ	overridesÚtool_clss     €€€r.   Úresolve_nativeÚHNativeOrLocalTool._resolve_native_with_overrides.<locals>.resolve_native8  s4   øé € Ü 3°H¸nÈcÓ R×RˆKÞ8A”7˜;Ñ4¨)Ñ4ÐRÀ{ÐRñ Sùs   ƒ0”.•0rF   )r]   re   rg   r   )r>   r$   r	   rA   r   r:   r;   )r-   rz   ry   r{   rx   s    `` @r.   Ú_resolve_native_with_overridesÚ0NativeOrLocalTool._resolve_native_with_overrides  s²   ú€ ô  �d—k‘k 8×,Ñ,Þ8A”7˜4Ÿ;™;Ñ4¨)Ñ4ÐRÀtÇ{Á{ÐRà�;‰;˜%ÒÙÑ(˜iÑ(Ð(àŸ™ˆÜ˜×'Ñ'ÜÜ˜“:×&Ñ&Ð'ð (Ø×%Ñ%Ð& g¨nÑ-?ðAóð ÷
	Sñ 	Sð Ðr1   )r(   r)   r'   r&   r$   )r$   r#   r&   r%   r'   ú
str | Noner(   rW   r)   r   rg   ÚNone)rg   r€   )rg   zAbstractNativeTool | None)rg   r?   )rg   z5Tool[AgentDepsT] | AbstractToolset[AgentDepsT] | None)rg   rW   )rR   z
str | boolrg   z.Tool[AgentDepsT] | AbstractToolset[AgentDepsT])rg   z%Sequence[AgentNativeTool[AgentDepsT]])rg   z"AbstractToolset[AgentDepsT] | None)ro   z(Sequence[AbstractCapability[AgentDepsT]]rg   zAbstractCapability[AgentDepsT])rz   ztype[_NativeToolT]ry   zdict[str, Any]rg   zY_NativeToolT | Callable[[RunContext[AgentDepsT]], Awaitable[_NativeToolT] | _NativeToolT])r;   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   Ú__annotations__r&   r/   r   r5   r6   r,   r<   rK   r=   rC   r@   rB   rX   ri   Úclassmethodrs   r}   Ú__static_attributes__rF   r1   r.   r!   r!      s,  ‡ ñð* 26€FÐ.Ó5ðð fj€EÐbÓiðð 6:ØimØØ#Ø"&ñð 3ðð gð	ð
 ðð ðð  ðð 
õñ  CHØ˜¨°tñCÐÐ?ó ðñ puØ˜¨°tñp€OÐló ð iô*ô\ô
ôô&ô	
ô	ôôð4 ó%ó ð%ðN!Ø*ð!Ø7Eð!à	b÷!r1   r!   N))Ú
__future__r   Úcollections.abcr   r   r   Údataclassesr   r   r	   Útypingr
   r   r   Úpydantic_ai._utilsr   Úpydantic_ai.exceptionsr   Úpydantic_ai.native_toolsr   Úpydantic_ai.toolsr   r   r   r   r   Úpydantic_ai.toolsetsr   Úpydantic_ai.toolsets.functionr   Úpydantic_ai.toolsets.preparedr   Ú_merger   r   Ú_native_resolutionr   Úabstractr   r   r!   rF   r1   r.   Ú<module>r–      su   ðÝ "ç 9Ñ 9ß 1Ñ 1ß %Ñ %å .Ý ,Ý 7ß [Õ [Ý 0Ý 9Ý 9ç ?Ý 3õñ �~Ð-?Ñ@€ñ �ÑôcÐ*¨:Ñ6ó có ñcr1   