From f0af7e54d78dc7545b89e1c1816a0b09151e278e Mon Sep 17 00:00:00 2001 From: Rohit Rajan Date: Fri, 24 Apr 2026 13:40:48 +0530 Subject: [PATCH] feat: add support for document extraction --- src/commands/robots.ts | 47 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/commands/robots.ts b/src/commands/robots.ts index dc10963..37a086e 100644 --- a/src/commands/robots.ts +++ b/src/commands/robots.ts @@ -1,7 +1,10 @@ import { Command } from 'commander'; import chalk from 'chalk'; import { getClient } from '../lib/api'; -import { spinner, printTable, shortId, formatDate, statusBadge, saveOutput, success, error, printJSON } from '../lib/output'; +import * as fs from 'fs'; +import * as path from 'path'; +import FormData from 'form-data'; +import { spinner, printTable, formatDate, success, error, printJSON } from '../lib/output'; export const robotsCommand = new Command('robots') .description('Manage your Maxun robots'); @@ -212,6 +215,48 @@ robotsCommand } }); +robotsCommand + .command('document ') + .description('Create a document-extraction robot from a local PDF file') + .requiredOption('-p, --prompt ', 'What to extract (e.g. "invoice number, vendor, total")') + .option('-n, --name ', 'Robot name') + .option('--model ', 'Ollama Cloud model override') + .action(async (pdfPath, options) => { + const resolved = path.resolve(pdfPath); + if (!fs.existsSync(resolved)) { + console.error(chalk.red(`File not found: ${resolved}`)); + process.exit(1); + } + + const spin = spinner(`Creating document robot from ${chalk.cyan(path.basename(resolved))}...`); + const client = getClient(); + + try { + const form = new FormData(); + form.append('file', fs.createReadStream(resolved), path.basename(resolved)); + form.append('prompt', options.prompt); + if (options.name) form.append('robotName', options.name); + if (options.model) form.append('ollamaModel', options.model); + + const res = await client.post('/api/sdk/robots/document', form, { + headers: form.getHeaders(), + timeout: 120000, + }); + spin.stop(); + + const robot = res.data?.data || res.data?.robot || res.data; + const robotId = res.data?.robotId || robot?.recording_meta?.id || robot?.id; + const name = robot?.recording_meta?.name || options.name || 'Document Robot'; + + success(`Document robot created: ${chalk.bold(name)} (${chalk.cyan(robotId)})`); + console.log(chalk.gray(` Run it: maxun run ${robotId}`)); + } catch (e: any) { + spin.fail('Failed to create document robot'); + if (e.response?.data?.error) error(e.response.data.error); + process.exit(1); + } + }); + robotsCommand .command('get ') .description('Get robot details')