§
    øžyj% ã                  ó0   — d Z ddlmZ  G d„ d¦  «        ZdS )u  Billing and subscription handlers for the interactive CLI (god-file decomposition).

This module hosts the Nous billing/subscription methods lifted out of
``cli.py``'s ``HermesCLI`` class. ``HermesCLI`` inherits
``CLIBillingMixin`` so every ``self.<handler>`` call resolves unchanged
via the MRO â€” behavior-neutral apart from focused billing fixes.

Import discipline mirrors ``hermes_cli.cli_commands_mixin``:
  * Neutral, non-cyclic dependencies are imported at module top level below.
  * cli.py-internal symbols (the ``_cprint``/``_b``/``_d`` helpers and
    display constants) are imported LAZILY inside each method via
    ``from cli import ...``. The mixin never imports ``cli`` at module load
    time, avoiding the cycle created when ``cli.py`` imports this mixin.
é    )Úannotationsc                  ó  — e Zd ZdZd3d„Zd4d„Zd„ Zd„ Zd5d„Zd„ Z	ddœd„Z
d„ Zd„ Zddœd„Zd„ Zd6ddœd„Zddœd„Zd„ Zd„ Zd7d8d„Zdd œd9d"„Zd#„ Zd:d%„Zd&„ Zd3d'„Zd(„ Zd)„ Zd*„ Zd+„ Zd,„ Zd-„ Zddd.œd/„Zd0„ Z d1„ Z!d2„ Z"dS );ÚCLIBillingMixinz@Mixin holding interactive-CLI billing and subscription handlers.ÚreturnÚboolc                ó.  — ddl m}m}m} 	 ddlm}m}  |¦   «         }n# t          $ r d}d}Y nw xY w|��&|j        �r|��d}|j	        p|j
        dk    rdnd}t          |dd¦  «        p ||j        ¦  «        }	|	rd	|	› �nd
}
|r,t          ¦   «           |d |d|› |
› �¦  «        › �¦  «         d}|                      ||j	        ¦  «        D ]} ||¦  «         d}Œ|j        r|j        � |d|j        d›�¦  «         |j
        dk    r |d |d¦  «        › �¦  «         d}n5|j
        dk    r*|j        �d|j        d›�nd}d|› d�} |d|› �¦  «         d}|rdS ddlm}  |¦   «         }|sdS t          ¦   «          |D ]}t          d|› �¦  «         ŒdS )u½  Print the Nous dollar balance block (two-bar view) when a Nous account
        is logged in. Returns True if it printed anything.

        Prefers the shared dollar usage model (``agent.billing_usage`` â€” two-bar
        plan/top-up view, dollars-only, the /usage + /subscription source of
        truth). Falls back to the legacy ``nous_credits_lines`` text only when the
        model is unavailable. Agent-independent (a portal fetch gated on "a Nous
        account is logged in"), so /usage shows the block even in the TUI
        slash-worker subprocess that resumes WITHOUT a live agent. Fail-open and
        wall-clock-bounded; honors HERMES_DEV_CREDITS_FIXTURE for offline testing.
        r   ©Ú_cprintÚ_bÚ_d)Úbuild_usage_modelÚformat_renewsNFÚfreeÚFreeÚrenews_displayõ    Â· renews Ú ú  úPlan: Tú  Total spendable: $ú,.2fuC   > Free Â· free models only. Run /subscription to reach paid models.Úlowú$úunder $5õ   ! Low balance Â· z# left. Run /topup or /subscription.)Únous_credits_lines)Úclir
   r   r   Úagent.billing_usager   r   Ú	ExceptionÚ	availableÚ	plan_nameÚstatusÚgetattrÚ	renews_atÚprintÚ_usage_bar_linesÚ	has_topupÚtotal_spendable_usdÚagent.account_usager   )Úselfr
   r   r   r   r   ÚusageÚprinted_anyÚplanr   ÚrenewsÚ_bar_lnÚ_amtÚ_lowr   ÚlinesÚlines                    úB/home/ragecks/.hermes/hermes-agent/hermes_cli/cli_billing_mixin.pyÚ_print_nous_credits_blockz)CLIBillingMixin._print_nous_credits_block   sŸ  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'ð	!ØLÐLÐLÐLÐLÐLÐLÐLà%Ð%Ñ'Ô'ˆEˆEøÝð 	!ð 	!ð 	!ØˆEØ ˆMˆMˆMð	!øøøð Ñ ¤Ñ°]Ñ5NØˆKØ”?ÐR°´ÀÒ1GÐ1G v vÈTˆDÝ$ UÐ,<¸dÑCÔCÐeÀ}À}ÐUZÔUdÑGeÔGeˆNØ7EÐMÐ3 >Ð3Ð3Ð3È2ˆFØð #Ý‘”�Ø�Ð:˜R˜RÐ 7¨Ð 7¨vÐ 7Ð 7Ñ8Ô8Ð:Ð:Ñ;Ô;Ð;Ø"�ð  ×0Ò0°¸¼ÑHÔHð #ð #�Ø�˜Ñ Ô Ð Ø"��ØŒð Q 5Ô#<Ð#HØ�ÐO¨uÔ/HÐOÐOÐOÑPÔPÐPàŒ|˜vÒ%Ð%Ø�Ðh˜R˜RÐ eÑfÔfÐhÐhÑiÔiÐiØ"��Ø” Ò&Ð&Ø?DÔ?XÐ?dÐ;˜5Ô4Ð;Ð;Ð;Ð;Ðjt�ØT¨4ÐTÐTÐT�Ø�˜˜T˜˜Ñ$Ô$Ð$Ø"�àð Ø�tð 	;Ð:Ð:Ð:Ð:Ð:à"Ð"Ñ$Ô$ˆØð 	Ø�5Ý‰ŒˆØð 	ð 	ˆDÝ�+�t�+�+ÑÔÐÐØˆts   Œ Ÿ0¯0ÚNonec                óD   — ddl m}m}  |d |d¦  «        › �¦  «         dS )aE  Print the `/usage` call-to-action pointing at /subscription + /topup.

        Mirrors the TUI's ``USAGE_CTA`` (``session.ts``) so every surface ends a
        usage read with the same nudge. Only called when a Nous account is logged
        in (the balance block printed), since both commands are Nous-account only.
        r   ©r
   r   r   uA   Run /subscription to change plan Â· /topup to add to your balanceN)r   r
   r   )r*   r
   r   s      r4   Ú_print_usage_ctaz CLIBillingMixin._print_usage_ctaX   sF   € ð 	$Ð#Ð#Ð#Ð#Ð#Ð#Ð#àˆÐ^�R�RÐ[Ñ\Ô\Ð^Ð^Ñ_Ô_Ð_Ð_Ð_ó    c                óè  — ddl m}m}m} ddlm}m}  |¦   «         }|j        s]t          ¦   «          |j	        r  |d |d|j	        › �¦  «        › �¦  «         n& |d |d¦  «        › �¦  «         t          d¦  «         dS |j
        d	k    rÇt          ¦   «           |d
 |d¦  «        › �¦  «         t          dd› �¦  «         |j        rE|j        pd                     ¦   «         }d|j        › |rd|› �nd› �} |d ||¦  «        › �¦  «         |j        pd}	t          d|	› d�¦  «         t          d¦  «          |d |d¦  «        › �¦  «         dS |                      | ||¦  «        ¦  «         dS )u£  `/subscription` (alias `/upgrade`) â€” view the Nous plan + browser hand-off.

        The CLI mirror of the TUI ``SubscriptionOverlay``: a read of the current
        plan, this cycle's subscription credits, renewal date, and the plans you
        could switch to â€” then a deep-link to NAS's own ``/manage-subscription``
        page (NOT the Stripe portal; that page routes upgradeâ†’Checkout /
        downgradeâ†’scheduled internally). The terminal NEVER charges for a
        subscription. Fail-open: logged-out / portal hiccup degrades to a clear
        message, never a crash. Mirrors ``_show_billing``
        discipline for the interactive-vs-text split.
        r   r	   )Úbuild_subscription_stateÚsubscription_manage_urlõ     ðŸ’³ zCould not load subscription: úNot logged into Nous Portal.z4  Run `hermes portal` to log in, then /subscription.NÚteamõ     âš• zTeam subscriptionr   õ{   â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€r   úOrg: õ    Â· z
a team orgz   This terminal is connected to z. Teams run on a sharedu%     balance Â· use /topup to add funds.z5Personal subscriptions live on your personal account.)r   r
   r   r   Úagent.subscription_viewr<   r=   Ú	logged_inr%   ÚerrorÚcontextÚorg_nameÚroleÚtitleÚ_subscription_overview)
r*   r
   r   r   r<   r=   ÚstaterJ   Ú	_org_lineÚorgs
             r4   Ú_show_subscriptionz"CLIBillingMixin._show_subscriptiong   s  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'à]Ð]Ð]Ð]Ð]Ð]Ð]Ð]à(Ð(Ñ*Ô*ˆàŒð 	Ý‰GŒGˆGØŒ{ð NØ�ÐU " "Ð%RÀUÄ[Ð%RÐ%RÑ"SÔ"SÐUÐUÑVÔVÐVÐVà�ÐF " "Ð%CÑ"DÔ"DÐFÐFÑGÔGÐGÝÐLÑMÔMÐMØˆFð Œ=˜FÒ"Ð"Ý‰GŒGˆGØˆGÐ6˜R˜RÐ 3Ñ4Ô4Ð6Ð6Ñ7Ô7Ð7ÝÐ#�zÐ#Ð#Ñ$Ô$Ð$ØŒ~ð .Øœ
Ð( b×/Ò/Ñ1Ô1�ØS E¤NÐSÀTÐ4Q°M¸4°M°M°MÈrÐSÐS�	Ø�Ð,˜R˜R 	™]œ]Ð,Ð,Ñ-Ô-Ð-Ø”.Ð0 LˆCÝÐQ°SÐQÐQÐQÑRÔRÐRÝÐ9Ñ:Ô:Ð:ØˆGÐV˜˜ÐSÑTÔTÐVÐVÑWÔWÐWØˆFà×#Ò# EÐ+BÐ+BÀ5Ñ+IÔ+IÑJÔJÐJÐJÐJr:   c                óÄ  — ddl m}m}m} ddlm} 	 ddlm}  |¦   «         }n# t          $ r d}Y nw xY w|j        }	|	o|	j	         }
|j
        }|	r|	j        p|	j	        n
|r|j        nd}|rt          |dd¦  «        nd}| }|rt          |dd¦  «        nd}|s|	r|	j        r ||	j        ¦  «        }d}|	r
|	j        rd	}n|	r|	j        r
d
|	j        › �}|sd}n^|�$|dk    r|j        �d|j        d›�}d|› |› d|› d�}n8|rt          |dd¦  «        nd}|�d|d›d�nd}|rdn|rd|› �nd}d|› |› |› |› �}d}|	r&|	j        r ||	j        ¦  «        pd}|	j        pdd|f}n,|	r*|	j        r# ||	j        ¦  «        pd}|	j        pd|	j        |f} |d¦  «         |rc|\  }}} |d |d¦  «        › �¦  «          |d|› d|› d |d|z   ¦  «        › �¦  «          |d |d|› d �¦  «        › �¦  «          |d¦  «          |d! ||¦  «        › �¦  «         t)          dd"› �¦  «         |                      ||¦  «        D ]}t)          |¦  «         Œ|r:t          |d#d$¦  «        r)t          |dd¦  «        �t)          d%|j        d›�¦  «         |
r |d |d&¦  «        › �¦  «         n0|dk    r*|�|j        �d|j        d›�nd'}d(|› d)�} |d|› �¦  «         |j        rE|j        pd                     ¦   «         }d*|j        › |rd|› �nd› �} |d ||¦  «        › �¦  «         t)          dd"› �¦  «         |s;t)          ¦   «           |d |d+¦  «        › �¦  «         |rt)          d,|› �¦  «         dS t          | d-d¦  «        s3t)          ¦   «          |r!t)          d.|› �¦  «         t)          d/¦  «         dS |
r|                      ||¦  «         dS |                      ||¦  «         dS )0u†  Print the plan read block, then the browser hand-off to manage it.

        Dollars-only (no "credits") â€” mirrors the TUI overlay: a status line, the
        shared two-bar dollar usage view (plan + top-up) with the plan name on
        the bar, and state-matched free/low nudges. No in-terminal tier picker â€”
        the only action is managing the subscription on the portal.
        r   r	   ©r   ©r   Nr"   r   r   u    â†’ cancelsu    â†’ u   Plan: Free Â· free models onlyr   r   r   r   rD   z leftr(   u    Â· $u    Â· view onlyr   úthe end of the billing periodú	your planÚcancelszthe end of the cycleu     â�³ zScheduled changer   u    â”€â”€â–¶ u   Â· z	You keep z (and its credits) until then.rA   rB   r'   Fr   z;> Paid models need a subscription. Start one to reach them.r   r   z1 left. Top up or upgrade before a mid-run cutoff.rC   z%Plan changes need an org admin/owner.ú  Manage on portal: Ú_appz  Manage your subscription: z5  Open it in your browser, then re-run /subscription.)r   r
   r   r   r   r   r   r   ÚcurrentÚtier_idÚcan_change_planÚ	tier_namer!   r#   Úcycle_ends_atÚcancel_at_period_endÚpending_downgrade_tier_namer(   Úcancellation_effective_atÚpending_downgrade_atr%   r&   rI   rJ   rK   Ú_subscription_free_catalogÚ_subscription_change_menu)r*   rM   Ú
manage_urlr
   r   r   r   r   r+   ÚcÚis_freeÚ
