Skip to content

Commit 7468e82

Browse files
docs: atualiza README com instruções completas
- Instruções de instalação via GitHub - Explica Device Flow com polling automático - Documenta provider qwen-code e modelos disponíveis - Adiciona seção de troubleshooting - Atualiza URL do repositório
1 parent c9fb609 commit 7468e82

2 files changed

Lines changed: 98 additions & 97 deletions

File tree

README.md

Lines changed: 97 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,161 @@
1-
# Qwen OAuth Plugin for OpenCode
1+
# opencode-qwen-auth
22

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**.
44

5-
## Features
5+
## Funcionalidades
66

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`
1213

13-
## Quick Start
14+
## Instalação
1415

15-
### 1. Add the plugin to your OpenCode config
16+
### 1. Adicione o plugin ao OpenCode
1617

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`:
1829

1930
```json
2031
{
21-
"$schema": "https://opencode.ai/config.json",
2232
"plugin": ["opencode-qwen-auth"]
2333
}
2434
```
2535

26-
### 2. Authenticate
36+
### 2. Instale as dependências
2737

2838
```bash
29-
opencode auth login
39+
cd ~/.opencode && npm install
3040
```
3141

32-
Choose the **Qwen** provider and select **OAuth with Qwen (qwen.ai account)**.
42+
### 3. Autentique
3343

34-
### 3. Start using Qwen models
44+
Inicie o OpenCode e selecione o provider **Qwen Code**:
3545

3646
```bash
37-
opencode --model qwen/qwen3-coder-plus
47+
opencode
3848
```
3949

40-
## Available Models
50+
Ou via linha de comando (selecione "Other" e digite `qwen-code`):
4151

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+
```
4955

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.
5157

52-
Just run:
58+
### 4. Use os modelos Qwen
5359

5460
```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
6062
```
6163

62-
## Configuration
64+
## Modelos Disponíveis
6365

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 |
6570

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
8772

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
9177

92-
## Quota Information
78+
## Limites de Uso
9379

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 |
9783

98-
## Local Development
84+
## Desenvolvimento Local
9985

10086
```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
10389
cd opencode-qwen-auth
10490

105-
# Install dependencies
91+
# Instale dependências
10692
bun install
10793

108-
# Build
109-
bun run build
94+
# Verifique tipos
95+
bun run typecheck
11096

111-
# Link to OpenCode config
112-
# Add to ~/.config/opencode/opencode.json:
97+
# Link local no OpenCode
98+
# Edite ~/.opencode/package.json:
11399
{
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+
}
115103
}
104+
105+
# Reinstale
106+
cd ~/.opencode && npm install
116107
```
117108

118-
## How It Works
109+
## Estrutura do Projeto
119110

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+
```
124124

125125
## Troubleshooting
126126

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
135128

136-
The plugin automatically refreshes tokens. If issues persist:
129+
O plugin renova tokens automaticamente. Se houver problemas:
137130

138131
```bash
139-
# Remove old credentials
132+
# Remova credenciais antigas
140133
rm ~/.qwen/oauth_creds.json
141134

142-
# Re-authenticate
135+
# Re-autentique
143136
opencode auth login
144137
```
145138

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
147148

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
151152

152-
## Related Projects
153+
## Projetos Relacionados
153154

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
157158

158-
## License
159+
## Licença
159160

160161
MIT

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"license": "MIT",
2525
"repository": {
2626
"type": "git",
27-
"url": "https://github.com/YOUR_USERNAME/opencode-qwen-auth"
27+
"url": "https://github.com/gustavodiasdev/opencode-qwen-auth"
2828
},
2929
"dependencies": {
3030
"open": "^10.1.0"

0 commit comments

Comments
 (0)