UNPKG

@nestbox-ai/cli

Version:

The cli tools that helps developers to build agents

94 lines 4.96 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerListCommand = registerListCommand; const error_1 = require("../../utils/error"); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const cli_table3_1 = __importDefault(require("cli-table3")); const project_1 = require("../../utils/project"); const agentType_1 = require("../../types/agentType"); const apiUtils_1 = require("./apiUtils"); function registerListCommand(agentCommand) { agentCommand .command("list") .description("List all AI agents associated with the authenticated user") .option("--project <projectName>", "Project name (defaults to the current project)") .action((options) => __awaiter(this, void 0, void 0, function* () { var _a, _b; try { let apis = (0, apiUtils_1.createApis)(); // Execute with token refresh support yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () { var _a; // Resolve project const projectData = yield (0, project_1.resolveProject)(apis.projectsApi, options); const spinner = (0, ora_1.default)(`Listing agents in project ${projectData.name}...`).start(); try { // Get the agents for the specific project const agentsResponse = yield apis.agentsApi.machineAgentControllerGetMachineAgentByProjectId(projectData.id, 0, 10, agentType_1.AgentType.REGULAR); spinner.succeed("Successfully retrieved agents"); // Display the results const agents = ((_a = agentsResponse.data) === null || _a === void 0 ? void 0 : _a.machineAgents) || []; if (!agents || agents.length === 0) { console.log(chalk_1.default.yellow(`No agents found in project ${projectData.name}`)); return; } console.log(chalk_1.default.blue(`\nAgents in project ${projectData.name}:\n`)); // Create a formatted table const table = new cli_table3_1.default({ head: [ chalk_1.default.white.bold("ID"), chalk_1.default.white.bold("Name"), chalk_1.default.white.bold("URL"), ], style: { head: [], border: [], }, }); // Add agents to the table agents.forEach((agent) => { let url = "N/A"; if (agent.instanceIP) { url = `${agent.instanceIP}/v1/agents/${agent.modelBaseId}/query`; } table.push([agent.id || "N/A", agent.agentName || "N/A", url]); }); console.log(table.toString()); console.log(`\nTotal agents: ${agents.length}`); } catch (error) { spinner.fail("Failed to retrieve agents"); throw error; } }), () => { // Recreate APIs after token refresh apis = (0, apiUtils_1.createApis)(); }); } catch (error) { if (error.message && error.message.includes('Authentication')) { console.error(chalk_1.default.red(error.message)); } else if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) { console.error(chalk_1.default.red("API Error:"), error.response.data.message); } else { console.error(chalk_1.default.red("Error:"), error.message || "Unknown error"); } } })); } //# sourceMappingURL=list.js.map