
    `gj                    H    d Z ddlmZ ddlmZmZmZ ddlmZ	  G d d      Z
y)u  Gateway-side RPC client for a remote meet node.

Each call opens a short-lived synchronous WebSocket to the node, sends
exactly one request, reads exactly one response, and closes. This keeps
the client trivial to use from non-async tool handlers and avoids
maintaining persistent connection state across agent turns.

The ``websockets`` package is an optional dep — we import it lazily so
plugin load doesn't require it.
    )annotations)AnyDictOptional)protocolc                  t    e Zd ZdZdddZddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZddZdddZ	dd	Z
dd
Zy)
NodeClientzAThin synchronous WS client matching the server's request surface.c                    t        |t              r|st        d      t        |t              r|st        d      || _        || _        t        |      | _        y )Nzurl must be a non-empty stringz token must be a non-empty string)
isinstancestr
ValueErrorurltokenfloattimeout)selfr   r   r   s       R/root/.hermes/venv/lib/python3.12/site-packages/plugins/google_meet/node/client.py__init__zNodeClient.__init__   sK    #s#3=>>%%U?@@
W~    c                8   	 ddl m} t	        j
                  || j                  |      }t	        j                  |      } || j                  | j                  | j                        5 }|j                  |       |j                  | j                        }ddd       t        t        t        f      r|j                  d      }t	        j                  |      }	|	j!                  d      d	k(  rt        d
|	j!                  d	d             |	j!                  d      |d   k7  r#t        d|d    d|	j!                  d            |	j!                  d      }
t        |
t"              st        d      |
S # t        $ r}t        d      |d}~ww xY w# 1 sw Y   xY w)zSend one request, return the response payload dict.

        Raises RuntimeError when the server sends an ``error`` envelope
        or the response id doesn't match.
        r   )connectzUNodeClient requires the 'websockets' package. Install it with: pip install websocketsN)open_timeoutclose_timeout)r   zutf-8typeerrorznode error: z	<unknown>idzresponse id mismatch: sent z, got payloadzresponse missing payload dict)websockets.sync.clientr   ImportErrorRuntimeError_protomake_requestr   encoder   r   sendrecvr   bytes	bytearraydecodegetdict)r   r   r   r   excreqraw_outwsraw_inresppayload_outs              r   _rpczNodeClient._rpc!   st   	6 !!$

G<--$TXXDLL#'<<1 	346GGGWWT\\W2F	3
 fui01]]7+F}}V$88Fw&dhhw.L-MNOO88D>SY&-c$i[txx~>PQ  hhy)+t,>??9  	: 		3 	3s#   E3 '.F3	F<FFFNc                T    ||t        |      |d}|||d<   | j                  d|      S )N)r   
guest_nameheadedmodeduration	start_bot)boolr2   )r   r   r4   r7   r5   r6   r   s          r   r8   zNodeClient.start_botI   s>     $6l	#
 "*GJyyg..r   c                &    | j                  di       S )Nstopr2   r   s    r   r;   zNodeClient.stop[       yy$$r   c                &    | j                  di       S )Nstatusr<   r=   s    r   r@   zNodeClient.status^   s    yy2&&r   c                J    i }|t        |      |d<   | j                  d|      S )Nlast
transcript)intr2   )r   rB   r   s      r   rC   zNodeClient.transcripta   s+    "$!$iGFOyyw//r   c                <    | j                  ddt        |      i      S )Nsaytext)r2   r   )r   rG   s     r   rF   zNodeClient.sayg   s    yyT 344r   c                &    | j                  di       S )Npingr<   r=   s    r   rI   zNodeClient.pingj   r>   r   )g      $@)r   r   r   r   r   r   returnNone)r   r   r   Dict[str, Any]rJ   rL   )zHermes AgentNF
transcribe)r   r   r4   r   r7   zOptional[str]r5   r9   r6   r   rJ   rL   )rJ   rL   )N)rB   zOptional[int]rJ   rL   )rG   r   rJ   rL   )__name__
__module____qualname____doc__r   r2   r8   r;   r@   rC   rF   rI    r   r   r	   r	      sv    K&$V )"& // /  	/
 / / 
/$%'05%r   r	   N)rQ   
__future__r   typingr   r   r   plugins.google_meet.noder   r!   r	   rR   r   r   <module>rV      s$   	 # & & 7X% X%r   