
    $j5	                     N    d Z ddlmZ ddlmZ erddlmZ  G d de          ZdS )z2Base Extension class for all Hindsight extensions.    )ABC)TYPE_CHECKING)ExtensionContextc                   ^    e Zd ZdZdeeef         fdZddZedd	            Z	dd
Z
ddZdS )	Extensiona  
    Base class for all Hindsight extensions.

    Extensions are loaded via environment variables and receive configuration
    from prefixed environment variables.

    Example:
        HINDSIGHT_API_MY_EXTENSION=mypackage.ext:MyExtension
        HINDSIGHT_API_MY_SOME_CONFIG=value

        The extension receives: {"some_config": "value"}

    Extensions also receive an ExtensionContext that provides a controlled API
    for interacting with the system (e.g., running migrations for tenant schemas).
    configc                 "    || _         d| _        dS )z
        Initialize the extension with configuration.

        Args:
            config: Dictionary of configuration values from environment variables.
                    Keys are lowercased with the prefix stripped.
        N)r   _context)selfr   s     e/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/hindsight_api/extensions/base.py__init__zExtension.__init__   s     37    contextr   returnNc                     || _         dS )z
        Set the extension context.

        Called by the extension loader after instantiation.
        Extensions should not call this directly.

        Args:
            context: The ExtensionContext providing system APIs.
        N)r
   )r   r   s     r   set_contextzExtension.set_context&   s      r   c                 <    | j         t          d          | j         S )z
        Get the extension context.

        Returns:
            The ExtensionContext providing system APIs.

        Raises:
            RuntimeError: If context has not been set yet.
        Nz\Extension context not set. Context is available after the extension is loaded by the system.)r
   RuntimeErrorr   s    r   r   zExtension.context2   s+     = n   }r   c                 
   K   dS )z
        Called when the application starts.

        Override to perform initialization tasks like connecting to external services.
        N r   s    r   
on_startupzExtension.on_startupC          	r   c                 
   K   dS )z~
        Called when the application shuts down.

        Override to perform cleanup tasks like closing connections.
        Nr   r   s    r   on_shutdownzExtension.on_shutdownK   r   r   )r   r   r   N)r   r   )r   N)__name__
__module____qualname____doc__dictstrr   r   propertyr   r   r   r   r   r   r   r   
   s          	8tCH~ 	8 	8 	8 	8
  
  
  
     X         r   r   N)r   abcr   typingr    hindsight_api.extensions.contextr   r   r   r   r   <module>r&      s    8 8                   BAAAAAAG G G G G G G G G Gr   