
    Yj0                        d Z ddlmZ ddlZddlmZ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 erddlmZ ddlmZ g dZ G d de          Z G d d          Z G d d          ZdS )z6Conclusion types and scoped access for the Honcho SDK.    )annotationsN)TYPE_CHECKINGAny)	BaseModel   )ConclusionResponseRepresentationResponse)SessionBase)routes)SyncPage)
resolve_idConclusionScopeAio)Honcho)
ConclusionConclusionScopeConclusionCreateParamsc                  (    e Zd ZU ded<   dZded<   dS )r   strcontentN
str | None
session_id)__name__
__module____qualname____annotations__r        Y/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/honcho/conclusions.pyr   r      s,         LLL!J!!!!!!r   r   c                      e Zd ZU dZded<   ded<   ded<   ded<   dZded	<   d
ed<   ddZedd            ZddZ	ddZ
dS )r   a  
    A conclusion from Honcho's reasoning system.

    Conclusions are facts derived from messages that help build a representation
    of a peer.

    Attributes:
        id: Unique identifier for this conclusion
        content: The conclusion content/text
        observer_id: The peer ID who made this conclusion
        observed_id: The peer ID this conclusion is about
        session_id: The session this conclusion relates to
        created_at: Timestamp for when the conclusion was created
    r   idr   observer_idobserved_idNr   r   datetime.datetime
created_atreturnNonec                Z    || _         || _        || _        || _        || _        || _        d S Nr!   r   r"   r#   r   r%   )selfr!   r   r"   r#   r   r%   s          r   __init__zConclusion.__init__8   s4     &&$$r   datar   'Conclusion'c                `     | |j         |j        |j        |j        |j        |j                  S )z)Create a Conclusion from an API response.r*   r*   )clsr-   s     r   from_api_responsezConclusion.from_api_responseH   s=     swL((
 
 
 	
r   c                    t          | j                  dk    r| j        d d          dn| j        }d| j         d| dS )N2   z...zConclusion(id='z', content='z'))lenr   r!   )r+   	truncateds     r   __repr__zConclusion.__repr__T   sW    ),T\):):R)?)?t|CRC %%%%T\ 	 DCCiCCCCr   c                    | j         S r)   )r   r+   s    r   __str__zConclusion.__str__Z   s
    |r   )r!   r   r   r   r"   r   r#   r   r   r   r%   r$   r&   r'   )r-   r   r&   r.   r&   r   )r   r   r   __doc__r   r   r,   classmethodr1   r6   r9   r   r   r   r   r   !   s           GGGLLL!J!!!!!!!!% % % %  	
 	
 	
 [	
D D D D     r   r   c                      e Zd ZU dZded<   ded<   ded<   ded<   d.d	Zed/d            Z	 	 	 d0d1dZ	 	 d2d3dZ	d4d Z
d5d#Z	 	 	 	 	 d6d7d,Zd8d-ZdS )9r   aK  
    Scoped access to conclusions for a specific observer/observed relationship.

    This class provides convenient methods to list, query, create, and delete conclusions
    that are automatically scoped to a specific observer/observed pair.

    Typically accessed via `peer.conclusions` (for self-conclusions) or
    `peer.conclusions_of(target)` (for conclusions about another peer).

    Example:
        ```python
        # Get self-conclusions
        conclusions = peer.conclusions
        obs_list = conclusions.list()
        search_results = conclusions.query("preferences")

        # Get conclusions about another peer
        bob_conclusions = peer.conclusions_of("bob")
        bob_list = bob_conclusions.list()

        # Async operations via .aio accessor
        obs_list = await peer.conclusions.aio.list()
        ```
    'Honcho'_honchor   workspace_idobserverobservedhonchoc                >    || _         || _        || _        || _        dS )z
        Initialize a ConclusionScope.

        Args:
            honcho: The Honcho client instance
            workspace_id: The workspace ID
            observer: The observer peer ID
            observed: The observed peer ID
        N)r?   r@   rA   rB   )r+   rC   r@   rA   rB   s        r   r,   zConclusionScope.__init__}   s%      (  r   r&   'ConclusionScopeAio'c                $    ddl m}  ||           S )a  
        Access async versions of all ConclusionScope methods.

        Returns a ConclusionScopeAio view that provides async versions of all methods
        while sharing state with this ConclusionScope instance.

        Example:
            ```python
            # Async operations
            obs_list = await scope.aio.list()
            results = await scope.aio.query("preferences")
            ```
        r   r   )aior   )r+   r   s     r   rG   zConclusionScope.aio   s'      	,+++++!!$'''r   r   r3   Npageintsizesessionstr | SessionBase | None(SyncPage[ConclusionResponse, Conclusion]c                N     j                                          t          |          } j         j        d|r|d<    j         j                            t          j         j	                  di|d          }dd