can_changer!   Úu_statusÚ	view_onlyr   Ú_flipr"   Ú_totÚ_spendÚ_leftÚ_tailÚ_transÚ_whenÚ_fromÚ_tor/   r0   r1   rJ   rN   s                                  r4   rL   z&CLIBillingMixin._subscription_overview“   s-  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'ð 	6Ð5Ð5Ð5Ð5Ð5ð	Ø=Ð=Ð=Ð=Ð=Ð=à%Ð%Ñ'Ô'ˆEˆEøÝð 	ð 	ð 	ØˆEˆEˆEð	øøøð ŒMˆØ�˜QœYÐ'ˆØÔ*ˆ
à23Ð]�Q”[Ð- A¤IøÈUÐ:\¸%¼/¸/ÐX\ˆ	Ø5:ÐD•7˜5 (¨DÑ1Ô1Ð1ÀˆØ"�Nˆ	ØCHÐR� Ð(8¸$Ñ?Ô?Ð?ÈdˆØð 	< !ð 	<¨¬ð 	<Ø*˜]¨1¬?Ñ;Ô;ˆNð ˆØð 	<�Ô'ð 	<Ø"ˆEˆEØð 	<�1Ô0ð 	<Ø;˜AÔ9Ð;Ð;ˆEØð 		?Ø5ˆFˆFØÐ 8¨uÒ#4Ð#4¸Ô9RÐ9^Ø7�uÔ0Ð7Ð7Ð7ˆDØ?˜iÐ?¨Ð?Ð?°DÐ?Ð?Ð?ˆFˆFàDIÐS•W˜UÐ$9¸4Ñ@Ô@Ð@ÈtˆFØ28Ð2DÐ.˜FÐ.Ð.Ð.Ð.Ð.È"ˆEØ'0Ðp�O�OÐYgÐ7oÐ7UÀ^Ð7UÐ7UÐ7UÐmoˆEØ>˜iÐ>¨Ð>°Ð>°uÐ>Ð>ˆFð
 ˆØð 	Z�Ô'ð 	ZØ!�M !Ô"=Ñ>Ô>ÐaÐBaˆEØ”{Ð1 k°I¸uÐEˆFˆFØð 	Z�1Ô0ð 	ZØ!�M !Ô"8Ñ9Ô9ÐSÐ=SˆEØ”{Ð1 k°AÔ4QÐSXÐYˆFØˆ�‰ŒˆØð 	Ø &ÑˆE�3˜ØˆGÐ5˜R˜RÐ 2Ñ3Ô3Ð5Ð5Ñ6Ô6Ð6ØˆGÐE˜ÐEÐE¨3ÐEÐE°"°"°U¸U±]Ñ2CÔ2CÐEÐEÑFÔFÐFØˆGÐP˜˜ÐM¨ÐMÐMÐMÑNÔNÐPÐPÑQÔQÐQØˆG�B‰KŒKˆKàˆÐ%˜˜˜F™œÐ%Ð%Ñ&Ô&Ð&ÝÐ�:ÐÐÑ Ô Ð ð ×,Ò,¨U°IÑ>Ô>ð 	ð 	ˆGÝ�'‰NŒNˆNˆNØð 	K•W˜U K°Ñ7Ô7ð 	K½GÀEÐK`ÐbfÑ<gÔ<gÐ<sÝÐI¨Ô)BÐIÐIÐIÑJÔJÐJð ð 	!ØˆGÐ\˜˜ÐYÑZÔZÐ\Ð\Ñ]Ô]Ð]Ð]Ø˜ÒÐØ;@Ð;LÐQVÔQjÐQvÐ7�uÔ0Ð7Ð7Ð7Ð7ð  }GˆDØ^ tÐ^Ð^Ð^ˆDØˆG�K˜�K�KÑ Ô Ð àŒ>ð 	*Ø”JÐ$ "×+Ò+Ñ-Ô-ˆDØO ¤ÐOÀÐ0M°°t°°°È2ÐOÐOˆIØˆGÐ(˜˜˜I™œÐ(Ð(Ñ)Ô)Ð)ÝÐ�:ÐÐÑ Ô Ð ð
 ð 	Ý‰GŒGˆGØˆGÐF˜˜ÐCÑDÔDÐFÐFÑGÔGÐGØð ;ÝÐ9¨ZÐ9Ð9Ñ:Ô:Ð:ØˆFå�t˜V TÑ*Ô*ð 	å‰GŒGˆGØð OÝÐA°ZÐAÐAÑBÔBÐBÝÐMÑNÔNÐNØˆFàð 	ð ×+Ò+¨E°:Ñ>Ô>Ð>ØˆFð 	×&Ò& u¨jÑ9Ô9Ð9Ð9Ð9ó   ’# £2±2ÚurlÚstrc                óÚ   — |sdS 	 ddl m}m}  |¦   «         s
 |¦   «         sdS n# t          $ r Y nw xY w	 ddl}t          |                     |¦  «        ¦  «        S # t          $ r Y dS w xY w)a\  Open ``url`` in a REAL graphical browser; return whether one opened.

        The one opener behind every "open the portal" path in this mixin. Applies
        the same console-browser / remote-session guard the device-code auth flows
        use (``hermes_cli.auth``): ``webbrowser.open()`` returns ``True`` even when
        it launched a text-mode browser (w3m/lynx over SSH) that hijacks the TTY,
        so we refuse those and let the caller print the URL instead. Returns
        ``False`` on any guard refusal or open failure, ``True`` only when a real
        graphical browser launched.
        Fr   )Ú_can_open_graphical_browserÚ_is_remote_sessionN)Úhermes_cli.authrw   rx   r   Ú
webbrowserr   Úopen)r*   rt   rw   rx   rz   s        r4   Ú_open_url_in_browserz$CLIBillingMixin._open_url_in_browser  sÇ   € ð ð 	Ø�5ð	ØWÐWÐWÐWÐWÐWÐWÐWà!Ð!Ñ#Ô#ð Ð+FÐ+FÑ+HÔ+Hð Ø�uðøåð 	ð 	ð 	àˆDð	øøøð	ØÐÐÐå˜
Ÿš¨Ñ,Ô,Ñ-Ô-Ð-øÝð 	ð 	ð 	Ø�5�5ð	øøøs   †% ¥
2±2¶%A Á
A*Á)A*c           	     óx  ‡‡— ddl m}m}m} ddlmŠm}m}  ||¦  «        }|s|                      ||d¬¦  «         dS t          ¦   «           |d |d¦  «        › �¦  «         t          d	d
› �¦  «         t          |d¦  «        D ]#\  }	}
t          d	|	› d ‰|
¦  «        › �¦  «         Œ$ |d	 |d¦  «        › �¦  «         ˆfd„|D ¦   «         }|                     d¦  «         |                      dd|¬¦  «        }|pd                     ¦   «         }|                     ¦   «         rHdt          |¦  «        cxk    rt!          |¦  «        k    r!n n|t          |¦  «        dz
           j        Šn|                      ||¦  «        Š‰r‰dk    rt          d¦  «         dS  ||‰¬¦  «        p|}|s |d	 |d¦  «        › �¦  «         dS t'          ˆfd„|D ¦   «         d¦  «        }|r|j        nd}|                      |¦  «        rt          d|› d�¦  «         nt          d|› d|› �¦  «         t          d¦  «         dS )u‘  Free + admin/owner + interactive: print the plan catalog, pick one, then
        open the portal manage-subscription deep-link with ``plan=<tier_id>``.

        The catalog mirrors the TUI Free rows (name Â· $/mo Â· $credits/mo, from the
        same ``tiers[]`` data via the shared ``selectable_tiers`` / ``format_tier_row``
        helpers). Monthly credits are DOLLARS â€” rendered ``$X credits/mo`` (hidden
        when absent/zero). Starting a NEW subscription needs a fresh card, so the
        only action is the portal hand-off (the terminal never charges here); the
        picked tier rides along as ``plan=`` so the portal preselects it.
        r   r	   )Úformat_tier_rowÚselectable_tiersr=   zStart a subscription©ÚverbNrA   zChoose a planr   rB   é   z. z:Starting a subscription opens the portal to add your card.c                óH   •— g | ]}|j          ‰|¦  «        d |j        › d�f‘ŒS )zstart z on the portal)rZ   Úname)Ú.0Útr~   s     €r4   ú
<listcomp>z>CLIBillingMixin._subscription_free_catalog.<locals>.<listcomp>D  s;   ø€ ÐcÐcÐcÐXY�A”I˜˜¨qÑ1Ô1Ð3R¸A¼FÐ3RÐ3RÐ3RÐSÐcÐcÐcr:   ©ÚcancelÚCancelú
do nothingz%Pick a plan to open it on the portal.©rK   ÚdetailÚchoicesr   r‰   u"     ðŸŸ¡ Cancelled. No plan started.©rZ   õ6   No manage URL available â€” is your portal configured?c              3  ó2   •K  — | ]}|j         ‰k    ¯|V — Œd S ©Nr�   )r…   r†   Úchoices     €r4   ú	<genexpr>z=CLIBillingMixin._subscription_free_catalog.<locals>.<genexpr>[  s/   øè è € Ð?Ð?˜Q¨1¬9¸Ò+>Ð+>�qÐ+>Ð+>Ð+>Ð+>Ð?Ð?r:   rU   z  Opening the portal to start u   â€¦z  Open this URL to start ú: ú4  Finish in your browser, then re-run /subscription.)r   r
   r   r   rE   r~   r   r=   Ú_subscription_open_portalr%   Ú	enumerateÚappendÚ_prompt_text_input_modalÚstripÚisdigitÚintÚlenrZ   Ú_normalize_slash_confirm_choiceÚnextr„   r|   )r*   rM   rd   r
   r   r   r   r=   ÚtiersÚir†   rŽ   ÚrawÚ_digitÚtier_urlÚpickedÚlabelr“   r~   s                    @@r4   rb   z*CLIBillingMixin._subscription_free_catalog$  s'  øø€ ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'ð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð !Ð  Ñ'Ô'ˆØð 	à×*Ò*¨5°*ÐCYÐ*ÑZÔZÐZØˆFå‰ŒˆØˆÐ.˜˜˜OÑ,Ô,Ð.Ð.Ñ/Ô/Ð/ÝÐ�:ÐÐÑ Ô Ð Ý˜e QÑ'Ô'ð 	2ð 	2‰DˆAˆqÝÐ0�qÐ0Ð0˜O˜O¨AÑ.Ô.Ð0Ð0Ñ1Ô1Ð1Ð1ØˆÐW�R�RÐTÑUÔUÐWÐWÑXÔXÐXàcÐcÐcÐcÐ]bÐcÑcÔcˆØ�ŠÐ9Ñ:Ô:Ð:Ø×+Ò+Ø(Ø:Øð ,ñ 
ô 
ˆð �)˜×"Ò"Ñ$Ô$ˆØ�>Š>ÑÔð 	H ¥S¨¡[¤[Ð >Ð >Ò >Ð >µC¸±J´JÒ >Ð >Ð >Ð >Ð >Ø�3˜v™;œ;¨™?Ô+Ô3ˆFˆFà×9Ò9¸#¸wÑGÔGˆFØð 	˜ 8Ò+Ð+ÝÐ6Ñ7Ô7Ð7ØˆFð +Ð*¨5¸&ÐAÑAÔAÐOÀZˆØð 	ØˆGÐW˜˜ÐTÑUÔUÐWÐWÑXÔXÐXØˆFÝÐ?Ð?Ð?Ð? %Ð?Ñ?Ô?ÀÑFÔFˆØ%Ð6�”�¨;ˆØ×$Ò$ XÑ.Ô.ð 	CÝÐ=°5Ð=Ð=Ð=Ñ>Ô>Ð>Ð>õ ÐA¨eÐAÐA°xÐAÐAÑBÔBÐBÝÐDÑEÔEÐEÐEÐEr:   úManage your subscriptionr€   c               óL  — ddl m}m} |s't          ¦   «           |d |d¦  «        › �¦  «         dS t          ¦   «          d|dfdd	g}|                      |d
|¬¦  «        }|                      ||¦  «        }|dk    rF|                      |¦  «        st          d|› �¦  «         t          ¦   «          t          d¦  «         dS |dk    rM	 |                      |¦  «         t          d|› �¦  «         dS # t          $ r t          d|› �¦  «         Y dS w xY wt          d¦  «         dS )u@   Open / copy the manage-subscription URL â€” the portal hand-off.r   r8   r   r�   Nr{   z*open the subscription page in your browser)Úcopyz	Copy linkz2copy the manage-subscription URL to your clipboardrˆ   r   rŒ   ú  Open this URL: r–   rª   u     ðŸ“‹ Copied: z  Manage URL: õ     ðŸŸ¡ Cancelled.)	r   r
   r   r%   rš   rŸ   r|   Ú_write_osc52_clipboardr   )	r*   rM   rd   r�   r
   r   rŽ   r£   r“   s	            r4   r—   z)CLIBillingMixin._subscription_open_portale  s�  € à#Ð#Ð#Ð#Ð#Ð#Ð#Ð#àð 	Ý‰GŒGˆGØˆGÐW˜˜ÐTÑUÔUÐWÐWÑXÔXÐXØˆFÝ‰Œˆà�TÐGÐHØWØ.ð
ˆð
 ×+Ò+°$¸rÈ7Ð+ÑSÔSˆØ×5Ò5°c¸7ÑCÔCˆØ�VÒÐØ×,Ò,¨ZÑ8Ô8ð 8ÝÐ6¨*Ð6Ð6Ñ7Ô7Ð7Ý‰GŒGˆGÝÐHÑIÔIÐIÐIÐIØ�vÒÐð5Ø×+Ò+¨JÑ7Ô7Ð7ÝÐ4¨
Ð4Ð4Ñ5Ô5Ð5Ð5Ð5øÝð 5ð 5ð 5ÝÐ3 zÐ3Ð3Ñ4Ô4Ð4Ð4Ð4Ð4ð5øøøõ Ð%Ñ&Ô&Ð&Ð&Ð&s   Ã	'C2 Ã2DÄDc                óF  — |j         }t          |o|j        p|j        ¦  «        }|r|j        ndpd}|rdd|› d�dfdg}nddg}|                     d	¦  «         |                     d
¦  «         |                      dd|¬¦  «        }|                      ||¦  «        }|dk    r|                      |¦  «         dS |dk    r|  	                    |d¦  «         dS |dk    r|  
                    |¦  «         dS |dk    r|                      ||¦  «         dS t          d¦  «         dS )zAThe in-terminal change menu for a paid admin/owner (interactive).NrU   ÚkeepzKeep z (undo the scheduled change)zcancel the pending change)ÚchangeúChange planz$upgrade or downgrade in the terminal)Ú
cancel_subúCancel subscriptionú#schedule cancellation at period end©ÚportalúManage on portalz%open the billing page in your browser)ÚcloseÚCloser‹   r¨   r   rŒ   r°   )ÚresumeNr²   r¶   u     ðŸŸ¡ Closed. No plan change.)rY   r   r^   r_   r\   r™   rš   rŸ   Ú_subscription_pick_tierÚ_subscription_applyÚ_subscription_confirm_cancelr—   r%   )	r*   rM   rd   re   Úhas_pendingÚ	keep_namerŽ   r£   r“   s	            r4   rc   z)CLIBillingMixin._subscription_change_menuƒ  s€  € àŒMˆÝ˜1ÐZ !Ô"8Ð"Y¸AÔ<YÑ[Ô[ˆØ$%Ð/�Q”[�[¨4Ð?°Kˆ	ð
 ð 		àÐH ÐHÐHÐHÐJeÐfØQðˆGˆGð RØ\ðˆGð 	�ŠÐ^Ñ_Ô_Ð_Ø�ŠÐ7Ñ8Ô8Ð8Ø×+Ò+Ð2LÐUWÐahÐ+ÑiÔiˆØ×5Ò5°c¸7ÑCÔCˆØ�XÒÐØ×(Ò(¨Ñ/Ô/Ð/Ð/Ð/Ø�vÒÐØ×$Ò$ UÐ,<Ñ=Ô=Ð=Ð=Ð=Ø�|Ò#Ð#Ø×-Ò-¨eÑ4Ô4Ð4Ð4Ð4Ø�xÒÐØ×*Ò*¨5°*Ñ=Ô=Ð=Ð=Ð=åÐ2Ñ3Ô3Ð3Ð3Ð3r:   c                ó   — ddl m}m}m} |j        } ||¦  «        }|st          d¦  «         dS g }|D ]J} |||j        ¦  «        rdnd}	|                     |j         ||¦  «        › d|	› �d|j        › �f¦  «         ŒK|                     d	¦  «         |  	                    d
d|r|j
        nd› d�|¬¦  «        }
|                      |
|¦  «        }|r|dk    rt          d¦  «         dS |                      ||¦  «         dS )uD   Tier picker â†’ preview â†’ confirm (mirrors the TUI picker screen).r   )r~   Ú
is_upgrader   z6  No other plans are available to switch to right now.NÚupgradeÚ	downgraderD   z
switch to ©r‰   ÚBackr‹   r±   z	Current: r   z$. Pick a plan to preview the effect.rŒ   r‰   õ!     ðŸŸ¡ Cancelled. No plan change.)rE   r~   rÁ   r   rY   r%   rZ   r™   r„   rš   r\   rŸ   Ú!_subscription_preview_and_confirm)r*   rM   r~   rÁ   r   re   Ú
selectablerŽ   r†   Ú	directionr£   r“   s               r4   r»   z'CLIBillingMixin._subscription_pick_tier¥  so  € àYÐYÐYÐYÐYÐYÐYÐYÐYÐYàŒMˆð &Ð% eÑ,Ô,ˆ
Øð 	ÝÐJÑKÔKÐKØˆFØˆØð 	gð 	gˆAØ%/ Z°°q´yÑ%AÔ%AÐR˜	˜	À{ˆIØ�NŠN˜AœI¨/¨/¸!Ñ*<Ô*<Ð'MÐ'MÀ)Ð'MÐ'MÐOdÐ\]Ô\bÐOdÐOdÐeÑfÔfÐfÐfØ�ŠÐ7Ñ8Ô8Ð8Ø×+Ò+ØØa¨aÐ;˜qœ{˜{°VÐaÐaÐaØð ,ñ 
ô 
ˆð
 ×5Ò5°c¸7ÑCÔCˆØð 	˜ 8Ò+Ð+ÝÐ5Ñ6Ô6Ð6ØˆFØ×.Ò.¨u°fÑ=Ô=Ð=Ð=Ð=r:   T©Úallow_stepupc               ó   — ddl m}m}m} ddlm} ddlm}m}	m	}
  |d |d¦  «        › �¦  «         	  |
|¬¦  «        }n[# |	$ r/ |r|  
                    |d|f¬	¦  «         nt          d
¦  «         Y dS |$ r!}|                      ||¦  «         Y d}~dS d}~ww xY w ||¦  «        }|j        }|j        pd}t          ¦   «          |dk    r |d |d|› d�¦  «        › �¦  «         dS |dvrPddlm}m}  |||¦  «        r|nd} |d|j        pd› �¦  «          |||¬¦  «        }|rt          d|› �¦  «         dS |dk    rÖ|j        �d|j        dz  d›�nd} |d |d¦  «        › d |d¦  «        › �¦  «         |r |d|› d|› d�¦  «         n |d|› d�¦  «         d }	 dd!lm}  |d"¬#¦  «        }|j        r|j        nd}|�|j        d$v r
|j        › d%�}n# t2          $ r Y nw xY w |d ||¦  «        › �¦  «         |rd&|› d'�nd(}d)|f}d*d+|d,fg}nu|j        r't7          |j        ¦  «        d-k    r|j        dd-…         nd.} |d |d¦  «        › d |d/¦  «        › �¦  «          |d0|› d1|› d2�¦  «         d3|› �}d4|f}d+|d5fd6g}|j        r  |d |d7|j        › d8�¦  «        › �¦  «         |                      |d9|¬:¦  «        }|                      ||¦  «        d+k    rt          d;¦  «         dS |                      |||¬<¦  «         dS )=a
  Preview the change (chargeless quote), show the effect, then confirm+apply.

        ``allow_stepup=False`` (a post-grant replay) declines a second step-up on a
        repeated scope denial so the flow can't re-prompt/re-open the browser in a
        loop.
        r   r	   )Ú(subscription_change_preview_from_payload)ÚBillingErrorÚBillingScopeRequiredÚpost_subscription_previewr   u   Checking the changeâ€¦©Úsubscription_type_idÚpreview)Úretryõƒ     Remote Spending still isn't active for this terminal â€” the authorization didn't take. Retry, or make this change on the portal.Nzthe selected planÚno_opzYou are already on u    â€” nothing to change.)Ú
charge_nowÚ	scheduled)rÁ   r=   õ     ðŸŸ¡ uA   This change cannot be confirmed here â€” manage it on the portal.r�   rW   r×   r   éd   z.2fzConfirm plan changeu   Â· charged nowz  Upgrade to z. You will be charged z now (prorated).z.. You will be charged the prorated amount now.z.The card on your subscription will be charged.©Úbuild_billing_stateg      @)Útimeout)ÚsubPinÚcustomerDefaultu7    â€” the card on your subscription â€” will be charged.úPay z & upgrade nowzUpgrade now (prorated charge)rÂ   ©r‰   úGo backúdo not chargeÚyeszcharge + upgrade nowé
   rT   õ   Â· scheduled Â· not todayz  Change to u    â€” takes effect z7. No charge now; you keep your current plan until then.zSchedule change to Úschedulezapply this change)r‰   râ   zdo not changezMonthly credits change: ú.r   rŒ   rÆ   rÊ   ) r   r
   r   r   rE   rÍ   Úhermes_cli.nous_billingrÎ   rÏ   rÐ   Ú#_subscription_handle_scope_requiredr%   Ú_subscription_render_errorÚeffectÚtarget_tier_namerÁ   r=   ÚreasonÚamount_due_now_centsÚagent.billing_viewrÜ   rF   ÚcardÚresolved_viaÚmaskedr   Úeffective_atrž   Úmonthly_credits_deltarš   rŸ   r¼   )r*   rM   rZ   rË   r
   r   r   rÍ   rÎ   rÏ   rÐ   ÚpayloadÚexcÚprì   ÚtargetrÁ   r=   Ú_planÚ_mur0   Ú
_card_linerÜ   Ú_bsÚ_cÚ	pay_labelÚactionÚconfirm_choicesrp   r£   s                                 r4   rÇ   z1CLIBillingMixin._subscription_preview_and_confirmÁ  s=  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'àTÐTÐTÐTÐTÐTØiÐiÐiÐiÐiÐiÐiÐiÐiÐiàˆÐ3�R�RÐ0Ñ1Ô1Ð3Ð3Ñ4Ô4Ð4ð
	Ø/Ð/ÀWÐMÑMÔMˆGˆGøØ#ð 	ð 	ð 	Øð ]Ø×8Ò8¸ÀyÐRYÐFZÐ8Ñ[Ô[Ð[Ð[åð  \ñ  ]ô  ]ð  ]ØˆFˆFØð 	ð 	ð 	Ø×+Ò+¨E°3Ñ7Ô7Ð7ØˆFˆFˆFˆFˆFøøøøð	øøøð 5Ð4°WÑ=Ô=ˆØ”ˆØÔ#Ð:Ð':ˆÝ‰ŒˆØ�WÒÐØˆGÐT˜˜ÐQ°&ÐQÐQÐQÑRÔRÐTÐTÑUÔUÐUØˆFØÐ4Ð4Ð4ð TÐSÐSÐSÐSÐSÐSÐSà)˜z¨%°Ñ9Ô9ÐC�G�G¸tˆEØˆGÐo˜aœhÐmÐ*mÐoÐoÑpÔpÐpØ)Ð)¨%¸Ð?Ñ?Ô?ˆCØð 4ÝÐ2¨SÐ2Ð2Ñ3Ô3Ð3ØˆFØ�\Ò!Ð!Ø=>Ô=SÐ=_Ð9�qÔ-°Ñ3Ð9Ð9Ð9Ð9ÐeiˆDØˆGÐL˜˜Ð1Ñ2Ô2ÐLÐL°b°bÐ9IÑ6JÔ6JÐLÐLÑMÔMÐMØð `Ø�Ð\¨Ð\Ð\ÀdÐ\Ð\Ð\Ñ]Ô]Ð]Ð]à�Ð^¨Ð^Ð^Ð^Ñ_Ô_Ð_ð
 JˆJðØBÐBÐBÐBÐBÐBà)Ð)°#Ð6Ñ6Ô6�Ø!$¤Ð8�S”X�X°D�Ø�> b¤oÐ9VÐ&VÐ&VØ$&¤IÐ!fÐ!fÐ!f�JøøÝð ð ð Ø�ðøøøàˆGÐ)˜˜˜J™œÐ)Ð)Ñ*Ô*Ð*Ø7;Ð`Ð3˜tÐ3Ð3Ð3Ð3ÐA`ˆIØ Ð)ˆFð 7Ø˜	Ð#9Ð:ðˆOˆOð
 -.¬NÐ~½sÀ1Ä>Ñ?RÔ?RÐVXÒ?XÐ?X�A”N 3 B 3Ô'Ð'Ð_~ˆEØˆGÐW˜˜Ð1Ñ2Ô2ÐWÐW°b°bÐ9TÑ6UÔ6UÐWÐWÑXÔXÐXØˆGÐ{ 6Ð{Ð{¸UÐ{Ð{Ð{Ñ|Ô|Ð|Ø6¨fÐ6Ð6ˆIØ  'Ð*ˆFà˜	Ð#6Ð7Ø6ðˆOð Ô"ð 	VØˆGÐT˜˜ÐQ°qÔ7NÐQÐQÐQÑRÔRÐTÐTÑUÔUÐUØ×+Ò+°)ÀBÐP_Ð+Ñ`Ô`ˆØ×/Ò/°°_ÑEÔEÈÒNÐNÝÐ5Ñ6Ô6Ð6ØˆFØ× Ò  ¨¸\Ð ÑJÔJÐJÐJÐJs/   ³A  Á 0BÁ3BÁ7BÂBÆ"7G Ç
G'Ç&G'c                óî  — ddl m}m}m} ddlm} |j        }|r|j        r ||j        ¦  «        ndpd}t          ¦   «           |d |d¦  «        › d |d¦  «        › �¦  «          |d	|r|j	        nd
› d|› d�¦  «          |d |d¦  «        › �¦  «         ddg}|  
                    dd|¬¦  «        }	|                      |	|¦  «        dk    rt          d¦  «         dS |                      |d¦  «         dS )z4Confirm, then schedule a cancellation at period end.r   r	   rR   NrT   r   zConfirm cancellationræ   z	  Cancel rU   u    â€” it stays active until z, then won't renew.zOYou keep your remaining credits for this period. You can resume before it ends.)rä   r³   r´   )r‰   râ   zkeep your planzCancel subscription?r   rŒ   rä   u)     ðŸŸ¡ Cancelled. Your plan is unchanged.)r‰   N)r   r
   r   r   r   r   rY   r]   r%   r\   rš   rŸ   r¼   )
