@fractal-solutions/qflow 1.0.57 → 1.0.59

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.
@@ -44,3 +44,5 @@ export * from '../agent/raor_agent.js';
44
44
  export * from '../agent/ooda_agent.js';
45
45
  export * from '../agent/lpavrl_agent.js';
46
46
  export * from '../agent/pema_agent.js';
47
+ export * from './webview.js';
48
+ export * from './interactive_webview.js';
@@ -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
- console.log(`[InteractiveInputNode] Executing: ${command}`);
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
- console.error(`InteractiveInputNode error: ${error.message}`);
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
- console.warn(`InteractiveInputNode stderr: ${stderr}`);
63
+ log(`InteractiveInputNode stderr: ${stderr}`, this.params.logging, { type: 'warn' });
63
64
  }
64
65
  const userInput = stdout.trim();
65
- console.log(`User input received: "${userInput}"`);
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
- console.log(`[DeepSeek] Sending prompt for \"${keyword}\"...`);
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
- console.log(`[DeepSeek] Received response for \"${keyword}\".`);
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
- console.log(`OpenAILLMNode: Sending prompt to OpenAI: \"${prompt.substring(0, 50)}\"...`);
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
- console.log(`OpenAILLMNode: Received response: \"${llmResponse.substring(0, 50)}\"...`);
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
- console.error('OpenAILLMNode: Error during API call:', error);
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
- console.log(`GeminiLLMNode: Sending prompt to Gemini: "${prompt.substring(0, 50)}"...`);
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
- console.log(`GeminiLLMNode: Received response: "${llmResponse.substring(0, 50)}"...`);
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
- console.error('GeminiLLMNode: Error during API call:', error);
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
- console.log(`[Ollama] Sending prompt to ${model} at ${baseUrl}: "${prompt.substring(0, 50)}"...`);
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
- console.log(`[Ollama] Received response from ${model}: "${llmResponse.substring(0, 50)}"...`);
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
- console.error('OllamaLLMNode: Error during API call:', error);
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
- console.log(`[HuggingFace] Sending prompt to ${model} at ${baseUrl}...`);
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
- console.log(`[HuggingFace] Received response from ${model}.`);
207
+ log(`[HuggingFace] Received response from ${model}.`, this.params.logging);
207
208
  return llmResponse;
208
209
  }
209
210
  catch (error) {
210
- console.error('HuggingFaceLLMNode: Error during API call:', error);
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
- console.log(`[MultimediaProcessingNode] Executing: ${ffmpegCommand}`);
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
- console.warn(`[MultimediaProcessingNode] ffmpeg warnings/errors: ${result.stderr}`);
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
- console.log(`[OpenRouter] Sending prompt to ${model}...`);
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
- console.log(`[OpenRouter] Received response from ${model}.`);
47
+ log(`[OpenRouter] Received response from ${model}.`, this.params.logging);
47
48
  return llmResponse;
48
49
  }
49
50
  catch (error) {
50
- console.error('OpenRouterLLMNode: Error during API call:', error);
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
- console.log(`[AgentOpenRouter] Sending prompt to ${model}...`);
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
- console.log(`[AgentOpenRouter] Received response from ${model}.`);
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
- console.error('AgentOpenRouterLLMNode: Error during API call:', error);
112
+ log('AgentOpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
112
113
  throw error;
113
114
  }
114
115
  }
@@ -1,6 +1,7 @@
1
1
  import { AsyncNode } from '../qflow.js';
2
2
  // You would need to install the 'ssh2' library: npm install ssh2
3
3
  import { Client } from 'ssh2';
