@fractal-solutions/qflow 1.0.62 → 1.0.63
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/package.json +1 -1
- package/dist/agent/agent.d.ts +0 -23
- package/dist/agent/agent.js +0 -365
- package/dist/agent/base_agent.d.ts +0 -21
- package/dist/agent/base_agent.js +0 -206
- package/dist/agent/logger.d.ts +0 -9
- package/dist/agent/logger.js +0 -45
- package/dist/agent/lpavrl_agent.d.ts +0 -5
- package/dist/agent/lpavrl_agent.js +0 -178
- package/dist/agent/ooda_agent.d.ts +0 -5
- package/dist/agent/ooda_agent.js +0 -167
- package/dist/agent/pema_agent.d.ts +0 -5
- package/dist/agent/pema_agent.js +0 -171
- package/dist/agent/raor_agent.d.ts +0 -5
- package/dist/agent/raor_agent.js +0 -164
- package/dist/agent/tools.d.ts +0 -5378
- package/dist/agent/tools.js +0 -1174
- package/dist/logger.d.ts +0 -9
- package/dist/logger.js +0 -107
- package/dist/nodes/agent_llm.d.ts +0 -31
- package/dist/nodes/agent_llm.js +0 -302
- package/dist/nodes/browser_control.d.ts +0 -4
- package/dist/nodes/browser_control.js +0 -73
- package/dist/nodes/code_interpreter.d.ts +0 -9
- package/dist/nodes/code_interpreter.js +0 -121
- package/dist/nodes/data_extractor.d.ts +0 -5
- package/dist/nodes/data_extractor.js +0 -81
- package/dist/nodes/data_validation.d.ts +0 -9
- package/dist/nodes/data_validation.js +0 -48
- package/dist/nodes/database.d.ts +0 -6
- package/dist/nodes/database.js +0 -89
- package/dist/nodes/display_image.d.ts +0 -4
- package/dist/nodes/display_image.js +0 -47
- package/dist/nodes/embedding.d.ts +0 -7
- package/dist/nodes/embedding.js +0 -45
- package/dist/nodes/filesystem.d.ts +0 -41
- package/dist/nodes/filesystem.js +0 -88
- package/dist/nodes/gis.d.ts +0 -37
- package/dist/nodes/gis.js +0 -106
- package/dist/nodes/git.d.ts +0 -4
- package/dist/nodes/git.js +0 -55
- package/dist/nodes/github.d.ts +0 -27
- package/dist/nodes/github.js +0 -75
- package/dist/nodes/hackernews.d.ts +0 -19
- package/dist/nodes/hackernews.js +0 -47
- package/dist/nodes/hardware_interaction.d.ts +0 -8
- package/dist/nodes/hardware_interaction.js +0 -98
- package/dist/nodes/http.d.ts +0 -26
- package/dist/nodes/http.js +0 -67
- package/dist/nodes/http_server.d.ts +0 -17
- package/dist/nodes/http_server.js +0 -190
- package/dist/nodes/image_gallery.d.ts +0 -8
- package/dist/nodes/image_gallery.js +0 -100
- package/dist/nodes/index.d.ts +0 -48
- package/dist/nodes/index.js +0 -48
- package/dist/nodes/interactive_input.d.ts +0 -4
- package/dist/nodes/interactive_input.js +0 -71
- package/dist/nodes/interactive_webview.d.ts +0 -19
- package/dist/nodes/interactive_webview.js +0 -310
- package/dist/nodes/iterator.d.ts +0 -5
- package/dist/nodes/iterator.js +0 -23
- package/dist/nodes/llm.d.ts +0 -18
- package/dist/nodes/llm.js +0 -215
- package/dist/nodes/memory.d.ts +0 -12
- package/dist/nodes/memory.js +0 -48
- package/dist/nodes/multimedia_processing.d.ts +0 -10
- package/dist/nodes/multimedia_processing.js +0 -80
- package/dist/nodes/openrouter_llm.d.ts +0 -8
- package/dist/nodes/openrouter_llm.js +0 -124
- package/dist/nodes/pdf_processor.d.ts +0 -4
- package/dist/nodes/pdf_processor.js +0 -75
- package/dist/nodes/remote_execution.d.ts +0 -4
- package/dist/nodes/remote_execution.js +0 -83
- package/dist/nodes/s3.d.ts +0 -6
- package/dist/nodes/s3.js +0 -38
- package/dist/nodes/scheduler.d.ts +0 -20
- package/dist/nodes/scheduler.js +0 -98
- package/dist/nodes/search.d.ts +0 -25
- package/dist/nodes/search.js +0 -78
- package/dist/nodes/semantic_memory.d.ts +0 -17
- package/dist/nodes/semantic_memory.js +0 -111
- package/dist/nodes/shell.d.ts +0 -11
- package/dist/nodes/shell.js +0 -29
- package/dist/nodes/speech_synthesis.d.ts +0 -45
- package/dist/nodes/speech_synthesis.js +0 -142
- package/dist/nodes/spreadsheet.d.ts +0 -10
- package/dist/nodes/spreadsheet.js +0 -241
- package/dist/nodes/stripe.d.ts +0 -23
- package/dist/nodes/stripe.js +0 -69
- package/dist/nodes/subflow.d.ts +0 -5
- package/dist/nodes/subflow.js +0 -16
- package/dist/nodes/summarize.d.ts +0 -12
- package/dist/nodes/summarize.js +0 -31
- package/dist/nodes/system_notification.d.ts +0 -4
- package/dist/nodes/system_notification.js +0 -50
- package/dist/nodes/transform.d.ts +0 -5
- package/dist/nodes/transform.js +0 -32
- package/dist/nodes/user.d.ts +0 -11
- package/dist/nodes/user.js +0 -32
- package/dist/nodes/webhook.d.ts +0 -15
- package/dist/nodes/webhook.js +0 -125
- package/dist/nodes/webscraper.d.ts +0 -11
- package/dist/nodes/webscraper.js +0 -33
- package/dist/nodes/websockets.d.ts +0 -4
- package/dist/nodes/websockets.js +0 -73
- package/dist/nodes/webview.d.ts +0 -12
- package/dist/nodes/webview.js +0 -27
- package/dist/qflow.d.ts +0 -69
- package/dist/qflow.js +0 -320
package/dist/nodes/git.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import simpleGit from 'simple-git';
|
|
3
|
-
export class GitNode extends AsyncNode {
|
|
4
|
-
async execAsync() {
|
|
5
|
-
const { action, repoPath, remoteUrl, files, message, branch, remote = 'origin', } = this.params;
|
|
6
|
-
if (!repoPath && action !== 'clone') {
|
|
7
|
-
throw new Error('GitNode requires a `repoPath` for all actions except `clone`.');
|
|
8
|
-
}
|
|
9
|
-
const git = simpleGit(repoPath);
|
|
10
|
-
let result = {};
|
|
11
|
-
switch (action) {
|
|
12
|
-
case 'clone':
|
|
13
|
-
if (!remoteUrl || !repoPath)
|
|
14
|
-
throw new Error('`remoteUrl` and `repoPath` are required for `clone`.');
|
|
15
|
-
await git.clone(remoteUrl, repoPath);
|
|
16
|
-
result = { message: `Repository cloned from ${remoteUrl} to ${repoPath}` };
|
|
17
|
-
break;
|
|
18
|
-
case 'init':
|
|
19
|
-
await git.init();
|
|
20
|
-
result = { message: `Initialized empty Git repository in ${repoPath}` };
|
|
21
|
-
break;
|
|
22
|
-
case 'add':
|
|
23
|
-
if (!files)
|
|
24
|
-
throw new Error('`files` parameter is required for `add` action.');
|
|
25
|
-
await git.add(files);
|
|
26
|
-
result = { message: `Files added: ${files.join(', ')}` };
|
|
27
|
-
break;
|
|
28
|
-
case 'commit':
|
|
29
|
-
if (!message)
|
|
30
|
-
throw new Error('`message` parameter is required for `commit` action.');
|
|
31
|
-
const commitResult = await git.commit(message);
|
|
32
|
-
result = { message: 'Commit successful', ...commitResult };
|
|
33
|
-
break;
|
|
34
|
-
case 'push':
|
|
35
|
-
if (!branch)
|
|
36
|
-
throw new Error('`branch` parameter is required for `push` action.');
|
|
37
|
-
await git.push(remote, branch);
|
|
38
|
-
result = { message: `Pushed to ${remote}/${branch}` };
|
|
39
|
-
break;
|
|
40
|
-
case 'pull':
|
|
41
|
-
if (!branch)
|
|
42
|
-
throw new Error('`branch` parameter is required for `pull` action.');
|
|
43
|
-
await git.pull(remote, branch);
|
|
44
|
-
result = { message: `Pulled from ${remote}/${branch}` };
|
|
45
|
-
break;
|
|
46
|
-
case 'status':
|
|
47
|
-
const statusResult = await git.status();
|
|
48
|
-
result = statusResult;
|
|
49
|
-
break;
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(`Unsupported Git action: ${action}`);
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
}
|
package/dist/nodes/github.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a new issue in a GitHub repository.
|
|
3
|
-
* @param {object} params - The parameters for the node.
|
|
4
|
-
* @param {string} params.token - The GitHub personal access token.
|
|
5
|
-
* @param {string} params.owner - The owner of the repository.
|
|
6
|
-
* @param {string} params.repo - The name of the repository.
|
|
7
|
-
* @param {string} params.title - The title of the issue.
|
|
8
|
-
* @param {string} [params.body] - The body of the issue.
|
|
9
|
-
* @returns {Promise<object>} A promise that resolves to the created issue object.
|
|
10
|
-
*/
|
|
11
|
-
export class CreateIssueNode extends AsyncNode {
|
|
12
|
-
execAsync(): Promise<unknown>;
|
|
13
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves an issue from a GitHub repository.
|
|
17
|
-
* @param {object} params - The parameters for the node.
|
|
18
|
-
* @param {string} params.token - The GitHub personal access token.
|
|
19
|
-
* @param {string} params.owner - The owner of the repository.
|
|
20
|
-
* @param {string} params.repo - The name of the repository.
|
|
21
|
-
* @param {number} params.issue_number - The number of the issue to retrieve.
|
|
22
|
-
* @returns {Promise<object>} A promise that resolves to the issue object.
|
|
23
|
-
*/
|
|
24
|
-
export class GetIssueNode extends AsyncNode {
|
|
25
|
-
execAsync(): Promise<unknown>;
|
|
26
|
-
}
|
|
27
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/github.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { log } from '../logger.js';
|
|
3
|
-
const API_BASE = 'https://api.github.com';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a new issue in a GitHub repository.
|
|
6
|
-
* @param {object} params - The parameters for the node.
|
|
7
|
-
* @param {string} params.token - The GitHub personal access token.
|
|
8
|
-
* @param {string} params.owner - The owner of the repository.
|
|
9
|
-
* @param {string} params.repo - The name of the repository.
|
|
10
|
-
* @param {string} params.title - The title of the issue.
|
|
11
|
-
* @param {string} [params.body] - The body of the issue.
|
|
12
|
-
* @returns {Promise<object>} A promise that resolves to the created issue object.
|
|
13
|
-
*/
|
|
14
|
-
export class CreateIssueNode extends AsyncNode {
|
|
15
|
-
async execAsync() {
|
|
16
|
-
const { token, owner, repo, title, body } = this.params;
|
|
17
|
-
if (!token || !owner || !repo || !title) {
|
|
18
|
-
throw new Error('Missing required parameters: token, owner, repo, title');
|
|
19
|
-
}
|
|
20
|
-
log(`[GitHub] Creating issue "${title}" in ${owner}/${repo}...`, this.params.logging);
|
|
21
|
-
const response = await fetch(`${API_BASE}/repos/${owner}/${repo}/issues`, {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: {
|
|
24
|
-
'Authorization': `token ${token}`,
|
|
25
|
-
'Content-Type': 'application/json'
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({ title, body })
|
|
28
|
-
});
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
const errorData = await response.json();
|
|
31
|
-
throw new Error(`GitHub API error: ${response.status} - ${errorData.message}`);
|
|
32
|
-
}
|
|
33
|
-
const issue = await response.json();
|
|
34
|
-
log(`[GitHub] Successfully created issue #${issue.number}`, this.params.logging);
|
|
35
|
-
return issue;
|
|
36
|
-
}
|
|
37
|
-
async postAsync(shared, prepRes, execRes) {
|
|
38
|
-
shared.createdIssue = execRes; // Put the result in the shared object
|
|
39
|
-
return 'default'; // Return an action to transition
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves an issue from a GitHub repository.
|
|
44
|
-
* @param {object} params - The parameters for the node.
|
|
45
|
-
* @param {string} params.token - The GitHub personal access token.
|
|
46
|
-
* @param {string} params.owner - The owner of the repository.
|
|
47
|
-
* @param {string} params.repo - The name of the repository.
|
|
48
|
-
* @param {number} params.issue_number - The number of the issue to retrieve.
|
|
49
|
-
* @returns {Promise<object>} A promise that resolves to the issue object.
|
|
50
|
-
*/
|
|
51
|
-
export class GetIssueNode extends AsyncNode {
|
|
52
|
-
async prepAsync(shared) {
|
|
53
|
-
// Retrieve the issue number from the shared object
|
|
54
|
-
this.params.issue_number = shared.createdIssue?.number;
|
|
55
|
-
}
|
|
56
|
-
async execAsync() {
|
|
57
|
-
const { token, owner, repo, issue_number } = this.params;
|
|
58
|
-
if (!token || !owner || !repo || !issue_number) {
|
|
59
|
-
throw new Error('Missing required parameters: token, owner, repo, issue_number');
|
|
60
|
-
}
|
|
61
|
-
log(`[GitHub] Getting issue #${issue_number} from ${owner}/${repo}...`, this.params.logging);
|
|
62
|
-
const response = await fetch(`${API_BASE}/repos/${owner}/${repo}/issues/${issue_number}`, {
|
|
63
|
-
headers: {
|
|
64
|
-
'Authorization': `token ${token}`
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
if (!response.ok) {
|
|
68
|
-
const errorData = await response.json();
|
|
69
|
-
throw new Error(`GitHub API error: ${response.status} - ${errorData.message}`);
|
|
70
|
-
}
|
|
71
|
-
const issue = await response.json();
|
|
72
|
-
log(`[GitHub] Successfully retrieved issue #${issue.number}`, this.params.logging);
|
|
73
|
-
return issue;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fetches the top story IDs from the Hacker News API.
|
|
3
|
-
* @param {object} params - The parameters for the node.
|
|
4
|
-
* @param {number} [params.limit=10] - The maximum number of story IDs to return.
|
|
5
|
-
* @returns {Promise<number[]>} A promise that resolves to an array of story IDs.
|
|
6
|
-
*/
|
|
7
|
-
export class GetTopStoriesNode extends AsyncNode {
|
|
8
|
-
execAsync(prepRes: any, shared: any): Promise<string>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Fetches the details of a specific item from the Hacker News API.
|
|
12
|
-
* @param {object} params - The parameters for the node.
|
|
13
|
-
* @param {number} params.id - The ID of the item to fetch.
|
|
14
|
-
* @returns {Promise<object>} A promise that resolves to the item details.
|
|
15
|
-
*/
|
|
16
|
-
export class GetItemNode extends AsyncNode {
|
|
17
|
-
execAsync(): Promise<unknown>;
|
|
18
|
-
}
|
|
19
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/hackernews.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { log } from '../logger.js';
|
|
3
|
-
const API_BASE = 'https://hacker-news.firebaseio.com/v0';
|
|
4
|
-
/**
|
|
5
|
-
* Fetches the top story IDs from the Hacker News API.
|
|
6
|
-
* @param {object} params - The parameters for the node.
|
|
7
|
-
* @param {number} [params.limit=10] - The maximum number of story IDs to return.
|
|
8
|
-
* @returns {Promise<number[]>} A promise that resolves to an array of story IDs.
|
|
9
|
-
*/
|
|
10
|
-
export class GetTopStoriesNode extends AsyncNode {
|
|
11
|
-
async execAsync(prepRes, shared) {
|
|
12
|
-
const { limit = 10 } = this.params;
|
|
13
|
-
log(`[HackerNews] Fetching top ${limit} stories...`, this.params.logging);
|
|
14
|
-
const response = await fetch(`${API_BASE}/topstories.json`);
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
throw new Error(`Hacker News API error: ${response.status}`);
|
|
17
|
-
}
|
|
18
|
-
const storyIds = await response.json();
|
|
19
|
-
const limitedIds = storyIds.slice(0, limit);
|
|
20
|
-
log(`[HackerNews] Found ${limitedIds.length} stories.`, this.params.logging);
|
|
21
|
-
shared.storyIds = limitedIds;
|
|
22
|
-
return 'default';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Fetches the details of a specific item from the Hacker News API.
|
|
27
|
-
* @param {object} params - The parameters for the node.
|
|
28
|
-
* @param {number} params.id - The ID of the item to fetch.
|
|
29
|
-
* @returns {Promise<object>} A promise that resolves to the item details.
|
|
30
|
-
*/
|
|
31
|
-
export class GetItemNode extends AsyncNode {
|
|
32
|
-
async execAsync() {
|
|
33
|
-
const { id } = this.params;
|
|
34
|
-
if (!id) {
|
|
35
|
-
throw new Error('Item ID is required for GetItemNode.');
|
|
36
|
-
}
|
|
37
|
-
log(`[HackerNews] Fetching item ${id}...`, this.params.logging);
|
|
38
|
-
const response = await fetch(`${API_BASE}/item/${id}.json`);
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
throw new Error(`Hacker News API error: ${response.status}`);
|
|
41
|
-
}
|
|
42
|
-
const item = await response.json();
|
|
43
|
-
log(`[HackerNews] Fetched item title: ${item.title}`, this.params.logging);
|
|
44
|
-
log(`[HackerNews] Fetched item: ${item.url}`, this.params.logging);
|
|
45
|
-
return item;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export class HardwareInteractionNode extends AsyncNode {
|
|
2
|
-
port: SerialPort<any> | null;
|
|
3
|
-
parser: ReadlineParser | null;
|
|
4
|
-
execAsync(): Promise<any>;
|
|
5
|
-
}
|
|
6
|
-
import { AsyncNode } from '../qflow.js';
|
|
7
|
-
import { SerialPort } from 'serialport';
|
|
8
|
-
import { ReadlineParser } from '@serialport/parser-readline';
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
// You would need to install the 'serialport' library: npm install serialport
|
|
3
|
-
import { SerialPort } from 'serialport';
|
|
4
|
-
import { ReadlineParser } from '@serialport/parser-readline'; // For reading line-by-line
|
|
5
|
-
import { log } from '../logger.js';
|
|
6
|
-
export class HardwareInteractionNode extends AsyncNode {
|
|
7
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
8
|
-
super(maxRetries, wait);
|
|
9
|
-
this.port = null;
|
|
10
|
-
this.parser = null;
|
|
11
|
-
}
|
|
12
|
-
async execAsync() {
|
|
13
|
-
const { portPath, // e.g., '/dev/ttyUSB0' on Linux, 'COM1' on Windows
|
|
14
|
-
baudRate = 9600, action, // 'write', 'read_line', 'list_ports'
|
|
15
|
-
dataToWrite, // For 'write' action
|
|
16
|
-
timeout = 5000 // For 'read_line' action
|
|
17
|
-
} = this.params;
|
|
18
|
-
if (!action || !['write', 'read_line', 'list_ports'].includes(action)) {
|
|
19
|
-
throw new Error('HardwareInteractionNode requires an `action`: "write", "read_line", or "list_ports".');
|
|
20
|
-
}
|
|
21
|
-
let result;
|
|
22
|
-
switch (action) {
|
|
23
|
-
case 'list_ports':
|
|
24
|
-
// List available serial ports
|
|
25
|
-
try {
|
|
26
|
-
const ports = await SerialPort.list();
|
|
27
|
-
result = ports.map(p => ({
|
|
28
|
-
path: p.path,
|
|
29
|
-
manufacturer: p.manufacturer,
|
|
30
|
-
serialNumber: p.serialNumber,
|
|
31
|
-
pnpId: p.pnpId,
|
|
32
|
-
productId: p.productId,
|
|
33
|
-
vendorId: p.vendorId,
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
throw new Error(`Failed to list serial ports: ${e.message}`);
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
case 'write':
|
|
41
|
-
case 'read_line':
|
|
42
|
-
if (!portPath) {
|
|
43
|
-
throw new Error('For "write" or "read_line" action, `portPath` is required.');
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
this.port = new SerialPort({ path: portPath, baudRate: baudRate });
|
|
47
|
-
await new Promise((resolve, reject) => {
|
|
48
|
-
this.port.on('open', resolve);
|
|
49
|
-
this.port.on('error', reject);
|
|
50
|
-
});
|
|
51
|
-
log(`[HardwareInteractionNode] Serial port ${portPath} opened.`, this.params.logging);
|
|
52
|
-
if (action === 'write') {
|
|
53
|
-
if (dataToWrite === undefined) {
|
|
54
|
-
throw new Error('Write action requires `dataToWrite`.');
|
|
55
|
-
}
|
|
56
|
-
await new Promise((resolve, reject) => {
|
|
57
|
-
this.port.write(dataToWrite, (err) => {
|
|
58
|
-
if (err)
|
|
59
|
-
reject(err);
|
|
60
|
-
else
|
|
61
|
-
resolve();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
result = { status: 'data_written', data: dataToWrite };
|
|
65
|
-
}
|
|
66
|
-
else if (action === 'read_line') {
|
|
67
|
-
this.parser = this.port.pipe(new ReadlineParser({ delimiter: '\n' }));
|
|
68
|
-
result = await new Promise((resolve, reject) => {
|
|
69
|
-
const timer = setTimeout(() => {
|
|
70
|
-
reject(new Error(`Timeout waiting for data on ${portPath}`));
|
|
71
|
-
}, timeout);
|
|
72
|
-
this.parser.on('data', (line) => {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
resolve(line.trim());
|
|
75
|
-
});
|
|
76
|
-
this.port.on('error', (err) => {
|
|
77
|
-
clearTimeout(timer);
|
|
78
|
-
reject(err);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (e) {
|
|
84
|
-
throw new Error(`Serial port operation failed: ${e.message}. Check portPath, baudRate, and permissions.`);
|
|
85
|
-
}
|
|
86
|
-
finally {
|
|
87
|
-
if (this.port && this.port.isOpen) {
|
|
88
|
-
await new Promise(resolve => this.port.close(resolve));
|
|
89
|
-
log(`[HardwareInteractionNode] Serial port ${portPath} closed.`, this.params.logging);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
default:
|
|
94
|
-
throw new Error(`Unsupported action: ${action}`);
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
}
|
package/dist/nodes/http.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A flexible node for making generic HTTP requests to any REST API.
|
|
3
|
-
* @param {object} params - The parameters for the node.
|
|
4
|
-
* @param {string} params.url - The full URL of the API endpoint.
|
|
5
|
-
* @param {string} [params.method='GET'] - The HTTP method (e.g., 'POST', 'PUT', 'DELETE').
|
|
6
|
-
* @param {object} [params.headers] - Custom headers for the request.
|
|
7
|
-
* @param {*} [params.body] - The request payload. If it's an object, it will be stringified as JSON.
|
|
8
|
-
* @param {object} [params.auth] - Authentication configuration.
|
|
9
|
-
* @param {'bearer'|'basic'} [params.auth.type] - The type of authentication.
|
|
10
|
-
* @param {string} [params.auth.token] - The bearer token.
|
|
11
|
-
* @param {string} [params.auth.username] - The username for basic auth.
|
|
12
|
-
* @param {string} [params.auth.password] - The password for basic auth.
|
|
13
|
-
* @returns {Promise<object>} A promise that resolves to a structured object containing the status, headers, and body of the response.
|
|
14
|
-
*/
|
|
15
|
-
export class HttpRequestNode extends AsyncNode {
|
|
16
|
-
execAsync(): Promise<{
|
|
17
|
-
status: number;
|
|
18
|
-
headers: {
|
|
19
|
-
[k: string]: string;
|
|
20
|
-
};
|
|
21
|
-
body: any;
|
|
22
|
-
}>;
|
|
23
|
-
parseResponseBody(response: any): Promise<any>;
|
|
24
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
25
|
-
}
|
|
26
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/http.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { log } from '../logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* A flexible node for making generic HTTP requests to any REST API.
|
|
5
|
-
* @param {object} params - The parameters for the node.
|
|
6
|
-
* @param {string} params.url - The full URL of the API endpoint.
|
|
7
|
-
* @param {string} [params.method='GET'] - The HTTP method (e.g., 'POST', 'PUT', 'DELETE').
|
|
8
|
-
* @param {object} [params.headers] - Custom headers for the request.
|
|
9
|
-
* @param {*} [params.body] - The request payload. If it's an object, it will be stringified as JSON.
|
|
10
|
-
* @param {object} [params.auth] - Authentication configuration.
|
|
11
|
-
* @param {'bearer'|'basic'} [params.auth.type] - The type of authentication.
|
|
12
|
-
* @param {string} [params.auth.token] - The bearer token.
|
|
13
|
-
* @param {string} [params.auth.username] - The username for basic auth.
|
|
14
|
-
* @param {string} [params.auth.password] - The password for basic auth.
|
|
15
|
-
* @returns {Promise<object>} A promise that resolves to a structured object containing the status, headers, and body of the response.
|
|
16
|
-
*/
|
|
17
|
-
export class HttpRequestNode extends AsyncNode {
|
|
18
|
-
async execAsync() {
|
|
19
|
-
const { url, method = 'GET', headers = {}, body, auth } = this.params;
|
|
20
|
-
if (!url) {
|
|
21
|
-
throw new Error('HttpRequestNode requires a `url` parameter.');
|
|
22
|
-
}
|
|
23
|
-
const fetchOptions = {
|
|
24
|
-
method,
|
|
25
|
-
headers: { ...headers }, // Create a mutable copy
|
|
26
|
-
};
|
|
27
|
-
// Handle Authentication
|
|
28
|
-
if (auth) {
|
|
29
|
-
if (auth.type === 'bearer' && auth.token) {
|
|
30
|
-
fetchOptions.headers['Authorization'] = `Bearer ${auth.token}`;
|
|
31
|
-
}
|
|
32
|
-
else if (auth.type === 'basic' && auth.username && auth.password) {
|
|
33
|
-
const credentials = btoa(`${auth.username}:${auth.password}`);
|
|
34
|
-
fetchOptions.headers['Authorization'] = `Basic ${credentials}`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Handle Body
|
|
38
|
-
if (body) {
|
|
39
|
-
if (typeof body === 'object' && !fetchOptions.headers['Content-Type']) {
|
|
40
|
-
fetchOptions.headers['Content-Type'] = 'application/json';
|
|
41
|
-
fetchOptions.body = JSON.stringify(body);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
fetchOptions.body = body;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
log(`[HTTP] ${method} ${url}`, this.params.logging);
|
|
48
|
-
const response = await fetch(url, fetchOptions);
|
|
49
|
-
const responseBody = await this.parseResponseBody(response);
|
|
50
|
-
return {
|
|
51
|
-
status: response.status,
|
|
52
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
53
|
-
body: responseBody,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async parseResponseBody(response) {
|
|
57
|
-
const contentType = response.headers.get('content-type') || '';
|
|
58
|
-
if (contentType.includes('application/json')) {
|
|
59
|
-
return await response.json();
|
|
60
|
-
}
|
|
61
|
-
return await response.text();
|
|
62
|
-
}
|
|
63
|
-
async postAsync(shared, prepRes, execRes) {
|
|
64
|
-
shared.httpResult = execRes;
|
|
65
|
-
return 'default';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class HttpServerNode extends AsyncNode {
|
|
2
|
-
constructor();
|
|
3
|
-
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | null;
|
|
4
|
-
findMatchingRoute(routes: any, method: any, path: any): {
|
|
5
|
-
flow: any;
|
|
6
|
-
params: {};
|
|
7
|
-
} | null;
|
|
8
|
-
handleStatic(staticDir: any, reqPath: any, res: any): Promise<boolean>;
|
|
9
|
-
applyCorsHeaders(res: any, corsConfig: any): void;
|
|
10
|
-
execAsync(): Promise<{
|
|
11
|
-
status: string;
|
|
12
|
-
port: any;
|
|
13
|
-
}>;
|
|
14
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
15
|
-
}
|
|
16
|
-
import { AsyncNode } from '../qflow.js';
|
|
17
|
-
import http from 'http';
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import { URL } from 'url';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { promises as fsPromises } from 'fs';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import { log } from '../logger.js';
|
|
8
|
-
// Basic mime-type lookup to avoid adding new dependencies
|
|
9
|
-
function getMimeType(filePath) {
|
|
10
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
11
|
-
const types = {
|
|
12
|
-
'.html': 'text/html',
|
|
13
|
-
'.css': 'text/css',
|
|
14
|
-
'.js': 'application/javascript',
|
|
15
|
-
'.json': 'application/json',
|
|
16
|
-
'.png': 'image/png',
|
|
17
|
-
'.jpg': 'image/jpeg',
|
|
18
|
-
'.jpeg': 'image/jpeg',
|
|
19
|
-
'.gif': 'image/gif',
|
|
20
|
-
'.svg': 'image/svg+xml',
|
|
21
|
-
'.txt': 'text/plain',
|
|
22
|
-
};
|
|
23
|
-
return types[ext] || 'application/octet-stream';
|
|
24
|
-
}
|
|
25
|
-
export class HttpServerNode extends AsyncNode {
|
|
26
|
-
constructor() {
|
|
27
|
-
super();
|
|
28
|
-
this.server = null;
|
|
29
|
-
}
|
|
30
|
-
// Helper to find a matching route and extract params
|
|
31
|
-
findMatchingRoute(routes, method, path) {
|
|
32
|
-
for (const routePath in routes) {
|
|
33
|
-
const routeHandlers = routes[routePath];
|
|
34
|
-
const paramNames = [];
|
|
35
|
-
// Convert route path to regex, e.g., /users/:id -> /users/([^/]+)
|
|
36
|
-
const regexPath = routePath.replace(/:(\w+)/g, (_, paramName) => {
|
|
37
|
-
paramNames.push(paramName);
|
|
38
|
-
return '([^/]+)';
|
|
39
|
-
});
|
|
40
|
-
const regex = new RegExp(`^${regexPath}$`);
|
|
41
|
-
const match = path.match(regex);
|
|
42
|
-
if (match) {
|
|
43
|
-
const handler = routeHandlers[method.toUpperCase()];
|
|
44
|
-
if (handler) {
|
|
45
|
-
const params = {};
|
|
46
|
-
paramNames.forEach((name, index) => {
|
|
47
|
-
params[name] = match[index + 1];
|
|
48
|
-
});
|
|
49
|
-
return { flow: handler, params };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
// Helper to serve static files
|
|
56
|
-
async handleStatic(staticDir, reqPath, res) {
|
|
57
|
-
if (!staticDir)
|
|
58
|
-
return false;
|
|
59
|
-
// Prevent directory traversal attacks
|
|
60
|
-
const safePath = path.normalize(reqPath).replace(/^(\.\.[\/\\])+/, '');
|
|
61
|
-
const filePath = path.join(staticDir, safePath);
|
|
62
|
-
try {
|
|
63
|
-
const stats = await fsPromises.stat(filePath);
|
|
64
|
-
if (stats.isFile()) {
|
|
65
|
-
const mimeType = getMimeType(filePath);
|
|
66
|
-
res.writeHead(200, { 'Content-Type': mimeType });
|
|
67
|
-
// Create a read stream and pipe it to the response
|
|
68
|
-
const fileStream = fs.createReadStream(filePath);
|
|
69
|
-
fileStream.pipe(res);
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
// File doesn't exist, fall through to dynamic routing
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
// Helper to apply CORS headers
|
|
79
|
-
applyCorsHeaders(res, corsConfig) {
|
|
80
|
-
if (!corsConfig)
|
|
81
|
-
return;
|
|
82
|
-
if (corsConfig.origin) {
|
|
83
|
-
res.setHeader('Access-Control-Allow-Origin', corsConfig.origin);
|
|
84
|
-
}
|
|
85
|
-
if (corsConfig.methods) {
|
|
86
|
-
res.setHeader('Access-Control-Allow-Methods', corsConfig.methods);
|
|
87
|
-
}
|
|
88
|
-
if (corsConfig.headers) {
|
|
89
|
-
res.setHeader('Access-Control-Allow-Headers', corsConfig.headers);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async execAsync() {
|
|
93
|
-
const { port = 3000, routes = {}, staticDir, cors } = this.params;
|
|
94
|
-
if (this.server && this.server.listening) {
|
|
95
|
-
log(`[HttpServerNode] Server already listening on port ${port}.`, this.params.logging, { type: 'warn' });
|
|
96
|
-
return { status: 'server_already_running', port };
|
|
97
|
-
}
|
|
98
|
-
this.server = http.createServer(async (req, res) => {
|
|
99
|
-
// Apply CORS headers to all responses
|
|
100
|
-
this.applyCorsHeaders(res, cors);
|
|
101
|
-
// Handle CORS pre-flight OPTIONS request
|
|
102
|
-
if (cors && req.method === 'OPTIONS') {
|
|
103
|
-
res.writeHead(204); // No Content
|
|
104
|
-
res.end();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const requestUrl = new URL(req.url, `http://${req.headers.host}`);
|
|
108
|
-
const reqPath = requestUrl.pathname;
|
|
109
|
-
// 1. Try to serve static file
|
|
110
|
-
if (staticDir) {
|
|
111
|
-
const served = await this.handleStatic(staticDir, reqPath, res);
|
|
112
|
-
if (served)
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
// 2. Find a matching dynamic route
|
|
116
|
-
const routeMatch = this.findMatchingRoute(routes, req.method, reqPath);
|
|
117
|
-
if (!routeMatch) {
|
|
118
|
-
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
119
|
-
res.end(JSON.stringify({ error: 'Not Found' }));
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const { flow, params: pathParams } = routeMatch;
|
|
123
|
-
if (!(flow instanceof AsyncFlow)) {
|
|
124
|
-
log(`[HttpServerNode] Handler for ${req.method} ${reqPath} is not an AsyncFlow.`, this.params.logging, { type: 'error' });
|
|
125
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
126
|
-
res.end(JSON.stringify({ error: 'Internal Server Error: Invalid handler' }));
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// 3. Process request body and trigger flow
|
|
130
|
-
let body = '';
|
|
131
|
-
req.on('data', chunk => { body += chunk.toString(); });
|
|
132
|
-
req.on('end', async () => {
|
|
133
|
-
let payload;
|
|
134
|
-
if (body) {
|
|
135
|
-
try {
|
|
136
|
-
payload = JSON.parse(body);
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
payload = body; // Not JSON, treat as raw string
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const requestContext = {
|
|
143
|
-
headers: req.headers,
|
|
144
|
-
body: payload,
|
|
145
|
-
method: req.method,
|
|
146
|
-
path: reqPath,
|
|
147
|
-
query: Object.fromEntries(requestUrl.searchParams),
|
|
148
|
-
params: pathParams
|
|
149
|
-
};
|
|
150
|
-
try {
|
|
151
|
-
const flowResult = await flow.runAsync({ request: requestContext });
|
|
152
|
-
const response = flowResult || { statusCode: 204, body: '' };
|
|
153
|
-
const statusCode = response.statusCode || 200;
|
|
154
|
-
const headers = response.headers || {};
|
|
155
|
-
let responseBody = response.body;
|
|
156
|
-
if (typeof responseBody === 'object' && !(responseBody instanceof Buffer)) {
|
|
157
|
-
responseBody = JSON.stringify(responseBody);
|
|
158
|
-
if (!headers['Content-Type']) {
|
|
159
|
-
headers['Content-Type'] = 'application/json';
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
res.writeHead(statusCode, headers);
|
|
163
|
-
res.end(responseBody);
|
|
164
|
-
}
|
|
165
|
-
catch (flowError) {
|
|
166
|
-
log(`[HttpServerNode] Flow for ${req.method} ${reqPath} failed:`, this.params.logging, { type: 'error' });
|
|
167
|
-
if (!res.writableEnded) {
|
|
168
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
169
|
-
res.end(JSON.stringify({ error: 'Flow execution failed', details: flowError.message }));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
await new Promise((resolve, reject) => {
|
|
175
|
-
this.server.on('error', (err) => {
|
|
176
|
-
log(`[HttpServerNode] Failed to start server on port ${port}:`, this.params.logging, { type: 'error' });
|
|
177
|
-
reject(err);
|
|
178
|
-
});
|
|
179
|
-
this.server.listen(port, () => {
|
|
180
|
-
log(`[HttpServerNode] Listening on http://localhost:${port}`, this.params.logging);
|
|
181
|
-
resolve();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
return { status: 'listening', port };
|
|
185
|
-
}
|
|
186
|
-
async postAsync(shared, prepRes, execRes) {
|
|
187
|
-
shared.httpServer = this.server;
|
|
188
|
-
return 'default';
|
|
189
|
-
}
|
|
190
|
-
}
|