d fdt          |t                    S )a7  
        List conclusions in this scope.

        Args:
            page: Page number (1-indexed)
            size: Number of results per page
            session: Optional session (ID string or Session object) to filter by

        Returns:
            Paginated response containing Conclusion objects
        r"   r#   r   filtersrH   rJ   bodyqueryresponser   r&   r   c                6    t                               |           S r)   )r   r1   )rU   s    r   	transformz'ConclusionScope.list.<locals>.transform   s    //999r   rH   rI   rM   c                    j         j                            t          j        j                  di| d          }t          |t                    S )NrP   rQ   rR   )r?   _httppostr   conclusions_listr@   r   r   )rH   	next_data
fetch_nextrP   r+   rJ   rW   s     r   r]   z(ConclusionScope.list.<locals>.fetch_next   s_     *//'(9::)#T22 0  I
 I'99jQQQr   )rU   r   r&   r   )rH   rI   r&   rM   )r?   _ensure_workspacer   rA   rB   rY   rZ   r   r[   r@   r   r   )	r+   rH   rJ   rK   resolved_session_idr-   r]   rP   rW   s	   ` `   @@@r   listzConclusionScope.list   s    " 	&&((((11==#
 #
  	8$7GL!|!&&#D$566W%.. ' 
 
	: 	: 	: 	:	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 0)ZHHHr   
   rT   top_kdistancefloat | Nonelist[Conclusion]c                    | j                                          | j        | j        d}|||d}|||d<   | j         j                            t          j        | j                  |          }d |D             S )a5  
        Semantic search for conclusions in this scope.

        Args:
            query: The search query string
            top_k: Maximum number of results to return
            distance: Maximum cosine distance threshold (0.0-1.0)

        Returns:
            List of matching Conclusion objects
        rO   )rT   rb   rP   Nrc   rS   c                f    g | ].}t                               t          j        |                    /S r   r   r1   r   model_validate.0items     r   
<listcomp>z)ConclusionScope.query.<locals>.<listcomp>   B     
 
 
 (();)J4)P)PQQ
 
 
r   )	r?   r^   rA   rB   rY   rZ   r   conclusions_queryr@   )r+   rT   rb   rc   rP   rS   r-   s          r   rT   zConclusionScope.query   s    " 	&&(((==#
 #
  
  

 'D|!&&$T%677 ' 
 

 

 
 
 	
r   conclusion_idr'   c                    | j                                          | j         j                            t	          j        | j        |                     dS )zy
        Delete a conclusion by ID.

        Args:
            conclusion_id: The ID of the conclusion to delete
        N)r?   r^   rY   deleter   
conclusionr@   )r+   rq   s     r   rs   zConclusionScope.delete   sG     	&&(((!!&"3D4E}"U"UVVVVVr   conclusions-list[ConclusionCreateParams | dict[str, Any]]c                      j                                          d
 fdfd|D             } j         j                            t	          j         j                  d|i          }d	 |D             S )ag  
        Create conclusions in this scope.

        Args:
            conclusions: List of conclusions to create.
                Each conclusion can be a ConclusionCreateParams object or a dictionary
                with a required 'content' key and an optional 'session_id' key.

        Returns:
            List of created Conclusion objects

        Example:
            ```python
            conclusions = peer.conclusions.create([
                {"content": "User prefers dark mode", "session_id": "session1"},
                {"content": "User is interested in AI"},
            ])
            ```
        rm   'ConclusionCreateParams | dict[str, Any]r&   dict[str, Any]c                    j         j        d}t          | t                    r| j        |d<   | j        
