UNPKG

@nestbox-ai/cli

Version:

The cli tools that helps developers to build agents

138 lines 7.85 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.registerDocProcEvalCommands = registerDocProcEvalCommands; 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 EVAL_TEMPLATE = `testCases: - id: q1 question: "What are the payment terms?" expectedAnswer: "Net 30" `; function registerDocProcEvalCommands(docProcCommand) { const evalCommand = docProcCommand.command('eval').description('Manage document evaluations'); evalCommand .command('init') .description('Create an eval YAML template') .option('-o, --output <path>', 'Output file path', './eval.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, EVAL_TEMPLATE, options.force); console.log(chalk_1.default.green(`Eval template created: ${options.output}`)); })); }); evalCommand .command('run') .description('Create evaluation from YAML file') .requiredOption('--document <documentId>', 'Document ID') .requiredOption('-f, --file <path>', 'Path to eval 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)); form.append('documentId', options.document); const response = yield apis.documentProcessingApi.documentProcessingControllerCreateEval(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('Evaluation created successfully.')); console.log(JSON.stringify(data, null, 2)); })); }); evalCommand .command('validate') .description('Validate eval YAML for a document without creating evaluation') .requiredOption('--document <documentId>', 'Document ID') .requiredOption('-f, --file <path>', 'Path to eval 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.documentProcessingControllerValidateEvalYaml(context.projectId, context.instanceId, options.document, { 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)); })); }); evalCommand .command('list') .description('List evaluations for a document') .requiredOption('--document <documentId>', 'Document ID') .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.documentProcessingControllerListEvals(context.projectId, context.instanceId, options.document, { 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 evals = (data === null || data === void 0 ? void 0 : data.data) || data || []; if (!evals.length) { console.log(chalk_1.default.yellow('No evaluations found.')); return; } (0, helpers_1.printSimpleTable)(['Eval ID', 'Status', 'Created At'], evals.map((entry) => [entry.id || 'N/A', entry.status || 'N/A', entry.createdAt || 'N/A'])); })); }); evalCommand .command('show') .description('Get evaluation details by eval ID') .requiredOption('--document <documentId>', 'Document ID') .requiredOption('--eval <evalId>', 'Evaluation 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.documentProcessingControllerGetEval(context.projectId, context.instanceId, options.document, options.eval); const data = (0, helpers_1.getResponseData)(response); if ((0, helpers_1.maybePrintJson)(data, options.json)) return; console.log(JSON.stringify(data, null, 2)); })); }); } //# sourceMappingURL=eval.js.map