
    $jF                     l    d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 erddl
mZ  G d de	e          Zd	S )
z
HTTP Extension for adding custom endpoints to the Hindsight API.

This extension allows adding custom HTTP endpoints under the /ext/ path prefix.
The extension provides a FastAPI router that is mounted on the main application.
    )ABCabstractmethod)TYPE_CHECKING)	APIRouter)	Extension)MemoryEnginec                   H    e Zd ZdZedddefd            Zdddedz  fdZdS )HttpExtensiona?  
    Base class for HTTP extensions that add custom API endpoints.

    HTTP extensions provide a FastAPI router that gets mounted under /ext/.
    The extension has full control over the routes, request/response models, and handlers.

    Example:
        ```python
        from fastapi import APIRouter
        from hindsight_api.extensions import HttpExtension

        class MyHttpExtension(HttpExtension):
            def get_router(self, memory: MemoryEngine) -> APIRouter:
                router = APIRouter()

                @router.get("/hello")
                async def hello():
                    return {"message": "Hello from extension!"}

                @router.post("/custom/{bank_id}/action")
                async def custom_action(bank_id: str):
                    # Access memory engine for database operations
                    pool = await memory._get_pool()
                    # ... custom logic
                    return {"status": "ok"}

                return router
        ```

    The routes will be available at:
        - GET /ext/hello
        - POST /ext/custom/{bank_id}/action

    Configuration via environment variables:
        HINDSIGHT_API_HTTP_EXTENSION=mypackage.ext:MyHttpExtension
        HINDSIGHT_API_HTTP_SOME_CONFIG=value

    The extension receives config: {"some_config": "value"}
    memoryr   returnc                     dS )a  
        Return a FastAPI router with custom endpoints.

        The router will be mounted at /ext/ on the main application.
        All routes defined in the router will be prefixed with /ext/.

        Args:
            memory: The MemoryEngine instance for database access and core operations.
                   Use this to access the connection pool, run queries, or call
                   memory operations like retain, recall, etc.

        Returns:
            A FastAPI APIRouter with the custom endpoints defined.

        Example:
            ```python
            def get_router(self, memory: MemoryEngine) -> APIRouter:
                router = APIRouter(tags=["My Extension"])

                @router.get("/status")
                async def status():
                    health = await memory.health_check()
                    return {"extension": "healthy", "memory": health}

                return router
            ```
        N selfr   s     e/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/hindsight_api/extensions/http.py
get_routerzHttpExtension.get_router<   s	    : 	    Nc                     dS )a|  
        Return a FastAPI router with endpoints mounted at the app root.

        Unlike get_router() which is mounted at /ext/, this router is mounted
        directly on the application root. Use for well-known endpoints or other
        paths that must be at specific locations.

        Returns None by default (no root routes). Override to provide root-level routes.
        Nr   r   s     r   get_root_routerzHttpExtension.get_root_router[   s	     tr   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r
   r
      st        & &P  I    ^<
n 
T9I 
 
 
 
 
 
r   r
   N)r   abcr   r   typingr   fastapir   hindsight_api.extensions.baser   hindsight_apir   r
   r   r   r   <module>r      s     $ # # # # # # #                   3 3 3 3 3 3 +******R R R R RIs R R R R Rr   