
    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y)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<   y)r   strcontentN
str | None
session_id)__name__
__module____qualname____annotations__r        /home/cube/projects/richard/traning coach/.omo/evidence/nutricoach-v150-combined/st_01a0560c-r63-installed-wheel-first-claim-qa/venv/lib/python3.12/site-packages/honcho/conclusions.pyr   r      s    L!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
y)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_atc                X    || _         || _        || _        || _        || _        || _        y Nr!   r   r"   r#   r   r%   )selfr!   r   r"   r#   r   r%   s          r   __init__zConclusion.__init__8   s0     &&$$r   c                     | |j                   |j                  |j                  |j                  |j                  |j
                        S )z)Create a Conclusion from an API response.r(   r(   )clsdatas     r   from_api_responsezConclusion.from_api_responseH   s?     wwLL((((
 	
r   c                    t        | j                        dkD  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   sN    ),T\\):R)?t||CR !%T\\ 	 !	i[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$   returnNone)r-   r   r7   z'Conclusion'r7   r   )r   r   r   __doc__r   r   r*   classmethodr.   r3   r6   r   r   r   r   r   !   s     	GL!J
!!!%% % 	%
 % % &% 
%  	
 	
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	 	 	 d	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZ	ddZ
	 	 	 	 ddZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZy
)r   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observedc                <    || _         || _        || _        || _        y)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?   r@   rA   )r)   honchor?   r@   rA   s        r   r*   zConclusionScope.__init__}   s!      (  r   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   rE   zConclusionScope.aio   s      	,!$''r   Nc                r     j                   j                          t        |      } j                   j                  d|r|d<    j                   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pagesizebodyqueryc                ,    t         j                  |       S r'   )r   r.   )responses    r   	transformz'ConclusionScope.list.<locals>.transform   s    //99r   c                    j                   j                  j                  t        j                  j
                        di| d      }t        |t              S )NrH   rI   rL   )r>   _httppostr   conclusions_listr?   r   r   )rJ   	next_data
fetch_nextrH   r)   rK   rQ   s     r   rW   z(ConclusionScope.list.<locals>.fetch_next   s\     **//''(9(9:)#T2 0 I
 I'99jQQr   )rP   r   r7   r   )rJ   intr7   (SyncPage[ConclusionResponse, Conclusion])r>   _ensure_workspacer   r@   rA   rS   rT   r   rU   r?   r   r   )	r)   rJ   rK   sessionresolved_session_idr-   rW   rH   rQ   s	   ` `   @@@r   listzConclusionScope.list   s    " 	&&((1====#
 $7GL!||!!&&##D$5$56W%. ' 
	:	R	R5	R 	R 0)ZHHr   c                   | j                   j                          | j                  | j                  d}|||d}|||d<   | j                   j                  j                  t        j                  | j                        |      }|D cg c]*  }t        j                  t        j                  |            , c}S c c}w )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
        rG   )rN   top_krH   distancerM   )r>   rZ   r@   rA   rS   rT   r   conclusions_queryr?   r   r.   r   model_validate)r)   rN   r_   r`   rH   rM   r-   items           r   rN   zConclusionScope.query   s    " 	&&(====#
  

 'D||!!&&$$T%6%67 ' 
 
 (();)J)J4)PQ
 	
 
s   	/B;c                    | j                   j                          | j                   j                  j                  t	        j
                  | j                  |             y)zy
        Delete a conclusion by ID.

        Args:
            conclusion_id: The ID of the conclusion to delete
        N)r>   rZ   rS   deleter   
conclusionr?   )r)   conclusion_ids     r   rf   zConclusionScope.delete   s?     	&&(!!&"3"3D4E4E}"UVr   c                     j                   j                          	 	 	 	 d fd}|D cg c]
  } ||       }} j                   j                  j                  t	        j
                   j                        d|i      }|D cg c]*  }t        j                  t        j                  |            , c}S c c}w c c}w )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"},
            ])
            ```
        c                    j                   j                  d}t        | t              r,| j                  |d<   | j
                  | j
                  |d<   |S | d   |d<   | j                  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.
            rG   r   r   )r@   rA   
isinstancer   r   r   get)rd   payloadr   r)   s      r   build_conclusion_payloadz8ConclusionScope.create.<locals>.build_conclusion_payload   s    .  $}}#}}'G $ 67%)\\	"??.,0OOGL)!%iGI,/J%(2%Nr   conclusionsra   )rd   z'ConclusionCreateParams | dict[str, Any]r7   zdict[str, Any])r>   rZ   rS   rT   r   ro   r?   r   r.   r   rc   )r)   ro   rn   cconclusion_paramsr-   rd   s   `      r   createzConclusionScope.create  s    . 	&&($	9$	$	L CNN+Q5a8+N||!!&&t001!23 ' 
 
 (();)J)J4)PQ
 	
 O
s   B7/B<c                x   | j                   j                          d| j                  i}|||d<   |||d<   |||d<   |||d<   |||d<   | j                   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
        targetsearch_querysearch_top_ksearch_max_distanceinclude_most_frequentmax_conclusionsra   )r>   rZ   rA   rS   rT   r   peer_representationr?   r@   r	   rc   representation)	r)   ru   rv   rw   rx   ry   rM   r-   rP   s	            r   r{   zConclusionScope.representationQ  s    0 	&&( ($--8##/D ##/D **=D&' ,,AD()&&5D"#||!!&&&&t'8'8$--H ' 
 *88>&&&r   c                V    d| j                   d| j                  d| j                  dS )NzConclusionScope(workspace_id=z, observer=z, observed=))r?   r@   rA   r5   s    r   r3   zConclusionScope.__repr__}  s8    +D,=,=+@ A(DMM3DAG	
r   )rC   r=   r?   r   r@   r   rA   r   )r7   z'ConclusionScopeAio')r   r0   N)rJ   rX   rK   rX   r[   zstr | SessionBase | Noner7   rY   )
   N)rN   r   r_   rX   r`   float | Noner7   list[Conclusion])rh   r   r7   r8   )ro   z-list[ConclusionCreateParams | dict[str, Any]]r7   r   )NNNNN)ru   r   rv   
int | Nonerw   r   rx   zbool | Nonery   r   r7   r   r9   )r   r   r   r:   r   r*   propertyrE   r]   rN   rf   rr   r{   r3   r   r   r   r   r   ^   sE   2 MM!! ! 	!
 !* ( (* ,0	-I-I -I *	-I
 
2-Id !%	&
&
 &
 	&

 
&
PWH
BH
 
H
X $(#',0-1&**' *' !*' *	*'
  +*' $*' 
*'X
r   r   )r:   
__future__r   datetimetypingr   r   pydanticr   	api_typesr   r	   baser
   httpr   
paginationr   utilsr   rE   r   clientr   __all__r   r   r   r   r   r   <module>r      sV    < "  %  A     '"Y "
: :zc
 c
r   