Hotfix: Prevent crash on missing config.cjs & Graceful fallback

This commit is contained in:
Gemini AI
2025-12-14 00:48:56 +04:00
Unverified
parent 8e8d80c110
commit 1b3edad0d2

View File

@@ -29,12 +29,10 @@ try {
// Handle both ESM and CJS exports // Handle both ESM and CJS exports
if (config.default) config = config.default; if (config.default) config = config.default;
} catch (e) { } catch (e) {
// Fallback or error if config is missing // Config missing is expected for first-time users using CLI only.
console.error('Error loading config:', e.message); // We don't crash here - we just run without OAuth support (CLI fallback)
console.error('Error: config.cjs not found. Please copy config.example.cjs to config.cjs and add your Client ID.');
process.exit(1);
} }
const QWEN_OAUTH_CLIENT_ID = config.QWEN_OAUTH_CLIENT_ID; const QWEN_OAUTH_CLIENT_ID = config.QWEN_OAUTH_CLIENT_ID || null;
const QWEN_OAUTH_SCOPE = 'openid profile email model.completion'; const QWEN_OAUTH_SCOPE = 'openid profile email model.completion';
const QWEN_OAUTH_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code'; const QWEN_OAUTH_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code';
const QWEN_CHAT_API = 'https://chat.qwen.ai/api/chat/completions'; const QWEN_CHAT_API = 'https://chat.qwen.ai/api/chat/completions';
@@ -166,6 +164,10 @@ class QwenOAuth {
async startDeviceFlow() { async startDeviceFlow() {
console.log('Starting Qwen Device Code Flow with PKCE...'); console.log('Starting Qwen Device Code Flow with PKCE...');
if (!QWEN_OAUTH_CLIENT_ID) {
throw new Error('Missing Client ID. Please copy config.example.cjs to config.cjs and add your QWEN_OAUTH_CLIENT_ID to use this feature.');
}
// Generate PKCE pair // Generate PKCE pair
this.codeVerifier = generateCodeVerifier(); this.codeVerifier = generateCodeVerifier();
const codeChallenge = generateCodeChallenge(this.codeVerifier); const codeChallenge = generateCodeChallenge(this.codeVerifier);