@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.
Files changed (114) hide show
  1. package/README.md +75 -74
  2. package/dist/qflow.config.d.ts +5 -0
  3. package/dist/qflow.config.js +16 -0
  4. package/dist/src/agent/agent.d.ts +23 -0
  5. package/dist/src/agent/agent.js +365 -0
  6. package/dist/src/agent/base_agent.d.ts +21 -0
  7. package/dist/src/agent/base_agent.js +206 -0
  8. package/dist/src/agent/logger.d.ts +9 -0
  9. package/dist/src/agent/logger.js +45 -0
  10. package/dist/src/agent/lpavrl_agent.d.ts +5 -0
  11. package/dist/src/agent/lpavrl_agent.js +178 -0
  12. package/dist/src/agent/ooda_agent.d.ts +5 -0
  13. package/dist/src/agent/ooda_agent.js +167 -0
  14. package/dist/src/agent/pema_agent.d.ts +5 -0
  15. package/dist/src/agent/pema_agent.js +171 -0
  16. package/dist/src/agent/raor_agent.d.ts +5 -0
  17. package/dist/src/agent/raor_agent.js +164 -0
  18. package/dist/src/agent/tools.d.ts +1 -0
  19. package/dist/src/agent/tools.js +148 -0
  20. package/dist/src/logger.d.ts +9 -0
  21. package/dist/src/logger.js +107 -0
  22. package/dist/src/nodes/agent_llm.d.ts +31 -0
  23. package/dist/src/nodes/agent_llm.js +302 -0
  24. package/dist/src/nodes/browser_control.d.ts +35 -0
  25. package/dist/src/nodes/browser_control.js +106 -0
  26. package/dist/src/nodes/code_interpreter.d.ts +38 -0
  27. package/dist/src/nodes/code_interpreter.js +150 -0
  28. package/dist/src/nodes/data_extractor.d.ts +40 -0
  29. package/dist/src/nodes/data_extractor.js +118 -0
  30. package/dist/src/nodes/data_validation.d.ts +36 -0
  31. package/dist/src/nodes/data_validation.js +77 -0
  32. package/dist/src/nodes/database.d.ts +50 -0
  33. package/dist/src/nodes/database.js +135 -0
  34. package/dist/src/nodes/display_image.d.ts +18 -0
  35. package/dist/src/nodes/display_image.js +63 -0
  36. package/dist/src/nodes/embedding.d.ts +29 -0
  37. package/dist/src/nodes/embedding.js +69 -0
  38. package/dist/src/nodes/filesystem.d.ts +105 -0
  39. package/dist/src/nodes/filesystem.js +160 -0
  40. package/dist/src/nodes/gis.d.ts +62 -0
  41. package/dist/src/nodes/gis.js +133 -0
  42. package/dist/src/nodes/git.d.ts +46 -0
  43. package/dist/src/nodes/git.js +99 -0
  44. package/dist/src/nodes/github.d.ts +83 -0
  45. package/dist/src/nodes/github.js +135 -0
  46. package/dist/src/nodes/hackernews.d.ts +47 -0
  47. package/dist/src/nodes/hackernews.js +79 -0
  48. package/dist/src/nodes/hardware_interaction.d.ts +39 -0
  49. package/dist/src/nodes/hardware_interaction.js +131 -0
  50. package/dist/src/nodes/http.d.ts +77 -0
  51. package/dist/src/nodes/http.js +120 -0
  52. package/dist/src/nodes/http_server.d.ts +54 -0
  53. package/dist/src/nodes/http_server.js +223 -0
  54. package/dist/src/nodes/image_gallery.d.ts +37 -0
  55. package/dist/src/nodes/image_gallery.js +129 -0
  56. package/dist/src/nodes/index.d.ts +48 -0
  57. package/dist/src/nodes/index.js +48 -0
  58. package/dist/src/nodes/interactive_input.d.ts +26 -0
  59. package/dist/src/nodes/interactive_input.js +95 -0
  60. package/dist/src/nodes/interactive_webview.d.ts +78 -0
  61. package/dist/src/nodes/interactive_webview.js +369 -0
  62. package/dist/src/nodes/iterator.d.ts +23 -0
  63. package/dist/src/nodes/iterator.js +43 -0
  64. package/dist/src/nodes/llm.d.ts +160 -0
  65. package/dist/src/nodes/llm.js +367 -0
  66. package/dist/src/nodes/memory.d.ts +43 -0
  67. package/dist/src/nodes/memory.js +90 -0
  68. package/dist/src/nodes/multimedia_processing.d.ts +57 -0
  69. package/dist/src/nodes/multimedia_processing.js +129 -0
  70. package/dist/src/nodes/openrouter_llm.d.ts +38 -0
  71. package/dist/src/nodes/openrouter_llm.js +156 -0
  72. package/dist/src/nodes/pdf_processor.d.ts +43 -0
  73. package/dist/src/nodes/pdf_processor.js +112 -0
  74. package/dist/src/nodes/remote_execution.d.ts +51 -0
  75. package/dist/src/nodes/remote_execution.js +132 -0
  76. package/dist/src/nodes/s3.d.ts +73 -0
  77. package/dist/src/nodes/s3.js +107 -0
  78. package/dist/src/nodes/scheduler.d.ts +51 -0
  79. package/dist/src/nodes/scheduler.js +131 -0
  80. package/dist/src/nodes/search.d.ts +61 -0
  81. package/dist/src/nodes/search.js +118 -0
  82. package/dist/src/nodes/semantic_memory.d.ts +64 -0
  83. package/dist/src/nodes/semantic_memory.js +160 -0
  84. package/dist/src/nodes/shell.d.ts +25 -0
  85. package/dist/src/nodes/shell.js +45 -0
  86. package/dist/src/nodes/speech_synthesis.d.ts +72 -0
  87. package/dist/src/nodes/speech_synthesis.js +171 -0
  88. package/dist/src/nodes/spreadsheet.d.ts +61 -0
  89. package/dist/src/nodes/spreadsheet.js +294 -0
  90. package/dist/src/nodes/stripe.d.ts +67 -0
  91. package/dist/src/nodes/stripe.js +117 -0
  92. package/dist/src/nodes/subflow.d.ts +23 -0
  93. package/dist/src/nodes/subflow.js +36 -0
  94. package/dist/src/nodes/summarize.d.ts +26 -0
  95. package/dist/src/nodes/summarize.js +51 -0
  96. package/dist/src/nodes/system_notification.d.ts +26 -0
  97. package/dist/src/nodes/system_notification.js +74 -0
  98. package/dist/src/nodes/transform.d.ts +23 -0
  99. package/dist/src/nodes/transform.js +52 -0
  100. package/dist/src/nodes/user.d.ts +25 -0
  101. package/dist/src/nodes/user.js +48 -0
  102. package/dist/src/nodes/webhook.d.ts +49 -0
  103. package/dist/src/nodes/webhook.js +161 -0
  104. package/dist/src/nodes/webscraper.d.ts +25 -0
  105. package/dist/src/nodes/webscraper.js +49 -0
  106. package/dist/src/nodes/websockets.d.ts +27 -0
  107. package/dist/src/nodes/websockets.js +98 -0
  108. package/dist/src/nodes/webview.d.ts +38 -0
  109. package/dist/src/nodes/webview.js +55 -0
  110. package/dist/src/qflow.d.ts +69 -0
  111. package/dist/src/qflow.js +320 -0
  112. package/dist/src/types.d.ts +6 -0
  113. package/dist/src/types.js +5 -0
  114. package/package.json +1 -1
