ó
    °"³j©g  ã                  óð  • S SK Jr  S SKrS SKrS SKJrJr  S SKJrJ	r	  S SK
Jr  S SKJrJr  S SKrS SKJr  SS	KJrJrJr  \R*                  S
:  a  S SKJr  O\r\(       a  SSKJrJrJrJr  SSKJr  Sr " S S\ 5      r! " S S\ 5      r" " S S\ 5      r# " S S\ 5      r$ " S S\ 5      r% " S S\ 5      r& " S S\ 5      r' " S S\(5      r) " S S \)5      r* " S! S"\(5      r+S#r, " S$ S%\+5      r- " S& S'\+5      r. " S( S)\+5      r/ " S* S+\+5      r0 " S, S-\+5      r1 " S. S/\15      r2 " S0 S1\+5      r3 " S2 S3\35      r4 " S4 S5\\   5      r5 " S6 S7\ 5      r6 " S8 S9\ 5      r7 " S: S;\15      r8 " S< S=\95      r:g)>é    )ÚannotationsN)ÚMappingÚSequence)ÚdatetimeÚtimezone)Úparsedate_to_datetime)ÚTYPE_CHECKINGÚAny)Úcore_schemaé   )ÚCostCalculationFailedWarningÚCostNotFoundWarningÚPydanticAIDeprecationWarning)é   é   )ÚExceptionGroup)ÚModelMessageÚModelResponseÚRetryPromptPartÚToolReturnPart©ÚRunUsage)Ú
ModelRetryÚCallDeferredÚApprovalRequiredÚSkipModelRequestÚSkipToolValidationÚSkipToolExecutionÚ	UserErrorÚUndrainedPendingMessagesErrorÚAgentRunErrorÚRunCancelledÚSuspendedResponseExpiredÚUnexpectedModelBehaviorÚUsageLimitExceededÚConcurrencyLimitExceededÚModelAPIErrorÚModelHTTPErrorÚContentFilterErrorÚIncompleteToolCallÚMessageHistoryMutatedWarningr   r   r   ÚFallbackExceptionGroupÚ
ToolFailedc                  óf   ^ • \ rS rSr% SrS\S'    S
U 4S jjrSS jrSS jr\	SS j5       r
S	rU =r$ )r   é9   as  Exception to raise to request a model retry.

Can be raised from tool functions, output validators, and capability hooks
(such as `after_model_request`, `after_tool_execute`, etc.) to send
a retry prompt back to the model asking it to try again.

For a terminal failure the model should see but not retry, raise
[`ToolFailed`][pydantic_ai.exceptions.ToolFailed] instead.
ÚstrÚmessagec                ó0   >• Xl         [        TU ]	  U5        g ©N©r1   ÚsuperÚ__init__©Úselfr1   Ú	__class__s     €ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pydantic_ai/exceptions.pyr6   ÚModelRetry.__init__G   ó   ø€ ØŒÜ‰Ñ˜Õ!ó    c                ól   • [        XR                  5      =(       a    UR                  U R                  :H  $ r3   ©Ú
isinstancer9   r1   ©r8   Úothers     r:   Ú__eq__ÚModelRetry.__eq__K   ó#   € Ü˜%§¡Ó0×R°U·]±]ÀdÇlÁlÑ5RÐRr=   c                óD   • [        U R                  U R                  45      $ r3   ©Úhashr9   r1   ©r8   s    r:   Ú__hash__ÚModelRetry.__hash__N   ó   € Ü�T—^‘^ T§\¡\Ð2Ó3Ð3r=   c           	     ó*  • [         R                  " [         R                  " [         R                  " 5       5      [         R                  " [         R                  " S/5      5      S.5      n[         R
                  " S U[         R                  " S US9S9$ )z@Pydantic core schema to allow `ModelRetry` to be (de)serialized.úmodel-retry©r1   Úkindc                ó   • [        U S   5      $ ©Nr1   )r   )Údcts    r:   Ú<lambda>Ú9ModelRetry.__get_pydantic_core_schema__.<locals>.<lambda>[   s   € œ
 3 y¡>Ô2r=   c                ó    • U R                   SS.$ )NrN   rO   ©r1   ©Úxs    r:   rT   rU   ^   ó   €  a§i¡i¸ÒGr=   ©Úreturn_schema)Úserialization)r   Útyped_dict_schemaÚtyped_dict_fieldÚ
str_schemaÚliteral_schemaÚ no_info_after_validator_functionÚ$plain_serializer_function_ser_schema)ÚclsÚ_Ú__Úschemas       r:   Ú__get_pydantic_core_schema__Ú'ModelRetry.__get_pydantic_core_schema__Q   s|   € ô ×.Ò.ä&×7Ò7¼×8NÒ8NÓ8PÓQÜ#×4Ò4´[×5OÒ5OÐQ^ÐP_Ó5`Óañó
ˆô ×;Ò;Ù2ØÜ%×JÒJÙGØ$ññ
ð 	
r=   rW   ©r1   r0   )rB   r
   ÚreturnÚbool©rk   Úint©re   r
   rf   r
   rk   zcore_schema.CoreSchema©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r6   rC   rJ   Úclassmethodrh   Ú__static_attributes__Ú__classcell__©r9   s   @r:   r   r   9   s6   ø‡ ñð ƒLØ-÷"ôSô4ð ó
