@nestbox-ai/cli
Version:
The cli tools that helps developers to build agents
63 lines • 4 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.registerCollectionListCommand = registerCollectionListCommand;
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 apiUtils_1 = require("./apiUtils");
function registerCollectionListCommand(collectionCommand) {
const listCmd = collectionCommand
.command('list')
.description('List document collections for a specific instance')
.requiredOption('--instance <instanceId>', 'Instance ID')
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
listCmd.action((options) => __awaiter(this, void 0, void 0, function* () {
yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const apis = (0, apiUtils_1.createDocumentApis)();
const project = yield (0, project_1.resolveProject)(apis.projectsApi, options);
const spinner = (0, ora_1.default)(`Listing document collections for instance ${options.instance} in project ${project.name}...`).start();
try {
const response = yield apis.documentsApi.documentControllerGetAllCollections(project.id, options.instance);
const collections = Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.collections) ? response.data.collections : [];
spinner.succeed('Successfully retrieved document collections');
if (collections.length === 0) {
console.log(chalk_1.default.yellow(`No document collections found for instance ${options.instance} in project ${project.name}`));
return;
}
console.log(chalk_1.default.blue(`\nDocument collections for instance ${options.instance} in project ${project.name}:\n`));
collections.forEach((collection) => {
const name = typeof collection === 'string' ? collection : (collection === null || collection === void 0 ? void 0 : collection.name) || 'Unnamed Collection';
console.log(chalk_1.default.white.bold(name));
});
}
catch (error) {
spinner.fail('Operation failed');
if (error.response && error.response.status === 401) {
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
}
else if ((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.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');
}
throw error;
}
}));
}));
}
//# sourceMappingURL=collectionList.js.map