opencode-qwen-oauth 1.0.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -1
- package/dist/browser.d.ts +10 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +87 -0
- package/dist/browser.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +25 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +79 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -205
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +15 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +79 -0
- package/dist/logger.js.map +1 -0
- package/dist/mutex.d.ts +30 -0
- package/dist/mutex.d.ts.map +1 -0
- package/dist/mutex.js +90 -0
- package/dist/mutex.js.map +1 -0
- package/dist/oauth.d.ts +33 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +262 -0
- package/dist/oauth.js.map +1 -0
- package/dist/pkce.d.ts +8 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +17 -0
- package/dist/pkce.js.map +1 -0
- package/dist/retry.d.ts +18 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +74 -0
- package/dist/retry.js.map +1 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +125 -0
- package/dist/validation.js.map +1 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ Qwen OAuth authentication plugin for [OpenCode](https://opencode.ai) - authentic
|
|
|
14
14
|
- 📝 **File Logging** - All OAuth activity logged to `~/.config/opencode/logs/qwen-oauth.log`
|
|
15
15
|
- 🐛 **Debug Mode** - Enable verbose output with `QWEN_OAUTH_DEBUG=true`
|
|
16
16
|
- 🚀 **Easy Install** - One-command installation with CLI tool
|
|
17
|
+
- 🎯 **Custom Headers** - Automatically adds Qwen-specific headers to API requests
|
|
18
|
+
- ⚙️ **Optimized Parameters** - Pre-configured temperature and topP settings for Qwen models
|
|
19
|
+
- 🌍 **Environment Variables** - Exposes Qwen credentials to shell environments
|
|
20
|
+
- 📊 **Event Monitoring** - Tracks authentication and session events for debugging
|
|
17
21
|
|
|
18
22
|
## Quick Start
|
|
19
23
|
|
|
@@ -139,6 +143,25 @@ Use the CLI directly:
|
|
|
139
143
|
opencode auth login qwen
|
|
140
144
|
```
|
|
141
145
|
|
|
146
|
+
### Browser doesn't open automatically (Linux)
|
|
147
|
+
The plugin tries multiple methods to open your browser:
|
|
148
|
+
1. First tries `xdg-open` (standard Linux)
|
|
149
|
+
2. Falls back to: `google-chrome`, `firefox`, `chromium`, `brave-browser`, `microsoft-edge`
|
|
150
|
+
|
|
151
|
+
If none work, manually copy the URL shown in the terminal and open it in your browser.
|
|
152
|
+
|
|
153
|
+
To ensure browser opening works, install `xdg-utils`:
|
|
154
|
+
```bash
|
|
155
|
+
# Ubuntu/Debian
|
|
156
|
+
sudo apt install xdg-utils
|
|
157
|
+
|
|
158
|
+
# Fedora/RHEL
|
|
159
|
+
sudo dnf install xdg-utils
|
|
160
|
+
|
|
161
|
+
# Arch Linux
|
|
162
|
+
sudo pacman -S xdg-utils
|
|
163
|
+
```
|
|
164
|
+
|
|
142
165
|
### Check logs
|
|
143
166
|
```bash
|
|
144
167
|
cat ~/.config/opencode/logs/qwen-oauth.log
|
|
@@ -181,12 +204,47 @@ cd /path/to/project
|
|
|
181
204
|
opencode-qwen-oauth install
|
|
182
205
|
```
|
|
183
206
|
|
|
207
|
+
## Plugin Architecture
|
|
208
|
+
|
|
209
|
+
This plugin implements multiple OpenCode plugin hooks:
|
|
210
|
+
|
|
211
|
+
### Hooks Implemented
|
|
212
|
+
|
|
213
|
+
#### `auth` Hook
|
|
214
|
+
Provides OAuth device flow authentication with automatic browser opening and token polling.
|
|
215
|
+
|
|
216
|
+
#### `config` Hook
|
|
217
|
+
Dynamically registers the Qwen provider and available models with OpenCode.
|
|
218
|
+
|
|
219
|
+
#### `event` Hook
|
|
220
|
+
Monitors session events (creation, errors) for debugging and logging.
|
|
221
|
+
|
|
222
|
+
#### `chat.headers` Hook
|
|
223
|
+
Injects custom headers for Qwen API requests:
|
|
224
|
+
- `X-Qwen-Client: OpenCode`
|
|
225
|
+
- `X-Qwen-Plugin-Version: 1.1.0`
|
|
226
|
+
|
|
227
|
+
#### `chat.params` Hook
|
|
228
|
+
Optimizes model parameters for Qwen:
|
|
229
|
+
- Temperature: `0.7` (default)
|
|
230
|
+
- Top P: `0.95` (default)
|
|
231
|
+
|
|
232
|
+
#### `shell.env` Hook
|
|
233
|
+
Exposes environment variables to shell commands:
|
|
234
|
+
- `QWEN_API_BASE_URL` - Qwen API endpoint
|
|
235
|
+
- `QWEN_PROVIDER` - Provider identifier
|
|
236
|
+
|
|
184
237
|
## Project Structure
|
|
185
238
|
|
|
186
239
|
```
|
|
187
240
|
opencode-qwen-oauth/
|
|
188
241
|
├── src/ # TypeScript source files
|
|
189
|
-
│
|
|
242
|
+
│ ├── index.ts # Main plugin with hooks
|
|
243
|
+
│ ├── oauth.ts # OAuth device flow logic
|
|
244
|
+
│ ├── pkce.ts # PKCE implementation
|
|
245
|
+
│ ├── browser.ts # Browser opening utility
|
|
246
|
+
│ ├── logger.ts # Logging utilities
|
|
247
|
+
│ └── constants.ts # API constants
|
|
190
248
|
├── bin/ # CLI scripts
|
|
191
249
|
│ └── install.js # Installer script
|
|
192
250
|
├── dist/ # Compiled JavaScript (generated)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser utilities for opening URLs
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Opens a URL in the default browser
|
|
6
|
+
* Supports macOS, Windows, and Linux with fallback mechanisms
|
|
7
|
+
* Debounced to prevent multiple rapid calls
|
|
8
|
+
*/
|
|
9
|
+
export declare function openBrowser(url: string): void;
|
|
10
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE7C"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser utilities for opening URLs
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { Debouncer } from "./mutex.js";
|
|
6
|
+
// Debouncer to prevent multiple rapid browser opens
|
|
7
|
+
const browserDebouncer = new Debouncer();
|
|
8
|
+
/**
|
|
9
|
+
* Opens a URL in the default browser
|
|
10
|
+
* Supports macOS, Windows, and Linux with fallback mechanisms
|
|
11
|
+
* Debounced to prevent multiple rapid calls
|
|
12
|
+
*/
|
|
13
|
+
export function openBrowser(url) {
|
|
14
|
+
openBrowserDebounced(url);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Internal debounced browser opening function
|
|
18
|
+
*/
|
|
19
|
+
const openBrowserDebounced = browserDebouncer.debounce(async (url) => {
|
|
20
|
+
openBrowserInternal(url);
|
|
21
|
+
}, 1000);
|
|
22
|
+
/**
|
|
23
|
+
* Internal function that actually opens the browser
|
|
24
|
+
*/
|
|
25
|
+
function openBrowserInternal(url) {
|
|
26
|
+
try {
|
|
27
|
+
const platform = process.platform;
|
|
28
|
+
let command;
|
|
29
|
+
let args;
|
|
30
|
+
if (platform === "darwin") {
|
|
31
|
+
// macOS
|
|
32
|
+
command = "open";
|
|
33
|
+
args = [url];
|
|
34
|
+
}
|
|
35
|
+
else if (platform === "win32") {
|
|
36
|
+
// Windows
|
|
37
|
+
command = "rundll32";
|
|
38
|
+
args = ["url.dll,FileProtocolHandler", url];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Linux and other Unix-like systems
|
|
42
|
+
// Try xdg-open first, with fallbacks
|
|
43
|
+
command = "xdg-open";
|
|
44
|
+
args = [url];
|
|
45
|
+
// Check if xdg-open exists, if not try common browsers
|
|
46
|
+
const child = spawn(command, args, {
|
|
47
|
+
stdio: "ignore",
|
|
48
|
+
detached: true,
|
|
49
|
+
});
|
|
50
|
+
child.on("error", (error) => {
|
|
51
|
+
// xdg-open failed, try common Linux browsers
|
|
52
|
+
const browsers = [
|
|
53
|
+
"google-chrome",
|
|
54
|
+
"firefox",
|
|
55
|
+
"chromium",
|
|
56
|
+
"brave-browser",
|
|
57
|
+
"microsoft-edge",
|
|
58
|
+
];
|
|
59
|
+
for (const browser of browsers) {
|
|
60
|
+
try {
|
|
61
|
+
const browserChild = spawn(browser, [url], {
|
|
62
|
+
stdio: "ignore",
|
|
63
|
+
detached: true,
|
|
64
|
+
});
|
|
65
|
+
browserChild.unref?.();
|
|
66
|
+
return; // Success, exit
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Try next browser
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
child.unref?.();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const child = spawn(command, args, {
|
|
78
|
+
stdio: "ignore",
|
|
79
|
+
detached: true,
|
|
80
|
+
});
|
|
81
|
+
child.unref?.();
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Silently fail - user can manually open the URL
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"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AE;gBAC1B,6CAA6C;gBAC7C,MAAM,QAAQ,GAAG;oBACf,eAAe;oBACf,SAAS;oBACT,UAAU;oBACV,eAAe;oBACf,gBAAgB;iBACjB,CAAC;gBAEF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;oBAC/B,IAAI,CAAC;wBACH,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE;4BACzC,KAAK,EAAE,QAAQ;4BACf,QAAQ,EAAE,IAAI;yBACf,CAAC,CAAC;wBACH,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC;wBACvB,OAAO,CAAC,gBAAgB;oBAC1B,CAAC;oBAAC,MAAM,CAAC;wBACP,mBAAmB;wBACnB,SAAS;oBACX,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;YACjC,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iDAAiD;IACnD,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration system for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export interface QwenConfig {
|
|
5
|
+
/** Request timeout in milliseconds */
|
|
6
|
+
timeout: number;
|
|
7
|
+
/** Maximum number of retries for failed requests */
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
/** Time before token expiry to trigger refresh (milliseconds) */
|
|
10
|
+
refreshThreshold: number;
|
|
11
|
+
/** Logging level */
|
|
12
|
+
logLevel: "debug" | "info" | "warn" | "error";
|
|
13
|
+
/** Base delay for exponential backoff (milliseconds) */
|
|
14
|
+
baseRetryDelay: number;
|
|
15
|
+
/** Maximum delay for exponential backoff (milliseconds) */
|
|
16
|
+
maxRetryDelay: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const defaultConfig: QwenConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Get configuration with environment variable overrides
|
|
21
|
+
*/
|
|
22
|
+
export declare function getConfig(): QwenConfig;
|
|
23
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB;IACpB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC9C,wDAAwD;IACxD,cAAc,EAAE,MAAM,CAAC;IACvB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,EAAE,UAO3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,IAAI,UAAU,CAStC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration system for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export const defaultConfig = {
|
|
5
|
+
timeout: 30000, // 30 seconds
|
|
6
|
+
maxRetries: 3,
|
|
7
|
+
refreshThreshold: 300000, // 5 minutes
|
|
8
|
+
logLevel: process.env.QWEN_OAUTH_DEBUG === "true" ? "debug" : "info",
|
|
9
|
+
baseRetryDelay: 1000, // 1 second
|
|
10
|
+
maxRetryDelay: 30000, // 30 seconds
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get configuration with environment variable overrides
|
|
14
|
+
*/
|
|
15
|
+
export function getConfig() {
|
|
16
|
+
return {
|
|
17
|
+
timeout: parseInt(process.env.QWEN_OAUTH_TIMEOUT || String(defaultConfig.timeout)),
|
|
18
|
+
maxRetries: parseInt(process.env.QWEN_OAUTH_MAX_RETRIES || String(defaultConfig.maxRetries)),
|
|
19
|
+
refreshThreshold: parseInt(process.env.QWEN_OAUTH_REFRESH_THRESHOLD || String(defaultConfig.refreshThreshold)),
|
|
20
|
+
logLevel: process.env.QWEN_OAUTH_LOG_LEVEL || defaultConfig.logLevel,
|
|
21
|
+
baseRetryDelay: defaultConfig.baseRetryDelay,
|
|
22
|
+
maxRetryDelay: defaultConfig.maxRetryDelay,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,MAAM,CAAC,MAAM,aAAa,GAAe;IACvC,OAAO,EAAE,KAAK,EAAE,aAAa;IAC7B,UAAU,EAAE,CAAC;IACb,gBAAgB,EAAE,MAAM,EAAE,YAAY;IACtC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;IACpE,cAAc,EAAE,IAAI,EAAE,WAAW;IACjC,aAAa,EAAE,KAAK,EAAE,aAAa;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAClF,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC5F,gBAAgB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAC9G,QAAQ,EAAG,OAAO,CAAC,GAAG,CAAC,oBAA4B,IAAI,aAAa,CAAC,QAAQ;QAC7E,cAAc,EAAE,aAAa,CAAC,cAAc;QAC5C,aAAa,EAAE,aAAa,CAAC,aAAa;KAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export declare const QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
|
|
5
|
+
export declare const QWEN_DEVICE_CODE_ENDPOINT = "/api/v1/oauth2/device/code";
|
|
6
|
+
export declare const QWEN_TOKEN_ENDPOINT = "/api/v1/oauth2/token";
|
|
7
|
+
export declare const QWEN_CLIENT_ID = "f0304373b74a44d2b584a3fb70ca9e56";
|
|
8
|
+
export declare const QWEN_SCOPES: string[];
|
|
9
|
+
export declare const QWEN_API_BASE_URL = "https://portal.qwen.ai/v1";
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,yBAAyB,+BAA+B,CAAC;AACtE,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,cAAc,qCAAqC,CAAC;AACjE,eAAO,MAAM,WAAW,UAAqD,CAAC;AAC9E,eAAO,MAAM,iBAAiB,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export const QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
|
|
5
|
+
export const QWEN_DEVICE_CODE_ENDPOINT = "/api/v1/oauth2/device/code";
|
|
6
|
+
export const QWEN_TOKEN_ENDPOINT = "/api/v1/oauth2/token";
|
|
7
|
+
export const QWEN_CLIENT_ID = "f0304373b74a44d2b584a3fb70ca9e56";
|
|
8
|
+
export const QWEN_SCOPES = ["openid", "profile", "email", "model.completion"];
|
|
9
|
+
export const QWEN_API_BASE_URL = "https://portal.qwen.ai/v1";
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAC1D,MAAM,CAAC,MAAM,yBAAyB,GAAG,4BAA4B,CAAC;AACtE,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAC1D,MAAM,CAAC,MAAM,cAAc,GAAG,kCAAkC,CAAC;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error types for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export declare class QwenAuthError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
recoverable: boolean;
|
|
7
|
+
userMessage?: string | undefined;
|
|
8
|
+
constructor(message: string, code: string, recoverable?: boolean, userMessage?: string | undefined);
|
|
9
|
+
}
|
|
10
|
+
export declare class NetworkError extends QwenAuthError {
|
|
11
|
+
constructor(message: string, userMessage?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class TokenExpiredError extends QwenAuthError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class RateLimitError extends QwenAuthError {
|
|
17
|
+
constructor(message: string, waitTimeMs?: number);
|
|
18
|
+
}
|
|
19
|
+
export declare class AuthorizationError extends QwenAuthError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class ValidationError extends QwenAuthError {
|
|
23
|
+
constructor(message: string, field?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class DeviceFlowError extends QwenAuthError {
|
|
26
|
+
errorType?: string | undefined;
|
|
27
|
+
constructor(message: string, errorType?: string | undefined);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if error is recoverable
|
|
31
|
+
*/
|
|
32
|
+
export declare function isRecoverableError(error: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get user-friendly error message
|
|
35
|
+
*/
|
|
36
|
+
export declare function getUserMessage(error: unknown): string;
|
|
37
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,aAAc,SAAQ,KAAK;IAG7B,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,OAAO;IACpB,WAAW,CAAC,EAAE,MAAM;gBAH3B,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,OAAc,EAC3B,WAAW,CAAC,EAAE,MAAM,YAAA;CAM9B;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CASlD;AAED,qBAAa,iBAAkB,SAAQ,aAAa;gBACtC,OAAO,GAAE,MAA4B;CASlD;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAOjD;AAED,qBAAa,kBAAmB,SAAQ,aAAa;gBACvC,OAAO,EAAE,MAAM;CAS5B;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAS5C;AAED,qBAAa,eAAgB,SAAQ,aAAa;IACZ,SAAS,CAAC,EAAE,MAAM;gBAA1C,OAAO,EAAE,MAAM,EAAS,SAAS,CAAC,EAAE,MAAM,YAAA;CAIvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQrD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error types for Qwen OAuth Plugin
|
|
3
|
+
*/
|
|
4
|
+
export class QwenAuthError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
recoverable;
|
|
7
|
+
userMessage;
|
|
8
|
+
constructor(message, code, recoverable = true, userMessage) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.recoverable = recoverable;
|
|
12
|
+
this.userMessage = userMessage;
|
|
13
|
+
this.name = "QwenAuthError";
|
|
14
|
+
Error.captureStackTrace(this, this.constructor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class NetworkError extends QwenAuthError {
|
|
18
|
+
constructor(message, userMessage) {
|
|
19
|
+
super(message, "NETWORK_ERROR", true, userMessage || "Network request failed. Please check your connection.");
|
|
20
|
+
this.name = "NetworkError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class TokenExpiredError extends QwenAuthError {
|
|
24
|
+
constructor(message = "Token has expired") {
|
|
25
|
+
super(message, "TOKEN_EXPIRED", true, "Your authentication token has expired. Please re-authenticate.");
|
|
26
|
+
this.name = "TokenExpiredError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class RateLimitError extends QwenAuthError {
|
|
30
|
+
constructor(message, waitTimeMs) {
|
|
31
|
+
const userMsg = waitTimeMs
|
|
32
|
+
? `Rate limit exceeded. Please wait ${Math.ceil(waitTimeMs / 1000)} seconds.`
|
|
33
|
+
: "Rate limit exceeded. Please try again later.";
|
|
34
|
+
super(message, "RATE_LIMIT_EXCEEDED", true, userMsg);
|
|
35
|
+
this.name = "RateLimitError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class AuthorizationError extends QwenAuthError {
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message, "AUTHORIZATION_ERROR", false, "Authorization failed. Please check your credentials.");
|
|
41
|
+
this.name = "AuthorizationError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class ValidationError extends QwenAuthError {
|
|
45
|
+
constructor(message, field) {
|
|
46
|
+
super(message, "VALIDATION_ERROR", false, field ? `Invalid ${field}: ${message}` : message);
|
|
47
|
+
this.name = "ValidationError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class DeviceFlowError extends QwenAuthError {
|
|
51
|
+
errorType;
|
|
52
|
+
constructor(message, errorType) {
|
|
53
|
+
super(message, "DEVICE_FLOW_ERROR", true, message);
|
|
54
|
+
this.errorType = errorType;
|
|
55
|
+
this.name = "DeviceFlowError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type guard to check if error is recoverable
|
|
60
|
+
*/
|
|
61
|
+
export function isRecoverableError(error) {
|
|
62
|
+
if (error instanceof QwenAuthError) {
|
|
63
|
+
return error.recoverable;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get user-friendly error message
|
|
69
|
+
*/
|
|
70
|
+
export function getUserMessage(error) {
|
|
71
|
+
if (error instanceof QwenAuthError && error.userMessage) {
|
|
72
|
+
return error.userMessage;
|
|
73
|
+
}
|
|
74
|
+
if (error instanceof Error) {
|
|
75
|
+
return error.message;
|
|
76
|
+
}
|
|
77
|
+
return "An unexpected error occurred";
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAG7B;IACA;IACA;IAJT,YACE,OAAe,EACR,IAAY,EACZ,cAAuB,IAAI,EAC3B,WAAoB;QAE3B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAgB;QAC3B,gBAAW,GAAX,WAAW,CAAS;QAG3B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,YAAY,OAAe,EAAE,WAAoB;QAC/C,KAAK,CACH,OAAO,EACP,eAAe,EACf,IAAI,EACJ,WAAW,IAAI,uDAAuD,CACvE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAClD,YAAY,UAAkB,mBAAmB;QAC/C,KAAK,CACH,OAAO,EACP,eAAe,EACf,IAAI,EACJ,gEAAgE,CACjE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,aAAa;IAC/C,YAAY,OAAe,EAAE,UAAmB;QAC9C,MAAM,OAAO,GAAG,UAAU;YACxB,CAAC,CAAC,oCAAoC,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW;YAC7E,CAAC,CAAC,8CAA8C,CAAC;QACnD,KAAK,CAAC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O,CAAC;IACvB,CAAC;IACD,OAAO,8BAA8B,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,qBAAqB,CAAC;AAU/D,eAAO,MAAM,eAAe,EAAE,MA4K7B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|