
    Fj                    ~    d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 dZ
dZdZddZddZddZddZddZddZdS )u  ``hermes portal`` — small CLI surface for Nous Portal users.

Subcommands:
  status   Show Portal auth state + which Tool Gateway tools are routed.
  open     Open the Portal subscription page in the user's default browser.
  tools    List Tool Gateway tools and which are active in the current config.

This command is intentionally minimal — it does not duplicate functionality
already in ``hermes auth`` or ``hermes tools``. It's a discovery + status
surface for the Portal subscription itself.
    )annotationsN)Colorscolor)load_configzhttps://portal.nousresearch.comz3https://portal.nousresearch.com/manage-subscriptionzKhttps://hermes-agent.nousresearch.com/docs/user-guide/features/tool-gatewayreturnstrc                     	 ddl m}   |             pi }|                    d          }t          |t                    r)|                                r|                    d          S n# t          $ r Y nw xY wt          S )z7Resolve the Portal base URL from auth state or default.r   get_nous_auth_statusportal_base_url/)	hermes_cli.authr   get
isinstancer   striprstrip	ExceptionDEFAULT_PORTAL_URL)r   statusurls      4/usr/local/lib/hermes-agent/hermes_cli/portal_cli.py_nous_portal_base_urlr      s    888888%%''-2jj*++c3 	#CIIKK 	#::c??"   s   A$A( (
A54A5intc                   ddl m} ddlm} t	                      pi }	  |            pi }n# t
          $ r i }Y nw xY wt          |                    d                    }t                       t          t          dt          j                             t          t          dt          j                             |r|                    d          pt          }t          dt          d	t          j                              t          d
|            |                    d          }|rt          d|            nPt          dt          dt          j                              t          dt                      t          d           t!          |                    d          t"                    r|                    d          ni }t%          |                    d          pd                                                                          }	|	dk    r+t          dt          dt          j                              n|	rt          d|	 d           t                       t          t          dt          j                             t          t          dt          j                             	  ||          }
n# t
          $ r d}
Y nw xY w|
t          d           dS g }|
                                D ]z}|j        rt          dt          j                  }n:|j        r|j        r|j        }n$|j        rd}nt          dt          j                  }|                    |j        |f           {t9          d |D             d           }|D ]\  }}t          d!|d"| d#|            |s=t                       t          t          d$t:           t          j                             dS )%z0Show Portal auth + Tool Gateway routing summary.r   r
   get_nous_subscription_features	logged_inz  Nous Portalu#     ───────────r   z  Auth:    u   ✓ logged inz  Portal:  inference_base_urlz  API:     znot logged inz  Sign up: z,  Login:   hermes auth add nous --type oauthmodelprovider nousz  Model:   u$   ✓ using Nous as inference providerz  Model:   currently z (switch with `hermes model`)z  Tool Gatewayu&     ────────────Nz(  (could not resolve subscription state)zvia Nous Portalactivenot configuredc              3  @   K   | ]}t          |d                    V  dS )r   Nlen).0rs     r   	<genexpr>z_cmd_status.<locals>.<genexpr>d   s,      ))qQqT))))))    )default  <z     Docs: )r   r   hermes_cli.nous_subscriptionr   r   r   boolr   printr   r   MAGENTAr   GREENYELLOWSUBSCRIPTION_URLr   dictr   r   loweritemsmanaged_by_nousr#   current_providerDIMappendlabelmaxDOCS_URL)argsr   r   configauthr   portal	inference	model_cfgr    featuresrowsfeatstatewidthr>   s                   r   _cmd_statusrL   &   s,   444444KKKKKK]] bF##%%+    TXXk**++I	GGG	%
0
0111	%5v~
F
FGGG 
?+,,B0BBE/6<@@BBCCC$F$$%%%HH122	 	-+	++,,,CE/6=AACCDDD.,..///=>>> (2&**W2E2Et'L'LT

7###RTI9==,,23399;;AACCH6YE"H&,WWYYZZZZ	 OMhMMMNNN 
GGG	% &.
1
1222	%8&.
I
IJJJ11&99    8999qD   	) 	) 	8+V\::EE[ 	8T2 	8)EE[ 	8EE*FJ77ETZ'(((())D)))1555E / /u-5-5----e--.... 8e)x))6:667771s   + ::9K KKc                    t           }t          d|            	 t          j        |          }n# t          $ r d}Y nw xY w|st                       t          d           dS dS )z9Open the Portal subscription page in the default browser.zOpening Fz9Could not launch a browser. Visit the URL above manually.   r   )r6   r2   
webbrowseropenr   )rA   targetopeneds      r   	_cmd_openrS   n   s    F	
V

