11use clap:: Args ;
22use crossterm:: style:: Stylize ;
33use crossterm:: {
4- cursor,
54 execute,
65 queue,
76 style,
87} ;
8+ use std:: env;
99
1010use crate :: auth:: builder_id:: is_idc_user;
11+ use crate :: auth:: social:: is_social_logged_in;
1112use crate :: cli:: chat:: {
1213 ActualSubscriptionStatus ,
1314 ChatError ,
1415 ChatSession ,
1516 ChatState ,
1617 get_subscription_status_with_spinner,
17- with_spinner,
1818} ;
1919use crate :: constants:: subscription_text;
2020use crate :: os:: Os ;
2121use crate :: theme:: StyledText ;
2222use crate :: util:: system_info:: is_remote;
2323
24+ const DEFAULT_SUBSCRIPTION_DOMAIN : & str = "app.kiro.dev" ;
25+
26+ fn get_subscription_url ( ) -> String {
27+ let domain = env:: var ( "KIRO_SUBSCRIPTION_DOMAIN" ) . unwrap_or_else ( |_| DEFAULT_SUBSCRIPTION_DOMAIN . to_string ( ) ) ;
28+ format ! ( "https://{domain}/account/usage" )
29+ }
30+
2431/// Arguments for the subscribe command to manage Developer Pro subscriptions
2532#[ deny( missing_docs) ]
2633#[ derive( Debug , PartialEq , Args ) ]
@@ -39,53 +46,30 @@ impl SubscribeArgs {
3946 style:: Print ( format!( "\n {}\n \n " , subscription_text:: idc_subscription_message( ) ) ) ,
4047 StyledText :: reset( ) ,
4148 ) ?;
42- } else if self . manage {
43- queue ! ( session. stderr, style:: Print ( "\n " ) , ) ?;
49+ } else if is_social_logged_in ( & os. database ) . await {
50+ // Social login - redirect to kiro.dev
51+ redirect_to_kiro_dev ( session) . await ?;
52+ } else {
53+ // Builder ID users - check subscription status
4454 match get_subscription_status_with_spinner ( os, & mut session. stderr ) . await {
45- Ok ( status) => {
46- if status != ActualSubscriptionStatus :: Active {
47- queue ! (
55+ Ok ( ActualSubscriptionStatus :: Active ) => {
56+ // Paid Builder ID (active) - keep current experience
57+ if self . manage {
58+ manage_subscription ( os, session) . await ?;
59+ } else {
60+ execute ! (
4861 session. stderr,
4962 StyledText :: warning_fg( ) ,
50- style:: Print ( format!( "{}. " , subscription_text:: no_subscription_message( ) ) ) ,
51- StyledText :: secondary_fg( ) ,
52- style:: Print ( "Use " ) ,
53- StyledText :: success_fg( ) ,
54- style:: Print ( "/subscribe" ) ,
55- StyledText :: secondary_fg( ) ,
56- style:: Print ( " to upgrade your subscription.\n \n " ) ,
63+ style:: Print ( format!( "\n {}\n \n " , subscription_text:: already_subscribed_message( ) ) ) ,
5764 StyledText :: reset( ) ,
5865 ) ?;
5966 }
6067 } ,
61- Err ( err) => {
62- queue ! (
63- session. stderr,
64- StyledText :: error_fg( ) ,
65- style:: Print ( format!( "Failed to get subscription status: {err}\n \n " ) ) ,
66- StyledText :: reset( ) ,
67- ) ?;
68+ _ => {
69+ // Free Builder ID - redirect to kiro.dev
70+ redirect_to_kiro_dev ( session) . await ?;
6871 } ,
6972 }
70-
71- let url = format ! (
72- "https://{}.console.aws.amazon.com/amazonq/developer/home#/subscriptions" ,
73- os. database
74- . get_idc_region( )
75- . ok( )
76- . flatten( )
77- . unwrap_or( "us-east-1" . to_string( ) )
78- ) ;
79- if is_remote ( ) || crate :: util:: open:: open_url_async ( & url) . await . is_err ( ) {
80- execute ! (
81- session. stderr,
82- style:: Print ( format!( "Open this URL to manage your subscription: {}\n \n " , url. blue( ) ) ) ,
83- StyledText :: reset( ) ,
84- StyledText :: reset( ) ,
85- ) ?;
86- }
87- } else {
88- upgrade_to_pro ( os, session) . await ?;
8973 }
9074
9175 Ok ( ChatState :: PromptUser {
@@ -94,93 +78,72 @@ impl SubscribeArgs {
9478 }
9579}
9680
97- async fn upgrade_to_pro ( os : & mut Os , session : & mut ChatSession ) -> Result < ( ) , ChatError > {
98- queue ! ( session. stderr, style:: Print ( "\n " ) , ) ?;
81+ async fn redirect_to_kiro_dev ( session : & mut ChatSession ) -> Result < ( ) , ChatError > {
82+ let url = get_subscription_url ( ) ;
83+
84+ execute ! (
85+ session. stderr,
86+ style:: Print ( "\n " ) ,
87+ StyledText :: primary_fg( ) ,
88+ style:: Print ( "Visit kiro.dev to manage your subscription.\n \n " ) ,
89+ StyledText :: reset( ) ,
90+ ) ?;
91+
92+ if is_remote ( ) || crate :: util:: open:: open_url_async ( & url) . await . is_err ( ) {
93+ execute ! (
94+ session. stderr,
95+ style:: Print ( format!( "Open this URL: {}\n \n " , url. blue( ) ) ) ,
96+ ) ?;
97+ }
9998
100- // Get current subscription status
99+ Ok ( ( ) )
100+ }
101+
102+ async fn manage_subscription ( os : & mut Os , session : & mut ChatSession ) -> Result < ( ) , ChatError > {
103+ queue ! ( session. stderr, style:: Print ( "\n " ) , ) ?;
101104 match get_subscription_status_with_spinner ( os, & mut session. stderr ) . await {
102105 Ok ( status) => {
103- if status = = ActualSubscriptionStatus :: Active {
106+ if status ! = ActualSubscriptionStatus :: Active {
104107 queue ! (
105108 session. stderr,
106109 StyledText :: warning_fg( ) ,
107- style:: Print ( format!( "{}\n \n " , subscription_text:: already_subscribed_message( ) ) ) ,
110+ style:: Print ( format!( "{}. " , subscription_text:: no_subscription_message( ) ) ) ,
111+ StyledText :: secondary_fg( ) ,
112+ style:: Print ( "Use " ) ,
113+ StyledText :: success_fg( ) ,
114+ style:: Print ( "/subscribe" ) ,
115+ StyledText :: secondary_fg( ) ,
116+ style:: Print ( " to upgrade your subscription.\n \n " ) ,
108117 StyledText :: reset( ) ,
109118 ) ?;
110- return Ok ( ( ) ) ;
111119 }
112120 } ,
113- Err ( e ) => {
114- execute ! (
121+ Err ( err ) => {
122+ queue ! (
115123 session. stderr,
116124 StyledText :: error_fg( ) ,
117- style:: Print ( format!( "{e }\n \n " ) ) ,
125+ style:: Print ( format!( "Failed to get subscription status: {err }\n \n " ) ) ,
118126 StyledText :: reset( ) ,
119127 ) ?;
120- // Don't exit early here, the check isn't required to subscribe.
121128 } ,
122129 }
123130
124- // Upgrade information
125- queue ! (
126- session. stderr,
127- StyledText :: primary_fg( ) ,
128- style:: Print ( subscription_text:: subscribe_title( ) ) ,
129- StyledText :: secondary_fg( ) ,
130- style:: Print ( format!( "\n \n {}\n \n " , subscription_text:: SUBSCRIBE_INFO ) ) ,
131- StyledText :: reset( ) ,
132- cursor:: Show
133- ) ?;
134-
135- let prompt = format ! (
136- "{}{}{}{}{}" ,
137- "Would you like to open the AWS console to upgrade? [" . dark_grey( ) ,
138- "y" . green( ) ,
139- "/" . dark_grey( ) ,
140- "n" . green( ) ,
141- "]: " . dark_grey( ) ,
131+ let url = format ! (
132+ "https://{}.console.aws.amazon.com/amazonq/developer/home#/subscriptions" ,
133+ os. database
134+ . get_idc_region( )
135+ . ok( )
136+ . flatten( )
137+ . unwrap_or( "us-east-1" . to_string( ) )
142138 ) ;
143-
144- let user_input = session. read_user_input ( & prompt, true ) ;
145- queue ! ( session. stderr, StyledText :: reset( ) , style:: Print ( "\n " ) , ) ?;
146-
147- if !user_input. is_some_and ( |i| [ "y" , "Y" ] . contains ( & i. as_str ( ) ) ) {
139+ if is_remote ( ) || crate :: util:: open:: open_url_async ( & url) . await . is_err ( ) {
148140 execute ! (
149141 session. stderr,
150- StyledText :: error_fg( ) ,
151- style:: Print ( "Upgrade cancelled.\n \n " ) ,
142+ style:: Print ( format!( "Open this URL to manage your subscription: {}\n \n " , url. blue( ) ) ) ,
152143 StyledText :: reset( ) ,
153- ) ?;
154- return Ok ( ( ) ) ;
155- }
156-
157- // Create a subscription token and open the webpage
158- let r = os. client . create_subscription_token ( ) . await ?;
159-
160- let url = with_spinner ( & mut session. stderr , "Preparing to upgrade..." , || async move {
161- r. encoded_verification_url ( )
162- . map ( |s| s. to_string ( ) )
163- . ok_or ( ChatError :: Custom ( "Missing verification URL" . into ( ) ) )
164- } )
165- . await ?;
166-
167- if is_remote ( ) || crate :: util:: open:: open_url_async ( & url) . await . is_err ( ) {
168- queue ! (
169- session. stderr,
170- StyledText :: secondary_fg( ) ,
171- style:: Print ( format!(
172- "{} Having issues opening the AWS console? Try copy and pasting the URL > {}\n \n " ,
173- "?" . magenta( ) ,
174- url. blue( )
175- ) ) ,
176144 StyledText :: reset( ) ,
177145 ) ?;
178146 }
179147
180- execute ! (
181- session. stderr,
182- style:: Print ( "Once upgraded, type a new prompt to continue your work, or type /quit to exit the chat.\n \n " )
183- ) ?;
184-
185148 Ok ( ( ) )
186149}
0 commit comments