@fractal-solutions/qflow 1.0.29 → 1.0.31
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 +504 -0
- package/README.md +182 -52
- package/dist/agent/tools.d.ts +3114 -181
- package/dist/agent/tools.js +492 -0
- package/dist/nodes/browser_control.d.ts +4 -0
- package/dist/nodes/browser_control.js +73 -0
- package/dist/nodes/data_validation.d.ts +9 -0
- package/dist/nodes/data_validation.js +48 -0
- package/dist/nodes/display_image.d.ts +4 -0
- package/dist/nodes/display_image.js +46 -0
- package/dist/nodes/gis.d.ts +37 -0
- package/dist/nodes/gis.js +106 -0
- package/dist/nodes/git.d.ts +4 -0
- package/dist/nodes/git.js +55 -0
- package/dist/nodes/hardware_interaction.d.ts +8 -0
- package/dist/nodes/hardware_interaction.js +97 -0
- package/dist/nodes/image_gallery.d.ts +8 -0
- package/dist/nodes/image_gallery.js +99 -0
- package/dist/nodes/index.d.ts +12 -0
- package/dist/nodes/index.js +12 -0
- package/dist/nodes/multimedia_processing.d.ts +10 -0
- package/dist/nodes/multimedia_processing.js +79 -0
- package/dist/nodes/pdf_processor.d.ts +4 -0
- package/dist/nodes/pdf_processor.js +75 -0
- package/dist/nodes/remote_execution.d.ts +4 -0
- package/dist/nodes/remote_execution.js +82 -0
- package/dist/nodes/scheduler.d.ts +20 -0
- package/dist/nodes/scheduler.js +97 -0
- package/dist/nodes/speech_synthesis.d.ts +45 -0
- package/dist/nodes/speech_synthesis.js +142 -0
- package/dist/nodes/spreadsheet.d.ts +10 -0
- package/dist/nodes/spreadsheet.js +241 -0
- package/dist/nodes/webhook.d.ts +15 -0
- package/dist/nodes/webhook.js +110 -0
- package/dist/nodes/websockets.d.ts +4 -0
- package/dist/nodes/websockets.js +73 -0
- package/package.json +11 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
export class DisplayImageNode extends AsyncNode {
|
|
5
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
6
|
+
super(maxRetries, wait);
|
|
7
|
+
}
|
|
8
|
+
async execAsync() {
|
|
9
|
+
const { imagePath } = this.params;
|
|
10
|
+
if (!imagePath) {
|
|
11
|
+
throw new Error('DisplayImageNode requires an `imagePath` parameter.');
|
|
12
|
+
}
|
|
13
|
+
let command = '';
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'linux':
|
|
17
|
+
// 'xdg-open' is a standard way to open files with default application on Linux desktops
|
|
18
|
+
command = `xdg-open "${imagePath}"`;
|
|
19
|
+
break;
|
|
20
|
+
case 'darwin': // macOS
|
|
21
|
+
// 'open' command opens files with their default application
|
|
22
|
+
command = `open "${imagePath}"`;
|
|
23
|
+
break;
|
|
24
|
+
case 'win32': // Windows
|
|
25
|
+
// 'start' command opens files with their default application
|
|
26
|
+
command = `start "" "${imagePath}"`; // The first "" is for the title, which is optional but good practice
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unsupported platform for DisplayImageNode: ${platform}`);
|
|
30
|
+
}
|
|
31
|
+
console.log(`[DisplayImageNode] Executing: ${command}`);
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
exec(command, (error, stdout, stderr) => {
|
|
34
|
+
if (error) {
|
|
35
|
+
console.error(`DisplayImageNode error: ${error.message}`);
|
|
36
|
+
return reject(error);
|
|
37
|
+
}
|
|
38
|
+
if (stderr) {
|
|
39
|
+
console.warn(`DisplayImageNode stderr: ${stderr}`);
|
|
40
|
+
}
|
|
41
|
+
console.log(`Image opened: ${imagePath}`);
|
|
42
|
+
resolve({ imagePath, stdout, stderr });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class GISNode extends AsyncNode {
|
|
2
|
+
providers: {
|
|
3
|
+
google: GoogleMapsProvider;
|
|
4
|
+
openstreetmap: OpenStreetMapProvider;
|
|
5
|
+
};
|
|
6
|
+
execAsync(): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
import { AsyncNode } from '../qflow.js';
|
|
9
|
+
declare class GoogleMapsProvider {
|
|
10
|
+
constructor(apiKey: any);
|
|
11
|
+
apiKey: any;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
geocode(address: any): Promise<{
|
|
14
|
+
lat: any;
|
|
15
|
+
lng: any;
|
|
16
|
+
formattedAddress: any;
|
|
17
|
+
}>;
|
|
18
|
+
reverseGeocode(lat: any, lng: any): Promise<{
|
|
19
|
+
lat: number;
|
|
20
|
+
lng: number;
|
|
21
|
+
formattedAddress: any;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
declare class OpenStreetMapProvider {
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
geocode(address: any): Promise<{
|
|
27
|
+
lat: number;
|
|
28
|
+
lng: number;
|
|
29
|
+
formattedAddress: any;
|
|
30
|
+
}>;
|
|
31
|
+
reverseGeocode(lat: any, lng: any): Promise<{
|
|
32
|
+
lat: number;
|
|
33
|
+
lng: number;
|
|
34
|
+
formattedAddress: any;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
+
import { HttpRequestNode } from './index.js'; // For making HTTP requests to APIs
|
|
3
|
+
// Internal helper for Google Maps API calls
|
|
4
|
+
class GoogleMapsProvider {
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
this.baseUrl = "https://maps.googleapis.com/maps/api";
|
|
8
|
+
}
|
|
9
|
+
async geocode(address) {
|
|
10
|
+
if (!this.apiKey) {
|
|
11
|
+
throw new Error("Google Maps API Key is not configured for GoogleMapsProvider.");
|
|
12
|
+
}
|
|
13
|
+
const url = `${this.baseUrl}/geocode/json?address=${encodeURIComponent(address)}&key=${this.apiKey}`;
|
|
14
|
+
const httpRequest = new HttpRequestNode();
|
|
15
|
+
httpRequest.setParams({ url, method: 'GET' });
|
|
16
|
+
const response = await new AsyncFlow(httpRequest).runAsync({});
|
|
17
|
+
const data = response.body;
|
|
18
|
+
if (data.status === 'OK' && data.results.length > 0) {
|
|
19
|
+
const location = data.results[0].geometry.location;
|
|
20
|
+
return { lat: location.lat, lng: location.lng, formattedAddress: data.results[0].formatted_address };
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Google Geocoding failed: ${data.status || JSON.stringify(data)}`);
|
|
23
|
+
}
|
|
24
|
+
async reverseGeocode(lat, lng) {
|
|
25
|
+
if (!this.apiKey) {
|
|
26
|
+
throw new Error("Google Maps API Key is not configured for GoogleMapsProvider.");
|
|
27
|
+
}
|
|
28
|
+
const url = `${this.baseUrl}/geocode/json?latlng=${lat},${lng}&key=${this.apiKey}`;
|
|
29
|
+
const httpRequest = new HttpRequestNode();
|
|
30
|
+
httpRequest.setParams({ url, method: 'GET' });
|
|
31
|
+
const response = await new AsyncFlow(httpRequest).runAsync({});
|
|
32
|
+
const data = response.body;
|
|
33
|
+
if (data.status === 'OK' && data.results.length > 0) {
|
|
34
|
+
const result = data.results[0];
|
|
35
|
+
return { lat: parseFloat(result.geometry.location.lat), lng: parseFloat(result.geometry.location.lng), formattedAddress: result.formatted_address };
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Google Reverse Geocoding failed: ${data.status || JSON.stringify(data)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Internal helper for OpenStreetMap (Nominatim for geocoding)
|
|
41
|
+
class OpenStreetMapProvider {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.baseUrl = "https://nominatim.openstreetmap.org";
|
|
44
|
+
}
|
|
45
|
+
async geocode(address) {
|
|
46
|
+
const url = `${this.baseUrl}/search?q=${encodeURIComponent(address)}&format=json&limit=1`;
|
|
47
|
+
const httpRequest = new HttpRequestNode();
|
|
48
|
+
httpRequest.setParams({ url, method: 'GET', headers: { 'User-Agent': 'QFlowGISNode/1.0 (https://github.com/fractal-solutions/qflow)' } }); // Nominatim requires User-Agent
|
|
49
|
+
const response = await new AsyncFlow(httpRequest).runAsync({});
|
|
50
|
+
const data = response.body;
|
|
51
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
52
|
+
const result = data[0];
|
|
53
|
+
return { lat: parseFloat(result.lat), lng: parseFloat(result.lon), formattedAddress: result.display_name };
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`OpenStreetMap Geocoding failed: No results for ${address}`);
|
|
56
|
+
}
|
|
57
|
+
async reverseGeocode(lat, lng) {
|
|
58
|
+
const url = `${this.baseUrl}/reverse?lat=${lat}&lon=${lng}&format=json`;
|
|
59
|
+
const httpRequest = new HttpRequestNode();
|
|
60
|
+
httpRequest.setParams({ url, method: 'GET', headers: { 'User-Agent': 'QFlowGISNode/1.0 (https://github.com/fractal-solutions/qflow)' } }); // Nominatim requires User-Agent
|
|
61
|
+
const response = await new AsyncFlow(httpRequest).runAsync({});
|
|
62
|
+
const data = response.body;
|
|
63
|
+
if (data && data.display_name) {
|
|
64
|
+
return { lat: parseFloat(data.lat), lng: parseFloat(data.lon), formattedAddress: data.display_name };
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`OpenStreetMap Reverse Geocoding failed: No results for ${lat},${lng}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class GISNode extends AsyncNode {
|
|
70
|
+
constructor(maxRetries = 3, wait = 1) {
|
|
71
|
+
super(maxRetries, wait);
|
|
72
|
+
this.providers = {
|
|
73
|
+
google: new GoogleMapsProvider(process.env.GOOGLE_MAPS_API_KEY), // API key from env var
|
|
74
|
+
openstreetmap: new OpenStreetMapProvider(),
|
|
75
|
+
// Add other providers here (e.g., mapbox: new MapboxProvider(process.env.MAPBOX_API_KEY))
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async execAsync() {
|
|
79
|
+
const { operation, provider = 'openstreetmap', params } = this.params; // Default to openstreetmap
|
|
80
|
+
if (!operation) {
|
|
81
|
+
throw new Error('GISNode requires an `operation` parameter (e.g., "geocode", "reverseGeocode", "route").');
|
|
82
|
+
}
|
|
83
|
+
if (!this.providers[provider]) {
|
|
84
|
+
throw new Error(`GIS provider '${provider}' not supported or configured.`);
|
|
85
|
+
}
|
|
86
|
+
const currentProvider = this.providers[provider];
|
|
87
|
+
// Dispatch to the appropriate provider method based on operation
|
|
88
|
+
switch (operation) {
|
|
89
|
+
case 'geocode':
|
|
90
|
+
if (!params || !params.address) {
|
|
91
|
+
throw new Error('Geocode operation requires `params.address`.');
|
|
92
|
+
}
|
|
93
|
+
return await currentProvider.geocode(params.address);
|
|
94
|
+
case 'reverseGeocode':
|
|
95
|
+
if (!params || typeof params.lat !== 'number' || typeof params.lng !== 'number') {
|
|
96
|
+
throw new Error('Reverse Geocode operation requires `params.lat` and `params.lng` as numbers.');
|
|
97
|
+
}
|
|
98
|
+
return await currentProvider.reverseGeocode(params.lat, params.lng);
|
|
99
|
+
// Add other operations here
|
|
100
|
+
// case 'route':
|
|
101
|
+
// return await currentProvider.route(params.origin, params.destination);
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unsupported GIS operation: ${operation}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import simpleGit from 'simple-git';
|
|
3
|
+
export class GitNode extends AsyncNode {
|
|
4
|
+
async execAsync() {
|
|
5
|
+
const { action, repoPath, remoteUrl, files, message, branch, remote = 'origin', } = this.params;
|
|
6
|
+
if (!repoPath && action !== 'clone') {
|
|
7
|
+
throw new Error('GitNode requires a `repoPath` for all actions except `clone`.');
|
|
8
|
+
}
|
|
9
|
+
const git = simpleGit(repoPath);
|
|
10
|
+
let result = {};
|
|
11
|
+
switch (action) {
|
|
12
|
+
case 'clone':
|
|
13
|
+
if (!remoteUrl || !repoPath)
|
|
14
|
+
throw new Error('`remoteUrl` and `repoPath` are required for `clone`.');
|
|
15
|
+
await git.clone(remoteUrl, repoPath);
|
|
16
|
+
result = { message: `Repository cloned from ${remoteUrl} to ${repoPath}` };
|
|
17
|
+
break;
|
|
18
|
+
case 'init':
|
|
19
|
+
await git.init();
|
|
20
|
+
result = { message: `Initialized empty Git repository in ${repoPath}` };
|
|
21
|
+
break;
|
|
22
|
+
case 'add':
|
|
23
|
+
if (!files)
|
|
24
|
+
throw new Error('`files` parameter is required for `add` action.');
|
|
25
|
+
await git.add(files);
|
|
26
|
+
result = { message: `Files added: ${files.join(', ')}` };
|
|
27
|
+
break;
|
|
28
|
+
case 'commit':
|
|
29
|
+
if (!message)
|
|
30
|
+
throw new Error('`message` parameter is required for `commit` action.');
|
|
31
|
+
const commitResult = await git.commit(message);
|
|
32
|
+
result = { message: 'Commit successful', ...commitResult };
|
|
33
|
+
break;
|
|
34
|
+
case 'push':
|
|
35
|
+
if (!branch)
|
|
36
|
+
throw new Error('`branch` parameter is required for `push` action.');
|
|
37
|
+
await git.push(remote, branch);
|
|
38
|
+
result = { message: `Pushed to ${remote}/${branch}` };
|
|
39
|
+
break;
|
|
40
|
+
case 'pull':
|
|
41
|
+
if (!branch)
|
|
42
|
+
throw new Error('`branch` parameter is required for `pull` action.');
|
|
43
|
+
await git.pull(remote, branch);
|
|
44
|
+
result = { message: `Pulled from ${remote}/${branch}` };
|
|
45
|
+
break;
|
|
46
|
+
case 'status':
|
|
47
|
+
const statusResult = await git.status();
|
|
48
|
+
result = statusResult;
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unsupported Git action: ${action}`);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export class HardwareInteractionNode extends AsyncNode {
|
|
2
|
+
port: SerialPort<any> | null;
|
|
3
|
+
parser: ReadlineParser | null;
|
|
4
|
+
execAsync(): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
import { AsyncNode } from '../qflow.js';
|
|
7
|
+
import { SerialPort } from 'serialport';
|
|
8
|
+
import { ReadlineParser } from '@serialport/parser-readline';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
// You would need to install the 'serialport' library: npm install serialport
|
|
3
|
+
import { SerialPort } from 'serialport';
|
|
4
|
+
import { ReadlineParser } from '@serialport/parser-readline'; // For reading line-by-line
|
|
5
|
+
export class HardwareInteractionNode extends AsyncNode {
|
|
6
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
7
|
+
super(maxRetries, wait);
|
|
8
|
+
this.port = null;
|
|
9
|
+
this.parser = null;
|
|
10
|
+
}
|
|
11
|
+
async execAsync() {
|
|
12
|
+
const { portPath, // e.g., '/dev/ttyUSB0' on Linux, 'COM1' on Windows
|
|
13
|
+
baudRate = 9600, action, // 'write', 'read_line', 'list_ports'
|
|
14
|
+
dataToWrite, // For 'write' action
|
|
15
|
+
timeout = 5000 // For 'read_line' action
|
|
16
|
+
} = this.params;
|
|
17
|
+
if (!action || !['write', 'read_line', 'list_ports'].includes(action)) {
|
|
18
|
+
throw new Error('HardwareInteractionNode requires an `action`: "write", "read_line", or "list_ports".');
|
|
19
|
+
}
|
|
20
|
+
let result;
|
|
21
|
+
switch (action) {
|
|
22
|
+
case 'list_ports':
|
|
23
|
+
// List available serial ports
|
|
24
|
+
try {
|
|
25
|
+
const ports = await SerialPort.list();
|
|
26
|
+
result = ports.map(p => ({
|
|
27
|
+
path: p.path,
|
|
28
|
+
manufacturer: p.manufacturer,
|
|
29
|
+
serialNumber: p.serialNumber,
|
|
30
|
+
pnpId: p.pnpId,
|
|
31
|
+
productId: p.productId,
|
|
32
|
+
vendorId: p.vendorId,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new Error(`Failed to list serial ports: ${e.message}`);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case 'write':
|
|
40
|
+
case 'read_line':
|
|
41
|
+
if (!portPath) {
|
|
42
|
+
throw new Error('For "write" or "read_line" action, `portPath` is required.');
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
this.port = new SerialPort({ path: portPath, baudRate: baudRate });
|
|
46
|
+
await new Promise((resolve, reject) => {
|
|
47
|
+
this.port.on('open', resolve);
|
|
48
|
+
this.port.on('error', reject);
|
|
49
|
+
});
|
|
50
|
+
console.log(`[HardwareInteractionNode] Serial port ${portPath} opened.`);
|
|
51
|
+
if (action === 'write') {
|
|
52
|
+
if (dataToWrite === undefined) {
|
|
53
|
+
throw new Error('Write action requires `dataToWrite`.');
|
|
54
|
+
}
|
|
55
|
+
await new Promise((resolve, reject) => {
|
|
56
|
+
this.port.write(dataToWrite, (err) => {
|
|
57
|
+
if (err)
|
|
58
|
+
reject(err);
|
|
59
|
+
else
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
result = { status: 'data_written', data: dataToWrite };
|
|
64
|
+
}
|
|
65
|
+
else if (action === 'read_line') {
|
|
66
|
+
this.parser = this.port.pipe(new ReadlineParser({ delimiter: '\n' }));
|
|
67
|
+
result = await new Promise((resolve, reject) => {
|
|
68
|
+
const timer = setTimeout(() => {
|
|
69
|
+
reject(new Error(`Timeout waiting for data on ${portPath}`));
|
|
70
|
+
}, timeout);
|
|
71
|
+
this.parser.on('data', (line) => {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
resolve(line.trim());
|
|
74
|
+
});
|
|
75
|
+
this.port.on('error', (err) => {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
reject(err);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
throw new Error(`Serial port operation failed: ${e.message}. Check portPath, baudRate, and permissions.`);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
if (this.port && this.port.isOpen) {
|
|
87
|
+
await new Promise(resolve => this.port.close(resolve));
|
|
88
|
+
console.log(`[HardwareInteractionNode] Serial port ${portPath} closed.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
+
import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is available
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
export class ImageGalleryNode extends AsyncNode {
|
|
7
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
8
|
+
super(maxRetries, wait);
|
|
9
|
+
}
|
|
10
|
+
async execAsync() {
|
|
11
|
+
const { imagePaths, // Array of absolute paths to image files
|
|
12
|
+
title = 'Image Gallery', description = 'Generated by QFlow Agent', outputDir // Optional: directory to save the HTML file
|
|
13
|
+
} = this.params;
|
|
14
|
+
if (!imagePaths || !Array.isArray(imagePaths) || imagePaths.length === 0) {
|
|
15
|
+
throw new Error('ImageGalleryNode requires an `imagePaths` array.');
|
|
16
|
+
}
|
|
17
|
+
const tempDir = outputDir || path.join(os.tmpdir(), `qflow_image_gallery_${Date.now()}`);
|
|
18
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
19
|
+
const htmlFilePath = path.join(tempDir, 'index.html');
|
|
20
|
+
// Generate HTML content
|
|
21
|
+
let imageHtml = '';
|
|
22
|
+
for (const imagePath of imagePaths) {
|
|
23
|
+
// For security and portability, it's best to embed images as base64 data URIs
|
|
24
|
+
// or ensure they are served from a web-accessible location.
|
|
25
|
+
// For simplicity in this node, we'll use file:// URLs, but this might have browser security warnings.
|
|
26
|
+
// A more robust solution would involve a local web server (like BrowserGUINode).
|
|
27
|
+
// For simplicity in this node, we'll assume direct file access for now.
|
|
28
|
+
// Or, even better, copy images to the tempDir and reference them relatively.
|
|
29
|
+
const imageName = path.basename(imagePath);
|
|
30
|
+
const destImagePath = path.join(tempDir, imageName);
|
|
31
|
+
try {
|
|
32
|
+
await fs.copyFile(imagePath, destImagePath); // Copy image to temp dir
|
|
33
|
+
imageHtml += `<div class="gallery-item">\n`;
|
|
34
|
+
imageHtml += ` <img src="${imageName}" alt="${imageName}">\n`;
|
|
35
|
+
imageHtml += ` <p>${imageName}</p>\n`;
|
|
36
|
+
imageHtml += `</div>\n`;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.warn(`[ImageGalleryNode] Could not copy image ${imagePath}: ${e.message}. Skipping.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const htmlContent = `
|
|
43
|
+
<!DOCTYPE html>
|
|
44
|
+
<html lang="en">
|
|
45
|
+
<head>
|
|
46
|
+
<meta charset="UTF-8">
|
|
47
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
48
|
+
<title>${title}</title>
|
|
49
|
+
<style>
|
|
50
|
+
body { font-family: sans-serif; margin: 20px; background-color: #f0f0f0; }
|
|
51
|
+
h1 { color: #333; }
|
|
52
|
+
p { color: #666; }
|
|
53
|
+
.gallery-container {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
56
|
+
gap: 20px;
|
|
57
|
+
padding: 20px;
|
|
58
|
+
background-color: #fff;
|
|
59
|
+
border-radius: 8px;
|
|
60
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
61
|
+
}
|
|
62
|
+
.gallery-item {
|
|
63
|
+
border: 1px solid #ddd;
|
|
64
|
+
border-radius: 4px;
|
|
65
|
+
padding: 10px;
|
|
66
|
+
text-align: center;
|
|
67
|
+
background-color: #f9f9f9;
|
|
68
|
+
}
|
|
69
|
+
.gallery-item img {
|
|
70
|
+
max-width: 100%;
|
|
71
|
+
height: auto;
|
|
72
|
+
display: block;
|
|
73
|
+
margin: 0 auto 10px auto;
|
|
74
|
+
border-radius: 4px;
|
|
75
|
+
}
|
|
76
|
+
</style>
|
|
77
|
+
</head>
|
|
78
|
+
<body>
|
|
79
|
+
<h1>${title}</h1>
|
|
80
|
+
<p>${description}</p>
|
|
81
|
+
<div class="gallery-container">
|
|
82
|
+
${imageHtml}
|
|
83
|
+
</div>
|
|
84
|
+
</body>
|
|
85
|
+
</html>
|
|
86
|
+
`;
|
|
87
|
+
await fs.writeFile(htmlFilePath, htmlContent);
|
|
88
|
+
console.log(`[ImageGalleryNode] Generated HTML gallery at: ${htmlFilePath}`);
|
|
89
|
+
// Open the HTML file in the default web browser
|
|
90
|
+
const openBrowserCommand = os.platform() === 'darwin' ? `open "${htmlFilePath}"` :
|
|
91
|
+
os.platform() === 'win32' ? `start "" "${htmlFilePath}"` :
|
|
92
|
+
`xdg-open "${htmlFilePath}"`;
|
|
93
|
+
const shellNode = new ShellCommandNode();
|
|
94
|
+
shellNode.setParams({ command: openBrowserCommand });
|
|
95
|
+
await new AsyncFlow(shellNode).runAsync({});
|
|
96
|
+
console.log(`[ImageGalleryNode] Opened gallery in browser.`);
|
|
97
|
+
return { status: 'gallery_displayed', htmlFilePath: htmlFilePath, imageCount: imagePaths.length };
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/nodes/index.d.ts
CHANGED
|
@@ -8,6 +8,18 @@ export * from "./stripe.js";
|
|
|
8
8
|
export * from "./webscraper.js";
|
|
9
9
|
export * from "./system_notification.js";
|
|
10
10
|
export * from "./interactive_input.js";
|
|
11
|
+
export * from "./pdf_processor.js";
|
|
12
|
+
export * from "./gis.js";
|
|
13
|
+
export * from "./display_image.js";
|
|
14
|
+
export * from "./hardware_interaction.js";
|
|
15
|
+
export * from "./webhook.js";
|
|
16
|
+
export * from "./scheduler.js";
|
|
17
|
+
export * from "./image_gallery.js";
|
|
18
|
+
export * from "./speech_synthesis.js";
|
|
19
|
+
export * from "./multimedia_processing.js";
|
|
20
|
+
export * from "./remote_execution.js";
|
|
21
|
+
export * from "./data_validation.js";
|
|
22
|
+
export * from "./spreadsheet.js";
|
|
11
23
|
export * from "./shell.js";
|
|
12
24
|
export * from "./filesystem.js";
|
|
13
25
|
export * from "./user.js";
|
package/dist/nodes/index.js
CHANGED
|
@@ -8,6 +8,18 @@ export * from './stripe.js';
|
|
|
8
8
|
export * from './webscraper.js';
|
|
9
9
|
export * from './system_notification.js';
|
|
10
10
|
export * from './interactive_input.js';
|
|
11
|
+
export * from './pdf_processor.js';
|
|
12
|
+
export * from './gis.js';
|
|
13
|
+
export * from './display_image.js';
|
|
14
|
+
export * from './hardware_interaction.js';
|
|
15
|
+
export * from './webhook.js';
|
|
16
|
+
export * from './scheduler.js';
|
|
17
|
+
export * from './image_gallery.js';
|
|
18
|
+
export * from './speech_synthesis.js';
|
|
19
|
+
export * from './multimedia_processing.js';
|
|
20
|
+
export * from './remote_execution.js';
|
|
21
|
+
export * from './data_validation.js';
|
|
22
|
+
export * from './spreadsheet.js';
|
|
11
23
|
export * from './shell.js';
|
|
12
24
|
export * from './filesystem.js';
|
|
13
25
|
export * from './user.js';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
+
import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is available
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
export class MultimediaProcessingNode extends AsyncNode {
|
|
7
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
8
|
+
super(maxRetries, wait);
|
|
9
|
+
}
|
|
10
|
+
async execAsync() {
|
|
11
|
+
const { action, // e.g., 'convert', 'trim', 'extract_audio', 'extract_frame'
|
|
12
|
+
inputPath, // Path to the input multimedia file
|
|
13
|
+
outputPath, // Path for the output file
|
|
14
|
+
// Parameters specific to actions
|
|
15
|
+
format, // For 'convert' (e.g., 'mp4', 'mp3', 'gif')
|
|
16
|
+
startTime, // For 'trim' (e.g., '00:00:10')
|
|
17
|
+
duration, // For 'trim' (e.g., '00:00:05')
|
|
18
|
+
resolution, // For 'convert' video (e.g., '1280x720')
|
|
19
|
+
frameTime, // For 'extract_frame' (e.g., '00:00:05')
|
|
20
|
+
ffmpegArgs // Optional: raw ffmpeg arguments for advanced users
|
|
21
|
+
} = this.params;
|
|
22
|
+
if (!action) {
|
|
23
|
+
throw new Error('MultimediaProcessingNode requires an `action`.');
|
|
24
|
+
}
|
|
25
|
+
if (!inputPath && action !== 'list_codecs') { // list_codecs doesn't need input
|
|
26
|
+
throw new Error('MultimediaProcessingNode requires an `inputPath`.');
|
|
27
|
+
}
|
|
28
|
+
if (!outputPath && !['list_codecs'].includes(action)) { // list_codecs doesn't need output
|
|
29
|
+
throw new Error('MultimediaProcessingNode requires an `outputPath`.');
|
|
30
|
+
}
|
|
31
|
+
let ffmpegCommand = `ffmpeg -y`; // -y to overwrite output files without asking
|
|
32
|
+
switch (action) {
|
|
33
|
+
case 'convert':
|
|
34
|
+
if (!format)
|
|
35
|
+
throw new Error('Convert action requires `format`.');
|
|
36
|
+
ffmpegCommand += ` -i "${inputPath}"`;
|
|
37
|
+
if (resolution)
|
|
38
|
+
ffmpegCommand += ` -vf scale=${resolution}`;
|
|
39
|
+
ffmpegCommand += ` "${outputPath}"`;
|
|
40
|
+
break;
|
|
41
|
+
case 'trim':
|
|
42
|
+
if (!startTime || !duration)
|
|
43
|
+
throw new Error('Trim action requires `startTime` and `duration`.');
|
|
44
|
+
ffmpegCommand += ` -ss ${startTime} -i "${inputPath}" -t ${duration} -c copy "${outputPath}"`;
|
|
45
|
+
break;
|
|
46
|
+
case 'extract_audio':
|
|
47
|
+
if (!format)
|
|
48
|
+
throw new Error('Extract audio requires `format` (e.g., "mp3", "wav").');
|
|
49
|
+
// Re-encode audio to the specified format
|
|
50
|
+
ffmpegCommand += ` -i "${inputPath}" -vn -c:a libmp3lame "${outputPath}"`; // -vn: no video, -c:a libmp3lame: re-encode audio to MP3
|
|
51
|
+
break;
|
|
52
|
+
case 'extract_frame':
|
|
53
|
+
if (!frameTime)
|
|
54
|
+
throw new Error('Extract frame requires `frameTime` (e.g., "00:00:05").');
|
|
55
|
+
ffmpegCommand += ` -ss ${frameTime} -i "${inputPath}" -vframes 1 "${outputPath}"`; // -vframes 1: extract one frame
|
|
56
|
+
break;
|
|
57
|
+
case 'custom': // For advanced users to pass raw ffmpeg arguments
|
|
58
|
+
if (!ffmpegArgs)
|
|
59
|
+
throw new Error('Custom action requires `ffmpegArgs`.');
|
|
60
|
+
ffmpegCommand = `ffmpeg -y ${ffmpegArgs}`;
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
64
|
+
}
|
|
65
|
+
console.log(`[MultimediaProcessingNode] Executing: ${ffmpegCommand}`);
|
|
66
|
+
const shellNode = new ShellCommandNode();
|
|
67
|
+
shellNode.setParams({ command: ffmpegCommand });
|
|
68
|
+
try {
|
|
69
|
+
const result = await new AsyncFlow(shellNode).runAsync({});
|
|
70
|
+
if (result.stderr) {
|
|
71
|
+
console.warn(`[MultimediaProcessingNode] ffmpeg warnings/errors: ${result.stderr}`);
|
|
72
|
+
}
|
|
73
|
+
return { status: 'success', action: action, outputPath: outputPath, stdout: result.stdout, stderr: result.stderr };
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
throw new Error(`Multimedia processing failed: ${e.message}. Ensure ffmpeg is installed and input/output paths are valid.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|