ó ö
r=   r   c                  óf   ^ • \ rS rSr% SrS\S'    S
U 4S jjrSS jrSS jr\	SS j5       r
S	rU =r$ )r-   éd   uÁ  Exception to raise to report a terminal tool failure to the model.

Raise this when a tool call is done and has failed â€” a missing resource, an unsupported
operation, a definitive upstream error â€” and you want the model to see the failure
and adapt rather than try the same call again. Can be raised from tool functions, args
validators, and tool validation/execution hooks.

Like [`ModelRetry`][pydantic_ai.exceptions.ModelRetry], this produces a failed tool result the
model sees; unlike `ModelRetry` it does not prepend retry/correction instructions and does not
consume the tool's retry budget. Bound repeated failures with
[`UsageLimits`][pydantic_ai.usage.UsageLimits] at the run level instead.
r0   r1   c                ó0   >• Xl         [        TU ]	  U5        g r3   r4   r7   s     €r:   r6   ÚToolFailed.__init__u   r<   r=   c                ól   • [        XR                  5      =(       a    UR                  U R                  :H  $ r3   r?   rA   s     r:   rC   ÚToolFailed.__eq__y   rE   r=   c                óD   • [        U R                  U R                  45      $ r3   rG   rI   s    r:   rJ   ÚToolFailed.__hash__|   rL   r=   c           	     ó´  ^ • [         R                  " [         R                  " [         R                  " 5       5      [         R                  " [         R                  " S/5      5      S.5      n[         R
                  " U 4S jU5      n[         R                  " U[         R                  " [         R                  " T 5      U/5      [         R                  " S US9S9$ )z@Pydantic core schema to allow `ToolFailed` to be (de)serialized.útool-failedrO   c                ó   >• T" U S   5      $ rR   © )rS   rd   s    €r:   rT   Ú9ToolFailed.__get_pydantic_core_schema__.<locals>.<lambda>‰   s   ø€ ™˜C 	™NÔ+r=   c                ó    • U R                   SS.$ )Nr„   rO   rW   rX   s    r:   rT   r‡   �   rZ   r=   r[   )Újson_schemaÚpython_schemar]   )
r   r^   r_   r`   ra   rb   Újson_or_python_schemaÚunion_schemaÚis_instance_schemarc   )rd   re   rf   Úserialized_schemaÚdeserialization_schemas   `    r:   rh   Ú'ToolFailed.__get_pydantic_core_schema__   s´   ø€ ô (×9Ò9ä&×7Ò7¼×8NÒ8NÓ8PÓQÜ#×4Ò4´[×5OÒ5OÐQ^ÐP_Ó5`Óañó
Ðô "-×!MÒ!MÜ+Øó"
Ðô ×0Ò0Ø.Ü%×2Ò2´K×4RÒ4RÐSVÓ4WÐYoÐ3pÓqÜ%×JÒJÙGØ/ññ
ð 	
r=   rW   rj   )rB   Úobjectrk   rl   rm   ro   rp   rz   s   @r:   r-   r-   d   s6   ø‡ ñð ƒLØ5÷"ôSô4ð ó
ó ö
r=   r-   c                  ó>   ^ • \ rS rSrSrSSU 4S jjjrSS jrSrU =r$ )	r   é–   aC  Exception to raise when a tool call should be deferred.

See [tools docs](../deferred-tools.md#deferred-tools) for more information.

Args:
    metadata: Optional dictionary of metadata to attach to the deferred tool call.
        This metadata will be available in `DeferredToolRequests.metadata` keyed by `tool_call_id`.
c                ó.   >• Xl         [        TU ]	  5         g r3   ©Úmetadatar5   r6   ©r8   r–   r9   s     €r:   r6   ÚCallDeferred.__init__    ó   ø€ Ø ŒÜ‰ÑÕr=   c                ó4   • U R                   U R                  44$ r3   ©r9   r–   rI   s    r:   Ú
__reduce__ÚCallDeferred.__reduce__¤   ó   € Ø�~‰~ §¡Ð/Ð/Ð/r=   ©r–   r3   ©r–   údict[str, Any] | None©rk   ztuple[type, tuple[Any, ...]]©	rq   rr   rs   rt   ru   r6   rœ   rx   ry   rz   s   @r:   r   r   –   ó   ø† ñ÷ñ ÷0ò 0r=   r   c                  ó>   ^ • \ rS rSrSrSSU 4S jjjrSS jrSrU =r$ )	r   é¨   ae  Exception to raise when a tool call requires human-in-the-loop approval.

See [tools docs](../deferred-tools.md#human-in-the-loop-tool-approval) for more information.

Args:
    metadata: Optional dictionary of metadata to attach to the deferred tool call.
        This metadata will be available in `DeferredToolRequests.metadata` keyed by `tool_call_id`.
c                ó.   >• Xl         [        TU ]	  5         g r3   r•   r—   s     €r:   r6   ÚApprovalRequired.__init__²   r™   r=   c                ó4   • U R                   U R                  44$ r3   r›   rI   s    r:   rœ   ÚApprovalRequired.__reduce__¶   rž   r=   rŸ   r3   r    r¢   r£   rz   s   @r:   r   r   ¨   r¤   r=   r   c                  ó<   ^ • \ rS rSr% SrS\S'   SU 4S jjrSrU =r$ )r   éº   aj  Exception to raise in before/wrap model request hooks to skip the model call.

The provided response will be used instead of calling the model.

Note: when raised in `before_model_request`, any message history modifications
made by earlier capabilities in that hook will not be persisted to the agent's
message history, since the request preparation is aborted.
r   Úresponsec                ó.   >• Xl         [        TU ]	  5         g r3   )r­   r5   r6   )r8   r­   r9   s     €r:   r6   ÚSkipModelRequest.__init__Æ   r™   r=   )r­   )r­   r   ©	rq   rr   rs   rt   ru   rv   r6   rx   ry   rz   s   @r:   r   r   º   s   ø‡ ñð Ó÷õ r=   r   c                  ó<   ^ • \ rS rSr% SrS\S'   SU 4S jjrSrU =r$ )r   éË   z†Exception to raise in before/wrap tool validate hooks to skip validation.

