UNPKG

@alvinveroy/codecompass

Version:

AI-powered MCP server for codebase navigation and LLM prompt optimization

95 lines (94 loc) 3.84 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); // Removed unused logger import /** * This script sets the DeepSeek API key in a way that ensures it's available to all parts of the application. * It writes the key to a configuration file that's loaded at startup. */ function main() { // Get API key from command line argument or environment const apiKey = process.argv[2] || process.env.DEEPSEEK_API_KEY; if (!apiKey) { console.error('Error: No API key provided'); console.error('Usage: npm run set-deepseek-key YOUR_API_KEY'); console.error(' or: DEEPSEEK_API_KEY=your_key npm run set-deepseek-key'); process.exit(1); } // Create config directory if it doesn't exist const configDir = path.join(process.env.HOME || process.env.USERPROFILE || '', '.codecompass'); if (!fs.existsSync(configDir)) { fs.mkdirSync(configDir, { recursive: true }); } // Write API key to configuration file const configFile = path.join(configDir, 'deepseek-config.json'); const config = { DEEPSEEK_API_KEY: apiKey, DEEPSEEK_API_URL: process.env.DEEPSEEK_API_URL || "https://api.deepseek.com/chat/completions", timestamp: new Date().toISOString() }; fs.writeFileSync(configFile, JSON.stringify(config, null, 2)); console.log(`DeepSeek API key saved to ${configFile}`); // Also set it in the current environment process.env.DEEPSEEK_API_KEY = apiKey; // Test the connection try { void import('../lib/deepseek.js').then(async (deepseek) => { console.log('Testing DeepSeek connection...'); const connected = await deepseek.testDeepSeekConnection(); if (connected) { console.log('✅ Connection successful! The API key is working.'); } else { console.log('❌ Connection failed. The API key may be invalid or there may be network issues.'); } }); } catch (error) { const err = error; console.error('Error testing connection:', err.message); } } try { main(); } catch (error) { // Unused eslint-disable directive for @typescript-eslint/no-unsafe-call was here console.error('Unhandled error:', error instanceof Error ? error.message : String(error)); process.exit(1); }