ó
    °"³j‰¶  ã                  ó¤  • % 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rS SK	r	S SK
r
S SKrS SKrS SKJrJrJrJrJr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  S SKJ r J!r!J"r"J#r#  S SK$J$r$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/J0r0J1r1J2r2  S SK3r3S SK4J5r5  S SK6J7r7J8r8  S SK9J:r:J;r;  S SK<J=r=  S SK>J?r?J@r@JArAJBrB  S SKCJDrD  S SKEJFrF  S SKGJHrHJIrJ  S SKKJLrL  S SKMJNrN  SSKOJPrP  \	R¢                  S:  a  S SKRJSrS  O\SrS\HrH\+(       a  S SKTJUrUJVrV  S SKWJXrX  SSKYJZr[  SSK\J]r]  \?" S5      r^\A" S5      r_\" S \	RÀ                  S!:H  S"9raS#\bS '   \" S$SS"9rcS%\bS$'   \" S&S'S"9rdS#\bS&'   \" S(S'S"9reS#\bS('   SoS) jrfSpS* jrI\SqS+ j5       rg\SrS, j5       rh\SqS- j5       riSsS. jrjStS/ jrkSuS0 jrlSvS1 jrmSwS2 jrn\A" S35      roSxS4 jrp\! " S5 S6\-\o   5      5       rq\q\o   S-  rrS7\bS8'    SyS9 jrsSS:.SzS; jjrtSoS< jru " S= S>5      rv\v" 5       rwS{S? jrxS|S@ jry      S}SA jrzS~SB jr{SSC jr|\      S€SD j5       r}S�SE jr~S‚SF jrSƒSG jr€S„SH jr�    S…SI jr‚\GR                  " SJ5      r„ S†SK jr…SLr†S‡SM jr‡\A" SN\\,   \\o   SO9rˆ " SP SQ\-\o\ˆ4   5      r‰SˆSR jrŠS‰SS jr‹SŠST jrŒS‹SU jr�SŒSV jrŽ\8" \$5      r�S�SW jr�\SX\\o   4   r‘\2SŽSY j5       r’\2S�SZ j5       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–Sa jr˜S—Sb jr™\GR                  " Sc\GR4                  Sd9r›S˜Se jrœS™Sf jr�SšSg jržS›Sh jrŸSœSi jr S�Sj jr¡SžSk jr¢\GR                  " Sl5      r£SŸSm jr¤S Sn jr¥g)¡é    )ÚannotationsN)ÚAsyncGeneratorÚAsyncIterableÚAsyncIteratorÚ	AwaitableÚCallableÚ	GeneratorÚIterableÚIterator)ÚExecutor)ÚasynccontextmanagerÚcontextmanagerÚsuppress)Ú
ContextVarÚcopy_context)ÚMISSINGÚ	dataclassÚfieldsÚis_dataclass)ÚdatetimeÚtimezone)ÚEnum)ÚGenericAlias)ÚTYPE_CHECKINGÚAnyÚGenericÚ	TypeAliasÚ	TypeGuardÚget_argsÚ
get_originÚoverload)Úrun_sync)Ú	BaseModelÚTypeAdapter)Ú_decoratorsÚ_typing_extra)ÚJsonSchemaValue)Ú	ParamSpecÚTypeIsÚTypeVarÚis_typeddict)Útyping_objects)Úis_union_origin)ÚAbstractSpanÚrun_until_complete)ÚUnsupportedEventLoopError)Úget_callable_nameé   ©Ú	UserError©é   é   )ÚBaseExceptionGroup)ÚAgentRunÚAgentRunResult)ÚGraphRun)Úmessages)ÚObjectJsonSchemaÚ_PÚ_RÚ_disable_threadsÚ
emscripten)ÚdefaultzContextVar[bool]Ú_thread_executorzContextVar[Executor | None]Ú_in_sync_callbackFÚ_abandon_on_cancelc                 óL   • [         R                  5       (       a  [        S5      eg)uo  Reject sync agent entry points inside sync callbacks dispatched by Pydantic AI.

Sync tools, output functions, and similar callbacks are dispatched through
[`run_in_executor`][pydantic_ai._utils.run_in_executor], which flags the callback's context â€”
whether the callback runs on a worker thread or inline under [`disable_threads`][pydantic_ai._utils.disable_threads].
On a worker thread, a nested sync run starts a second event loop that can deadlock against an async
resource bound to the parent run's loop; inline, it would drive the already-running loop and fail
anyway. Either way we fail fast with guidance instead.
a#  `Agent.run_sync()` and `Agent.run_stream_sync()` cannot be used inside a synchronous tool, output function, or other function called during an agent run, as they can deadlock the run. Make the function `async def` and use `await agent.run(...)` or `async with agent.run_stream(...)` instead.N)rD   Úgetr4   © ó    ÚO/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/_utils.pyÚcheck_no_nested_sync_runrK   U   s+   € ô ×Ñ×ÑÜðzó
ð 	
ð rI   c                ój   •  [        U 5      $ ! [         a  n[        UR                  5      UeSnAff = f)a­  Run `coro` to completion on the event loop, for use by the sync wrappers.

Wraps `pydantic_graph`'s `run_until_complete()` to report an event loop that can't be driven by the caller
-- like Temporal's workflow event loop -- as a `UserError`, which is how the rest of the library reports
usage mistakes, and which durable execution integrations know to treat as a deterministic failure rather
than an infrastructure one to retry.
N)Ú_graph_run_until_completer0   r4   Úmessage)ÚcoroÚes     rJ   r/   r/   g   s3   € ð*Ü(¨Ó.Ð.øÜ$ó *Ü˜Ÿ	™	Ó"¨Ð)ûð*ús   ‚
 �
2—-­2c               #  óž   #   • [         R                  S5      n  Sv •  [         R                  U 5        g! [         R                  U 5        f = f7f)aÛ  Context manager to disable thread-based execution for sync functions.

Inside this context, sync functions will execute inline rather than
being sent to a thread pool via [`anyio.to_thread.run_sync`][anyio.to_thread.run_sync].

This is useful in environments where threading is restricted, such as
Temporal workflows which use a sandboxed event loop. On emscripten,
sync callbacks already run inline by default because Python threads are
unavailable there.

Yields:
    None
TN)r@   ÚsetÚreset©Útokens    rJ   Údisable_threadsrV   u   s<   é € ô × Ñ  Ó&€Eð&Ûä×Ñ˜uÕ%øÔ×Ñ˜uÕ%üó   ‚A™3 �A³A
Á
Ac              #  óž   #   • [         R                  U 5      n Sv •  [         R                  U5        g! [         R                  U5        f = f7f)a^  Context manager to use a custom executor for running sync functions in threads.

Inside this context, sync functions will be executed using the provided executor
via [`asyncio.get_running_loop().run_in_executor()`][asyncio.loop.run_in_executor]
instead of the default [`anyio.to_thread.run_sync`][anyio.to_thread.run_sync].

This is useful in long-running servers (e.g. FastAPI) where thread accumulation
from ephemeral anyio worker threads can be a problem, and you want to use a bounded
`ThreadPoolExecutor` instead.

Args:
    executor: The executor to use for running sync functions.

Yields:
    None
N)rC   rR   rS   )ÚexecutorrU   s     rJ   Úusing_thread_executorrZ   ‹   s<   é € ô$ × Ñ  Ó*€Eð&Ûä×Ñ˜uÕ%øÔ×Ñ˜uÕ%ürW   c               #  óž   #   • [         R                  S5      n  Sv •  [         R                  U 5        g! [         R                  U 5        f = f7f)aš  Context manager to abandon worker threads running sync functions when they're cancelled.

Inside this context, a cancellation delivered while awaiting a worker thread abandons that thread
-- it runs to completion in the background and its result is discarded -- instead of waiting for it
to finish. Outside it, [`anyio.to_thread.run_sync`][anyio.to_thread.run_sync] shields the await, so
the cancellation is only delivered once the thread returns.

This is used around calls that carry a deadline, so that [`anyio.fail_after`][anyio.fail_after] can
actually raise `TimeoutError` when a sync function overruns it, rather than only after it returns.

Yields:
    None
