
    Yj                    \   d Z ddlmZ ddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZ ddlmZmZmZmZmZmZmZ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! ddl"m#Z# ddl$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z, erddl-m.Z. ddl/m0Z0  ej1        e2          Z3ddgZ4 G d dee          Z5dS )z"Sync Session class for Honcho SDK.    )annotationsN)datetime)TYPE_CHECKINGAny)
ConfigDictFieldPrivateAttrvalidate_call   )MessageCreateParamsMessageResponsePeerResponseQueueStatusResponseRepresentationResponseSessionConfigurationSessionPeerConfigSessionResponse)PeerBaseSessionBase)routes)Message)MetadataConfigMixin)SyncPage)Peer)SessionContextSessionSummariesSummary)datetime_to_isonormalize_peers_to_dictprepare_file_for_upload
resolve_id
SessionAio)HonchoSessionr   c                      e Zd ZU dZ ed          Zded<    ed          Zded<    e            Zded	<   e	dd            Z
e	dd            Zd ZddZddZddZddZddZe edd          fdd            Ze	dd            Z e ed !          "           edd#d$%           edd&          f edd'           edd(          d)d fd.            Z edd/          fdd2Z edd3          fdd4Z edd5          fdd7Zdd9Zdd=Zdd>Ze edd?          fddC            Ze eddD          dEddH            ZddIZ ddJddNZ! e ed !          "          d  eddOdPQ           eddR           eddS           eddT           edUdV           edd#dWdXY           eddZd[d\Y           edd]           edd#dWd^Y          d_
ddp            Z"ddrZ#e edd#ds%           eddt           edud#dWdvw          fdd{            Z$ e ed !          "           edd|           edd}           edd~           edd           edd          fdd            Z% e ed !          "          dd edd#dW           eddZd[          d edd#dW          ddd            Z& e ed !          "          	 	 ddd            Z' e ed !          "           edd           edd          fdd            Z(ddZ)ddZ* xZ+S )r%   a  
    Represents a session in Honcho.

    Sessions are scoped to a set of peers and contain messages/content.
    They create bidirectional relationships between peers and provide
    a context for multi-party conversations and interactions.

    Attributes:
        id: Unique identifier for this session
        workspace_id: Workspace ID for scoping operations
        metadata: Cached metadata for this session. May be stale if not recently
            fetched. Call get_metadata() for fresh data.
        configuration: Cached configuration for this session. May be stale if not
            recently fetched. Call get_configuration() for fresh data.
    N)defaultdict[str, object] | None	_metadataSessionConfiguration | None_configurationz'Honcho'_honchoreturnc                    | j         S )zRCached metadata for this session. May be stale. Use get_metadata() for fresh data.)r)   selfs    U/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/honcho/session.pymetadatazSession.metadataC   s     ~    c                    | j         S )z\Cached configuration for this session. May be stale. Use get_configuration() for fresh data.)r+   r/   s    r1   configurationzSession.configurationH   s     ""r3   c                L    | j                                          | j         j        S N)r,   _ensure_workspace_httpr/   s    r1   _get_http_clientzSession._get_http_clientN   s!    &&(((|!!r3   strc                4    t          j        | j                  S r7   )r   sessionsworkspace_idr/   s    r1   _get_fetch_routezSession._get_fetch_routeR   s    t0111r3   c                @    t          j        | j        | j                  S r7   )r   sessionr>   idr/   s    r1   _get_update_routezSession._get_update_routeU   s    ~d/999r3   dict[str, Any]c                    d| j         iS )NrB   rB   r/   s    r1   _get_fetch_bodyzSession._get_fetch_bodyX   s    dgr3   data+tuple[dict[str, object], dict[str, object]]c                r    t          j        |          }|j        pi |j                            d          fS )NTexclude_none)r   model_validater2   r5   
