UNPKG

@nestbox-ai/cli

Version:

The cli tools that helps developers to build agents

139 lines 8.11 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.registerDocProcDocumentCommands = registerDocProcDocumentCommands; 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"); function registerDocProcDocumentCommands(docProcCommand) { const documentCommand = docProcCommand.command('document').description('Create and inspect document-processing documents'); documentCommand .command('create') .description('Create a document processing job by uploading a file') .requiredOption('--input <path>', 'Document file path') .option('--profile <profileId>', 'Processing profile ID') .option('--stages <stages>', 'Comma-separated stage override') .option('--priority <priority>', 'Job priority: low|normal|high') .option('--tags <tags>', 'Comma-separated list of tags (e.g. "invoice,2024,finance")') .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.input); 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.input)); if (options.profile) form.append('profileId', options.profile); if (options.stages) form.append('stages', options.stages); if (options.priority) form.append('priority', options.priority); 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.documentProcessingControllerCreateDocumentProcessingJob(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('Document processing job created successfully.')); console.log(JSON.stringify(data, null, 2)); })); }); documentCommand .command('list') .description('List processed documents') .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('--profile <profileId>', 'Filter by profile ID') .option('--tags <tags>', 'Filter by comma-separated tags (e.g. "invoice,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.profile) params.profileId = options.profile; if (options.tags) params.tags = options.tags; const response = yield apis.documentProcessingApi.documentProcessingControllerListDocuments(context.projectId, context.instanceId, { params }); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; const documents = (data === null || data === void 0 ? void 0 : data.data) || data || []; if (!documents.length) { console.log(chalk_1.default.yellow('No documents found.')); return; } (0, helpers_1.printSimpleTable)(['Document ID', 'Name', 'Tags', 'Profile ID', 'Processed At'], documents.map((doc) => [ doc.documentId || doc.id || 'N/A', doc.fileName || doc.name || 'N/A', Array.isArray(doc.tags) && doc.tags.length ? doc.tags.join(', ') : '—', doc.profileId || 'N/A', doc.processedAt || doc.createdAt || 'N/A', ])); })); }); documentCommand .command('show') .description('Show processed document details') .requiredOption('--document <documentId>', 'Document 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.documentProcessingControllerGetDocument(context.projectId, context.instanceId, options.document); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(JSON.stringify(data, null, 2)); })); }); documentCommand .command('artifacts') .description('Download document artifacts as zip') .requiredOption('--document <documentId>', 'Document ID') .option('-o, --output <path>', 'Output zip path', './document-artifacts.zip') .option('--project <projectId>', 'Project ID or name (defaults to current project)') .option('--instance <instanceId>', 'Document processing instance ID') .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.documentProcessingControllerDownloadDocumentArtifacts(context.projectId, context.instanceId, options.document, { responseType: 'arraybuffer' }); fs_1.default.writeFileSync(options.output, Buffer.from(response.data)); console.log(chalk_1.default.green(`Artifacts downloaded: ${options.output}`)); })); }); } //# sourceMappingURL=document.js.map