UNPKG

@nestbox-ai/cli

Version:

The cli tools that helps developers to build agents

133 lines 7.46 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.registerDocProcQueryCommands = registerDocProcQueryCommands; 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 QUERY_TEMPLATE = `queries: - id: payment_terms question: "What are the payment terms?" mode: local `; function registerDocProcQueryCommands(docProcCommand) { const queryCommand = docProcCommand.command('query').description('Manage batch query YAML submissions'); queryCommand .command('init') .description('Create a batch query YAML template') .option('-o, --output <path>', 'Output file path', './query.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, QUERY_TEMPLATE, options.force); console.log(chalk_1.default.green(`Query template created: ${options.output}`)); })); }); queryCommand .command('create') .description('Create a batch query from YAML file') .requiredOption('-f, --file <path>', 'YAML file path') .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.documentProcessingControllerCreateBatchQuery(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('Batch query created successfully.')); console.log(JSON.stringify(data, null, 2)); })); }); queryCommand .command('validate') .description('Validate query YAML without creating a query') .requiredOption('-f, --file <path>', 'YAML file path') .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(JSON.stringify(data, null, 2)); })); }); queryCommand .command('list') .description('List batch queries') .option('--page <page>', 'Page number', '1') .option('--limit <limit>', 'Page size', '20') .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.documentProcessingControllerListQueries(context.projectId, context.instanceId, { params: { page: Number(options.page), limit: Number(options.limit) } }); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; const queries = (data === null || data === void 0 ? void 0 : data.data) || data || []; if (!queries.length) { console.log(chalk_1.default.yellow('No queries found.')); return; } (0, helpers_1.printSimpleTable)(['Query ID', 'Name', 'Created At'], queries.map((query) => [query.id || 'N/A', query.name || 'N/A', query.createdAt || 'N/A'])); })); }); queryCommand .command('show') .description('Get batch query details by ID') .requiredOption('--query <queryId>', 'Query 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.documentProcessingControllerGetQuery(context.projectId, context.instanceId, options.query); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(JSON.stringify(data, null, 2)); })); }); } //# sourceMappingURL=query.js.map