Skip to main content

sync_auth/providers/
qwen_coder.rs

1//! Qwen Code auth provider.
2
3use crate::{AuthProvider, CredentialFile, ValidationResult};
4use std::path::PathBuf;
5
6/// Provider for Qwen Code CLI credentials (officially "Qwen Code", npm: `qwen-code`).
7///
8/// Qwen Code stores config in `~/.qwen/`.
9/// Key files: `oauth_creds.json` (OAuth tokens), `settings.json` (API keys/settings).
10#[derive(Debug, Clone, Default)]
11pub struct QwenCoderProvider;
12
13#[async_trait::async_trait]
14impl AuthProvider for QwenCoderProvider {
15    fn name(&self) -> &str {
16        "qwen-coder"
17    }
18
19    fn display_name(&self) -> &str {
20        "Qwen Code"
21    }
22
23    fn credential_files(&self) -> Vec<CredentialFile> {
24        let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("~"));
25        vec![CredentialFile {
26            relative_path: "qwen-coder/dot-qwen".to_string(),
27            local_path: home.join(".qwen"),
28            is_dir: true,
29        }]
30    }
31
32    async fn validate(&self) -> ValidationResult {
33        let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("~"));
34        let qwen_dir = home.join(".qwen");
35        if qwen_dir.join("oauth_creds.json").exists() || qwen_dir.join("settings.json").exists() {
36            ValidationResult::Valid
37        } else {
38            ValidationResult::Missing
39        }
40    }
41}