model_dumpr0   rH   rA   s      r1   _parse_responsezSession._parse_response[   sG     "066%2w'<'G'G (H (
 (
 
 	
r3   r   c                8   | j                                          |                                                     |                                 |                                           }t          j        |          }|j        pi | _	        |j
        | _        | j        S )z
        Get configuration from the server and update the cache.

        Returns:
            A SessionConfiguration object containing the configuration settings.
        body)r,   r8   r:   postr?   rG   r   rM   r2   r)   r5   r+   rO   s      r1   get_configurationzSession.get_configurationd   s     	&&((($$&&++!!##$*>*>*@*@ , 
 
 "066 )/R%3""r3   .zConfiguration to set)descriptionr5   Nonec                    |                                                      |                                 d|                    d          i           || _        dS )z
        Set configuration on the server and update the cache.

        Args:
            configuration: A SessionConfiguration object with configuration settings.
        r5   TrK   rR   N)r:   putrC   rN   r+   )r0   r5   s     r1   set_configurationzSession.set_configurationt   se     	##""$$!=#;#;#;#N#NO 	$ 	
 	
 	
 ,r3   'SessionAio'c                $    ddl m}  ||           S )a  
        Access async versions of all Session methods.

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

        Example:
            ```python
            session = honcho.session("session-123")

            # Async operations
            await session.aio.add_messages(peer.message("Hello"))
            async for msg in session.aio.messages():
                print(msg.content)
            ```
        r   r"   )aior#   )r0   r#   s     r1   r]   zSession.aio   s&    & 	$#####z$r3   T)arbitrary_types_allowed)configr   z"Unique identifier for this session)
min_lengthrV   zHoncho client instancezwOptional metadata dictionary to associate with this session. If set, will get/create session immediately with metadata.zgOptional configuration to set for this session. If set, will get/create session immediately with flags.r2   r5   
session_idhonchor   r2   c                  t                                          ||j                   || _        || _        || _        ||| j                                         d|i}|||d<   ||                    d          |d<   |j        	                    t          j        |j                  |          }t          j        |          }|j        | _        |j        | _        dS dS )	aY  
        Initialize a new Session.

        Provided metadata and configuration will overwrite any existing data in those
        locations if given.

        Args:
            session_id: Unique identifier for this session within the workspace
            honcho: Honcho client instance
            metadata: Optional metadata dictionary to associate with this session.
                If set, will get/create session immediately with metadata.
            configuration: Optional configuration to set for this session.
                If set, will get/create session immediately with flags.
        )rB   r>   NrB   r2   TrK   r5   rR   )super__init__r>   r,   r)   r+   r8   rN   r9   rT   r   r=   r   rM   r2   r5   )	r0   rb   rc   r2   r5   rS   rH   session_data	__class__s	           r1   rf   zSession.__init__   s    > 	, 	 	
 	
 	
 !+$(<L**,,,$(*#5D##+Z ((5(@(@d(@(S(S_%<$$V_V5H%I%IPT$UUD*9$??L)2DN"."<D )=(<r3   zPeers to add to the sessionpeersstr | PeerBase | tuple[str, SessionPeerConfig] | tuple[PeerBase, SessionPeerConfig] | list[PeerBase | str] | list[tuple[PeerBase | str, SessionPeerConfig]] | list[PeerBase | str | tuple[PeerBase | str, SessionPeerConfig]]c                    | j                                          | j         j                            t	          j        | j        | j                  t          |                     dS )af  
        Add peers to this session.

        Makes an API call to add one or more peers to this session. Adding peers
        creates bidirectional relationships and allows them to participate in
        the session's conversations.

        Args:
            peers: Peers to add to the session. Can be:
                - str: Single peer ID
                - Peer: Single Peer object
                - List[Union[Peer, str]]: List of Peer objects and/or peer IDs
                - tuple[str, SessionPeerConfig]: Single peer ID and SessionPeerConfig
                - tuple[Peer, SessionPeerConfig]: Single Peer object and SessionPeerConfig
                - List[tuple[Union[Peer, str], SessionPeerConfig]]: List of Peer objects and/or peer IDs and SessionPeerConfig
                - Mixed lists with peers and tuples/lists containing peer+config combinations
        rR   N)	r,   r8   r9   rT   r   session_peersr>   rB   r   r0   ri   s     r1   	add_peerszSession.add_peers   sd    : 	&&((( !2DG<<(// 	  	
 	
 	
 	
 	
r3   zPeers to set for the sessionc                    | j                                          | j         j                            t	          j        | j        | j                  t          |                     dS )a^  
        Set the complete peer list for this session.

        Makes an API call to replace the current peer list with the provided peers.
        This will remove any peers not in the new list and add any that are missing.

        Args:
            peers: Peers to set for the session. Can be:
                - str: Single peer ID
                - Peer: Single Peer object
                - List[Union[Peer, str]]: List of Peer objects and/or peer IDs
                - tuple[str, SessionPeerConfig]: Single peer ID and SessionPeerConfig
                - tuple[Peer, SessionPeerConfig]: Single Peer object and SessionPeerConfig
                - List[tuple[Union[Peer, str], SessionPeerConfig]]: List of Peer objects and/or peer IDs and SessionPeerConfig
                - Mixed lists with peers and tuples/lists containing peer+config combinations
        rR   N)	r,   r8   r9   rY   r   rl   r>   rB   r   rm   s     r1   	set_peerszSession.set_peers   sd    8 	&&((( !2DG<<(// 	 	
 	
 	
 	
 	
r3   z Peers to remove from the session%str | PeerBase | list[PeerBase | str]c                    | j                                          t          |t                    s|g}d |D             }| j         j                            t          j        | j        | j	                  |           dS )a  
        Remove peers from this session.

        Makes an API call to remove one or more peers from this session.
        Removed peers will no longer be able to participate in the session
        unless added back.

        Args:
            peers: Peers to remove from the session. Can be:
                   - str: Single peer ID
                   - Peer: Single Peer object
                   - List[Union[Peer, str]]: List of Peer objects and/or peer IDs
        c                J    g | ] }t          |t                    r|n|j        !S  )
isinstancer;   rB   ).0peers     r1   
<listcomp>z(Session.remove_peers.<locals>.<listcomp>/  s-    QQQ4JtS11>DDtwQQQr3   rR   N)
r,   r8   ru   listr9   deleter   rl   r>   rB   )r0   ri   peer_idss      r1   remove_peerszSession.remove_peers  s    & 	&&(((%&& 	GEQQ5QQQ!! !2DG<< 	" 	
 	
 	
 	
 	
r3   
list[Peer]c                      j                                           j         j                            t	          j         j         j                            }|                    dg           } fd|D             S )av  
        Get all peers in this session.

        Makes an API call to retrieve the list of peer IDs that are currently
        members of this session. Automatically converts the paginated response
        into a list for us -- the max number of peers in a session is usually 10.

        Returns:
            A list of Peer objects that are members of this session
        itemsc                h    g | ].}t          t          j        |          j        j                  /S rt   )r   r   rM   rB   r,   )rv   rw   r0   s     r1   rx   z!Session.peers.<locals>.<listcomp>G  sC     
 
 
 ,T225t|DD
 
 