The provided args will be used as the validated arguments.
údict[str, Any]Úvalidated_argsc                ó.   >• Xl         [        TU ]	  5         g r3   )r´   r5   r6   )r8   r´   r9   s     €r:   r6   ÚSkipToolValidation.__init__Ó   s   ø€ Ø,ÔÜ‰ÑÕr=   )r´   )r´   r³   r°   rz   s   @r:   r   r   Ë   s   ø‡ ñð
 #Ó"÷õ r=   r   c                  ó<   ^ • \ rS rSr% SrS\S'   SU 4S jjrSrU =r$ )r   éØ   z~Exception to raise in before/wrap tool execute hooks to skip execution.

The provided result will be used as the tool result.
r
   Úresultc                ó.   >• Xl         [        TU ]	  5         g r3   )r¹   r5   r6   )r8   r¹   r9   s     €r:   r6   ÚSkipToolExecution.__init__à   s   ø€ ØŒÜ‰ÑÕr=   )r¹   )r¹   r
   r°   rz   s   @r:   r   r   Ø   s   ø‡ ñð
 ƒK÷õ r=   r   c                  ó>   ^ • \ rS rSr% SrS\S'    SU 4S jjrSrU =r$ )r   éå   uE   Error caused by a usage mistake by the application developer â€” You!r0   r1   c                ó0   >• Xl         [        TU ]	  U5        g r3   r4   r7   s     €r:   r6   ÚUserError.__init__ë   r<   r=   rW   rj   r°   rz   s   @r:   r   r   å   s   ø‡ ÙOàƒLØ%÷"õ "r=   r   c                  ó   • \ rS rSrSrSrg)r    éð   a  Error that used to be raised when an agent run ended with messages still queued via `enqueue`.

A bare `async for node in agent_run` loop used to skip the node hooks, so `'when_idle'`
messages and end-of-run redirects (which drain in `after_node_run`) were stranded. Bare
iteration now advances through [`AgentRun.next()`][pydantic_ai.run.AgentRun.next] like every
other way of driving a run, so pending messages always drain and this error is no longer
raised. It is kept so existing `except` clauses keep working.
r†   N©rq   rr   rs   rt   ru   rx   r†   r=   r:   r    r    ð   s   † ôr=   r    c                  óH   ^ • \ rS rSr% SrS\S'    SU 4S jjrS	S jrSrU =r	$ )
r!   éû   z4Base class for errors occurring during an agent run.r0   r1   c                ó0   >• Xl         [        TU ]	  U5        g r3   r4   r7   s     €r:   r6   ÚAgentRunError.__init__  r<   r=   c                ó   • U R                   $ r3   rW   rI   s    r:   Ú__str__ÚAgentRunError.__str__  s   € Ø�|‰|Ðr=   rW   rj   ©rk   r0   )
rq   rr   rs   rt   ru   rv   r6   rÈ   rx   ry   rz   s   @r:   r!   r!   û   s   ø‡ Ù>àƒLØ÷"÷ò r=   r!   Ú_pydantic_ai_run_cancelledc                  ó$  ^ • \ rS rSrSrSSSSSSS.             SU 4S jjjrSS jrSS	 jr\SS
 j5       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5       r\SS j5       r\SS j5       r\S S j5       r\S S j5       rSrU =r$ )!r"   i  u½  Raised when the agent run was cancelled by the application itself.

Raised by [`AgentRun.cancel()`][pydantic_ai.run.AgentRun.cancel] and
[`RunContext.cancel()`][pydantic_ai.tools.RunContext.cancel].
This is a normal, catchable application-level outcome: the run stopped because your own code
asked it to. External cancellation of the task running the agent (`asyncio.Task.cancel()`,
a timeout scope, workflow cancellation under durable execution) is infrastructure-level and
keeps propagating as `asyncio.CancelledError` instead â€” it is never translated into this
exception, and when both race, the external cancellation wins. (On Python 3.10, which lacks
`Task.uncancel()`, the race cannot be disambiguated and a requested first-party cancellation
wins instead.)