r*   rM   r
   r   r   r   re   Ú_endr  r£   s
             r4   r½   z,CLIBillingMixin._subscription_confirm_cancel  sm  € à'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'à5Ð5Ð5Ð5Ð5Ð5àŒMˆØ34ÐS¸¼ÐS��˜aœoÑ.Ô.Ð.ÈtÐwÐXwˆÝ‰ŒˆØˆÐT�R�RÐ.Ñ/Ô/ÐTÐT°2°2Ð6QÑ3RÔ3RÐTÐTÑUÔUÐUØˆÐu¨AÐ>˜Qœ[˜[°;ÐuÐuÐ\`ÐuÐuÐuÑvÔvÐvØˆÐl�R�RÐiÑjÔjÐlÐlÑmÔmÐmàQØ3ð
ˆð ×+Ò+Ð2HÐQSÐ]lÐ+ÑmÔmˆØ×/Ò/°°_ÑEÔEÈÒNÐNÝÐ=Ñ>Ô>Ð>ØˆFØ× Ò  Ð(8Ñ9Ô9Ð9Ð9Ð9r:   Nc               óD  — ddl m}m}m}m} ddlm}	m}
m}m	}m
}m}m}m} |\  }}d}|dk    rddlm} |p	 |¦   «         }	 |dk    �r|	  |||¬¦  «        pi }n™# |$ r ‚ |
||f$ r!}|                      ||¦  «         Y d}~dS d}~w|	$ re}t#          |dd¦  «        }t#          |d	d¦  «        }|d
v s|�|dk    r|                      |¦  «         n|                      ||¦  «         Y d}~dS d}~ww xY w|                     d¦  «        }|                     d¦  «        pd}|                     d¦  «        }|dk    r |d|› d|› d|› �¦  «         nt|dk    r |d|› d|› d|› �¦  «         nY|dk    r |d¦  «         |r |d|› �¦  «         n7|dk    r |d¦  «         |r |d|› �¦  «         n|                      d¦  «         dS |dk    r ||¬¦  «          |d|› d|› �¦  «         nE|dk    r |d¬ ¦  «          |d|› d!|› �¦  «         n!|d"k    r |¦   «           |d|› d#|› �¦  «          |d |d$¦  «        › �¦  «         dS # |$ r0 |r|                      |||¬%¦  «         Y dS t+          d&¦  «         Y dS |	$ r!}|                      ||¦  «         Y d}~dS d}~ww xY w)'aì  Run the mutation for `action`, handling the scope step-up + the result.

        `action` is one of ("upgrade", tier_id) / ("schedule", tier_id) /
        ("cancel", None) / ("resume", None). insufficient_scope routes to the
        step-up and replays; the upgrade idempotency key is reused across the replay.
        ``allow_stepup=False`` (a post-grant replay) declines a second step-up on a
        repeated scope denial so the flow can't re-prompt/re-open the browser in a loop.
        r   ©r
   r   Ú_DIMÚ_RST)rÎ   ÚBillingTransientÚBillingRemoteSpendingRevokedrÏ   ÚBillingSessionRevokedÚ"delete_subscription_pending_changeÚpost_subscription_upgradeÚput_subscription_pending_changeNrÂ   ©Únew_idempotency_key)rÒ   Úidempotency_keyr"   rG   )Únetwork_errorÚendpoint_unavailableiô  ÚtargetTierNamezyour new planÚrecoveryUrlÚalready_on_tierr   u   âœ“ You are already on rè   Úupgradedu   âœ“ Upgraded to z,. Your new monthly credits land in a moment.Úrequires_actionuL     ðŸŸ¡ This upgrade needs extra verification (3DS). Finish it on the portal.ú
  Portal: Úpayment_faileduV     ðŸ”´ Your card was declined. Update your payment method on the portal and try again.rç   rÑ   ut   âœ“ Scheduled â€” your plan doesn't change today. You keep it until the end of the billing period, then it switches.r‰   T)r‰   uu   âœ“ Scheduled â€” your plan stays active until the end of the billing period, then it cancels. Nothing changes today.rº   u-   âœ“ Undone â€” you stay on your current plan.z*Re-run /subscription anytime to review it.)rÔ   r  rÕ   )r   r
   r   r  r  ré   rÎ   r  r	  rÏ   r
  r  r  r  rð   r  rë   r#   Ú&_subscription_render_upgrade_ambiguousÚgetrê   r%   )r*   rM   r   r  rË   r
   r   r  r  rÎ   r  r	  rÏ   r
  r  r  r  ÚkindÚargÚkeyr  Úresr÷   Ú_statusÚ_coder"   r„   Ú_urls                               r4   r¼   z#CLIBillingMixin._subscription_apply5  s  € ð 	0Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/ð		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð 		
ð ‰	ˆˆcØˆØ�9ÒÐØ>Ð>Ð>Ð>Ð>Ð>à!Ð:Ð%8Ð%8Ñ%:Ô%:ˆCð=	8Ø�yÒ Ñ ðØ3Ð3ÈÐ^aÐbÑbÔbÐhÐfh�C�CøØ+ð ð ð ØØ(Ð*?ÐA]Ð^ð ð ð ð ×3Ò3°E¸3Ñ?Ô?Ð?Ø�F�F�F�F�FøøøøØ#ð ð ð Ý% c¨8°TÑ:Ô:�GÝ# C¨°$Ñ7Ô7�EØÐ IÐIÐIÈWÈ_Ð`gÐknÒ`nÐ`nð
 ×CÒCÀCÑHÔHÐHÐHð ×7Ò7¸¸sÑCÔCÐCØ�F�F�F�F�Føøøøðøøøð Ÿš Ñ*Ô*�Ø—w’wÐ/Ñ0Ô0ÐC°O�Ø—w’w˜}Ñ-Ô-�ØÐ.Ò.Ð.Ø�GÐK ÐKÐK¸dÐKÐKÀTÐKÐKÑLÔLÐLÐLØ˜zÒ)Ð)Ø�GÐo ÐoÐo°tÐoÐoÐimÐoÐoÑpÔpÐpÐpØÐ0Ò0Ð0Ø�GÐjÑkÔkÐkØð 5Ø˜Ð 3¨TÐ 3Ð 3Ñ4Ô4Ð4øØÐ/Ò/Ð/Ø�GÐtÑuÔuÐuØð 5Ø˜Ð 3¨TÐ 3Ð 3Ñ4Ô4Ð4øð ×?Ò?ÀÑEÔEÐEØ�Ø�zÒ!Ð!Ø/Ð/ÀSÐIÑIÔIÐIØ�ð  ^˜Tð  ^ð  ^ð  X\ð  ^ð  ^ñ  _ô  _ð  _ð  _Ø˜Ò!Ð!Ø/Ð/°tÐ<Ñ<Ô<Ð<Ø�ð  _˜Tð  _ð  _ð  Y]ð  _ð  _ñ  `ô  `ð  `ð  `Ø˜Ò!Ð!Ø2Ð2Ñ4Ô4Ð4Ø�ÐV˜TÐVÐVÐPTÐVÐVÑWÔWÐWØˆGÐK˜˜ÐHÑIÔIÐKÐKÑLÔLÐLÐLÐLøØ#ð 	]ð 	]ð 	]Øð ]Ø×8Ò8¸ÀfÐ^aÐ8ÑbÔbÐbÐbÐbÐbåð  \ñ  ]ô  ]ð  ]ð  ]ð  ]ð  ]Øð 	8ð 	8ð 	8Ø×+Ò+¨E°3Ñ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7Ð7øøøøð	8øøøsi   ÁI Á	A ÁI ÁC/Á&BÁ<I ÂC/Â
