@@ -132,18 +132,19 @@ export const QwenAuthPlugin = async (_input: unknown) => {
132132 const deviceAuth = await requestDeviceAuthorization ( challenge ) ;
133133 openBrowser ( deviceAuth . verification_uri_complete ) ;
134134
135+ const POLLING_MARGIN_MS = 3000 ;
136+
135137 return {
136138 url : deviceAuth . verification_uri_complete ,
137- instructions : `Abra o link e autorize.\n\nCódigo: ${ deviceAuth . user_code } \n\nApós autorizar, pressione Enter...` ,
138- method : 'code' ,
139- callback : async ( _code : string ) => {
140- // Polling após Enter
139+ instructions : `Código: ${ deviceAuth . user_code } ` ,
140+ method : 'auto' as const ,
141+ callback : async ( ) => {
141142 const startTime = Date . now ( ) ;
142143 const timeoutMs = deviceAuth . expires_in * 1000 ;
143- let interval = 2000 ;
144+ let interval = 5000 ;
144145
145146 while ( Date . now ( ) - startTime < timeoutMs ) {
146- await new Promise ( r => setTimeout ( r , interval ) ) ;
147+ await Bun . sleep ( interval + POLLING_MARGIN_MS ) ;
147148
148149 try {
149150 const tokenResponse = await pollDeviceToken ( deviceAuth . device_code , verifier ) ;
@@ -153,7 +154,7 @@ export const QwenAuthPlugin = async (_input: unknown) => {
153154 saveCredentials ( credentials ) ;
154155
155156 return {
156- type : 'success' ,
157+ type : 'success' as const ,
157158 access : credentials . accessToken ,
158159 refresh : credentials . refreshToken || '' ,
159160 expires : credentials . expiryDate || Date . now ( ) + 3600000 ,
@@ -162,23 +163,23 @@ export const QwenAuthPlugin = async (_input: unknown) => {
162163 } catch ( e ) {
163164 const msg = e instanceof Error ? e . message : '' ;
164165 if ( msg . includes ( 'slow_down' ) ) {
165- interval = Math . min ( interval * 1.5 , 10000 ) ;
166+ interval = Math . min ( interval + 5000 , 15000 ) ;
166167 } else if ( ! msg . includes ( 'authorization_pending' ) ) {
167- return { type : 'failed' } ;
168+ return { type : 'failed' as const } ;
168169 }
169170 }
170171 }
171172
172- return { type : 'failed' } ;
173+ return { type : 'failed' as const } ;
173174 } ,
174175 } ;
175176 } catch ( e ) {
176177 const msg = e instanceof Error ? e . message : 'Erro desconhecido' ;
177178 return {
178179 url : '' ,
179180 instructions : `Erro: ${ msg } ` ,
180- method : 'code' ,
181- callback : async ( ) => ( { type : 'failed' } ) ,
181+ method : 'auto' as const ,
182+ callback : async ( ) => ( { type : 'failed' as const } ) ,
182183 } ;
183184 }
184185 } ,
0 commit comments