ó
    ±"³j%1  ã                  óæ   • S r SSKJr  SSK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  SSKJr  SS	KJr  \(       a  S
SKJr      SS jr\" S15      r SS jrSS jrSS jrSS jrSS jrg)az  Merging two capabilities that resolved to the same `id` into the one a run uses.

Private to the package: this is what `AbstractCapability.combine` does by default, so a capability
that wants it gets it by declaring a default `id` and writing no `combine` at all. One that wants
something else overrides `combine` and writes the merge it needs, rather than parameterizing this.
é    )ÚannotationsN)ÚMappingÚSequenceÚSet)Úcached_property)ÚTYPE_CHECKINGÚAnyÚcast)Úreplace_no_init)Ú	UserError)Ú
AgentDepsTé   )ÚAbstractCapabilityc                ót  • U S   n[         R                  " U5       Vs1 s H  o"R                  iM     nn[        [	        U5      5      U-
  nU  H€  n[        [        U5      5      U-
  U-
  [        -
  nU(       d  M-  [	        U5      R                  nSR                  [        U5      5      n[        SUR                  < SU SU SU SU S35      e   0 n	[         R                  " U5       Hw  nUR                  (       d  M  [        XR                  5      n
[        U  Vs/ s H  n[        XRR                  5      PM     snUR                  S	9nXºLd  Mi  X¹UR                  '   My     U	(       a  [!        U40 U	D6OUnU	(       a-  [#        S
UR$                  5      nU[        U5      -   H  nXÞ	 M     U$ s  snf s  snf )uO  Merge same-class capabilities field by field, the way overlapping dicts merge.

The `combine` implementation for a capability an agent has one of, where two of them are one
configuration stated twice and nothing either of them states should be dropped:

| both sides | result |
|---|---|
| neither states a value | unset |
| only one states a value | that value survives |
| both state a mapping, sequence, or set | the union, later entries winning a shared key |
| anything else | the later value |

`None` reads as "not stated", which is what makes a restriction survive being composed with a
capability that doesn't mention it: `WebSearch(allowed_domains=[...])` beside a plain
`WebSearch()` keeps the allow-list, rather than the plain one silently widening it.

Merging starts from the last capability so the fields that can't be reconciled â€” and the
subclass state `replace_no_init` carries over â€” are the last one's, matching the "later wins"
fallback.

Fields declared `compare=False` are per-run bookkeeping rather than configuration, so they are
left as the last capability's rather than merged.

Two limits worth knowing, both from configuration that is resolved before `combine` sees it:
a field a `__post_init__` has already materialized (`NativeOrLocalTool` turns `native=True` into
a tool instance and `local=None` into its default) can no longer be told apart from one the user
stated, so those take the later value; and two objects that carry no meaningful equality (two
stores, two clients) likewise take the later. A capability that needs either reconciled â€” or
needs a numeric budget to take the *smaller* value rather than the later one â€” overrides
`combine` itself.

An attribute no field declares is a harder limit, and is refused. The table above is what the
merge promises, and its first row is the load-bearing one: a value only one side states
survives. That cannot hold for an attribute the merge cannot enumerate -- `replace_no_init`
copies the last instance, so such an attribute silently takes the last value even where an
earlier instance was the only one to state it. Refusing says so instead.

A leading underscore does not exempt an attribute from that: it does not distinguish
configuration from derived state, and configuration is exactly what must not be dropped. Two
kinds are exempt, and they are exempt for different reasons. State the class can produce again
-- a `cached_property` -- is *dropped* from the copy, so it is recomputed from the merged fields
rather than carried over stale. `__orig_class__` is not the capability's state at all, so it is
left alone and simply not counted against it. Nothing here re-runs `__post_init__`
(`replace_no_init` exists precisely to skip it), so state a `__post_init__` derives is declared
as a field and recomputed in the capability's own `combine`, the way `NativeOrLocalTool`
rebuilds its native tool.
éÿÿÿÿz, zCapability id z is used by multiple z capabilities, but z sets z· outside its dataclass fields. Merging keeps a value only one of them states, and cannot do that for an attribute it cannot enumerate -- the last instance would win silently. Declare a   as dataclass fields to have them merged; or, for state derived from other fields, make it a `cached_property` so merging can recompute it, or declare it as a field and override `combine` to recompute it after merging, since this does not re-run `__post_init__`.)Ú
field_namezdict[str, Any])ÚdataclassesÚfieldsÚnameÚ_rebuildable_attributesÚtypeÚsetÚvarsÚ_NOT_CAPABILITY_STATEÚ__name__ÚjoinÚsortedr   ÚidÚcompareÚgetattrÚmerge_field_valuesr   r
   Ú__dict__)ÚcapabilitiesÚmergedÚfieldÚfield_namesÚrebuildableÚ
capabilityÚ
undeclaredÚcls_nameÚnamesÚchangesÚcurrentÚvalueÚresultÚinstance_dictr   s                  Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/capabilities/_merge.pyÚmerge_capability_fieldsr2      s­  € ðd ˜"Ñ€FÜ+6×+=Ò+=¸fÔ+EÓFÒ+E %—:”:Ñ+E€KÐFô *¬$¨v«,Ó7¸+ÑE€KÛ"ˆ
ô
 œ˜jÓ)Ó*¨[Ñ8¸;ÑFÔI^Ñ^ˆ
ßˆ:Ü˜F“|×,Ñ,ˆHØ—I‘Iœf ZÓ0Ó1ˆEÜØ  §¡¡Ð-BÀ8À*ÐL_Ð`hÐ_ið jØ�wð %à%* Gð ,*ð*óð ñ #ð$ !€GÜ×#Ò# FÖ+ˆØ�}�}ÙÜ˜&§*¡*Ó-ˆÜ"Ù?KÓLº|°ŒW�Z§¡Ö,¹|ÑLÐY^×YcÑYcñ
ˆð ÔØ"'�E—J‘JÓñ ,ö 4;Œ_˜VÑ/ wÒ/À€FÞô Ð-¨v¯©Ó?ˆØ¤# mÓ"4Ô4ˆDØÒ#ñ 5à€MùòQ Gùò8 Ms   žF0ÄF5
Ú__orig_class__c                ó°   • [        5       nU R                   H2  nUR                  S [        U5      R	                  5        5       5        M4     [        U5      $ )a¼  Attribute names the class can produce again on demand, so merging drops rather than keeps them.

A `cached_property` is the supported way to derive state from fields. It is declared on the
class, so this can find it without a list of exceptions to maintain, and discarding the cached
value is what makes the merged capability recompute against the merged fields instead of
reporting what the last instance happened to have cached.

Only names that can actually be recomputed belong here, since everything here is deleted from
the merged copy -- an attribute that is merely uninteresting to the merge goes in
`_NOT_CAPABILITY_STATE` instead, where it is exempt from the check without being destroyed.
c              3  óX   #   • U  H   u  p[        U[        5      (       d  M  Uv •  M"     g 7f©N)Ú
isinstancer   )Ú.0r   r.   s      r1   Ú	<genexpr>Ú*_rebuildable_attributes.<locals>.<genexpr>Œ   s    é € ÐgÒ-@™k˜dÄJÈuÔVe×Df—T‘TÒ-@ùs   ‚*¡	*)r   Ú__mro__Úupdater   ÚitemsÚ	frozenset)Úclsr+   Úklasss      r1   r   r   ~   sC   € ô “e€EØ—”ˆØ�‰Ñg¬T°%«[×->Ñ->Ô-@ÓgÖgñ ä�UÓÐó    c               óh  ^^• U  Vs/ s H	  o"c  M  UPM     nnU(       d  gUtmn[        U4S jU 5       5      (       a  T$ [        S U 5       5      (       a2  0 n[        SU5       H  nUR                  U5        M     [        TXQ5      $ [        S U 5       5      (       a5  [        [
           " 5       R                  " [        SU5      6 n[        TXa5      $ [        S U 5       5      (       a=  / m[        SU5       H  nTR                  U4S	 jU 5       5        M      [        TTU5      $ US
   $ s  snf )a]  Merge one field's values across the capabilities sharing an id, in application order.

`field_name` names the field in the error raised when a declared collection type cannot be
rebuilt; the merge itself does not depend on it. Required rather than defaulted, so no caller
can produce an error that leaves its reader guessing which field to look at.
Nc              3  ó<   >#   • U  H  n[        TU5      v •  M     g 7fr6   ©Ú_same_value)r8   ÚotherÚfirsts     €r1   r9   Ú%merge_field_values.<locals>.<genexpr>›   s   øé € Ð
7²$¨Œ;�u˜e×$Ð$²$ùó   ƒc              3  óB   #   • U  H  n[        U[        5      v •  M     g 7fr6   )r7   r   ©r8   r.   s     r1   r9   rH   �   s   é € Ð
:²6¨%Œ:�eœW×%Ð%²6ùó   ‚zlist[Mapping[Any, Any]]c              3  óB   #   • U  H  n[        U[        5      v •  M     g 7fr6   )r7   ÚAbstractSetrK   s     r1   r9   rH   ¢   s   é € Ð
>²v¨eŒ:�eœ[×)Ð)²vùrL   zlist[AbstractSet[Any]]c              3  óp   #   • U  H,  n[        U[        5      =(       a    [        U5      (       + v •  M.     g 7fr6   )r7   r   Ú
_is_recordrK   s     r1   r9   rH   ¥   s'   é € Ð
UÊfÀUŒ:�eœXÓ&×@¬z¸%Ó/@Ô+@Ô@Êfùs   ‚46zlist[Sequence[Any]]c              3  ób   >^#   • U  H#  m[        U4S  jT 5       5      (       a  M  Tv •  M%     g7f)c              3  ó<   >#   • U  H  n[        TU5      v •  M     g 7fr6   rD   )r8   ÚkeptÚentrys     €r1   r9   Ú/merge_field_values.<locals>.<genexpr>.<genexpr>ª   s   øé € Ð3iÒYhÐQU´KÀÀt×4LÐ4LÒYhùrI   N)Úany)r8   rT   Úmerged_sequences    @€r1   r9   rH   ©   s$   ùé € ð #Ú#(˜%´Ô3iÑYhÓ3i×0i—‘¢5ùs   „/¦	/r   )Úallr
   r<   Ú_as_declaredr   r	   ÚunionÚextend)	Úvaluesr   r.   ÚstatedÚrestÚmerged_mappingÚ
merged_setrG   rW   s	          @@r1   r!   r!   �   s   ù€ ñ "(Ó=¢˜�e¡€FÐ=ÞØØ€L€EˆDÜ
Ô
7±$Ó
7×7Ñ7ØˆÜ
Ñ
:±6Ó
:×:Ñ:Ø)+ˆÜÐ3°VÖ<ˆEØ×!Ñ! %Ö(ñ =ä˜E >Ó>Ð>Ü
Ñ
>±vÓ
>×>Ñ>Üœ’X“Z×%Ò%¤tÐ,DÀfÓ'MÐNˆ
Ü˜E :Ó:Ð:Ü
Ñ
UÉfÓ
U×UÑUà%'ˆÜÐ/°Ö8ˆEØ×"Ñ"ô #Ù#(ó#ö ñ 9ô ˜E ?°JÓ?Ð?Ø�"‰:Ðùò- >s
   ‡D/‘D/c                ó”   • [        U [        [        45      (       a  g[        U [        5      =(       a    [	        [        SU 5      S5      $ )a   Whether a value is a record that merely satisfies `Sequence`, rather than a collection.

A `str` is a sequence of characters and a `NamedTuple` a sequence of its fields, but neither is
something two capabilities are contributing *entries* to: unioning them would splice one
value's characters or columns into the other's. They take the later value, which is what the
table gives everything the merge cannot combine.
Tr	   Ú_fields)r7   ÚstrÚbytesÚtupleÚhasattrr
   )r.   s    r1   rP   rP   °   s:   € ô �%œ#œu˜×&Ñ&Øô �eœUÓ#×N¬´°U¸EÓ0BÀIÓ(NÐNrA   c                óZ  • [        U 5      [        U5      L a  U$  [        U 5      " U5      $ ! [        [        4 an  n[        SU< S[        U5      R                   S[        U 5      R                   S[        U 5      R                   S[        U 5      R                   S35      UeSnAff = f)aB  Rebuild `merged` as the collection type the field already held, or refuse.

The union is computed in a plain `dict`/`set`/`list`, which would hand a field annotated
`tuple[str, ...]` or `frozenset[str]` a value of the wrong type -- and `replace_no_init` skips
the `__post_init__` that might otherwise have caught it.

A collection type that cannot be rebuilt from its contents leaves no answer worth guessing.
Handing back the plain union gives the field a value its own annotation says it cannot hold;
handing back one instance's value drops entries the other stated, which is the one thing the
merge promises not to do. Records that only look like collections are already gone by here
(see `_is_record`), so what is left is a real collection with no way to rebuild it -- and
saying so is what the capability's author needs to hear.
z2Merging capabilities under one `id` unioned field z into a z, but its declared type zM cannot be rebuilt from that. Keeping the union would give the field a value zT does not describe, and keeping one instance would drop what the other stated. Give z‡ a constructor that takes its contents, declare the field as a plain collection type, or override `combine` to merge this field itself.N)r   Ú	TypeErrorÚ
ValueErrorr   r   )rG   r$   r   Úexcs       r1   rY   rY   ¿   sµ   € ô ˆEƒ{”d˜6“lÒ"ØˆðÜ�EŒ{˜6Ó"Ð"øÜ”zÐ"ó 	ÜØ@ÀÁÈhÜ�F‹|×$Ñ$Ð%Ð%=¼dÀ5»k×>RÑ>RÐ=Sð T&ä&*¨5£k×&:Ñ&:Ð%;ð <6Ü6:¸5³k×6JÑ6JÐ5Kð Lð	ó
ð ð	ûð	ús   ›, ¬B*¼A)B%Â%B*c                óH   • XL a  g [        X:H  5      $ ! [         a     gf = f)zTWhether two field values are interchangeable, treating an unusable `__eq__` as "no".TF)ÚboolÚ	Exception)ÚleftÚrights     r1   rE   rE   Ý   s.   € à‚}ØðÜ�D‘MÓ"Ð"øÜó áðús   ‡ ”
! !)r#   z(Sequence[AbstractCapability[AgentDepsT]]ÚreturnzAbstractCapability[AgentDepsT])r?   ztype[AbstractCapability[Any]]rp   zfrozenset[str])r\   zSequence[Any]r   rc   rp   r	   )r.   r	   rp   rl   )rG   r	   r$   r	   r   rc   rp   r	   )rn   r	   ro   r	   rp   rl   )Ú__doc__Ú
__future__r   r   Úcollections.abcr   r   r   rN   Ú	functoolsr   Útypingr   r	   r
   Úpydantic_ai._utilsr   Úpydantic_ai.exceptionsr   Úpydantic_ai.toolsr   Úabstractr   r2   r>   r   r   r!   rP   rY   rE   © rA   r1   Ú<module>r{      sz   ðñõ #ã ß AÑ AÝ %ß +Ñ +å .Ý ,Ý (æÝ,ð[Ø:ð[à#ô[ñ| "Ð#3Ð"4Ó5Ð ðôô$ô@Oôõ<rA   