Workflow parameters: types, defaults, checked before a run (#23, #11)
CI / Test (jest) (pull_request) Successful in 26s
CI / Lint (eslint) (pull_request) Successful in 29s
CI / Security (npm audit) (pull_request) Successful in 13s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 1m36s
CI / Integration (api) (pull_request) Successful in 2m26s
CI / UI (playwright) (pull_request) Successful in 2m25s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 2m3s

#23
- Parameters can be text (default), number (min, max), select
  (options), boolean, or worker, with a default. The Run dialog shows a
  matching field, the allowed characters for text, and the range for
  numbers; worker parameters choose from the connected workers.
- Values are checked before anything starts: in the dialog, naming the
  characters that are not allowed, and by the server (resolveParams),
  which answers 400 "Invalid parameters: ..." and creates no execution.
  A bad value used to fail mid-run as "Unsafe value for workflow
  parameter". Server errors now show in the dialog instead of a toast.

#11
- Saving a workflow checks its shape (definitionErrors): known step
  types and their required fields, unique ids, prompt routes that match
  options, route conditions, and parameter definitions. Unknown step
  types were silently skipped at run time.
- README documents the parameter types and the checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-23 18:11:49 -05:00
1 parent 7204c806df
commit a6d693c13e
8 files changed
+477 -39

No files matched your search

+108 -17
View File
@@ -248,20 +248,94 @@
/* ---------------------------------------------------------------
Run modal (execute): always shown, replaces the old confirm().
--------------------------------------------------------------- */
// Run dialog fields by parameter type (#23): text, number, select, boolean, worker.
// The rule for text values is shown up front instead of failing mid-run.
var PARAM_RE = /^[a-zA-Z0-9._:@/-]+$/;
var PARAM_RULE = 'Letters, digits and . _ : @ / - only';
// The characters a value may not contain, named: "space, ;" (#23).
function disallowed(val) {
var seen = [];
val.replace(/[^a-zA-Z0-9._:@/-]/g, function (c) {
var name = c === ' ' ? 'space' : c === '\t' ? 'tab' : c;
if (seen.indexOf(name) === -1) seen.push(name);
return c;
});
return seen.join(' ');
}
function paramFieldHtml(p) {
var esc = window.Pulse.esc;
var type = p.type || 'text';
var id = 'wf-run-param-' + esc(p.name);
var label = esc(p.label || p.name);
var required = p.required ? ' <span class="wf-required">*</span>' : '';
return (
'<div class="lt-form-group">' +
'<label class="lt-label" for="wf-run-param-' + esc(p.name) + '">' + label + required + '</label>' +
'<input type="text" id="wf-run-param-' + esc(p.name) + '" class="lt-input" ' +
'data-param-name="' + esc(p.name) + '" data-required="' + (p.required ? '1' : '0') + '" ' +
'placeholder="' + esc(p.placeholder || '') + '">' +
'</div>'
);
var dflt = p.default === undefined || p.default === null ? '' : String(p.default);
var data = ' data-param-name="' + esc(p.name) + '" data-param-type="' + esc(type) + '"';
var field;
var hint = '';
if (type === 'boolean') {
var on = ['true', '1', 'yes', 'on'].indexOf(dflt.toLowerCase()) !== -1;
return '<div class="lt-form-group">' +
'<label class="wf-checkbox-label"><input type="checkbox" class="lt-checkbox" id="' + id + '"' + data +
(on ? ' checked' : '') + '> ' + label + '</label>' +
'<div class="lt-field-error" id="wf-run-err-' + esc(p.name) + '" hidden></div></div>';
}
if (type === 'select') {
var opts = (Array.isArray(p.options) ? p.options : []).map(function (o) {
o = String(o);
return '<option value="' + esc(o) + '"' + (o === dflt ? ' selected' : '') + '>' + esc(o) + '</option>';
}).join('');
field = '<select class="lt-select" id="' + id + '"' + data + '>' +
(p.required && !dflt ? '<option value="">Choose&hellip;</option>' : (!p.required ? '<option value="">(none)</option>' : '')) +
opts + '</select>';
} else if (type === 'worker') {
field = '<select class="lt-select" id="' + id + '"' + data + ' data-default="' + esc(dflt) + '">' +
'<option value="">Loading workers&hellip;</option></select>';
} else if (type === 'number') {
field = '<input type="number" class="lt-input" id="' + id + '"' + data + ' value="' + esc(dflt) + '"' +
(typeof p.min === 'number' ? ' min="' + p.min + '"' : '') +
(typeof p.max === 'number' ? ' max="' + p.max + '"' : '') +
' placeholder="' + esc(p.placeholder || '') + '">';
if (typeof p.min === 'number' || typeof p.max === 'number') {
hint = 'Between ' + (typeof p.min === 'number' ? p.min : '&minus;&infin;') + ' and ' + (typeof p.max === 'number' ? p.max : '&infin;');
}
} else {
field = '<input type="text" class="lt-input" id="' + id + '"' + data + ' value="' + esc(dflt) + '"' +
' placeholder="' + esc(p.placeholder || '') + '" autocomplete="off" spellcheck="false">';
hint = PARAM_RULE;
}
return '<div class="lt-form-group">' +
'<label class="lt-label" for="' + id + '">' + label + required + '</label>' + field +
(hint ? '<div class="lt-form-hint">' + hint + '</div>' : '') +
'<div class="lt-field-error" id="wf-run-err-' + esc(p.name) + '" hidden></div>' +
'</div>';
}
// Worker parameters choose from the connected workers, online ones first.
function fillWorkerSelects(paramsEl) {
var selects = paramsEl.querySelectorAll('select[data-param-type="worker"]');
if (!selects.length) return;
window.Pulse.api.get('/api/workers').then(function (workers) {
var list = (workers || []).slice().sort(function (a, b) {
return (a.status === 'online' ? 0 : 1) - (b.status === 'online' ? 0 : 1) || String(a.name).localeCompare(String(b.name));
});
Array.prototype.forEach.call(selects, function (sel) {
var dflt = sel.getAttribute('data-default') || '';
sel.textContent = '';
sel.appendChild(new Option(list.length ? 'Choose a worker' : 'No workers connected', ''));
list.forEach(function (w) {
var opt = new Option(w.name + (w.status === 'online' ? '' : ' (' + w.status + ')'), w.name);
if (w.name === dflt) opt.selected = true;
sel.appendChild(opt);
});
});
}).catch(function () {
Array.prototype.forEach.call(selects, function (sel) { sel.options[0].text = 'Could not load workers'; });
});
}
function openRunModal(workflowId) {
var row = _rowsById[workflowId];
var def = _registry[workflowId] || {};
@@ -274,10 +348,12 @@
var paramsEl = document.getElementById('wf-run-params');
paramsEl.innerHTML = paramDefs.map(paramFieldHtml).join('');
fillWorkerSelects(paramsEl);
showFieldError('wf-run-error', '');
window.lt.modal.open('wf-run-modal');
var first = paramsEl.querySelector('input');
var first = paramsEl.querySelector('input, select');
if (first) setTimeout(function () { first.focus(); }, 60);
}
@@ -286,19 +362,33 @@
var def = _registry[_pendingWorkflowId] || {};
var paramDefs = def.params || [];
var params = {};
var firstBad = null;
// Same rules as the server (#23), so mistakes show next to the field.
for (var i = 0; i < paramDefs.length; i++) {
var p = paramDefs[i];
var type = p.type || 'text';
var el = document.getElementById('wf-run-param-' + p.name);
var val = el ? el.value.trim() : '';
if (p.required && !val) {
el.classList.add('is-invalid');
el.focus();
return;
if (!el) continue;
var val = type === 'boolean' ? (el.checked ? 'true' : 'false') : el.value.trim();
var problem = '';
if (!val) {
if (p.required) problem = 'Required';
} else if (type === 'number') {
var n = Number(val);
if (!isFinite(n)) problem = 'Must be a number';
else if (typeof p.min === 'number' && n < p.min) problem = 'Must be at least ' + p.min;
else if (typeof p.max === 'number' && n > p.max) problem = 'Must be at most ' + p.max;
} else if ((type === 'text' || type === 'worker') && !PARAM_RE.test(val)) {
problem = 'Not allowed: ' + disallowed(val);
}
el && el.classList.remove('is-invalid');
if (val) params[p.name] = val;
el.classList.toggle('is-invalid', !!problem);
showFieldError('wf-run-err-' + p.name, problem);
if (problem && !firstBad) firstBad = el;
if (val && !problem) params[p.name] = val;
}
if (firstBad) { firstBad.focus(); return; }
showFieldError('wf-run-error', '');
var dryRun = document.getElementById('wf-run-dryrun').checked;
var workflowId = _pendingWorkflowId;
@@ -313,7 +403,8 @@
window.Pulse.toast.success(dryRun ? 'Dry run started' : 'Workflow started');
window.location.href = '/executions?open=' + encodeURIComponent(result.id);
}).catch(function (e) {
window.Pulse.toast.error((e && e.message) || 'Failed to start execution');
// e.g. "Invalid parameters: ..." from the server: keep the dialog open and say why.
showFieldError('wf-run-error', (e && e.message) || 'Failed to start execution');
});
}