@lenne.tech/cli
Version:
lenne.Tech CLI: lt
78 lines (77 loc) • 3.5 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const command = {
alias: ['d'],
description: 'Deletes a Qdrant collection',
name: 'delete',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
const { http, print, prompt } = toolbox;
const qdrantApi = http.create({
baseURL: 'http://localhost:6333',
headers: { 'Content-Type': 'application/json' },
timeout: 5000,
});
// 1. Fetch all collections
const collectionsResponse = yield qdrantApi.get('/collections');
if (!collectionsResponse.ok) {
print.error('Error fetching collections from Qdrant.');
print.info('Please ensure Qdrant is running on http://localhost:6333');
return;
}
const collections = (_b = (_a = collectionsResponse.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.collections;
if (!collections || collections.length === 0) {
print.warning('No collections found in Qdrant.');
return;
}
const collectionNames = collections.map((c) => c.name);
// 2. Ask user to select a collection
const { collectionToDelete } = yield prompt.ask({
choices: collectionNames,
message: 'Which collection do you want to delete?',
name: 'collectionToDelete',
type: 'select',
});
if (!collectionToDelete) {
print.info('No collection selected. Aborting.');
return;
}
print.info(`You selected: ${collectionToDelete}`);
// 3. Confirm the action
const { confirm } = yield prompt.ask({
initial: true,
message: `Are you sure you want to delete collection "${collectionToDelete}"? This action cannot be undone.`,
name: 'confirm',
type: 'confirm',
});
if (!confirm) {
print.info('Aborting.');
return;
}
const spinner = print.spin(`Deleting collection "${collectionToDelete}"...`);
// 4. Delete the collection
const deleteResponse = yield qdrantApi.delete(`/collections/${collectionToDelete}`);
if (!deleteResponse.ok) {
spinner.fail(`Error deleting collection "${collectionToDelete}".`);
print.error(deleteResponse.data);
return;
}
spinner.succeed(`Successfully deleted collection "${collectionToDelete}".`);
// Exit if not running from menu
if (!toolbox.parameters.options.fromGluegunMenu) {
process.exit();
}
// For tests
return `qdrant deleted ${collectionToDelete}`;
}),
};
exports.default = command;