@@ -0,0 +1,74 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import { exec } from 'child_process';
3
+ import os from 'os';
4
+ import { log } from '../logger.js';
5
+ export class SystemNotificationNode extends AsyncNode {
6
+ static getToolDefinition() {
7
+ return {
8
+ name: "system_notification",
9
+ description: "Displays a system-level notification across OSs.",
10
+ parameters: {
11
+ type: "object",
12
+ properties: {
13
+ message: {
14
+ type: "string",
15
+ description: "The main message content of the notification."
16
+ },
17
+ title: {
18
+ type: "string",
19
+ description: "Optional. The title of the notification. Defaults to 'QFlow Notification'."
20
+ },
21
+ icon: {
22
+ type: "string",
23
+ description: "Optional. Path to an icon file or a system icon name (Linux specific). Ignored on macOS/Windows."
24
+ }
25
+ },
26
+ required: ["message"]
27
+ }
28
+ };
29
+ }
30
+ constructor(maxRetries = 1, wait = 0) {
31
+ super(maxRetries, wait);
32
+ }
33
+ async execAsync() {
34
+ const { message, title = 'QFlow', icon = '' } = this.params;
35
+ if (!message) {
36
+ throw new Error('SystemNotificationNode requires a `message` parameter.');
37
+ }
38
+ let command = '';
39
+ const platform = os.platform();
40
+ switch (platform) {
41
+ case 'linux':
42
+ // Requires 'notify-send' (libnotify-bin package)
43
+ command = `notify-send "${title}" "${message}"`;
44
+ if (icon)
45
+ command += ` -i "${icon}"`;
46
+ break;
47
+ case 'darwin': // macOS
48
+ command = `osascript -e 'display notification "${message}" with title "${title}"'`;
49
+ // osascript doesn't directly support icons in this simple form
50
+ break;
51
+ case 'win32': // Windows
52
+ // Using PowerShell for a simple message box.
53
+ // For more advanced toast notifications, a dedicated module or more complex script would be needed.
54
+ command = `powershell -Command "[System.Windows.Forms.MessageBox]::Show(\"${message}\", \"${title}\")"`;
55
+ break;
56
+ default:
57
+ throw new Error(`Unsupported platform for SystemNotificationNode: ${platform}`);
58
+ }
59
+ log(`[SystemNotificationNode] Executing: ${command}`, this.params.logging);
60
+ return new Promise((resolve, reject) => {
61
+ exec(command, (error, stdout, stderr) => {
62
+ if (error) {
63
+ log(`SystemNotificationNode error: ${error.message}`, this.params.logging, { type: 'error' });
64
+ return reject(error);
65
+ }
66
+ if (stderr) {
67
+ log(`SystemNotificationNode stderr: ${stderr}`, this.params.logging, { type: 'warn' });
68
+ }
69
+ log(`Notification displayed: "${message}"`, this.params.logging);
70
+ resolve({ message, title, stdout, stderr });
71
+ });
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,23 @@
1
+ export class TransformNode extends AsyncNode {
2
+ static getToolDefinition(): {
3
+ name: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ input: {
9
+ type: string;
10
+ description: string;
11
+ };
12
+ transformFunction: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ };
17
+ required: string[];
18
+ };
19
+ };
20
+ execAsync(): Promise<any>;
21
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
22
+ }
23
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,52 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import { log } from '../logger.js';
3
+ export class TransformNode extends AsyncNode {
4
+ static getToolDefinition() {
5
+ return {
6
+ name: "transform_node",
7
+ description: "Transforms data using a JavaScript function.",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ input: {
12
+ type: "object", // Can be any type of data
13
+ description: "The data to be transformed."
14
+ },
15
+ transformFunction: {
16
+ type: "string",
17
+ description: "A JavaScript function string (e.g., '(data) => data.map(item => item.name)') that takes 'data' as an argument and returns the transformed result."
18
+ }
19
+ },
20
+ required: ["input", "transformFunction"]
21
+ }
22
+ };
23
+ }
24
+ async execAsync() {
25
+ const { input, transformFunction } = this.params;
26
+ if (transformFunction === undefined) {
27
+ throw new Error('TransformNode requires a `transformFunction`.');
28
+ }
29
+ let func;
30
+ try {
31
+ // Create a function from the string. This allows dynamic transformations.
32
+ // Using new Function() is powerful but requires careful handling of scope and security.
33
+ // For this context, we assume the user provides safe functions.
34
+ func = new Function('data', `return (${transformFunction})(data);`);
35
+ }
36
+ catch (e) {
37
+ throw new Error(`Invalid transformFunction provided: ${e.message}`);
38
+ }
39
+ try {
40
+ const result = func(input);
41
+ log(`[TransformNode] Transformation complete. Result: ${JSON.stringify(result).substring(0, 100)}...`, this.params.logging);
42
+ return result;
43
+ }
44
+ catch (e) {
45
+ throw new Error(`Error during transformation execution: ${e.message}`);
46
+ }
47
+ }
48
+ async postAsync(shared, prepRes, execRes) {
49
+ shared.transformedData = execRes;
50
+ return 'default';
51
+ }
52
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Prompts the user for input and waits for their response.
3
+ * @param {object} params - The parameters for the node.
4
+ * @param {string} params.prompt - The message to display to the user.
5
+ * @returns {Promise<string>} A promise that resolves to the user's input.
6
+ */
7
+ export class UserInputNode extends AsyncNode {
8
+ static getToolDefinition(): {
9
+ name: string;
10
+ description: string;
11
+ parameters: {
12
+ type: string;
13
+ properties: {
14
+ prompt: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ };
19
+ required: string[];
20
+ };
21
+ };
22
+ execAsync(): Promise<any>;
23
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
24
+ }
25
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,48 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import readline from 'readline';
3
+ /**
4
+ * Prompts the user for input and waits for their response.
5
+ * @param {object} params - The parameters for the node.
6
+ * @param {string} params.prompt - The message to display to the user.
7
+ * @returns {Promise<string>} A promise that resolves to the user's input.
8
+ */
9
+ export class UserInputNode extends AsyncNode {
10
+ static getToolDefinition() {
11
+ return {
12
+ name: "user_input",
13
+ description: "Prompts user for input.",
14
+ parameters: {
15
+ type: "object",
16
+ properties: {
17
+ prompt: {
18
+ type: "string",
19
+ description: "The message to display to the user."
20
+ }
21
+ },
22
+ required: ["prompt"]
23
+ }
24
+ };
25
+ }
26
+ async execAsync() {
27
+ const { prompt } = this.params;
28
+ if (!prompt) {
29
+ throw new Error('Missing required parameter: prompt');
30
+ }
31
+ const rl = readline.createInterface({
32
+ input: process.stdin,
33
+ output: process.stdout
34
+ });
35
+ return new Promise((resolve) => {
36
+ // ANSI escape codes for yellow text
37
+ const yellowPrompt = `\x1b[33m${prompt}\x1b[0m`;
38
+ rl.question(yellowPrompt, (answer) => {
39
+ rl.close();
40
+ resolve(answer);
41
+ });
42
+ });
43
+ }
44
+ async postAsync(shared, prepRes, execRes) {
45
+ shared.userInput = execRes;
46
+ return 'default';
47
+ }
48
+ }
@@ -0,0 +1,49 @@
1
+ export class WebHookNode extends AsyncNode {
2
+ static getToolDefinition(): {
3
+ name: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ port: {
9
+ type: string;
10
+ description: string;
11
+ };
12
+ path: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ flow: {
17
+ type: string;
18
+ description: string;
19
+ };
20
+ sharedSecret: {
21
+ type: string;
22
+ description: string;
23
+ };
24
+ responseStatus: {
25
+ type: string;
26
+ description: string;
27
+ };
28
+ responseBody: {
29
+ type: string;
30
+ description: string;
31
+ };
32
+ };
33
+ required: string[];
34
+ };
35
+ };
36
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | null;
37
+ flowToTrigger: AsyncFlow | null;
38
+ webhookPath: any;
39
+ sharedSecret: any;
40
+ execAsync(): Promise<{
41
+ status: string;
42
+ port: any;
43
+ path: any;
44
+ }>;
45
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
46
+ }
47
+ import { AsyncNode } from '../qflow.js';
48
+ import http from 'http';
49
+ import { AsyncFlow } from '../qflow.js';
@@ -0,0 +1,161 @@
1
+ import { AsyncNode, AsyncFlow } from '../qflow.js';
2
+ import http from 'http';
3
+ import { URL } from 'url'; // Node.js built-in
4
+ import crypto from 'crypto'; // Node.js built-in
5
+ import { log } from '../logger.js';
6
+ export class WebHookNode extends AsyncNode {
7
+ static getToolDefinition() {
8
+ return {
9
+ name: "webhook",
10
+ description: "Exposes an HTTP endpoint to receive webhooks, triggering a specified qflow flow.",
11
+ parameters: {
12
+ type: "object",
13
+ properties: {
14
+ port: {
15
+ type: "number",
16
+ description: "Optional. The port number to listen on. Defaults to 3000."
17
+ },
18
+ path: {
19
+ type: "string",
20
+ description: "Optional. The URL path for the webhook endpoint. Defaults to '/webhook'."
21
+ },
22
+ flow: {
23
+ type: "string", // This will be the name of a flow in the flowRegistry
24
+ description: "The name of the qflow AsyncFlow instance to trigger when a webhook is received."
25
+ },
26
+ sharedSecret: {
27
+ type: "string",
28
+ description: "Optional. A shared secret for HMAC verification of incoming webhooks."
29
+ },
30
+ responseStatus: {
31
+ type: "number",
32
+ description: "Optional. The HTTP status code to send back to the webhook sender. Defaults to 200."
33
+ },
34
+ responseBody: {
35
+ type: "object",
36
+ description: "Optional. The JSON body to send back to the webhook sender. Defaults to { status: 'received' }."
37
+ }
38
+ },
39
+ required: ["flow"]
40
+ }
41
+ };
42
+ }
43
+ constructor(maxRetries = 1, wait = 0) {
44
+ super(maxRetries, wait);
45
+ this.server = null;
46
+ this.flowToTrigger = null;
47
+ this.webhookPath = null;
48
+ this.sharedSecret = null;
49
+ }
50
+ async execAsync() {
51
+ const { port = 3000, // Port to listen on
52
+ path = '/webhook', // URL path for the webhook
53
+ flow, // The qflow AsyncFlow instance to trigger
54
+ sharedSecret, // Optional: for HMAC verification
55
+ responseStatus = 200, // HTTP status to send back
56
+ responseBody = { status: 'received' }, // HTTP body to send back
57
+ waitForFlow = false // Whether to wait for the flow to complete
58
+ } = this.params;
59
+ if (!flow || !(flow instanceof AsyncFlow)) {
60
+ throw new Error('WebHookNode requires a `flow` parameter of type AsyncFlow to trigger.');
61
+ }
62
+ this.flowToTrigger = flow;
63
+ this.webhookPath = path;
64
+ this.sharedSecret = sharedSecret;
65
+ // Ensure server is not already running
66
+ if (this.server && this.server.listening) {
67
+ log(`[WebHookNode] Server already listening on port ${port}. Reusing existing server.`, this.params.logging, { type: 'warn' });
68
+ return { status: 'server_already_running', port, path };
69
+ }
70
+ this.server = http.createServer(async (req, res) => {
71
+ const requestUrl = new URL(req.url, `http://${req.headers.host}`);
72
+ if (req.method === 'POST' && requestUrl.pathname === this.webhookPath) {
73
+ let body = '';
74
+ req.on('data', chunk => {
75
+ body += chunk.toString();
76
+ });
77
+ req.on('end', async () => {
78
+ let payload;
79
+ try {
80
+ payload = JSON.parse(body);
81
+ }
82
+ catch (e) {
83
+ log('[WebHookNode] Failed to parse webhook body as JSON:', this.params.logging, { type: 'error' });
84
+ res.writeHead(400, { 'Content-Type': 'application/json' });
85
+ res.end(JSON.stringify({ error: 'Invalid JSON payload' }));
86
+ return;
87
+ }
88
+ // --- Security: HMAC Verification (if sharedSecret is provided) ---
89
+ if (this.sharedSecret) {
90
+ const signature = req.headers['x-hub-signature-256'] || req.headers['x-webhook-signature']; // Common headers
91
+ if (!signature) {
92
+ log('[WebHookNode] Webhook received without signature, but sharedSecret is configured.', this.params.logging, { type: 'warn' });
93
+ res.writeHead(401, { 'Content-Type': 'application/json' });
94
+ res.end(JSON.stringify({ error: 'Missing signature' }));
95
+ return;
96
+ }
97
+ const hmac = crypto.createHmac('sha256', this.sharedSecret);
98
+ hmac.update(body);
99
+ const digest = `sha256=${hmac.digest('hex')}`; // Format might vary (e.g., 'v1=...')
100
+ if (digest !== signature) { // Simple comparison, real-world might need more robust parsing
101
+ log('[WebHookNode] Webhook signature mismatch. Request rejected.', this.params.logging, { type: 'warn' });
102
+ res.writeHead(403, { 'Content-Type': 'application/json' });
103
+ res.end(JSON.stringify({ error: 'Invalid signature' }));
104
+ return;
105
+ }
106
+ log('[WebHookNode] Webhook signature verified.', this.params.logging);
107
+ }
108
+ log(`[WebHookNode] Webhook received on ${this.webhookPath}. Triggering flow...`, this.params.logging);
109
+ const triggeredFlowShared = { webhook: { headers: req.headers, payload: payload, method: req.method, path: requestUrl.pathname } };
110
+ if (this.params.waitForFlow) {
111
+ try {
112
+ const flowResult = await this.flowToTrigger.runAsync(triggeredFlowShared);
113
+ log('[WebHookNode] Triggered flow completed successfully:', this.params.logging);
114
+ res.writeHead(this.params.responseStatus || 200, { 'Content-Type': 'application/json' });
115
+ res.end(JSON.stringify(flowResult));
116
+ }
117
+ catch (flowError) {
118
+ log('[WebHookNode] Triggered flow failed:', this.params.logging, { type: 'error' });
119
+ res.writeHead(500, { 'Content-Type': 'application/json' });
120
+ res.end(JSON.stringify({ error: 'Flow execution failed' }));
121
+ }
122
+ }
123
+ else {
124
+ this.flowToTrigger.runAsync(triggeredFlowShared)
125
+ .then(flowResult => {
126
+ log('[WebHookNode] Triggered flow completed successfully:', this.params.logging);
127
+ })
128
+ .catch(flowError => {
129
+ log('[WebHookNode] Triggered flow failed:', this.params.logging, { type: 'error' });
130
+ });
131
+ // Send response back to webhook sender
132
+ res.writeHead(this.params.responseStatus || 200, { 'Content-Type': 'application/json' });
133
+ res.end(JSON.stringify(this.params.responseBody || { status: 'received' }));
134
+ }
135
+ });
136
+ }
137
+ else {
138
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
139
+ res.end('Not Found');
140
+ }
141
+ });
142
+ await new Promise(resolve => {
143
+ this.server.listen(port, () => {
144
+ log(`[WebHookNode] Listening for webhooks on http://localhost:${port}${this.webhookPath}`, this.params.logging);
145
+ resolve();
146
+ });
147
+ });
148
+ // This node returns immediately after starting the server.
149
+ // The flow continues, and the server runs in the background.
150
+ return { status: 'listening', port, path: this.webhookPath };
151
+ }
152
+ // Cleanup: Ensure the server is closed when the node's flow completes or is cancelled
153
+ async postAsync(shared, prepRes, execRes) {
154
+ // For a long-running webhook listener, the server should NOT be closed here.
155
+ // The server is intended to run in the background.
156
+ // Cleanup (server.close()) should be handled by the application's shutdown logic
157
+ // or if the WebHookNode is explicitly stopped by another part of the flow.
158
+ // We will remove the automatic server closing here.
159
+ return execRes;
160
+ }
161
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Fetches the HTML content of a given URL.
3
+ * @param {object} params - The parameters for the node.
4
+ * @param {string} params.url - The URL to scrape.
5
+ * @returns {Promise<string>} A promise that resolves to the HTML content of the page.
6
+ */
7
+ export class ScrapeURLNode extends AsyncNode {
8
+ static getToolDefinition(): {
9
+ name: string;
10
+ description: string;
11
+ parameters: {
12
+ type: string;
13
+ properties: {
14
+ url: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ };
19
+ required: string[];
20
+ };
21
+ };
22
+ execAsync(): Promise<string>;
23
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
24
+ }
25
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,49 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import { log } from '../logger.js';
3
+ /**
4
+ * Fetches the HTML content of a given URL.
5
+ * @param {object} params - The parameters for the node.
6
+ * @param {string} params.url - The URL to scrape.
7
+ * @returns {Promise<string>} A promise that resolves to the HTML content of the page.
8
+ */
9
+ export class ScrapeURLNode extends AsyncNode {
10
+ static getToolDefinition() {
11
+ return {
12
+ name: "web_scraper",
13
+ description: "Fetches HTML content from a URL. Use with 'data_extractor' for specifics.",
14
+ parameters: {
15
+ type: "object",
16
+ properties: {
17
+ url: {
18
+ type: "string",
19
+ description: "The URL to scrape."
20
+ }
21
+ },
22
+ required: ["url"]
23
+ }
24
+ };
25
+ }
26
+ async execAsync() {
27
+ const { url } = this.params;
28
+ if (!url) {
29
+ throw new Error('URL is required for ScrapeURLNode.');
30
+ }
31
+ log(`[WebScraper] Scraping URL: ${url}...`, this.params.logging);
32
+ const response = await fetch(url);
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to fetch URL: ${response.status} - ${response.statusText}`);
35
+ }
36
+ const html = await response.text();
37
+ log(`[WebScraper] Successfully scraped URL: ${url}`, this.params.logging);
38
+ return html;
39
+ }
40
+ async postAsync(shared, prepRes, execRes) {
41
+ // Truncate the scraped HTML to avoid exceeding LLM context windows
42
+ const MAX_HTML_LENGTH = 4000;
43
+ shared.webScrapedContent = execRes.substring(0, MAX_HTML_LENGTH);
44
+ if (execRes.length > MAX_HTML_LENGTH) {
45
+ log(`[WebScraper] Truncated HTML content from ${execRes.length} to ${MAX_HTML_LENGTH} characters.`, this.params.logging, { type: 'warn' });
46
+ }
47
+ return shared.webScrapedContent;
48
+ }
49
+ }
@@ -0,0 +1,27 @@
1
+ export class WebSocketsNode extends AsyncNode {
2
+ static getToolDefinition(): {
3
+ name: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ action: {
9
+ type: string;
10
+ enum: string[];
11
+ description: string;
12
+ };
13
+ url: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ message: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ };
22
+ required: string[];
23
+ };
24
+ };
25
+ execAsync(prepRes: any, shared: any): Promise<any>;
26
+ }
27
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,98 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import WebSocket from 'ws';
3
+ export class WebSocketsNode extends AsyncNode {
4
+ static getToolDefinition() {
5
+ return {
6
+ name: "websockets",
7
+ description: "Establishes and manages WebSocket connections.",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ action: {
12
+ type: "string",
13
+ enum: ["connect", "send", "receive", "close"],
14
+ description: "The WebSocket action to perform."
15
+ },
16
+ url: {
17
+ type: "string",
18
+ description: "The URL of the WebSocket server (for 'connect' action)."
19
+ },
20
+ message: {
21
+ type: "string",
22
+ description: "The message to send to the server (for 'send' action)."
23
+ }
24
+ },
25
+ required: ["action"]
26
+ }
27
+ };
28
+ }
29
+ async execAsync(prepRes, shared) {
30
+ const { action, url, message, timeout = 5000, // 5-second timeout
31
+ } = this.params;
32
+ const connection = shared.webSocketConnection;
33
+ return new Promise(async (resolve, reject) => {
34
+ const timer = setTimeout(() => reject(new Error(`WebSocket action '${action}' timed out after ${timeout}ms`)), timeout);
35
+ try {
36
+ switch (action) {
37
+ case 'connect':
38
+ if (!url)
39
+ throw new Error('`url` parameter is required for `connect` action.');
40
+ const ws = new WebSocket(url);
41
+ ws.on('open', () => {
42
+ clearTimeout(timer);
43
+ shared.webSocketConnection = ws;
44
+ resolve({ message: `WebSocket connected to ${url}` });
45
+ });
46
+ ws.on('error', (err) => {
47
+ clearTimeout(timer);
48
+ reject(err);
49
+ });
50
+ break;
51
+ case 'send':
52
+ if (!connection)
53
+ throw new Error('No active WebSocket connection found.');
54
+ if (message === undefined)
55
+ throw new Error('`message` parameter is required for `send` action.');
56
+ const dataToSend = typeof message === 'object' ? JSON.stringify(message) : message;
57
+ connection.send(dataToSend);
58
+ clearTimeout(timer);
59
+ resolve({ message: 'Message sent' });
60
+ break;
61
+ case 'receive':
62
+ if (!connection)
63
+ throw new Error('No active WebSocket connection found.');
64
+ connection.once('message', (data) => {
65
+ clearTimeout(timer);
66
+ try {
67
+ // Try to parse as JSON, otherwise return as string
68
+ resolve(JSON.parse(data.toString()));
69
+ }
70
+ catch (e) {
71
+ resolve(data.toString());
72
+ }
73
+ });
74
+ connection.once('error', (err) => {
75
+ clearTimeout(timer);
76
+ reject(err);
77
+ });
78
+ break;
79
+ case 'close':
80
+ if (connection) {
81
+ connection.close();
82
+ delete shared.webSocketConnection;
83
+ }
84
+ clearTimeout(timer);
85
+ resolve({ message: 'WebSocket connection closed' });
86
+ break;
87
+ default:
88
+ clearTimeout(timer);
89
+ throw new Error(`Unsupported WebSocket action: ${action}`);
90
+ }
91
+ }
92
+ catch (error) {
93
+ clearTimeout(timer);
94
+ reject(error);
95
+ }
96
+ });
97
+ }
98
+ }