@fractal-solutions/qflow 1.0.74 → 1.0.76
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.
|
@@ -16,8 +16,8 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
16
16
|
properties: {
|
|
17
17
|
mode: {
|
|
18
18
|
type: "string",
|
|
19
|
-
enum: ["notification", "dialog", "input", "custom"],
|
|
20
|
-
description: "The mode of the webview
|
|
19
|
+
enum: ["custom-dialog", "custom-input", "notification", "dialog", "input", "custom"],
|
|
20
|
+
description: "The mode of the webview. Commonly used options include 'custom-dialog' (custom HTML with dialog options), 'custom-input' (custom HTML with text input), and 'notification' (message with close button). Other modes are 'dialog' (message with options), 'input' (message with text input), or 'custom' (full HTML control)."
|
|
21
21
|
},
|
|
22
22
|
message: {
|
|
23
23
|
type: "string",
|
|
@@ -42,7 +42,7 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
42
42
|
},
|
|
43
43
|
height: {
|
|
44
44
|
type: "number",
|
|
45
|
-
description: "Optional. The height of the webview window. Defaults to
|
|
45
|
+
description: "Optional. The height of the webview window. Defaults to 300. For agent-generated content or elaborate custom HTML, it is often necessary to set a larger height to prevent content from being cut off. Ensure it fits content well and is not too small."
|
|
46
46
|
},
|
|
47
47
|
theme: {
|
|
48
48
|
type: "string",
|
|
@@ -74,7 +74,7 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
74
74
|
const { mode = 'notification', // 'notification', 'dialog', 'input'
|
|
75
75
|
message = '', options = [], // for dialog mode
|
|
76
76
|
prompt = '', // for input mode
|
|
77
|
-
title = 'Qflow', width = 400, height =
|
|
77
|
+
title = 'Qflow', width = 400, height = 300, theme = 'light', // 'light', 'dark'
|
|
78
78
|
persistent = false, // New parameter for persistent webview
|
|
79
79
|
html = '', // New parameter for custom HTML content
|
|
80
80
|
multilineInput = false, // New parameter for multi-line input
|
|
@@ -102,10 +102,26 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
102
102
|
if (!html) {
|
|
103
103
|
throw new Error('InteractiveWebviewNode in custom mode requires an `html` parameter.');
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
// Inject a helper function for custom HTML to send data back
|
|
106
|
+
const injectedScript = `
|
|
107
|
+
<script>
|
|
108
|
+
function sendResultToQflow(data) {
|
|
109
|
+
if (typeof qflow === 'function') {
|
|
110
|
+
qflow(data);
|
|
111
|
+
} else {
|
|
112
|
+
console.error("qflow function not available in webview context.");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
</script>
|
|
116
|
+
`;
|
|
117
|
+
contentHtml = html.replace('</body>', `${injectedScript}</body>`);
|
|
118
|
+
if (!html.includes('</body>')) {
|
|
119
|
+
// Fallback if </body> tag is missing
|
|
120
|
+
contentHtml = `${html}${injectedScript}`;
|
|
121
|
+
}
|
|
106
122
|
}
|
|
107
123
|
else {
|
|
108
|
-
contentHtml = this.generateHTML(mode, { message, options, prompt, title, theme, multilineInput });
|
|
124
|
+
contentHtml = this.generateHTML(mode, { message, options, prompt, title, theme, multilineInput, html });
|
|
109
125
|
}
|
|
110
126
|
webview.setHTML(contentHtml);
|
|
111
127
|
webview.run(); // This is a blocking call
|
|
@@ -137,7 +153,7 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
137
153
|
return 'default';
|
|
138
154
|
}
|
|
139
155
|
generateHTML(mode, params) {
|
|
140
|
-
const { message, options, prompt, title, theme, multilineInput } = params;
|
|
156
|
+
const { message, options, prompt, title, theme, multilineInput, html } = params;
|
|
141
157
|
const lightTheme = `
|
|
142
158
|
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
|
|
143
159
|
:root {
|
|
@@ -325,36 +341,42 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
325
341
|
}
|
|
326
342
|
`;
|
|
327
343
|
let contentHtml = '';
|
|
344
|
+
let interactiveElements = '';
|
|
345
|
+
let mainContent = message || prompt || ''; // Default content if no custom HTML
|
|
346
|
+
if (mode === 'custom-dialog' || mode === 'custom-input') {
|
|
347
|
+
if (html) {
|
|
348
|
+
mainContent = html; // Use custom HTML if provided
|
|
349
|
+
}
|
|
350
|
+
}
|
|
328
351
|
switch (mode) {
|
|
329
352
|
case 'dialog':
|
|
330
|
-
|
|
331
|
-
|
|
353
|
+
case 'custom-dialog':
|
|
354
|
+
interactiveElements = `
|
|
332
355
|
<div class="button-group">
|
|
333
356
|
${options.map(option => `<button onclick="qflow('${option}')">${option}</button>`).join('')}
|
|
334
357
|
</div>
|
|
335
358
|
`;
|
|
336
359
|
break;
|
|
337
360
|
case 'input':
|
|
361
|
+
case 'custom-input':
|
|
338
362
|
const inputElement = multilineInput ?
|
|
339
|
-
`<textarea id="userInput" rows="10" style="
|
|
340
|
-
`<input type="text" id="userInput" onkeydown="if(event.key==='Enter') document.getElementById('submitBtn').click()"/>`;
|
|
341
|
-
|
|
342
|
-
<h1>${prompt}</h1>
|
|
363
|
+
`<textarea id="userInput" rows="10" style="margin-top: 20px;"></textarea>` :
|
|
364
|
+
`<input type="text" id="userInput" onkeydown="if(event.key==='Enter') document.getElementById('submitBtn').click()" style="margin-top: 20px;"/>`;
|
|
365
|
+
interactiveElements = `
|
|
343
366
|
${inputElement}
|
|
344
367
|
<button id="submitBtn" onclick="qflow(document.getElementById('userInput').value)">Submit</button>
|
|
345
368
|
`;
|
|
346
369
|
break;
|
|
347
370
|
case 'notification':
|
|
348
371
|
default:
|
|
349
|
-
|
|
350
|
-
<h1>${message}</h1>
|
|
372
|
+
interactiveElements = `
|
|
351
373
|
<div class="button-group">
|
|
352
374
|
<button onclick="qflow('closed')">${theme === 'dark' ? 'Acknowledge' : 'Close'}</button>
|
|
353
375
|
</div>
|
|
354
376
|
`;
|
|
355
377
|
break;
|
|
356
378
|
}
|
|
357
|
-
const container = `<div class="container"><div class="title-bar">${title}</div><div class="content">${
|
|
379
|
+
const container = `<div class="container"><div class="title-bar">${title}</div><div class="content">${mode === 'custom-dialog' || mode === 'custom-input' ? mainContent : `<h1>${mainContent}</h1>`}${interactiveElements}</div></div>`;
|
|
358
380
|
return `
|
|
359
381
|
<html>
|
|
360
382
|
<head>
|
package/package.json
CHANGED