@fractal-solutions/qflow 1.0.59 → 1.0.61

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 +77 -1
  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,135 @@
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
+ static getToolDefinition() {
16
+ return {
17
+ name: "github_create_issue",
18
+ description: "Creates a new issue in a GitHub repository.",
19
+ parameters: {
20
+ type: "object",
21
+ properties: {
22
+ token: {
23
+ type: "string",
24
+ description: "The GitHub personal access token."
25
+ },
26
+ owner: {
27
+ type: "string",
28
+ description: "The owner of the repository."
29
+ },
30
+ repo: {
31
+ type: "string",
32
+ description: "The name of the repository."
33
+ },
34
+ title: {
35
+ type: "string",
36
+ description: "The title of the issue."
37
+ },
38
+ body: {
39
+ type: "string",
40
+ description: "Optional. The body of the issue."
41
+ }
42
+ },
43
+ required: ["token", "owner", "repo", "title"]
44
+ }
45
+ };
46
+ }
47
+ async execAsync() {
48
+ const { token, owner, repo, title, body } = this.params;
49
+ if (!token || !owner || !repo || !title) {
50
+ throw new Error('Missing required parameters: token, owner, repo, title');
51
+ }
52
+ log(`[GitHub] Creating issue "${title}" in ${owner}/${repo}...`, this.params.logging);
53
+ const response = await fetch(`${API_BASE}/repos/${owner}/${repo}/issues`, {
54
+ method: 'POST',
55
+ headers: {
56
+ 'Authorization': `token ${token}`,
57
+ 'Content-Type': 'application/json'
58
+ },
59
+ body: JSON.stringify({ title, body })
60
+ });
61
+ if (!response.ok) {
62
+ const errorData = await response.json();
63
+ throw new Error(`GitHub API error: ${response.status} - ${errorData.message}`);
64
+ }
65
+ const issue = await response.json();
66
+ log(`[GitHub] Successfully created issue #${issue.number}`, this.params.logging);
67
+ return issue;
68
+ }
69
+ async postAsync(shared, prepRes, execRes) {
70
+ shared.createdIssue = execRes; // Put the result in the shared object
71
+ return 'default'; // Return an action to transition
72
+ }
73
+ }
74
+ /**
75
+ * Retrieves an issue from a GitHub repository.
76
+ * @param {object} params - The parameters for the node.
77
+ * @param {string} params.token - The GitHub personal access token.
78
+ * @param {string} params.owner - The owner of the repository.
79
+ * @param {string} params.repo - The name of the repository.
80
+ * @param {number} params.issue_number - The number of the issue to retrieve.
81
+ * @returns {Promise<object>} A promise that resolves to the issue object.
82
+ */
83
+ export class GetIssueNode extends AsyncNode {
84
+ static getToolDefinition() {
85
+ return {
86
+ name: "github_get_issue",
87
+ description: "Retrieves an issue from a GitHub repository.",
88
+ parameters: {
89
+ type: "object",
90
+ properties: {
91
+ token: {
92
+ type: "string",
93
+ description: "The GitHub personal access token."
94
+ },
95
+ owner: {
96
+ type: "string",
97
+ description: "The owner of the repository."
98
+ },
99
+ repo: {
100
+ type: "string",
101
+ description: "The name of the repository."
102
+ },
103
+ issue_number: {
104
+ type: "number",
105
+ description: "The number of the issue to retrieve."
106
+ }
107
+ },
108
+ required: ["token", "owner", "repo", "issue_number"]
109
+ }
110
+ };
111
+ }
112
+ async prepAsync(shared) {
113
+ // Retrieve the issue number from the shared object
114
+ this.params.issue_number = shared.createdIssue?.number;
115
+ }
116
+ async execAsync() {
117
+ const { token, owner, repo, issue_number } = this.params;
118
+ if (!token || !owner || !repo || !issue_number) {
119
+ throw new Error('Missing required parameters: token, owner, repo, issue_number');
120
+ }
121
+ log(`[GitHub] Getting issue #${issue_number} from ${owner}/${repo}...`, this.params.logging);
122
+ const response = await fetch(`${API_BASE}/repos/${owner}/${repo}/issues/${issue_number}`, {
123
+ headers: {
124
+ 'Authorization': `token ${token}`
125
+ }
126
+ });
127
+ if (!response.ok) {
128
+ const errorData = await response.json();
129
+ throw new Error(`GitHub API error: ${response.status} - ${errorData.message}`);
130
+ }
131
+ const issue = await response.json();
132
+ log(`[GitHub] Successfully retrieved issue #${issue.number}`, this.params.logging);
133
+ return issue;
134
+ }
135
+ }
@@ -0,0 +1,47 @@
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
+ static getToolDefinition(): {
9
+ name: string;
10
+ description: string;
11
+ parameters: {
12
+ type: string;
13
+ properties: {
14
+ limit: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ };
19
+ required: never[];
20
+ };
21
+ };
22
+ execAsync(prepRes: any, shared: any): Promise<string>;
23
+ }
24
+ /**
25
+ * Fetches the details of a specific item from the Hacker News API.
26
+ * @param {object} params - The parameters for the node.
27
+ * @param {number} params.id - The ID of the item to fetch.
28
+ * @returns {Promise<object>} A promise that resolves to the item details.
29
+ */
30
+ export class GetItemNode extends AsyncNode {
31
+ static getToolDefinition(): {
32
+ name: string;
33
+ description: string;
34
+ parameters: {
35
+ type: string;
36
+ properties: {
37
+ id: {
38
+ type: string;
39
+ description: string;
40
+ };
41
+ };
42
+ required: string[];
43
+ };
44
+ };
45
+ execAsync(): Promise<unknown>;
46
+ }
47
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,79 @@
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
+ static getToolDefinition() {
12
+ return {
13
+ name: "hackernews_get_top_stories",
14
+ description: "Fetches the top story IDs from the Hacker News API.",
15
+ parameters: {
16
+ type: "object",
17
+ properties: {
18
+ limit: {
19
+ type: "number",
20
+ description: "Optional. The maximum number of story IDs to return. Defaults to 10."
21
+ }
22
+ },
23
+ required: []
24
+ }
25
+ };
26
+ }
27
+ async execAsync(prepRes, shared) {
28
+ const { limit = 10 } = this.params;
29
+ log(`[HackerNews] Fetching top ${limit} stories...`, this.params.logging);
30
+ const response = await fetch(`${API_BASE}/topstories.json`);
31
+ if (!response.ok) {
32
+ throw new Error(`Hacker News API error: ${response.status}`);
33
+ }
34
+ const storyIds = await response.json();
35
+ const limitedIds = storyIds.slice(0, limit);
36
+ log(`[HackerNews] Found ${limitedIds.length} stories.`, this.params.logging);
37
+ shared.storyIds = limitedIds;
38
+ return 'default';
39
+ }
40
+ }
41
+ /**
42
+ * Fetches the details of a specific item from the Hacker News API.
43
+ * @param {object} params - The parameters for the node.
44
+ * @param {number} params.id - The ID of the item to fetch.
45
+ * @returns {Promise<object>} A promise that resolves to the item details.
46
+ */
47
+ export class GetItemNode extends AsyncNode {
48
+ static getToolDefinition() {
49
+ return {
50
+ name: "hackernews_get_item",
51
+ description: "Fetches the details of a specific item from the Hacker News API.",
52
+ parameters: {
53
+ type: "object",
54
+ properties: {
55
+ id: {
56
+ type: "number",
57
+ description: "The ID of the item to fetch."
58
+ }
59
+ },
60
+ required: ["id"]
61
+ }
62
+ };
63
+ }
64
+ async execAsync() {
65
+ const { id } = this.params;
66
+ if (!id) {
67
+ throw new Error('Item ID is required for GetItemNode.');
68
+ }
69
+ log(`[HackerNews] Fetching item ${id}...`, this.params.logging);
70
+ const response = await fetch(`${API_BASE}/item/${id}.json`);
71
+ if (!response.ok) {
72
+ throw new Error(`Hacker News API error: ${response.status}`);
73
+ }
74
+ const item = await response.json();
75
+ log(`[HackerNews] Fetched item title: ${item.title}`, this.params.logging);
76
+ log(`[HackerNews] Fetched item: ${item.url}`, this.params.logging);
77
+ return item;
78
+ }
79
+ }
@@ -0,0 +1,39 @@
1
+ export class HardwareInteractionNode 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
+ portPath: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ baudRate: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ dataToWrite: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ timeout: {
26
+ type: string;
27
+ description: string;
28
+ };
29
+ };
30
+ required: string[];
31
+ };
32
+ };
33
+ port: SerialPort<any> | null;
34
+ parser: ReadlineParser | null;
35
+ execAsync(): Promise<any>;
36
+ }
37
+ import { AsyncNode } from '../qflow.js';
38
+ import { SerialPort } from 'serialport';
39
+ import { ReadlineParser } from '@serialport/parser-readline';
@@ -0,0 +1,131 @@
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
+ static getToolDefinition() {
8
+ return {
9
+ name: "hardware_interaction",
10
+ description: "Communicates with local hardware via serial port (UART).",
11
+ parameters: {
12
+ type: "object",
13
+ properties: {
14
+ action: {
15
+ type: "string",
16
+ enum: ["write", "read_line", "list_ports"],
17
+ description: "The action to perform: 'write' data, 'read_line' from port, or 'list_ports' available."
18
+ },
19
+ portPath: {
20
+ type: "string",
21
+ description: "Required for 'write'/'read_line'. The path to the serial port (e.g., '/dev/ttyUSB0', 'COM1')."
22
+ },
23
+ baudRate: {
24
+ type: "number",
25
+ description: "Optional. The baud rate for serial communication. Defaults to 9600."
26
+ },
27
+ dataToWrite: {
28
+ type: "string",
29
+ description: "Required for 'write'. The data string to send to the serial port."
30
+ },
31
+ timeout: {
32
+ type: "number",
33
+ description: "Optional. Timeout in milliseconds for 'read_line' action. Defaults to 5000."
34
+ }
35
+ },
36
+ required: ["action"]
37
+ }
38
+ };
39
+ }
40
+ constructor(maxRetries = 1, wait = 0) {
41
+ super(maxRetries, wait);
42
+ this.port = null;
43
+ this.parser = null;
44
+ }
45
+ async execAsync() {
46
+ const { portPath, // e.g., '/dev/ttyUSB0' on Linux, 'COM1' on Windows
47
+ baudRate = 9600, action, // 'write', 'read_line', 'list_ports'
48
+ dataToWrite, // For 'write' action
49
+ timeout = 5000 // For 'read_line' action
50
+ } = this.params;
51
+ if (!action || !['write', 'read_line', 'list_ports'].includes(action)) {
52
+ throw new Error('HardwareInteractionNode requires an `action`: "write", "read_line", or "list_ports".');
53
+ }
54
+ let result;
55
+ switch (action) {
56
+ case 'list_ports':
57
+ // List available serial ports
58
+ try {
59
+ const ports = await SerialPort.list();
60
+ result = ports.map(p => ({
61
+ path: p.path,
62
+ manufacturer: p.manufacturer,
63
+ serialNumber: p.serialNumber,
64
+ pnpId: p.pnpId,
65
+ productId: p.productId,
66
+ vendorId: p.vendorId,
67
+ }));
68
+ }
69
+ catch (e) {
70
+ throw new Error(`Failed to list serial ports: ${e.message}`);
71
+ }
72
+ break;
73
+ case 'write':
74
+ case 'read_line':
75
+ if (!portPath) {
76
+ throw new Error('For "write" or "read_line" action, `portPath` is required.');
77
+ }
78
+ try {
79
+ this.port = new SerialPort({ path: portPath, baudRate: baudRate });
80
+ await new Promise((resolve, reject) => {
81
+ this.port.on('open', resolve);
82
+ this.port.on('error', reject);
83
+ });
84
+ log(`[HardwareInteractionNode] Serial port ${portPath} opened.`, this.params.logging);
85
+ if (action === 'write') {
86
+ if (dataToWrite === undefined) {
87
+ throw new Error('Write action requires `dataToWrite`.');
88
+ }
89
+ await new Promise((resolve, reject) => {
90
+ this.port.write(dataToWrite, (err) => {
91
+ if (err)
92
+ reject(err);
93
+ else
94
+ resolve();
95
+ });
96
+ });
97
+ result = { status: 'data_written', data: dataToWrite };
98
+ }
99
+ else if (action === 'read_line') {
100
+ this.parser = this.port.pipe(new ReadlineParser({ delimiter: '\n' }));
101
+ result = await new Promise((resolve, reject) => {
102
+ const timer = setTimeout(() => {
103
+ reject(new Error(`Timeout waiting for data on ${portPath}`));
104
+ }, timeout);
105
+ this.parser.on('data', (line) => {
106
+ clearTimeout(timer);
107
+ resolve(line.trim());
108
+ });
109
+ this.port.on('error', (err) => {
110
+ clearTimeout(timer);
111
+ reject(err);
112
+ });
113
+ });
114
+ }
115
+ }
116
+ catch (e) {
117
+ throw new Error(`Serial port operation failed: ${e.message}. Check portPath, baudRate, and permissions.`);
118
+ }
119
+ finally {
120
+ if (this.port && this.port.isOpen) {
121
+ await new Promise(resolve => this.port.close(resolve));
122
+ log(`[HardwareInteractionNode] Serial port ${portPath} closed.`, this.params.logging);
123
+ }
124
+ }
125
+ break;
126
+ default:
127
+ throw new Error(`Unsupported action: ${action}`);
128
+ }
129
+ return result;
130
+ }
131
+ }
@@ -0,0 +1,77 @@
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
+ static getToolDefinition(): {
17
+ name: string;
18
+ description: string;
19
+ parameters: {
20
+ type: string;
21
+ properties: {
22
+ url: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ method: {
27
+ type: string;
28
+ enum: string[];
29
+ default: string;
30
+ description: string;
31
+ };
32
+ headers: {
33
+ type: string;
34
+ description: string;
35
+ };
36
+ body: {
37
+ type: string;
38
+ description: string;
39
+ };
40
+ auth: {
41
+ type: string;
42
+ properties: {
43
+ type: {
44
+ type: string;
45
+ enum: string[];
46
+ description: string;
47
+ };
48
+ token: {
49
+ type: string;
50
+ description: string;
51
+ };
52
+ username: {
53
+ type: string;
54
+ description: string;
55
+ };
56
+ password: {
57
+ type: string;
58
+ description: string;
59
+ };
60
+ };
61
+ description: string;
62
+ };
63
+ };
64
+ required: string[];
65
+ };
66
+ };
67
+ execAsync(): Promise<{
68
+ status: number;
69
+ headers: {
70
+ [k: string]: string;
71
+ };
72
+ body: any;
73
+ }>;
74
+ parseResponseBody(response: any): Promise<any>;
75
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
76
+ }
77
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,120 @@
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
+ static getToolDefinition() {
19
+ return {
20
+ name: "http_request",
21
+ description: "Makes HTTP requests.",
22
+ parameters: {
23
+ type: "object",
24
+ properties: {
25
+ url: {
26
+ type: "string",
27
+ description: "The full URL of the API endpoint."
28
+ },
29
+ method: {
30
+ type: "string",
31
+ enum: ["GET", "POST", "PUT", "DELETE", "PATCH"],
32
+ default: "GET",
33
+ description: "The HTTP method to use."
34
+ },
35
+ headers: {
36
+ type: "object",
37
+ description: "Custom headers for the request (key-value pairs)."
38
+ },
39
+ body: {
40
+ type: "object", // Can be any type, but object is common for JSON
41
+ description: "The request payload. If an object, it will be stringified as JSON."
42
+ },
43
+ auth: {
44
+ type: "object",
45
+ properties: {
46
+ type: {
47
+ type: "string",
48
+ enum: ["bearer", "basic"],
49
+ description: "The type of authentication."
50
+ },
51
+ token: {
52
+ type: "string",
53
+ description: "The bearer token."
54
+ },
55
+ username: {
56
+ type: "string",
57
+ description: "The username for basic auth."
58
+ },
59
+ password: {
60
+ type: "string",
61
+ description: "The password for basic auth."
62
+ }
63
+ },
64
+ description: "Authentication configuration."
65
+ }
66
+ },
67
+ required: ["url"]
68
+ }
69
+ };
70
+ }
71
+ async execAsync() {
72
+ const { url, method = 'GET', headers = {}, body, auth } = this.params;
73
+ if (!url) {
74
+ throw new Error('HttpRequestNode requires a `url` parameter.');
75
+ }
76
+ const fetchOptions = {
77
+ method,
78
+ headers: { ...headers }, // Create a mutable copy
79
+ };
80
+ // Handle Authentication
81
+ if (auth) {
82
+ if (auth.type === 'bearer' && auth.token) {
83
+ fetchOptions.headers['Authorization'] = `Bearer ${auth.token}`;
84
+ }
85
+ else if (auth.type === 'basic' && auth.username && auth.password) {
86
+ const credentials = btoa(`${auth.username}:${auth.password}`);
87
+ fetchOptions.headers['Authorization'] = `Basic ${credentials}`;
88
+ }
89
+ }
90
+ // Handle Body
91
+ if (body) {
92
+ if (typeof body === 'object' && !fetchOptions.headers['Content-Type']) {
93
+ fetchOptions.headers['Content-Type'] = 'application/json';
94
+ fetchOptions.body = JSON.stringify(body);
95
+ }
96
+ else {
97
+ fetchOptions.body = body;
98
+ }
99
+ }
100
+ log(`[HTTP] ${method} ${url}`, this.params.logging);
101
+ const response = await fetch(url, fetchOptions);
102
+ const responseBody = await this.parseResponseBody(response);
103
+ return {
104
+ status: response.status,
105
+ headers: Object.fromEntries(response.headers.entries()),
106
+ body: responseBody,
107
+ };
108
+ }
109
+ async parseResponseBody(response) {
110
+ const contentType = response.headers.get('content-type') || '';
111
+ if (contentType.includes('application/json')) {
112
+ return await response.json();
113
+ }
114
+ return await response.text();
115
+ }
116
+ async postAsync(shared, prepRes, execRes) {
117
+ shared.httpResult = execRes;
118
+ return 'default';
119
+ }
120
+ }
@@ -0,0 +1,54 @@
1
+ export class HttpServerNode 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
+ routes: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ staticDir: {
17
+ type: string;
18
+ description: string;
19
+ };
20
+ cors: {
21
+ type: string;
22
+ properties: {
23
+ origin: {
24
+ type: string;
25
+ };
26
+ methods: {
27
+ type: string;
28
+ };
29
+ headers: {
30
+ type: string;
31
+ };
32
+ };
33
+ description: string;
34
+ };
35
+ };
36
+ required: never[];
37
+ };
38
+ };
39
+ constructor();
40
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | null;
41
+ findMatchingRoute(routes: any, method: any, path: any): {
42
+ flow: any;
43
+ params: {};
44
+ } | null;
45
+ handleStatic(staticDir: any, reqPath: any, res: any): Promise<boolean>;
46
+ applyCorsHeaders(res: any, corsConfig: any): void;
47
+ execAsync(): Promise<{
48
+ status: string;
49
+ port: any;
50
+ }>;
51
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
52
+ }
53
+ import { AsyncNode } from '../qflow.js';
54
+ import http from 'http';