@fractal-solutions/qflow 1.0.60 → 1.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -74
- package/dist/qflow.config.d.ts +5 -0
- package/dist/qflow.config.js +16 -0
- package/dist/src/agent/agent.d.ts +23 -0
- package/dist/src/agent/agent.js +365 -0
- package/dist/src/agent/base_agent.d.ts +21 -0
- package/dist/src/agent/base_agent.js +206 -0
- package/dist/src/agent/logger.d.ts +9 -0
- package/dist/src/agent/logger.js +45 -0
- package/dist/src/agent/lpavrl_agent.d.ts +5 -0
- package/dist/src/agent/lpavrl_agent.js +178 -0
- package/dist/src/agent/ooda_agent.d.ts +5 -0
- package/dist/src/agent/ooda_agent.js +167 -0
- package/dist/src/agent/pema_agent.d.ts +5 -0
- package/dist/src/agent/pema_agent.js +171 -0
- package/dist/src/agent/raor_agent.d.ts +5 -0
- package/dist/src/agent/raor_agent.js +164 -0
- package/dist/src/agent/tools.d.ts +1 -0
- package/dist/src/agent/tools.js +148 -0
- package/dist/src/logger.d.ts +9 -0
- package/dist/src/logger.js +107 -0
- package/dist/src/nodes/agent_llm.d.ts +31 -0
- package/dist/src/nodes/agent_llm.js +302 -0
- package/dist/src/nodes/browser_control.d.ts +35 -0
- package/dist/src/nodes/browser_control.js +106 -0
- package/dist/src/nodes/code_interpreter.d.ts +38 -0
- package/dist/src/nodes/code_interpreter.js +150 -0
- package/dist/src/nodes/data_extractor.d.ts +40 -0
- package/dist/src/nodes/data_extractor.js +118 -0
- package/dist/src/nodes/data_validation.d.ts +36 -0
- package/dist/src/nodes/data_validation.js +77 -0
- package/dist/src/nodes/database.d.ts +50 -0
- package/dist/src/nodes/database.js +135 -0
- package/dist/src/nodes/display_image.d.ts +18 -0
- package/dist/src/nodes/display_image.js +63 -0
- package/dist/src/nodes/embedding.d.ts +29 -0
- package/dist/src/nodes/embedding.js +69 -0
- package/dist/src/nodes/filesystem.d.ts +105 -0
- package/dist/src/nodes/filesystem.js +160 -0
- package/dist/src/nodes/gis.d.ts +62 -0
- package/dist/src/nodes/gis.js +133 -0
- package/dist/src/nodes/git.d.ts +46 -0
- package/dist/src/nodes/git.js +99 -0
- package/dist/src/nodes/github.d.ts +83 -0
- package/dist/src/nodes/github.js +135 -0
- package/dist/src/nodes/hackernews.d.ts +47 -0
- package/dist/src/nodes/hackernews.js +79 -0
- package/dist/src/nodes/hardware_interaction.d.ts +39 -0
- package/dist/src/nodes/hardware_interaction.js +131 -0
- package/dist/src/nodes/http.d.ts +77 -0
- package/dist/src/nodes/http.js +120 -0
- package/dist/src/nodes/http_server.d.ts +54 -0
- package/dist/src/nodes/http_server.js +223 -0
- package/dist/src/nodes/image_gallery.d.ts +37 -0
- package/dist/src/nodes/image_gallery.js +129 -0
- package/dist/src/nodes/index.d.ts +48 -0
- package/dist/src/nodes/index.js +48 -0
- package/dist/src/nodes/interactive_input.d.ts +26 -0
- package/dist/src/nodes/interactive_input.js +95 -0
- package/dist/src/nodes/interactive_webview.d.ts +78 -0
- package/dist/src/nodes/interactive_webview.js +369 -0
- package/dist/src/nodes/iterator.d.ts +23 -0
- package/dist/src/nodes/iterator.js +43 -0
- package/dist/src/nodes/llm.d.ts +160 -0
- package/dist/src/nodes/llm.js +367 -0
- package/dist/src/nodes/memory.d.ts +43 -0
- package/dist/src/nodes/memory.js +90 -0
- package/dist/src/nodes/multimedia_processing.d.ts +57 -0
- package/dist/src/nodes/multimedia_processing.js +129 -0
- package/dist/src/nodes/openrouter_llm.d.ts +38 -0
- package/dist/src/nodes/openrouter_llm.js +156 -0
- package/dist/src/nodes/pdf_processor.d.ts +43 -0
- package/dist/src/nodes/pdf_processor.js +112 -0
- package/dist/src/nodes/remote_execution.d.ts +51 -0
- package/dist/src/nodes/remote_execution.js +132 -0
- package/dist/src/nodes/s3.d.ts +73 -0
- package/dist/src/nodes/s3.js +107 -0
- package/dist/src/nodes/scheduler.d.ts +51 -0
- package/dist/src/nodes/scheduler.js +131 -0
- package/dist/src/nodes/search.d.ts +61 -0
- package/dist/src/nodes/search.js +118 -0
- package/dist/src/nodes/semantic_memory.d.ts +64 -0
- package/dist/src/nodes/semantic_memory.js +160 -0
- package/dist/src/nodes/shell.d.ts +25 -0
- package/dist/src/nodes/shell.js +45 -0
- package/dist/src/nodes/speech_synthesis.d.ts +72 -0
- package/dist/src/nodes/speech_synthesis.js +171 -0
- package/dist/src/nodes/spreadsheet.d.ts +61 -0
- package/dist/src/nodes/spreadsheet.js +294 -0
- package/dist/src/nodes/stripe.d.ts +67 -0
- package/dist/src/nodes/stripe.js +117 -0
- package/dist/src/nodes/subflow.d.ts +23 -0
- package/dist/src/nodes/subflow.js +36 -0
- package/dist/src/nodes/summarize.d.ts +26 -0
- package/dist/src/nodes/summarize.js +51 -0
- package/dist/src/nodes/system_notification.d.ts +26 -0
- package/dist/src/nodes/system_notification.js +74 -0
- package/dist/src/nodes/transform.d.ts +23 -0
- package/dist/src/nodes/transform.js +52 -0
- package/dist/src/nodes/user.d.ts +25 -0
- package/dist/src/nodes/user.js +48 -0
- package/dist/src/nodes/webhook.d.ts +49 -0
- package/dist/src/nodes/webhook.js +161 -0
- package/dist/src/nodes/webscraper.d.ts +25 -0
- package/dist/src/nodes/webscraper.js +49 -0
- package/dist/src/nodes/websockets.d.ts +27 -0
- package/dist/src/nodes/websockets.js +98 -0
- package/dist/src/nodes/webview.d.ts +38 -0
- package/dist/src/nodes/webview.js +55 -0
- package/dist/src/qflow.d.ts +69 -0
- package/dist/src/qflow.js +320 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
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
|
+
static getToolDefinition() {
|
|
27
|
+
return {
|
|
28
|
+
name: "http_server",
|
|
29
|
+
description: "Creates a web server and handles HTTP requests by triggering qflow flows.",
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
port: {
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Optional. The port number to listen on. Defaults to 3000."
|
|
36
|
+
},
|
|
37
|
+
routes: {
|
|
38
|
+
type: "object",
|
|
39
|
+
description: "An object defining API routes. Keys are route paths (e.g., '/api/data', '/users/:id'), values are objects mapping HTTP methods (GET, POST, etc.) to the name of a qflow AsyncFlow instance to trigger. Example: { '/api/data': { 'GET': 'myGetDataFlow' } }."
|
|
40
|
+
},
|
|
41
|
+
staticDir: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Optional. The absolute path to a directory to serve static files from."
|
|
44
|
+
},
|
|
45
|
+
cors: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
origin: { type: "string" },
|
|
49
|
+
methods: { type: "string" },
|
|
50
|
+
headers: { type: "string" }
|
|
51
|
+
},
|
|
52
|
+
description: "Optional. CORS configuration for the server."
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
required: [] // Port has a default, routes/staticDir are optional for a basic server
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
this.server = null;
|
|
62
|
+
}
|
|
63
|
+
// Helper to find a matching route and extract params
|
|
64
|
+
findMatchingRoute(routes, method, path) {
|
|
65
|
+
for (const routePath in routes) {
|
|
66
|
+
const routeHandlers = routes[routePath];
|
|
67
|
+
const paramNames = [];
|
|
68
|
+
// Convert route path to regex, e.g., /users/:id -> /users/([^/]+)
|
|
69
|
+
const regexPath = routePath.replace(/:(\w+)/g, (_, paramName) => {
|
|
70
|
+
paramNames.push(paramName);
|
|
71
|
+
return '([^/]+)';
|
|
72
|
+
});
|
|
73
|
+
const regex = new RegExp(`^${regexPath}$`);
|
|
74
|
+
const match = path.match(regex);
|
|
75
|
+
if (match) {
|
|
76
|
+
const handler = routeHandlers[method.toUpperCase()];
|
|
77
|
+
if (handler) {
|
|
78
|
+
const params = {};
|
|
79
|
+
paramNames.forEach((name, index) => {
|
|
80
|
+
params[name] = match[index + 1];
|
|
81
|
+
});
|
|
82
|
+
return { flow: handler, params };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
// Helper to serve static files
|
|
89
|
+
async handleStatic(staticDir, reqPath, res) {
|
|
90
|
+
if (!staticDir)
|
|
91
|
+
return false;
|
|
92
|
+
// Prevent directory traversal attacks
|
|
93
|
+
const safePath = path.normalize(reqPath).replace(/^(\.\.[\/\\])+/, '');
|
|
94
|
+
const filePath = path.join(staticDir, safePath);
|
|
95
|
+
try {
|
|
96
|
+
const stats = await fsPromises.stat(filePath);
|
|
97
|
+
if (stats.isFile()) {
|
|
98
|
+
const mimeType = getMimeType(filePath);
|
|
99
|
+
res.writeHead(200, { 'Content-Type': mimeType });
|
|
100
|
+
// Create a read stream and pipe it to the response
|
|
101
|
+
const fileStream = fs.createReadStream(filePath);
|
|
102
|
+
fileStream.pipe(res);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
// File doesn't exist, fall through to dynamic routing
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
// Helper to apply CORS headers
|
|
112
|
+
applyCorsHeaders(res, corsConfig) {
|
|
113
|
+
if (!corsConfig)
|
|
114
|
+
return;
|
|
115
|
+
if (corsConfig.origin) {
|
|
116
|
+
res.setHeader('Access-Control-Allow-Origin', corsConfig.origin);
|
|
117
|
+
}
|
|
118
|
+
if (corsConfig.methods) {
|
|
119
|
+
res.setHeader('Access-Control-Allow-Methods', corsConfig.methods);
|
|
120
|
+
}
|
|
121
|
+
if (corsConfig.headers) {
|
|
122
|
+
res.setHeader('Access-Control-Allow-Headers', corsConfig.headers);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async execAsync() {
|
|
126
|
+
const { port = 3000, routes = {}, staticDir, cors } = this.params;
|
|
127
|
+
if (this.server && this.server.listening) {
|
|
128
|
+
log(`[HttpServerNode] Server already listening on port ${port}.`, this.params.logging, { type: 'warn' });
|
|
129
|
+
return { status: 'server_already_running', port };
|
|
130
|
+
}
|
|
131
|
+
this.server = http.createServer(async (req, res) => {
|
|
132
|
+
// Apply CORS headers to all responses
|
|
133
|
+
this.applyCorsHeaders(res, cors);
|
|
134
|
+
// Handle CORS pre-flight OPTIONS request
|
|
135
|
+
if (cors && req.method === 'OPTIONS') {
|
|
136
|
+
res.writeHead(204); // No Content
|
|
137
|
+
res.end();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const requestUrl = new URL(req.url, `http://${req.headers.host}`);
|
|
141
|
+
const reqPath = requestUrl.pathname;
|
|
142
|
+
// 1. Try to serve static file
|
|
143
|
+
if (staticDir) {
|
|
144
|
+
const served = await this.handleStatic(staticDir, reqPath, res);
|
|
145
|
+
if (served)
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// 2. Find a matching dynamic route
|
|
149
|
+
const routeMatch = this.findMatchingRoute(routes, req.method, reqPath);
|
|
150
|
+
if (!routeMatch) {
|
|
151
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
152
|
+
res.end(JSON.stringify({ error: 'Not Found' }));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const { flow, params: pathParams } = routeMatch;
|
|
156
|
+
if (!(flow instanceof AsyncFlow)) {
|
|
157
|
+
log(`[HttpServerNode] Handler for ${req.method} ${reqPath} is not an AsyncFlow.`, this.params.logging, { type: 'error' });
|
|
158
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
159
|
+
res.end(JSON.stringify({ error: 'Internal Server Error: Invalid handler' }));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// 3. Process request body and trigger flow
|
|
163
|
+
let body = '';
|
|
164
|
+
req.on('data', chunk => { body += chunk.toString(); });
|
|
165
|
+
req.on('end', async () => {
|
|
166
|
+
let payload;
|
|
167
|
+
if (body) {
|
|
168
|
+
try {
|
|
169
|
+
payload = JSON.parse(body);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
payload = body; // Not JSON, treat as raw string
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const requestContext = {
|
|
176
|
+
headers: req.headers,
|
|
177
|
+
body: payload,
|
|
178
|
+
method: req.method,
|
|
179
|
+
path: reqPath,
|
|
180
|
+
query: Object.fromEntries(requestUrl.searchParams),
|
|
181
|
+
params: pathParams
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
const flowResult = await flow.runAsync({ request: requestContext });
|
|
185
|
+
const response = flowResult || { statusCode: 204, body: '' };
|
|
186
|
+
const statusCode = response.statusCode || 200;
|
|
187
|
+
const headers = response.headers || {};
|
|
188
|
+
let responseBody = response.body;
|
|
189
|
+
if (typeof responseBody === 'object' && !(responseBody instanceof Buffer)) {
|
|
190
|
+
responseBody = JSON.stringify(responseBody);
|
|
191
|
+
if (!headers['Content-Type']) {
|
|
192
|
+
headers['Content-Type'] = 'application/json';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
res.writeHead(statusCode, headers);
|
|
196
|
+
res.end(responseBody);
|
|
197
|
+
}
|
|
198
|
+
catch (flowError) {
|
|
199
|
+
log(`[HttpServerNode] Flow for ${req.method} ${reqPath} failed:`, this.params.logging, { type: 'error' });
|
|
200
|
+
if (!res.writableEnded) {
|
|
201
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
202
|
+
res.end(JSON.stringify({ error: 'Flow execution failed', details: flowError.message }));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
await new Promise((resolve, reject) => {
|
|
208
|
+
this.server.on('error', (err) => {
|
|
209
|
+
log(`[HttpServerNode] Failed to start server on port ${port}:`, this.params.logging, { type: 'error' });
|
|
210
|
+
reject(err);
|
|
211
|
+
});
|
|
212
|
+
this.server.listen(port, () => {
|
|
213
|
+
log(`[HttpServerNode] Listening on http://localhost:${port}`, this.params.logging);
|
|
214
|
+
resolve();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
return { status: 'listening', port };
|
|
218
|
+
}
|
|
219
|
+
async postAsync(shared, prepRes, execRes) {
|
|
220
|
+
shared.httpServer = this.server;
|
|
221
|
+
return 'default';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class ImageGalleryNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
imagePaths: {
|
|
9
|
+
type: string;
|
|
10
|
+
items: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
title: {
|
|
16
|
+
type: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
description: {
|
|
20
|
+
type: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
outputDir: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
required: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
execAsync(): Promise<{
|
|
32
|
+
status: string;
|
|
33
|
+
htmlFilePath: string;
|
|
34
|
+
imageCount: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
+
import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is available
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
import { log } from '../logger.js';
|
|
7
|
+
export class ImageGalleryNode extends AsyncNode {
|
|
8
|
+
static getToolDefinition() {
|
|
9
|
+
return {
|
|
10
|
+
name: "image_gallery",
|
|
11
|
+
description: "Generates an HTML gallery from multiple image files and opens it in a web browser.",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
imagePaths: {
|
|
16
|
+
type: "array",
|
|
17
|
+
items: { type: "string" },
|
|
18
|
+
description: "An array of absolute paths to the image files to display in the gallery."
|
|
19
|
+
},
|
|
20
|
+
title: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Optional. The title of the HTML gallery page. Defaults to 'Image Gallery'."
|
|
23
|
+
},
|
|
24
|
+
description: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Optional. A short description to display on the gallery page. Defaults to 'Generated by QFlow Agent'."
|
|
27
|
+
},
|
|
28
|
+
outputDir: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Optional. Directory to save the generated HTML file and copied images. Defaults to a temporary directory."
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
required: ["imagePaths"]
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
38
|
+
super(maxRetries, wait);
|
|
39
|
+
}
|
|
40
|
+
async execAsync() {
|
|
41
|
+
const { imagePaths, // Array of absolute paths to image files
|
|
42
|
+
title = 'Image Gallery', description = 'Generated by QFlow Agent', outputDir // Optional: directory to save the HTML file
|
|
43
|
+
} = this.params;
|
|
44
|
+
if (!imagePaths || !Array.isArray(imagePaths) || imagePaths.length === 0) {
|
|
45
|
+
throw new Error('ImageGalleryNode requires an `imagePaths` array.');
|
|
46
|
+
}
|
|
47
|
+
const tempDir = outputDir || path.join(os.tmpdir(), `qflow_image_gallery_${Date.now()}`);
|
|
48
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
49
|
+
const htmlFilePath = path.join(tempDir, 'index.html');
|
|
50
|
+
// Generate HTML content
|
|
51
|
+
let imageHtml = '';
|
|
52
|
+
for (const imagePath of imagePaths) {
|
|
53
|
+
// For security and portability, it's best to embed images as base64 data URIs
|
|
54
|
+
// or ensure they are served from a web-accessible location.
|
|
55
|
+
// For simplicity in this node, we'll use file:// URLs, but this might have browser security warnings.
|
|
56
|
+
// A more robust solution would involve a local web server (like BrowserGUINode).
|
|
57
|
+
// For simplicity in this node, we'll assume direct file access for now.
|
|
58
|
+
// Or, even better, copy images to the tempDir and reference them relatively.
|
|
59
|
+
const imageName = path.basename(imagePath);
|
|
60
|
+
const destImagePath = path.join(tempDir, imageName);
|
|
61
|
+
try {
|
|
62
|
+
await fs.copyFile(imagePath, destImagePath); // Copy image to temp dir
|
|
63
|
+
imageHtml += `<div class="gallery-item">\n`;
|
|
64
|
+
imageHtml += ` <img src="${imageName}" alt="${imageName}">\n`;
|
|
65
|
+
imageHtml += ` <p>${imageName}</p>\n`;
|
|
66
|
+
imageHtml += `</div>\n`;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
log(`[ImageGalleryNode] Could not copy image ${imagePath}: ${e.message}. Skipping.`, this.params.logging, { type: 'warn' });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const htmlContent = `
|
|
73
|
+
<!DOCTYPE html>
|
|
74
|
+
<html lang="en">
|
|
75
|
+
<head>
|
|
76
|
+
<meta charset="UTF-8">
|
|
77
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
78
|
+
<title>${title}</title>
|
|
79
|
+
<style>
|
|
80
|
+
body { font-family: sans-serif; margin: 20px; background-color: #f0f0f0; }
|
|
81
|
+
h1 { color: #333; }
|
|
82
|
+
p { color: #666; }
|
|
83
|
+
.gallery-container {
|
|
84
|
+
display: grid;
|
|
85
|
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
86
|
+
gap: 20px;
|
|
87
|
+
padding: 20px;
|
|
88
|
+
background-color: #fff;
|
|
89
|
+
border-radius: 8px;
|
|
90
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
91
|
+
}
|
|
92
|
+
.gallery-item {
|
|
93
|
+
border: 1px solid #ddd;
|
|
94
|
+
border-radius: 4px;
|
|
95
|
+
padding: 10px;
|
|
96
|
+
text-align: center;
|
|
97
|
+
background-color: #f9f9f9;
|
|
98
|
+
}
|
|
99
|
+
.gallery-item img {
|
|
100
|
+
max-width: 100%;
|
|
101
|
+
height: auto;
|
|
102
|
+
display: block;
|
|
103
|
+
margin: 0 auto 10px auto;
|
|
104
|
+
border-radius: 4px;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
107
|
+
</head>
|
|
108
|
+
<body>
|
|
109
|
+
<h1>${title}</h1>
|
|
110
|
+
<p>${description}</p>
|
|
111
|
+
<div class="gallery-container">
|
|
112
|
+
${imageHtml}
|
|
113
|
+
</div>
|
|
114
|
+
</body>
|
|
115
|
+
</html>
|
|
116
|
+
`;
|
|
117
|
+
await fs.writeFile(htmlFilePath, htmlContent);
|
|
118
|
+
log(`[ImageGalleryNode] Generated HTML gallery at: ${htmlFilePath}`, this.params.logging);
|
|
119
|
+
// Open the HTML file in the default web browser
|
|
120
|
+
const openBrowserCommand = os.platform() === 'darwin' ? `open "${htmlFilePath}"` :
|
|
121
|
+
os.platform() === 'win32' ? `start "" "${htmlFilePath}"` :
|
|
122
|
+
`xdg-open "${htmlFilePath}"`;
|
|
123
|
+
const shellNode = new ShellCommandNode();
|
|
124
|
+
shellNode.setParams({ command: openBrowserCommand });
|
|
125
|
+
await new AsyncFlow(shellNode).runAsync({});
|
|
126
|
+
log(`[ImageGalleryNode] Opened gallery in browser.`, this.params.logging);
|
|
127
|
+
return { status: 'gallery_displayed', htmlFilePath: htmlFilePath, imageCount: imagePaths.length };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export * from "./llm.js";
|
|
2
|
+
export * from "./agent_llm.js";
|
|
3
|
+
export * from "./data_extractor.js";
|
|
4
|
+
export * from "./code_interpreter.js";
|
|
5
|
+
export * from "./hackernews.js";
|
|
6
|
+
export * from "./github.js";
|
|
7
|
+
export * from "./stripe.js";
|
|
8
|
+
export * from "./webscraper.js";
|
|
9
|
+
export * from "./browser_control.js";
|
|
10
|
+
export * from "./system_notification.js";
|
|
11
|
+
export * from "./interactive_input.js";
|
|
12
|
+
export * from "./pdf_processor.js";
|
|
13
|
+
export * from "./gis.js";
|
|
14
|
+
export * from "./display_image.js";
|
|
15
|
+
export * from "./hardware_interaction.js";
|
|
16
|
+
export * from "./webhook.js";
|
|
17
|
+
export * from "./scheduler.js";
|
|
18
|
+
export * from "./image_gallery.js";
|
|
19
|
+
export * from "./speech_synthesis.js";
|
|
20
|
+
export * from "./multimedia_processing.js";
|
|
21
|
+
export * from "./remote_execution.js";
|
|
22
|
+
export * from "./data_validation.js";
|
|
23
|
+
export * from "./spreadsheet.js";
|
|
24
|
+
export * from "./shell.js";
|
|
25
|
+
export * from "./filesystem.js";
|
|
26
|
+
export * from "./user.js";
|
|
27
|
+
export * from "./http.js";
|
|
28
|
+
export * from "./http_server.js";
|
|
29
|
+
export * from "./search.js";
|
|
30
|
+
export * from "./summarize.js";
|
|
31
|
+
export * from "./memory.js";
|
|
32
|
+
export * from "./transform.js";
|
|
33
|
+
export * from "./embedding.js";
|
|
34
|
+
export * from "./semantic_memory.js";
|
|
35
|
+
export * from "./semantic_memory.js";
|
|
36
|
+
export * from "../agent/agent.js";
|
|
37
|
+
export * from "./subflow.js";
|
|
38
|
+
export * from "./iterator.js";
|
|
39
|
+
export * from "./openrouter_llm.js";
|
|
40
|
+
export * from "./database.js";
|
|
41
|
+
export * from "./s3.js";
|
|
42
|
+
export * from "../agent/base_agent.js";
|
|
43
|
+
export * from "../agent/raor_agent.js";
|
|
44
|
+
export * from "../agent/ooda_agent.js";
|
|
45
|
+
export * from "../agent/lpavrl_agent.js";
|
|
46
|
+
export * from "../agent/pema_agent.js";
|
|
47
|
+
export * from "./webview.js";
|
|
48
|
+
export * from "./interactive_webview.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export * from './llm.js';
|
|
2
|
+
export * from './agent_llm.js';
|
|
3
|
+
export * from './data_extractor.js';
|
|
4
|
+
export * from './code_interpreter.js';
|
|
5
|
+
export * from './hackernews.js';
|
|
6
|
+
export * from './github.js';
|
|
7
|
+
export * from './stripe.js';
|
|
8
|
+
export * from './webscraper.js';
|
|
9
|
+
export * from './browser_control.js';
|
|
10
|
+
export * from './system_notification.js';
|
|
11
|
+
export * from './interactive_input.js';
|
|
12
|
+
export * from './pdf_processor.js';
|
|
13
|
+
export * from './gis.js';
|
|
14
|
+
export * from './display_image.js';
|
|
15
|
+
export * from './hardware_interaction.js';
|
|
16
|
+
export * from './webhook.js';
|
|
17
|
+
export * from './scheduler.js';
|
|
18
|
+
export * from './image_gallery.js';
|
|
19
|
+
export * from './speech_synthesis.js';
|
|
20
|
+
export * from './multimedia_processing.js';
|
|
21
|
+
export * from './remote_execution.js';
|
|
22
|
+
export * from './data_validation.js';
|
|
23
|
+
export * from './spreadsheet.js';
|
|
24
|
+
export * from './shell.js';
|
|
25
|
+
export * from './filesystem.js';
|
|
26
|
+
export * from './user.js';
|
|
27
|
+
export * from './http.js';
|
|
28
|
+
export * from './http_server.js';
|
|
29
|
+
export * from './search.js';
|
|
30
|
+
export * from './summarize.js';
|
|
31
|
+
export * from './memory.js';
|
|
32
|
+
export * from './transform.js';
|
|
33
|
+
export * from './embedding.js';
|
|
34
|
+
export * from './semantic_memory.js';
|
|
35
|
+
export * from './semantic_memory.js';
|
|
36
|
+
export * from '../agent/agent.js';
|
|
37
|
+
export * from './subflow.js';
|
|
38
|
+
export * from './iterator.js';
|
|
39
|
+
export * from './openrouter_llm.js';
|
|
40
|
+
export * from './database.js';
|
|
41
|
+
export * from './s3.js';
|
|
42
|
+
export * from '../agent/base_agent.js';
|
|
43
|
+
export * from '../agent/raor_agent.js';
|
|
44
|
+
export * from '../agent/ooda_agent.js';
|
|
45
|
+
export * from '../agent/lpavrl_agent.js';
|
|
46
|
+
export * from '../agent/pema_agent.js';
|
|
47
|
+
export * from './webview.js';
|
|
48
|
+
export * from './interactive_webview.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class InteractiveInputNode 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
|
+
title: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
defaultValue: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
required: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
execAsync(): Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,95 @@
|
|
|
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 InteractiveInputNode extends AsyncNode {
|
|
6
|
+
static getToolDefinition() {
|
|
7
|
+
return {
|
|
8
|
+
name: "interactive_input",
|
|
9
|
+
description: "Prompts the user for input via a GUI popup (cross-platform).",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
prompt: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The message to display in the input dialog."
|
|
16
|
+
},
|
|
17
|
+
title: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Optional. The title of the input dialog. Defaults to 'QFlow Input'."
|
|
20
|
+
},
|
|
21
|
+
defaultValue: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Optional. The default value to pre-fill in the input field."
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
required: ["prompt"]
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
31
|
+
super(maxRetries, wait);
|
|
32
|
+
}
|
|
33
|
+
async execAsync() {
|
|
34
|
+
const { prompt, title = 'QFlow Input', defaultValue = '' } = this.params;
|
|
35
|
+
if (!prompt) {
|
|
36
|
+
throw new Error('InteractiveInputNode requires a `prompt` parameter.');
|
|
37
|
+
}
|
|
38
|
+
let command = '';
|
|
39
|
+
const platform = os.platform();
|
|
40
|
+
switch (platform) {
|
|
41
|
+
case 'linux':
|
|
42
|
+
let linuxCommand = '';
|
|
43
|
+
try {
|
|
44
|
+
await new Promise((res, rej) => exec('which zenity', (e) => e ? rej(e) : res()));
|
|
45
|
+
linuxCommand = `zenity --entry --title="${title}" --text="${prompt}" --entry-text="${defaultValue}"`;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
try {
|
|
49
|
+
await new Promise((res, rej) => exec('which kdialog', (e) => e ? rej(e) : res()));
|
|
50
|
+
linuxCommand = `kdialog --inputbox "${prompt}" "${defaultValue}" --title "${title}"`;
|
|
51
|
+
}
|
|
52
|
+
catch (e2) {
|
|
53
|
+
throw new Error('No GUI input tool (zenity or kdialog) found on Linux. Please install one or use UserInputNode.');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
command = linuxCommand;
|
|
57
|
+
break;
|
|
58
|
+
case 'darwin': // macOS
|
|
59
|
+
// osascript -e 'set T to text returned of (display dialog "PROMPT" default answer "DEFAULT" with title "TITLE")'
|
|
60
|
+
command = `osascript -e 'set T to text returned of (display dialog "${prompt}" default answer "${defaultValue}" with title "${title}")'`;
|
|
61
|
+
break;
|
|
62
|
+
case 'win32': // Windows
|
|
63
|
+
// PowerShell for input box
|
|
64
|
+
// (New-Object -TypeName Microsoft.VisualBasic.Interaction).InputBox("PROMPT", "TITLE", "DEFAULT")
|
|
65
|
+
command = `powershell -Command "(New-Object -TypeName Microsoft.VisualBasic.Interaction).InputBox('${prompt}', '${title}', '${defaultValue}')"`;
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(`Unsupported platform for InteractiveInputNode: ${platform}`);
|
|
69
|
+
}
|
|
70
|
+
log(`[InteractiveInputNode] Executing: ${command}`, this.params.logging);
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
exec(command, (error, stdout, stderr) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
// User cancelled the dialog or tool not found
|
|
75
|
+
log(`InteractiveInputNode error: ${error.message}`, this.params.logging, { type: 'error' });
|
|
76
|
+
// Differentiate between user cancellation and actual error
|
|
77
|
+
if (error.code === 1 && platform === 'linux' && error.message.includes('zenity')) {
|
|
78
|
+
// Zenity returns 1 on cancel
|
|
79
|
+
return resolve(null); // Or reject with a specific message
|
|
80
|
+
}
|
|
81
|
+
if (error.message.includes('User canceled')) { // osascript cancel
|
|
82
|
+
return resolve(null);
|
|
83
|
+
}
|
|
84
|
+
return reject(error);
|
|
85
|
+
}
|
|
86
|
+
if (stderr) {
|
|
87
|
+
log(`InteractiveInputNode stderr: ${stderr}`, this.params.logging, { type: 'warn' });
|
|
88
|
+
}
|
|
89
|
+
const userInput = stdout.trim();
|
|
90
|
+
log(`User input received: "${userInput}"`, this.params.logging);
|
|
91
|
+
resolve(userInput);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|