4
+ import { log } from '../logger.js';
4
5
  export class RemoteExecutionNode extends AsyncNode {
5
6
  constructor(maxRetries = 1, wait = 0) {
6
7
  super(maxRetries, wait);
@@ -30,7 +31,7 @@ export class RemoteExecutionNode extends AsyncNode {
30
31
  try {
31
32
  await new Promise((resolve, reject) => {
32
33
  conn.on('ready', () => {
33
- console.log(`[RemoteExecutionNode] Connected to ${username}@${host}:${port}`);
34
+ log(`[RemoteExecutionNode] Connected to ${username}@${host}:${port}`, this.params.logging);
34
35
  resolve();
35
36
  }).on('error', (err) => {
36
37
  reject(new Error(`SSH connection error: ${err.message}`));
@@ -74,7 +75,7 @@ export class RemoteExecutionNode extends AsyncNode {
74
75
  finally {
75
76
  if (conn && conn.connected) {
76
77
  conn.end();
77
- console.log(`[RemoteExecutionNode] Disconnected from ${host}`);
78
+ log(`[RemoteExecutionNode] Disconnected from ${host}`, this.params.logging);
78
79
  }
79
80
  }
80
81
  return result;
@@ -1,6 +1,7 @@
1
1
  import { AsyncNode, AsyncFlow } from '../qflow.js';
2
2
  // You would need to install the 'node-cron' library: npm install node-cron
3
3
  import * as cron from 'node-cron';
4
+ import { log } from '../logger.js';
4
5
  export class SchedulerNode extends AsyncNode {
5
6
  // Static map to hold all active scheduled tasks
6
7
  static activeTasks = new Map();
@@ -26,12 +27,12 @@ export class SchedulerNode extends AsyncNode {
26
27
  const existingTask = SchedulerNode.activeTasks.get(id);
27
28
  existingTask.stop();
28
29
  SchedulerNode.activeTasks.delete(id);
29
- console.log(`[SchedulerNode] Stopped existing task with ID: ${id}`);
30
+ log(`[SchedulerNode] Stopped existing task with ID: ${id}`, this.params.logging);
30
31
  }
31
32
  let task;
32
33
  if (typeof schedule === 'string') { // Cron string
33
34
  task = cron.schedule(schedule, async () => {
34
- console.log(`[SchedulerNode] Scheduled cron task triggered for ID: ${id}`);
35
+ log(`[SchedulerNode] Scheduled cron task triggered for ID: ${id}`, this.params.logging);
35
36
  try {
36
37
  // If flow is a string, assume it's a flow name from a global registry
37
38
  // This would require the SchedulerNode to have access to the flowRegistry
@@ -39,37 +40,37 @@ export class SchedulerNode extends AsyncNode {
39
40
  const flowInstance = flow; // Assuming flow is an AsyncFlow instance
40
41
  const taskShared = { ...flowParams };
41
42
  const result = await flowInstance.runAsync(taskShared);
42
- console.log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result:`, result);
43
+ log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result: ${JSON.stringify(result)}`, this.params.logging);
43
44
  }
44
45
  catch (e) {
45
- console.error(`[SchedulerNode] Scheduled flow (ID: ${id}) failed:`, e);
46
+ log(`[SchedulerNode] Scheduled flow (ID: ${id}) failed: ${e.message}`, this.params.logging, { type: 'error' });
46
47
  }
47
48
  }, {
48
49
  scheduled: true,
49
50
  timezone: 'America/New_York' // Example timezone
50
51
  });
51
- console.log(`[SchedulerNode] Started cron job (ID: ${id}) with schedule: ${schedule}`);
52
+ log(`[SchedulerNode] Started cron job (ID: ${id}) with schedule: ${schedule}`, this.params.logging);
52
53
  SchedulerNode.activeTasks.set(id, task);
53
54
  return { status: 'scheduled', type: 'cron', schedule: schedule, id: id };
54
55
  }
55
56
  else if (typeof schedule === 'number') { // Milliseconds for setTimeout
56
57
  const timerId = setTimeout(async () => {
57
- console.log(`[SchedulerNode] Scheduled one-time task triggered for ID: ${id}`);
58
+ log(`[SchedulerNode] Scheduled one-time task triggered for ID: ${id}`, this.params.logging);
58
59
  try {
59
60
  const flowInstance = flow; // Assuming flow is an AsyncFlow instance
60
61
  const taskShared = { ...flowParams };
61
62
  const result = await flowInstance.runAsync(taskShared);
62
- console.log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result:`, result);
63
+ log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result: ${JSON.stringify(result)}`, this.params.logging);
63
64
  }
64
65
  catch (e) {
65
- console.error(`[SchedulerNode] Scheduled flow (ID: ${id}) failed:`, e);
66
+ log(`[SchedulerNode] Scheduled flow (ID: ${id}) failed: ${e.message}`, this.params.logging, { type: 'error' });
66
67
  }
67
68
  finally {
68
69
  SchedulerNode.activeTasks.delete(id); // Remove one-time task after execution
69
70
  }
70
71
  }, schedule);
71
72
  task = { id: id, stop: () => clearTimeout(timerId) }; // Simple wrapper for setTimeout
72
- console.log(`[SchedulerNode] Started one-time task (ID: ${id}) in ${schedule}ms`);
73
+ log(`[SchedulerNode] Started one-time task (ID: ${id}) in ${schedule}ms`, this.params.logging);
73
74
  SchedulerNode.activeTasks.set(id, task);
74
75
  return { status: 'scheduled', type: 'timeout', schedule: schedule, id: id };
75
76
  }
@@ -85,11 +86,11 @@ export class SchedulerNode extends AsyncNode {
85
86
  const taskToStop = SchedulerNode.activeTasks.get(id);
86
87
  taskToStop.stop();
87
88
  SchedulerNode.activeTasks.delete(id);
88
- console.log(`[SchedulerNode] Stopped task with ID: ${id}`);
89
+ log(`[SchedulerNode] Stopped task with ID: ${id}`, this.params.logging);
89
90
  return { status: 'stopped', id: id };
90
91
  }
91
92
  else {
92
- console.warn(`[SchedulerNode] No active task found with ID: ${id}`);
93
+ log(`[SchedulerNode] No active task found with ID: ${id}`, this.params.logging, { type: 'warn' });
93
94
  return { status: 'not_found', id: id };
94
95
  }
95
96
  }