AC*Ã$I Ã*C/Ã/CI ÇB I ÉJÉ(JÉ:JÉ>JÊJ)r  c               óV  — ddl m}m}m}m} t          ¦   «          t          d¦  «          |d |d¦  «        › �¦  «         t          | dd¦  «        st          d¦  «         dS d	d
g}|                      dd|¬¦  «        }	|                      |	|¦  «        dk    rt          d¦  «         dS t          d¦  «         	 ddl	m
}
  |
d¬¦  «        }n*# t          $ r}t          d|› �¦  «         Y d}~dS d}~ww xY w|st          d¦  «         dS  |d|› d|› �¦  «         	 ddlm} |                     ¦   «          n# t          $ r Y nw xY wddlm} 	  |¦   «         }n# t          $ r |}Y nw xY w|\  }}|dk    r|                      ||d¬¦  «         dS |                      |||d¬¦  «         dS )u?  insufficient_scope â†’ allow remote spending (step-up), then replay `retry`.

        Mirrors _billing_handle_scope_required: the classic CLI calls
        step_up_nous_billing_scope directly (it opens the browser + blocks), then
        replays the held preview/mutation so the user never re-runs the command.
        r   r  ú  ! One-time setupr   zŒTo change your plan from the terminal, allow Remote Spending once. It opens your browser to authorize, then your change picks up right here.rX   NzK  Run `hermes portal` and allow Remote Spending, then re-run /subscription.©rä   úAllow Remote Spendingzopen your browser to authorize©ÚnozNot nowr‰   r&  ú.Opens your browser to authorize this terminal.rŒ   rä   z:  No change made. Allow Remote Spending when you're ready.õ2     Opening your browser to allow Remote Spendingâ€¦©Ústep_up_nous_billing_scopeT©Úopen_browserú"  Couldn't allow Remote Spending: uZ     Couldn't allow Remote Spending â€” an org admin or owner has to approve it for this org.u   âœ“ Remote Spending allowed.)Únous_billing)r<   rÓ   FrÊ   )r  rË   )r   r
   r   r  r  r%   r#   rš   rŸ   ry   r,  r   Ú
hermes_clir0  Úinvalidate_cached_tokenrE   r<   rÇ   r¼   )r*   rM   rÔ   r  r
   r   r  r  r  r£   r,  Úgrantedr÷   Ú_nbr<   ÚfreshÚrkindÚrargs                     r4   rê   z3CLIBillingMixin._subscription_handle_scope_required�  sº  € ð 	0Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/å‰ŒˆÝÐ"Ñ#Ô#Ð#Øˆð  j�R�Rð  gñ  hô  hð  jð  jñ  	kô  	kð  	kÝ�t˜V TÑ*Ô*ð 	ÝÐ_Ñ`Ô`Ð`ØˆFàNØ'ð
ˆð ×+Ò+Ø)ØCØ#ð ,ñ 
ô 
ˆð
 ×/Ò/°°_ÑEÔEÈÒNÐNÝÐNÑOÔOÐOØˆFÝÐBÑCÔCÐCð	ØBÐBÐBÐBÐBÐBà0Ð0¸dÐCÑCÔCˆGˆGøÝð 	ð 	ð 	ÝÐ<°sÐ<Ð<Ñ=Ô=Ð=ØˆFˆFˆFˆFˆFøøøøð	øøøð ð 	ÝÐnÑoÔoÐoØˆFØˆÐ=�TÐ=Ð=°tÐ=Ð=Ñ>Ô>Ð>ð
	Ø6Ð6Ð6Ð6Ð6Ð6à×'Ò'Ñ)Ô)Ð)Ð)øÝð 	ð 	ð 	ØˆDð	øøøð 	EÐDÐDÐDÐDÐDð	Ø,Ð,Ñ.Ô.ˆEˆEøÝð 	ð 	ð 	ØˆEˆEˆEð	øøøà‰ˆˆtØ�IÒÐØ×2Ò2°5¸$ÈUÐ2ÑSÔSÐSÐSÐSà×$Ò$ U¨EÀ?ÐafÐ$ÑgÔgÐgÐgÐgs<   Â:C Ã
C4ÃC/Ã/C4ÄD7 Ä7
EÅEÅ
E ÅE(Å'E(c                ó  — ddl m} t          |dd¦  «        }t          |¦  «        pd}|dk    r |d¦  «         n!|dv r |d	|› �¦  «         n |d
|› �¦  «         t          |dd¦  «        }|r |d|› �¦  «         dS dS )zLRender a subscription BillingError (a lighter _billing_render_charge_error).r   )r
   rG   NzSomething went wrong.Úinsufficient_scopeu?     ðŸŸ¡ Remote Spending isn't allowed yet. Allow it, then retry.)Úsubscription_mutation_rejectedÚpreview_rejectedrÙ   õ     ðŸ”´ Ú
