()
| 362 | } |
| 363 | |
| 364 | async function handleAlibabaLogin() { |
| 365 | const check = await checkExistingConnection("alibaba") |
| 366 | if (!check.proceed) { |
| 367 | prompts.outro("Cancelled") |
| 368 | return |
| 369 | } |
| 370 | |
| 371 | prompts.log.info("Authorize Alibaba (Qwen Code) with your Qwen account via device login.") |
| 372 | |
| 373 | const { ArcticQwenAuth } = await import("../../auth/qwen-oauth") |
| 374 | const plugin = await ArcticQwenAuth({} as any) |
| 375 | |
| 376 | if (!plugin.auth) { |
| 377 | throw new Error("Qwen auth plugin failed to initialize") |
| 378 | } |
| 379 | |
| 380 | const oauthMethod = plugin.auth.methods.find((m) => m.type === "oauth") |
| 381 | if (!oauthMethod || !oauthMethod.authorize) { |
| 382 | throw new Error("Qwen OAuth method not found") |
| 383 | } |
| 384 | |
| 385 | const authorize = await oauthMethod.authorize() |
| 386 | |
| 387 | if (authorize.instructions) { |
| 388 | prompts.log.info(authorize.instructions) |
| 389 | } |
| 390 | |
| 391 | if (authorize.method === "auto" && authorize.callback) { |
| 392 | const spinner = prompts.spinner() |
| 393 | spinner.start("Waiting for authorization...") |
| 394 | const result = await authorize.callback() |
| 395 | if (result.type === "failed") { |
| 396 | spinner.stop("Failed to authorize", 1) |
| 397 | } |
| 398 | if (result.type === "success") { |
| 399 | spinner.stop("Login successful") |
| 400 | |
| 401 | const alibabaAuth = await Auth.get("alibaba") |
| 402 | if (alibabaAuth) { |
| 403 | const authKey = check.connectionName ? Auth.formatKey("alibaba", check.connectionName) : "alibaba" |
| 404 | if (authKey !== "alibaba") { |
| 405 | await Auth.set(authKey, alibabaAuth) |
| 406 | await Auth.remove("alibaba") |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | prompts.outro("Done") |
| 413 | } |
| 414 | |
| 415 | export const AuthCommand = cmd({ |
| 416 | command: "auth", |
no test coverage detected