o
    i>                     @  s  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZmZ z2ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z, W n e-y Z. ze-de.dZ.[.ww g dZ/ddddddddddddd@d7d8Z0e%fdddddddddddddAd>d?Z1dS )BzProvides an AG-UI protocol adapter for the Pydantic AI agent.

This package provides seamless integration between pydantic-ai agents and ag-ui
for building interactive AI applications with streaming event-based communication.
    )annotations)AsyncIteratorSequence)Any   )DeferredToolResults)AbstractAgent)ModelMessage)KnownModelNameModel)
OutputSpec)ModelSettings)
AgentDepsT)AbstractToolset)RunUsageUsageLimits)	BaseEvent)RunAgentInput)Request)Response)SSE_CONTENT_TYPEOnCompleteFunc	StateDepsStateHandler)AGUIAdapter)AGUIAppu   Please install the `ag-ui-protocol` and `starlette` packages to use `AGUIAdapter`, you can use the `ag-ui` optional group — `pip install "pydantic-ai-slim[ag-ui]"`N)r   r   r   r   r   handle_ag_ui_request	run_ag_uiToutput_typemessage_historydeferred_tool_resultsmodeldepsmodel_settingsusage_limitsusage
infer_nametoolsetson_completeagentAbstractAgent[AgentDepsT, Any]requestr   r   OutputSpec[Any] | Noner    Sequence[ModelMessage] | Noner!   DeferredToolResults | Noner"   #Model | KnownModelName | str | Noner#   r   r$   ModelSettings | Noner%   UsageLimits | Noner&   RunUsage | Noner'   boolr(   ,Sequence[AbstractToolset[AgentDepsT]] | Noner)    OnCompleteFunc[BaseEvent] | Nonereturnr   c                  s0   t t j|| ||||||||	|
||dI dH S )a  Handle an AG-UI request by running the agent and returning a streaming response.

    Args:
        agent: The agent to run.
        request: The Starlette request (e.g. from FastAPI) containing the AG-UI run input.

        output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
            output validators since output validators would expect an argument that matches the agent's output type.
        message_history: History of the conversation so far.
        deferred_tool_results: Optional results for deferred tool calls in the message history.
        model: Optional model to use for this run, required if `model` was not set when creating the agent.
        deps: Optional dependencies to use for this run.
        model_settings: Optional settings to use for this model's request.
        usage_limits: Optional limits on model request count or token usage.
        usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
        infer_name: Whether to try to infer the agent name from the call frame if it's not set.
        toolsets: Optional additional toolsets for this run.
        on_complete: Optional callback function called when the agent run completes successfully.
            The callback receives the completed [`AgentRunResult`][pydantic_ai.agent.AgentRunResult] and can access `all_messages()` and other result data.

    Returns:
        A streaming Starlette response with AG-UI protocol events.
    )r*   r#   r   r    r!   r"   r$   r%   r&   r'   r(   r)   N)r   r   dispatch_request)r*   r,   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)    r9   W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/ag_ui.pyr   3   s    'r   	run_inputr   acceptstrAsyncIterator[str]c                C  s4   t | ||d}||j|||||||	|
|||dS )a+  Run the agent with the AG-UI run input and stream AG-UI protocol events.

    Args:
        agent: The agent to run.
        run_input: The AG-UI run input containing thread_id, run_id, messages, etc.
        accept: The accept header value for the run.

        output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
            output validators since output validators would expect an argument that matches the agent's output type.
        message_history: History of the conversation so far.
        deferred_tool_results: Optional results for deferred tool calls in the message history.
        model: Optional model to use for this run, required if `model` was not set when creating the agent.
        deps: Optional dependencies to use for this run.
        model_settings: Optional settings to use for this model's request.
        usage_limits: Optional limits on model request count or token usage.
        usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
        infer_name: Whether to try to infer the agent name from the call frame if it's not set.
        toolsets: Optional additional toolsets for this run.
        on_complete: Optional callback function called when the agent run completes successfully.
            The callback receives the completed [`AgentRunResult`][pydantic_ai.agent.AgentRunResult] and can access `all_messages()` and other result data.

    Yields:
        Streaming event chunks encoded as strings according to the accept header value.
    )r*   r;   r<   r   )r   encode_stream
run_stream)r*   r;   r<   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   adapterr9   r9   r:   r   k   s    )r   )r*   r+   r,   r   r   r-   r    r.   r!   r/   r"   r0   r#   r   r$   r1   r%   r2   r&   r3   r'   r4   r(   r5   r)   r6   r7   r   )r*   r+   r;   r   r<   r=   r   r-   r    r.   r!   r/   r"   r0   r#   r   r$   r1   r%   r2   r&   r3   r'   r4   r(   r5   r)   r6   r7   r>   )2__doc__
__future__r   collections.abcr   r   typingr    r   r*   r   messagesr	   modelsr
   r   outputr   settingsr   toolsr   r(   r   r&   r   r   
ag_ui.corer   ag_ui.core.typesr   starlette.requestsr   starlette.responsesr   uir   r   r   r   ui.ag_uir   ui.ag_ui.appr   ImportErrore__all__r   r   r9   r9   r9   r:   <module>   sp    ;