portal_urlr  )r   r
   r#   ru   )r*   rM   r÷   r
   ÚcodeÚmsgr"  s          r4   rë   z*CLIBillingMixin._subscription_render_errorÏ  sÓ   € àÐÐÐÐÐå�s˜G TÑ*Ô*ˆÝ�#‰hŒhÐ1Ð1ˆØÐ'Ò'Ð'àˆGÐUÑVÔVÐVÐVØÐKÐKÐKØˆG�O˜c�O�OÑ$Ô$Ð$Ð$àˆG�O˜c�O�OÑ$Ô$Ð$Ý�s˜L¨$Ñ/Ô/ˆØð 	)ØˆGÐ' Ð'Ð'Ñ(Ô(Ð(Ð(Ð(ð	)ð 	)r:   c                ó¨   — ddl m}m}  |d¦  «          |d |d¦  «        › �¦  «         |�t          |dd¦  «        nd}|r |d|› �¦  «         dS dS )	ue  A charge-route failure (transport / timeout / 500 / unknown status) is
        AMBIGUOUS â€” NAS may have already prorated + charged. Steer to a re-check,
        never a flat failure that invites a blind retry (mirrors the TUI's
        upgradeResult(null) â€” the CLI can't persist the key across a command re-run,
        so a re-check is the safe path).r   r8   uS     ðŸŸ¡ Couldn't confirm the upgrade â€” your card may or may not have been charged.r   z<Re-run /subscription to check your plan before trying again.Nr=  r  )r   r
   r   r#   )r*   r÷   r
   r   r"  s        r4   r  z6CLIBillingMixin._subscription_render_upgrade_ambiguousà  sœ   € ð 	$Ð#Ð#Ð#Ð#Ð#Ð#Ð#àˆÐeÑfÔfÐfØˆÐY�R�RÐVÑWÔWÐYÐYÑZÔZÐZØ36°?�w�s˜L¨$Ñ/Ô/Ð/ÈˆØð 	)ØˆGÐ' Ð'Ð'Ñ(Ô(Ð(Ð(Ð(ð	)ð 	)r:   ú/topupÚcommandc                ó,  — ddl m}m} ddlm}  |¦   «         }|j        s_t          ¦   «          |j        r"d|j        › �} |d ||¦  «        › �¦  «         n& |d |d¦  «        › �¦  «         t          d¦  «         dS |                      |¦  «         dS )	uý  `/topup` â€” Remote Spending for Nous (one interactive modal).

        ZERO sub-commands: any argument is ignored. Bare ``/topup`` always
        opens the Overview (Screen 1), whose numbered menu is the *only* way to
        reach the Buy / Auto-reload / Monthly-limit sub-screens. (Per the unified
        UX spec Â§0.4 â€” ``/topup buy`` etc. are gone; we don't error on a stray
        arg, we just open the menu.)

        Interactive CLI uses the prompt_toolkit modal; non-interactive contexts
        (TUI slash-worker / no live app) render text + the portal deep-link, never
        prompting (the URL is the affordance), same discipline as ``_show_subscription``.
        All money is Decimal end-to-end; the terminal never collects card details.
        r   r8   rÛ   zCouldn't load billing: r>   r?   z-  Run `hermes portal` to log in, then /topup.N)	r   r
   r   rð   rÜ   rF   r%   rG   Ú_billing_overview)r*   rB  r
   r   rÜ   rM   Ú_msgs          r4   Ú_show_billingzCLIBillingMixin._show_billingò  sá   € ð 	$Ð#Ð#Ð#Ð#Ð#Ð#Ð#à:Ð:Ð:Ð:Ð:Ð:à#Ð#Ñ%Ô%ˆØŒð 	Ý‰GŒGˆGØŒ{ð GØ>°´Ð>Ð>�Ø�Ð, " " T¡(¤(Ð,Ð,Ñ-Ô-Ð-Ð-à�ÐF " "Ð%CÑ"DÔ"DÐFÐFÑGÔGÐGÝÐEÑFÔFÐFØˆFð 	×Ò˜uÑ%Ô%Ð%Ð%Ð%r:   r   ©rî   rî   c               ó|   — t          |dd¦  «        }|sdS |rt          d|› �¦  «         t          d|› �¦  «         dS )zCPrint a portal deep-link line (the funnel for portal-only actions).r=  Nr   rW   )r#   r%   )r*   rM   rî   rt   s       r4   Ú_billing_portal_hintz$CLIBillingMixin._billing_portal_hint  sY   € å�e˜\¨4Ñ0Ô0ˆØð 	ØˆFØð 	!Ý�-�v�-�-Ñ Ô Ð ÝÐ* SÐ*Ð*Ñ+Ô+Ð+Ð+Ð+r:   c           	     óP  — ddl m}m}m} ddlm} 	 ddlm}  |¦   «         }n# t          $ r d}Y nw xY wt          ¦   «           |d |d ||j
        ¦  «        › �¦  «        › �¦  «         |j        rE|j        pd                     ¦   «         }d	|j        › |rd
|› �nd› �}	 |d ||	¦  «        › �¦  «         t          dd› �¦  «         |                      |t          |dd¦  «        ¦  «        D ]}
t          |
¦  «         Œ|j        }|�H|j        r2t          d ||j        ¦  «        › d ||j        ¦  «        › �¦  «         nt          d¦  «         |j        rB|j        r;|j        �t          d|j        j        › �¦  «         n |d |d¦  «        › �¦  «         t          dd› �¦  «         |j        s. |d |d¦  «        › �¦  «         |                      |¦  «         dS |j        s0 |d |d¦  «        › �¦  «         |                      |d¬¦  «         dS t          | dd¦  «        s|                      |¦  «         dS  |d |d¦  «        › �¦  «         |�m|j        rf|j        �_|j                             ¦   «         rF|j        �?|j                             ¦   «         r&d ||j        ¦  «        › d ||j        ¦  «        › d�}nd} |d ||¦  «        › �¦  «         t          dd› �¦  «         g d¢}|                      dd|¬¦  «        }|                      ||¦  «        }|d k    r|                      |¦  «         dS |d!k    r|                      |¦  «         dS |d"k    r|                      |¦  «         dS |d#k    r|                      |¦  «         dS t          d$¦  «         dS )%u�  Screen 1 â€” overview: balance in title, two-bar dollar usage, action menu.

        Dollars-only (no "credits") â€” mirrors the TUI /topup overlay: balance
        leads in the title, the shared plan + top-up bars render below, then the
        reordered menu (Add funds first). No scope preflight â€” remote spending
        is discovered reactively when a charge 403s insufficient_scope.
        r   r	   ©Úformat_moneyrS   Nr>   u   Top up Â· balance r   rC   rD   r   rB   r!   u     Auto-reload: on â€” below õ    â†’ reload to z  Auto-reload: offz  Card: uG   No saved card on file â€” â€œAdd fundsâ€� walks you through adding one.ú+Billing actions require an org admin/owner.ú$Remote spending is off for this org.zUA billing admin can turn it on from the portal's Hermes Agent page to add funds here.rG  rX   u?   Add funds now â€” a single charge, added to your balance today.u   Refill when low â€” charges z- automatically when your balance falls below rè   ue   Refill when low â€” charges your card automatically when your balance falls below the amount you set.))Úbuyú	Add fundsz,a single charge, added to your balance today)ÚautoúAuto-reloadz/refill automatically when your balance runs low)ÚlimitzMonthly limitz&show the monthly spend cap (read-only)rµ   rˆ   zTop up your balancerŒ   rP  rR  rT  r¶   z  Cancelled.) r   r
   r   r   rð   rL  r   r   r   r%   Úbalance_usdrI   rJ   rK   r&   r#   Úauto_reloadÚenabledÚthreshold_usdÚreload_to_usdr[   Úcli_billing_enabledrñ   ÚdisplayrI  Ú	is_finiterš   rŸ   Ú_billing_buy_flowÚ_billing_auto_reload_flowÚ_billing_limit_screenÚ_billing_open_portal)r*   rM   r
   r   r   rL  r   r+   rJ   rN   r/   ÚarÚ
_auto_linerŽ   r£   r“   s                   r4   rD  z!CLIBillingMixin._billing_overview  s9  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'à3Ð3Ð3Ð3Ð3Ð3ð	Ø=Ð=Ð=Ð=Ð=Ð=à%Ð%Ñ'Ô'ˆEˆEøÝð 	ð 	ð 	ØˆEˆEˆEð	øøøõ 	‰ŒˆØˆÐV˜"˜"ÐS°,°,¸uÔ?PÑ2QÔ2QÐSÐSÑTÔTÐVÐVÑWÔWÐWØŒ>ð 	*Ø”JÐ$ "×+Ò+Ñ-Ô-ˆDØO ¤ÐOÀÐ0M°°t°°°È2ÐOÐOˆIØˆGÐ(˜˜˜I™œÐ(Ð(Ñ)Ô)Ð)ÝÐ�:ÐÐÑ Ô Ð ð ×,Ò,¨UµG¸EÀ;ÐPTÑ4UÔ4UÑVÔVð 	ð 	ˆGÝ�'‰NŒNˆNˆNàÔˆØˆ>ØŒzð ,ÝðF°<°<ÀÔ@PÑ3QÔ3Qð Fð FØ%1 \°"Ô2BÑ%CÔ%CðFð Fñô ð ð õ
 Ð*Ñ+Ô+Ð+ð Ô ð 	n UÔ%>ð 	nØŒzÐ%ÝÐ5 ¤Ô!3Ð5Ð5Ñ6Ô6Ð6Ð6à�Ðl˜R˜RÐ iÑjÔjÐlÐlÑmÔmÐmÝÐ�:ÐÐÑ Ô Ð ð Ô$ð 	ØˆGÐL˜˜ÐIÑJÔJÐLÐLÑMÔMÐMØ×%Ò% eÑ,Ô,Ð,ØˆFØÔ(ð 	ØˆGÐE˜˜ÐBÑCÔCÐEÐEÑFÔFÐFØ×%Ò%ØØnð &ñ ô ð ð ˆFõ �t˜V TÑ*Ô*ð 	Ø×%Ò% eÑ,Ô,Ð,ØˆFð 	ˆÐ\�R�RÐYÑZÔZÐ\Ð\Ñ]Ô]Ð]àˆNØ”
ð àÔ Ð,ØÔ ×*Ò*Ñ,Ô,ð -àÔ Ð,ØÔ ×*Ò*Ñ,Ô,ð -ðS¨|¨|¸BÔ<LÑ/MÔ/Mð Sð SØ1=°¸bÔ>NÑ1OÔ1OðSð Sð Sð ˆJð2ð ð 	ˆÐ%�R�R˜
‘^”^Ð%Ð%Ñ&Ô&Ð&ÝÐ�:ÐÐÑ Ô Ð ð
ð 
ð 
ˆð ×+Ò+Ø'°Øð ,ñ 
ô 
ˆð ×5Ò5°c¸7ÑCÔCˆØ�UŠ?ˆ?Ø×"Ò" 5Ñ)Ô)Ð)Ð)Ð)Ø�vÒÐØ×*Ò*¨5Ñ1Ô1Ð1Ð1Ð1Ø�wÒÐØ×&Ò& uÑ-Ô-Ð-Ð-Ð-Ø�xÒÐØ×%Ò% eÑ,Ô,Ð,Ð,Ð,å�.Ñ!Ô!Ð!Ð!Ð!rs   Úlistc                óH  — g }|rt          |dd¦  «        nd}|�®|j        dk    r£t          dt          dt	          |j        dz  ¦  «        ¦  «        ¦  «        }d|z  dd|z
  z  z   }|j        �d|j        › d�nd	}|pd
                     d¦  «        dd…         }|                     d|› d|› d|j	        d›d|j        d›|› �	¦  «         |rt          |dd¦  «        nd}	|	�C|	j	        dk    r8|                     dd                     d¦  «        › dd› d|	j	        d›d�¦  «         |S )u—  The plan + top-up dollar bars as ready-to-print lines (filled = remaining).

        Returns [] when there's nothing to draw. The caller resolves ``plan_name``
        (the plan-bar label) and picks its own print fn â€” block ordering differs
        per surface (``_cprint`` vs ``print`` under patch_stdout). One source of
        truth for the bar format across /usage, /subscription, and /topup.
        Úplan_barNr   rå   u   â–ˆu   â–‘rD   z% usedr   r-   é   r   Ú[z]  $r   z
 left of $Ú	topup_barztop-upu   â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆu    Â· never expires)
r#   Ú	total_usdÚmaxÚminÚroundÚfill_fractionÚpct_usedÚljustr™   Úremaining_usd)
r*   r+   r!   r2   ÚpbÚfilledÚbarÚpct_sr§   Útbs
             r4   r&   z CLIBillingMixin._usage_bar_linesž  sm  € ð ˆØ16Ð@�W�U˜J¨Ñ-Ô-Ð-¸DˆØˆ>˜bœl¨QÒ.Ð.Ý˜�C ¥E¨"Ô*:¸RÑ*?Ñ$@Ô$@ÑAÔAÑBÔBˆFØ˜6‘> e¨r°F©{Ñ&;Ñ<ˆCØ24´+Ð2IÐ.˜2œ;Ð.Ð.Ð.Ð.ÈrˆEØÐ( &×/Ò/°Ñ2Ô2°2°A°2Ô6ˆEØ�LŠLÐj˜eÐjÐj cÐjÐj¨rÔ/?ÐjÐjÐjÐPRÔP\ÐjÐjÐchÐjÐjÑkÔkÐkØ27ÐA�W�U˜K¨Ñ.Ô.Ð.¸TˆØˆ>˜bÔ.°Ò2Ð2Ø�LŠLÐj˜hŸnšn¨QÑ/Ô/ÐjÐj°*ÐjÐjÀ"ÔBRÐjÐjÐjÐjÑkÔkÐkØˆr:   c                óº   — t          |dd ¦  «        }|st          d¦  «         d S |                      |¦  «        st          d|› �¦  «         t          d¦  «         d S )Nr=  z  No portal URL available.r«   z*  Complete billing changes in the browser.)r#   r%   r|   )r*   rM   rt   s      r4   r`  z$CLIBillingMixin._billing_open_portal³  sq   € Ý�e˜\¨4Ñ0Ô0ˆØð 	ÝÐ.Ñ/Ô/Ð/ØˆFØ×(Ò(¨Ñ-Ô-ð 	-ÝÐ+ cÐ+Ð+Ñ,Ô,Ð,ÝÐ:Ñ;Ô;Ð;Ð;Ð;r:   c                ó&  — ddl m}m} |j        s<t	          ¦   «           |d |d¦  «        › �¦  «         |                      |¦  «         dS |j        s>t	          ¦   «           |d |d¦  «        › �¦  «         |                      |d¬¦  «         dS d	S )
zGGuard charge/auto-reload entry points; print + return False if blocked.r   r8   r>   rN  FrO  zWA billing admin can turn it on from the portal's Hermes Agent page before adding funds.rG  T)r   r
   r   r[   r%   rI  rZ  )r*   rM   r
   r   s       r4   Ú_billing_require_adminz&CLIBillingMixin._billing_require_admin¼  sÒ   € à#Ð#Ð#Ð#Ð#Ð#Ð#Ð#àÔ$ð 	Ý‰GŒGˆGØˆGÐQ˜b˜bÐ!NÑOÔOÐQÐQÑRÔRÐRØ×%Ò% eÑ,Ô,Ð,Ø�5ØÔ(ð 	Ý‰GŒGˆGØˆGÐJ˜b˜bÐ!GÑHÔHÐJÐJÑKÔKÐKØ×%Ò%ØØpð &ñ ô ð ð �5Øˆtr:   c           	     ó˜  — ddl m}m}m}m}m} t          ¦   «           |d |d¦  «        › �¦  «          |d¦  «          |d |d¦  «        › �¦  «         g d¢}t          d	¦  «        D ]Ñ}|                      d
