@fractal-solutions/qflow 1.0.75 → 1.0.77
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: ["notification", "dialog", "input", "custom", "custom-dialog", "custom-input"],
|
|
20
|
+
description: "The mode of the webview. For 'custom-dialog' and 'custom-input' modes, the tool generates the interactive elements (buttons or input field) based on 'options' or 'multilineInput' parameters; the 'html' parameter is for additional display content only. For 'custom' mode, you provide the full HTML and JavaScript, and must call the globally available JavaScript function `qflow(result)` directly from your HTML/JavaScript to return data. Do NOT use `window.qflow.send()` or similar custom mechanisms. Other modes are 'notification' (message with close button), 'dialog' (message with options), 'input' (message with text input)."
|
|
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 300. Ensure it fits content well and is not too small."
|
|
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",
|
|
@@ -55,7 +55,7 @@ export class InteractiveWebviewNode extends AsyncNode {
|
|
|
55
55
|
},
|
|
56
56
|
html: {
|
|
57
57
|
type: "string",
|
|
58
|
-
description: "Required for 'custom' mode. The full HTML content to display in the webview."
|
|
58
|
+
description: "Required for 'custom' mode. The full HTML content to display in the webview. For 'custom-dialog' and 'custom-input' modes, this HTML should be for display purposes only and should NOT contain interactive elements (like buttons or input fields) that attempt to return data to the flow, as these are handled by the tool's 'options' or 'multilineInput' parameters."
|
|
59
59
|
},
|
|
60
60
|
multilineInput: {
|
|
61
61
|
type: "boolean",
|
|
@@ -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