@fractal-solutions/qflow 1.0.58 → 1.0.60
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 +77 -1
- package/dist/logger.d.ts +9 -0
- package/dist/logger.js +107 -0
- package/dist/nodes/agent_llm.js +14 -13
- package/dist/nodes/code_interpreter.js +4 -3
- package/dist/nodes/data_extractor.js +5 -4
- package/dist/nodes/display_image.js +5 -4
- package/dist/nodes/embedding.js +3 -2
- package/dist/nodes/filesystem.js +9 -8
- package/dist/nodes/github.js +5 -4
- package/dist/nodes/hackernews.js +6 -5
- package/dist/nodes/hardware_interaction.js +3 -2
- package/dist/nodes/http.js +2 -1
- package/dist/nodes/http_server.js +6 -5
- package/dist/nodes/image_gallery.js +4 -3
- package/dist/nodes/index.d.ts +2 -0
- package/dist/nodes/index.js +2 -0
- package/dist/nodes/interactive_input.js +5 -4
- package/dist/nodes/interactive_webview.d.ts +19 -0
- package/dist/nodes/interactive_webview.js +310 -0
- package/dist/nodes/llm.js +15 -14
- package/dist/nodes/multimedia_processing.js +3 -2
- package/dist/nodes/openrouter_llm.js +7 -6
- package/dist/nodes/remote_execution.js +3 -2
- package/dist/nodes/scheduler.js +12 -11
- package/dist/nodes/search.js +3 -2
- package/dist/nodes/semantic_memory.js +5 -4
- package/dist/nodes/stripe.js +5 -4
- package/dist/nodes/summarize.js +3 -2
- package/dist/nodes/system_notification.js +5 -4
- package/dist/nodes/transform.js +2 -1
- package/dist/nodes/webhook.js +12 -11
- package/dist/nodes/webscraper.js +4 -3
- package/dist/nodes/webview.d.ts +12 -0
- package/dist/nodes/webview.js +27 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { URL } from 'url';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { promises as fsPromises } from 'fs';
|
|
6
6
|
import fs from 'fs';
|
|
7
|
+
import { log } from '../logger.js';
|
|
7
8
|
// Basic mime-type lookup to avoid adding new dependencies
|
|
8
9
|
function getMimeType(filePath) {
|
|
9
10
|
const ext = path.extname(filePath).toLowerCase();
|
|
@@ -91,7 +92,7 @@ export class HttpServerNode extends AsyncNode {
|
|
|
91
92
|
async execAsync() {
|
|
92
93
|
const { port = 3000, routes = {}, staticDir, cors } = this.params;
|
|
93
94
|
if (this.server && this.server.listening) {
|
|
94
|
-
|
|
95
|
+
log(`[HttpServerNode] Server already listening on port ${port}.`, this.params.logging, { type: 'warn' });
|
|
95
96
|
return { status: 'server_already_running', port };
|
|
96
97
|
}
|
|
97
98
|
this.server = http.createServer(async (req, res) => {
|
|
@@ -120,7 +121,7 @@ export class HttpServerNode extends AsyncNode {
|
|
|
120
121
|
}
|
|
121
122
|
const { flow, params: pathParams } = routeMatch;
|
|
122
123
|
if (!(flow instanceof AsyncFlow)) {
|
|
123
|
-
|
|
124
|
+
log(`[HttpServerNode] Handler for ${req.method} ${reqPath} is not an AsyncFlow.`, this.params.logging, { type: 'error' });
|
|
124
125
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
125
126
|
res.end(JSON.stringify({ error: 'Internal Server Error: Invalid handler' }));
|
|
126
127
|
return;
|
|
@@ -162,7 +163,7 @@ export class HttpServerNode extends AsyncNode {
|
|
|
162
163
|
res.end(responseBody);
|
|
163
164
|
}
|
|
164
165
|
catch (flowError) {
|
|
165
|
-
|
|
166
|
+
log(`[HttpServerNode] Flow for ${req.method} ${reqPath} failed:`, this.params.logging, { type: 'error' });
|
|
166
167
|
if (!res.writableEnded) {
|
|
167
168
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
168
169
|
res.end(JSON.stringify({ error: 'Flow execution failed', details: flowError.message }));
|
|
@@ -172,11 +173,11 @@ export class HttpServerNode extends AsyncNode {
|
|
|
172
173
|
});
|
|
173
174
|
await new Promise((resolve, reject) => {
|
|
174
175
|
this.server.on('error', (err) => {
|
|
175
|
-
|
|
176
|
+
log(`[HttpServerNode] Failed to start server on port ${port}:`, this.params.logging, { type: 'error' });
|
|
176
177
|
reject(err);
|
|
177
178
|
});
|
|
178
179
|
this.server.listen(port, () => {
|
|
179
|
-
|
|
180
|
+
log(`[HttpServerNode] Listening on http://localhost:${port}`, this.params.logging);
|
|
180
181
|
resolve();
|
|
181
182
|
});
|
|
182
183
|
});
|
|
@@ -3,6 +3,7 @@ import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is a
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import { promises as fs } from 'fs';
|
|
6
|
+
import { log } from '../logger.js';
|
|
6
7
|
export class ImageGalleryNode extends AsyncNode {
|
|
7
8
|
constructor(maxRetries = 1, wait = 0) {
|
|
8
9
|
super(maxRetries, wait);
|
|
@@ -36,7 +37,7 @@ export class ImageGalleryNode extends AsyncNode {
|
|
|
36
37
|
imageHtml += `</div>\n`;
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
39
|
-
|
|
40
|
+
log(`[ImageGalleryNode] Could not copy image ${imagePath}: ${e.message}. Skipping.`, this.params.logging, { type: 'warn' });
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
const htmlContent = `
|
|
@@ -85,7 +86,7 @@ export class ImageGalleryNode extends AsyncNode {
|
|
|
85
86
|
</html>
|
|
86
87
|
`;
|
|
87
88
|
await fs.writeFile(htmlFilePath, htmlContent);
|
|
88
|
-
|
|
89
|
+
log(`[ImageGalleryNode] Generated HTML gallery at: ${htmlFilePath}`, this.params.logging);
|
|
89
90
|
// Open the HTML file in the default web browser
|
|
90
91
|
const openBrowserCommand = os.platform() === 'darwin' ? `open "${htmlFilePath}"` :
|
|
91
92
|
os.platform() === 'win32' ? `start "" "${htmlFilePath}"` :
|
|
@@ -93,7 +94,7 @@ export class ImageGalleryNode extends AsyncNode {
|
|
|
93
94
|
const shellNode = new ShellCommandNode();
|
|
94
95
|
shellNode.setParams({ command: openBrowserCommand });
|
|
95
96
|
await new AsyncFlow(shellNode).runAsync({});
|
|
96
|
-
|
|
97
|
+
log(`[ImageGalleryNode] Opened gallery in browser.`, this.params.logging);
|
|
97
98
|
return { status: 'gallery_displayed', htmlFilePath: htmlFilePath, imageCount: imagePaths.length };
|
|
98
99
|
}
|
|
99
100
|
}
|
package/dist/nodes/index.d.ts
CHANGED
package/dist/nodes/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
2
|
import { exec } from 'child_process';
|
|
3
3
|
import os from 'os';
|
|
4
|
+
import { log } from '../logger.js';
|
|
4
5
|
export class InteractiveInputNode extends AsyncNode {
|
|
5
6
|
constructor(maxRetries = 1, wait = 0) {
|
|
6
7
|
super(maxRetries, wait);
|
|
@@ -42,12 +43,12 @@ export class InteractiveInputNode extends AsyncNode {
|
|
|
42
43
|
default:
|
|
43
44
|
throw new Error(`Unsupported platform for InteractiveInputNode: ${platform}`);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
log(`[InteractiveInputNode] Executing: ${command}`, this.params.logging);
|
|
46
47
|
return new Promise((resolve, reject) => {
|
|
47
48
|
exec(command, (error, stdout, stderr) => {
|
|
48
49
|
if (error) {
|
|
49
50
|
// User cancelled the dialog or tool not found
|
|
50
|
-
|
|
51
|
+
log(`InteractiveInputNode error: ${error.message}`, this.params.logging, { type: 'error' });
|
|
51
52
|
// Differentiate between user cancellation and actual error
|
|
52
53
|
if (error.code === 1 && platform === 'linux' && error.message.includes('zenity')) {
|
|
53
54
|
// Zenity returns 1 on cancel
|
|
@@ -59,10 +60,10 @@ export class InteractiveInputNode extends AsyncNode {
|
|
|
59
60
|
return reject(error);
|
|
60
61
|
}
|
|
61
62
|
if (stderr) {
|
|
62
|
-
|
|
63
|
+
log(`InteractiveInputNode stderr: ${stderr}`, this.params.logging, { type: 'warn' });
|
|
63
64
|
}
|
|
64
65
|
const userInput = stdout.trim();
|
|
65
|
-
|
|
66
|
+
log(`User input received: "${userInput}"`, this.params.logging);
|
|
66
67
|
resolve(userInput);
|
|
67
68
|
});
|
|
68
69
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A node that displays an interactive webview window.
|
|
3
|
+
* It can be used for dialogs, user input, and notifications.
|
|
4
|
+
* The result from the user interaction is passed to the next node.
|
|
5
|
+
*/
|
|
6
|
+
export class InteractiveWebviewNode extends AsyncNode {
|
|
7
|
+
constructor();
|
|
8
|
+
_webviewInstance: Webview | null;
|
|
9
|
+
execAsync(): Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Sends data or executes JavaScript within an open persistent webview.
|
|
12
|
+
* @param {string} script - The JavaScript code to execute in the webview.
|
|
13
|
+
*/
|
|
14
|
+
sendToWebview(script: string): void;
|
|
15
|
+
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
16
|
+
generateHTML(mode: any, params: any): string;
|
|
17
|
+
}
|
|
18
|
+
import { AsyncNode } from '../qflow.js';
|
|
19
|
+
import { Webview } from 'webview-bun';
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { Webview, SizeHint } from 'webview-bun';
|
|
3
|
+
import { log } from '../logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* A node that displays an interactive webview window.
|
|
6
|
+
* It can be used for dialogs, user input, and notifications.
|
|
7
|
+
* The result from the user interaction is passed to the next node.
|
|
8
|
+
*/
|
|
9
|
+
export class InteractiveWebviewNode extends AsyncNode {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._webviewInstance = null; // Store webview instance for sendToWebview
|
|
13
|
+
}
|
|
14
|
+
async execAsync() {
|
|
15
|
+
const { mode = 'notification', // 'notification', 'dialog', 'input'
|
|
16
|
+
message = '', options = [], // for dialog mode
|
|
17
|
+
prompt = '', // for input mode
|
|
18
|
+
title = 'Qflow', width = 400, height = 220, theme = 'light', // 'light', 'dark'
|
|
19
|
+
persistent = false, // New parameter for persistent webview
|
|
20
|
+
html = '', // New parameter for custom HTML content
|
|
21
|
+
multilineInput = false, // New parameter for multi-line input
|
|
22
|
+
} = this.params;
|
|
23
|
+
log(`[InteractiveWebviewNode] Creating '${mode}' webview with title: "${title}"`, this.params.logging);
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const webview = new Webview(false, {
|
|
26
|
+
width,
|
|
27
|
+
height,
|
|
28
|
+
hint: SizeHint.FIXED,
|
|
29
|
+
});
|
|
30
|
+
webview.title = title;
|
|
31
|
+
this._webviewInstance = webview; // Always store the instance
|
|
32
|
+
webview.bind('qflow', (result) => {
|
|
33
|
+
// This is the crucial part: qflow() from webview resolves execAsync
|
|
34
|
+
// If persistent, we still resolve, but the webview stays open.
|
|
35
|
+
// The flow will then continue.
|
|
36
|
+
resolve(result);
|
|
37
|
+
if (!persistent) {
|
|
38
|
+
webview.destroy();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
let contentHtml;
|
|
42
|
+
if (mode === 'custom') {
|
|
43
|
+
if (!html) {
|
|
44
|
+
throw new Error('InteractiveWebviewNode in custom mode requires an `html` parameter.');
|
|
45
|
+
}
|
|
46
|
+
contentHtml = html;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
contentHtml = this.generateHTML(mode, { message, options, prompt, title, theme, multilineInput });
|
|
50
|
+
}
|
|
51
|
+
webview.setHTML(contentHtml);
|
|
52
|
+
webview.run(); // This is a blocking call
|
|
53
|
+
// This log will only be reached after webview.run() exits (i.e., webview is closed)
|
|
54
|
+
log(`[InteractiveWebviewNode] Webview window closed.`, this.params.logging);
|
|
55
|
+
// If persistent, and webview.run() exits, it means the user closed it manually.
|
|
56
|
+
// In this case, we should resolve with a 'closed' status if not already resolved.
|
|
57
|
+
// However, the resolve(result) in webview.bind handles the primary interaction.
|
|
58
|
+
// If the webview is closed without qflow() being called, the promise might hang.
|
|
59
|
+
// Let's add a fallback resolve if webview.run() exits without qflow() being called.
|
|
60
|
+
// This is complex with blocking run().
|
|
61
|
+
// For now, assume qflow() is always called before manual close for persistent.
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sends data or executes JavaScript within an open persistent webview.
|
|
66
|
+
* @param {string} script - The JavaScript code to execute in the webview.
|
|
67
|
+
*/
|
|
68
|
+
sendToWebview(script) {
|
|
69
|
+
if (this._webviewInstance && this._webviewInstance.unsafeHandle) {
|
|
70
|
+
this._webviewInstance.eval(script);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
log(`[InteractiveWebviewNode] Cannot send to webview: no persistent webview instance found.`, this.params.logging, { type: 'warn' });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async postAsync(shared, prepRes, execRes) {
|
|
77
|
+
shared.webviewResult = execRes;
|
|
78
|
+
return 'default';
|
|
79
|
+
}
|
|
80
|
+
generateHTML(mode, params) {
|
|
81
|
+
const { message, options, prompt, title, theme, multilineInput } = params;
|
|
82
|
+
const lightTheme = `
|
|
83
|
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
|
|
84
|
+
:root {
|
|
85
|
+
--primary-color: #007bff;
|
|
86
|
+
--bg-color: #f4f6f8;
|
|
87
|
+
--border-color: #d1d9e0;
|
|
88
|
+
--text-color: #212529;
|
|
89
|
+
--title-color: #212529;
|
|
90
|
+
--shadow-color: #007bff40;
|
|
91
|
+
}
|
|
92
|
+
body {
|
|
93
|
+
font-family: 'Orbitron', sans-serif;
|
|
94
|
+
background-color: var(--bg-color);
|
|
95
|
+
color: var(--text-color);
|
|
96
|
+
margin: 0;
|
|
97
|
+
padding: 1px;
|
|
98
|
+
overflow: auto;
|
|
99
|
+
user-select: none;
|
|
100
|
+
}
|
|
101
|
+
.container {
|
|
102
|
+
border: 1px solid var(--border-color);
|
|
103
|
+
height: calc(100vh - 2px);
|
|
104
|
+
width: calc(100vw - 2px);
|
|
105
|
+
display: flex;
|
|
106
|
+
flex-direction: column;
|
|
107
|
+
background-color: #ffffff;
|
|
108
|
+
box-shadow: 0 0 20px #0000001a;
|
|
109
|
+
}
|
|
110
|
+
.title-bar {
|
|
111
|
+
background-color: #e9ecef;
|
|
112
|
+
color: var(--title-color);
|
|
113
|
+
padding: 0.5rem;
|
|
114
|
+
text-align: center;
|
|
115
|
+
font-weight: bold;
|
|
116
|
+
border-bottom: 1px solid var(--border-color);
|
|
117
|
+
text-transform: uppercase;
|
|
118
|
+
letter-spacing: 2px;
|
|
119
|
+
}
|
|
120
|
+
.content {
|
|
121
|
+
flex-grow: 1;
|
|
122
|
+
padding: 1.5rem;
|
|
123
|
+
display: flex;
|
|
124
|
+
flex-direction: column;
|
|
125
|
+
justify-content: center;
|
|
126
|
+
align-items: center;
|
|
127
|
+
text-align: center;
|
|
128
|
+
}
|
|
129
|
+
h1 {
|
|
130
|
+
font-size: 1.2rem;
|
|
131
|
+
margin-bottom: 1rem;
|
|
132
|
+
color: var(--title-color);
|
|
133
|
+
}
|
|
134
|
+
.button-group {
|
|
135
|
+
display: flex;
|
|
136
|
+
flex-wrap: wrap; /* Allow buttons to wrap */
|
|
137
|
+
justify-content: center; /* Center buttons */
|
|
138
|
+
gap: 1rem;
|
|
139
|
+
margin-top: 1rem;
|
|
140
|
+
}
|
|
141
|
+
button {
|
|
142
|
+
background-color: var(--primary-color);
|
|
143
|
+
color: white;
|
|
144
|
+
border: 1px solid var(--primary-color);
|
|
145
|
+
padding: 0.6rem 1.2rem;
|
|
146
|
+
font-family: 'Orbitron', sans-serif;
|
|
147
|
+
font-size: 0.9rem;
|
|
148
|
+
font-weight: bold;
|
|
149
|
+
cursor: pointer;
|
|
150
|
+
transition: all 0.3s ease;
|
|
151
|
+
text-transform: uppercase;
|
|
152
|
+
}
|
|
153
|
+
button:hover {
|
|
154
|
+
background-color: #0056b3;
|
|
155
|
+
border-color: #0056b3;
|
|
156
|
+
}
|
|
157
|
+
input, textarea { /* Apply styles to textarea as well */
|
|
158
|
+
background-color: #ffffff;
|
|
159
|
+
border: 1px solid var(--border-color);
|
|
160
|
+
color: var(--text-color);
|
|
161
|
+
padding: 0.6rem;
|
|
162
|
+
width: 80%;
|
|
163
|
+
font-family: 'Orbitron', sans-serif;
|
|
164
|
+
font-size: 1rem;
|
|
165
|
+
margin-bottom: 1rem;
|
|
166
|
+
}
|
|
167
|
+
input:focus, textarea:focus {
|
|
168
|
+
outline: none;
|
|
169
|
+
border-color: var(--primary-color);
|
|
170
|
+
box-shadow: 0 0 8px var(--shadow-color);
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
173
|
+
const darkTheme = `
|
|
174
|
+
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
|
|
175
|
+
:root {
|
|
176
|
+
--primary-color: #00ffff;
|
|
177
|
+
--bg-color: #0a0a1a;
|
|
178
|
+
--border-color: #00ffff80;
|
|
179
|
+
--text-color: #e0e0e0;
|
|
180
|
+
--title-color: #ffffff;
|
|
181
|
+
--shadow-color: #00ffff40;
|
|
182
|
+
}
|
|
183
|
+
body {
|
|
184
|
+
font-family: 'Orbitron', sans-serif;
|
|
185
|
+
background-color: var(--bg-color);
|
|
186
|
+
color: var(--text-color);
|
|
187
|
+
margin: 0;
|
|
188
|
+
padding: 1px;
|
|
189
|
+
overflow: auto; /* Allow scrolling */
|
|
190
|
+
user-select: none;
|
|
191
|
+
}
|
|
192
|
+
.container {
|
|
193
|
+
border: 1px solid var(--border-color);
|
|
194
|
+
height: calc(100vh - 2px);
|
|
195
|
+
width: calc(100vw - 2px);
|
|
196
|
+
display: flex;
|
|
197
|
+
flex-direction: column;
|
|
198
|
+
background: radial-gradient(circle, rgba(10, 10, 26, 0.95) 0%, rgba(10, 10, 26, 0.85) 100%);
|
|
199
|
+
box-shadow: 0 0 20px var(--shadow-color);
|
|
200
|
+
}
|
|
201
|
+
.title-bar {
|
|
202
|
+
background-color: #00000030;
|
|
203
|
+
color: var(--title-color);
|
|
204
|
+
padding: 0.5rem;
|
|
205
|
+
text-align: center;
|
|
206
|
+
font-weight: bold;
|
|
207
|
+
border-bottom: 1px solid var(--border-color);
|
|
208
|
+
text-transform: uppercase;
|
|
209
|
+
letter-spacing: 2px;
|
|
210
|
+
text-shadow: 0 0 5px var(--primary-color);
|
|
211
|
+
}
|
|
212
|
+
.content {
|
|
213
|
+
flex-grow: 1;
|
|
214
|
+
padding: 1.5rem;
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
justify-content: center;
|
|
218
|
+
align-items: center;
|
|
219
|
+
text-align: center;
|
|
220
|
+
}
|
|
221
|
+
h1 {
|
|
222
|
+
font-size: 1.2rem;
|
|
223
|
+
margin-bottom: 1rem;
|
|
224
|
+
color: var(--title-color);
|
|
225
|
+
text-shadow: 0 0 8px var(--shadow-color);
|
|
226
|
+
}
|
|
227
|
+
.button-group {
|
|
228
|
+
display: flex;
|
|
229
|
+
flex-wrap: wrap; /* Allow buttons to wrap */
|
|
230
|
+
justify-content: center; /* Center buttons */
|
|
231
|
+
gap: 1rem;
|
|
232
|
+
margin-top: 1rem;
|
|
233
|
+
}
|
|
234
|
+
button {
|
|
235
|
+
background-color: transparent;
|
|
236
|
+
color: var(--primary-color);
|
|
237
|
+
border: 1px solid var(--primary-color);
|
|
238
|
+
padding: 0.6rem 1.2rem;
|
|
239
|
+
font-family: 'Orbitron', sans-serif;
|
|
240
|
+
font-size: 0.9rem;
|
|
241
|
+
font-weight: bold;
|
|
242
|
+
cursor: pointer;
|
|
243
|
+
transition: all 0.3s ease;
|
|
244
|
+
text-transform: uppercase;
|
|
245
|
+
box-shadow: 0 0 10px var(--shadow-color) inset;
|
|
246
|
+
}
|
|
247
|
+
button:hover {
|
|
248
|
+
background-color: var(--primary-color);
|
|
249
|
+
color: var(--bg-color);
|
|
250
|
+
box-shadow: 0 0 20px var(--shadow-color);
|
|
251
|
+
}
|
|
252
|
+
input, textarea { /* Apply styles to textarea as well */
|
|
253
|
+
background-color: #00000030;
|
|
254
|
+
border: 1px solid var(--border-color);
|
|
255
|
+
color: var(--text-color);
|
|
256
|
+
padding: 0.6rem;
|
|
257
|
+
width: 80%;
|
|
258
|
+
font-family: 'Orbitron', sans-serif;
|
|
259
|
+
font-size: 1rem;
|
|
260
|
+
margin-bottom: 1rem;
|
|
261
|
+
}
|
|
262
|
+
input:focus, textarea:focus {
|
|
263
|
+
outline: none;
|
|
264
|
+
border-color: var(--primary-color);
|
|
265
|
+
box-shadow: 0 0 10px var(--shadow-color);
|
|
266
|
+
}
|
|
267
|
+
`;
|
|
268
|
+
let contentHtml = '';
|
|
269
|
+
switch (mode) {
|
|
270
|
+
case 'dialog':
|
|
271
|
+
contentHtml = `
|
|
272
|
+
<h1>${message}</h1>
|
|
273
|
+
<div class="button-group">
|
|
274
|
+
${options.map(option => `<button onclick="qflow('${option}')">${option}</button>`).join('')}
|
|
275
|
+
</div>
|
|
276
|
+
`;
|
|
277
|
+
break;
|
|
278
|
+
case 'input':
|
|
279
|
+
const inputElement = multilineInput ?
|
|
280
|
+
`<textarea id="userInput" rows="10" style="width: 80%;"></textarea>` :
|
|
281
|
+
`<input type="text" id="userInput" onkeydown="if(event.key==='Enter') document.getElementById('submitBtn').click()"/>`;
|
|
282
|
+
contentHtml = `
|
|
283
|
+
<h1>${prompt}</h1>
|
|
284
|
+
${inputElement}
|
|
285
|
+
<button id="submitBtn" onclick="qflow(document.getElementById('userInput').value)">Submit</button>
|
|
286
|
+
`;
|
|
287
|
+
break;
|
|
288
|
+
case 'notification':
|
|
289
|
+
default:
|
|
290
|
+
contentHtml = `
|
|
291
|
+
<h1>${message}</h1>
|
|
292
|
+
<div class="button-group">
|
|
293
|
+
<button onclick="qflow('closed')">${theme === 'dark' ? 'Acknowledge' : 'Close'}</button>
|
|
294
|
+
</div>
|
|
295
|
+
`;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
const container = `<div class="container"><div class="title-bar">${title}</div><div class="content">${contentHtml}</div></div>`;
|
|
299
|
+
return `
|
|
300
|
+
<html>
|
|
301
|
+
<head>
|
|
302
|
+
<style>${theme === 'dark' ? darkTheme : lightTheme}</style>
|
|
303
|
+
</head>
|
|
304
|
+
<body>
|
|
305
|
+
${container}
|
|
306
|
+
</body>
|
|
307
|
+
</html>
|
|
308
|
+
`;
|
|
309
|
+
}
|
|
310
|
+
}
|
package/dist/nodes/llm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { log } from '../logger.js';
|
|
2
3
|
// --- Reusable LLM Node for DeepSeek ---
|
|
3
4
|
export class DeepSeekLLMNode extends AsyncNode {
|
|
4
5
|
constructor(maxRetries = 3, wait = 2) {
|
|
@@ -17,7 +18,7 @@ export class DeepSeekLLMNode extends AsyncNode {
|
|
|
17
18
|
if (!apiKey) {
|
|
18
19
|
throw new Error("DeepSeek API Key is not configured.");
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
log(`[DeepSeek] Sending prompt for "${keyword}"...`, this.params.logging);
|
|
21
22
|
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
|
22
23
|
method: 'POST',
|
|
23
24
|
headers: {
|
|
@@ -40,7 +41,7 @@ export class DeepSeekLLMNode extends AsyncNode {
|
|
|
40
41
|
throw new Error('Invalid response structure from DeepSeek API.');
|
|
41
42
|
}
|
|
42
43
|
const llmResponse = data.choices[0].message.content.trim();
|
|
43
|
-
|
|
44
|
+
log(`[DeepSeek] Received response for "${keyword}".`, this.params.logging);
|
|
44
45
|
return llmResponse; // Return the actual content
|
|
45
46
|
}
|
|
46
47
|
}
|
|
@@ -53,7 +54,7 @@ export class OpenAILLMNode extends AsyncNode {
|
|
|
53
54
|
if (!apiKey) {
|
|
54
55
|
throw new Error('OpenAI API Key is required.');
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
log(`OpenAILLMNode: Sending prompt to OpenAI: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
57
58
|
try {
|
|
58
59
|
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
59
60
|
method: 'POST',
|
|
@@ -73,11 +74,11 @@ export class OpenAILLMNode extends AsyncNode {
|
|
|
73
74
|
}
|
|
74
75
|
const data = await response.json();
|
|
75
76
|
const llmResponse = data.choices[0].message.content.trim();
|
|
76
|
-
|
|
77
|
+
log(`OpenAILLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
77
78
|
return llmResponse; // Return the LLM's response
|
|
78
79
|
}
|
|
79
80
|
catch (error) {
|
|
80
|
-
|
|
81
|
+
log('OpenAILLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
81
82
|
throw error; // Re-throw to trigger qflow's retry/fallback
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -91,7 +92,7 @@ export class GeminiLLMNode extends AsyncNode {
|
|
|
91
92
|
if (!apiKey) {
|
|
92
93
|
throw new Error('Google Gemini API Key is required.');
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
log(`GeminiLLMNode: Sending prompt to Gemini: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
95
96
|
try {
|
|
96
97
|
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`, {
|
|
97
98
|
method: 'POST',
|
|
@@ -108,11 +109,11 @@ export class GeminiLLMNode extends AsyncNode {
|
|
|
108
109
|
}
|
|
109
110
|
const data = await response.json();
|
|
110
111
|
const llmResponse = data.candidates[0].content.parts[0].text.trim();
|
|
111
|
-
|
|
112
|
+
log(`GeminiLLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
112
113
|
return llmResponse; // Return the LLM's response
|
|
113
114
|
}
|
|
114
115
|
catch (error) {
|
|
115
|
-
|
|
116
|
+
log('GeminiLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
116
117
|
throw error; // Re-throw to trigger qflow's retry/fallback
|
|
117
118
|
}
|
|
118
119
|
}
|
|
@@ -131,7 +132,7 @@ export class OllamaLLMNode extends AsyncNode {
|
|
|
131
132
|
if (!prompt) {
|
|
132
133
|
throw new Error('Prompt is required for OllamaLLMNode.');
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
+
log(`[Ollama] Sending prompt to ${model} at ${baseUrl}: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
135
136
|
try {
|
|
136
137
|
const response = await fetch(`${baseUrl}/api/generate`, {
|
|
137
138
|
method: 'POST',
|
|
@@ -150,11 +151,11 @@ export class OllamaLLMNode extends AsyncNode {
|
|
|
150
151
|
}
|
|
151
152
|
const data = await response.json();
|
|
152
153
|
const llmResponse = data.response.trim();
|
|
153
|
-
|
|
154
|
+
log(`[Ollama] Received response from ${model}: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
154
155
|
return llmResponse;
|
|
155
156
|
}
|
|
156
157
|
catch (error) {
|
|
157
|
-
|
|
158
|
+
log('OllamaLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
158
159
|
throw error;
|
|
159
160
|
}
|
|
160
161
|
}
|
|
@@ -187,7 +188,7 @@ export class HuggingFaceLLMNode extends AsyncNode {
|
|
|
187
188
|
max_tokens: max_new_tokens,
|
|
188
189
|
// Add other OpenAI-compatible parameters as needed
|
|
189
190
|
});
|
|
190
|
-
|
|
191
|
+
log(`[HuggingFace] Sending prompt to ${model} at ${baseUrl}...`, this.params.logging);
|
|
191
192
|
try {
|
|
192
193
|
const response = await fetch(url, {
|
|
193
194
|
method: 'POST',
|
|
@@ -203,11 +204,11 @@ export class HuggingFaceLLMNode extends AsyncNode {
|
|
|
203
204
|
throw new Error('Invalid response structure from Hugging Face API.');
|
|
204
205
|
}
|
|
205
206
|
const llmResponse = data.choices[0].message.content.trim();
|
|
206
|
-
|
|
207
|
+
log(`[HuggingFace] Received response from ${model}.`, this.params.logging);
|
|
207
208
|
return llmResponse;
|
|
208
209
|
}
|
|
209
210
|
catch (error) {
|
|
210
|
-
|
|
211
|
+
log('HuggingFaceLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
211
212
|
throw error;
|
|
212
213
|
}
|
|
213
214
|
}
|
|
@@ -3,6 +3,7 @@ import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is a
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import { promises as fs } from 'fs';
|
|
6
|
+
import { log } from '../logger.js';
|
|
6
7
|
export class MultimediaProcessingNode extends AsyncNode {
|
|
7
8
|
constructor(maxRetries = 1, wait = 0) {
|
|
8
9
|
super(maxRetries, wait);
|
|
@@ -62,13 +63,13 @@ export class MultimediaProcessingNode extends AsyncNode {
|
|
|
62
63
|
default:
|
|
63
64
|
throw new Error(`Unsupported action: ${action}`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
log(`[MultimediaProcessingNode] Executing: ${ffmpegCommand}`, this.params.logging);
|
|
66
67
|
const shellNode = new ShellCommandNode();
|
|
67
68
|
shellNode.setParams({ command: ffmpegCommand });
|
|
68
69
|
try {
|
|
69
70
|
const result = await new AsyncFlow(shellNode).runAsync({});
|
|
70
71
|
if (result.stderr) {
|
|
71
|
-
|
|
72
|
+
log(`[MultimediaProcessingNode] ffmpeg warnings/errors: ${result.stderr}`, this.params.logging, { type: 'warn' });
|
|
72
73
|
}
|
|
73
74
|
return { status: 'success', action: action, outputPath: outputPath, stdout: result.stdout, stderr: result.stderr };
|
|
74
75
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { log } from '../logger.js';
|
|
2
3
|
export class OpenRouterLLMNode extends AsyncNode {
|
|
3
4
|
constructor(maxRetries = 3, wait = 2) {
|
|
4
5
|
super(maxRetries, wait);
|
|
@@ -24,7 +25,7 @@ export class OpenRouterLLMNode extends AsyncNode {
|
|
|
24
25
|
if (siteTitle) {
|
|
25
26
|
headers['X-Title'] = siteTitle;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
log(`[OpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
28
29
|
try {
|
|
29
30
|
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
30
31
|
method: 'POST',
|
|
@@ -43,11 +44,11 @@ export class OpenRouterLLMNode extends AsyncNode {
|
|
|
43
44
|
throw new Error('Invalid response structure from OpenRouter API.');
|
|
44
45
|
}
|
|
45
46
|
const llmResponse = data.choices[0].message.content.trim();
|
|
46
|
-
|
|
47
|
+
log(`[OpenRouter] Received response from ${model}.`, this.params.logging);
|
|
47
48
|
return llmResponse;
|
|
48
49
|
}
|
|
49
50
|
catch (error) {
|
|
50
|
-
|
|
51
|
+
log('OpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
51
52
|
throw error;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -85,7 +86,7 @@ export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
|
85
86
|
if (siteTitle) {
|
|
86
87
|
headers['X-Title'] = siteTitle;
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
+
log(`[AgentOpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
89
90
|
try {
|
|
90
91
|
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
91
92
|
method: 'POST',
|
|
@@ -104,11 +105,11 @@ export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
|
104
105
|
throw new Error('Invalid response structure from OpenRouter API or missing content.');
|
|
105
106
|
}
|
|
106
107
|
const llmResponse = data.choices[0].message.content.trim();
|
|
107
|
-
|
|
108
|
+
log(`[AgentOpenRouter] Received response from ${model}.`, this.params.logging);
|
|
108
109
|
return llmResponse; // Return the actual content
|
|
109
110
|
}
|
|
110
111
|
catch (error) {
|
|
111
|
-
|
|
112
|
+
log('AgentOpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
112
113
|
throw error;
|
|
113
114
|
}
|
|
114
115
|
}
|