Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/commands/robots.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -212,6 +215,48 @@ robotsCommand
}
});

robotsCommand
.command('document <pdf>')
.description('Create a document-extraction robot from a local PDF file')
.requiredOption('-p, --prompt <prompt>', 'What to extract (e.g. "invoice number, vendor, total")')
.option('-n, --name <name>', 'Robot name')
.option('--model <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 <id>')
.description('Get robot details')
Expand Down