Feat v0.7.9 workflow independence (#63)
All checks were successful
CI/CD / detect-changes (push) Successful in 20s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 25s
CI/CD / test-sqlite (push) Successful in 2m51s
CI/CD / test-go-pg (push) Successful in 3m0s
CI/CD / build-and-deploy (push) Successful in 1m26s

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #63.
This commit is contained in:
2026-04-02 22:31:47 +00:00
committed by xcaliber
parent 3cdfdcf943
commit a9cf71b76d
27 changed files with 1324 additions and 4205 deletions

View File

@@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Data.ChannelTitle}} — {{.InstanceName}}</title>
<title>{{.Data.WorkflowTitle}} — {{.InstanceName}}</title>
<link rel="icon" type="image/svg+xml" href="{{.BasePath}}/favicon.svg?v={{.Version}}">
<link rel="icon" type="image/x-icon" href="{{.BasePath}}/favicon.ico?v={{.Version}}">
<link rel="stylesheet" href="{{.BasePath}}/css/variables.css?v={{.Version}}">
@@ -93,52 +93,22 @@
.wf-form-success h3 { font-size: 18px; margin-bottom: 8px; }
.wf-form-success p { color: var(--text-2); }
/* ── Chat ───────────────────────── */
.wf-chat {
flex: 1; overflow-y: auto; padding: 16px 24px;
}
.wf-chat .message {
margin-bottom: 12px; padding: 10px 14px;
border-radius: 8px; max-width: 80%;
}
.wf-chat .message.user { background: var(--accent-dim); margin-left: auto; }
.wf-chat .message.assistant { background: var(--bg-raised); }
.wf-chat .message .meta { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.wf-chat .message .content { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.wf-input {
padding: 12px 24px; border-top: 1px solid var(--border);
background: var(--bg-surface); display: flex; gap: 8px;
}
.wf-input textarea {
flex: 1; resize: none; background: var(--input-bg); color: var(--text);
border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
font-family: var(--font); font-size: 14px; min-height: 42px; max-height: 160px;
}
.wf-input textarea:focus { outline: none; border-color: var(--accent); }
.wf-input button {
background: var(--accent); color: #fff; border: none; border-radius: 8px;
padding: 0 20px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.wf-input button:hover { background: var(--accent-hover); }
.wf-input button:disabled { opacity: 0.5; cursor: default; }
.wf-session-info {
padding: 8px 24px; font-size: 12px; color: var(--text-3);
border-top: 1px solid var(--border); background: var(--bg);
}
/* ── Form+Chat layout ───────────── */
.wf-body-split { display: flex; flex: 1; overflow: hidden; }
.wf-body-split .wf-form { flex: 1; border-right: 1px solid var(--border); overflow-y: auto; }
.wf-body-split .wf-chat-col { flex: 1; display: flex; flex-direction: column; }
.wf-body-split .wf-chat { flex: 1; }
/* ── Unsupported mode fallback ─── */
.wf-unsupported {
flex: 1; display: flex; align-items: center; justify-content: center;
padding: 24px; text-align: center; color: var(--text-2);
}
/* ── Branding (v0.35.0) ────────── */
/* ── Branding ────────────────────── */
.wf-branding-logo { max-height: 32px; margin-bottom: 4px; }
.wf-branding-tagline { font-size: 13px; color: var(--text-2); margin-top: 2px; }
/* ── Progressive Forms (v0.35.0) ── */
/* ── Progressive Forms ────────── */
.wf-fieldset-nav {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 16px; padding-bottom: 12px;
@@ -175,8 +145,8 @@
<body>
<div class="wf-shell">
<div class="wf-header" id="wfHeader">
<h1>{{.Data.ChannelTitle}}</h1>
{{if .Data.ChannelDescription}}<p>{{.Data.ChannelDescription}}</p>{{end}}
<h1>{{.Data.WorkflowTitle}}</h1>
{{if .Data.WorkflowDescription}}<p>{{.Data.WorkflowDescription}}</p>{{end}}
</div>
{{if .Data.StageName}}
@@ -188,62 +158,55 @@
</div>
{{end}}
<!-- Stage surface mount point (v0.30.2) -->
<!-- Modes: form_only, form_chat, chat_only, review, or custom surface via SurfacePkgID -->
<!-- Stage surface: form, review, delegated (custom surface), or automated -->
{{if .Data.SurfacePkgID}}
<div id="customSurfaceMount" style="flex:1;overflow-y:auto"></div>
{{else if eq .Data.StageMode "form_only"}}
{{else if eq .Data.StageMode "form"}}
<div class="wf-form" id="formArea"></div>
{{else if eq .Data.StageMode "form_chat"}}
<div class="wf-body-split">
<div class="wf-form" id="formArea"></div>
<div class="wf-chat-col">
<div class="wf-chat" id="chatMessages"></div>
<div class="wf-input">
<textarea id="chatInput" placeholder="Type a message…" rows="1"
onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
<button id="sendBtn" onclick="sendMessage()">Send</button>
</div>
</div>
</div>
{{else if eq .Data.StageMode "review"}}
<div id="reviewArea" style="flex:1;overflow-y:auto;display:flex">
<div id="reviewDataPanel" style="flex:1;overflow-y:auto;border-right:1px solid var(--border)"></div>
<div id="reviewActionPanel" style="flex:1;overflow-y:auto;display:flex;flex-direction:column"></div>
</div>
{{else if eq .Data.Status "completed"}}
<div class="wf-form-success" style="flex:1;display:flex;flex-direction:column;justify-content:center">
<h3>Completed</h3>
<p>This workflow has been completed. Thank you for your submission.</p>
</div>
{{else}}
<div class="wf-chat" id="chatMessages"></div>
<div class="wf-input">
<textarea id="chatInput" placeholder="Type a message…" rows="1"
onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
<button id="sendBtn" onclick="sendMessage()">Send</button>
<div class="wf-unsupported">
<p>This stage type ({{.Data.StageMode}}) does not have an interactive surface.</p>
</div>
{{end}}
<div class="wf-session-info">
{{if .Data.SurfacePkgID}}Session:{{else if eq .Data.StageMode "form_only"}}Submitting as{{else if eq .Data.StageMode "review"}}Reviewing as{{else}}Chatting as{{end}} <strong>{{.Data.SessionName}}</strong>
{{if .Data.SurfacePkgID}}Session:{{else if eq .Data.StageMode "form"}}Submitting as{{else if eq .Data.StageMode "review"}}Reviewing as{{else}}Session:{{end}} <strong>{{.Data.SessionName}}</strong>
</div>
</div>
<script>
(function() {
const BASE = '{{.BasePath}}';
const CHAN_ID = '{{.Data.ChannelID}}';
const INSTANCE_ID = '{{.Data.InstanceID}}';
const ENTRY_TOKEN = '{{.Data.EntryToken}}';
const SESSION_ID = '{{.Data.SessionID}}';
const STAGE_MODE = '{{.Data.StageMode}}';
const TOTAL_STAGES = {{.Data.TotalStages}};
const CURRENT_STAGE = {{.Data.CurrentStage}};
const SURFACE_PKG_ID = '{{.Data.SurfacePkgID}}';
const STATUS = '{{.Data.Status}}';
// API calls use the entry token (public) or instance ID
const API_ID = ENTRY_TOKEN || INSTANCE_ID;
var FORM_TPL = null;
try { FORM_TPL = JSON.parse('{{.Data.FormTemplateJSON}}' || 'null'); } catch(e) {}
// v0.35.0: Branding
var BRANDING = null;
try { BRANDING = JSON.parse('{{.Data.BrandingJSON}}' || 'null'); } catch(e) {}
// v0.35.0: Apply branding
// Apply branding
(function() {
if (!BRANDING) return;
var header = document.getElementById('wfHeader');
@@ -279,11 +242,11 @@
}
})();
// ── Form rendering (v0.35.0: progressive forms + conditional fields) ──
// ── Form rendering (progressive forms + conditional fields) ──
var _fieldsetIndex = 0;
var _fieldsetCount = 0;
if ((STAGE_MODE === 'form_only' || STAGE_MODE === 'form_chat') && FORM_TPL) {
if (STAGE_MODE === 'form' && FORM_TPL) {
var formArea = document.getElementById('formArea');
if (FORM_TPL.fieldsets && FORM_TPL.fieldsets.length > 0) {
renderProgressiveForm(formArea, FORM_TPL);
@@ -326,7 +289,6 @@
html += '</div></div>';
}
container.innerHTML = html;
// Apply conditional fields for all fieldsets
for (var s = 0; s < tpl.fieldsets.length; s++) {
applyConditionalFields(tpl.fieldsets[s].fields);
}
@@ -350,7 +312,7 @@
var handler = function() { evaluateCondition(field); };
srcEl.addEventListener('change', handler);
srcEl.addEventListener('input', handler);
handler(); // initial evaluation
handler();
})(f);
}
}
@@ -436,7 +398,7 @@
}
window.submitForm = async function() {
if (!FORM_TPL || !FORM_TPL.fields) return;
if (!FORM_TPL || (!FORM_TPL.fields && !FORM_TPL.fieldsets)) return;
var btn = document.getElementById('formSubmitBtn');
if (btn) btn.disabled = true;
@@ -448,7 +410,7 @@
el.textContent = '';
});
// Collect form data (v0.35.0: get all fields from fieldsets or top-level)
// Collect form data (get all fields from fieldsets or top-level)
var allFields = FORM_TPL.fields || [];
if (FORM_TPL.fieldsets && FORM_TPL.fieldsets.length > 0) {
allFields = [];
@@ -461,7 +423,7 @@
var f = allFields[i];
var el = document.getElementById('ff_' + f.key);
if (!el) continue;
// v0.35.0: Skip hidden conditional fields
// Skip hidden conditional fields
var fieldWrap = document.querySelector('.wf-form-field[data-key="' + f.key + '"]');
if (fieldWrap && fieldWrap.classList.contains('cond-hidden')) continue;
if (f.type === 'checkbox') {
@@ -474,7 +436,7 @@
}
try {
var resp = await fetch(BASE + '/api/v1/public/workflows/advance/' + CHAN_ID, {
var resp = await fetch(BASE + '/api/v1/public/workflows/advance/' + API_ID, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data: data }),
@@ -490,16 +452,13 @@
return;
}
// Success
if (result.status === 'advanced' || result.status === 'completed') {
showFormSuccess(result.status === 'completed'
? 'Thank you! Your submission is complete.'
: 'Submitted! Moving to the next step...');
if (result.status === 'advanced') {
setTimeout(function() { window.location.reload(); }, 1500);
}
// Success — API returns instance status: "active" (advanced) or "completed"
if (result.status === 'completed') {
showFormSuccess('Thank you! Your submission is complete.');
} else {
showFormSuccess('Your response has been submitted.');
// Still active = advanced to next stage — reload to render it
showFormSuccess('Submitted! Moving to the next step...');
setTimeout(function() { window.location.reload(); }, 1500);
}
} catch(e) {
alert('Network error: ' + e.message);
@@ -524,22 +483,6 @@
}
}
// ── Chat ───────────────────────────
var chatEl = document.getElementById('chatMessages');
var inputEl = document.getElementById('chatInput');
var sendBtn = document.getElementById('sendBtn');
var sending = false;
function addMessage(role, content, name) {
if (!chatEl) return;
var div = document.createElement('div');
div.className = 'message ' + role;
var meta = name ? '<div class="meta">' + escHtml(name) + '</div>' : '';
div.innerHTML = meta + '<div class="content">' + escHtml(content) + '</div>';
chatEl.appendChild(div);
chatEl.scrollTop = chatEl.scrollHeight;
}
function escHtml(s) {
var d = document.createElement('div');
d.textContent = s;
@@ -550,46 +493,7 @@
return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
window.sendMessage = async function() {
if (!inputEl || !sendBtn) return;
var text = inputEl.value.trim();
if (!text || sending) return;
sending = true;
sendBtn.disabled = true;
inputEl.value = '';
addMessage('user', text, '{{.Data.SessionName}}');
try {
// TODO(v0.8+): form_chat completions endpoint not yet implemented
var resp = { ok: false, statusText: 'Chat mode not yet available', json: function() { return Promise.resolve({ error: 'Chat mode not yet available' }); } };
if (resp.ok) {
var data = await resp.json();
if (data.content) {
addMessage('assistant', data.content, data.persona_name || 'Assistant');
}
} else {
var err = await resp.json().catch(function() { return {}; });
addMessage('assistant', 'Error: ' + (err.error || resp.statusText));
}
} catch(e) {
addMessage('assistant', 'Network error: ' + e.message);
}
sending = false;
sendBtn.disabled = false;
inputEl.focus();
};
// Auto-resize textarea
if (inputEl) {
inputEl.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = Math.min(this.scrollHeight, 160) + 'px';
});
}
// ── Custom surface (v0.37.14: legacy registry removed) ──────────
// ── Custom surface (delegated mode) ──────────
if (SURFACE_PKG_ID) {
var mount = document.getElementById('customSurfaceMount');
if (mount) {
@@ -607,7 +511,7 @@
});
}
// ── Review surface (v0.35.0: structured review with side-by-side + comments) ──
// ── Review surface (structured review with side-by-side + comments) ──
if (STAGE_MODE === 'review') {
var dataPanel = document.getElementById('reviewDataPanel');
var actionPanel = document.getElementById('reviewActionPanel');
@@ -624,7 +528,7 @@
html += '<h3 style="margin-bottom:16px">Collected Data</h3>';
try {
var resp = await fetch(BASE + '/api/v1/public/workflows/resume/' + CHAN_ID, {
var resp = await fetch(BASE + '/api/v1/public/workflows/resume/' + API_ID, {
headers: { 'Content-Type': 'application/json' },
});
if (resp.ok) {
@@ -666,7 +570,7 @@
actHtml += '</div>';
actionPanel.innerHTML = actHtml;
// Keyboard shortcuts (v0.35.0)
// Keyboard shortcuts
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.key === 'Enter') {
e.preventDefault();
@@ -681,7 +585,7 @@
document.getElementById('reviewAdvanceBtn').addEventListener('click', async function() {
this.disabled = true;
try {
var r = await fetch(BASE + '/api/v1/public/workflows/advance/' + CHAN_ID, {
var r = await fetch(BASE + '/api/v1/public/workflows/advance/' + API_ID, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data: {} }),
});
@@ -702,7 +606,7 @@
if (!reason) return;
this.disabled = true;
try {
var r = await fetch(BASE + '/api/v1/public/workflows/advance/' + CHAN_ID, {
var r = await fetch(BASE + '/api/v1/public/workflows/advance/' + API_ID, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data: { _action: 'reject', reason: reason } }),
});