ropilot 0.1.32 → 0.1.34

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.
Files changed (2) hide show
  1. package/lib/proxy.js +40 -20
  2. package/package.json +1 -1
package/lib/proxy.js CHANGED
@@ -177,11 +177,15 @@ async function checkPluginUpdate() {
177
177
  }
178
178
  }
179
179
 
180
+ // Cached key validation result
181
+ let keyValidationError = null;
182
+
180
183
  /**
181
- * Validate API key with edge server
182
- * Returns { valid: true } or { valid: false, reason: string }
184
+ * Validate API key with edge server (cached)
183
185
  */
184
186
  async function validateApiKey(apiKey) {
187
+ if (keyValidationError !== null) return keyValidationError;
188
+
185
189
  try {
186
190
  const url = `${EDGE_URL}/mcp/${apiKey}`;
187
191
  const response = await fetch(url, {
@@ -196,19 +200,18 @@ async function validateApiKey(apiKey) {
196
200
  });
197
201
 
198
202
  if (response.status === 401 || response.status === 403) {
199
- return { valid: false, reason: 'Invalid or expired API key' };
200
- }
201
- if (response.status === 402) {
202
- return { valid: false, reason: 'No credits remaining - upgrade at https://ropilot.ai' };
203
- }
204
- if (!response.ok) {
205
- return { valid: false, reason: `Server error: ${response.status}` };
203
+ keyValidationError = '[ROPILOT] API key is invalid. Tell the user to follow these steps: 1. Log into the Ropilot dashboard at https://ropilot.ai 2. Copy their API key 3. Run "npx ropilot init" in this directory and paste the key';
204
+ } else if (response.status === 402) {
205
+ keyValidationError = '[ROPILOT] No credits remaining. Tell the user to upgrade their plan at https://ropilot.ai';
206
+ } else if (!response.ok) {
207
+ keyValidationError = `[ROPILOT] Server error (${response.status}). Tell the user to try again later.`;
206
208
  }
207
- return { valid: true };
208
209
  } catch (err) {
209
- // Network error - might be offline, let it proceed and fail later
210
- return { valid: true };
210
+ // Network error - don't cache, might be temporary
211
+ return `[ROPILOT] Cannot reach server. Tell the user to check their internet connection and try again.`;
211
212
  }
213
+
214
+ return keyValidationError;
212
215
  }
213
216
 
214
217
  /**
@@ -223,14 +226,6 @@ export async function serve() {
223
226
  process.exit(1);
224
227
  }
225
228
 
226
- // Validate API key before starting
227
- const validation = await validateApiKey(apiKey);
228
- if (!validation.valid) {
229
- console.error(`[Ropilot] ${validation.reason}`);
230
- console.error('[Ropilot] Update your key with "npx ropilot init" or at https://ropilot.ai');
231
- process.exit(1);
232
- }
233
-
234
229
  // Run update in background (non-blocking) - keeps prompts fresh
235
230
  runBackgroundUpdate();
236
231
 
@@ -305,6 +300,31 @@ export async function serve() {
305
300
  */
306
301
  async function handleRequest(apiKey, request) {
307
302
  try {
303
+ // For initialize, we respond locally first, then validate in background
304
+ if (request.method === 'initialize') {
305
+ // Validate key in background (caches result for later requests)
306
+ validateApiKey(apiKey);
307
+
308
+ // Return a basic initialize response so MCP connects
309
+ sendResponse({
310
+ jsonrpc: '2.0',
311
+ id: request.id,
312
+ result: {
313
+ protocolVersion: '2024-11-05',
314
+ capabilities: { tools: {} },
315
+ serverInfo: { name: 'ropilot', version: '1.0.0' }
316
+ }
317
+ });
318
+ return;
319
+ }
320
+
321
+ // For other requests, check if key is valid first
322
+ const keyError = await validateApiKey(apiKey);
323
+ if (keyError) {
324
+ sendError(request.id, -32000, keyError);
325
+ return;
326
+ }
327
+
308
328
  const response = await processRequest(apiKey, request);
309
329
  if (response) {
310
330
  sendResponse(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ropilot",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "AI-powered Roblox development assistant - MCP CLI",
5
5
  "author": "whut",
6
6
  "license": "MIT",