
    $j                        d 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 ddlmZ ddlmZ dd	lmZ d
dlmZ d Zd Zd Zd Zd ZdefdZee	_        ee_        ee	_        ee	_        ee	_        ee	_         eZe	Zg dZ!dS )uc  
Hindsight Client - Clean, pythonic wrapper for the Hindsight API.

This package provides a high-level ``Hindsight`` class with simplified methods
for the most common operations (retain, recall, reflect, banks, mental models,
directives).

For operations not available as convenience methods — such as documents,
entities, async operations, webhooks, and monitoring — use the low-level API
clients exposed as properties on the ``Hindsight`` instance (e.g.
``client.documents``, ``client.entities``, ``client.operations``).
All low-level methods are async.

Quick start::

    from hindsight_client import Hindsight

    client = Hindsight(base_url="http://localhost:8888")

    # Store a memory
    client.retain(bank_id="alice", content="Alice loves AI")

    # Search memories
    response = client.recall(bank_id="alice", query="What does Alice like?")
    for r in response.results:
        print(r.text)

    # Generate contextual answer
    answer = client.reflect(bank_id="alice", query="What are my interests?")
    print(answer.text)

Low-level API access::

    import asyncio

    # List documents
    docs = asyncio.run(client.documents.list_documents("alice"))

    # Check operation status
    status = asyncio.run(client.operations.get_operation_status("alice", "op-id"))

    # List entities
    entities = asyncio.run(client.entities.list_entities("alice"))
    )BankProfileResponse)DispositionTraits)ListMemoryUnitsResponse)RecallResponse)RecallResult)ReflectFact)ReflectResponse)RetainResponse   )	Hindsightc                     t          | j                  dk    r| j        d d         dz   n| j        }d| j        d d          d| j         d| dS )NP   z...zRecallResult(id='   z...', type='z	', text='z'))lentextidtype)selftext_previews     a/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/hindsight_client/__init__.py_recall_result_reprr   =   s\    -0^^b-@-@49SbS>E))diL\twrr{\\	\\L\\\\    c                    | j         rt          | j                   nd}g }| j        r|                    d           | j        r*|                    dt          | j                              | j        r*|                    dt          | j                              |rdd                    |          z   nd}d| d| d	S )
Nr   z
trace=Truez	entities=zchunks=z,  zRecallResponse(z results))resultsr   traceappendentitieschunksjoin)r   countextras
extras_strs       r   _recall_response_reprr%   B   s    !%4C1EFz $l###} 86#dm"4"466777{ 42DK 0 022333-3;		&))))J9U99J9999r   c                 .    t          | j        pg           S )z.Iterate directly over results for convenience.)iterr   r   s    r   _recall_response_iterr)   O   s    "###r   c                 <    | j         rt          | j                   ndS )zReturn number of results.r   )r   r   r(   s    r   _recall_response_lenr+   T   s     $33t|!3r   c                     | j         |         S )zAccess results by index.)r   )r   indexs     r   _recall_response_getitemr.   Y   s    <r   returnc                    ddl }| j        pi }g }g }| j        pg D ]s}d|j        i}|j        r
|j        |d<   dD ]}t          ||d          }|r|||<   |j        r|j        |v r||j                 j        |d<   |                    |           t|                    d|                    |d	          z              | j	        rg }	| j	        
                                D ]9\  }
}|j        r-|j        d         j        }|	                    d
|
 d|            :|	r+|                    dd                    |	          z              d                    |          S )a  Serialize the recall response to a string suitable for LLM prompts.

    Builds a prompt containing:
    - Facts: each result as a JSON object with ``text``, ``context``, and
      temporal fields (``occurred_start``, ``occurred_end``, ``mentioned_at``).
      If the result has a ``chunk_id`` matching a chunk in the response, the
      chunk text is included as ``source_chunk``.
    - Entities: entity summaries from observations, formatted as sections.

    This mirrors the format used internally by Hindsight's reflect operation.
    r   Nr   context)occurred_startoccurred_endmentioned_atsource_chunkzFACTS:
   )indentz## 
z
ENTITIES:
z

)jsonr    r   r   r1   getattrchunk_idr   dumpsr   itemsobservationsr!   )r   r9   
chunks_mapsectionsformatted_factsresultfact_objfieldvalueentity_partsnamestateobs_texts                r   !_recall_response_to_prompt_stringrJ   ^   s    KKK"JH #%O,$" 
) 
) &+.> 	1"(.HYG 	( 	(EFE400E ("'? 	Hv*<<'1&/'B'GH^$x((((OOJOA!F!FFGGG } G"$=..00 	> 	>KD%! > -a05##$<$$<$<($<$<=== 	GOOMFKK,E,EEFFF;;x   r   )	r   r
   r   r   r	   r   r   r   r   N)"__doc__1hindsight_client_api.models.bank_profile_responser   .hindsight_client_api.models.disposition_traitsr   6hindsight_client_api.models.list_memory_units_responser   +hindsight_client_api.models.recall_responser   _RecallResponse)hindsight_client_api.models.recall_resultr   _RecallResult(hindsight_client_api.models.reflect_factr   ,hindsight_client_api.models.reflect_responser	   +hindsight_client_api.models.retain_responser
   hindsight_clientr   r   r%   r)   r+   r.   strrJ   to_prompt_string__repr____iter____len____getitem____all__ r   r   <module>r_      sv  + +Z R Q Q Q Q Q L L L L L L Z Z Z Z Z Z Y Y Y Y Y Y S S S S S S @ @ @ @ @ @ H H H H H H G F F F F F ' ' ' ' ' '] ] ]

: 
: 
:$ $ $
4 4 4
  
*!s *! *! *! *!Z $E  , 0 0 . 6     r   