UNPKG

@claude-vector/cli

Version:

CLI for Claude-integrated vector search

114 lines (97 loc) 4.2 kB
/** * Agent command - AIエージェント向けAPIサーバーの起動 * * このコマンドはclaude-search専用で、ccvectorには影響しません */ import chalk from 'chalk'; import ora from 'ora'; export const agentCommand = { name: 'agent', description: 'Start AI agent API server', options: [ { flags: '-p, --port <port>', description: 'Port to listen on', default: '3000' }, { flags: '-h, --host <host>', description: 'Host to bind to', default: 'localhost' }, { flags: '--no-open', description: 'Do not open browser automatically' } ], async execute(options) { const spinner = ora('Starting Agent API server...').start(); try { // agent-apiパッケージを動的インポート // これによりccvectorでは読み込まれない const { AgentAPIServer } = await import('@claude-vector/agent-api'); // サーバーの作成 const server = new AgentAPIServer({ port: parseInt(options.port), host: options.host }); // サーバーの起動 await server.start(); spinner.succeed(chalk.green('Agent API server started successfully')); console.log('\n' + chalk.bold('Agent API Server Information:')); console.log(chalk.cyan('URL:'), `http://${options.host}:${options.port}`); console.log(chalk.cyan('API Docs:'), `http://${options.host}:${options.port}/api-docs`); console.log(chalk.cyan('Health Check:'), `http://${options.host}:${options.port}/health`); console.log('\n' + chalk.bold('Available Endpoints:')); console.log(' GET /api/capabilities - List available features'); console.log(' POST /api/search - Perform semantic search'); console.log(' POST /api/sessions - Create development session'); console.log(' POST /api/operations - Start async operation'); console.log(' GET /api/operations/:id - Check operation status'); console.log(' POST /api/batch - Execute batch operations'); console.log('\n' + chalk.bold('WebSocket Support:')); console.log(` ws://${options.host}:${options.port} - Real-time updates`); console.log('\n' + chalk.yellow('Press Ctrl+C to stop the server')); // ブラウザを開く(オプション) if (options.open) { try { const open = (await import('open')).default; await open(`http://${options.host}:${options.port}/api-docs`); } catch (error) { // openパッケージがない場合は警告のみ console.log(chalk.yellow('\nNote: Could not open browser automatically.')); console.log(chalk.cyan(`Please open: http://${options.host}:${options.port}/api-docs`)); } } // グレースフルシャットダウンの設定 process.on('SIGINT', async () => { console.log('\n' + chalk.yellow('Shutting down server...')); await server.stop(); process.exit(0); }); process.on('SIGTERM', async () => { console.log('\n' + chalk.yellow('Shutting down server...')); await server.stop(); process.exit(0); }); } catch (error) { spinner.fail(chalk.red('Failed to start Agent API server')); if (error.code === 'MODULE_NOT_FOUND') { console.error(chalk.red('\nError: @claude-vector/agent-api package not found')); console.error(chalk.yellow('Please ensure agent-api is installed:')); console.error(chalk.cyan(' npm install')); console.error(chalk.cyan(' npm run build')); } else if (error.code === 'EADDRINUSE') { console.error(chalk.red(`\nError: Port ${options.port} is already in use`)); console.error(chalk.yellow('Try a different port:')); console.error(chalk.cyan(` claude-search agent --port 3001`)); } else { console.error(chalk.red('\nError:'), error.message); if (options.verbose) { console.error(error.stack); } } process.exit(1); } } };