|
1 | | -# Qwen OAuth Plugin for OpenCode |
| 1 | +# opencode-qwen-auth |
2 | 2 |
|
3 | | -Authenticate OpenCode CLI with your qwen.ai account to use Qwen3-Coder models with **2,000 free requests per day**! |
| 3 | +Plugin de autenticação OAuth para [OpenCode CLI](https://opencode.ai) que permite usar modelos Qwen3-Coder através da sua conta [qwen.ai](https://chat.qwen.ai) com **2.000 requisições gratuitas por dia**. |
4 | 4 |
|
5 | | -## Features |
| 5 | +## Funcionalidades |
6 | 6 |
|
7 | | -- 🔐 **OAuth Authentication** - Sign in with your qwen.ai account |
8 | | -- 🆓 **Free Tier** - 2,000 requests/day, 60 requests/minute (no token limits!) |
9 | | -- 🔄 **Auto-refresh** - Automatic token refresh |
10 | | -- 🔗 **qwen-code compatible** - Reuses credentials from qwen-code CLI |
11 | | -- ⚡ **1M Context** - Access to models with 1M token context windows |
| 7 | +- **OAuth Device Flow** - Autenticação segura via navegador (RFC 8628) |
| 8 | +- **Polling Automático** - Detecta automaticamente quando você autoriza no navegador |
| 9 | +- **2.000 req/dia grátis** - Sem necessidade de cartão de crédito |
| 10 | +- **1M de contexto** - Modelos com janela de contexto de 1 milhão de tokens |
| 11 | +- **Auto-refresh** - Renova tokens automaticamente quando expiram |
| 12 | +- **Compatível com qwen-code** - Reutiliza credenciais existentes de `~/.qwen/oauth_creds.json` |
12 | 13 |
|
13 | | -## Quick Start |
| 14 | +## Instalação |
14 | 15 |
|
15 | | -### 1. Add the plugin to your OpenCode config |
| 16 | +### 1. Adicione o plugin ao OpenCode |
16 | 17 |
|
17 | | -Create or edit `~/.config/opencode/opencode.json`: |
| 18 | +Edite `~/.opencode/package.json`: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "dependencies": { |
| 23 | + "opencode-qwen-auth": "github:gustavodiasdev/opencode-qwen-auth" |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +Edite `~/.opencode/opencode.jsonc`: |
18 | 29 |
|
19 | 30 | ```json |
20 | 31 | { |
21 | | - "$schema": "https://opencode.ai/config.json", |
22 | 32 | "plugin": ["opencode-qwen-auth"] |
23 | 33 | } |
24 | 34 | ``` |
25 | 35 |
|
26 | | -### 2. Authenticate |
| 36 | +### 2. Instale as dependências |
27 | 37 |
|
28 | 38 | ```bash |
29 | | -opencode auth login |
| 39 | +cd ~/.opencode && npm install |
30 | 40 | ``` |
31 | 41 |
|
32 | | -Choose the **Qwen** provider and select **OAuth with Qwen (qwen.ai account)**. |
| 42 | +### 3. Autentique |
33 | 43 |
|
34 | | -### 3. Start using Qwen models |
| 44 | +Inicie o OpenCode e selecione o provider **Qwen Code**: |
35 | 45 |
|
36 | 46 | ```bash |
37 | | -opencode --model qwen/qwen3-coder-plus |
| 47 | +opencode |
38 | 48 | ``` |
39 | 49 |
|
40 | | -## Available Models |
| 50 | +Ou via linha de comando (selecione "Other" e digite `qwen-code`): |
41 | 51 |
|
42 | | -| Model | Context | Output | Description | |
43 | | -|-------|---------|--------|-------------| |
44 | | -| `qwen3-coder-plus` | 1M tokens | 64K tokens | Most capable coding model | |
45 | | -| `qwen3-coder-flash` | 1M tokens | 64K tokens | Faster responses | |
46 | | -| `qwen-coder-plus` | 128K tokens | 32K tokens | Standard coding model | |
47 | | - |
48 | | -## Alternative: Import from qwen-code |
| 52 | +```bash |
| 53 | +opencode auth login |
| 54 | +``` |
49 | 55 |
|
50 | | -If you already use [qwen-code](https://github.com/QwenLM/qwen-code), this plugin will automatically detect and reuse your existing credentials from `~/.qwen/oauth_creds.json`. |
| 56 | +Escolha **"Qwen Code (qwen.ai OAuth)"** e autorize no navegador. |
51 | 57 |
|
52 | | -Just run: |
| 58 | +### 4. Use os modelos Qwen |
53 | 59 |
|
54 | 60 | ```bash |
55 | | -# First, authenticate with qwen-code |
56 | | -qwen # This will prompt for OAuth login |
57 | | - |
58 | | -# Then OpenCode will automatically use those credentials |
59 | | -opencode --model qwen/qwen3-coder-plus |
| 61 | +opencode --provider qwen-code --model qwen3-coder-plus |
60 | 62 | ``` |
61 | 63 |
|
62 | | -## Configuration |
| 64 | +## Modelos Disponíveis |
63 | 65 |
|
64 | | -### Full config example |
| 66 | +| Modelo | Contexto | Output | Descrição | |
| 67 | +|--------|----------|--------|-----------| |
| 68 | +| `qwen3-coder-plus` | 1M tokens | 64K tokens | Modelo mais capaz para programação | |
| 69 | +| `qwen3-coder-flash` | 1M tokens | 64K tokens | Respostas mais rápidas | |
65 | 70 |
|
66 | | -```json |
67 | | -{ |
68 | | - "$schema": "https://opencode.ai/config.json", |
69 | | - "plugin": ["opencode-qwen-auth"], |
70 | | - "provider": { |
71 | | - "qwen": { |
72 | | - "models": { |
73 | | - "qwen3-coder-plus": { |
74 | | - "name": "Qwen3 Coder Plus (OAuth)", |
75 | | - "limit": { |
76 | | - "context": 1048576, |
77 | | - "output": 65536 |
78 | | - } |
79 | | - } |
80 | | - } |
81 | | - } |
82 | | - } |
83 | | -} |
84 | | -``` |
85 | | - |
86 | | -### Environment Variables |
| 71 | +## Como Funciona |
87 | 72 |
|
88 | | -| Variable | Description | |
89 | | -|----------|-------------| |
90 | | -| `OPENCODE_QWEN_DEBUG` | Set to `1` to enable debug logging | |
| 73 | +1. **Device Flow (RFC 8628)**: Ao fazer login, o plugin abre seu navegador para `chat.qwen.ai` |
| 74 | +2. **Polling Automático**: O plugin detecta automaticamente quando você autoriza (sem precisar pressionar Enter) |
| 75 | +3. **Armazenamento**: Credenciais são salvas em `~/.qwen/oauth_creds.json` (compatível com qwen-code) |
| 76 | +4. **Auto-refresh**: Tokens são renovados automaticamente 30 segundos antes de expirar |
91 | 77 |
|
92 | | -## Quota Information |
| 78 | +## Limites de Uso |
93 | 79 |
|
94 | | -| Plan | Rate Limit | Daily Limit | |
95 | | -|------|------------|-------------| |
96 | | -| Free (OAuth) | 60 requests/min | 2,000 requests/day | |
| 80 | +| Plano | Rate Limit | Limite Diário | |
| 81 | +|-------|------------|---------------| |
| 82 | +| Gratuito (OAuth) | 60 req/min | 2.000 req/dia | |
97 | 83 |
|
98 | | -## Local Development |
| 84 | +## Desenvolvimento Local |
99 | 85 |
|
100 | 86 | ```bash |
101 | | -# Clone the repository |
102 | | -git clone https://github.com/YOUR_USERNAME/opencode-qwen-auth.git |
| 87 | +# Clone o repositório |
| 88 | +git clone https://github.com/gustavodiasdev/opencode-qwen-auth.git |
103 | 89 | cd opencode-qwen-auth |
104 | 90 |
|
105 | | -# Install dependencies |
| 91 | +# Instale dependências |
106 | 92 | bun install |
107 | 93 |
|
108 | | -# Build |
109 | | -bun run build |
| 94 | +# Verifique tipos |
| 95 | +bun run typecheck |
110 | 96 |
|
111 | | -# Link to OpenCode config |
112 | | -# Add to ~/.config/opencode/opencode.json: |
| 97 | +# Link local no OpenCode |
| 98 | +# Edite ~/.opencode/package.json: |
113 | 99 | { |
114 | | - "plugin": ["file:///absolute/path/to/opencode-qwen-auth/dist/index.js"] |
| 100 | + "dependencies": { |
| 101 | + "opencode-qwen-auth": "file:/caminho/absoluto/para/opencode-qwen-auth" |
| 102 | + } |
115 | 103 | } |
| 104 | + |
| 105 | +# Reinstale |
| 106 | +cd ~/.opencode && npm install |
116 | 107 | ``` |
117 | 108 |
|
118 | | -## How It Works |
| 109 | +## Estrutura do Projeto |
119 | 110 |
|
120 | | -1. **OAuth Flow**: Opens your browser to qwen.ai for authentication |
121 | | -2. **Token Storage**: Saves credentials to `~/.qwen/oauth_creds.json` |
122 | | -3. **Auto-refresh**: Refreshes tokens automatically when they expire |
123 | | -4. **API Proxy**: Routes OpenCode requests through Qwen's chat API |
| 111 | +``` |
| 112 | +src/ |
| 113 | +├── constants.ts # Constantes (endpoints OAuth, modelos) |
| 114 | +├── types.ts # Interfaces TypeScript |
| 115 | +├── index.ts # Plugin principal |
| 116 | +├── cli.ts # CLI standalone (opcional) |
| 117 | +├── qwen/ |
| 118 | +│ └── oauth.ts # Lógica OAuth Device Flow + PKCE |
| 119 | +└── plugin/ |
| 120 | + ├── auth.ts # Gerenciamento de credenciais |
| 121 | + ├── client.ts # Cliente API Qwen |
| 122 | + └── utils.ts # Utilitários |
| 123 | +``` |
124 | 124 |
|
125 | 125 | ## Troubleshooting |
126 | 126 |
|
127 | | -### Port 14561 already in use |
128 | | - |
129 | | -The plugin uses port 14561 for the OAuth callback. If it's busy: |
130 | | - |
131 | | -1. Check for other processes: `lsof -i :14561` |
132 | | -2. Kill the process or wait for it to finish |
133 | | - |
134 | | -### Token expired |
| 127 | +### Token expirado |
135 | 128 |
|
136 | | -The plugin automatically refreshes tokens. If issues persist: |
| 129 | +O plugin renova tokens automaticamente. Se houver problemas: |
137 | 130 |
|
138 | 131 | ```bash |
139 | | -# Remove old credentials |
| 132 | +# Remova credenciais antigas |
140 | 133 | rm ~/.qwen/oauth_creds.json |
141 | 134 |
|
142 | | -# Re-authenticate |
| 135 | +# Re-autentique |
143 | 136 | opencode auth login |
144 | 137 | ``` |
145 | 138 |
|
146 | | -### Rate limit exceeded |
| 139 | +### Provider não aparece no `auth login` |
| 140 | + |
| 141 | +O provider `qwen-code` é adicionado via plugin. No comando `opencode auth login`: |
| 142 | +1. Selecione **"Other"** |
| 143 | +2. Digite `qwen-code` |
| 144 | + |
| 145 | +No TUI (interface gráfica do OpenCode), o provider aparece automaticamente. |
| 146 | + |
| 147 | +### Rate limit excedido |
147 | 148 |
|
148 | | -If you hit the daily limit (2,000 requests): |
149 | | -- Wait until midnight UTC for quota reset |
150 | | -- Consider using API keys for higher limits |
| 149 | +Se atingir o limite diário (2.000 requisições): |
| 150 | +- Aguarde até meia-noite UTC para reset |
| 151 | +- Considere usar API Key do [DashScope](https://dashscope.aliyun.com) para limites maiores |
151 | 152 |
|
152 | | -## Related Projects |
| 153 | +## Projetos Relacionados |
153 | 154 |
|
154 | | -- [qwen-code](https://github.com/QwenLM/qwen-code) - Official Qwen coding CLI |
155 | | -- [opencode-gemini-auth](https://github.com/jenslys/opencode-gemini-auth) - Gemini OAuth plugin (inspiration for this project) |
156 | | -- [qwen-code-oai-proxy](https://github.com/aptdnfapt/qwen-code-oai-proxy) - Proxy for using Qwen with any OpenAI-compatible client |
| 155 | +- [qwen-code](https://github.com/QwenLM/qwen-code) - CLI oficial do Qwen para programação |
| 156 | +- [OpenCode](https://opencode.ai) - CLI de IA para desenvolvimento |
| 157 | +- [opencode-gemini-auth](https://github.com/jenslys/opencode-gemini-auth) - Plugin similar para Google Gemini |
157 | 158 |
|
158 | | -## License |
| 159 | +## Licença |
159 | 160 |
|
160 | 161 | MIT |
0 commit comments