r3   )r,   r8   r9   getr   rl   r>   rB   )r0   rH   
peers_datas   `  r1   ri   zSession.peers6  s     	&&(((#|155 !2DG<< 
  
 !%" 5 5

 
 
 
"
 
 
 	
r3   rw   str | PeerBaser   c                X   | j                                          t          |t                    r|n|j        }| j         j                            t          j        | j	        | j        |                    }t          |                    d          |                    d                    S )zC
        Get the configuration for a peer in this session.
        observe_others
observe_me)r   r   )r,   r8   ru   r;   rB   r9   r   r   session_peer_configr>   r   )r0   rw   peer_idrH   s       r1   get_peer_configurationzSession.get_peer_configurationL  s     	&&((($T3//<$$TW|!%%&t'8$'7KK
 
 !88$455xx--
 
 
 	
r3   c                :   | j                                          t          |t                    r|n|j        }i }|j        
|j        |d<   |j        
|j        |d<   | j         j                            t          j
        | j        | j        |          |           dS )zC
        Set the configuration for a peer in this session.
        Nr   r   rR   )r,   r8   ru   r;   rB   r   r   r9   rY   r   r   r>   )r0   rw   r5   r   rS   s        r1   set_peer_configurationzSession.set_peer_configurationZ  s     	&&((($T3//<$$TW!'3%2%AD!"#/!.!9D&t'8$'7KK 	 	
 	
 	
 	
 	
r3   zMessages to add to the sessionmessages/MessageCreateParams | list[MessageCreateParams]list[Message]c                   | j                                          t          |t                    s|g}d |D             }| j         j                            t          j        | j        | j	                  d|i          }d |D             S )a  
        Add one or more messages to this session.

        Makes an API call to store messages in this session. Any message added
        to a session will automatically add the creating peer to the session
        if they are not already a member.

        Args:
            messages: Messages to add to the session. Can be:
                      - MessageCreateParams: Single MessageCreateParams object
                      - List[MessageCreateParams]: List of MessageCreateParams objects
        c                <    g | ]}|                     d d          S )jsonT)moderL   )rN   rv   msgs     r1   rx   z(Session.add_messages.<locals>.<listcomp>  s5     
 
 
?BCNNTN::
 
 
r3   r   rR   c                Z    g | ](}t          j        t          j        |                    )S rt   r   from_api_responser   rM   r   s     r1   rx   z(Session.add_messages.<locals>.<listcomp>  >     
 
 
 %o&DS&I&IJJ
 
 
r3   )
r,   r8   ru   ry   r9   rT   r   r   r>   rB   )r0   r   messages_datarH   s       r1   add_messageszSession.add_messagesm  s    & 	&&((((D)) 	" zH
 
FN
 
 
 |!&&OD-tw77m, ' 
 

 

 
 
 	
r3   zDictionary of filter criteria)filtersr   "SyncPage[MessageResponse, Message]c                    j                                           j         j                            t	          j         j         j                  rdind          }ddd fdt          |t                    S )a  
        Get messages from this session with optional filtering.

        Makes an API call to retrieve messages from this session. Results can be
        filtered based on various criteria.

        Args:
            filters: Dictionary of filter criteria. Supported filters include:
                    - peer_id: Filter messages by the peer who created them
                    - metadata: Filter messages by metadata key-value pairs
                    - timestamp_start: Filter messages after a specific timestamp
                    - timestamp_end: Filter messages before a specific timestamp

        Returns:
            A list of Message objects matching the specified criteria, ordered by
            creation time (most recent first)
        r   NrR   responser   r-   r   c                *    t          j        |           S r7   )r   r   )r   s    r1   	transformz#Session.messages.<locals>.transform  s    ,X666r3   pageintr   c                    j         j                            t          j        j        j                  rdind d| i          }t          |t                    S )Nr   r   )rS   query)	r,   r9   rT   r   messages_listr>   rB   r   r   )r   	next_data
fetch_nextr   r0   r   s     r1   r   z$Session.messages.<locals>.fetch_next  sf    *//$T%6@@-4>i))$tn 0  I
 I	:NNNr3   )r   r   r-   r   )r   r   r-   r   )
r,   r8   r9   rT   r   r   r>   rB   r   r   )r0   r   rH   r   r   s   `` @@r1   r   zSession.messages  s    2 	&&(((|!&& !2DG<<)0:)W%%d ' 
 

	7 	7 	7 	7	O 	O 	O 	O 	O 	O 	O 	O 	O oy*EEEr3   c                    | j                                          | j         j                            t	          j        | j        | j                             dS )aY  
        Delete this session and all associated data.

        Makes an API call to permanently delete this session and all related data including:
        - Messages
        - Message embeddings
        - Conclusions
        - Session-Peer associations
        - Background processing queue items

        This action cannot be undone.
        N)r,   r8   r9   rz   r   rA   r>   rB   r/   s    r1   rz   zSession.delete  sH     	&&(((!!&.1BDG"L"LMMMMMr3   )
message_idr   
str | None	'Session'c               @   | j                                          i }|||d<   | j         j                            t	          j        | j        | j                  |r|nd          }t          j	        |          }t          |j        | j         |j        |j                  S )ay  
        Clone this session, optionally up to a specific message.

        Makes an API call to create a copy of this session with a new ID.
        All messages and peers from the original session are copied to the new session.
        If a message_id is provided, only messages up to and including that message
        are copied.

        Args:
            message_id: Optional message ID to cut off the clone at. If provided,
                       the cloned session will only contain messages up to and
                       including this message.

        Returns:
            A new Session object representing the cloned session

        Example:
            ```python
            # Clone entire session
            cloned = session.clone()

            # Clone session up to a specific message
            cloned = session.clone(message_id="msg_abc123")
            ```
        Nr   r   ra   )r,   r8   r9   rT   r   session_cloner>   rB   r   rM   r%   r2   r5   )r0   r   r   rH   cloneds        r1   clonezSession.clone  s    < 	&&((( "!",E,|!&& !2DG<< *%%d ' 
 
 !/55IL_ .	
 
 
 	
r3   r   z2Maximum number of tokens to include in the context)gtrV   a5  A peer ID to get context for. If given *without* `peer_perspective`, a representation and peer card will be included from the omniscient Honcho-level view of `peer_target`. If given *with* `peer_perspective`, will get the representation and card for `peer_target` *from the perspective of `peer_perspective`*.zA query string (or Message object) used to fetch semantically relevant conclusions. Use this alongside `peer_target` to get a more focused context -- does nothing if `peer_target` is not provided.zA peer ID to get context *from the perspective of*. If given, response will attempt to include representation and card from the perspective of `peer_perspective`. Must be provided with `peer_target`.FzwWhether to limit the representation to this session only. If True, only conclusions from this session will be included.d   zSNumber of semantically relevant facts to return when searching with `search_query`.)gelerV   g        g      ?zZMaximum semantic distance for search results (0.0-1.0) when searching with `search_query`.zGWhether to include the most frequent conclusions in the representation.z?Maximum number of conclusions to include in the representation.)
summarytokenspeer_targetsearch_querypeer_perspectivelimit_to_sessionsearch_top_ksearch_max_distanceinclude_most_frequentmax_conclusionsr   boolr   
int | Noner   r   str | Message | Noner   r   r   r   float | Noner   bool | Noner   r   c       
   
     Z   | j                                          ||t          d          ||t          d          t          |t                    r|j        n|}||d}|||d<   |||d<   |||d<   |||d<   |||d	<   |||d
<   |	|	|d<   |
|
|d<   | j         j                            t          j	        | j
        | j                  |          }d}|                    d          r:|d         }t          |d         |d         |d         |d         |d                   }d |                    dg           D             }t          | j        |||                    d          r"t          |                    d                    nd|                    d                    S )a  
        Get optimized context for this session within a token limit.

        Makes an API call to retrieve a curated list of messages that provides
        optimal context for the conversation while staying within the specified
        token limit. Uses tiktoken for token counting, so results should be
        compatible with OpenAI models.

        Args:
            summary: Whether to include summary information
            tokens: Maximum number of tokens to include in the context. Will default
            to Honcho server configuration if not provided.
            peer_target: A peer ID to get context for.
            search_query: A query string for semantic search.
            peer_perspective: A peer ID to get context from the perspective of.
            limit_to_session: Whether to limit the representation to this session only.
            search_top_k: Number of semantically relevant facts to return.
            search_max_distance: Maximum semantic distance for search results.
            include_most_frequent: Whether to include the most frequent conclusions.
            max_conclusions: Maximum number of conclusions to include.

        Returns:
            A SessionContext object containing the optimized message history and
            summary, if available, that maximizes conversational context while
            respecting the token limit

        Note:
            Token counting is performed using tiktoken. For models using different
            tokenizers, you may need to adjust the token limit accordingly.
        NzDYou must provide a `peer_target` when `peer_perspective` is providedz@You must provide a `peer_target` when `search_query` is provided)r   r   r   r   r   r   r   r   r   r   r   r   contentr   summary_type
created_attoken_countr   r   r   r   r   c                Z    g | ](}t          j        t          j        |                    )S rt   r   r   s     r1   rx   z#Session.context.<locals>.<listcomp>  s>     
 
 
 %o&DS&I&IJJ
 
 
r3   r   peer_representation	peer_card)rb   r   r   r   r   )r,   r8   
ValueErrorru   r   r   r9   r   r   session_contextr>   rB   r   r   r;   )r0   r   r   r   r   r   r   r   r   r   r   search_query_textr   rH   session_summarysr   s                    r1   contextzSession.context  s;   Z 	&&(((#3#?V   <#;R  
 %/|W$E$EWL  < 	
  0!
 !
 $E(O($5E.!"#.E- '(8E$%#$0E.!*+>E'( ,-BE)*&'6E#$|!%%"4#4dg>> & 
 
 88I 	YA%)\?~.\?m,  O
 
xx
B//
 
 

 w#xx-..!DHH-B$C$C D D Dhh{++
 
 
 	
r3   r   c                H   | j                                          | j         j                            t	          j        | j        | j                            }d}|                    d          r:|d         }t          |d         |d         |d         |d         |d                   }d}|                    d	          r:|d	         }t          |d         |d         |d         |d         |d                   }t          |                    d
          p| j        ||          S )a  
        Get available summaries for this session.

        Makes an API call to retrieve both short and long summaries for this session,
        if they are available. Summaries are created asynchronously by the backend
        as messages are added to the session.

        Returns:
            A SessionSummaries object containing:
            - id: The session ID
            - short_summary: The short summary if available, including metadata
            - long_summary: The long summary if available, including metadata

        Note:
            Summaries may be None if:
            - Not enough messages have been added to trigger summary generation
            - The summary generation is still in progress
            - Summary generation is disabled for this session
        Nshort_summaryr   r   r   r   r   r   long_summaryrB   )rB   r   r   )
r,   r8   r9   r   r   session_summariesr>   rB   r   r   )r0   rH   r   r   r   s        r1   	summarieszSession.summaries  s6   ( 	&&(((|!%%$T%6@@
 
 88O$$ 	_%A#)\?~.\?m,  M 88N## 	^$A")\?~.\?m,  L  xx~~('%
 
 
 	
r3   zThe search query to usezFilters to scope the search
   zNumber of results to return)r'   r   r   rV   r   limitr   c                    | j                                          | j         j                            t	          j        | j        | j                  |||d          }d |D             S )a1  
        Search for messages in this session.

        Makes an API call to search for messages in this session.

        Args:
            query: The search query to use
            filters: Filters to scope the search. See [search filters documentation](https://docs.honcho.dev/v3/documentation/core-concepts/features/using-filters).
            limit: Number of results to return (1-100, default: 10)

        Returns:
            A list of Message objects representing the search results.
            Returns an empty list if no messages are found.
        )r   r   r   rR   c                Z    g | ](}t          j        t          j        |                    )S rt   r   r   s     r1   rx   z"Session.search.<locals>.<listcomp>  r   r3   )r,   r8   r9   rT   r   session_searchr>   rB   )r0   r   r   r   rH   s        r1   searchzSession.search  sz    2 	&&(((|!&&!$"3TW== WuEE ' 
 

 

 
 
 	
r3   zxFile to upload. Can be a file object, (filename, bytes, content_type) tuple, or (filename, fileobj, content_type) tuple.z9The peer creating the messages (ID string or Peer object)z;Optional metadata dictionary to associate with the messagesz@Optional configuration dictionary to associate with the messageszWOptional created-at timestamp for the messages. Should be an ISO 8601 formatted string.file3tuple[str, bytes, str] | tuple[str, Any, str] | Anydict[str, Any] | Noner   str | datetime | Nonec                   | j                                          t          |          \  }}}t          |t                    r|n|j        }	d|	i}
|t          j        |          |
d<   |t          j        |          |
d<   t          |          }|||
d<   | j         j	        
                    t          j        | j        | j                  d|||fi|
          }d |D             S )	a#  
        Upload file to create message(s) in this session.

        Accepts a flexible payload:
        - File objects (opened in binary mode)
        - (filename, bytes, content_type) tuples
        - (filename, fileobj, content_type) tuples

        Files are normalized to (filename, fileobj, content_type) tuples for the HTTP client.

        Args:
            file: File to upload. Can be:
                - a file object (must have .name and .read())
                - a tuple (filename, bytes, content_type)
                - a tuple (filename, fileobj, content_type)
            peer: The peer who will be attributed as the creator of the messages.
                Can be a peer ID string or a Peer object.
            metadata: Optional metadata dictionary to associate with the messages
            configuration: Optional configuration dictionary to associate with the messages
            created_at: Optional created-at timestamp for the messages. Should be an ISO 8601 formatted string.

        Returns:
            A list of Message objects representing the created messages

        Note:
            Supported file types include PDFs, text files, and JSON documents.
            Large files will be automatically split into multiple messages to fit
            within message size limits.
        r   Nr2   r5   r   r   )filesrH   c                Z    g | ](}t          j        t          j        |                    )S rt   r   r   s     r1   rx   z'Session.upload_file.<locals>.<listcomp>2  r   r3   )r,   r8   r    ru   r;   rB   r   dumpsr   r9   uploadr   messages_uploadr>   )r0   r   rw   r2   r5   r   filenamecontent_bytescontent_typeresolved_peer_id	data_dictcreated_at_isor   s                r1   upload_filezSession.upload_file  s   h 	&&((( 1H0M0M-- $.dC#8#8E44dg &/0@$A	$(Jx$8$8Ij!$)-M)B)BIo&(44%&4Il#<%,,"4#4dg>>Hm\BC - 
 

 

 
 
 	
r3   )r   r   )targetr   r   r   r   r   r   str | PeerBase | Nonec               ~   | j                                          t          |          }t          |          }	d| j        i}
|	r|	|
d<   |||
d<   |||
d<   |||
d<   |||
d<   |||
d<   | j         j                            t          j        | j        |          |
	          }t          j
        |          }|j        S )
a  
        Get a subset of the representation of the peer in this session.

        Args:
            peer: Peer to get the representation of.
            target: Optional target peer to get the representation of. If provided,
            queries what `peer` knows about the `target`.
            search_query: Semantic search query to filter relevant conclusions
            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

        Example:
            ```python
            # Get peer's representation in this session
            rep = session.representation('user123')
            print(rep)

            # Get what user123 knows about assistant in this session
            local_rep = session.representation('user123', target='assistant')

            # Get representation with semantic search
            searched_rep = session.representation(
                'user123',
                search_query='preferences',
                search_top_k=10
            )
            ```
        rb   r   Nr   r   r   r   r   rR   )r,   r8   r!   rB   r9   rT   r   r   r>   r   rM   representation)r0   rw   r   r   r   r   r   r   r   	target_idr   rH   r   s                r1   r   zSession.representation7  s    Z 	&&(((T""v&&	!-tw 7 	('E(O#$0E.!#$0E.!*+>E'( ,-BE)*&'6E#$|!&&&t'8'BB ' 
 
 *8>>&&r3   observersenderr   c                6   | j                                          t          |          }t          |          }d| j        i}|r||d<   |r||d<   | j         j                            t          j        | j                  |          }t          j
        |          S )a1  
        Get the queue processing status, optionally scoped to an observer, sender, and/or session.

        Args:
            observer: Optional observer (ID string or Peer object) to scope the status check
            sender: Optional sender (ID string or Peer object) to scope the status check
        rb   observer_id	sender_idr   )r,   r8   r!   rB   r9   r   r   workspace_queue_statusr>   r   rM   )r0   r   r   resolved_observer_idresolved_sender_idr   rH   s          r1   queue_statuszSession.queue_status}  s     	&&((()(33'//!-tw 7 	8#7E-  	4!3E+|!%%)$*;<< & 
 
 #1$777r3   z*The Message object or message ID to updatez&The metadata to update for the messagemessageMessage | strdict[str, object]r   c                >   | j                                          t          |t                    r|j        n|}| j         j                            t          j        | j	        | j        |          d|i          }t          j
        t          j        |                    S )ai  
        Update the metadata of a message in this session.

        Makes an API call to update the metadata of a specific message within this session.

        Args:
            message: Either a Message object or a message ID string
            metadata: The metadata to update for the message

        Returns:
            The updated Message object
        r2   rR   )r,   r8   ru   r   rB   r9   rY   r   r   r>   r   r   rM   )r0   r   r2   r   rH   s        r1   update_messagezSession.update_message  s    , 	&&(((#-gw#?#?LWZZW
|!%%N4,dgzBBh' & 
 
 ()G)M)MNNNr3   c                    d| j          dS )z
        Return a string representation of the Session.

        Returns:
            A string representation suitable for debugging
        zSession(id='z')rF   r/   s    r1   __repr__zSession.__repr__  s     *dg))))r3   c                    | j         S )z~
        Return a human-readable string representation of the Session.

        Returns:
            The session's ID
        rF   r/   s    r1   __str__zSession.__str__  s     wr3   )r-   r(   )r-   r*   )r-   r;   )r-   rD   )rH   rD   r-   rI   )r-   r   )r5   r   r-   rW   )r-   r[   )
rb   r;   rc   r   r2   r(   r5   r*   r-   rW   )ri   rj   r-   rW   )ri   rq   r-   rW   )r-   r}   )rw   r   r-   r   )rw   r   r5   r   r-   rW   )r   r   r-   r   )r   r(   r-   r   )r-   rW   )r   r   r-   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r   )r-   r   )r   r;   r   r(   r   r   r-   r   )r   r   rw   r   r2   r(   r5   r   r   r   r-   r   )rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r;   )NN)r   r   r   r   r-   r   )r   r   r2   r   r-   r   ),__name__
__module____qualname____doc__r	   r)   __annotations__r+   r,   propertyr2   r5   r:   r?   rC   rG   rP   rU   r
   r   rZ   r]   r   rf   rn   rp   r|   ri   r   r   r   r   rz   r   r   r   r   r   r   r   r  r  r  __classcell__)rh   s   @r1   r%   r%   .   sg           +6+d*C*C*CICCCC2=+d2K2K2KNKKKK#G%%%%   X # # # X#
" " "2 2 2 2: : : :   
 
 
 
# # # #   /4e3/
 /
 /
, , , , ],$       X , ]**TBBBCCC  %A+O
 
 
 eC-EFFF2= .3U R.
 .
 .
 6;U B6
 6
 6
2= 2= 2= 2= 2= 2= 2= DC2=x MRE:M
 M
 M
!
 !
 !
 !
 !
V MRE;M
 M
 M
 
  
  
  
  
H 8=u?8
 8
 8

 
 
 
 
<
 
 
 
,
 
 
 

 
 
 
&  EJE=E
 E
 E
!
 !
 !
 !
 ]!
F  -2E=-
 -
 -
)F )F )F )F )F ])FVN N N N& "&-
 -
 -
 -
 -
 -
^ ]**TBBBCCC "UQ$X
 
 
 #(% P#
 #
 #
 .3U _.
 .
 .
 (-u b(
 (
 (
 "' R"
 "
 "
 $)5m	$
 $
 $
 -2Et	-
 -
 -
 .3Ua.
 .
 .
 ',eY	'
 '
 '
OO
 O
 O
 O
 O
 DCO
b3
 3
 3
 3
j  U31:STTT,1E;-
 -
 -
 U12O
 
 
 
  
  
  
 ] 
D ]**TBBBCCC EJE SE
 E
 E
  %uX 
  
  
 .3UU.
 .
 .
 05uZ0
 0
 0
 -2Eq-
 -
 -
#N
 N
 N
 N
 DCN
` ]**TBBBCCC
 )-#'#(5!#<#<#<,1E$33,G,G,G-1&+eDQ3&?&?&?C' C' C' C' C' DCC'J ]**TBBBCCC +/(,8 8 8 8 DC88 ]**TBBBCCC "'I"
 "
 "
 ',eE'
 '
 '
O O O O DCO<* * * *       r3   )6r	  
__future__r   r   loggingr   typingr   r   pydanticr   r   r	   r
   	api_typesr   r   r   r   r   r   r   r   baser   r   httpr   r   r   mixinsr   
paginationr   rw   r   r   r   r   r   utilsr   r   r    r!   r]   r#   clientr$   	getLoggerr  logger__all__r%   rt   r3   r1   <module>r     s;   ( ( " " " " " "         % % % % % % % % B B B B B B B B B B B B	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ( ' ' ' ' ' ' '             ' ' ' ' ' '                   F F F F F F F F F F             		8	$	$)
*[ [ [ [ [k. [ [ [ [ [r3   