@halilertekin/claude-code-router-config 1.2.3 → 1.3.3

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/cli/commands.js +148 -62
  2. package/package.json +3 -2
package/cli/commands.js CHANGED
@@ -219,71 +219,157 @@ function backupConfig() {
219
219
  }
220
220
  }
221
221
 
222
+ // Helper to find original ccr binary
223
+ function getOriginalCcrPath() {
224
+ try {
225
+ // Try to find it in dependencies
226
+ return require.resolve('@musistudio/claude-code-router/dist/cli.js');
227
+ } catch (e) {
228
+ return null;
229
+ }
230
+ }
231
+
232
+ // Proxy command to original router
233
+ function proxyToOriginal(args) {
234
+ const originalPath = getOriginalCcrPath();
235
+ if (!originalPath) {
236
+ console.error(chalk.red('❌ Original @musistudio/claude-code-router not found.'));
237
+ return;
238
+ }
239
+
240
+ const child = spawn('node', [originalPath, ...args], {
241
+ stdio: 'inherit',
242
+ env: process.env
243
+ });
244
+
245
+ child.on('exit', (code) => {
246
+ if (code !== 0) {
247
+ process.exit(code || 1);
248
+ }
249
+ });
250
+ }
251
+
222
252
  // CLI command handler
223
253
  async function main() {
224
254
  const [command, ...args] = process.argv.slice(2);
225
-
226
- switch (command) {
227
- case 'test':
228
- const provider = args[0];
229
- const model = args[1];
230
- if (provider) {
231
- await testProvider(provider, model);
232
- } else {
233
- console.error(chalk.red(' Please specify a provider: ccr test <provider> [model]'));
234
- }
235
- break;
236
-
237
- case 'benchmark':
238
- const options = {
239
- allProviders: args.includes('--all'),
240
- compareSpeed: args.includes('--compare-speed')
241
- };
242
- await benchmarkProviders(options);
243
- break;
244
-
245
- case 'status':
246
- const statusOptions = {
247
- detailed: args.includes('--detailed'),
248
- showCosts: args.includes('--show-costs')
249
- };
250
- await showDetailedStatus(statusOptions);
251
- break;
252
-
253
- case 'config':
254
- const configCommand = args[0];
255
- switch (configCommand) {
256
- case 'validate':
257
- validateConfig();
258
- break;
259
- case 'backup':
260
- backupConfig();
261
- break;
262
- default:
263
- console.log(chalk.yellow('Available config commands:'));
264
- console.log(' validate - Check configuration validity');
265
- console.log(' backup - Backup current configuration');
266
- }
267
- break;
268
-
269
- default:
270
- console.log(chalk.blue('Claude Code Router - Advanced CLI'));
271
- console.log(chalk.gray('─'.repeat(40)));
272
- console.log(chalk.yellow('Available commands:'));
273
- console.log('');
274
- console.log('Testing & Benchmarking:');
275
- console.log(' ccr test <provider> [model] - Test provider connection');
276
- console.log(' ccr benchmark [--all] [--compare-speed] - Benchmark providers');
277
- console.log(' ccr status [--detailed] [--show-costs] - Show router status');
278
- console.log('');
279
- console.log('Configuration Management:');
280
- console.log(' ccr config validate - Validate configuration');
281
- console.log(' ccr config backup - Backup configuration');
282
- console.log('');
283
- console.log('Examples:');
284
- console.log(' ccr test openai gpt-4o');
285
- console.log(' ccr benchmark --all --compare-speed');
286
- console.log(' ccr status --detailed --show-costs');
255
+ const advancedCommands = ['test', 'benchmark', 'analytics', 'status', 'config', 'health', 'update', 'help', 'version', '-v', '--version', '--help', '-h'];
256
+
257
+ // Check if it's an advanced command, help/version flag, or no command at all
258
+ const isAdvancedOrHelp = advancedCommands.includes(command) || !command;
259
+
260
+ if (isAdvancedOrHelp) {
261
+ switch (command) {
262
+ case 'update':
263
+ console.log(chalk.blue('🔄 Checking for updates and updating...'));
264
+ const updateProcess = spawn('pnpm', ['add', '-g', '@halilertekin/claude-code-router-config@latest'], {
265
+ stdio: 'inherit',
266
+ env: process.env
267
+ });
268
+ updateProcess.on('exit', (code) => {
269
+ if (code === 0) {
270
+ console.log(chalk.green('✅ Successfully updated to the latest version!'));
271
+ } else {
272
+ console.error(chalk.red(`❌ Update failed with code ${code}. Please try running manually: pnpm add -g @halilertekin/claude-code-router-config@latest`));
273
+ }
274
+ });
275
+ break;
276
+
277
+ case 'version':
278
+ case '-v':
279
+ case '--version':
280
+ const packageJson = require('../package.json');
281
+ console.log(chalk.blue(`v${packageJson.version}`));
282
+ break;
283
+
284
+ case 'test':
285
+ const provider = args[0];
286
+ const model = args[1];
287
+ if (provider) {
288
+ await testProvider(provider, model);
289
+ } else {
290
+ console.error(chalk.red('❌ Please specify a provider: ccr test <provider> [model]'));
291
+ }
292
+ break;
293
+
294
+ case 'benchmark':
295
+ const options = {
296
+ allProviders: args.includes('--all'),
297
+ compareSpeed: args.includes('--compare-speed')
298
+ };
299
+ await benchmarkProviders(options);
300
+ break;
301
+
302
+ case 'status':
303
+ if (args.includes('--detailed')) {
304
+ const statusOptions = {
305
+ detailed: true,
306
+ showCosts: args.includes('--show-costs')
307
+ };
308
+ await showDetailedStatus(statusOptions);
309
+ } else {
310
+ // Pass basic status to original router
311
+ proxyToOriginal(['status', ...args]);
312
+ }
313
+ break;
314
+
315
+ case 'analytics':
316
+ // Forward to analytics script
317
+ const analyticsPath = path.join(__dirname, 'analytics.js');
318
+ spawn('node', [analyticsPath, ...args], { stdio: 'inherit' });
319
+ break;
320
+
321
+ case 'health':
322
+ const healthPath = path.join(__dirname, '../logging/health-monitor.js');
323
+ spawn('node', [healthPath, ...args], { stdio: 'inherit' });
324
+ break;
325
+
326
+ case 'config':
327
+ const configCommand = args[0];
328
+ switch (configCommand) {
329
+ case 'validate':
330
+ validateConfig();
331
+ break;
332
+ case 'backup':
333
+ backupConfig();
334
+ break;
335
+ default:
336
+ console.log(chalk.yellow('Available config commands:'));
337
+ console.log(' validate - Check configuration validity');
338
+ console.log(' backup - Backup current configuration');
339
+ }
340
+ break;
341
+
342
+ default:
343
+ // Handles 'help', '--help', '-h' and empty command
344
+ console.log(chalk.blue('Claude Code Router - Advanced CLI (v1.3.3)'));
345
+ console.log(chalk.gray('─'.repeat(45)));
346
+
347
+ console.log(chalk.yellow('🚀 Advanced CLI Tools:'));
348
+ console.log(' test <provider> [model] - Test provider connection');
349
+ console.log(' benchmark [--all] [--compare-speed] - Benchmark providers');
350
+ console.log(' analytics [period] - View usage statistics');
351
+ console.log(' status --detailed [--show-costs] - Show detailed router status');
352
+ console.log(' config validate - Validate configuration');
353
+ console.log(' config backup - Backup configuration');
354
+ console.log(' health [--all-providers] - Check provider health');
355
+ console.log(' update - Update to the latest version');
356
+
357
+ console.log(chalk.yellow('\n📦 Core Router Commands (Proxy):'));
358
+ console.log(' start - Start router server (Backend only)');
359
+ console.log(' stop - Stop router server');
360
+ console.log(' restart - Restart router server');
361
+ console.log(' status - Show server status');
362
+ console.log(' code - Start Router + Claude Code (Recommended)');
363
+ console.log(' model - Switch models at runtime');
364
+ console.log(' activate - Export env variables');
365
+
366
+ console.log(chalk.yellow('\n💡 Tip:'));
367
+ console.log(' To start everything at once, run: ' + chalk.cyan('ccr code'));
368
+ console.log(' To only start the background server, run: ' + chalk.cyan('ccr start'));
369
+ }
370
+ } else {
371
+ // Forward unknown commands to the original router
372
+ proxyToOriginal([command, ...args]);
287
373
  }
288
374
  }
289
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halilertekin/claude-code-router-config",
3
- "version": "1.2.3",
3
+ "version": "1.3.3",
4
4
  "description": "Multi-provider configuration for Claude Code Router with intent-based routing, advanced CLI tools, analytics, and smart routing. Setup OpenAI, Anthropic, Gemini, Qwen, GLM, OpenRouter, and GitHub Copilot with intelligent routing.",
5
5
  "main": "install.js",
6
6
  "bin": {
@@ -86,7 +86,8 @@
86
86
  "fs-extra": "^11.1.1",
87
87
  "dotenv": "^16.3.1",
88
88
  "express": "^4.18.2",
89
- "cors": "^2.8.5"
89
+ "cors": "^2.8.5",
90
+ "@musistudio/claude-code-router": "^1.0.73"
90
91
  },
91
92
  "devDependencies": {
92
93
  "jest": "^29.7.0"