d|¬¦  «        }	|  	                    |	|¦  «        }
|
dk    r-|  
                    |¦  «          |d |d¦  «        › �¦  «         Œc|
dk    rhddlm} 	  |¦   «         }n# t          $ r d}Y nw xY w|�	|j        r|}|j        �" |d|› d|j        j        › d|› �¦  «         |c S t          d¦  «         ŒÑ t          d¦  «         dS )u   No saved card â†’ guide adding one on the portal, with a re-check loop.

        Cards are added on the portal (never in-terminal). "I've added it" re-fetches
        billing state so the purchase continues right here once the card is saved â€”
        this also recovers a transient miss (the card display is best-effort
        server-side). Returns the refreshed state (card present), or None to abandon.
        r   )r
   r   r   r  r  r>   zAdd a card firstz  No saved card on file.r   ua   Add a card once on the portal billing page â€” after that you can top up right from the terminal.))r¶   zAdd a card on the portalz&opens the billing page in your browser)Úrechecku   I've added it â€” check againz"re-check for the card and continuerÄ   rf  z
Add a cardr   rŒ   r¶   uC   Add the card on the billing page, then pick â€œcheck againâ€� here.rz  rÛ   Nu   âœ“ Card found: u    â€” continuing.uM     Still no card on file â€” finish adding it on the portal, then check again.ú  Cancelled. No funds added.)r   r
   r   r   r  r  r%   Úrangerš   rŸ   r`  rð   rÜ   r   rF   rñ   r[  )r*   rM   r
   r   r   r  r  rŽ   Ú_r£   r“   rÜ   r5  s                r4   Ú_billing_add_card_flowz&CLIBillingMixin._billing_add_card_flowÏ  sÿ  € ð 	4Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3å‰ŒˆØˆÐ2˜"˜"Ð/Ñ0Ô0Ð2Ð2Ñ3Ô3Ð3ØˆÐ*Ñ+Ô+Ð+ØˆÐ~�R�RÐ{Ñ|Ô|Ð~Ð~ÑÔÐð
ð 
ð 
ˆõ
 �q‘”ð 	ð 	ˆAØ×/Ò/°lÈ2ÐW^Ð/Ñ_Ô_ˆCØ×9Ò9¸#¸wÑGÔGˆFØ˜Ò!Ð!Ø×)Ò)¨%Ñ0Ô0Ð0Ø�Ðh˜R˜RÐ eÑfÔfÐhÐhÑiÔiÐiØØ˜Ò"Ð"ØBÐBÐBÐBÐBÐBð!Ø/Ð/Ñ1Ô1�E�EøÝ ð !ð !ð !Ø �E�E�Eð!øøøàÐ$¨¬Ð$Ø!�EØ”:Ð)Ø�GÐa ÐaÐa°u´zÔ7IÐaÐaÐ[_ÐaÐaÑbÔbÐbØ �L�L�LÝÐeÑfÔfÐfØØÝÐ,Ñ-Ô-Ð-Øˆts   Ã
C$Ã$C3Ã2C3c                ó¾  ‡— ddl m}m} ddlmŠm} |                      |¦  «        sdS t          | dd¦  «        sƒd                     ˆfd„|j	        D ¦   «         ¦  «        }t          ¦   «           |d |d	¦  «        › �¦  «         t          d
|› �¦  «         t          d¦  «         |                      |¦  «         dS |j        € |                      |¦  «        }|�|j        €dS g }|j	        D ]0}|                     t          |¦  «         ‰|¦  «        df¦  «         Œ1|                     d¦  «         |                     d¦  «         |j        }|r
d|j        › �nd}	|                      d	|	|¬¦  «        }
|                      |
|¦  «        }|r|dk    rt          d¦  «         dS ddlm} |dk    rj|                      d¦  «        }|€t          d¦  «         dS  ||pd|j        |j        ¬¦  «        }|j        st          d|j        › �¦  «         dS |j        }n-	  ||¦  «        }n # t6          $ r t          d¦  «         Y dS w xY w|                      ||¦  «         dS )u@   Screen 2 (preset select) â†’ Screen 3 (confirm + charge + poll).r   )r
   r   ©rL  Úvalidate_charge_amountNrX   z, c              3  ó.   •K  — | ]} ‰|¦  «        V — Œd S r’   © )r…   rø   rL  s     €r4   r”   z4CLIBillingMixin._billing_buy_flow.<locals>.<genexpr>  s+   øè è € ÐNÐN°A  ¨Q¡¤ÐNÐNÐNÐNÐNÐNr:   r>   rQ  z  Presets: z9  Run this in the interactive CLI to complete a purchase.zone-time credit purchase)Úcustomu   Custom amountâ€¦zenter your own amountrˆ   z	Payment: zNo saved card on filerŒ   r‰   r{  )ÚDecimalr„  z  Amount (USD): r   ©Úmin_usdÚmax_usdr<  u     ðŸ”´ Invalid selection.)r   r
   r   rð   rL  r�  rx  r#   ÚjoinÚcharge_presetsr%   rI  rñ   r~  r™   ru   r[  rš   rŸ   Údecimalr…  Ú_prompt_text_inputr‡  rˆ  ÚokrG   Úamountr   Ú_billing_confirm_and_charge)r*   rM   r
   r   r�  ÚpresetsÚpreset_choicesrø   rñ   r�   r£   r“   r…  ÚenteredÚvrŽ  rL  s                   @r4   r]  z!CLIBillingMixin._billing_buy_flowû  s  ø€ à#Ð#Ð#Ð#Ð#Ð#Ð#Ð#àKÐKÐKÐKÐKÐKÐKÐKà×*Ò*¨5Ñ1Ô1ð 	ØˆFõ �t˜V TÑ*Ô*ð 	Ø—i’iÐNÐNÐNÐN¸Ô9MÐNÑNÔNÑNÔNˆGÝ‰GŒGˆGØˆGÐ/˜b˜b ™oœoÐ/Ð/Ñ0Ô0Ð0ÝÐ) Ð)Ð)Ñ*Ô*Ð*ÝÐMÑNÔNÐNØ×%Ò% eÑ,Ô,Ð,ØˆFð
 Œ:ÐØ×/Ò/°Ñ6Ô6ˆEØˆ} ¤
Ð 2Ø�àˆØÔ%ð 	Yð 	YˆAØ×!Ò!¥3 q¡6¤6¨<¨<¸©?¬?Ð<VÐ"WÑXÔXÐXÐXØ×ÒÐUÑVÔVÐVØ×ÒÐ@ÑAÔAÐAàŒzˆØ/3ÐPÐ+˜Tœ\Ð+Ð+Ð+Ð9PˆØ×+Ò+Ø f°nð ,ñ 
ô 
ˆð ×5Ò5°c¸>ÑJÔJˆØð 	˜ 8Ò+Ð+ÝÐ0Ñ1Ô1Ð1ØˆFà#Ð#Ð#Ð#Ð#Ð#à�XÒÐØ×-Ò-Ð.@ÑAÔAˆGØˆåÐ4Ñ5Ô5Ð5Ø�Ø&Ð&Ø�˜2 u¤}¸e¼mðñ ô ˆAð ”4ð ÝÐ) ¤Ð)Ð)Ñ*Ô*Ð*Ø�Ø”XˆFˆFðØ ˜ ™œ��øÝð ð ð ÝÐ1Ñ2Ô2Ð2Ø��ðøøøð 	×(Ò(¨°Ñ7Ô7Ð7Ð7Ð7s   ÈH' È'IÉIc                ó€  — ddl m}m}m} ddlm}m} |j        }t          ¦   «           |d |d¦  «        › �¦  «         t          dd› �¦  «         t          d ||¦  «        › �¦  «         |r5t          d	|j	        › �¦  «         |j
        € |d |d¦  «        › �¦  «         t          dd› �¦  «         d}	 |d ||	¦  «        › �¦  «         dd ||¦  «        › d�dfddg}
t          | dd
¦  «        st          d¦  «         d
S |                      d ||¦  «        › d�|r|j	        nd|
¬¦  «        }|                      ||
¦  «        }|dk    r|                      |¦  «         d
S |dk    rt          d¦  «         d
S ddlm}m}m}  |¦   «         }	  |||¬¦  «        }nH# |$ r |                      |||¬¦  «         Y d
S |$ r!}|                      ||¦  «         Y d
}~d
S d
}~ww xY w|                     d¦  «        }|st          d¦  «         d
S  |d |d¦  «        › �¦  «         |                      |||¦  «         d
S ) uF   Screen 3 â€” confirm total + consent, charge, then poll to settlement.r   r	   )rL  r  r>   zConfirm purchaser   rB   z	  Total: z  Payment: Nz.Your card saved on the portal will be charged.z;By confirming, you allow Nous Research to charge your card.Úpayrà   z nowzsubmit the charge)r¶   r·   z)manage your card / billing in the browserrá   rX   z3  Run in the interactive CLI to confirm a purchase.ú?zno saved cardrŒ   r¶   r{  )rÎ   rÏ   Úpost_charge©Ú
amount_usdr  ©rŽ  r  ÚchargeIdu6     ðŸ”´ No charge id returned; please check the portal.u-   Charge submitted â€” confirming settlementâ€¦)r   r
   r   r   rð   rL  r  rñ   r%   r[  Ú
provenancer#   rš   rŸ   r`  ré   rÎ   rÏ   r—  Ú_billing_handle_scope_requiredÚ_billing_render_charge_errorr  Ú_billing_poll_charge)r*   rM   rŽ  r
   r   r   rL  r  rñ   Ú_consentr  r£   r“   rÎ   rÏ   r—  r  Úresultr÷   Ú	charge_ids                       r4   r�  z+CLIBillingMixin._billing_confirm_and_chargeD  sr  € à'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'àHÐHÐHÐHÐHÐHÐHÐHàŒzˆÝ‰ŒˆØˆÐ2˜"˜"Ð/Ñ0Ô0Ð2Ð2Ñ3Ô3Ð3ÝÐ�:ÐÐÑ Ô Ð ÝÐ0˜,˜, vÑ.Ô.Ð0Ð0Ñ1Ô1Ð1Øð 	UÝÐ. ¤Ð.Ð.Ñ/Ô/Ð/ð ŒÐ&Ø�ÐS˜R˜RÐ PÑQÔQÐSÐSÑTÔTÐTÝÐ�:ÐÐÑ Ô Ð àIð 	ð 	ˆÐ#�R�R˜‘\”\Ð#Ð#Ñ$Ô$Ð$ð Ð5˜<˜<¨Ñ/Ô/Ð5Ð5Ð5Ð7JÐKØWØ2ð
ˆõ
 �t˜V TÑ*Ô*ð 	ÝÐGÑHÔHÐHØˆFØ×+Ò+Ø0˜˜ fÑ-Ô-Ð0Ð0Ð0Ø$(Ð=�D”L�L¨oØ#ð ,ñ 
ô 
ˆð
 ×5Ò5°c¸?ÑKÔKˆØ�XÒÐØ×%Ò% eÑ,Ô,Ð,ØˆFØ�UŠ?ˆ?ÝÐ0Ñ1Ô1Ð1ØˆFð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð "Ð!Ñ#Ô#ˆð		Ø �[¨FÀCÐHÑHÔHˆFˆFøØ#ð 	ð 	ð 	ð ×/Ò/°¸fÐVYÐ/ÑZÔZÐZØˆFˆFØð 	ð 	ð 	Ø×-Ò-¨e°SÑ9Ô9Ð9ØˆFˆFˆFˆFˆFøøøøð	øøøð —J’J˜zÑ*Ô*ˆ	Øð 	ÝÐJÑKÔKÐKØˆFØˆÐJ�R�RÐGÑHÔHÐJÐJÑKÔKÐKØ×!Ò! %¨°FÑ;Ô;Ð;Ð;Ð;s   ÆF  Æ G%Ç G%ÇG Ç G%c                óF  — ddl }ddlm} ddlm}m}m} |                      ¦   «         dz   }	d}
|                      ¦   «         |	k     �r6	  ||¦  «        }n^# |$ r6}|j        pd}|                     t          |d¦  «        ¦  «         Y d}~Œ\d}~w|$ r}t          d	|› �¦  «         Y d}~dS d}~ww xY w|                     d
¦  «        }|dk    rQ|                     d¦  «        }ddlm} |r | ||¦  «        ¦  «        n
 ||¦  «        }t          d|› d�¦  «         dS |dk    r+|                      ||                     d¦  «        ¦  «         dS |                     |
