@fractal-solutions/qflow 1.0.62 → 1.0.64

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.
Files changed (199) hide show
  1. package/dist/agent/tools.d.ts +1 -5378
  2. package/dist/agent/tools.js +145 -1171
  3. package/dist/nodes/browser_control.d.ts +31 -0
  4. package/dist/nodes/browser_control.js +33 -0
  5. package/dist/nodes/code_interpreter.d.ts +29 -0
  6. package/dist/nodes/code_interpreter.js +29 -0
  7. package/dist/nodes/data_extractor.d.ts +35 -0
  8. package/dist/nodes/data_extractor.js +37 -0
  9. package/dist/nodes/data_validation.d.ts +27 -0
  10. package/dist/nodes/data_validation.js +29 -0
  11. package/dist/nodes/database.d.ts +44 -0
  12. package/dist/nodes/database.js +46 -0
  13. package/dist/nodes/display_image.d.ts +14 -0
  14. package/dist/nodes/display_image.js +16 -0
  15. package/dist/nodes/embedding.d.ts +22 -0
  16. package/dist/nodes/embedding.js +24 -0
  17. package/dist/nodes/filesystem.d.ts +64 -0
  18. package/dist/nodes/filesystem.js +72 -0
  19. package/dist/nodes/gis.d.ts +25 -0
  20. package/dist/nodes/gis.js +27 -0
  21. package/dist/nodes/git.d.ts +42 -0
  22. package/dist/nodes/git.js +44 -0
  23. package/dist/nodes/github.d.ts +56 -0
  24. package/dist/nodes/github.js +60 -0
  25. package/dist/nodes/hackernews.d.ts +28 -0
  26. package/dist/nodes/hackernews.js +32 -0
  27. package/dist/nodes/hardware_interaction.d.ts +31 -0
  28. package/dist/nodes/hardware_interaction.js +33 -0
  29. package/dist/nodes/http.d.ts +51 -0
  30. package/dist/nodes/http.js +53 -0
  31. package/dist/nodes/http_server.d.ts +37 -0
  32. package/dist/nodes/http_server.js +33 -0
  33. package/dist/nodes/image_gallery.d.ts +29 -0
  34. package/dist/nodes/image_gallery.js +29 -0
  35. package/dist/nodes/interactive_input.d.ts +22 -0
  36. package/dist/nodes/interactive_input.js +24 -0
  37. package/dist/nodes/interactive_webview.d.ts +59 -0
  38. package/dist/nodes/interactive_webview.js +59 -0
  39. package/dist/nodes/iterator.d.ts +18 -0
  40. package/dist/nodes/iterator.js +20 -0
  41. package/dist/nodes/llm.d.ts +142 -0
  42. package/dist/nodes/llm.js +152 -0
  43. package/dist/nodes/memory.d.ts +31 -0
  44. package/dist/nodes/memory.js +80 -38
  45. package/dist/nodes/multimedia_processing.d.ts +47 -0
  46. package/dist/nodes/multimedia_processing.js +49 -0
  47. package/dist/nodes/openrouter_llm.d.ts +30 -0
  48. package/dist/nodes/openrouter_llm.js +32 -0
  49. package/dist/nodes/pdf_processor.d.ts +39 -0
  50. package/dist/nodes/pdf_processor.js +37 -0
  51. package/dist/nodes/remote_execution.d.ts +47 -0
  52. package/dist/nodes/remote_execution.js +49 -0
  53. package/dist/nodes/s3.d.ts +67 -0
  54. package/dist/nodes/s3.js +69 -0
  55. package/dist/nodes/scheduler.d.ts +31 -0
  56. package/dist/nodes/scheduler.js +33 -0
  57. package/dist/nodes/search.d.ts +36 -0
  58. package/dist/nodes/search.js +40 -0
  59. package/dist/nodes/semantic_memory.d.ts +47 -0
  60. package/dist/nodes/semantic_memory.js +49 -0
  61. package/dist/nodes/shell.d.ts +14 -0
  62. package/dist/nodes/shell.js +16 -0
  63. package/dist/nodes/speech_synthesis.d.ts +27 -0
  64. package/dist/nodes/speech_synthesis.js +29 -0
  65. package/dist/nodes/spreadsheet.d.ts +51 -0
  66. package/dist/nodes/spreadsheet.js +53 -0
  67. package/dist/nodes/stripe.d.ts +44 -0
  68. package/dist/nodes/stripe.js +48 -0
  69. package/dist/nodes/subflow.d.ts +18 -0
  70. package/dist/nodes/subflow.js +20 -0
  71. package/dist/nodes/summarize.d.ts +14 -0
  72. package/dist/nodes/summarize.js +20 -0
  73. package/dist/nodes/system_notification.d.ts +22 -0
  74. package/dist/nodes/system_notification.js +24 -0
  75. package/dist/nodes/transform.d.ts +18 -0
  76. package/dist/nodes/transform.js +20 -0
  77. package/dist/nodes/user.d.ts +14 -0
  78. package/dist/nodes/user.js +16 -0
  79. package/dist/nodes/webhook.d.ts +34 -0
  80. package/dist/nodes/webhook.js +36 -0
  81. package/dist/nodes/webscraper.d.ts +14 -0
  82. package/dist/nodes/webscraper.js +16 -0
  83. package/dist/nodes/websockets.d.ts +23 -0
  84. package/dist/nodes/websockets.js +25 -0
  85. package/dist/nodes/webview.d.ts +26 -0
  86. package/dist/nodes/webview.js +28 -0
  87. package/package.json +3 -2
  88. package/dist/qflow.config.d.ts +0 -5
  89. package/dist/qflow.config.js +0 -16
  90. package/dist/src/agent/agent.d.ts +0 -23
  91. package/dist/src/agent/agent.js +0 -365
  92. package/dist/src/agent/base_agent.d.ts +0 -21
  93. package/dist/src/agent/base_agent.js +0 -206
  94. package/dist/src/agent/logger.d.ts +0 -9
  95. package/dist/src/agent/logger.js +0 -45
  96. package/dist/src/agent/lpavrl_agent.d.ts +0 -5
  97. package/dist/src/agent/lpavrl_agent.js +0 -178
  98. package/dist/src/agent/ooda_agent.d.ts +0 -5
  99. package/dist/src/agent/ooda_agent.js +0 -167
  100. package/dist/src/agent/pema_agent.d.ts +0 -5
  101. package/dist/src/agent/pema_agent.js +0 -171
  102. package/dist/src/agent/raor_agent.d.ts +0 -5
  103. package/dist/src/agent/raor_agent.js +0 -164
  104. package/dist/src/agent/tools.d.ts +0 -1
  105. package/dist/src/agent/tools.js +0 -148
  106. package/dist/src/logger.d.ts +0 -9
  107. package/dist/src/logger.js +0 -107
  108. package/dist/src/nodes/agent_llm.d.ts +0 -31
  109. package/dist/src/nodes/agent_llm.js +0 -302
  110. package/dist/src/nodes/browser_control.d.ts +0 -35
  111. package/dist/src/nodes/browser_control.js +0 -106
  112. package/dist/src/nodes/code_interpreter.d.ts +0 -38
  113. package/dist/src/nodes/code_interpreter.js +0 -150
  114. package/dist/src/nodes/data_extractor.d.ts +0 -40
  115. package/dist/src/nodes/data_extractor.js +0 -118
  116. package/dist/src/nodes/data_validation.d.ts +0 -36
  117. package/dist/src/nodes/data_validation.js +0 -77
  118. package/dist/src/nodes/database.d.ts +0 -50
  119. package/dist/src/nodes/database.js +0 -135
  120. package/dist/src/nodes/display_image.d.ts +0 -18
  121. package/dist/src/nodes/display_image.js +0 -63
  122. package/dist/src/nodes/embedding.d.ts +0 -29
  123. package/dist/src/nodes/embedding.js +0 -69
  124. package/dist/src/nodes/filesystem.d.ts +0 -105
  125. package/dist/src/nodes/filesystem.js +0 -160
  126. package/dist/src/nodes/gis.d.ts +0 -62
  127. package/dist/src/nodes/gis.js +0 -133
  128. package/dist/src/nodes/git.d.ts +0 -46
  129. package/dist/src/nodes/git.js +0 -99
  130. package/dist/src/nodes/github.d.ts +0 -83
  131. package/dist/src/nodes/github.js +0 -135
  132. package/dist/src/nodes/hackernews.d.ts +0 -47
  133. package/dist/src/nodes/hackernews.js +0 -79
  134. package/dist/src/nodes/hardware_interaction.d.ts +0 -39
  135. package/dist/src/nodes/hardware_interaction.js +0 -131
  136. package/dist/src/nodes/http.d.ts +0 -77
  137. package/dist/src/nodes/http.js +0 -120
  138. package/dist/src/nodes/http_server.d.ts +0 -54
  139. package/dist/src/nodes/http_server.js +0 -223
  140. package/dist/src/nodes/image_gallery.d.ts +0 -37
  141. package/dist/src/nodes/image_gallery.js +0 -129
  142. package/dist/src/nodes/index.d.ts +0 -48
  143. package/dist/src/nodes/index.js +0 -48
  144. package/dist/src/nodes/interactive_input.d.ts +0 -26
  145. package/dist/src/nodes/interactive_input.js +0 -95
  146. package/dist/src/nodes/interactive_webview.d.ts +0 -78
  147. package/dist/src/nodes/interactive_webview.js +0 -369
  148. package/dist/src/nodes/iterator.d.ts +0 -23
  149. package/dist/src/nodes/iterator.js +0 -43
  150. package/dist/src/nodes/llm.d.ts +0 -160
  151. package/dist/src/nodes/llm.js +0 -367
  152. package/dist/src/nodes/memory.d.ts +0 -43
  153. package/dist/src/nodes/memory.js +0 -90
  154. package/dist/src/nodes/multimedia_processing.d.ts +0 -57
  155. package/dist/src/nodes/multimedia_processing.js +0 -129
  156. package/dist/src/nodes/openrouter_llm.d.ts +0 -38
  157. package/dist/src/nodes/openrouter_llm.js +0 -156
  158. package/dist/src/nodes/pdf_processor.d.ts +0 -43
  159. package/dist/src/nodes/pdf_processor.js +0 -112
  160. package/dist/src/nodes/remote_execution.d.ts +0 -51
  161. package/dist/src/nodes/remote_execution.js +0 -132
  162. package/dist/src/nodes/s3.d.ts +0 -73
  163. package/dist/src/nodes/s3.js +0 -107
  164. package/dist/src/nodes/scheduler.d.ts +0 -51
  165. package/dist/src/nodes/scheduler.js +0 -131
  166. package/dist/src/nodes/search.d.ts +0 -61
  167. package/dist/src/nodes/search.js +0 -118
  168. package/dist/src/nodes/semantic_memory.d.ts +0 -64
  169. package/dist/src/nodes/semantic_memory.js +0 -160
  170. package/dist/src/nodes/shell.d.ts +0 -25
  171. package/dist/src/nodes/shell.js +0 -45
  172. package/dist/src/nodes/speech_synthesis.d.ts +0 -72
  173. package/dist/src/nodes/speech_synthesis.js +0 -171
  174. package/dist/src/nodes/spreadsheet.d.ts +0 -61
  175. package/dist/src/nodes/spreadsheet.js +0 -294
  176. package/dist/src/nodes/stripe.d.ts +0 -67
  177. package/dist/src/nodes/stripe.js +0 -117
  178. package/dist/src/nodes/subflow.d.ts +0 -23
  179. package/dist/src/nodes/subflow.js +0 -36
  180. package/dist/src/nodes/summarize.d.ts +0 -26
  181. package/dist/src/nodes/summarize.js +0 -51
  182. package/dist/src/nodes/system_notification.d.ts +0 -26
  183. package/dist/src/nodes/system_notification.js +0 -74
  184. package/dist/src/nodes/transform.d.ts +0 -23
  185. package/dist/src/nodes/transform.js +0 -52
  186. package/dist/src/nodes/user.d.ts +0 -25
  187. package/dist/src/nodes/user.js +0 -48
  188. package/dist/src/nodes/webhook.d.ts +0 -49
  189. package/dist/src/nodes/webhook.js +0 -161
  190. package/dist/src/nodes/webscraper.d.ts +0 -25
  191. package/dist/src/nodes/webscraper.js +0 -49
  192. package/dist/src/nodes/websockets.d.ts +0 -27
  193. package/dist/src/nodes/websockets.js +0 -98
  194. package/dist/src/nodes/webview.d.ts +0 -38
  195. package/dist/src/nodes/webview.js +0 -55
  196. package/dist/src/qflow.d.ts +0 -69
  197. package/dist/src/qflow.js +0 -320
  198. /package/dist/{src/types.d.ts → types.d.ts} +0 -0
  199. /package/dist/{src/types.js → types.js} +0 -0
@@ -1,129 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
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';
@@ -1,156 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
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';
@@ -1,112 +0,0 @@
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
- }
@@ -1,51 +0,0 @@
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';
@@ -1,132 +0,0 @@
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
- }