Everything the run completed before the cancellation took effect â€” including the partial
response of an interrupted stream and the results of tool calls that finished â€” is preserved
in [`all_messages()`][pydantic_ai.exceptions.RunCancelled.all_messages]: pass it as
`message_history` to a new run (with a new user prompt or not) to resume the conversation; any
tool calls that never produced a result are automatically closed out with synthesized
`outcome='interrupted'` returns before the history is sent to a model.

Cancellation is terminal: capability hooks (`wrap_run`, `wrap_node_run`, `on_run_error`) may
observe it and clean up, but cannot recover a cancelled run into a successful result.
r†   r   N)ÚmessagesÚnew_message_indexÚusager–   Úrun_idÚconversation_idc               ó    >• Uc  SSK Jn  U" 5       n[        U5      U l        X0l        X@l        XPl        X`l        Xpl        [        T	U ])  U5        g )Nr   r   )rÏ   r   ÚlistÚ	_messagesÚ_new_message_indexÚ_usageÚ	_metadataÚ_run_idÚ_conversation_idr5   r6   )
r8   r1   rÍ   rÎ   rÏ   r–   rÐ   rÑ   r   r9   s
            €r:   r6   ÚRunCancelled.__init__$  sG   ø€ ð ‰=Ý'á“JˆEÜ˜h›ˆŒØ"3ÔØŒØ!ŒØŒØ /ÔÜ‰Ñ˜Õ!r=   c                óJ   • U R                   U R                  4U R                  4$ r3   )r9   r1   Ú__dict__rI   s    r:   rœ   ÚRunCancelled.__reduce__;  s   € Ø�~‰~ §¡˜°·±Ð=Ð=r=   c                ó&   • [        U[        U 5        g r3   )ÚsetattrÚ_RUN_CANCELLED_ATTR)r8   Úexcs     r:   Ú