TN)rE   rR   rS   rT   s    rJ   Úabandon_threads_on_cancelr\   ¤   s<   é € ô ×"Ñ" 4Ó(€Eð(Ûä× Ñ  Õ'øÔ× Ñ  Õ'ürW   c              �  óh  ^ ^^#   • SUU U4S jjn[         R                  5       (       a  U" 5       $ [        R                  5       nUbC  [        R                  " 5       n[        5       nUR                  XFR                  U5      I S h  v•N $ [        U[        R                  5       S9I S h  v•N $  N( N7f)Nc                 óž   >• [         R                  S5      n  T" T0 TD6[         R                  U 5        $ ! [         R                  U 5        f = f©NT)rD   rR   rS   )rU   ÚargsÚfuncÚkwargss    €€€rJ   Úcall_with_sync_agent_guardÚ3run_in_executor.<locals>.call_with_sync_agent_guard»   sC   ø€ Ü!×%Ñ% dÓ+ˆð	+Ù˜Ð( Ñ(ä×#Ñ# EÕ*øÔ×#Ñ# EÕ*ús	   ˜5 µA)Úabandon_on_cancel)Úreturnr?   )
r@   rG   rC   ÚasyncioÚget_running_loopr   Úrun_in_executorÚrunr"   rE   )ra   r`   rb   rc   rY   ÚloopÚctxs   ```    rJ   ri   ri   º   s’   úé € ÷+ñ +ô ×Ñ×ÑÙ)Ó+Ð+ä×#Ñ#Ó%€HØÑÜ×'Ò'Ó)ˆÜ‹nˆØ×)Ñ)¨(·G±GÐ=WÓX×XÐXäÐ4ÔHZ×H^ÑH^ÓH`Ña×aÐañ Yáaùs$   …B B2ÂB.Â#B2Â)B0Â*B2Â0B2c                ó   • S[        U 5      ;   $ )Nz)asynchronous generator is already running)Ústr)Úexcs    rJ   Ú"is_async_generator_already_runningrp   Î   s   € Ø6¼#¸c»(ÑBÐBrI   c                óø   • [        U [        5      =(       ad    [        U [        5      (       + =(       aH    [        U [        5      =(       d1    [        U 5      =(       d    [        U 5      =(       d    [        U SS5      $ )z»Check if something is a pydantic model, dataclass or typedict.

These should all generate a JSON Schema with `{"type": "object"}` and therefore be usable directly as
function parameters.
Ú__is_model_like__F)Ú
isinstanceÚtyper   Ú
issubclassr#   r   r+   Úgetattr)Útype_s    rJ   Úis_model_likerx   Ò   sd   € ô 	�5œ$Ó÷ 	
Ü˜5¤,Ó/Ô/÷	
ô �uœiÓ(÷ :Ü˜EÓ"÷:ä˜EÓ"÷:ô �uÐ1°5Ó9ð	rI   c                óf  • SSK Jn  U R                  S5      S:X  a  U $ U R                  S5      =n(       au  SnUR                  U5      (       a[  U R                  S0 5      R                  U[	        U5      S  5      =n(       a'  UR                  S5      S:X  a  [        U5      (       d  U$ U $ U" S5      e)	Nr2   r3   rt   Úobjectú$refú#/$defs/ú$defszSchema must be an object)Ú
exceptionsr4   rG   Ú
startswithÚlenÚ_contains_ref)Úschemar4   ÚrefÚprefixÚresolveds        rJ   Úcheck_object_json_schemar†   ä   s£   € Ý%à‡z�z�&Ó˜XÓ%ØˆØ—
‘
˜6Ó"Ð	"ˆÕ	"Øˆð �N‰N˜6×"Ñ"Ø#ŸZ™Z¨°Ó4×8Ñ8¸¼SÀ»[¸]Ð9KÓLÐL�ÕLØ—‘˜VÓ$¨Ó0Ü! (×+Ñ+àˆOØˆáÐ2Ó3Ð3rI   c                ó„   • [        U [        5      (       a  SU ;   a  gU R                  5       nOU n[        S U 5       5      $ )z6Recursively check if an object contains any $ref keys.r{   Tc              3  ót   #   • U  H.  n[        U[        [        -  5      =(       a    [        U5      v •  M0     g 7f©N)rs   ÚdictÚlistr�   )Ú.0Úitems     rJ   Ú	<genexpr>Ú _contains_ref.<locals>.<genexpr>  s*   é € ÐWÒQVÈŒz˜$¤¤t¡Ó,×D´¸tÓ1DÔDÒQVùs   ‚68)rs   rŠ   ÚvaluesÚany)ÚobjÚitemss     rJ   r�   r�   ø   s=   € ô �#”t×ÑØ�S‹=ØØ—
‘
“‰àˆÜÑWÑQVÓWÓWÐWrI   ÚTc                óP   • U c  [        S[        U5      < S35      e[        U 5      $ )z6Validate and normalize a tool-prepare callback result.zPrepare function zg returned `None`; return `[]` to expose no tools, or return `tool_defs` to pass them through unchanged.)r4   r1   r‹   )ÚresultÚprepare_funcs     rJ   Úcheck_tools_prepare_func_resultr˜     s;   € à�~ÜØÔ 1°,Ó ?ÑBð Cdð dó
ð 	
ô �‹<ÐrI   c                  ó$   • \ rS rSr% SrS\S'   Srg)ÚSomei  z(Analogous to Rust's `Option::Some` type.r”   ÚvaluerH   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__rH   rI   rJ   rš   rš     s
   ‡ á2à†HrI   rš   r   ÚOptionc               ‡  ó&  ^
#   • [        5       nU/[        U 5      -  m
SU
4S jjn [        R                  " 5        ISh  v•N n[	        U 5       H  u  pEUR                  X$U5        M     SSS5      ISh  v•N   / nT
 H+  n	[        U	[         5      (       a   eUR                  U	5        M-     U$  No N;! , ISh  v•N  (       d  f       NP= f! [         a7  n[        UR                  5      S:X  a  UR                  S   nSUl        Uee SnAff = f7f)ak  Run awaitables concurrently via an `anyio` task group and return results in input order.

Unlike `asyncio.gather`, a failure in one coroutine cancels the rest instead of leaving them
as orphan background tasks. If exactly one task fails, its exception is re-raised directly to
match `asyncio.gather`'s shape; multi-failure cases propagate as an `ExceptionGroup`.
c              “  ó,   >#   • UI S h  v•N TU '   g  N7fr‰   rH   )ÚindexrO   Úresultss     €rJ   Ú_runÚgather.<locals>._run&  s   øé € Ø#Ÿˆ�Š™ùs   ƒ‰Š	Nr2   r   T)r¦   ÚintrO   úAwaitable[T]rf   ÚNone)ÚUnsetr€   ÚanyioÚcreate_task_groupÚ	enumerateÚ
start_soonr8   r~   Ú__suppress_context__rs   Úappend)ÚcorosÚsentinelr¨   ÚtgÚirO   Úegro   Úfinal_resultsr–   r§   s             @rJ   Úgatherrº     sé   øé € ô ‹w€HØ (˜z¬C°«JÑ6€G÷$ð	Ü×*Ò*×,Ô,°Ü$ UÖ+‘�Ø—‘˜d tÖ,ñ ,÷ -×,ð  €MÛˆÜ˜f¤e×,Ñ,Ð,Ð,Ø×Ñ˜VÖ$ñ ð Ð÷ -×,×,Ò,ûô ó Üˆr�}‰}Ó Ó"Ø—-‘- Ñ"ˆCØ'+ˆCÔ$ØˆIØûðüs{   ƒ"D¦C ¿B/Á C Á'B3Á*C Á5B1Á6C Á:5DÂ/C Â1C Â3C
Â9B<Â:C
ÃC Ã	DÃ
C Ã
DÃ2D	Ä	DÄD©Úmsgc              ‡  ó  #   • U H)  nUR                  5       (       a  M  UR                  U S9  M+     [        R                  " SS9   [        R
                  " USS06I Sh  v•N   SSS5        g N! , (       d  f       g= f7f)ak  Cancel any tasks still running and wait for them to finish unwinding.

Cleanup-only: results and exceptions from `tasks` are intentionally discarded so a
cancelled child cannot replace an exception already propagating in the caller.
Use after `asyncio.create_task` when an outer cancel/exception means the spawned
tasks must be torn down before the caller exits.
r»   T)ÚshieldÚreturn_exceptionsN)ÚdoneÚcancelr®   ÚCancelScoperg   rº   )r¼   ÚtasksÚtasks      rJ   Úcancel_and_drainrÅ   ;  sd   é € ó ˆØ�y‰y�{‹{Ø�K‰K˜CˆKÓ ñ ô 
×	Ò	 $Ó	'Ü�nŠn˜eÐ<°tÑ<×<Ð<÷ 
(Ð	'Ù<÷ 
(Õ	'üs4   ‚BŸ'BÁA0Á A.Á!A0Á%	BÁ.A0Á0
A>Á:Bc                 óÖ   • [         R                  S:  a  g [        R                  " 5       n U b+  U R                  5       S:”  a  [        R                  " S5      egg! [         a     gf = f)uÚ  Re-assert an external cancellation that a completed step absorbed (level-triggered backstop).

A step the run awaits â€” a Temporal activity under `WAIT_CANCELLATION_COMPLETED`, an
`event_stream_handler`, a capability hook â€” can catch the `CancelledError` injected by
`task.cancel()` and return normally. asyncio even *delegates* a task's cancellation to the
future it is currently awaiting, so an awaited child task that absorbs its cancel silently
completes the awaiting task too. Either way the cancellation is an edge the framework never
sees, and without a re-check the run would complete as if it was never cancelled.

Well-behaved consumers of their own cancellation, like `asyncio.timeout()` and AnyIO cancel
scopes, balance `Task.cancelling()` back down with `Task.uncancel()`, so a positive count at
a step boundary is treated as a still-pending cancellation of the run and re-raised. This is
deliberately a *policy*, not a proof of external intent: code awaited by the run that cancels
its own task as an internal wake-up and suppresses the `CancelledError` without calling
`Task.uncancel()` (a pre-3.11 idiom) will be read as a cancelled run. Call this only after
the just-completed step's results have been recorded to message history, so cancellation
never discards completed work.

The re-raise is a fresh `CancelledError`: the originally-injected exception object (and any
message it carried) was consumed by whatever absorbed it and cannot be recovered â€” the
cancellation *state* is re-asserted, not the original exception.

On Python 3.10 `Task.cancelling()` does not exist and this is a no-op: an absorbed external
cancellation cannot be reliably detected there, so the cancellation guarantee is documented
as best-effort on 3.10.
r5   Nr   zEpydantic-ai: re-asserting a cancellation absorbed by a completed step)ÚsysÚversion_inforg   Úcurrent_taskÚRuntimeErrorÚ
cancellingÚCancelledError)rÄ   s    rJ   Úraise_if_cancellingrÍ   O  sl   € ô6 ×Ñ˜'Ó!ØðÜ×#Ò#Ó%ˆð Ñ˜DŸO™OÓ-°Ó1Ü×$Ò$Ð%lÓmÐmð 2Ðøô ó áðús   —A Á
A(Á'A(c                  ó   • \ rS rSrSrSrg)r­   iu  z(A singleton to represent an unset value.rH   N)rœ   r�   rž   rŸ   r    r¢   rH   rI   rJ   r­   r­   u  s   † Ù2ârI   r­   c                ó   • U [         L$ r‰   )ÚUNSET)Ú
t_or_unsets    rJ   Úis_setrÒ   ~  s   € ØœUÐ"Ð"rI   c           
     óþ  • [        U 5      (       d   e[        U 5       Vs1 s H  o"R                  iM     nnUR                  5       U-
  =n(       a<  [	        S[        U 5      R                   SSR                  [        U5      5       35      e[        R                  " U 5      nXPL a"  [	        S[        U 5      R                   S35      eUR                  5        H  u  pg[        R                  XVU5        M     U$ s  snf )uð  Return a shallow copy of a dataclass instance with `changes` applied to its fields.

Use instead of `dataclasses.replace` on instances of subclassable dataclasses:
`replace` reconstructs through `type(obj).__init__`, which crashes for subclasses whose
custom `__init__` doesn't accept the dataclass field names
(https://github.com/pydantic/pydantic-ai/issues/6674). Copying preserves the subclass
and all of its state, and never re-runs `__init__`/`__post_init__` â€” the caller must
refresh any state it derives from the changed fields.

Not a drop-in for `replace`: fields declared `init=False` are carried over rather than
reset, so call sites that rely on `replace` resetting derived state (e.g. per-run state
isolation) must keep using `replace`.
zInvalid field name(s) for ú: ú, zCannot replace fields on z/: its `__copy__` does not return a new instance)r   r   ÚnameÚkeysÚ	TypeErrorrt   rœ   ÚjoinÚsortedÚcopyr“   rz   Ú__setattr__)r’   ÚchangesÚfÚfield_namesÚunknownÚnew_objrÖ   r›   s           rJ   Úreplace_no_initrâ   ‚  sß   € ô ˜×ÑÐÐÜ#)¨#¤;Ó/¢;˜a—6”6¡;€KÐ/Ø—,‘,“. ;Ñ.Ð.€wÕ.ÜÐ4´T¸#³Y×5GÑ5GÐ4HÈÈ4Ï9É9ÔU[Ð\cÓUdÓKeÐJfÐgÓhÐhÜ�iŠi˜‹n€GØ‚~ô Ð3´D¸³I×4FÑ4FÐ3GÐGvÐwÓxÐxØ—}‘}–‰ˆô 	×Ñ˜7¨%Ö0ñ 'ð €Nùò 0s    C:c              ƒ  ó  #   • U (       aB  U R                  S5        [        [        R                  [        5         U I Sh  v•N   SSS5        [        USS5      nUb  U" 5       I Sh  v•N   gg N-! , (       d  f       N1= f N7f)zGClean up pending task and async iterator after group_by_temporal exits.z)Cancelling group_by_temporal pending taskNÚaclose)rÁ   r   rg   rÌ   ÚStopAsyncIterationrv   )rÄ   Ú	aiteratorrä   s      rJ   Ú_cleanup_temporal_grouprç      sk   é € ö
 Ø�‰Ð?Ô@Ü”g×,Ñ,Ô.@ÕAØ�JˆJ÷ Bä�Y ¨$Ó/€FØÑÙ‹h�‰ð ñ ÷ BÕAúñ 	ùs9   ‚7B¹A/¿A-Á A/Á"BÁ&B Á'BÁ-A/Á/
A=Á9Bc              ƒ  óP   #   • [        U SS5      nUb  U" 5       I Sh  v•N   gg N7f)z9Close an async iterable if it exposes an `aclose` method.rä   N)rv   )Ústreamrä   s     rJ   Úaclose_if_supportedrê   ®  s*   é € ä3:¸6À8ÈTÓ3R€FØÑÙ‹h�‰ð Ùùs   ‚&�$ž&c              ƒ  óî   #   • / nU  H  n [        U5      I Sh  v•N   M     [        U5      S:X  a  US   eU(       a  [	        SU5      eg N0! [         a  nUR                  U5         SnAMf  SnAff = f7f)z>Close every async iterable, then propagate any close failures.Nr2   r   zErrors closing async iterables)rê   ÚBaseExceptionr³   r€   r8   )ÚstreamsÚerrorsré   Úerrors       rJ   Ú
aclose_allrð   µ  sw   é € à"$€FÛˆð	!Ü% fÓ-×-Ò-ñ ô ˆ6ƒ{�aÓØ�Q‰iˆÞÜ Ð!AÀ6ÓJÐJð ñ .øÜó 	!Ø�M‰M˜%× Ò ûð	!üs=   ‚A5‹A™A
šAž,A5Á
AÁ
A2ÁA-Á'A5Á-A2Á2A5c               óÎ   ^^^#   • Sm[        U 5      mTc	  SU4S jjnO
SUUU4S jjn U" 5       7v •  [        TT5      I Sh  v•N   g N! [        TT5      I Sh  v•N    f = f7f)au  Group items from an async iterable into lists based on time interval between them.

Effectively, this debounces the iterator.

This returns a context manager usable as an iterator so any pending tasks can be cancelled if an error occurs
during iteration.

Usage:

```python
async with group_by_temporal(yield_groups(), 0.1) as groups_iter:
    async for groups in groups_iter:
        print(groups)
```

Args:
    aiterable: The async iterable to group.
    soft_max_interval: Maximum interval over which to group items, this should avoid a trickle of items causing
        a group to never be yielded. It's a soft max in the sense that once we're over this time, we yield items
        as soon as `anext(aiter)` returns. If `None`, no grouping/debouncing is performed

Returns:
    A context manager usable as an async iterable of lists of items produced by the input async iterable.
Nc                ó:   >#   • T  S h  v•N n U /7v •  M   N
 g 7fr‰   rH   )r�   ræ   s    €rJ   Úasync_iter_groupsÚ,group_by_temporal.<locals>.async_iter_groupsæ  s   øé € Ù'÷ �dØ�f•ñ™iùs   ƒ†Š‹Ž	—™c                ó  >#   • Tb  TS:¼  d   S5       e/ n S n Uc  TnOT[         R                  " 5       U-
  -
  nTc  [        R                  " [	        T5      5      m[        R
                  " T4US9I S h  v•N u  p4U(       aK   UR                  5       R                  5       nU R                  U5        S mUc  [         R                  " 5       nOU (       a	  U 7v •  / n S nMÇ   Nj! [         a    U (       a  U 7v •  S m g f = f7f)Nr   z+soft_max_interval must be a positive number)Útimeout)
ÚtimeÚ	monotonicrg   Úcreate_taskÚanextÚwaitÚpopr–   r³   rå   )	ÚbufferÚgroup_start_timeÚ	wait_timerÀ   Ú_r�   ræ   Úsoft_max_intervalrÄ   s	         €€€rJ   ró   rô   ì  s  øé € ð %Ñ0Ð5FÈ!Ó5Kð Ø=óÐKð !ˆFØ-1ÐàØ#Ñ+à 1‘Ið !2´T·^²^Ó5EÐHXÑ5XÑ Y�Ið ‘<ô #×.Ò.¬u°YÓ/?Ó@�Dô !(§¢¨d¨W¸iÑ H×H‘�æð@Ø#Ÿx™x›z×0Ñ0Ó2˜ð Ÿ™ dÔ+Ø#˜à+Ñ3Ü/3¯~ª~Ó/?Ð,øÞà “Là�FØ'+Ð$ñO ñ Iøô .ó æ!Ø"(›LØ#˜Ùðüs6   ƒA2D Á5C Á6D ÂC" Â"?D Ã"C=Ã:D Ã<C=Ã=D )rf   zAsyncIterator[list[T]])Úaiterrç   )Ú	aiterabler  ró   ræ   rÄ   s    ` @@rJ   Úgroup_by_temporalr  Ä  sa   úé € ð: $(€DÜ�iÓ €IàÑ ÷	ð 	÷0	,ñ 0	,ðd7ÙÓ!Ó!ä% d¨IÓ6×6Ó6øÔ% d¨IÓ6×6Ò6üs3   …$A%ª
A ´A%ÁA	ÁA%ÁA"ÁAÁA"Á"A%c                óT   •  [        U 5      $ ! [         a  n[        5       UeSnAff = f)z™Get the next item from a sync iterator, raising `StopAsyncIteration` if it's exhausted.

Useful when iterating over a sync iterator in an async context.
N)ÚnextÚStopIterationrå   )ÚiteratorrP   s     rJ   Ú
sync_anextr	  $  s,   € ð
*Ü�H‹~ÐøÜó *Ü Ó"¨Ð)ûð*ús   ‚
 �
'—"¢'c                 óF   • [         R                  " [        R                  S9$ )N)Útz)r   Únowr   ÚutcrH   rI   rJ   Únow_utcr  /  s   € Ü�<Š<œ8Ÿ<™<Ñ(Ð(rI   c               ó°   • U R                   =(       d
    [        5       U l         U R                  =(       d    UU l        U R                  =(       d    UU l        g)a]  Fill in framework-tracked metadata (`timestamp`, `run_id`, `conversation_id`) that's still unset.

Producer-supplied values are preserved; only unset fields are filled in. Centralizing the field
list here means a new framework-tracked field only needs to be handled in one place, rather than
every site that materializes a message into the history.
N)Ú	timestampr  Úrun_idÚconversation_id)rN   r  r  s      rJ   Úfill_run_metadatar  3  s<   € ð  ×)Ñ)×6¬W«Y€GÔØ—^‘^×- v€G„NØ%×5Ñ5×H¸€GÕrI   c          	     óf   • U R                   U:w  a!  [        SU R                   < SU SU< S35      eg)zgRaise `UserError` if an `UploadedFile` references a different provider than the model it was passed to.z!UploadedFile with `provider_name=z` cannot be used with z". Expected `provider_name` to be `z`.N)Úprovider_namer4   )r�   ÚsystemÚmodel_type_names      rJ   Úvalidate_uploaded_file_providerr  ?  sK   € à×Ñ˜VÓ#ÜØ/°×0BÑ0BÑ/EÐE[Ð\kÐ[lð m/Ø/5©j¸ð<ó
ð 	
ð $rI   c                ó<   • U R                   =(       d
    [        5       $ )zTType guard that either returns the tool call id or generates a new one if it's None.)Útool_call_idÚgenerate_tool_call_id)Úts    rJ   Úguard_tool_call_idr  H  s   € ð �>‰>×4Ô2Ó4Ð4rI   z[^a-zA-Z0-9_-]c                ó.   • [         R                  SU 5      $ )z4Replace characters outside `[a-zA-Z0-9_-]` with `_`.r   )ÚTOOL_NAME_SANITIZERÚsub)rÖ   s    rJ   Úsanitize_tool_namer!  W  s   € ä×"Ñ" 3¨Ó-Ð-rI   Úpyd_ai_c                 óP   • [          [        R                  " 5       R                   3$ )zBGenerate a tool call id.

Ensure that the tool call id is unique.
)ÚTOOL_CALL_ID_PREFIXÚuuidÚuuid4ÚhexrH   rI   rJ   r  r  _  s!   € ô
 "Ð"¤4§:¢:£<×#3Ñ#3Ð"4Ð5Ð5rI   ÚSourceT)ÚboundrB   c                  óT   • \ rS rSrS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	rg
)ÚPeekableAsyncStreamij  zÜWraps an async iterable of type T and allows peeking at the *next* item without consuming it.

We only buffer one item at a time (the next item). Once that item is yielded, it is discarded.
This is a single-pass stream.
c                ó”   • Xl         S U l        [        U l        SU l        [
        R                  " 5       U l        [        5       U l	        g )NF)
ÚsourceÚ_source_iterrÐ   Ú_bufferÚ
_exhaustedr®   ÚLockÚ_source_lockrR   Ú_pull_scopes)Úselfr-  s     rJ   Ú__init__ÚPeekableAsyncStream.__init__q  s7   € ØŒØ59ˆÔÜ"'ˆŒØˆŒô
 "ŸJšJ›LˆÔÜ47³EˆÕrI   c              ƒ  ó’  #   • U R                   (       a  [        $ [        U R                  [        5      (       d  U R                  $ U R
                  c  [        U R                  5      U l        [        R                  " 5        nU R                  R                  U5         U R                   ISh  v•N    [        U R
                  5      I Sh  v•N U l        SSS5      ISh  v•N   U R                  U R                  R                  U5        sSSS5        $  Ng NK! [         aF    SU l         [        s sSSS5      ISh  v•N    U R                  R                  U5        sSSS5        $ f = f N‹! , ISh  v•N  (       d  f       N = f! U R                  R                  U5        f = f! , (       d  f       O= fSU l         [        $ 7f)zlReturns the next item that would be yielded without consuming it.

Returns None if the stream is exhausted.
NT)r0  rÐ   rs   r/  r­   r.  r  r-  r®   rÂ   r3  Úaddr2  rú   rå   Údiscard)r4  Úscopes     rJ   ÚpeekÚPeekableAsyncStream.peek}  sR  é € ð
 �?�?ÜˆLô ˜$Ÿ,™,¬×.Ñ.Ø—<‘<Ðð ×ÑÑ$Ü % d§k¡kÓ 2ˆDÔä×ÒÔ  EØ×Ñ×!Ñ! %Ô(ð	1Ø×,×,Ó,ð%Ü-2°4×3DÑ3DÓ-E×'E˜œ÷ -×,ð —|‘|à×!Ñ!×)Ñ)¨%Ô0÷ !Ñ ñ -á'EøÜ-ó %Ø*.˜œÜ$™÷ -×,Ñ,ð ×!Ñ!×)Ñ)¨%Ô0÷ !Ñ ð%ú÷ -×,×,Ð,ûð ×!Ñ!×)Ñ)¨%Õ0ú÷ !Õ úð ˆŒÜˆùsÌ   ‚A?GÂF)ÂF	Â.DÂ/F	Â2E/Â4DÃDÃ	DÃF	Ã!E-Ã"F	Ã1F)Ä
GÄF	ÄDÄE*Ä1E/Ä2F	Ä>EÄ?F	ÅF)Å
GÅ)E*Å*E/Å-F	Å/F	Å5E8Å6F	ÆF	Æ	F&Æ&F)Æ)
F7Æ3Gc              ƒ  óZ   #   • [        U R                  5       I Sh  v•N [        5      $  N7f)z9Returns True if the stream is exhausted, False otherwise.N)rs   r;  r­   ©r4  s    rJ   Úis_exhaustedÚ PeekableAsyncStream.is_exhaustedž  s   é € ä §	¡	£×+¬UÓ3Ð3Ñ+ùs   ‚+›)œ+c                ó   • U $ r‰   rH   r>  s    rJ   Ú	__aiter__ÚPeekableAsyncStream.__aiter__¢  s   € àˆrI   c              ƒ  ó`  #   • U R                   (       a  [        e[        U R                  [        5      (       d  U R                  n[
        U l        U$ U R                  c  [        U R                  5      U l        [        R                  " 5        nU R                  R                  U5         U R                   ISh  v•N    [        U R                  5      I Sh  v•N sSSS5      ISh  v•N   U R                  R                  U5        sSSS5        $  NW N; N-! [         a	    SU l         e f = f! , ISh  v•N  (       d  f       O= f U R                  R                  U5        O ! U R                  R                  U5        f = f SSS5        O! , (       d  f       O= fSU l         [        e7f)z˜Yields the buffered item if present, otherwise fetches the next item from the underlying source.

Raises StopAsyncIteration if the stream is exhausted.
NT)r0  rå   rs   r/  r­   rÐ   r.  r  r-  r®   rÂ   r3  r8  r2  rú   r9  )r4  r�   r:  s      rJ   Ú	__anext__ÚPeekableAsyncStream.__anext__¦  sM  é € ð
 �?�?Ü$Ð$ô ˜$Ÿ,™,¬×.Ñ.Ø—<‘<ˆDÜ ˆDŒLØˆKð ×ÑÑ$Ü % d§k¡kÓ 2ˆDÔä×ÒÔ  EØ×Ñ×!Ñ! %Ô(ð1Ø×,×,Ó,ðÜ%*¨4×+<Ñ+<Ó%=×=÷ -×,Ð,ð ×!Ñ!×)Ñ)¨%Ô0÷ !Ñ ñ -á=ñ -øô .ó Ø*.˜œØðú÷ -×,Ö,úÐ,ð ×!Ñ!×)Ñ)¨%Õ0ø�×!Ñ!×)Ñ)¨%Õ0úÐ0÷ !× Ö úð ˆŒÜ Ð ùs®   ‚BF.ÂFÂ+E&Â;DÂ<E&Â?D/ÃDÃDÃDÃE&Ã)DÃ*E&Ã.FÄ	
F.ÄE&ÄDÄE&ÄD,Ä,D/Ä/E	Ä5D8Ä6E	ÅE&Å
FÅ&FÆFÆ	F.Æ
FÆF.c              ƒ  óZ  #   • SU l         U R                   H  nUR                  5         M     U R                  b  U R                  OU R                  nU R
                   IS h  v•N   [        U5      I S h  v•N   S S S 5      IS h  v•N   g  N( N N	! , IS h  v•N  (       d  f       g = f7fr_   )r0  r3  rÁ   r.  r-  r2  rê   )r4  r:  r›   s      rJ   rä   ÚPeekableAsyncStream.acloseÈ  sy   é € ØˆŒØ×&Ô&ˆEØ�L‰LŽNñ 'à%)×%6Ñ%6Ñ%B�×!Ò!ÈÏÉˆð ×$×$Ó$Ü% eÓ,×,Ð,÷ %×$Ò$Ù,÷ %×$×$Ð$üsZ   ‚A B+Á"BÁ#B+Á&BÁ5BÁ6BÁ:B+ÂBÂB+ÂBÂB+ÂB(ÂBÂB(Â$B+)r/  r0  r3  r.  r2  r-  N)r-  r(  )rf   ú	T | Unset)rf   Úbool)rf   zAsyncIterator[T])rf   r”   ©rf   r¬   )rœ   r�   rž   rŸ   r    r5  r;  r?  rB  rE  rä   r¢   rH   rI   rJ   r+  r+  j  s'   † ñô
:ôôB4ôô !÷D-rI   r+  c                ó2   • U R                  SS9=(       d    S$ )NF)ÚrequiredÚ )Ú_traceparent©Úxs    rJ   Úget_traceparentrR  Ó  s   € Ø�>‰> 5ˆ>Ð)×/¨RÐ/rI   c                ó˜   ^ ^• SU 4S jjmUU 4S j[        T 5       5       nT R                  R                   SSR                  U5       S3$ )a§  Exclude fields with values equal to the field default.

A field is shown when its value differs from an explicit `default`. Fields that are
required or that only have a `default_factory` have no plain default to compare against
here, so they are always shown (the `default_factory` is deliberately not called: some
factories are impure, e.g. `uuid7()` or `now_utc()`, and `repr()` must stay observational).

The comparison is guarded because a value whose `__ne__`/`__bool__` does not return a plain
`bool` (e.g. a numpy array or pandas `Series`/`DataFrame`) would otherwise make `repr()`
raise `ValueError`, which breaks logging and traceback formatting of the message history.
c                óÊ   >• U R                   (       d  gU R                  [        L a  g [        [	        TU R
                  5      U R                  :g  5      $ ! [         a     gf = f)NFT)ÚreprrB   r   rJ  rv   rÖ   Ú	Exception)rÞ   r4  s    €rJ   Úinclude_fieldÚ3dataclasses_no_defaults_repr.<locals>.include_fieldä  sT   ø€ Ø�v�vØØ�9‰9œÒØð	Üœ  a§f¡fÓ-°·±Ñ:Ó;Ð;øÜó 	ñ ð	ús   ©+A Á
A"Á!A"c              3  óŽ   >#   • U  H:  nT" U5      (       d  M  UR                    S [        TUR                   5      < 3v •  M<     g7f)Ú=N)rÖ   rv   )rŒ   rÞ   rW  r4  s     €€rJ   rŽ   Ú/dataclasses_no_defaults_repr.<locals>.<genexpr>ð  s7   øé € Ð`º|¸!É}Ð]^×O_Ó5�1—6‘6�(˜!œG D¨!¯&©&Ó1Ñ4Õ5º|ùs
   ƒA˜-AÚ(rÕ   Ú))rÞ   r   rf   rJ  )r   Ú	__class__rž   rÙ   )r4  Úkv_pairsrW  s   ` @rJ   Údataclasses_no_defaults_reprr`  ×  sA   ù€ ÷
õ a¼vÀd¼|Ó`€HØ�n‰n×)Ñ)Ð*¨!¨D¯I©I°hÓ,?Ð+@ÀÐBÐBrI   c                óÈ   • [         R                  S:¼  a0  SSKn[        UR	                  XR
                  R                  S95      $ [        [        R                  " U 5      5      $ )uÔ  The annotations written on `cls` itself, without forcing lazy (PEP 649) evaluation.

On Python 3.14+ annotations are evaluated lazily, so a field referencing a class defined later in
the module must not be evaluated while the class is still being built â€” `@dataclass` defers it,
and anything inspecting a class from `__init_subclass__` has to as well. `Format.FORWARDREF`
never raises `NameError`, so an unresolvable annotation comes back as a `ForwardRef` instead.
)r6   é   r   N)Úformat)rÇ   rÈ   ÚannotationlibrŠ   Úget_annotationsÚFormatÚ
FORWARDREFÚinspect)Úclsrd  s     rJ   Úown_annotationsrj  ô  sP   € ô ×Ñ˜7Ó"Ûä�M×1Ñ1°#×>RÑ>R×>]Ñ>]Ð1Ð^Ó_Ð_Ü”×'Ò'¨Ó,Ó-Ð-rI   c                ól  • [        U 5      R                  5        H—  n[        R                  " [	        U5      5      (       d  [        R                  " U5      (       a  MD  [        U[        5      (       a  UO[        USS5      nUb,  [        R                  " SUR                  5       5      (       a  M—    g   g)a  Whether `@dataclass` would give `cls` fields of its own, i.e. it annotates a non-`ClassVar` name.

Annotations are inspected without being evaluated (see [`own_annotations`][]), so a `ClassVar`
that can't be resolved yet is still recognized from the way it was written.
Ú__forward_arg__Nz^(typing\.)?ClassVar\bTF)rj  r�   r,   Úis_classvarr    rs   rn   rv   ÚreÚmatchÚstrip)ri  Ú
annotationÚtexts      rJ   Údeclares_dataclass_fieldsrs    sŒ   € ô & cÓ*×1Ñ1Ö3ˆ
Ü×%Ò%¤j°Ó&<×=Ñ=Ä×A[ÒA[Ð\f×AgÑAgÙä'¨
´C×8Ñ8‰z¼gÀjÐRcÐeiÓ>jˆØÑ¤§¢Ð)BÀDÇJÁJÃL× QÑ QÙÙñ 4ð rI   c                ó®   • [        U 5       Vs0 s H"  o3R                  [        XR                  5      _M$     nnUR                  U5        U" S0 UD6$ s  snf )u~  Shared utility for typed-part narrowers â€” preserves base fields when promoting to a typed subclass.

Construct a new dataclass instance from `src`'s fields, overriding selected ones.
Lets typed-part narrowers stay maintainable when fields are added to the base
class â€” base-class field changes flow through automatically instead of needing
every narrower to be updated by hand.
rH   )r   rÖ   rv   Úupdate)ÚsrcÚdst_clsÚ	overridesrÞ   Úfield_valuess        rJ   Úcopy_dataclass_fieldsrz    sQ   € ô KQÐQTÌ+Ó#VÊ+ÀQ§F¡F¬G°C¿¹Ó,@Ò$@É+€LÐ#VØ×Ñ˜	Ô"ÙÑ"�\Ñ"Ð"ùò $Ws   Ž)Ac                ó,   • [         R                  U 5      $ r‰   )Ú_datetime_taÚvalidate_pythonrP  s    rJ   Únumber_to_datetimer~  $  s   € Ü×'Ñ'¨Ó*Ð*rI   .c                ó   • g r‰   rH   ©r’   s    rJ   Úis_async_callabler�  +  s   € ØRUrI   c                ó   • g r‰   rH   r€  s    rJ   r�  r�  /  s   € ØCFrI   c                ó8  • [        U [        R                  5      (       a-  U R                  n [        U [        R                  5      (       a  M-  [        R
                  " U 5      =(       d2    [        U 5      =(       a     [        R
                  " U R                  5      $ )zÀCorrectly check if a callable is async.

This function was copied from Starlette:
https://github.com/encode/starlette/blob/78da9b9e218ab289117df7d62aee200ed4c59617/starlette/_utils.py#L36-L40
)rs   Ú	functoolsÚpartialra   rh  ÚiscoroutinefunctionÚcallableÚ__call__r€  s    rJ   r�  r�  3  sh   € ô �Sœ)×+Ñ+×
,Ñ
,Ø�h‰hˆô �Sœ)×+Ñ+×
,Ó
,ô ×&Ò& sÓ+×l´¸³×0kÄ'×B]ÒB]Ð^a×^jÑ^jÓBkÐlrI   c              ƒ  ó\   #   • [         R                  " U 5      (       a
  U I Sh  v•N $ U $  N7f)aæ  Await `value` if it is awaitable, otherwise return it unchanged.

Use this to resolve the result of calling a callback typed as `X | Awaitable[X]`, regardless of
how the awaitable is produced: an `async def`, or a plain `def` / callable object that *returns*
a coroutine. [`is_async_callable`][pydantic_ai._utils.is_async_callable] can't detect the latter
because it inspects the callable rather than its result, so dispatching on it alone drops such a
callback's coroutine un-awaited.
N)rh  Úisawaitable)r›   s    rJ   Úawait_mayber‹  ?  s*   é € ô ×Ò˜5×!Ñ!Ø�{ÐØ€Lñ ùs   ‚!,£*¤,c                óZ   • SSK Jn  [        U 5      nUc  gX!L =(       d    [        U5      UL $ )a,  Check if a callable takes a `RunContext` as its first argument.

Args:
    callable_obj: The callable to check.

Returns:
    `True` if the callable takes a `RunContext` as first argument, `False` otherwise.

Raises:
    UserError: If the callable has annotations that cannot be resolved at runtime.
r2   )Ú
RunContextF)Ú_run_contextr�  Úget_first_param_typer    )Úcallable_objr�  Úfirst_param_types      rJ   Útakes_run_contextr’  M  s4   € õ )ä+¨LÓ9ÐØÑØØÐ)×W¬ZÐ8HÓ-IÈZÐ-WÐWrI   c                ól  •  [         R                  " U 5      n [        [	        UR
                  R                  5       5      5      nU n[        U 5      n[        U [        R                  5      (       d2  [        [        U 5      SS5      nUb  Un[        U 5      R                  nOg [        R                   " [        R"                  " U5      5      nUR-                  U5      $ ! [         a     gf = f! [         a     gf = f! [$         a  n['        SU< SU S35      UeSnAf[(        [*        4 a     gf = f)aç  Get the type annotation of the first parameter of a callable.

Handles regular functions, methods, and callable classes with __call__.
Uses Pydantic internals to properly resolve type hints including forward references.

Args:
    callable_obj: The callable to inspect.

Returns:
    The type annotation of the first parameter, or None if the callable has no introspectable
        annotations.

Raises:
    UserError: If the callable has annotations that cannot be resolved at runtime.
Nrˆ  z*Unable to resolve the type annotations of rÔ   a6  . This typically happens when a type is imported inside an `if TYPE_CHECKING:` block in a module that uses `from __future__ import annotations`. Pydantic AI resolves these annotations at runtime to determine how to call the function, so every type used in its signature needs to be imported at runtime as well.)rh  Ú	signatureÚ
ValueErrorr  ÚiterÚ
parametersr×   r  r1   rs   r%   Ú_function_likerv   rt   rœ   r&   Úget_function_type_hintsÚunwrap_wrapped_functionÚ	NameErrorr4   rØ   ÚAttributeErrorrG   )r�  ÚsigÚfirst_param_nameÚcallable_for_hintsrÖ   Ú	call_funcÚ
type_hintsrP   s           rJ   r�  r�  a  s<  € ð Ü×Ò Ó-ˆðÜ¤ S§^¡^×%8Ñ%8Ó%:Ó ;Ó<Ðð
 &ÐÜ˜\Ó*€DÜ�l¤K×$>Ñ$>×?Ñ?ÜœD Ó.°
¸DÓAˆ	ØÑ Ø!*Ðä˜Ó%×.Ñ.‰DàðÜ"×:Ò:¼;×;^Ò;^Ð_qÓ;rÓsˆ
ð �>‰>Ð*Ó+Ð+øôG ó Ùðûô
 ó Ùðûô" ó 	ô Ø8¸¹ÀÀ1À#ð F[ð [ó
ð ð	ûô ”~Ð&ó Ùðús@   ‚C ™,C/ Â$*C? Ã
C,Ã+C,Ã/
C<Ã;C<Ã?
D3Ä	DÄD3Ä2D3c                ó.   • [         R                  " U 5      $ )zÀResolve type hints for a function, including forward references.

Wraps `pydantic._internal._typing_extra.get_function_type_hints` so callers
don't need to import Pydantic internals directly.
)r&   r™  )ra   s    rJ   r™  r™  ™  s   € ô ×0Ò0°Ó6Ð6rI   c                ó‚  • SU ;   a9  U S   nUR                  S5      (       a  USS nUR                  X35      nSU 3U S'   SU ;   a'  U S   nUR                  5        H  n[        Xa5        M     SU ;   a(  [	        U S   [
        5      (       a  U S   n[        Xq5        SU ;   a  U S   nU H  n	[        X‘5        M     SU ;   a(  [	        U S   [
        5      (       a  U S   n
[        X¡5        S	 H"  nX°;   d  M
  X   nU H  n	[        X‘5        M     M$     S
U ;   a*  [	        U S
   [
        5      (       a  U S
   n[        XÑ5        ggg)z@Update $refs in a schema to use the new names from name_mapping.r{   r|   é   NÚ
propertiesr“   ÚprefixItemsÚadditionalProperties)ÚanyOfÚoneOfÚallOfÚnot)r   rG   r�   Ú_update_mapped_json_schema_refsrs   rŠ   )ÚsÚname_mappingrƒ   Úoriginal_nameÚnew_nameÚpropsÚpropr“   Úprefix_itemsr�   Úadditional_propsÚkeywordÚkeyword_itemsÚ
not_schemas                 rJ   r¬  r¬  ¢  sQ  € à�ƒ{Ø�‰iˆØ�>‰>˜*×%Ñ%Ø  ˜GˆMØ#×'Ñ'¨ÓEˆHØ" 8 *Ð-ˆAˆf‰Ið �qÓØ+,¨\©?ˆØ—L‘L–NˆDÜ+¨DÖ?ñ #ð �!ƒ|œ
 1 W¡:¬t×4Ñ4Ø ! '¡
ˆÜ'¨Ô<Ø˜ÓØ-.¨}Ñ-=ˆÛ ˆDÜ+¨DÖ?ñ !ð  Ó"¤z°!Ð4JÑ2KÌT×'RÑ'RØ+,Ð-CÑ+DÐÜ'Ð(8ÔGó /ˆØ�<Ø23±*ˆMÛ%�Ü/°ÖCó &ñ /ð �ƒz”j  5¡¬4×0Ñ0Ø%& u¡Xˆ
Ü'¨
ÕAð 1€zrI   c                óŽ   • U nUR                  S5      =n(       a  U SU  3nSnUnU SU 3nX2;   a  US-  nU SU 3nX2;   a  M  U$ )zXGenerate a unique definition name by appending the schema title and/or a numeric suffix.Útitler   r2   )rG   )rÖ   r‚   Úall_defsr°  r¹  r·   Úoriginal_new_names          rJ   Ú_unique_def_namer¼  Ì  su   € à€HØ—
‘
˜7Ó#Ð#€uÕ#Ø�W˜A˜d˜VÐ$ˆà	€AØ ÐØ�˜1˜Q˜CÐ €HØ
Ó
Ø	ˆQ‰ˆØ'Ð(¨¨!¨Ð-ˆð Õ
ð €OrI   c                óš  • 0 n/ nU  GH>  nSU;  a  UR                  U5        M  UR                  5       nUR                  SS5      n0 nUR                  5        H2  u  pgXa;  a
  XqU'   XeU'   M  XqU   :w  d  M  [	        XcU5      XV'   XqXV   '   M4     SnU(       am  SnUR                  5        HN  u  pgXe;  d  M  [        R
                  " U5      n	[        X•5        X—:w  a  [	        XcU5      XV'   X‘XV   '   SnMJ  XeU'   MP     U(       a  Mm  UR                  5        H  n
[        X   U5        M     [        X55        UR                  U5        GMA     X!4$ )a  Merges the `$defs` from different JSON schemas into a single deduplicated `$defs`, handling name collisions of `$defs` that are not the same, and rewrites `$ref`s to point to the new `$defs`.

Returns a tuple of the rewritten schemas and a dictionary of the new `$defs`.
r}   NTF)r³   rÛ   rü   r“   r¼  Údeepcopyr¬  r�   )Úschemasrº  Úrewritten_schemasr‚   ÚdefsÚschema_name_mappingrÖ   Ú
def_schemaÚchangedÚupdatedr°  s              rJ   Úmerge_json_schema_defsrÆ  Û  s`  € ð
 +-€HØ.0ÐäˆØ˜&Ó Ø×$Ñ$ VÔ,Ùà—‘“ˆØ�z‰z˜' 4Ó(ˆØ.0Ðð !%§
¡
¦ÑˆDØÓ#Ø!+˜‘Ø,0 DÓ)Ø¨™~Õ-ä,<¸TÈ8Ó,TÐ#Ñ)Ø6@Ð,Ñ2Ó3ñ !-ð" ˆÞØˆGØ$(§J¡J¦LÑ �ØÕ2Ü"Ÿmšm¨JÓ7�GÜ3°GÔQØÓ,Ü4DÀTÐS[Ó4\Ð+Ñ1Ø>EÐ!4Ñ!:Ñ;Ø"&šà48¨DÓ1ñ %1÷ ˆgð ,×2Ñ2Ö4ˆHÜ+¨HÑ,>Ð@SÖTñ 5ô 	(¨ÔDØ× Ñ  ×(ñ_ ðb Ð&Ð&rI   z,```(?:\w+)?\r?\n(\{.*?\})\s*(?:\r?\n?```|\Z))Úflagsc                óœ   • U R                  S5      (       a  U $ [        R                  " [        U 5      nU(       a  UR	                  S5      $ U $ )NÚ{r2   )r   rn  ÚsearchÚ_MARKDOWN_FENCES_PATTERNÚgroup)rr  ro  s     rJ   Ústrip_markdown_fencesrÍ    s=   € Ø‡��s×ÑØˆä�IŠIÔ.°Ó5€EÞØ�{‰{˜1‹~Ðà€KrI   c                óº   • [        U 5      n[        R                  " U5      (       a4  U R                  n [        U 5      n[        R                  " U5      (       a  M4  U $ r‰   )r    r,   Úis_annotatedÚ
__origin__©ÚtpÚorigins     rJ   Ú_unwrap_annotatedrÔ  %  sH   € Ü˜‹^€FÜ
×
%Ò
% f×
-Ñ
-Ø�]‰]ˆÜ˜B“ˆô ×
%Ò
% f×
-Ó
-ð €IrI   c                óÔ   • [         R                  " U 5      (       a  U R                  n [        U 5      n [	        U 5      n[        U5      (       a  [        S [        U 5       5       5      $ g)zZExtract the arguments of a Union type if `tp` is a union, otherwise return an empty tuple.c              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr‰   )rÔ  )rŒ   Úargs     rJ   rŽ   Ú!get_union_args.<locals>.<genexpr>5  s   é € ÐD²|°Ô& s×+Ð+²|ùs   ‚rH   )r,   Úis_typealiastypeÚ	__value__rÔ  r    r-   Útupler   rÑ  s     rJ   Úget_union_argsrÜ  -  sR   € ä×&Ò& r×*Ñ*Ø�\‰\ˆä	˜2Ó	€BÜ˜‹^€FÜ�v×ÑÜÑD´xÀ´|ÓDÓDÐDàrI   c                 óÜ   •  [         R                  " 5       n U b  U R                  5       (       a+  [         R                  " 5       n [         R
                  " U 5        U $ ! [         a    S n  NSf = fr‰   )rg   Úget_event_looprÊ   Ú	is_closedÚnew_event_loopÚset_event_loop)Ú
event_loops    rJ   rÞ  rÞ  :  sc   € ðÜ×+Ò+Ó-ˆ
ð Ñ˜Z×1Ñ1×3Ñ3Ü×+Ò+Ó-ˆ
Ü×Ò˜zÔ*ØÐøô ó ØŠ
ðús   ‚A ÁA+Á*A+c                ó"   • [        U [        5      $ )z?Check if obj is a dict, narrowing the type to `dict[str, Any]`.)rs   rŠ   r€  s    rJ   Úis_str_dicträ  F  s   € ä�cœ4Ó Ð rI   c                óÌ   • U R                  S5      =(       dM    U S:H  =(       dA    U R                  S5      =(       d)    U S:H  =(       d    U R                  S5      =(       d    U S;   $ )z‡Check if a media type represents text-like content.

Returns True for `text/*`, JSON, XML, YAML, and their structured syntax suffixes.
ztext/zapplication/jsonz+jsonzapplication/xmlz+xml)zapplication/x-yamlzapplication/yaml)r   Úendswith)Ú
media_types    rJ   Úis_text_like_media_typerè  K  sr   € ð 	×Ñ˜gÓ&÷ 	DØÐ+Ñ+÷	Dà×Ñ˜wÓ'÷	Dð Ð*Ñ*÷	Dð ×Ñ˜vÓ&÷		Dð
 ÐCÑCðrI   c               ó@   • SR                  SU SU S3U SU S3/5      $ )zIFormat text file content with delimiters for inlining into a text prompt.Ú
