
    i                     0   d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZ e
j        j        Zddddddej        dej        dee	j        ej                          d	edz  d
edz  dedz  dej        dz  ddfdZdej        dej        dej        j        fdZdS )z FastAPI integration for Inngest.    N   )
client_libcomm_lib
config_libconstfunction
server_lib
transforms)public_pathserve_origin
serve_path	streamingappclient	functionsr   r   r   r   returnc                l  
 t          j        t          ||          
|                     t	          j                  pt          j                  dt          j	        dt          j
        f
fd            }|                     t	          j                  pt          j                  dt          j	        dt          j
        f
fd            }|                     t	          j                  pt          j                  dt          j	        dt          j
        f
fd            }	dS )a  
    Serve Inngest functions in a FastAPI app.

    Args:
    ----
        app: FastAPI app.
        client: Inngest client.
        functions: List of functions to serve.
        public_path: Path that the Inngest server sends requests to. This is only necessary if the SDK is behind a proxy that rewrites the path.
        serve_origin: Origin for serving Inngest functions. This is typically only useful during Docker-based development.
        serve_path: Path for serving Inngest functions. This is only useful if you don't want serve Inngest at the /api/inngest path.
        streaming: Controls whether to send keepalive bytes until the response is complete.
    )r   	frameworkr   r   requestr   c                 f  K   t                              t          j        |                                  d {V t          | j                                                  t          | j                                                  | t          | j
                                                S N)bodyheadersr   query_paramsraw_requestrequest_urlr   r   )_to_responseget_syncr   CommRequestr   dictr   itemsr   strurlr   r   handlerr   r   r   s    M/root/projects/qq-shell/venv/lib/python3.11/site-packages/inngest/fast_api.pyget_api_inngestzserve.<locals>.get_api_inngest4   s       $&||~~------ !6!6!8!899 +!%g&:&@&@&B&B!C!C ' #GK 0 0!-)	 	 	 
 
 	
    c                 r  K   t                              t          j        |                                  d {V t          | j                                                  t          | j                                                  | t          | j
                                       d {V           S r   )r   postr   r   r   r    r   r!   r   r"   r#   r$   s    r&   post_inngest_apizserve.<locals>.post_inngest_apiH   s       ,,$&||~~------ !6!6!8!899 +!%g&:&@&@&B&B!C!C ' #GK 0 0!-)	 	 	       
 
 	
r(   c                 r  K   t                              t          j        |                                  d {V t          | j                                                  t          | j                                                  | t          | j
                                       d {V           S r   )r   putr   r   r   r    r   r!   r   r"   r#   r$   s    r&   put_inngest_apizserve.<locals>.put_inngest_api\   s       ++$&||~~------ !6!6!8!899 +!%g&:&@&@&B&B!C!C ' #GK 0 0!-)	 	 	       
 
 	
r(   N)r   CommHandler	FRAMEWORKgetr   get_serve_pathr   DEFAULT_SERVE_PATHfastapiRequestResponser*   r-   )r   r   r   r   r   r   r   r'   r+   r.   r%   s    ` ```    @r&   server7      s   0 "	  G 	WWZ&z22Ne6NOO

		
 
 
 
 
 
 
 
 
 PO
& 	XXj'
33Ou7OPP

		
 
 
 
 
 
 
 
 
 QP
& 	WWZ&z22Ne6NOO

		
 
 
 
 
 
 
 
 
 PO
 
 
r(   comm_resc                    |j         >t          j                            |                                 |j        |j                  S t          j        |j                  }t          |t                    r>t          j                            | j        |          }t          j        |j                  }t          j                            |                    d          |j        |j                  S )N)r   status_codezutf-8)contentr   r:   )streamr4   	responsesStreamingResponser   r:   r
   	dump_jsonr   
isinstance	Exceptionr   CommResponse
from_errorloggerjsondumpsr6   encode)r   r8   r   s      r&   r   r   q   s     " 22OO$ , 3 
 
 	
 ..D$	"" )(33FM4HHz(-((%%G$$ ( &   r(   )__doc__rE   typingr4   	_internalr   r   r   r   r   r	   r
   	FrameworkFAST_APIr0   FastAPIInngestlistFunctionAnyr"   	Streamingr7   rB   r=   r6   r    r(   r&   <module>rT      s   & &                      )	 ##!(,Y
 Y
 Y
	Y
Y
 H%fj12Y

 tY
 *Y
 d
Y
 %Y
 
Y
 Y
 Y
 Y
x#      r(   