@nestbox-ai/cli
Version:
The cli tools that helps developers to build agents
182 lines (179 loc) • 9.68 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.registerDocProcProfileCommands = registerDocProcProfileCommands;
const chalk_1 = __importDefault(require("chalk"));
const fs_1 = __importDefault(require("fs"));
const form_data_1 = __importDefault(require("form-data"));
const apiUtils_1 = require("./apiUtils");
const helpers_1 = require("./helpers");
const PROFILE_TEMPLATE = `name: "My Document Pipeline"
description: "Optional description"
docling:
ocr:
enabled: true
engine: rapidocr
chunking:
strategy: docling_hybrid
maxTokens: 1200
overlapTokens: 200
graphrag:
enabled: true
`;
function registerDocProcProfileCommands(docProcCommand) {
const profileCommand = docProcCommand.command('profile').description('Manage document-processing profiles');
profileCommand
.command('init')
.description('Create a profile YAML template')
.option('-o, --output <path>', 'Output file path', './profile.yaml')
.option('-f, --force', 'Overwrite existing file')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
(0, helpers_1.writeTemplateFile)(options.output, PROFILE_TEMPLATE, options.force);
console.log(chalk_1.default.green(`Profile template created: ${options.output}`));
}));
});
profileCommand
.command('create')
.description('Create/register a processing profile from YAML file')
.requiredOption('-f, --file <path>', 'Path to profile YAML file')
.option('-n, --name <name>', 'Override profile name')
.option('--tags <tags>', 'Comma-separated list of tags (e.g. "finance,2024,invoice")')
.option('--project <projectId>', 'Project ID or name (defaults to current project)')
.option('--instance <instanceId>', 'Document processing instance ID')
.option('--json', 'Output JSON')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
(0, helpers_1.ensureFileExists)(options.file);
const apis = (0, apiUtils_1.createDocProcApis)();
if (!apis)
return;
const context = yield (0, helpers_1.resolveDocProcContext)(apis, options);
const form = new form_data_1.default();
// Backend expects the YAML file under the field name 'yaml'
form.append('yaml', fs_1.default.createReadStream(options.file));
if (options.name)
form.append('name', options.name);
if (options.tags) {
const tagList = options.tags.split(',').map((t) => t.trim()).filter(Boolean);
tagList.forEach((tag) => form.append('tags', tag));
}
const response = yield apis.documentProcessingApi.documentProcessingControllerCreateProfile(context.projectId, context.instanceId, { data: form, headers: form.getHeaders() });
const data = (0, helpers_1.getResponseData)(response);
if ((0, helpers_1.maybePrintJson)(data, options.json))
return;
console.log(chalk_1.default.green('Profile created successfully.'));
console.log(JSON.stringify(data, null, 2));
}));
});
profileCommand
.command('validate')
.description('Validate a profile YAML file against profile schema')
.requiredOption('-f, --file <path>', 'Path to profile YAML file')
.option('--project <projectId>', 'Project ID or name (defaults to current project)')
.option('--instance <instanceId>', 'Document processing instance ID')
.option('--json', 'Output JSON')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
(0, helpers_1.ensureFileExists)(options.file);
const apis = (0, apiUtils_1.createDocProcApis)();
if (!apis)
return;
const context = yield (0, helpers_1.resolveDocProcContext)(apis, options);
const form = new form_data_1.default();
form.append('file', fs_1.default.createReadStream(options.file));
const response = yield apis.documentProcessingApi.documentProcessingControllerValidateQueryYaml(context.projectId, context.instanceId, { data: form, headers: form.getHeaders() });
const data = (0, helpers_1.getResponseData)(response);
if ((0, helpers_1.maybePrintJson)(data, options.json))
return;
console.log(chalk_1.default.green('Validation response:'));
console.log(JSON.stringify(data, null, 2));
}));
});
profileCommand
.command('list')
.description('List processing profiles')
.option('--project <projectId>', 'Project ID or name (defaults to current project)')
.option('--instance <instanceId>', 'Document processing instance ID')
.option('--page <page>', 'Page number', '1')
.option('--limit <limit>', 'Page size', '20')
.option('--tags <tags>', 'Filter by comma-separated tags (e.g. "finance,2024")')
.option('--json', 'Output JSON')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
const apis = (0, apiUtils_1.createDocProcApis)();
if (!apis)
return;
const context = yield (0, helpers_1.resolveDocProcContext)(apis, options);
const params = { page: Number(options.page), limit: Number(options.limit) };
if (options.tags)
params.tags = options.tags;
const response = yield apis.documentProcessingApi.documentProcessingControllerListProfiles(context.projectId, context.instanceId, { params });
const data = (0, helpers_1.getResponseData)(response);
if ((0, helpers_1.maybePrintJson)(data, options.json))
return;
const profiles = (data === null || data === void 0 ? void 0 : data.data) || data || [];
if (!profiles.length) {
console.log(chalk_1.default.yellow('No profiles found.'));
return;
}
(0, helpers_1.printSimpleTable)(['Profile ID', 'Name', 'Tags', 'Created At'], profiles.map((profile) => [
profile.id || 'N/A',
profile.name || 'N/A',
Array.isArray(profile.tags) && profile.tags.length ? profile.tags.join(', ') : '—',
profile.createdAt || 'N/A',
]));
}));
});
profileCommand
.command('show')
.description('Show a processing profile by ID')
.requiredOption('--profile <profileId>', 'Profile ID')
.option('--project <projectId>', 'Project ID or name (defaults to current project)')
.option('--instance <instanceId>', 'Document processing instance ID')
.option('--json', 'Output JSON')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
const apis = (0, apiUtils_1.createDocProcApis)();
if (!apis)
return;
const context = yield (0, helpers_1.resolveDocProcContext)(apis, options);
const response = yield apis.documentProcessingApi.documentProcessingControllerGetProfile(context.projectId, context.instanceId, options.profile);
const data = (0, helpers_1.getResponseData)(response);
if ((0, helpers_1.maybePrintJson)(data, options.json))
return;
console.log(JSON.stringify(data, null, 2));
}));
});
profileCommand
.command('schema')
.description('Get profile schema for YAML configuration')
.option('--project <projectId>', 'Project ID or name (defaults to current project)')
.option('--instance <instanceId>', 'Document processing instance ID')
.option('--json', 'Output JSON')
.action((options) => {
(0, helpers_1.withDocProcErrorHandling)(() => __awaiter(this, void 0, void 0, function* () {
const apis = (0, apiUtils_1.createDocProcApis)();
if (!apis)
return;
const context = yield (0, helpers_1.resolveDocProcContext)(apis, options);
const response = yield apis.documentProcessingApi.documentProcessingControllerGetProfileSchema(context.projectId, context.instanceId);
const data = (0, helpers_1.getResponseData)(response);
if ((0, helpers_1.maybePrintJson)(data, options.json))
return;
console.log(JSON.stringify(data, null, 2));
}));
});
}
//# sourceMappingURL=profile.js.map