@nestbox-ai/cli
Version:
The cli tools that helps developers to build agents
85 lines • 4.63 kB
JavaScript
;
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.registerRemoveCommand = registerRemoveCommand;
const error_1 = require("../../utils/error");
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const project_1 = require("../../utils/project");
const agentType_1 = require("../../types/agentType");
const apiUtils_1 = require("./apiUtils");
function registerRemoveCommand(agentCommand) {
agentCommand
.command("remove")
.description("Remove an AI agent")
.requiredOption("--agent <agentId>", "Agent ID to remove")
.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)();
const { agent } = options;
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)(`Finding agent ${agent} in project ${projectData.name}...`).start();
try {
// Get the list of agents to find the correct modelbaseId
const agentsResponse = yield apis.agentsApi.machineAgentControllerGetMachineAgentByProjectId(projectData.id, 0, 100, agentType_1.AgentType.REGULAR);
const agents = ((_a = agentsResponse.data) === null || _a === void 0 ? void 0 : _a.machineAgents) || [];
const targetAgent = agents.find((a) => a.id.toString() === agent.toString());
if (!targetAgent) {
spinner.fail(`Agent with ID ${agent} not found in project ${projectData.name}`);
return;
}
const modelbaseId = targetAgent.modelBaseId;
if (!modelbaseId) {
spinner.fail(`Could not find modelbaseId for agent ${agent}. Please try again.`);
return;
}
spinner.text = `Removing agent ${agent} from project ${projectData.name}...`;
// Remove the agent
const payload = [
{
id: parseInt(agent, 10),
modelbaseId: modelbaseId,
},
];
yield apis.agentsApi.machineAgentControllerDeleteMachineAgents(projectData.id, agent, payload);
spinner.succeed("Successfully removed agent");
console.log(chalk_1.default.green(`Agent ${agent} removed successfully from project ${projectData.name}`));
}
catch (error) {
spinner.fail("Failed to remove agent");
throw error;
}
}), () => {
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=remove.js.map