((    IJJJq1s   0 ??c           	     X   ddl m} t                      pi }	  ||          }n,# t          $ r t	          dt
          j                   Y dS w xY wg d}t	                       t	          t          dt          j	                             t	          t          dt          j	                             |j
        s5t	          t          d	t          j                             t	                       t          d
 |D                       }|D ]\  }}}|j                            |          }	|	t          dt          j                  }
n\|	j        rt          dt          j                  }
n:|	j        r|	j        r|	j        }
n$|	j        rd}
nt          dt          j                  }
t	          d|d| d|dd|
            t	                       t	          t          dt(           t          j                             t	          t          dt*           t          j                             dS )z0List the Tool Gateway catalog + current routing.r   r   z%Could not resolve Tool Gateway state.filerN   ))webzWeb search & extract	Firecrawl)	image_genzImage generationFAL)ttszText-to-speechz
OpenAI TTS)browserzBrowser automationzBrowser Use)modalzCloud terminalModalz  Tool Gateway catalogu>     ────────────────────uS     Not logged into Nous Portal — sign in with `hermes auth add nous --type oauth`.c              3  <   K   | ]\  }}}t          |          V  d S )Nr&   )r(   _r>   s      r   r*   z_cmd_tools.<locals>.<genexpr>   s.      <<[Qqc%jj<<<<<<r+   Nunknownu   ✓ via Nous Portalr#   r$   r-   r.   z  partner: z<14 z  Manage your subscription: r/   )r0   r   r   r   r2   sysstderrr   r   r3   nous_auth_presentr5   r?   rG   r   r<   r:   r4   r#   r;   r6   r@   )rA   r   rB   rG   cataloglabel_widthkeyr>   partnerrI   rJ   s              r   
_cmd_toolsrj   }   sE   KKKKKK]] bF11&99   5CJGGGGqq
  G 
GGG	%(&.
9
9:::	%PRXR`
a
abbb% eikqkxyyzzz<<G<<<<<K& K KUG $$S))<)VZ00EE! 	8/>>EE[ 	8T2 	8)EE[ 	8EE*FJ77EI5I;IIIIGIII%IIJJJJ	GGG	%A/?AA6:
N
NOOO	%%8%%vz
2
23331s   $ %AAc                >   t          | dd          }|dv rt          |           S |dk    rt          |           S |dk    rt          |           S |dk    rt          |           S t	          d| t
          j                   t	          d	t
          j                   d
S )z4Top-level dispatch for `hermes portal <subcommand>`.portal_commandN>   Nr!   r   rP   toolszUnknown portal subcommand: rU   z!Run `hermes portal -h` for usage.rN   )getattrrL   rS   rj   r2   rc   rd   )rA   subs     r   rl   rl      s    
$($
/
/C
j 4   
h4   
f}}
g~~$	
-
-
-CJ????	
-CJ????1r+   Nonec                "   |                      ddd          }|                    d          }|                     dd	           |                     d
d	           |                     dd	           |                    t                     dS )zARegister `hermes portal` on the given argparse subparsers object.rD   z:Nous Portal status, subscription, and Tool Gateway routingzInspect Nous Portal auth, Tool Gateway routing, and open the Portal subscription page. Subcommands: status (default), open, tools.)helpdescriptionrl   )destr   z9Show Portal auth + Tool Gateway routing summary (default))rr   rP   z9Open the Portal subscription page in your default browserrm   z5List Tool Gateway tools and which are routed via Nous)funcN)
add_parseradd_subparsersset_defaultsrl   )
subparsersportal_parser
portal_subs      r   rv   rv      s    ))I	 *  M --3C-DDJH     H     D    
 N33333r+   )r   r   )r   r   )r   rp   )__doc__
__future__r   rc   rO   hermes_cli.colorsr   r   hermes_cli.configr   r   r6   r@   r   rL   rS   rj   rl   rv    r+   r   <module>r      s   
 
 # " " " " " 



     + + + + + + + + ) ) ) ) ) )6 H X
 
 
 
E E E EP   . . . .b   $4 4 4 4 4 4r+   