@ferchy/n8n-nodes-aimc-toolkit 0.1.6 → 0.1.8
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/README.md
CHANGED
|
@@ -5,7 +5,6 @@ AIMC Toolkit is a community node package for n8n with focused nodes:
|
|
|
5
5
|
- **AIMC Code**: run JavaScript with a practical toolbox of libraries.
|
|
6
6
|
- **AIMC Media**: FFmpeg-powered media operations without extra glue nodes.
|
|
7
7
|
- **AIMC TTS**: CPU-friendly text-to-speech using Piper.
|
|
8
|
-
- **AIMC Docling**: OCR/document extraction using Docling.
|
|
9
8
|
|
|
10
9
|
## Why I Built This
|
|
11
10
|
|
|
@@ -24,7 +23,6 @@ n8n is powerful, but real workflows often need basic utilities (validation, pars
|
|
|
24
23
|
- **Media ready**: convert, compress, merge, and inspect media in one place.
|
|
25
24
|
- **Practical libraries**: parsing, validation, dates, and web utilities built in.
|
|
26
25
|
- **Local voice**: generate speech on a CPU server without paid APIs.
|
|
27
|
-
- **Document extraction**: pull clean text/markdown from PDFs and scans.
|
|
28
26
|
|
|
29
27
|
## Installation
|
|
30
28
|
|
|
@@ -175,30 +173,6 @@ Output Mode: Binary
|
|
|
175
173
|
- Use **Output Mode = File Path** for large audio.
|
|
176
174
|
- For custom voice storage, set **Data Dir**.
|
|
177
175
|
|
|
178
|
-
### AIMC Docling (OCR + Document Parsing)
|
|
179
|
-
|
|
180
|
-
**What it does**
|
|
181
|
-
Extracts clean text/markdown from PDFs, images, and common document formats using Docling.
|
|
182
|
-
|
|
183
|
-
**Requirements**
|
|
184
|
-
- Python 3 installed
|
|
185
|
-
- Docling installed: `pip install docling`
|
|
186
|
-
|
|
187
|
-
**Input modes**
|
|
188
|
-
- Binary (from n8n)
|
|
189
|
-
- File Path (local file)
|
|
190
|
-
- URL (public file URL)
|
|
191
|
-
|
|
192
|
-
**Output formats**
|
|
193
|
-
- Markdown (default)
|
|
194
|
-
- JSON (structured output when available)
|
|
195
|
-
- Plain Text (markdown stripped)
|
|
196
|
-
|
|
197
|
-
**Example**
|
|
198
|
-
```
|
|
199
|
-
Input Mode: Binary
|
|
200
|
-
Output Format: Markdown
|
|
201
|
-
```
|
|
202
176
|
|
|
203
177
|
## Library Reference (AIMC Code)
|
|
204
178
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ferchy/n8n-nodes-aimc-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "AIMC Toolkit nodes for n8n: code execution and media operations.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ferchy",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"nodes": [
|
|
30
30
|
"dist/nodes/AimcCode/AimcCode.node.js",
|
|
31
31
|
"dist/nodes/AimcMedia/AimcMedia.node.js",
|
|
32
|
-
"dist/nodes/AimcTts/AimcTts.node.js"
|
|
33
|
-
"dist/nodes/AimcDocling/AimcDocling.node.js"
|
|
32
|
+
"dist/nodes/AimcTts/AimcTts.node.js"
|
|
34
33
|
]
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AimcDocling = void 0;
|
|
37
|
-
const n8n_workflow_1 = require("n8n-workflow");
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const os = __importStar(require("os"));
|
|
41
|
-
const child_process_1 = require("child_process");
|
|
42
|
-
const util_1 = require("util");
|
|
43
|
-
const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
|
|
44
|
-
let doclingChecked = null;
|
|
45
|
-
async function ensureDoclingAvailable(pythonPath) {
|
|
46
|
-
if (doclingChecked) {
|
|
47
|
-
if (!doclingChecked.ok) {
|
|
48
|
-
throw new Error(doclingChecked.message || 'Docling not available');
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
await execFileAsync(pythonPath, ['-c', 'import docling'], {
|
|
54
|
-
timeout: 10000,
|
|
55
|
-
maxBuffer: 1024 * 1024,
|
|
56
|
-
});
|
|
57
|
-
doclingChecked = { ok: true };
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
const message = error instanceof Error && error.message
|
|
61
|
-
? error.message
|
|
62
|
-
: 'Docling not available';
|
|
63
|
-
doclingChecked = { ok: false, message };
|
|
64
|
-
throw new Error(message);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async function createTempDir() {
|
|
68
|
-
return fs.promises.mkdtemp(path.join(os.tmpdir(), 'aimc-docling-'));
|
|
69
|
-
}
|
|
70
|
-
function safeFileName(name) {
|
|
71
|
-
return name.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
72
|
-
}
|
|
73
|
-
class AimcDocling {
|
|
74
|
-
constructor() {
|
|
75
|
-
this.description = {
|
|
76
|
-
displayName: 'AIMC Docling',
|
|
77
|
-
name: 'aimcDocling',
|
|
78
|
-
icon: 'file:aimc-docling.svg',
|
|
79
|
-
group: ['transform'],
|
|
80
|
-
version: 1,
|
|
81
|
-
description: 'Document extraction using Docling (OCR, PDF, DOCX).',
|
|
82
|
-
defaults: {
|
|
83
|
-
name: 'AIMC Docling',
|
|
84
|
-
},
|
|
85
|
-
inputs: ['main'],
|
|
86
|
-
outputs: ['main'],
|
|
87
|
-
properties: [
|
|
88
|
-
{
|
|
89
|
-
displayName: 'Input Mode',
|
|
90
|
-
name: 'inputMode',
|
|
91
|
-
type: 'options',
|
|
92
|
-
options: [
|
|
93
|
-
{ name: 'Binary', value: 'binary' },
|
|
94
|
-
{ name: 'File Path', value: 'filePath' },
|
|
95
|
-
{ name: 'URL', value: 'url' },
|
|
96
|
-
],
|
|
97
|
-
default: 'binary',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
displayName: 'Binary Property',
|
|
101
|
-
name: 'binaryProperty',
|
|
102
|
-
type: 'string',
|
|
103
|
-
default: 'data',
|
|
104
|
-
displayOptions: {
|
|
105
|
-
show: {
|
|
106
|
-
inputMode: ['binary'],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
displayName: 'File Path',
|
|
112
|
-
name: 'inputFilePath',
|
|
113
|
-
type: 'string',
|
|
114
|
-
default: '',
|
|
115
|
-
placeholder: '/path/to/document.pdf',
|
|
116
|
-
displayOptions: {
|
|
117
|
-
show: {
|
|
118
|
-
inputMode: ['filePath'],
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
displayName: 'URL',
|
|
124
|
-
name: 'inputUrl',
|
|
125
|
-
type: 'string',
|
|
126
|
-
default: '',
|
|
127
|
-
placeholder: 'https://example.com/file.pdf',
|
|
128
|
-
displayOptions: {
|
|
129
|
-
show: {
|
|
130
|
-
inputMode: ['url'],
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
displayName: 'Output Format',
|
|
136
|
-
name: 'outputFormat',
|
|
137
|
-
type: 'options',
|
|
138
|
-
options: [
|
|
139
|
-
{ name: 'Markdown', value: 'markdown' },
|
|
140
|
-
{ name: 'JSON', value: 'json' },
|
|
141
|
-
{ name: 'Plain Text', value: 'text' },
|
|
142
|
-
],
|
|
143
|
-
default: 'markdown',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
displayName: 'Python Path',
|
|
147
|
-
name: 'pythonPath',
|
|
148
|
-
type: 'string',
|
|
149
|
-
default: 'python3',
|
|
150
|
-
description: 'Path to Python binary with docling installed.',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
displayName: 'Timeout (Seconds)',
|
|
154
|
-
name: 'timeoutSeconds',
|
|
155
|
-
type: 'number',
|
|
156
|
-
default: 120,
|
|
157
|
-
typeOptions: {
|
|
158
|
-
minValue: 30,
|
|
159
|
-
maxValue: 1800,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
async execute() {
|
|
166
|
-
const items = this.getInputData();
|
|
167
|
-
const results = [];
|
|
168
|
-
for (let index = 0; index < items.length; index++) {
|
|
169
|
-
const item = items[index];
|
|
170
|
-
const inputMode = this.getNodeParameter('inputMode', index);
|
|
171
|
-
const binaryProperty = this.getNodeParameter('binaryProperty', index, 'data');
|
|
172
|
-
const inputFilePath = this.getNodeParameter('inputFilePath', index, '');
|
|
173
|
-
const inputUrl = this.getNodeParameter('inputUrl', index, '');
|
|
174
|
-
const outputFormat = this.getNodeParameter('outputFormat', index, 'markdown');
|
|
175
|
-
const pythonPath = this.getNodeParameter('pythonPath', index, 'python3');
|
|
176
|
-
const timeoutSeconds = this.getNodeParameter('timeoutSeconds', index, 120);
|
|
177
|
-
let tempDir = null;
|
|
178
|
-
let source = '';
|
|
179
|
-
if (inputMode === 'binary') {
|
|
180
|
-
const binary = this.helpers.assertBinaryData(index, binaryProperty);
|
|
181
|
-
const buffer = await this.helpers.getBinaryDataBuffer(index, binaryProperty);
|
|
182
|
-
tempDir = await createTempDir();
|
|
183
|
-
const name = safeFileName(binary.fileName || `document.${binary.fileExtension || 'bin'}`);
|
|
184
|
-
const filePath = path.join(tempDir, name);
|
|
185
|
-
await fs.promises.writeFile(filePath, buffer);
|
|
186
|
-
source = filePath;
|
|
187
|
-
}
|
|
188
|
-
else if (inputMode === 'filePath') {
|
|
189
|
-
if (!inputFilePath) {
|
|
190
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'File Path is required.');
|
|
191
|
-
}
|
|
192
|
-
source = inputFilePath;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
if (!inputUrl) {
|
|
196
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'URL is required.');
|
|
197
|
-
}
|
|
198
|
-
source = inputUrl;
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
await ensureDoclingAvailable(pythonPath);
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
const message = error instanceof Error ? error.message : 'Docling not available';
|
|
205
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Docling not found. Install with: pip install docling. ${message}`);
|
|
206
|
-
}
|
|
207
|
-
const script = `
|
|
208
|
-
+import json
|
|
209
|
-
+import sys
|
|
210
|
-
+from docling.document_converter import DocumentConverter
|
|
211
|
-
+
|
|
212
|
-
+source = ${JSON.stringify(source)}
|
|
213
|
-
+fmt = ${JSON.stringify(outputFormat)}
|
|
214
|
-
+
|
|
215
|
-
+converter = DocumentConverter()
|
|
216
|
-
+result = converter.convert(source)
|
|
217
|
-
+doc = result.document
|
|
218
|
-
+
|
|
219
|
-
+if fmt == 'markdown':
|
|
220
|
-
+ content = doc.export_to_markdown()
|
|
221
|
-
+elif fmt == 'text':
|
|
222
|
-
+ content = doc.export_to_markdown()
|
|
223
|
-
+ # naive text conversion
|
|
224
|
-
+ content = content.replace('#', '').replace('*', '')
|
|
225
|
-
+else:
|
|
226
|
-
+ try:
|
|
227
|
-
+ content = doc.model_dump()
|
|
228
|
-
+ except Exception:
|
|
229
|
-
+ content = {'text': doc.export_to_markdown()}
|
|
230
|
-
+
|
|
231
|
-
+payload = {"format": fmt, "content": content}
|
|
232
|
-
+print("__AIMC_RESULT__" + json.dumps(payload, default=str))
|
|
233
|
-
+`;
|
|
234
|
-
try {
|
|
235
|
-
const { stdout, stderr } = await execFileAsync(pythonPath, ['-c', script], {
|
|
236
|
-
timeout: Math.max(30, timeoutSeconds) * 1000,
|
|
237
|
-
maxBuffer: 20 * 1024 * 1024,
|
|
238
|
-
});
|
|
239
|
-
const combined = `${stdout}\n${stderr}`.trim();
|
|
240
|
-
const marker = '__AIMC_RESULT__';
|
|
241
|
-
const markerIndex = combined.lastIndexOf(marker);
|
|
242
|
-
if (markerIndex === -1) {
|
|
243
|
-
throw new Error('Docling did not return a result.');
|
|
244
|
-
}
|
|
245
|
-
const jsonPayload = combined.slice(markerIndex + marker.length).trim();
|
|
246
|
-
const payload = JSON.parse(jsonPayload);
|
|
247
|
-
results.push({
|
|
248
|
-
json: {
|
|
249
|
-
...item.json,
|
|
250
|
-
docling: {
|
|
251
|
-
format: payload.format,
|
|
252
|
-
content: payload.content,
|
|
253
|
-
},
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
259
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Docling failed: ${message}`);
|
|
260
|
-
}
|
|
261
|
-
finally {
|
|
262
|
-
if (tempDir) {
|
|
263
|
-
await fs.promises.rm(tempDir, { recursive: true, force: true });
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return [results];
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
exports.AimcDocling = AimcDocling;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
|
|
2
|
-
<defs>
|
|
3
|
-
<linearGradient id="aimc-docling-bg" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
-
<stop offset="0%" stop-color="#0A1021"/>
|
|
5
|
-
<stop offset="100%" stop-color="#0B1B3A"/>
|
|
6
|
-
</linearGradient>
|
|
7
|
-
<linearGradient id="aimc-docling-glow" x1="0" y1="0" x2="1" y2="1">
|
|
8
|
-
<stop offset="0%" stop-color="#7DD3FC"/>
|
|
9
|
-
<stop offset="100%" stop-color="#0EA5E9"/>
|
|
10
|
-
</linearGradient>
|
|
11
|
-
</defs>
|
|
12
|
-
<rect x="6" y="6" width="52" height="52" rx="10" fill="url(#aimc-docling-bg)"/>
|
|
13
|
-
<path d="M22 16H38L44 22V48H22Z" fill="#0F172A" stroke="#1E3A8A" stroke-width="2"/>
|
|
14
|
-
<path d="M38 16V22H44" stroke="#1E3A8A" stroke-width="2" fill="none"/>
|
|
15
|
-
<rect x="24" y="26" width="16" height="3" rx="1.5" fill="url(#aimc-docling-glow)"/>
|
|
16
|
-
<rect x="24" y="32" width="12" height="3" rx="1.5" fill="url(#aimc-docling-glow)"/>
|
|
17
|
-
<rect x="24" y="38" width="18" height="3" rx="1.5" fill="url(#aimc-docling-glow)"/>
|
|
18
|
-
<circle cx="46" cy="44" r="6" fill="#0B1223" stroke="#38BDF8" stroke-width="2"/>
|
|
19
|
-
<path d="M46 40V44L49 46" stroke="#38BDF8" stroke-width="2" stroke-linecap="round"/>
|
|
20
|
-
</svg>
|