UNPKG

@iqai/adk-cli

Version:

CLI tool for creating, running, and testing ADK-TS agents

137 lines 5.21 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServeCommand = void 0; const chalk_1 = __importDefault(require("chalk")); const nest_commander_1 = require("nest-commander"); const constants_1 = require("../common/constants"); const bootstrap_1 = require("../http/bootstrap"); const graceful_shutdown_1 = require("../utils/graceful-shutdown"); let ServeCommand = class ServeCommand extends nest_commander_1.CommandRunner { async run(_passedParams, options) { const port = options?.port ?? constants_1.DEFAULT_API_PORT; const host = options?.host ?? "localhost"; const agentsDir = options?.dir ?? process.cwd(); const quiet = !!options?.quiet; let swagger; if (options?.swagger) swagger = true; else if (options?.noSwagger) swagger = false; if (!quiet) { console.log(chalk_1.default.blue(`🚀 ADK-TS Server starting on http://${host}:${port}`)); } const server = await (0, bootstrap_1.startHttpServer)({ port, host, agentsDir, quiet, swagger, }); if (!quiet) { console.log(chalk_1.default.green("✅ Server ready")); console.log(chalk_1.default.cyan("Press Ctrl+C to stop the server")); } // Graceful shutdown with single-invocation guard and force-exit fallback const cleanup = (0, graceful_shutdown_1.createGracefulShutdownHandler)(server, { quiet, name: "server", }); process.on("SIGINT", cleanup); process.on("SIGTERM", cleanup); // Keep process running await new Promise(() => { }); } parsePort(val) { return Number(val); } parseHost(val) { return val; } parseDir(val) { return val; } parseQuiet() { return true; } parseSwagger() { return true; } parseNoSwagger() { return true; } }; exports.ServeCommand = ServeCommand; __decorate([ (0, nest_commander_1.Option)({ flags: "-p, --port <port>", description: "Port for the server", }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Number) ], ServeCommand.prototype, "parsePort", null); __decorate([ (0, nest_commander_1.Option)({ flags: "-h, --host <host>", description: "Host for the server", }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", String) ], ServeCommand.prototype, "parseHost", null); __decorate([ (0, nest_commander_1.Option)({ flags: "-d, --dir <directory>", description: "Directory to scan for agents (default: current directory)", }), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", String) ], ServeCommand.prototype, "parseDir", null); __decorate([ (0, nest_commander_1.Option)({ flags: "-q, --quiet", description: "Reduce logging output", defaultValue: false, }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Boolean) ], ServeCommand.prototype, "parseQuiet", null); __decorate([ (0, nest_commander_1.Option)({ flags: "--swagger", description: "Force enable OpenAPI docs (overrides default NODE_ENV-based behavior)", }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Boolean) ], ServeCommand.prototype, "parseSwagger", null); __decorate([ (0, nest_commander_1.Option)({ flags: "--no-swagger", description: "Disable OpenAPI docs (even in non-production)", }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Boolean) ], ServeCommand.prototype, "parseNoSwagger", null); exports.ServeCommand = ServeCommand = __decorate([ (0, nest_commander_1.Command)({ name: "serve", description: "Start an API server for agent management", }) ], ServeCommand); //# sourceMappingURL=serve.command.js.map