z-----BEGIN FILE id="z" type="z"-----z-----END FILE id=")rÙ   )rr  rç  Ú
identifiers      rJ   Úformat_inlined_text_filerì  Z  s9   € à�9‰9à" : ,¨h°z°lÀ&ÐIØØ   ¨FÐ3ð	
óð rI   z	[\s",.:]+c                óZ   • [        [        R                  U R                  5       5      5      $ )a  Roughly estimate the number of tokens in a string by splitting on whitespace and punctuation.

Shared by the test models, which report a plausible usage count without pulling in a tokenizer.
Blank text counts as one token, so a caller that wants zero for it guards the call itself.
)r€   Ú_TOKEN_SPLIT_PATTERNÚsplitrp  )rr  s    rJ   Úestimate_string_tokensrð  h  s!   € ô Ô#×)Ñ)¨$¯*©*«,Ó7Ó8Ð8rI   c                ó4  •  [         R                  " U 5      n[        R
                  " [        R                  " U5      5      R                  S   n[        U[        R                  5      (       d  0 $ 0 n[        UR                  UR                  SS 5       GHa  u  pE[        U[        R                  5      (       aR  [        UR                  [        R                  5      (       a)  [        UR                  R                  [        5      (       d  My  [        U[        R                   5      (       a  UR"                  nO/[        U[        R$                  5      (       a  UR&                  /nOMÔ  U Vs/ s HL  n[        U[        R(                  5      (       d  M$  UR*                  U R,                  ;   d  M@  UR*                  PMN     sn H/  n[         R.                  " UR                  R                  5      X8'   M1     GMd     U$ ! [        [        4 a    0 s $ f = fs  snf )aV  The docstring under each member of an `Enum`, by member name.

Pydantic reads a docstring under a model field with `use_attribute_docstrings`, but not one under an enum
member; this does the same for enums, so each option can be described where it is declared. Empty when the
source is not available, such as for a class defined in the REPL.
r   r2   N)rh  Ú	getsourceÚOSErrorrØ   ÚastÚparseÚtextwrapÚdedentÚbodyrs   ÚClassDefÚzipÚExprr›   ÚConstantrn   ÚAssignÚtargetsÚ	AnnAssignÚtargetÚNameÚidÚ__members__Úcleandoc)	ri  r-  Ú	class_defÚ
docstringsÚpreviousÚnoderþ  r   rÖ   s	            rJ   Úenum_member_docstringsr	  q  sƒ  € ðÜ×"Ò" 3Ó'ˆô —	’	œ(Ÿ/š/¨&Ó1Ó2×7Ñ7¸Ñ:€IÜ�i¤§¡×.Ñ.Øˆ	Ø!#€JÜ˜iŸn™n¨i¯n©n¸Q¸RÐ.@×A‰ˆä�tœSŸX™X×&Ñ&¬:°d·j±jÄ#Ç,Á,×+OÑ+OÔT^Ð_c×_iÑ_i×_oÑ_oÔqt×TuÑTuáô �h¤§
¡
×+Ñ+Ø×&Ñ&‰GÜ˜¤#§-¡-×0Ñ0Ø—‘Ð'‰GáÙ-4ÓvªW 6¼
À6Ì3Ï8É8×8T“YÐY_×YbÑYbÐfi×fuÑfuÑYu“Y�V—Y”Y©WÔvˆDÜ&×/Ò/°·
±
×0@Ñ0@ÓAˆJÓô wñ Bð Ðøô+ ”YÐó ØŠ	ðüò& ws#   ‚G= Å-#HÆHÆ0HÇ=HÈHrK  )rO   zAwaitable[_R]rf   r?   )rf   úGenerator[None])rY   r   rf   r
  )ra   zCallable[_P, _R]r`   z_P.argsrb   z	_P.kwargsrf   r?   )ro   rÊ   rf   rJ  )rw   r   rf   rJ  )r‚   r'   rf   r=   )r’   z'JsonSchemaValue | list[JsonSchemaValue]rf   rJ  )r–   zIterable[T] | Noner—   r   rf   úlist[T])r´   r«   rf   r  )rÃ   zasyncio.Task[Any]r¼   rz   rf   r¬   )rÑ   rI  rf   zTypeGuard[T])r’   r”   rÝ   r   rf   r”   )rÄ   zasyncio.Task[Any] | Noneræ   zAsyncIterator[Any]rf   r¬   )ré   zAsyncIterable[Any]rf   r¬   )rí   zIterable[AsyncIterable[Any]]rf   r¬   )r  zAsyncIterable[T]r  zfloat | Nonerf   z&AsyncGenerator[AsyncIterable[list[T]]])r  zIterator[T]rf   r”   )rf   r   )rN   z_messages.ModelMessager  ú
str | Noner  r  rf   r¬   )r�   z_messages.UploadedFiler  rn   r  rn   rf   r¬   )r  z�_messages.ToolCallPart | _messages.ToolReturnPart | _messages.RetryPromptPart | _messages.NativeToolCallPart | _messages.NativeToolReturnPartrf   rn   )rÖ   rn   rf   rn   )rf   rn   )rQ  z3AgentRun | AgentRunResult | GraphRun[Any, Any, Any]rf   rn   )r4  r   rf   rn   )ri  rt   rf   údict[str, Any])ri  rt   rf   rJ  )rv  r   rw  rt   rx  r   rf   r   )rQ  zint | floatrf   r   )r’   zAwaitableCallable[T]rf   zTypeIs[AwaitableCallable[T]])r’   r   rf   zTypeIs[AwaitableCallable[Any]])r’   r   rf   r   )r›   zT | Awaitable[T]rf   r”   )r�  úCallable[..., Any]rf   rJ  )r�  r  rf   z
Any | None)ra   r   rf   r  )r­  r  r®  údict[str, str]rf   r¬   )rÖ   rn   r‚   r  rº  zdict[str, dict[str, Any]]rf   rn   )r¿  zlist[dict[str, Any]]rf   z6tuple[list[dict[str, Any]], dict[str, dict[str, Any]]])rr  rn   rf   rn   )rÒ  r   rf   r   )rÒ  r   rf   ztuple[Any, ...])rf   zasyncio.AbstractEventLoop)r’   r   rf   zTypeGuard[dict[str, Any]])rç  rn   rf   rJ  )rr  rn   rç  rn   rë  rn   rf   rn   )rr  rn   rf   rª   )ri  z
type[Enum]rf   r  )¦Ú
__future__r   Ú_annotationsrô  rg   rÛ   r„  rh  rn  rÇ   rö  r÷   r%  Úcollections.abcr   r   r   r   r   r	   r
   r   Úconcurrent.futuresr   Ú
contextlibr   r   r   Úcontextvarsr   r   Údataclassesr   r   r   r   r   r   Úenumr   Útypesr   Útypingr   r   r   r   r   r   r    r!   r®   Úanyio.to_threadr"   Úpydanticr#   r$   Úpydantic._internalr%   r&   Úpydantic.json_schemar'   Útyping_extensionsr(   r)   r*   r+   Útyping_inspectionr,   Útyping_inspection.introspectionr-   Úpydantic_graph._utilsr.   r/   rM   Úpydantic_graph.exceptionsr0   Úpydantic_graph.utilr1   r~   r4   rÈ   Úexceptiongroupr8   Úpydantic_ai.agentr9   r:   Úpydantic_graphr;   rN  r<   Ú	_messagesÚtoolsr=   r>   r?   Úplatformr@   r¡   rC   rD   rE   rK   rV   rZ   r\   ri   rp   rx   r†   r�   r”   r˜   rš   r£   rº   rÅ   rÍ   r­   rÐ   rÒ   râ   rç   rê   rð   r  r	  r  r  r  r  Úcompiler  r!  r$  r  r(  r+  rR  r`  rj  rs  rz  r|  r~  ÚAwaitableCallabler�  r‹  r’  r�  r™  r¬  r¼  rÆ  ÚDOTALLrË  rÍ  rÔ  rÜ  rÞ  rä  rè  rì  rî  rð  r	  rH   rI   rJ   Ú<module>r-     sÒ  ðÞ 2ã 
Û Û Û Û Û 	Û 
Û Û Û ÷	÷ 	ó 	õ (ß DÑ Dß 0ß @Ó @ß 'Ý Ý ÷	÷ 	ó 	ó Ý $ß +ß 9Ý 0ß FÓ FÝ ,Ý ;÷õ @Ý 1å !à×Ñ�gÓÞGà+Ðà€æß:Ý'å'Ý'áˆtƒ_€ÙˆTƒ]€á%/Ð0BÈCÏLÉLÐ\hÑLhÑ%iÐ Ð"Ó iÙ0:Ð;MÐW[Ñ0\Ð Ð-Ó \Ù&0Ð1DÈeÑ&TÐ Ð#Ó Tñ (2Ð2FÐPUÑ'VÐ Ð$Ó Vô
ô$*ð ó&ó ð&ð* ó&ó ð&ð0 ó(ó ð(ô*bô(Côô$4ô(	Xñ ˆCƒL€ôð ôˆ7�1‰:ó ó ðð ˜‘G˜d‘N€ˆ	Ó "Ø fôð> EI÷ =ô(#n÷L	ñ 	ñ 	‹€ô#ôð<Ø
"ðà!ðð 
ôôôKð ð\7Øð\7Ø4@ð\7à+ó\7ó ð\7ô~*ô)ô	Iô
ð5ð%ð5ð 	ô5ð —j“jÐ!2Ó3Ð Ø Lô.ð
  Ð ô6ñ �) =°Ñ#5¸}ÈQÑ?OÑ
P€ôf-˜' ! W *Ñ-ô f-ôR0ôCô:.ôô"
#ñ ˜8Ó$€ô+ð ˜S )¨A¡,Ð.Ñ/Ð ð 
Û Uó 
Ø Uð 
Û Fó 
Ø Fô	môôXô(5,ôp7ô'BôTô9'ðx Ÿ:›:Ð&UÐ]_×]fÒ]fÑgÐ ôôô
ô	ô!ô
ôð —z“z ,Ó/Ð ô9õrI   