11#!/usr/bin/env node
2- import { Command } from 'commander' ;
3- import ora from 'ora' ;
4- import chalk from 'chalk' ;
5- import { extractDocument } from '@doc-agent/extract' ;
6- import type { Config } from '@doc-agent/core' ;
72import { exec } from 'node:child_process' ;
83import { promisify } from 'node:util' ;
4+ import type { Config } from '@doc-agent/core' ;
5+ import { extractDocument } from '@doc-agent/extract' ;
6+ import chalk from 'chalk' ;
7+ import { Command } from 'commander' ;
8+ import ora from 'ora' ;
99
1010const execAsync = promisify ( exec ) ;
1111
@@ -24,8 +24,8 @@ async function ensureOllamaModel(model: string) {
2424 if ( ! response . ok ) {
2525 throw new Error ( 'Ollama is not running. Please start Ollama first.' ) ;
2626 }
27- const data = await response . json ( ) as { models : { name : string } [ ] } ;
28- const modelExists = data . models . some ( m => m . name . includes ( model ) ) ;
27+ const data = ( await response . json ( ) ) as { models : { name : string } [ ] } ;
28+ const modelExists = data . models . some ( ( m ) => m . name . includes ( model ) ) ;
2929
3030 if ( ! modelExists ) {
3131 spinner . text = `Pulling Ollama model: ${ model } (this may take a while)...` ;
@@ -46,31 +46,35 @@ program
4646 . command ( 'extract <file>' )
4747 . description ( 'Extract structured data from a document' )
4848 . option ( '-p, --provider <provider>' , 'AI provider (gemini|openai|ollama)' , 'ollama' )
49- . option ( '-m, --model <model>' , 'Model to use (default: llama3.2-vision for ollama)' , 'llama3.2-vision' )
49+ . option (
50+ '-m, --model <model>' ,
51+ 'Model to use (default: llama3.2-vision for ollama)' ,
52+ 'llama3.2-vision'
53+ )
5054 . action ( async ( file : string , options ) => {
5155 try {
5256 if ( options . provider === 'ollama' ) {
5357 await ensureOllamaModel ( options . model ) ;
5458 }
5559
5660 const spinner = ora ( 'Extracting document data...' ) . start ( ) ;
57-
61+
5862 const config : Config = {
5963 aiProvider : options . provider ,
6064 geminiApiKey : process . env . GEMINI_API_KEY ,
6165 openaiApiKey : process . env . OPENAI_API_KEY ,
62- ollamaModel : options . model
66+ ollamaModel : options . model ,
6367 } ;
64-
68+
6569 const result = await extractDocument ( file , config ) ;
66-
70+
6771 spinner . succeed ( chalk . green ( 'Extraction complete!' ) ) ;
6872 console . log ( JSON . stringify ( result , null , 2 ) ) ;
6973 } catch ( error ) {
7074 // Only fail the spinner if it's running (ensureOllamaModel might have failed already)
7175 if ( ora ( ) . isSpinning ) {
72- // This check is tricky because ora() creates a new instance.
73- // We'll just log the error.
76+ // This check is tricky because ora() creates a new instance.
77+ // We'll just log the error.
7478 }
7579 console . error ( chalk . red ( '\nExtraction failed:' ) ) ;
7680 console . error ( ( error as Error ) . message ) ;
@@ -95,7 +99,7 @@ program
9599 } ) ;
96100
97101program
98- . command ( 'mcp' )
102+ . command ( 'mcp' )
99103 . description ( 'Start MCP server' )
100104 . action ( async ( ) => {
101105 const { startMCPServer } = await import ( './mcp/server.js' ) ;
0 commit comments