@fractal-solutions/qflow 1.0.60 → 1.0.62
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 +75 -74
- package/dist/qflow.config.d.ts +5 -0
- package/dist/qflow.config.js +16 -0
- package/dist/src/agent/agent.d.ts +23 -0
- package/dist/src/agent/agent.js +365 -0
- package/dist/src/agent/base_agent.d.ts +21 -0
- package/dist/src/agent/base_agent.js +206 -0
- package/dist/src/agent/logger.d.ts +9 -0
- package/dist/src/agent/logger.js +45 -0
- package/dist/src/agent/lpavrl_agent.d.ts +5 -0
- package/dist/src/agent/lpavrl_agent.js +178 -0
- package/dist/src/agent/ooda_agent.d.ts +5 -0
- package/dist/src/agent/ooda_agent.js +167 -0
- package/dist/src/agent/pema_agent.d.ts +5 -0
- package/dist/src/agent/pema_agent.js +171 -0
- package/dist/src/agent/raor_agent.d.ts +5 -0
- package/dist/src/agent/raor_agent.js +164 -0
- package/dist/src/agent/tools.d.ts +1 -0
- package/dist/src/agent/tools.js +148 -0
- package/dist/src/logger.d.ts +9 -0
- package/dist/src/logger.js +107 -0
- package/dist/src/nodes/agent_llm.d.ts +31 -0
- package/dist/src/nodes/agent_llm.js +302 -0
- package/dist/src/nodes/browser_control.d.ts +35 -0
- package/dist/src/nodes/browser_control.js +106 -0
- package/dist/src/nodes/code_interpreter.d.ts +38 -0
- package/dist/src/nodes/code_interpreter.js +150 -0
- package/dist/src/nodes/data_extractor.d.ts +40 -0
- package/dist/src/nodes/data_extractor.js +118 -0
- package/dist/src/nodes/data_validation.d.ts +36 -0
- package/dist/src/nodes/data_validation.js +77 -0
- package/dist/src/nodes/database.d.ts +50 -0
- package/dist/src/nodes/database.js +135 -0
- package/dist/src/nodes/display_image.d.ts +18 -0
- package/dist/src/nodes/display_image.js +63 -0
- package/dist/src/nodes/embedding.d.ts +29 -0
- package/dist/src/nodes/embedding.js +69 -0
- package/dist/src/nodes/filesystem.d.ts +105 -0
- package/dist/src/nodes/filesystem.js +160 -0
- package/dist/src/nodes/gis.d.ts +62 -0
- package/dist/src/nodes/gis.js +133 -0
- package/dist/src/nodes/git.d.ts +46 -0
- package/dist/src/nodes/git.js +99 -0
- package/dist/src/nodes/github.d.ts +83 -0
- package/dist/src/nodes/github.js +135 -0
- package/dist/src/nodes/hackernews.d.ts +47 -0
- package/dist/src/nodes/hackernews.js +79 -0
- package/dist/src/nodes/hardware_interaction.d.ts +39 -0
- package/dist/src/nodes/hardware_interaction.js +131 -0
- package/dist/src/nodes/http.d.ts +77 -0
- package/dist/src/nodes/http.js +120 -0
- package/dist/src/nodes/http_server.d.ts +54 -0
- package/dist/src/nodes/http_server.js +223 -0
- package/dist/src/nodes/image_gallery.d.ts +37 -0
- package/dist/src/nodes/image_gallery.js +129 -0
- package/dist/src/nodes/index.d.ts +48 -0
- package/dist/src/nodes/index.js +48 -0
- package/dist/src/nodes/interactive_input.d.ts +26 -0
- package/dist/src/nodes/interactive_input.js +95 -0
- package/dist/src/nodes/interactive_webview.d.ts +78 -0
- package/dist/src/nodes/interactive_webview.js +369 -0
- package/dist/src/nodes/iterator.d.ts +23 -0
- package/dist/src/nodes/iterator.js +43 -0
- package/dist/src/nodes/llm.d.ts +160 -0
- package/dist/src/nodes/llm.js +367 -0
- package/dist/src/nodes/memory.d.ts +43 -0
- package/dist/src/nodes/memory.js +90 -0
- package/dist/src/nodes/multimedia_processing.d.ts +57 -0
- package/dist/src/nodes/multimedia_processing.js +129 -0
- package/dist/src/nodes/openrouter_llm.d.ts +38 -0
- package/dist/src/nodes/openrouter_llm.js +156 -0
- package/dist/src/nodes/pdf_processor.d.ts +43 -0
- package/dist/src/nodes/pdf_processor.js +112 -0
- package/dist/src/nodes/remote_execution.d.ts +51 -0
- package/dist/src/nodes/remote_execution.js +132 -0
- package/dist/src/nodes/s3.d.ts +73 -0
- package/dist/src/nodes/s3.js +107 -0
- package/dist/src/nodes/scheduler.d.ts +51 -0
- package/dist/src/nodes/scheduler.js +131 -0
- package/dist/src/nodes/search.d.ts +61 -0
- package/dist/src/nodes/search.js +118 -0
- package/dist/src/nodes/semantic_memory.d.ts +64 -0
- package/dist/src/nodes/semantic_memory.js +160 -0
- package/dist/src/nodes/shell.d.ts +25 -0
- package/dist/src/nodes/shell.js +45 -0
- package/dist/src/nodes/speech_synthesis.d.ts +72 -0
- package/dist/src/nodes/speech_synthesis.js +171 -0
- package/dist/src/nodes/spreadsheet.d.ts +61 -0
- package/dist/src/nodes/spreadsheet.js +294 -0
- package/dist/src/nodes/stripe.d.ts +67 -0
- package/dist/src/nodes/stripe.js +117 -0
- package/dist/src/nodes/subflow.d.ts +23 -0
- package/dist/src/nodes/subflow.js +36 -0
- package/dist/src/nodes/summarize.d.ts +26 -0
- package/dist/src/nodes/summarize.js +51 -0
- package/dist/src/nodes/system_notification.d.ts +26 -0
- package/dist/src/nodes/system_notification.js +74 -0
- package/dist/src/nodes/transform.d.ts +23 -0
- package/dist/src/nodes/transform.js +52 -0
- package/dist/src/nodes/user.d.ts +25 -0
- package/dist/src/nodes/user.js +48 -0
- package/dist/src/nodes/webhook.d.ts +49 -0
- package/dist/src/nodes/webhook.js +161 -0
- package/dist/src/nodes/webscraper.d.ts +25 -0
- package/dist/src/nodes/webscraper.js +49 -0
- package/dist/src/nodes/websockets.d.ts +27 -0
- package/dist/src/nodes/websockets.js +98 -0
- package/dist/src/nodes/webview.d.ts +38 -0
- package/dist/src/nodes/webview.js +55 -0
- package/dist/src/qflow.d.ts +69 -0
- package/dist/src/qflow.js +320 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
import { log } from '../logger.js';
|
|
7
|
+
export class MultimediaProcessingNode extends AsyncNode {
|
|
8
|
+
static getToolDefinition() {
|
|
9
|
+
return {
|
|
10
|
+
name: "multimedia_processing",
|
|
11
|
+
description: "Performs various multimedia operations on audio and video files using ffmpeg.",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
action: {
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: ["convert", "trim", "extract_audio", "extract_frame", "custom"],
|
|
18
|
+
description: "The multimedia operation to perform."
|
|
19
|
+
},
|
|
20
|
+
inputPath: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Path to the input multimedia file."
|
|
23
|
+
},
|
|
24
|
+
outputPath: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Path for the output file."
|
|
27
|
+
},
|
|
28
|
+
format: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Required for 'convert' and 'extract_audio'. The output format (e.g., 'mp4', 'mp3', 'gif', 'wav')."
|
|
31
|
+
},
|
|
32
|
+
startTime: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "Required for 'trim'. Start time in HH:MM:SS or seconds (e.g., '00:00:10', '10')."
|
|
35
|
+
},
|
|
36
|
+
duration: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Required for 'trim'. Duration in HH:MM:SS or seconds (e.g., '00:00:05', '5')."
|
|
39
|
+
},
|
|
40
|
+
resolution: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Optional for video 'convert'. Resolution (e.g., '1280x720')."
|
|
43
|
+
},
|
|
44
|
+
frameTime: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "Required for 'extract_frame'. Time to extract frame from in HH:MM:SS or seconds (e.g., '00:00:05')."
|
|
47
|
+
},
|
|
48
|
+
ffmpegArgs: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Required for 'custom'. Raw ffmpeg arguments to execute directly."
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
required: ["action", "inputPath", "outputPath"]
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
58
|
+
super(maxRetries, wait);
|
|
59
|
+
}
|
|
60
|
+
async execAsync() {
|
|
61
|
+
const { action, // e.g., 'convert', 'trim', 'extract_audio', 'extract_frame'
|
|
62
|
+
inputPath, // Path to the input multimedia file
|
|
63
|
+
outputPath, // Path for the output file
|
|
64
|
+
// Parameters specific to actions
|
|
65
|
+
format, // For 'convert' (e.g., 'mp4', 'mp3', 'gif')
|
|
66
|
+
startTime, // For 'trim' (e.g., '00:00:10')
|
|
67
|
+
duration, // For 'trim' (e.g., '00:00:05')
|
|
68
|
+
resolution, // For 'convert' video (e.g., '1280x720')
|
|
69
|
+
frameTime, // For 'extract_frame' (e.g., '00:00:05')
|
|
70
|
+
ffmpegArgs // Optional: raw ffmpeg arguments for advanced users
|
|
71
|
+
} = this.params;
|
|
72
|
+
if (!action) {
|
|
73
|
+
throw new Error('MultimediaProcessingNode requires an `action`.');
|
|
74
|
+
}
|
|
75
|
+
if (!inputPath && action !== 'list_codecs') { // list_codecs doesn't need input
|
|
76
|
+
throw new Error('MultimediaProcessingNode requires an `inputPath`.');
|
|
77
|
+
}
|
|
78
|
+
if (!outputPath && !['list_codecs'].includes(action)) { // list_codecs doesn't need output
|
|
79
|
+
throw new Error('MultimediaProcessingNode requires an `outputPath`.');
|
|
80
|
+
}
|
|
81
|
+
let ffmpegCommand = `ffmpeg -y`; // -y to overwrite output files without asking
|
|
82
|
+
switch (action) {
|
|
83
|
+
case 'convert':
|
|
84
|
+
if (!format)
|
|
85
|
+
throw new Error('Convert action requires `format`.');
|
|
86
|
+
ffmpegCommand += ` -i "${inputPath}"`;
|
|
87
|
+
if (resolution)
|
|
88
|
+
ffmpegCommand += ` -vf scale=${resolution}`;
|
|
89
|
+
ffmpegCommand += ` "${outputPath}"`;
|
|
90
|
+
break;
|
|
91
|
+
case 'trim':
|
|
92
|
+
if (!startTime || !duration)
|
|
93
|
+
throw new Error('Trim action requires `startTime` and `duration`.');
|
|
94
|
+
ffmpegCommand += ` -ss ${startTime} -i "${inputPath}" -t ${duration} -c copy "${outputPath}"`;
|
|
95
|
+
break;
|
|
96
|
+
case 'extract_audio':
|
|
97
|
+
if (!format)
|
|
98
|
+
throw new Error('Extract audio requires `format` (e.g., "mp3", "wav").');
|
|
99
|
+
// Re-encode audio to the specified format
|
|
100
|
+
ffmpegCommand += ` -i "${inputPath}" -vn -c:a libmp3lame "${outputPath}"`; // -vn: no video, -c:a libmp3lame: re-encode audio to MP3
|
|
101
|
+
break;
|
|
102
|
+
case 'extract_frame':
|
|
103
|
+
if (!frameTime)
|
|
104
|
+
throw new Error('Extract frame requires `frameTime` (e.g., "00:00:05").');
|
|
105
|
+
ffmpegCommand += ` -ss ${frameTime} -i "${inputPath}" -vframes 1 "${outputPath}"`; // -vframes 1: extract one frame
|
|
106
|
+
break;
|
|
107
|
+
case 'custom': // For advanced users to pass raw ffmpeg arguments
|
|
108
|
+
if (!ffmpegArgs)
|
|
109
|
+
throw new Error('Custom action requires `ffmpegArgs`.');
|
|
110
|
+
ffmpegCommand = `ffmpeg -y ${ffmpegArgs}`;
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
114
|
+
}
|
|
115
|
+
log(`[MultimediaProcessingNode] Executing: ${ffmpegCommand}`, this.params.logging);
|
|
116
|
+
const shellNode = new ShellCommandNode();
|
|
117
|
+
shellNode.setParams({ command: ffmpegCommand });
|
|
118
|
+
try {
|
|
119
|
+
const result = await new AsyncFlow(shellNode).runAsync({});
|
|
120
|
+
if (result.stderr) {
|
|
121
|
+
log(`[MultimediaProcessingNode] ffmpeg warnings/errors: ${result.stderr}`, this.params.logging, { type: 'warn' });
|
|
122
|
+
}
|
|
123
|
+
return { status: 'success', action: action, outputPath: outputPath, stdout: result.stdout, stderr: result.stderr };
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
throw new Error(`Multimedia processing failed: ${e.message}. Ensure ffmpeg is installed and input/output paths are valid.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class OpenRouterLLMNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
prompt: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
model: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
apiKey: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
siteUrl: {
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
siteTitle: {
|
|
25
|
+
type: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
required: string[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
execAsync(): Promise<any>;
|
|
33
|
+
}
|
|
34
|
+
export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
35
|
+
postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
|
|
36
|
+
preparePrompt(shared: any): void;
|
|
37
|
+
}
|
|
38
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { log } from '../logger.js';
|
|
3
|
+
export class OpenRouterLLMNode extends AsyncNode {
|
|
4
|
+
static getToolDefinition() {
|
|
5
|
+
return {
|
|
6
|
+
name: "openrouter_llm_reasoning",
|
|
7
|
+
description: "Generates human-like text, reasons, and plans via OpenRouter. Not for external actions.",
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
prompt: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "The prompt or question to send to the language model."
|
|
14
|
+
},
|
|
15
|
+
model: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "The OpenRouter model ID (e.g., 'openai/gpt-4o', 'mistralai/mistral-7b-instruct')."
|
|
18
|
+
},
|
|
19
|
+
apiKey: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Your OpenRouter API key."
|
|
22
|
+
},
|
|
23
|
+
siteUrl: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Optional. Site URL for rankings on openrouter.ai."
|
|
26
|
+
},
|
|
27
|
+
siteTitle: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Optional. Site title for rankings on openrouter.ai."
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
required: ["prompt", "model", "apiKey"]
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
constructor(maxRetries = 3, wait = 2) {
|
|
37
|
+
super(maxRetries, wait);
|
|
38
|
+
}
|
|
39
|
+
async execAsync() {
|
|
40
|
+
const { prompt, apiKey, model, siteUrl, siteTitle } = this.params;
|
|
41
|
+
if (!prompt) {
|
|
42
|
+
throw new Error('OpenRouterLLMNode requires a `prompt`.');
|
|
43
|
+
}
|
|
44
|
+
if (!apiKey) {
|
|
45
|
+
throw new Error('OpenRouterLLMNode requires an `apiKey`.');
|
|
46
|
+
}
|
|
47
|
+
if (!model) {
|
|
48
|
+
throw new Error('OpenRouterLLMNode requires a `model`.');
|
|
49
|
+
}
|
|
50
|
+
const headers = {
|
|
51
|
+
'Content-Type': 'application/json',
|
|
52
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
53
|
+
};
|
|
54
|
+
if (siteUrl) {
|
|
55
|
+
headers['HTTP-Referer'] = siteUrl;
|
|
56
|
+
}
|
|
57
|
+
if (siteTitle) {
|
|
58
|
+
headers['X-Title'] = siteTitle;
|
|
59
|
+
}
|
|
60
|
+
log(`[OpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: headers,
|
|
65
|
+
body: JSON.stringify({
|
|
66
|
+
model: model,
|
|
67
|
+
messages: [{ role: 'user', content: prompt }],
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const errorData = await response.json();
|
|
72
|
+
throw new Error(`OpenRouter API error: ${response.status} - ${JSON.stringify(errorData)}`);
|
|
73
|
+
}
|
|
74
|
+
const data = await response.json();
|
|
75
|
+
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
76
|
+
throw new Error('Invalid response structure from OpenRouter API.');
|
|
77
|
+
}
|
|
78
|
+
const llmResponse = data.choices[0].message.content.trim();
|
|
79
|
+
log(`[OpenRouter] Received response from ${model}.`, this.params.logging);
|
|
80
|
+
return llmResponse;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
log('OpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
89
|
+
async execAsync() {
|
|
90
|
+
const { prompt, apiKey, model, siteUrl, siteTitle } = this.params; // prompt here is the stringified conversation history
|
|
91
|
+
if (!prompt) {
|
|
92
|
+
throw new Error("AgentOpenRouterLLMNode: Prompt (conversation history) is missing from params.");
|
|
93
|
+
}
|
|
94
|
+
if (!apiKey) {
|
|
95
|
+
throw new Error("OpenRouter API Key is not configured for AgentOpenRouterLLMNode.");
|
|
96
|
+
}
|
|
97
|
+
if (!model) {
|
|
98
|
+
throw new Error("AgentOpenRouterLLMNode requires a `model`.");
|
|
99
|
+
}
|
|
100
|
+
let messages;
|
|
101
|
+
try {
|
|
102
|
+
messages = JSON.parse(prompt);
|
|
103
|
+
// Ensure messages array contains objects with role and content
|
|
104
|
+
if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
|
|
105
|
+
throw new Error("Parsed prompt is not a valid messages array.");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw new Error(`AgentOpenRouterLLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
|
|
110
|
+
}
|
|
111
|
+
const headers = {
|
|
112
|
+
'Content-Type': 'application/json',
|
|
113
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
114
|
+
};
|
|
115
|
+
if (siteUrl) {
|
|
116
|
+
headers['HTTP-Referer'] = siteUrl;
|
|
117
|
+
}
|
|
118
|
+
if (siteTitle) {
|
|
119
|
+
headers['X-Title'] = siteTitle;
|
|
120
|
+
}
|
|
121
|
+
log(`[AgentOpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
122
|
+
try {
|
|
123
|
+
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: headers,
|
|
126
|
+
body: JSON.stringify({
|
|
127
|
+
model: model,
|
|
128
|
+
messages: messages, // Use the parsed messages array directly
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
const errorData = await response.json();
|
|
133
|
+
throw new Error(`OpenRouter API error: ${response.status} - ${JSON.stringify(errorData)}`);
|
|
134
|
+
}
|
|
135
|
+
const data = await response.json();
|
|
136
|
+
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
137
|
+
throw new Error('Invalid response structure from OpenRouter API or missing content.');
|
|
138
|
+
}
|
|
139
|
+
const llmResponse = data.choices[0].message.content.trim();
|
|
140
|
+
log(`[AgentOpenRouter] Received response from ${model}.`, this.params.logging);
|
|
141
|
+
return llmResponse; // Return the actual content
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
log('AgentOpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async postAsync(shared, prepRes, execRes) {
|
|
149
|
+
shared.llmResponse = execRes; // Store the full LLM response object
|
|
150
|
+
return execRes; // Return the full LLM response object
|
|
151
|
+
}
|
|
152
|
+
// preparePrompt is no longer needed as execAsync handles the prompt directly
|
|
153
|
+
preparePrompt(shared) {
|
|
154
|
+
throw new Error("preparePrompt should not be called on AgentOpenRouterLLMNode. Prompt is handled in execAsync.");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class PDFProcessorNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
filePath: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
action: {
|
|
13
|
+
type: string;
|
|
14
|
+
enum: string[];
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
outputDir: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
pageRange: {
|
|
22
|
+
type: string;
|
|
23
|
+
properties: {
|
|
24
|
+
start: {
|
|
25
|
+
type: string;
|
|
26
|
+
};
|
|
27
|
+
end: {
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
password: {
|
|
34
|
+
type: string;
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
required: string[];
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
execAsync(): Promise<{}>;
|
|
42
|
+
}
|
|
43
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
+
import { ShellCommandNode, ReadFileNode } from './index.js'; // Assuming these are in the same nodes directory
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
export class PDFProcessorNode extends AsyncNode {
|
|
7
|
+
static getToolDefinition() {
|
|
8
|
+
return {
|
|
9
|
+
name: "pdf_processor",
|
|
10
|
+
description: "Extracts text or images from PDF documents.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
filePath: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "The absolute path to the PDF file."
|
|
17
|
+
},
|
|
18
|
+
action: {
|
|
19
|
+
type: "string",
|
|
20
|
+
enum: ["extract_text", "extract_images"],
|
|
21
|
+
description: "The action to perform: 'extract_text' or 'extract_images'."
|
|
22
|
+
},
|
|
23
|
+
outputDir: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Optional. Directory to save extracted files. If not provided, a temporary directory will be used."
|
|
26
|
+
},
|
|
27
|
+
pageRange: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
start: { type: "number" },
|
|
31
|
+
end: { type: "number" }
|
|
32
|
+
},
|
|
33
|
+
description: "Optional. Page range to process (e.g., {start: 1, end: 5})."
|
|
34
|
+
},
|
|
35
|
+
password: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Optional. Password for encrypted PDFs."
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
required: ["filePath", "action"]
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
45
|
+
super(maxRetries, wait);
|
|
46
|
+
}
|
|
47
|
+
async execAsync() {
|
|
48
|
+
const { filePath, action, outputDir, pageRange, password } = this.params;
|
|
49
|
+
if (!filePath) {
|
|
50
|
+
throw new Error('PDFProcessorNode requires a `filePath` parameter.');
|
|
51
|
+
}
|
|
52
|
+
if (!action || !['extract_text', 'extract_images'].includes(action)) {
|
|
53
|
+
throw new Error('PDFProcessorNode requires an `action` parameter: "extract_text" or "extract_images".');
|
|
54
|
+
}
|
|
55
|
+
const tempOutputDir = outputDir || path.join(os.tmpdir(), `qflow_pdf_output_${Date.now()}`);
|
|
56
|
+
await fs.mkdir(tempOutputDir, { recursive: true });
|
|
57
|
+
let command = '';
|
|
58
|
+
let result = {};
|
|
59
|
+
switch (action) {
|
|
60
|
+
case 'extract_text':
|
|
61
|
+
// Requires 'pdftotext' (from poppler-utils)
|
|
62
|
+
const outputTextFilePath = path.join(tempOutputDir, `${path.basename(filePath, path.extname(filePath))}.txt`);
|
|
63
|
+
command = `pdftotext "${filePath}" "${outputTextFilePath}"`;
|
|
64
|
+
if (pageRange)
|
|
65
|
+
command += ` -f ${pageRange.start} -l ${pageRange.end}`;
|
|
66
|
+
if (password)
|
|
67
|
+
command += ` -opw "${password}"`; // Owner password
|
|
68
|
+
// User password: -upw "password"
|
|
69
|
+
try {
|
|
70
|
+
const shellNode = new ShellCommandNode();
|
|
71
|
+
shellNode.setParams({ command: command });
|
|
72
|
+
await new AsyncFlow(shellNode).runAsync({});
|
|
73
|
+
const readNode = new ReadFileNode();
|
|
74
|
+
readNode.setParams({ filePath: outputTextFilePath });
|
|
75
|
+
const textContent = await new AsyncFlow(readNode).runAsync({});
|
|
76
|
+
result = { text: textContent, outputFilePath: outputTextFilePath };
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error(`Failed to extract text using pdftotext: ${e.message}. Is pdftotext installed and in your PATH?`);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case 'extract_images':
|
|
83
|
+
// Requires 'pdfimages' (from poppler-utils)
|
|
84
|
+
const imagePrefix = path.join(tempOutputDir, path.basename(filePath, path.extname(filePath)));
|
|
85
|
+
command = `pdfimages -png "${filePath}" "${imagePrefix}"`; // -png for PNG format
|
|
86
|
+
if (pageRange)
|
|
87
|
+
command += ` -f ${pageRange.start} -l ${pageRange.end}`;
|
|
88
|
+
if (password)
|
|
89
|
+
command += ` -opw "${password}"`;
|
|
90
|
+
try {
|
|
91
|
+
const shellNode = new ShellCommandNode();
|
|
92
|
+
shellNode.setParams({ command: command });
|
|
93
|
+
await new AsyncFlow(shellNode).runAsync({});
|
|
94
|
+
const extractedImages = await fs.readdir(tempOutputDir);
|
|
95
|
+
const imageFiles = extractedImages.filter(file => file.startsWith(path.basename(filePath, path.extname(filePath))) && (file.endsWith('.png') || file.endsWith('.jpg')));
|
|
96
|
+
result = { imageCount: imageFiles.length, outputDirectory: tempOutputDir, imageFiles: imageFiles.map(f => path.join(tempOutputDir, f)) };
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
throw new Error(`Failed to extract images using pdfimages: ${e.message}. Is pdfimages installed and in your PATH?`);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
104
|
+
}
|
|
105
|
+
// Clean up temporary directory if it was created by this node and not specified by user
|
|
106
|
+
if (!outputDir) {
|
|
107
|
+
// Consider adding a cleanup mechanism or making it explicit for the user
|
|
108
|
+
// For now, we'll leave it for inspection.
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class RemoteExecutionNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
host: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
port: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
username: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
password: {
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
privateKey: {
|
|
25
|
+
type: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
passphrase: {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
action: {
|
|
33
|
+
type: string;
|
|
34
|
+
enum: string[];
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
command: {
|
|
38
|
+
type: string;
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
timeout: {
|
|
42
|
+
type: string;
|
|
43
|
+
description: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
required: string[];
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
execAsync(): Promise<{}>;
|
|
50
|
+
}
|
|
51
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
// You would need to install the 'ssh2' library: npm install ssh2
|
|
3
|
+
import { Client } from 'ssh2';
|
|
4
|
+
import { log } from '../logger.js';
|
|
5
|
+
export class RemoteExecutionNode extends AsyncNode {
|
|
6
|
+
static getToolDefinition() {
|
|
7
|
+
return {
|
|
8
|
+
name: "remote_execution",
|
|
9
|
+
description: "Executes commands on remote machines via SSH.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
host: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The hostname or IP address of the remote machine."
|
|
16
|
+
},
|
|
17
|
+
port: {
|
|
18
|
+
type: "number",
|
|
19
|
+
description: "Optional. The SSH port. Defaults to 22."
|
|
20
|
+
},
|
|
21
|
+
username: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The username for SSH authentication."
|
|
24
|
+
},
|
|
25
|
+
password: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Optional. The password for SSH authentication (use with caution, prefer privateKey)."
|
|
28
|
+
},
|
|
29
|
+
privateKey: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Optional. The content of the private SSH key or its absolute path."
|
|
32
|
+
},
|
|
33
|
+
passphrase: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "Optional. The passphrase for an encrypted private key."
|
|
36
|
+
},
|
|
37
|
+
action: {
|
|
38
|
+
type: "string",
|
|
39
|
+
enum: ["execute_command"],
|
|
40
|
+
description: "The action to perform. Currently only 'execute_command' is supported."
|
|
41
|
+
},
|
|
42
|
+
command: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "The command string to execute on the remote machine."
|
|
45
|
+
},
|
|
46
|
+
timeout: {
|
|
47
|
+
type: "number",
|
|
48
|
+
description: "Optional. Timeout in milliseconds for the command execution. Defaults to 30000 (30 seconds)."
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
required: ["host", "username", "action", "command"]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
56
|
+
super(maxRetries, wait);
|
|
57
|
+
}
|
|
58
|
+
async execAsync() {
|
|
59
|
+
const { host, port = 22, username, password, // Use with caution, prefer privateKey
|
|
60
|
+
privateKey, // Path to private key file or content
|
|
61
|
+
passphrase, // For encrypted private key
|
|
62
|
+
action, // 'execute_command'
|
|
63
|
+
command, // Command to execute
|
|
64
|
+
timeout = 30000 // Timeout for command execution
|
|
65
|
+
} = this.params;
|
|
66
|
+
if (!host || !username) {
|
|
67
|
+
throw new Error('RemoteExecutionNode requires `host` and `username`.');
|
|
68
|
+
}
|
|
69
|
+
if (!action || action !== 'execute_command') {
|
|
70
|
+
throw new Error('RemoteExecutionNode currently only supports `action: "execute_command"`.');
|
|
71
|
+
}
|
|
72
|
+
if (!command) {
|
|
73
|
+
throw new Error('RemoteExecutionNode `execute_command` action requires a `command`.');
|
|
74
|
+
}
|
|
75
|
+
if (!password && !privateKey) {
|
|
76
|
+
throw new Error('RemoteExecutionNode requires either `password` or `privateKey` for authentication.');
|
|
77
|
+
}
|
|
78
|
+
const conn = new Client();
|
|
79
|
+
let result = {};
|
|
80
|
+
try {
|
|
81
|
+
await new Promise((resolve, reject) => {
|
|
82
|
+
conn.on('ready', () => {
|
|
83
|
+
log(`[RemoteExecutionNode] Connected to ${username}@${host}:${port}`, this.params.logging);
|
|
84
|
+
resolve();
|
|
85
|
+
}).on('error', (err) => {
|
|
86
|
+
reject(new Error(`SSH connection error: ${err.message}`));
|
|
87
|
+
}).connect({
|
|
88
|
+
host: host,
|
|
89
|
+
port: port,
|
|
90
|
+
username: username,
|
|
91
|
+
password: password,
|
|
92
|
+
privateKey: privateKey ? (privateKey.startsWith('/') ? require('fs').readFileSync(privateKey) : privateKey) : undefined, // Read from file if path, else use content
|
|
93
|
+
passphrase: passphrase,
|
|
94
|
+
readyTimeout: timeout // Timeout for connection to become ready
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
// Execute command
|
|
98
|
+
await new Promise((resolve, reject) => {
|
|
99
|
+
conn.exec(command, { pty: false, x11: false, env: {} }, (err, stream) => {
|
|
100
|
+
if (err)
|
|
101
|
+
return reject(new Error(`SSH command execution error: ${err.message}`));
|
|
102
|
+
let stdout = '';
|
|
103
|
+
let stderr = '';
|
|
104
|
+
let exitCode = null;
|
|
105
|
+
let signal = null;
|
|
106
|
+
stream.on('data', (data) => {
|
|
107
|
+
stdout += data.toString();
|
|
108
|
+
}).stderr.on('data', (data) => {
|
|
109
|
+
stderr += data.toString();
|
|
110
|
+
}).on('close', (code, sig) => {
|
|
111
|
+
exitCode = code;
|
|
112
|
+
signal = sig;
|
|
113
|
+
resolve();
|
|
114
|
+
}).on('end', () => {
|
|
115
|
+
// Stream ended
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
result = { status: 'command_executed', command: command, stdout: stdout, stderr: stderr, exitCode: exitCode, signal: signal };
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
throw new Error(`Remote execution failed: ${e.message}`);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
if (conn && conn.connected) {
|
|
126
|
+
conn.end();
|
|
127
|
+
log(`[RemoteExecutionNode] Disconnected from ${host}`, this.params.logging);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
}
|