_attach_toÚRunCancelled._attach_to>  s   € Ü�Ô(¨$Õ/r=   c                ó®  • U/n[        5       nU(       aÁ  UR                  5       n[        U5      nXS;   a  M)  UR                  U5        [	        X@5      (       a  U$ [        U[        S5      n[	        X`5      (       a  U$ UR                  b  UR                  UR                  5        UR                  b  UR                  UR                  5        U(       a  MÁ  g)u  Recover run state from a cancellation-related exception.

External cancellation of a plain `agent.run()` keeps its standard asyncio semantics. Catch
it with `except asyncio.CancelledError as exc`, then call
`RunCancelled.from_cancellation(exc)` to access the partial run state attached by Pydantic
AI. This also works with the `TimeoutError` raised by `asyncio.timeout()` or
`asyncio.wait_for()`, whose exception chain contains the original `CancelledError`. An
external `CancelledError` must keep propagating for timeouts and task groups to tear down
correctly, so re-raise it after capturing the state rather than returning from the handler;
only a first-party `RunCancelled` is yours to consume.

Passing a `RunCancelled` directly returns the same instance, providing uniform handling for
first-party and external cancellation paths.

Python 3.11+ preserves the exception instance across an `await task` boundary. Python 3.10
recreates the `CancelledError` there, but chains the original exception â€” and the attached
run state â€” via `__context__`, which this method traverses; the chain is attached only to
the first `await` of the cancelled task, so later awaits of the same task see an unchained
exception. Use `capture_run_messages()` as the fallback when only message history is needed.
N)
ÚsetÚpopÚidÚaddr@   Úgetattrrà   Ú	__cause__ÚappendÚ__context__)rd   rá   ÚpendingÚvisitedÚcurrentÚ
current_idÚattacheds          r:   Úfrom_cancellationÚRunCancelled.from_cancellationA  sµ   € ð, �%ˆÜ›EˆÞØ—k‘k“mˆGÜ˜G›ˆJØÓ$ÙØ�K‰K˜
Ô#ä˜'×'Ñ'Ø�Ü˜wÔ(;¸TÓBˆHÜ˜(×(Ñ(Ø�à× Ñ Ñ,Ø—‘˜w×0Ñ0Ô1Ø×"Ñ"Ñ.Ø—‘˜w×2Ñ2Ô3÷! ˆgð" r=   c                ó   • U R                   $ )zÜReturn the complete resumable history of the cancelled run.

This is a DETACHED snapshot of the run's message history at termination, ready to pass as
`message_history` for a resumed run.

Returns:
    List of messages.
)rÔ   rI   s    r:   Úall_messagesÚRunCancelled.all_messagesl  s   € ð �~‰~Ðr=   c                óL   • SSK Jn  UR                  U R                  5       5      $ )zŸReturn all messages from [`all_messages`][pydantic_ai.exceptions.RunCancelled.all_messages] as JSON bytes.

Returns:
    JSON bytes representing the messages.
r   ©ÚModelMessagesTypeAdapter)rÍ   rù   Ú	dump_jsonrõ   ©r8   rù   s     r:   Úall_messages_jsonÚRunCancelled.all_messages_jsonw  ó!   € õ 	7à'×1Ñ1°$×2CÑ2CÓ2EÓFÐFr=   c                ó4   • U R                   U R                  S $ )z¯Return the messages produced during the cancelled run.

Messages provided via `message_history` and messages from older runs are excluded.

Returns:
    List of new messages.
N)rÔ   rÕ   rI   s    r:   Únew_messagesÚRunCancelled.new_messages�  s   € ð �~‰~˜d×5Ñ5Ð7Ð8Ð8r=   c                óL   • SSK Jn  UR                  U R                  5       5      $ )z£Return new messages from [`new_messages`][pydantic_ai.exceptions.RunCancelled.new_messages] as JSON bytes.

Returns:
    JSON bytes representing the new messages.
r   rø   )rÍ   rù   rú   r   rû   s     r:   Únew_messages_jsonÚRunCancelled.new_messages_json‹  rþ   r=   c                óŒ   • SSK Jn  [        U R                  5       5       H  n[	        X!5      (       d  M  Us  $    [        S5      e)zŠReturn the last response from the message history.

Raises:
    ValueError: If the run was cancelled before receiving any model response.
r   )r   z(No response found in the message history)rÍ   r   Úreversedrõ   r@   Ú
ValueError)r8   r   r1   s      r:   r­   ÚRunCancelled.response•  s=   € õ 	,ä × 1Ñ 1Ó 3Ö4ˆGÜ˜'×1Ó1Ø’ñ 5ô ÐCÓDÐDr=   c                ó.   • U R                   R                  $ )z‚Return the timestamp of the last response.

Raises:
    ValueError: If the run was cancelled before receiving any model response.
)r­   Ú	timestamprI   s    r:   r
  ÚRunCancelled.timestamp£  s   € ð �}‰}×&Ñ&Ð&r=   c                ó   • U R                   $ )z&Return the usage of the cancelled run.)rÖ   rI   s    r:   rÏ   ÚRunCancelled.usage¬  s   € ð �{‰{Ðr=   c                ó   • U R                   $ )z7Metadata associated with this agent run, if configured.)r×   rI   s    r:   r–   ÚRunCancelled.metadata±  s   € ð �~‰~Ðr=   c                ó   • U R                   $ )zWThe unique identifier for the agent run, or `None` if it was cancelled before starting.)rØ   rI   s    r:   rÐ   ÚRunCancelled.run_id¶  s   € ð �|‰|Ðr=   c                ó   • U R                   $ )zPThe conversation identifier, or `None` if the run was cancelled before starting.)rÙ   rI   s    r:   rÑ   ÚRunCancelled.conversation_id»  s   € ð ×$Ñ$Ð$r=   )rÙ   rÔ   r×   rÕ   rØ   rÖ   )r1   r0   rÍ   zSequence[ModelMessage]rÎ   rn   rÏ   zRunUsage | Noner–   r¡   rÐ   ú
str | NonerÑ   r  )rk   z'tuple[type, tuple[str], dict[str, Any]])rá   ÚBaseExceptionrk   ÚNone)rá   r  rk   zRunCancelled | None)rk   zlist[ModelMessage])rk   Úbytes)rk   r   )rk   r   )rk   r   )rk   r¡   )rk   r  )rq   rr   rs   rt   ru   r6   rœ   râ   rw   rò   rõ   rü   r   r  Úpropertyr­   r
  rÏ   r–   rÐ   rÑ   rx   ry   rz   s   @r:   r"   r"     s  ø† ñð6 ,.Ø!"Ø!%Ø*.Ø!Ø&*ñ"àð"ð )ð	"ð
 ð"ð ð"ð (ð"ð ð"ð $÷"ð "ô.>ô0ð ó(ó ð(ôT	ôGô9ôGð óEó ðEð ó'ó ð'ð óó ðð óó ðð óó ðð ó%ó ö%r=   r"   c                  ó   • \ rS rSrSrSrg)r#   iÁ  a�  Raised when resuming a suspended response whose server-side job is no longer available.

Suspended/background jobs are only resumable within the provider's retention window (e.g. ~10
minutes for OpenAI background mode). Resuming a persisted suspended response after that window
raises this instead of an opaque provider HTTP error; start a new run from the preceding messages
to retry from scratch.
r†   NrÂ   r†   r=   r:   r#   r#   Á  s   † ôr=   r#   c                  ó4   ^ • \ rS rSrSrSrSU 4S jjrSrU =r$ )r%   iË  z?Error raised when a Model's usage exceeds the specified limits.z•Consider raising the limit, or see the docs on usage limits for budget-aware patterns: https://pydantic.dev/docs/ai/core-concepts/agent/#usage-limitsc                ó„   >• U R                   U;  a   UR                  S5       SU R                    3n[        TU ]  U5        g )NÚ.z. )Ú_HINTÚremovesuffixr5   r6   r7   s     €r:   r6   ÚUsageLimitExceeded.__init__Ó  s<   ø€ à�:‰:˜WÓ$Ø ×-Ñ-¨cÓ2Ð3°2°d·j±j°\ÐBˆGÜ‰Ñ˜Õ!r=   r†   rj   )	rq   rr   rs   rt   ru   r  r6   rx   ry   rz   s   @r:   r%   r%   Ë  s   ø† ÙIð	dð 
÷
"õ "r=   r%   c                  ó   • \ rS rSrSrSrg)r&   iÚ  zAError raised when the concurrency queue depth exceeds max_queued.r†   NrÂ   r†   r=   r:   r&   r&   Ú  ó   † ÜKr=   r&   c                  ób   ^ • \ rS rSr% SrS\S'    S\S'    SSU 4S jjjrSS jrSS	 jrS
r	U =r
$ )r$   iÞ  zLError caused by unexpected Model behavior, e.g. an unexpected response code.r0   r1   r  Úbodyc                óÐ   >• Xl         Uc  S U l        O/ [        R                  " [        R                  " U5      SS9U l        [        TU ]  U5        g ! [
         a	    X l         N"f = f)Né   )Úindent)r1   r#  ÚjsonÚdumpsÚloadsr  r5   r6   )r8   r1   r#  r9   s      €r:   r6   Ú UnexpectedModelBehavior.__init__æ  sY   ø€ ØŒØ‰<Ø$(ˆD�Ið!Ü ŸJšJ¤t§z¢z°$Ó'7ÀÑB�”	ô 	‰Ñ˜Õ!øô ó !Ø –	ð!ús   ”.A ÁA%Á$A%c                óJ   • U R                   U R                  U R                  44$ r3   )r9   r1   r#  rI   s    r:   rœ   Ú"UnexpectedModelBehavior.__reduce__ñ  s   € Ø�~‰~ §¡¨d¯i©iÐ8Ð8Ð8r=   c                ór   • U R                   (       a  U R                   SU R                    3$ U R                  $ )Nz, body:
©r#  r1   rI   s    r:   rÈ   ÚUnexpectedModelBehavior.__str__ô  s,   € Ø�9�9Ø—l‘l�^ 9¨T¯Y©Y¨KÐ8Ð8à—<‘<Ðr=   r.  r3   )r1   r0   r#  r  r¢   rÊ   )rq   rr   rs   rt   ru   rv   r6   rœ   rÈ   rx   ry   rz   s   @r:   r$   r$   Þ  s0   ø‡ ÙVàƒLØ1Ø
ÓØ1÷	"ñ 	"ô9÷ ò  r=   r$   c                  ó   • \ rS rSrSrSrg)r)   iû  zARaised when content filtering is triggered by the model provider.r†   NrÂ   r†   r=   r:   r)   r)   û  r!  r=   r)   c                  óH   ^ • \ rS rSr% SrS\S'    SU 4S jjrS	S jrSrU =r	$ )
r'   iÿ  z/Raised when a model provider API request fails.r0   Ú
model_namec                ó0   >• Xl         [        TU ]	  U5        g r3   )r2  r5   r6   )r8   r2  r1   r9   s      €r:   r6   ÚModelAPIError.__init__  s   ø€ Ø$ŒÜ‰Ñ˜Õ!r=   c                óJ   • U R                   U R                  U R                  44$ r3   )r9   r2  r1   rI   s    r:   rœ   ÚModelAPIError.__reduce__	  s   € Ø�~‰~ §¡°·±Ð>Ð>Ð>r=   )r2  )r2  r0   r1   r0   r¢   )
rq   rr   rs   rt   ru   rv   r6   rœ   rx   ry   rz   s   @r:   r'   r'   ÿ  s   ø‡ Ù9àƒOØ:÷"÷?ò ?r=   r'   c                  ó¬   ^ • \ rS rSr% SrS\S'    S\S'    S\S'    S	\S
'     SSSS.         SU 4S jjjjrSS jrSS jr\	SS j5       r
SrU =r$ )r(   i  zFRaised when a model provider response has a status code of 4xx or 5xx.rn   Ústatus_codeúobject | Noner#  zdict[str, str] | NoneÚheadersr  Úsuggested_model_idN©r:  r;  c               óü   >• Xl         X0l        Ub4  UR                  5        VVs0 s H  u  pgUR                  5       U_M     snnOS U l        XPl        SU SU SU 3nUb
  USU< S3-  n[        T	U ]  X(S9  g s  snnf )Nzstatus_code: z, model_name: z, body: ú. Did you mean Ú?)r2  r1   )r8  r#  ÚitemsÚlowerr:  r;  r5   r6   )
r8   r8  r2  r#  r:  r;  ÚkÚvr1   r9   s
            €r:   r6   ÚModelHTTPError.__init__!  s‘   ø€ ð 'ÔØŒ	ØELÑEX°·±´ÔA²©¨˜Ÿ™›	 1š±ÓAÐ^bˆŒØ"4ÔØ! + ¨n¸Z¸LÈÐQUÐPVÐWˆØÑ)Ø˜Ð);Ñ(>¸aÐ@Ñ@ˆGÜ‰Ñ JÐÒ@ùó Bs   ¤A8c                ó�   • U R                   U R                  U R                  U R                  4U R                  U R
                  S.4$ )Nr<  )r9   r8  r2  r#  r:  r;  rI   s    r:   rœ   ÚModelHTTPError.__reduce__3  s@   € à�N‰NØ×Ñ˜tŸ™°·	±	Ð:àŸ<™<Ø&*×&=Ñ&=ñð
ð 	
r=   c                óä   • UR                  S5      U l        UR                  S5      U l        U R                  b7  U =R                  SU R                  < S3-  sl        U R                  4U l        g g )Nr:  r;  r>  r?  )Úgetr:  r;  r1   Úargs)r8   Ústates     r:   Ú__setstate__ÚModelHTTPError.__setstate__=  s`   € Ø—y‘y Ó+ˆŒØ"'§)¡)Ð,@Ó"AˆÔØ×"Ñ"Ñ.Ø�LŠL˜o¨d×.EÑ.EÑ-HÈÐJÑJ�LØŸ™˜ˆD�Ið /r=   c                ó  • U R                   c  gU R                   R                  S5      nUc  g [        U5      nUS:  a  g[        U5      $ ! [        [
        4 a     Of = f [        U5      n[        U[        5      (       d   eUR                  c  UR                  [        R                  S9nU[        R                  " [        R                  5      -
  R                  5       n[        SU5      $ ! [        [         ["        4 a     gf = f)a&  Seconds to wait before retrying, parsed from the `Retry-After` response header.

Returns `None` when the header is absent or cannot be parsed. The header value
is interpreted first as an integer number of seconds, then as an
[HTTP-date](https://httpwg.org/specs/rfc9110.html#http.date) string.
Nzretry-afterr   )Útzinfog        )r:  rH  rn   Úfloatr  ÚOverflowErrorr   r@   r   rN  Úreplacer   ÚutcÚnowÚtotal_secondsÚmaxÚ	TypeErrorÚAssertionError)r8   ÚrawÚsecondsÚ
retry_timeÚwaits        r:   Úretry_afterÚModelHTTPError.retry_afterD  sð   € ð �<‰<ÑØØ�l‰l×Ñ˜}Ó-ˆØ‰;Øð	Ü˜#“hˆGØ˜‹{ØÜ˜“>Ð!øÜœMÐ*ó 	Ùð	úð		Ü.¨sÓ3ˆJÜ˜j¬(×3Ñ3Ð3Ð3à× Ñ Ñ(Ø'×/Ñ/´x·|±|Ð/ÐD�
Ø¤§¢¬h¯l©lÓ!;Ñ;×JÑJÓLˆDÜ�s˜D“>Ð!øÜœI¤~Ð6ó 	Ùð	ús*   ¯A Á
A ÁAÁAÁ#BC0 Ã0DÄD)rI  r#  r:  r8  r;  r3   )
r8  rn   r2  r0   r#  r9  r:  zMapping[str, str] | Noner;  r  )rk   z,tuple[type, tuple[Any, ...], dict[str, Any]])rJ  r³   rk   r  )rk   zfloat | None)rq   rr   rs   rt   ru   rv   r6   rœ   rK  r  r\  rx   ry   rz   s   @r:   r(   r(     s    ø‡ ÙPàÓØ3à
ÓØ1à"Ó"ðð #Ó"Ø^ð #ð	Að -1Ø)-ñAàðAð ðAð ð	Að *ðAð '÷Añ Aô$
ô(ð óó ör=   r(   c                  ó   • \ rS rSrSrSrg)r,   id  zGA group of exceptions that can be raised when all fallback models fail.r†   NrÂ   r†   r=   r:   r,   r,   d  s   † ÜQr=   r,   c                  óN   ^ • \ rS rSrSrSU 4S jjrSS jr\S	S j5       rSr	U =r
$ )
ÚToolRetryErrorih  zMException used to signal a `ToolRetry` message should be returned to the LLM.c                óÒ   >• Xl         [        UR                  [        5      (       a  UR                  O%U R	                  UR                  UR
                  5      n[        TU ]  U5        g r3   )Ú
tool_retryr@   Úcontentr0   Ú_format_error_detailsÚ	tool_namer5   r6   )r8   rb  r1   r9   s      €r:   r6   ÚToolRetryError.__init__k  sX   ø€ Ø$Œô ˜*×,Ñ,¬c×2Ñ2ð ×Òà×+Ñ+¨J×,>Ñ,>À
×@TÑ@TÓUð 	ô
 	‰Ñ˜Õ!r=   c                ó4   • U R                   U R                  44$ r3   )r9   rb  rI   s    r:   rœ   ÚToolRetryError.__reduce__t  s   € Ø�~‰~ §¡Ð1Ð1Ð1r=   c           
     óD  • [        U 5      nU SUS:X  a  SOS U(       a  SU< 3OS 3/nU  H`  nUS   (       a  SR                  S US    5       5      OS	nUR                  U5        UR                  S
US    SUS    SUS   < S35        Mb     SR                  U5      $ )a}  Format ErrorDetails as a human-readable message.

We format manually rather than using ValidationError.from_exception_data because
some error types (value_error, assertion_error, etc.) require an 'error' key in ctx,
but when ErrorDetails are serialized, exception objects are stripped from ctx.
The 'msg' field already contains the human-readable message, so we use that directly.
z validation errorr   Ú Úsz for Úlocr  c              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr3   )r0   )Ú.0rY   s     r:   Ú	<genexpr>Ú7ToolRetryError._format_error_details.<locals>.<genexpr>…  s   é € Ð4ª8 aœ3˜qŸ6˜6ª8ùs   ‚Ú__root__z  Úmsgz [type=Útypez, input_value=ÚinputÚ]Ú
)ÚlenÚjoinrë   )Úerrorsre  Úerror_countÚlinesÚerl  s         r:   rd  Ú$ToolRetryError._format_error_detailsw  s¹   € ô ˜&“kˆàˆmÐ,°;À!Ó3C©RÈÐ,MÖgpÐPUÐV_ÑUbÑNcÐvxÐMyÐzð
ˆó ˆAØ89¸%¿�#—(‘(Ñ4¨1¨Uª8Ó4Ô4ÀjˆCØ�L‰L˜ÔØ�L‰L˜2˜a ™h˜Z w¨q°©y¨k¸ÈÈ'É
Á~ÐUVÐWÖXñ ð �y‰y˜ÓÐr=   )rb  )rb  r   r¢   )ry  z list[pydantic_core.ErrorDetails]re  r  rk   r0   )rq   rr   rs   rt   ru   r6   rœ   Ústaticmethodrd  rx   ry   rz   s   @r:   r`  r`  h  s$   ø† ÙW÷"ô2ð ó ó ö r=   r`  c                  ó:   ^ • \ rS rSrSrSU 4S jjrSS jrSrU =r$ )ÚToolFailedErrori‹  zQException used to signal a failed `ToolReturnPart` should be returned to the LLM.c                óJ   >• Xl         [        TU ]	  UR                  SS95        g )NF)Úwrap_if_error)Útool_failedr5   r6   Úmodel_response_str)r8   rƒ  r9   s     €r:   r6   ÚToolFailedError.__init__Ž  s&   ø€ Ø&Ôô 	‰Ñ˜×7Ñ7ÀeÐ7ÐLÕMr=   c                ó4   • U R                   U R                  44$ r3   )r9   rƒ  rI   s    r:   rœ   ÚToolFailedError.__reduce__”  s   € Ø�~‰~ × 0Ñ 0Ð2Ð2Ð2r=   )rƒ  )rƒ  r   r¢   r£   rz   s   @r:   r€  r€  ‹  s   ø† Ù[÷N÷3ò 3r=   r€  c                  ó   • \ rS rSrSrSrg)r*   i˜  zNError raised when a model stops due to token limit while emitting a tool call.r†   NrÂ   r†   r=   r:   r*   r*   ˜  s   † ÜXr=   r*   c                  ó   • \ rS rSrSrSrg)r+   iœ  uÂ  Warning raised when in-place mutation of the message history is detected at the end of a run.

Mutating messages that are already part of the run's history in place (e.g.
`ctx.messages[0].parts[0].content = '...'` from a tool) is not supported: the per-request
`gen_ai.input.messages` span attribute caches each message's serialized form, so spans recorded
after the mutation may not match the messages actually sent to the model. The run-level
`pydantic_ai.all_messages` attribute is always serialized fresh and does reflect the mutation.
To transform history mid-run, build new message or part objects instead â€” e.g. with
`dataclasses.replace`, passing the message a new `parts` list (replacing a message in the
history and reassigning its `parts` list are both safe) â€” for instance in a history processor
([`ProcessHistory`][pydantic_ai.capabilities.ProcessHistory]).

The warning is best-effort: it's raised when a mutation is detected at the end of a successful
run, which covers messages still present in the final history. Errored runs aren't checked â€”
with warnings configured as errors, the warning would displace the run's own exception. Its
absence does not guarantee that no stale span was recorded.
r†   NrÂ   r†   r=   r:   r+   r+   œ  s   † ôr=   r+   );Ú
__future__r   Ú_annotationsr'  ÚsysÚcollections.abcr   r   r   r   Úemail.utilsr   Útypingr	   r
   Úpydantic_corer   Ú	_warningsr   r   r   Úversion_infoÚexceptiongroupr   rÍ   r   r   r   r   rÏ   r   Ú__all__Ú	Exceptionr   r-   r   r   r   r   r   ÚRuntimeErrorr   r    r!   rà   r"   r#   r%   r&   r$   r)   r'   r(   r,   r`  r€  r*   ÚWarningr+   r†   r=   r:   Ú<module>r˜     s‹  ðÝ 2ã Û 
ß -ß 'Ý -ß %ã Ý %÷ñ ð ×Ñ�gÓÞ?à#€Nö ßVÓVÝð€ô8(
�ô (
ôV/
�ô /
ôd0�9ô 0ô$0�yô 0ô$�yô ô"
˜ô 
ô
˜	ô 
ô"�ô "ô Iô ô�Lô ð 3Ð ôr%�=ô r%ôj˜}ô ô"˜ô "ôL˜}ô Lô ˜mô  ô:LÐ0ô Lô?�Mô ?ôT�]ô TônR˜^¨CÑ0ô Rô  �Yô   ôF
3�iô 
3ôYÐ0ô Yô 7õ r=   