¦  «         |                      ¦   «         |	k     �°6t          d¦  «         |                      |¦  «         dS )zGPoll loop: 2s interval, 5-min cap, cancellable. settled = ledger truth.r   NrK  )rÎ   r  Úget_charge_statusi,  g       @é   é   u#     ðŸ”´ Could not check the charge: r"   ÚsettledÚ	amountUsd)Úparse_moneyu     âœ“ z added to your balance.Úfailedrî   us     ðŸŸ¡ Still processing after 5 minutes â€” this is a timeout, not a failure. Check /billing or the portal shortly.)Útimerð   rL  ré   rÎ   r  r¤  Úretry_afterÚsleeprk  r%   r  r©  Ú_billing_render_charge_failedrI  )r*   rM   r¢  rŽ  Ú_timerL  rÎ   r  r¤  ÚdeadlineÚintervalr"   r÷   ÚwaitÚ	state_strÚamtr©  Úshowns                     r4   rŸ  z$CLIBillingMixin._billing_poll_chargeŠ  s<  € àÐÐÐà3Ð3Ð3Ð3Ð3Ð3ð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð —:’:‘<”< #Ñ%ˆØˆØ�jŠj‰lŒl˜XÒ%Ñ%ð	Ø*Ð*¨9Ñ5Ô5��øØ#ð ð ð à”Ð+¨!�Ø—’�C  b™MœMÑ*Ô*Ð*Ø����øøøøØð ð ð ÝÐA¸CÐAÐAÑBÔBÐBØ�����øøøøðøøøð Ÿ
š
 8Ñ,Ô,ˆIØ˜IÒ%Ð%Ø—j’j Ñ-Ô-�Ø:Ð:Ð:Ð:Ð:Ð:à:=ÐW˜˜ [ [°Ñ%5Ô%5Ñ6Ô6Ð6À<À<ÐPVÑCWÔCW�ÝÐ=˜uÐ=Ð=Ð=Ñ>Ô>Ð>Ø�Ø˜HÒ$Ð$Ø×2Ò2°5¸&¿*º*ÀXÑ:NÔ:NÑOÔOÐOØ�à�KŠK˜Ñ!Ô!Ð!ð1 �jŠj‰lŒl˜XÒ%Ñ%õ6 	ð ?ñ 	@ô 	@ð 	@à×!Ò! %Ñ(Ô(Ð(Ð(Ð(s$   ÁA ÁB/Á,B
Â
B/ÂB*Â*B/c                ó
  — |pd                      ¦   «         }|dk    rt          d¦  «         nA|dk    rt          d¦  «         n+|dk    rt          d¦  «         nt          d|pd	› d
�¦  «         |                      |¦  «         dS )zCBranch the poll `failed` reasons to the right copy + portal funnel.r   Úauthentication_requiredu`     ðŸ”´ Your bank requires verification (3DS). Complete it on the portal to finish this purchase.Úpayment_method_expiredu6     ðŸ”´ Your card has expired. Update it on the portal.Úcard_declinedu>     ðŸ”´ Your card was declined. Try another card on the portal.u%     ðŸ”´ The charge didn't go through (Úprocessing_errorz).N)r›   r%   rI  )r*   rM   rî   s      r4   r®  z-CLIBillingMixin._billing_render_charge_failed¶  s´   € à�,˜B×%Ò%Ñ'Ô'ˆØÐ.Ò.Ð.Ýð 4ñ 5ô 5ð 5ð 5àÐ/Ò/Ð/ÝÐJÑKÔKÐKÐKØ�Ò&Ð&ÝÐRÑSÔSÐSÐSåÐZ¸&Ð:VÐDVÐZÐZÐZÑ[Ô[Ð[Ø×!Ò! %Ñ(Ô(Ð(Ð(Ð(r:   c                ó  — ddl m}m}m} t	          |dd¦  «        }t	          |dd¦  «        }t	          |dd¦  «        pt	          |dd¦  «        }t          ||¦  «        s|dk    r|dk    rd	nd
}	t          d|	› d�¦  «         �nkt          ||¦  «        s|dk    rt          d¦  «         �nD|dk    rt          d¦  «         �n-|dv st	          |dd¦  «        dk    rt          d¦  «         �n|dk    rt          d¦  «         ní|dk    rt          d¦  «         n×|dk    rLt	          |di ¦  «        pi                      d¦  «        }
|
�t          d|
› d�¦  «         n•t          d¦  «         n…t          ||¦  «        rMt	          |dd¦  «        }|r$d t          d!t          |d"z  ¦  «        ¦  «        › d#�nd$}t          d%|› d&�¦  «         n(|d'k    rt          d(¦  «         nt          d|› �¦  «         |rt          d)|› �¦  «         dS dS )*z6Render a typed BillingError at submit time (pre-poll).r   )r  r	  r
  rG   NÚactorr=  Úremote_spending_revokedÚadminz*An admin stopped this terminal's spending.z%You stopped this terminal's spending.r<  u>    Reconnect to restore â€” run `hermes portal` to re-authorize.Úsession_revokeduH     ðŸ”´ Your session was logged out. Run `hermes portal` to log in again.Úno_payment_methoduC     ðŸ’³ No card on file â€” top up and manage billing on the portal.)Úcli_billing_disabledÚremote_spending_disabledr>  rÂ  uq     Remote spending is off for this account â€” a billing admin can turn it on from the portal's Hermes Agent page.Úrole_requiredzO  Adding funds needs an org admin/owner. Ask an admin, or manage on the portal.Úidempotency_conflictuU     ðŸ”´ That charge key was already used for a different amount. Start a fresh top-up.Úmonthly_cap_exceededrö   ÚremainingUsdu&     ðŸ”´ Monthly spend cap reached â€” $z headroom left.u!     ðŸ”´ Monthly spend cap reached.r¬  z (try again in ~r‚   é<   z min)r   u!     ðŸŸ¡ Too many charges right nowz. This isn't a payment failure.r9  uM     ðŸ”´ Remote Spending needs approval â€” run /topup to allow it, then retry.r  )
ré   r  r	  r
  r#   Ú
isinstancer%   r  rj  rl  )r*   rM   r÷   r  r	  r
  r>  r¼  r=  ÚwhoÚ	remainingr²  Úminss                r4   rž  z,CLIBillingMixin._billing_render_charge_errorÄ  sß  € ð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
õ �s˜G TÑ*Ô*ˆÝ˜˜W dÑ+Ô+ˆÝ˜S ,°Ñ5Ô5Ð[½ÀÈÐVZÑ9[Ô9[ˆ
Ý�cÐ7Ñ8Ô8ð  	#¸DÐD]Ò<]Ð<]ð ˜wÒ&Ð&ð @Ð?à?ð õ Ð_˜CÐ_Ð_Ð_Ñ`Ô`Ð`Ñ`Ý˜Ð2Ñ3Ô3ð 	#°tÐ?PÒ7PÐ7PÝÐ\Ñ]Ô]Ð]Ñ]ØÐ(Ò(Ð(ÝÐWÑXÔXÐXÑXØÐIÐIÐIÝ˜˜V TÑ*Ô*Ð.HÒHÐHÝð  Fñ  Gô  Gð  Gñ  GØ�_Ò$Ð$ÝÐcÑdÔdÐdÐdØÐ+Ò+Ð+ÝÐiÑjÔjÐjÐjØÐ+Ò+Ð+Ý   i°Ñ4Ô4Ð:¸×?Ò?ÀÑOÔOˆIØÐ$ÝÐY¸yÐYÐYÐYÑZÔZÐZÐZåÐ9Ñ:Ô:Ð:Ð:Ý˜Ð-Ñ.Ô.ð 		#Ý˜3 ¨tÑ4Ô4ˆDØIMÐUÐE¥c¨!­U°4¸"±9Ñ-=Ô-=Ñ&>Ô&>ÐEÐEÐEÐEÐSUˆDÝÐ[°dÐ[Ð[Ð[Ñ\Ô\Ð\Ð\ØÐ)Ò)Ð)õ ÐaÑbÔbÐbÐbå�/˜C�/�/Ñ"Ô"Ð"Øð 	-ÝÐ+˜zÐ+Ð+Ñ,Ô,Ð,Ð,Ð,ð	-ð 	-r:   rš  c               ó°  — ddl m}m} ddlm} |� ||¦  «        nd}t          ¦   «          t          d¦  «          |d |d|› d	�¦  «        › �¦  «         t          | d
d¦  «        st          d¦  «         dS ddg}|                      dd|¬¦  «        }	|                      |	|¦  «        }
|
dk    rt          d¦  «         dS t          d¦  «         	 ddl	m
}  |d¬¦  «        }n*# t          $ r}t          d|› �¦  «         Y d}~dS d}~ww xY w|st          d¦  «         dS ddlm}  |¦   «         }|j        r|j        s&t          d¦  «         |                      |¦  «         dS |j        €=t          d¦  «          |d |d¦  «        › �¦  «         |                      |¦  «         dS |€t          d¦  «         dS t          d¦  «         dd  ||¦  «        › d!�d"fd#g}|                      d$ ||¦  «        › d%�|¬¦  «        }	|                      |	|¦  «        dk    rt          d&¦  «         dS dd'lm}m} dd(lm} |p	 |¦   «         }	  |||¬)¦  «        }n)# |$ r!}|                      ||¦  «         Y d}~dS d}~ww xY w|                     d*¦  «        }|st          d+¦  «         dS  |d |d,¦  «        › �¦  «         |                      |||¦  «         dS )-uú  403 insufficient_scope â†’ in-flight reauth, then resume the held charge.

        The buy path discovers remote spending isn't allowed only when the
        charge 403s â€” there is no preflight. We allow it in-flight ("Allow
        Remote Spending" â†’ browser device-flow), then on return ask the user to
        press Enter to resume the held ``amount`` (reusing ``idempotency_key`` so
        the resumed charge collapses with the original). Never leaks the raw
        billing:manage scope.
        r   r8   rK  Nzyour top-upr$  r   zcTo charge from this terminal, allow Remote Spending once. It opens your browser to authorize, then z picks up right here.rX   z<  Run `hermes portal` and allow Remote Spending, then retry.r%  r'  r&  r)  rŒ   rä   zD  No charge made. Run /topup when you want to allow Remote Spending.r*  r+  Tr-  r/  uh     Couldn't allow Remote Spending â€” an org admin or owner has to approve it. Your card was not charged.rÛ   z«  Remote Spending is allowed for this terminal, but it's still off for this org. A billing admin can turn it on from the portal's Hermes Agent page, then run /topup again.uB     âœ“ Remote Spending allowed â€” but there's no card on file yet.z4Top up and manage billing on the portal to continue.u6     âœ“ Remote Spending allowed. Run /topup to continue.u     âœ“ Remote Spending allowed.rº   zResume z top-upzfinish the held purchase)r‰   rŠ   rã   zResume your top-upu.    is ready to finish â€” press Enter to resume.r{  )rÎ   r—  r  r˜  r›  z1  No charge id returned; please check the portal.u1   Resuming your top-up â€” confirming settlementâ€¦)r   r
   r   rð   rL  r%   r#   rš   rŸ   ry   r,  r   rÜ   rF   rZ  rI  rñ   ré   rÎ   r—  r  rž  r  rŸ  )r*   rM   rŽ  r  r
   r   rL  Ú
amount_strr  r£   r“   r,  r3  r÷   rÜ   r5  Úresume_choicesrÎ   r—  r  r  r¡  r¢  s                          r4   r�  z.CLIBillingMixin._billing_handle_scope_requiredó  sp  € ð 	$Ð#Ð#Ð#Ð#Ð#Ð#Ð#à3Ð3Ð3Ð3Ð3Ð3à-3Ð-?�\�\ &Ñ)Ô)Ð)À]ˆ
Ý‰ŒˆÝÐ"Ñ#Ô#Ð#Øˆð  c�R�Rð  `ð  Ið  `ð  `ð  `ñ  aô  að  cð  cñ  	dô  	dð  	dÝ�t˜V TÑ*Ô*ð 	ÝÐPÑQÔQÐQØˆFàNØ'ð
ˆð ×+Ò+Ø)ØCØ#ð ,ñ 
ô 
ˆð
 ×5Ò5°c¸?ÑKÔKˆØ�UŠ?ˆ?ÝÐXÑYÔYÐYØˆFÝÐBÑCÔCÐCð	ØBÐBÐBÐBÐBÐBà0Ð0¸dÐCÑCÔCˆGˆGøÝð 	ð 	ð 	ÝÐ<°sÐ<Ð<Ñ=Ô=Ð=ØˆFˆFˆFˆFˆFøøøøð	øøøð ð 	ÝÐ|Ñ}Ô}Ð}ØˆFð
 	;Ð:Ð:Ð:Ð:Ð:à#Ð#Ñ%Ô%ˆØ”ð 	 EÔ$=ð 	Ýð  @ñ  Aô  Að  AØ×%Ò% eÑ,Ô,Ð,ØˆFð
 Œ:ÐÝÐVÑWÔWÐWØˆGÐU˜˜ÐRÑSÔSÐUÐUÑVÔVÐVØ×%Ò% eÑ,Ô,Ð,ØˆFð ˆ>ÝÐJÑKÔKÐKØˆFõ 	Ð.Ñ/Ô/Ð/àÐ>  ¨fÑ!5Ô!5Ð>Ð>Ð>Ð@ZÐ[Ø1ð
ˆð ×+Ò+Ø&Ø"�l 6Ñ*Ô*ÐZÐZÐZØ"ð ,ñ 
ô 
ˆð
 ×/Ò/°°^ÑDÔDÈÒPÐPÝÐ0Ñ1Ô1Ð1ØˆFð 	FÐEÐEÐEÐEÐEÐEÐEà:Ð:Ð:Ð:Ð:Ð:àÐ6Ð!4Ð!4Ñ!6Ô!6ˆð	Ø �[¨FÀCÐHÑHÔHˆFˆFøØð 	ð 	ð 	Ø×-Ò-¨e°SÑ9Ô9Ð9ØˆFˆFˆFˆFˆFøøøøð	øøøð —J’J˜zÑ*Ô*ˆ	Øð 	ÝÐEÑFÔFÐFØˆFØˆÐN�R�RÐKÑLÔLÐNÐNÑOÔOÐOØ×!Ò! %¨°FÑ;Ô;Ð;Ð;Ð;s0   ÃC$ Ã$
DÃ.DÄDÉ	I ÉI=ÉI8É8I=c           	     ó"	  — ddl m}m}m} ddlm}m} |                      |¦  «        sdS |j        }|j	        }t          |o|j        ¦  «        }	t          ¦   «           |d |d¦  «        › �¦  «         t          dd› �¦  «          |d |d	¦  «        › �¦  «         |rt          d
|j        › �¦  «         n&t          d¦  «         |                      |¦  «         dS |	r1t          d ||j        ¦  «        › d ||j        ¦  «        › �¦  «         t#          | dd¦  «        s&t          d¦  «         |                      |¦  «         dS |	rˆg d¢}
|                      dd ||j        ¦  «        › d ||j        ¦  «        › �|
¬¦  «        }|                      ||
¦  «        }|dk    r|                      |¦  «         dS |dk    rt          d¦  «         dS |	r ||j        ¦  «        nd}d}||rd|› d�ndz  }|                      |¦  «        }|€t          d¦  «         dS |pd                     ¦   «         s
|	r|j        }nH ||pd|j        |j        ¬¦  «        }|j        r|j        €t          d|j        › �¦  «         dS |j        }|	r ||j        ¦  «        nd}d}||rd|› d�ndz  }|                      |¦  «        }|€t          d¦  «         dS |pd                     ¦   «         s
|	r|j        }nH ||pd|j        |j        ¬¦  «        }|j        r|j        €t          d|j        › �¦  «         dS |j        }|�|�||k    rt          d¦  «         dS t          ¦   «          d|j        › d  ||¦  «        › d!�} |d ||¦  «        › �¦  «         d"d#g}|                      d$d% ||¦  «        › d ||¦  «        › �|¬¦  «        }|                      ||¦  «        }|d&k    rt          d¦  «         dS dd'lm}m}m} 	  |d(tA          |¦  «        tA          |¦  «        ¬)¦  «         nE# |$ r |  !                    |¦  «         Y dS |$ r!}|  "                    ||¦  «         Y d}~dS d}~ww xY wt          d* ||¦  «        › d ||¦  «        › d+�¦  «         dS ),u7  Screen 4 â€” auto-reload config: threshold + reload-to â†’ PATCH.

        Prefills the current values from ``state.auto_reload``. Validates both
        amounts (2dp, within bounds, ``reload_to > threshold``). When auto-reload
        is already on, offers a "Turn off" path (PATCH ``enabled:false``).
        r   r	   r€  Nr>   rS  r   rB   z1Automatically add funds when your balance is low.z  Card on file: u1     No saved card â€” manage billing on the portal.z  Currently: below rM  rX   z6  Run in the interactive CLI to configure auto-reload.))ÚeditzEdit thresholdsz change when / how much to reload)ÚoffzTurn offzdisable auto-reloadrˆ   u   On â€” below rŒ   rÑ  rÐ  r¬   z   When balance falls below (USD)z [z]: r•   r   r†  r<  z  Reload balance to (USD)u;     ðŸ”´ Reload-to amount must be greater than the threshold.z5By confirming, you authorize Nous Research to charge z whenever your balance reaches z*. Turn off any time here or on the portal.)ÚagreezAgree and turn onzenable auto-reloadrˆ   zTurn on auto-reload?zBelow rÒ  ©rÎ   rÏ   Úpatch_auto_top_upT©rW  Ú	thresholdÚtop_up_amountu     âœ… Auto-reload on: below rè   )#r   r
   r   r   rð   rL  r�  rx  rñ   rV  r   rW  r%   ró   rI  rX  rY  r#   rš   rŸ   Ú_billing_auto_reload_disablerŒ  r›   r‡  rˆ  r�  rŽ  rG   ré   rÎ   rÏ   rÔ  Úfloatr�  rž  )r*   rM   r
   r   r   rL  r�  rñ   ra  Úcurrently_onÚtop_choicesr£   ÚtopÚcur_thrÚ
thr_promptÚthreshold_rawÚthreshold_amtÚtvÚcur_relÚ
rel_promptÚ
reload_rawÚ
reload_amtÚrvÚ_ar_consentr  r“   rÎ   rÏ   rÔ  r÷   s                                 r4   r^  z)CLIBillingMixin._billing_auto_reload_flow^  sË  € ð 	(Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'àKÐKÐKÐKÐKÐKÐKÐKà×*Ò*¨5Ñ1Ô1ð 	ØˆFàŒzˆØÔˆÝ˜BÐ- 2¤:Ñ.Ô.ˆå‰ŒˆØˆÐ-˜"˜"˜]Ñ+Ô+Ð-Ð-Ñ.Ô.Ð.ÝÐ�:ÐÐÑ Ô Ð ØˆÐN�R�RÐKÑLÔLÐNÐNÑOÔOÐOØð 	ÝÐ2 T¤[Ð2Ð2Ñ3Ô3Ð3Ð3åÐEÑFÔFÐFØ×%Ò% eÑ,Ô,Ð,ØˆFØð 	Ýð> l l°2Ô3CÑ&DÔ&Dð >ð >Ø)˜\¨"Ô*:Ñ;Ô;ð>ð >ñô ð õ
 �t˜V TÑ*Ô*ð 	ÝÐJÑKÔKÐKØ×%Ò% eÑ,Ô,Ð,ØˆFð ð 	ðð ð ˆKð
 ×/Ò/Ø#ðB L L°Ô1AÑ$BÔ$Bð Bð BØ!- ¨bÔ.>Ñ!?Ô!?ðBð Bð $ð 0ñ ô ˆCð ×6Ò6°s¸KÑHÔHˆCØ�eŠ|ˆ|Ø×1Ò1°%Ñ8Ô8Ð8Ø�Ø�fŠ}ˆ}ÝÐ)Ñ*Ô*Ð*Ø�ð 5AÐJ�,�,˜rÔ/Ñ0Ô0Ð0ÀdˆØ7ˆ
Ø¨7Ð<Ð'˜7Ð'Ð'Ð'Ð'¸Ñ<ˆ
Ø×/Ò/°
Ñ;Ô;ˆØÐ åÐ%Ñ&Ô&Ð&ØˆFØÐ# ×*Ò*Ñ,Ô,ð 		&°ð 		&ØÔ,ˆMˆMà'Ð'ØÐ# ¨U¬]ÀEÄMðñ ô ˆBð ”5ð ˜BœIÐ-ÝÐ* ¤Ð*Ð*Ñ+Ô+Ð+Ø�ØœIˆMð 5AÐJ�,�,˜rÔ/Ñ0Ô0Ð0ÀdˆØ0ˆ
Ø¨7Ð<Ð'˜7Ð'Ð'Ð'Ð'¸Ñ<ˆ
Ø×,Ò,¨ZÑ8Ô8ˆ
ØÐÝÐ%Ñ&Ô&Ð&ØˆFØÐ ˜b×'Ò'Ñ)Ô)ð 		#¨lð 		#ØÔ)ˆJˆJà'Ð'ØÐ ˜b¨%¬-ÀÄðñ ô ˆBð ”5ð ˜BœIÐ-ÝÐ* ¤Ð*Ð*Ñ+Ô+Ð+Ø�ØœˆJàÐ Ð!6¸*ÈÒ:UÐ:UÝÐOÑPÔPÐPØˆFå‰Œˆð8ÀDÄKð 8ð 8Ø-9¨\¸-Ñ-HÔ-Hð8ð 8ð 8ð 	ð
 	ˆÐ&�R�R˜‘_”_Ð&Ð&Ñ'Ô'Ð'à@Ø.ð
ˆð ×+Ò+Ø(Øb˜L˜L¨Ñ7Ô7ÐbÐbÈÈÐU_ÑH`ÔH`ÐbÐbØ#ð ,ñ 
ô 
ˆð
 ×5Ò5°c¸?ÑKÔKˆØ�WÒÐÝÐ%Ñ&Ô&Ð&ØˆFð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð		ØÐØ­¨mÑ(<Ô(<ÍEÐR\ÑL]ÔL]ðñ ô ð ð øð $ð 	ð 	ð 	Ø×/Ò/°Ñ6Ô6Ð6ØˆFˆFØð 	ð 	ð 	Ø×-Ò-¨e°SÑ9Ô9Ð9ØˆFˆFˆFˆFˆFøøøøð	øøøõ 	ð 7¨\¨\¸-Ñ-HÔ-Hð 7ð 7Ø'˜<¨
Ñ3Ô3ð7ð 7ð 7ñ 	8ô 	8ð 	8ð 	8ð 	8s   Ï9(P" Ð"Q$Ð?Q$ÑQÑQ$c                ól  — ddl m}m}m} |j        }|r|j        �t          |j        ¦  «        nd}|r|j        �t          |j        ¦  «        nd}	  |d||¬¦  «         nE# |$ r |                      |¦  «         Y dS |$ r!}|  	                    ||¦  «         Y d}~dS d}~ww xY wt          d¦  «         dS )zÖTurn off auto-reload (PATCH ``enabled:false``).

        The endpoint requires ``threshold``/``topUpAmount`` in the body even when
        disabling, so we echo back the current values (falling back to 0).
        r   rÓ  Ng        FrÕ  u     âœ… Auto-reload turned off.)ré   rÎ   rÏ   rÔ  rV  rX  rÙ  rY  r�  rž  r%   )	r*   rM   rÎ   rÏ   rÔ  ra  ÚthrÚrelr÷   s	            r4   rØ  z,CLIBillingMixin._billing_auto_reload_disableï  s*  € ð	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð ÔˆØ)+ÐU°Ô0@Ð0L�e�BÔ$Ñ%Ô%Ð%ÐRUˆØ)+ÐU°Ô0@Ð0L�e�BÔ$Ñ%Ô%Ð%ÐRUˆð	ØÐ e°sÈ#ÐNÑNÔNÐNÐNøØ#ð 	ð 	ð 	Ø×/Ò/°Ñ6Ô6Ð6ØˆFˆFØð 	ð 	ð 	Ø×-Ò-¨e°SÑ9Ô9Ð9ØˆFˆFˆFˆFˆFøøøøð	øøøõ 	Ð-Ñ.Ô.Ð.Ð.Ð.s   ÁA  Á B"Á=B"ÂBÂB"c                óÆ  — ddl m}m}m} ddlm} t          ¦   «           |d |d¦  «        › �¦  «         t          dd› �¦  «         |j        }|�|j        € |d |d	¦  «        › �¦  «         nC ||j	        ¦  «        } ||j        ¦  «        }|j
        rd
nd}	t          d|› d|› d|	› �¦  «         d}
 |d ||
¦  «        › �¦  «         |                      |¦  «         dS )uA   Screen 5 â€” monthly spend limit (read-only; cap is portal-only).r   r	   rK  r>   zMonthly spend limitr   rB   Nz/No monthly cap visible (managed on the portal).z (default ceiling)r   z of z used this monthuK   The monthly limit is set on the portal â€” the terminal shows it read-only.)r   r
   r   r   rð   rL  r%   Úmonthly_capÚ	limit_usdÚspent_this_month_usdÚis_default_ceilingrI  )r*   rM   r
   r   r   rL  ÚcapÚspentrT  ÚceilingÚ_limit_notes              r4   r_  z%CLIBillingMixin._billing_limit_screen  sU  € à'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'à3Ð3Ð3Ð3Ð3Ð3å‰ŒˆØˆÐ5˜"˜"Ð2Ñ3Ô3Ð5Ð5Ñ6Ô6Ð6ÝÐ�:ÐÐÑ Ô Ð ØÔˆØˆ;˜#œ-Ð/ØˆGÐP˜˜ÐMÑNÔNÐPÐPÑQÔQÐQÐQà �L Ô!9Ñ:Ô:ˆEØ �L ¤Ñ/Ô/ˆEØ.1Ô.DÐLÐ*Ð*È"ˆGÝÐB�uÐBÐB %ÐBÐB¸ÐBÐBÑCÔCÐCðð 	ð 	ˆÐ&�R�R˜‘_”_Ð&Ð&Ñ'Ô'Ð'Ø×!Ò! %Ñ(Ô(Ð(Ð(Ð(r:   )r   r   )r   r6   )rt   ru   r   r   r’   )rA  )rB  ru   )rî   ru   r   r6   )r   rc  )#Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r9   rP   rL   r|   rb   r—   rc   r»   rÇ   r½   r¼   rê   rë   r  rF  rI  rD  r&   r`  rx  r~  r]  r�  rŸ  r®  rž  r�  r^  rØ  r_  rƒ  r:   r4   r   r      s¾  € € € € € ØJÐJð?ð ?ð ?ð ?ðB	`ð 	`ð 	`ð 	`ð*Kð *Kð *KðXs:ð s:ð s:ðjð ð ð ð8?Fð ?Fð ?FðB D^ð 'ð 'ð 'ð 'ð 'ð< 4ð  4ð  4ðD>ð >ð >ð8 QUð \Kð \Kð \Kð \Kð \Kð|:ð :ð :ð,Y8ÐW[ð Y8ð Y8ð Y8ð Y8ð Y8ðv TXð =hð =hð =hð =hð =hð~)ð )ð )ð")ð )ð )ð$&ð &ð &ð &ð &ð@ <>ð ,ð ,ð ,ð ,ð ,ð ,ðA"ð A"ð A"ðFð ð ð ð*<ð <ð <ðð ð ð ð&*ð *ð *ðXG8ð G8ð G8ðRD<ð D<ð D<ðL*)ð *)ð *)ðX)ð )ð )ð--ð --ð --ð^ ?CÐTXð i<ð i<ð i<ð i<ð i<ðVO8ð O8ð O8ðb/ð /ð /ð2)ð )ð )ð )ð )r:   r   N)r÷  Ú
__future__r   r   rƒ  r:   r4   ú<module>rù     s_   ððð ð #Ð "Ð "Ð "Ð "Ð "ðJ)ð J)ð J)ð J)ð J)ñ J)ô J)ð J)ð J)ð J)r:   