| j        |d<   |S | d         |d<   |                     d          }|||d<   |S )a  
            Build a single conclusion create payload.

            This normalizes both `ConclusionCreateParams` instances and plain dictionaries
            into the wire format expected by the Honcho API.

            Notes:
                - `content` is required.
                - `session_id` is optional; when not provided it is omitted from the payload.
                - `observer_id` and `observed_id` are always injected from this scope.

            Args:
                item: A `ConclusionCreateParams` instance or a dict with a required
                    `content` key and an optional `session_id` key.

            Returns:
                A dictionary suitable for inclusion in the `conclusions` array for the
                create conclusions endpoint.
            rO   r   Nr   )rA   rB   
isinstancer   r   r   get)rm   payloadr   r+   s      r   build_conclusion_payloadz8ConclusionScope.create.<locals>.build_conclusion_payload   s    .  $}#}' 'G $ 677 %)\	"?.,0OGL)!%iGI,//J%(2%Nr   c                &    g | ]} |          S r   r   )rl   cr~   s     r   rn   z*ConclusionScope.create.<locals>.<listcomp>F  s%    NNNQ55a88NNNr   ru   rg   c                f    g | ].}t                               t          j        |                    /S r   ri   rk   s     r   rn   z*ConclusionScope.create.<locals>.<listcomp>L  ro   r   )rm   rx   r&   ry   )r?   r^   rY   rZ   r   ru   r@   )r+   ru   conclusion_paramsr-   r~   s   `   @r   createzConclusionScope.create  s    . 	&&((($	 $	 $	 $	 $	 $	L ONNN+NNN|!&&t011!23 ' 
 

 

 
 
 	
r   search_queryr   search_top_k
int | Nonesearch_max_distanceinclude_most_frequentbool | Nonemax_conclusionsc                >   | j                                          d| j        i}|||d<   |||d<   |||d<   |||d<   |||d<   | j         j                            t          j        | j        | j                  |          }t          j
        |          }|j        S )	a  
        Get the computed representation for this scope.

        This returns the working representation (narrative) built from the
        conclusions in this scope.

        Args:
            search_query: Optional semantic search query to curate the representation
            search_top_k: Number of semantically relevant facts to return
            search_max_distance: Maximum semantic distance for search results (0.0-1.0)
            include_most_frequent: Whether to include the most frequent conclusions
            max_conclusions: Maximum number of conclusions to include

        Returns:
            A Representation string
        targetNr   r   r   r   r   rg   )r?   r^   rB   rY   rZ   r   peer_representationr@   rA   r	   rj   representation)	r+   r   r   r   r   r   rS   r-   rU   s	            r   r   zConclusionScope.representationQ  s    0 	&&((( ($-8##/D ##/D **=D&' ,,AD()&&5D"#|!&&&t'8$-HH ' 
 
 *8>>&&r   c                8    d| j         d| j        d| j        dS )NzConclusionScope(workspace_id=z, observer=z, observed=))r@   rA   rB   r8   s    r   r6   zConclusionScope.__repr__}  sF    GD,= G GG G48MG G G	
r   )rC   r>   r@   r   rA   r   rB   r   )r&   rE   )r   r3   N)rH   rI   rJ   rI   rK   rL   r&   rM   )ra   N)rT   r   rb   rI   rc   rd   r&   re   )rq   r   r&   r'   )ru   rv   r&   re   )NNNNN)r   r   r   r   r   rd   r   r   r   r   r&   r   r:   )r   r   r   r;   r   r,   propertyrG   r`   rT   rs   r   r   r6   r   r   r   r   r   ^   s<         2 MMMMMM! ! ! !* ( ( ( X(* ,0	-I -I -I -I -Id !%	&
 &
 &
 &
 &
PW W W WH
 H
 H
 H
X $(#',0-1&**' *' *' *' *'X
 
 
 
 
 
r   r   )r;   
__future__r   datetimetypingr   r   pydanticr   	api_typesr   r	   baser
   httpr   
paginationr   utilsr   rG   r   clientr   __all__r   r   r   r   r   r   <module>r      s|   < < " " " " " "  % % % % % % % %       A A A A A A A A                               ''''''  " " " " "Y " " "
: : : : : : : :zc
 c
 c
 c
 c
 c
 c
 c
 c
 c
r   