
    #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`` — the human-readable entry point for Nous Portal.

Running ``hermes portal`` with no subcommand performs the one-shot Portal
onboarding: OAuth login, pick a Nous model, switch the inference provider to
Nous, and offer to enable the Tool Gateway. It is the friendly alias for
``hermes auth add nous --type oauth`` (which still works), is identical to
``hermes setup --portal``, and runs the same Nous flow as the first-time quick
setup.

Subcommands:
  (none)   Log in to Nous Portal + set it up (one-shot onboarding).
  login    Explicit alias for the default one-shot onboarding.
  info     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 the onboarding + discovery
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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   )get_nous_auth_statusget_nous_subscription_features	logged_inz  Nous Portalu#     ───────────portal_base_urlz  Auth:    u   ✓ logged inz  Portal:  inference_base_urlz  API:     znot logged inz  Sign up: z  Login:   hermes portal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     :/home/ubuntu/.hermes/hermes-agent/hermes_cli/portal_cli.py	<genexpr>z_cmd_status.<locals>.<genexpr>`   s,      ))qQqT))))))    )default  <z     Docs: )hermes_cli.authr
   hermes_cli.nous_subscriptionr   r   	Exceptionboolgetprintr   r   MAGENTADEFAULT_PORTAL_URLGREENYELLOWSUBSCRIPTION_URL
isinstancedictstrstrip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widthr7   s                   r   _cmd_statusrE   "   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   )r,   r'   
webbrowseropenr$   )r:   targetopeneds      r   	_cmd_openrL   j   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.filerG   ))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>     ────────────────────u?     Not logged into Nous Portal — sign in with `hermes portal`.c              3  <   K   | ]\  }}}t          |          V  d S )Nr   )r   _r7   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!   )r#   r   r   r$   r'   sysstderrr   r   r(   nous_auth_presentr+   r8   r@   r&   r5   r3   r*   r   r4   r,   r9   )r:   r   r;   r@   cataloglabel_widthkeyr7   partnerrB   rC   s              r   
_cmd_toolsrc   y   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UW]Wdeefff<<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                    ddl m} t                      pi }	  ||           n5# t          t          f$ r! t                       t          d           Y dS w xY wdS )a  Run the one-shot Nous Portal onboarding (login + model + provider + tools).

    This is the human-readable front door for `hermes auth add nous --type
    oauth`. It reuses the exact wiring behind `hermes setup --portal` (which in
    turn runs the same Nous flow as the first-time quick setup), so the
    commands stay in lockstep: device-code login, pick a Nous model, switch the
    inference provider to Nous, then offer the Tool Gateway opt-in.
    r   )_run_portal_one_shotzPortal setup cancelled.rG   )hermes_cli.setupre   r   KeyboardInterruptEOFErrorr'   )r:   re   r;   s      r   
_cmd_loginri      s     655555]] bFV$$$$x(   '(((qq 1s   $ .AAc                :   t          | dd          }|dv rt          |           S |dv 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   login>   infostatusrI   toolszUnknown portal subcommand: rN   z!Run `hermes portal -h` for usage.rG   )getattrri   rE   rL   rc   r'   r\   r]   )r:   subs     r   rk   rk      s    
$($
/
/C
!!! $
   4   
f}}
g~~$	
-
-
-CJ????	
-CJ????1r   Nonec                z   |                      ddd          }|                    d          }|                     dd	           |                     d
d	           |                     d           |                     dd	           |                     dd	           |                    t                     dS )zARegister `hermes portal` on the given argparse subparsers object.r=   zLSet up Nous Portal (login, model pick, Tool Gateway); see also `portal info`u0  Run `hermes portal` with no subcommand to log in to Nous Portal and set it up — pick a model, set Nous as your provider, and offer the Tool Gateway (the human-readable alias for `hermes auth add nous --type oauth`, identical to `hermes setup --portal`). Subcommands: login (default), info, open, tools.)helpdescriptionrk   )destrl   z@Log in to Nous Portal + set it up (default; one-shot onboarding))rt   rm   z/Show Portal auth + Tool Gateway routing summaryrn   rI   z9Open the Portal subscription page in your default browserro   z5List Tool Gateway tools and which are routed via Nous)funcN)
add_parseradd_subparsersset_defaultsrk   )
subparsersportal_parser
portal_subs      r   rx   rx      s   ))[?	 * 
 
M --3C-DDJO     >    
 (###H     D    
 N33333r   )r   r   )r   rr   )__doc__
__future__r   r\   rH   hermes_cli.colorsr   r   hermes_cli.configr   r)   r,   r9   rE   rL   rc   ri   rk   rx    r   r   <module>r      s    ( # " " " " " 



     + + + + + + + + ) ) ) ) ) )6 H XE E E EP   . . . .b   *   ("4 "4 "4 "4 "4 "4r   