@dcyfr/ai-rag 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +124 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/ingestion/index.d.ts +8 -0
- package/dist/ingestion/index.d.ts.map +1 -0
- package/dist/ingestion/index.js +7 -0
- package/dist/ingestion/index.js.map +1 -0
- package/dist/ingestion/markitdown-bridge.d.ts +37 -0
- package/dist/ingestion/markitdown-bridge.d.ts.map +1 -0
- package/dist/ingestion/markitdown-bridge.js +325 -0
- package/dist/ingestion/markitdown-bridge.js.map +1 -0
- package/dist/ingestion/types.d.ts +158 -0
- package/dist/ingestion/types.d.ts.map +1 -0
- package/dist/ingestion/types.js +42 -0
- package/dist/ingestion/types.js.map +1 -0
- package/dist/pipeline/ingestion/pipeline.d.ts +17 -5
- package/dist/pipeline/ingestion/pipeline.d.ts.map +1 -1
- package/dist/pipeline/ingestion/pipeline.js +176 -33
- package/dist/pipeline/ingestion/pipeline.js.map +1 -1
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -1
- package/docs/API.md +1267 -0
- package/package.json +6 -7
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,135 @@
|
|
|
1
1
|
# @dcyfr/ai-rag
|
|
2
2
|
|
|
3
|
+
[](https://deepwiki.com/dcyfr/dcyfr-ai-rag)
|
|
4
|
+
|
|
3
5
|
> **RAG (Retrieval-Augmented Generation) framework for Node.js and TypeScript**
|
|
4
6
|
|
|
5
7
|
Build production-ready RAG systems with document loading, embedding, vector stores, and semantic search.
|
|
6
8
|
|
|
7
9
|
[](https://www.npmjs.com/package/@dcyfr/ai-rag)
|
|
8
|
-
[](https://www.typescriptlang.org/)
|
|
9
11
|
[](https://opensource.org/licenses/MIT)
|
|
10
12
|
|
|
13
|
+
---
|
|
14
|
+
- [Document Conversion](#-document-conversion-markitdown)
|
|
15
|
+
- **Document Conversion** - Convert 15+ file formats (PDF, DOCX, PPTX, XLSX, images, etc.) to Markdown via MarkItDown Python library
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📄 Document Conversion (MarkItDown)
|
|
19
|
+
|
|
20
|
+
Convert diverse document formats to LLM-optimized Markdown:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { convertToMarkdown, convertBatch } from '@dcyfr/ai-rag/ingestion';
|
|
24
|
+
|
|
25
|
+
// Single document conversion
|
|
26
|
+
const result = await convertToMarkdown('/path/to/document.pdf', {
|
|
27
|
+
timeout: 45000, // 45 seconds
|
|
28
|
+
maxFileSize: 50 * 1024 * 1024, // 50 MB
|
|
29
|
+
enableLLMDescriptions: true, // Use GPT-4 Vision for image descriptions
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(result.markdown); // Converted markdown content
|
|
33
|
+
console.log(result.metadata); // File size, duration, page count, etc.
|
|
34
|
+
|
|
35
|
+
// Batch conversion (parallel, concurrency-controlled)
|
|
36
|
+
const files = ['/docs/report.pdf', '/slides/deck.pptx', '/data/sheet.xlsx'];
|
|
37
|
+
const results = await convertBatch(files, { timeout: 60000 });
|
|
38
|
+
|
|
39
|
+
results.forEach((r, i) => {
|
|
40
|
+
if (r.success) {
|
|
41
|
+
console.log(`✅ ${files[i]}: ${r.markdown.length} chars`);
|
|
42
|
+
} else {
|
|
43
|
+
console.error(`❌ ${files[i]}: ${r.error}`);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Supported Formats:**
|
|
49
|
+
- **Documents:** PDF, DOCX, PPTX, XLSX, CSV, TXT, Markdown
|
|
50
|
+
- **Web:** HTML, XML, JSON
|
|
51
|
+
- **Images:** PNG, JPG, JPEG, GIF, WEBP (with optional LLM-powered OCR)
|
|
52
|
+
- **Audio:** MP3, WAV, M4A (transcription)
|
|
53
|
+
- **Archives:** EPUB, ZIP
|
|
54
|
+
|
|
55
|
+
**Installation:**
|
|
56
|
+
```bash
|
|
57
|
+
# Python environment required (workspace already configured)
|
|
58
|
+
pip install markitdown>=0.1.5
|
|
59
|
+
|
|
60
|
+
# Or use workspace .venv (pre-configured)
|
|
61
|
+
source /path/to/workspace/.venv/bin/activate
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Performance:**
|
|
65
|
+
- **Latency:** 200-500ms per document (PDF/Office), <100ms (text/HTML)
|
|
66
|
+
- **Concurrency:** Max 3 parallel conversions (configurable)
|
|
67
|
+
- **Memory:** ~50-200 MB per conversion (temp files auto-cleaned)
|
|
68
|
+
|
|
69
|
+
**Error Handling:**
|
|
70
|
+
```typescript
|
|
71
|
+
import { ConversionError, ConversionErrorType } from '@dcyfr/ai-rag/ingestion';
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const result = await convertToMarkdown('/path/to/file.pdf');
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof ConversionError) {
|
|
77
|
+
switch (error.type) {
|
|
78
|
+
case ConversionErrorType.TIMEOUT:
|
|
79
|
+
console.error('Conversion timed out - file too large?');
|
|
80
|
+
break;
|
|
81
|
+
case ConversionErrorType.FILE_TOO_LARGE:
|
|
82
|
+
console.error(`File exceeds ${error.details?.maxFileSize} bytes`);
|
|
83
|
+
break;
|
|
84
|
+
case ConversionErrorType.UNSUPPORTED_FORMAT:
|
|
85
|
+
console.error('File format not supported by MarkItDown');
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
console.error(`Conversion failed: ${error.message}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**LLM Integration (Optional):**
|
|
95
|
+
```typescript
|
|
96
|
+
// Enable GPT-4 Vision or Claude for image descriptions
|
|
97
|
+
const result = await convertToMarkdown('/path/to/presentation.pptx', {
|
|
98
|
+
enableLLMDescriptions: true,
|
|
99
|
+
llmModel: 'gpt-4-vision-preview', // or 'claude-3-opus-20240229'
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Requires environment variables:
|
|
103
|
+
// OPENAI_API_KEY=sk-...
|
|
104
|
+
// ANTHROPIC_API_KEY=sk-ant-...
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## ⚡ 30-Second Quick Start
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Install package
|
|
112
|
+
npm install @dcyfr/ai-rag
|
|
113
|
+
|
|
114
|
+
# Basic usage
|
|
115
|
+
import { TextLoader, InMemoryVectorStore } from '@dcyfr/ai-rag';
|
|
116
|
+
|
|
117
|
+
const loader = new TextLoader();
|
|
118
|
+
const store = new InMemoryVectorStore();
|
|
119
|
+
# ✅ RAG system ready for document ingestion
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🧭 Related Packages
|
|
125
|
+
|
|
126
|
+
| Package | Purpose | Type |
|
|
127
|
+
|---------|---------|------|
|
|
128
|
+
| [@dcyfr/ai](../dcyfr-ai) | Core AI harness | npm package |
|
|
129
|
+
| [@dcyfr/ai-agents](../dcyfr-ai-agents) | Autonomous agents | Template |
|
|
130
|
+
| [@dcyfr/ai-chatbot](../dcyfr-ai-chatbot) | Chatbot template | Template |
|
|
131
|
+
| [dcyfr-labs](../dcyfr-labs) | Production Next.js app | Application |
|
|
132
|
+
|
|
11
133
|
---
|
|
12
134
|
|
|
13
135
|
## ✨ Features
|
|
@@ -57,7 +179,7 @@ import {
|
|
|
57
179
|
// 1. Setup components
|
|
58
180
|
const loader = new TextLoader();
|
|
59
181
|
const embedder = new SimpleEmbeddingGenerator({ dimensions: 384 });
|
|
60
|
-
const store = new
|
|
182
|
+
const store = new InMemoryVectorStore({
|
|
61
183
|
collectionName: 'my-docs',
|
|
62
184
|
embeddingDimensions: 384,
|
|
63
185
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,mBAAmB,kBAAkB,CAAC;AAGtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,mBAAmB,kBAAkB,CAAC;AAGtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,UAAU;AACV,cAAc,oBAAoB,CAAC;AAEnC,SAAS;AACT,cAAc,mBAAmB,CAAC;AAElC,YAAY;AACZ,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,UAAU;AACV,cAAc,oBAAoB,CAAC;AAEnC,SAAS;AACT,cAAc,mBAAmB,CAAC;AAElC,YAAY;AACZ,cAAc,qBAAqB,CAAC;AAEpC,kCAAkC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document ingestion module for MarkItDown integration
|
|
3
|
+
* @module @dcyfr/ai-rag/ingestion
|
|
4
|
+
*/
|
|
5
|
+
export { convertToMarkdown, convertBatch, checkMarkItDownInstalled } from './markitdown-bridge.js';
|
|
6
|
+
export type { ConversionOptions, ConversionResult, SupportedFormat, SubprocessMessage, } from './types.js';
|
|
7
|
+
export { ConversionError, ConversionErrorType } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ingestion/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACnG,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document ingestion module for MarkItDown integration
|
|
3
|
+
* @module @dcyfr/ai-rag/ingestion
|
|
4
|
+
*/
|
|
5
|
+
export { convertToMarkdown, convertBatch, checkMarkItDownInstalled } from './markitdown-bridge.js';
|
|
6
|
+
export { ConversionError, ConversionErrorType } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ingestion/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAOnG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript bridge to Python MarkItDown document converter
|
|
3
|
+
* @module @dcyfr/ai-rag/ingestion/markitdown-bridge
|
|
4
|
+
*/
|
|
5
|
+
import type { ConversionOptions, ConversionResult } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Convert document to Markdown using Python MarkItDown subprocess
|
|
8
|
+
*
|
|
9
|
+
* @param filePath - Absolute path to file to convert
|
|
10
|
+
* @param options - Conversion options
|
|
11
|
+
* @returns Conversion result with markdown and metadata
|
|
12
|
+
*
|
|
13
|
+
* @throws {ConversionError} If conversion fails
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const result = await convertToMarkdown('/path/to/document.pdf', {
|
|
18
|
+
* timeout: 45000,
|
|
19
|
+
* enableLLMDescriptions: true
|
|
20
|
+
* });
|
|
21
|
+
* console.log(result.markdown);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function convertToMarkdown(filePath: string, options?: ConversionOptions): Promise<ConversionResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Batch convert multiple documents
|
|
27
|
+
*
|
|
28
|
+
* @param filePaths - Array of file paths to convert
|
|
29
|
+
* @param options - Shared conversion options
|
|
30
|
+
* @returns Array of conversion results (same order as input)
|
|
31
|
+
*/
|
|
32
|
+
export declare function convertBatch(filePaths: string[], options?: ConversionOptions): Promise<ConversionResult[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if Python MarkItDown is installed and accessible
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkMarkItDownInstalled(): Promise<boolean>;
|
|
37
|
+
//# sourceMappingURL=markitdown-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markitdown-bridge.d.ts","sourceRoot":"","sources":["../../src/ingestion/markitdown-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAwRpB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CAoE3B;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAkC7B;AAED;;GAEG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAmBjE"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript bridge to Python MarkItDown document converter
|
|
3
|
+
* @module @dcyfr/ai-rag/ingestion/markitdown-bridge
|
|
4
|
+
*/
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { join, resolve, basename, extname, dirname } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { ConversionError, ConversionErrorType } from './types.js';
|
|
11
|
+
// ES module __dirname equivalent
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
/**
|
|
15
|
+
* Default conversion options
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_OPTIONS = {
|
|
18
|
+
timeout: 30000, // 30 seconds
|
|
19
|
+
maxFileSize: 52428800, // 50MB
|
|
20
|
+
enableLLMDescriptions: false,
|
|
21
|
+
preserveMetadata: true,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Supported file extensions mapping to format types
|
|
25
|
+
*/
|
|
26
|
+
const EXTENSION_MAP = {
|
|
27
|
+
'.pdf': 'pdf',
|
|
28
|
+
'.docx': 'docx',
|
|
29
|
+
'.pptx': 'pptx',
|
|
30
|
+
'.xlsx': 'xlsx',
|
|
31
|
+
'.csv': 'csv',
|
|
32
|
+
'.html': 'html',
|
|
33
|
+
'.htm': 'htm',
|
|
34
|
+
'.xml': 'xml',
|
|
35
|
+
'.json': 'json',
|
|
36
|
+
'.png': 'png',
|
|
37
|
+
'.jpg': 'jpg',
|
|
38
|
+
'.jpeg': 'jpeg',
|
|
39
|
+
'.gif': 'gif',
|
|
40
|
+
'.webp': 'webp',
|
|
41
|
+
'.mp3': 'mp3',
|
|
42
|
+
'.wav': 'wav',
|
|
43
|
+
'.m4a': 'm4a',
|
|
44
|
+
'.epub': 'epub',
|
|
45
|
+
'.zip': 'zip',
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Detect file format from extension
|
|
49
|
+
*/
|
|
50
|
+
function detectFormat(filePath) {
|
|
51
|
+
const ext = extname(filePath).toLowerCase();
|
|
52
|
+
const format = EXTENSION_MAP[ext];
|
|
53
|
+
if (!format) {
|
|
54
|
+
throw new ConversionError(ConversionErrorType.UNSUPPORTED_FORMAT, `Unsupported file format: ${ext}`, { filePath, extension: ext });
|
|
55
|
+
}
|
|
56
|
+
return format;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create temporary directory for conversion workspace
|
|
60
|
+
*/
|
|
61
|
+
async function createTempDir() {
|
|
62
|
+
try {
|
|
63
|
+
const tempDir = join(tmpdir(), `markitdown-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`);
|
|
64
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
65
|
+
return tempDir;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new ConversionError(ConversionErrorType.TEMP_DIR_ERROR, 'Failed to create temporary directory', { error: error instanceof Error ? error.message : String(error) });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clean up temporary directory
|
|
73
|
+
*/
|
|
74
|
+
async function cleanupTempDir(tempDir) {
|
|
75
|
+
try {
|
|
76
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// Log warning but don't throw - cleanup failure shouldn't break the flow
|
|
80
|
+
console.warn(`Failed to cleanup temp directory ${tempDir}:`, error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate file accessibility and size
|
|
85
|
+
*/
|
|
86
|
+
async function validateFile(filePath, maxFileSize) {
|
|
87
|
+
try {
|
|
88
|
+
const stats = await fs.stat(filePath);
|
|
89
|
+
if (!stats.isFile()) {
|
|
90
|
+
throw new ConversionError(ConversionErrorType.FILE_NOT_FOUND, 'Path is not a file', { filePath });
|
|
91
|
+
}
|
|
92
|
+
if (stats.size > maxFileSize) {
|
|
93
|
+
throw new ConversionError(ConversionErrorType.FILE_TOO_LARGE, `File size ${stats.size} bytes exceeds limit ${maxFileSize} bytes`, { filePath, fileSize: stats.size, maxFileSize });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error instanceof ConversionError) {
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
throw new ConversionError(ConversionErrorType.FILE_NOT_FOUND, `File not found or inaccessible: ${filePath}`, { error: error instanceof Error ? error.message : String(error) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Find Python executable with worktree-aware fallback order
|
|
105
|
+
*/
|
|
106
|
+
function getPythonExecutable() {
|
|
107
|
+
const explicitPython = process.env.PYTHON_EXECUTABLE;
|
|
108
|
+
if (explicitPython && existsSync(explicitPython)) {
|
|
109
|
+
return explicitPython;
|
|
110
|
+
}
|
|
111
|
+
const activeVenv = process.env.VIRTUAL_ENV;
|
|
112
|
+
if (activeVenv) {
|
|
113
|
+
const activeVenvPython = join(activeVenv, 'bin', 'python');
|
|
114
|
+
if (existsSync(activeVenvPython)) {
|
|
115
|
+
return activeVenvPython;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const workspaceRoot = resolve(__dirname, '../../../..');
|
|
119
|
+
const candidatePaths = [
|
|
120
|
+
join(workspaceRoot, '.venv', 'bin', 'python'),
|
|
121
|
+
join(workspaceRoot, '..', 'dcyfr-workspace', '.venv', 'bin', 'python'),
|
|
122
|
+
'/usr/bin/python3',
|
|
123
|
+
];
|
|
124
|
+
for (const candidate of candidatePaths) {
|
|
125
|
+
if (existsSync(candidate)) {
|
|
126
|
+
return candidate;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return 'python3';
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Execute Python subprocess with timeout handling
|
|
133
|
+
*/
|
|
134
|
+
async function executeSubprocess(python, args, options) {
|
|
135
|
+
const child = spawn(python, args, {
|
|
136
|
+
cwd: options.cwd,
|
|
137
|
+
timeout: options.timeout,
|
|
138
|
+
env: options.env,
|
|
139
|
+
});
|
|
140
|
+
let stdout = '';
|
|
141
|
+
let stderr = '';
|
|
142
|
+
child.stdout?.on('data', (data) => {
|
|
143
|
+
stdout += data.toString();
|
|
144
|
+
});
|
|
145
|
+
child.stderr?.on('data', (data) => {
|
|
146
|
+
stderr += data.toString();
|
|
147
|
+
});
|
|
148
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
149
|
+
const timeoutId = setTimeout(() => {
|
|
150
|
+
child.kill('SIGTERM');
|
|
151
|
+
setTimeout(() => child.kill('SIGKILL'), 1000);
|
|
152
|
+
reject(new ConversionError(ConversionErrorType.TIMEOUT, `Conversion exceeded timeout of ${options.timeout}ms`, { filePath: options.filePath, timeout: options.timeout }));
|
|
153
|
+
}, options.timeout);
|
|
154
|
+
child.on('exit', (code) => {
|
|
155
|
+
clearTimeout(timeoutId);
|
|
156
|
+
resolve(code);
|
|
157
|
+
});
|
|
158
|
+
child.on('error', (error) => {
|
|
159
|
+
clearTimeout(timeoutId);
|
|
160
|
+
reject(new ConversionError(ConversionErrorType.SUBPROCESS_ERROR, `Python subprocess failed: ${error.message}`, { error: error.message, python }));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return { stdout, stderr, exitCode };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Build conversion result metadata
|
|
167
|
+
*/
|
|
168
|
+
async function buildMetadata(fileName, resolvedPath, format, durationMs, stderr, opts) {
|
|
169
|
+
const stats = await fs.stat(resolvedPath);
|
|
170
|
+
const metadata = {
|
|
171
|
+
fileName,
|
|
172
|
+
fileSize: stats.size,
|
|
173
|
+
format,
|
|
174
|
+
convertedAt: new Date().toISOString(),
|
|
175
|
+
durationMs,
|
|
176
|
+
usedLLMDescriptions: opts.enableLLMDescriptions,
|
|
177
|
+
};
|
|
178
|
+
const pageRegex = /(\p{N}+)\s+pages?/iu;
|
|
179
|
+
const pageMatch = pageRegex.exec(stderr);
|
|
180
|
+
if (pageMatch) {
|
|
181
|
+
metadata.pageCount = Number.parseInt(pageMatch[1], 10);
|
|
182
|
+
}
|
|
183
|
+
return metadata;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Validate subprocess execution result
|
|
187
|
+
*/
|
|
188
|
+
function validateSubprocessResult(output, resolvedPath) {
|
|
189
|
+
if (output.exitCode !== 0) {
|
|
190
|
+
throw new ConversionError(ConversionErrorType.SUBPROCESS_ERROR, `MarkItDown conversion failed with exit code ${output.exitCode}`, { exitCode: output.exitCode, stderr: output.stderr, stdout: output.stdout, filePath: resolvedPath });
|
|
191
|
+
}
|
|
192
|
+
const markdown = output.stdout.trim();
|
|
193
|
+
if (!markdown) {
|
|
194
|
+
throw new ConversionError(ConversionErrorType.SUBPROCESS_ERROR, 'MarkItDown returned empty output', { stderr: output.stderr, filePath: resolvedPath });
|
|
195
|
+
}
|
|
196
|
+
return markdown;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Convert document to Markdown using Python MarkItDown subprocess
|
|
200
|
+
*
|
|
201
|
+
* @param filePath - Absolute path to file to convert
|
|
202
|
+
* @param options - Conversion options
|
|
203
|
+
* @returns Conversion result with markdown and metadata
|
|
204
|
+
*
|
|
205
|
+
* @throws {ConversionError} If conversion fails
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const result = await convertToMarkdown('/path/to/document.pdf', {
|
|
210
|
+
* timeout: 45000,
|
|
211
|
+
* enableLLMDescriptions: true
|
|
212
|
+
* });
|
|
213
|
+
* console.log(result.markdown);
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export async function convertToMarkdown(filePath, options = {}) {
|
|
217
|
+
const resolvedPath = resolve(filePath);
|
|
218
|
+
const opts = {
|
|
219
|
+
...DEFAULT_OPTIONS,
|
|
220
|
+
...options,
|
|
221
|
+
};
|
|
222
|
+
await validateFile(resolvedPath, opts.maxFileSize);
|
|
223
|
+
const format = detectFormat(resolvedPath);
|
|
224
|
+
const fileName = basename(resolvedPath);
|
|
225
|
+
let tempDir = null;
|
|
226
|
+
try {
|
|
227
|
+
tempDir = await createTempDir();
|
|
228
|
+
const python = getPythonExecutable();
|
|
229
|
+
const startMs = Date.now();
|
|
230
|
+
const output = await executeSubprocess(python, ['-m', 'markitdown', resolvedPath], {
|
|
231
|
+
cwd: tempDir,
|
|
232
|
+
timeout: opts.timeout,
|
|
233
|
+
env: {
|
|
234
|
+
...process.env,
|
|
235
|
+
...(opts.enableLLMDescriptions && {
|
|
236
|
+
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
|
|
237
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
238
|
+
LLM_MODEL: opts.llmModel || 'gpt-4-vision-preview',
|
|
239
|
+
}),
|
|
240
|
+
},
|
|
241
|
+
filePath: resolvedPath,
|
|
242
|
+
});
|
|
243
|
+
const markdown = validateSubprocessResult(output, resolvedPath);
|
|
244
|
+
const durationMs = Date.now() - startMs;
|
|
245
|
+
const metadata = await buildMetadata(fileName, resolvedPath, format, durationMs, output.stderr, opts);
|
|
246
|
+
return {
|
|
247
|
+
markdown,
|
|
248
|
+
metadata,
|
|
249
|
+
success: true,
|
|
250
|
+
warnings: output.stderr ? [output.stderr] : undefined,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
if (error instanceof ConversionError) {
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
throw new ConversionError(ConversionErrorType.SUBPROCESS_ERROR, `Unexpected error during conversion: ${error instanceof Error ? error.message : String(error)}`, { error: error instanceof Error ? error.message : String(error), filePath: resolvedPath });
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
if (tempDir) {
|
|
261
|
+
await cleanupTempDir(tempDir);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Batch convert multiple documents
|
|
267
|
+
*
|
|
268
|
+
* @param filePaths - Array of file paths to convert
|
|
269
|
+
* @param options - Shared conversion options
|
|
270
|
+
* @returns Array of conversion results (same order as input)
|
|
271
|
+
*/
|
|
272
|
+
export async function convertBatch(filePaths, options = {}) {
|
|
273
|
+
// Process conversions in parallel with concurrency limit
|
|
274
|
+
const MAX_CONCURRENT = 3;
|
|
275
|
+
const results = [];
|
|
276
|
+
for (let i = 0; i < filePaths.length; i += MAX_CONCURRENT) {
|
|
277
|
+
const batch = filePaths.slice(i, i + MAX_CONCURRENT);
|
|
278
|
+
const batchResults = await Promise.allSettled(batch.map((path) => convertToMarkdown(path, options)));
|
|
279
|
+
for (const result of batchResults) {
|
|
280
|
+
if (result.status === 'fulfilled') {
|
|
281
|
+
results.push(result.value);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// Convert rejected promise to failed ConversionResult
|
|
285
|
+
const error = result.reason;
|
|
286
|
+
results.push({
|
|
287
|
+
markdown: '',
|
|
288
|
+
metadata: {
|
|
289
|
+
fileName: '',
|
|
290
|
+
fileSize: 0,
|
|
291
|
+
format: 'pdf',
|
|
292
|
+
convertedAt: new Date().toISOString(),
|
|
293
|
+
durationMs: 0,
|
|
294
|
+
},
|
|
295
|
+
success: false,
|
|
296
|
+
error: error instanceof Error ? error.message : String(error),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return results;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Check if Python MarkItDown is installed and accessible
|
|
305
|
+
*/
|
|
306
|
+
export async function checkMarkItDownInstalled() {
|
|
307
|
+
try {
|
|
308
|
+
const python = getPythonExecutable();
|
|
309
|
+
const child = spawn(python, ['-c', 'import markitdown; print("ok")'], {
|
|
310
|
+
timeout: 5000,
|
|
311
|
+
});
|
|
312
|
+
return new Promise((resolve) => {
|
|
313
|
+
child.on('exit', (code) => {
|
|
314
|
+
resolve(code === 0);
|
|
315
|
+
});
|
|
316
|
+
child.on('error', () => {
|
|
317
|
+
resolve(false);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=markitdown-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markitdown-bridge.js","sourceRoot":"","sources":["../../src/ingestion/markitdown-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAOzC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAElE,iCAAiC;AACjC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,eAAe,GAA+G;IAClI,OAAO,EAAE,KAAK,EAAE,aAAa;IAC7B,WA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