@iqai/adk-cli
Version:
CLI tool for creating, running, and testing ADK-TS agents
129 lines • 6.01 kB
JavaScript
;
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.WebCommand = 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");
// Default hosted web app URL (fallback when bundled assets unavailable or --web-url provided)
const HOSTED_WEB_URL = "https://adk-web.iqai.com";
let WebCommand = class WebCommand extends nest_commander_1.CommandRunner {
async run(_passedParams, options) {
const apiPort = options?.port ?? constants_1.DEFAULT_API_PORT;
const host = options?.host ?? "localhost";
const agentsDir = options?.dir ?? process.cwd();
// Determine mode: bundled (default) vs hosted (when --web-url provided)
const useHostedMode = !!options?.webUrl;
const webUrl = options?.webUrl ?? HOSTED_WEB_URL;
console.log(chalk_1.default.blue("🌐 Starting ADK-TS Web Interface..."));
// Start the server with web serving enabled in bundled mode
const server = await (0, bootstrap_1.startHttpServer)({
port: apiPort,
host,
agentsDir,
quiet: true,
serveWeb: !useHostedMode, // Only serve bundled web UI if not using hosted mode
});
// Determine what URL to show the user
if (!useHostedMode && server.webAssetsAvailable) {
// BUNDLED MODE: Web UI is served on the same port as API
const localUrl = `http://${host}:${apiPort}`;
console.log(chalk_1.default.green("✅ Web UI and API running on the same server"));
console.log(chalk_1.default.cyan(`🔗 Open in your browser: ${localUrl}`));
}
else {
// HOSTED MODE: Either explicitly requested or bundled assets not available
if (!useHostedMode && !server.webAssetsAvailable) {
console.log(chalk_1.default.yellow("⚠️ Bundled web assets not found. Falling back to hosted version."));
console.log(chalk_1.default.gray(" Run 'pnpm build' in the adk-cli package to enable bundled mode."));
}
// Build the web app URL - add port param if not using default
const url = new URL(webUrl);
if (apiPort !== constants_1.DEFAULT_API_PORT) {
url.searchParams.set("port", apiPort.toString());
}
const webAppUrl = url.toString();
console.log(chalk_1.default.cyan(`🔗 Open this URL in your browser: ${webAppUrl}`));
console.log(chalk_1.default.gray(` API Server: http://${host}:${apiPort}`));
}
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: false, // web command always shows output
name: "server",
});
process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);
// Keep the process running
await new Promise(() => { });
}
parsePort(val) {
return Number(val);
}
parseHost(val) {
return val;
}
parseDir(val) {
return val;
}
parseWebUrl(val) {
return val;
}
};
exports.WebCommand = WebCommand;
__decorate([
(0, nest_commander_1.Option)({
flags: "-p, --port <port>",
description: "Port for API server (and web UI in bundled mode)",
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Number)
], WebCommand.prototype, "parsePort", null);
__decorate([
(0, nest_commander_1.Option)({
flags: "-h, --host <host>",
description: "Host for servers",
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", String)
], WebCommand.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)
], WebCommand.prototype, "parseDir", null);
__decorate([
(0, nest_commander_1.Option)({
flags: "--web-url <url>",
description: "Use hosted web UI instead of bundled (e.g., https://adk-web.iqai.com)",
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", String)
], WebCommand.prototype, "parseWebUrl", null);
exports.WebCommand = WebCommand = __decorate([
(0, nest_commander_1.Command)({
name: "web",
description: "Start a web interface for testing agents",
})
], WebCommand);
//# sourceMappingURL=web.command.js.map