Changeset 0.30.2 cs2 (#202)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
@@ -599,6 +599,7 @@ type WorkflowPageData struct {
|
||||
FormTemplateJSON string // typed form template JSON (empty if chat_only)
|
||||
TotalStages int
|
||||
CurrentStage int
|
||||
SurfacePkgID string // v0.30.2: custom package surface override (empty = use StageMode)
|
||||
}
|
||||
|
||||
// WorkflowLandingPageData is passed to workflow-landing.html.
|
||||
@@ -650,7 +651,7 @@ func (e *Engine) RenderWorkflow() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// Load workflow stage info for form rendering (v0.29.3)
|
||||
var stageMode, stageName, formTplJSON string
|
||||
var stageMode, stageName, formTplJSON, surfacePkgID string
|
||||
var totalStages, currentStage int
|
||||
stageMode = "chat_only" // default
|
||||
if e.stores.Channels != nil && channelID != "" {
|
||||
@@ -669,6 +670,9 @@ func (e *Engine) RenderWorkflow() gin.HandlerFunc {
|
||||
if stageMode != "chat_only" {
|
||||
formTplJSON = string(stg.FormTemplate)
|
||||
}
|
||||
if stg.SurfacePkgID != nil {
|
||||
surfacePkgID = *stg.SurfacePkgID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -690,6 +694,7 @@ func (e *Engine) RenderWorkflow() gin.HandlerFunc {
|
||||
FormTemplateJSON: formTplJSON,
|
||||
TotalStages: totalStages,
|
||||
CurrentStage: currentStage,
|
||||
SurfacePkgID: surfacePkgID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -164,9 +164,11 @@
|
||||
{{end}}
|
||||
|
||||
<!-- Stage surface mount point (v0.30.2) -->
|
||||
<!-- Modes: form_only, form_chat, chat_only, review -->
|
||||
<!-- Modes: form_only, form_chat, chat_only, review, or custom surface via SurfacePkgID -->
|
||||
|
||||
{{if eq .Data.StageMode "form_only"}}
|
||||
{{if .Data.SurfacePkgID}}
|
||||
<div id="customSurfaceMount" style="flex:1;overflow-y:auto"></div>
|
||||
{{else if eq .Data.StageMode "form_only"}}
|
||||
<div class="wf-form" id="formArea"></div>
|
||||
{{else if eq .Data.StageMode "form_chat"}}
|
||||
<div class="wf-body-split">
|
||||
@@ -192,7 +194,7 @@
|
||||
{{end}}
|
||||
|
||||
<div class="wf-session-info">
|
||||
{{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_only"}}Submitting as{{else if eq .Data.StageMode "review"}}Reviewing as{{else}}Chatting as{{end}} <strong>{{.Data.SessionName}}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -204,6 +206,7 @@
|
||||
const STAGE_MODE = '{{.Data.StageMode}}';
|
||||
const TOTAL_STAGES = {{.Data.TotalStages}};
|
||||
const CURRENT_STAGE = {{.Data.CurrentStage}};
|
||||
const SURFACE_PKG_ID = '{{.Data.SurfacePkgID}}';
|
||||
|
||||
var FORM_TPL = null;
|
||||
try { FORM_TPL = JSON.parse('{{.Data.FormTemplateJSON}}' || 'null'); } catch(e) {}
|
||||
@@ -439,6 +442,44 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ── Custom surface (v0.30.2) ──────────
|
||||
if (SURFACE_PKG_ID) {
|
||||
(async function() {
|
||||
var mount = document.getElementById('customSurfaceMount');
|
||||
if (!mount) return;
|
||||
mount.innerHTML = '<div style="padding:24px;text-align:center;color:var(--text-3)">Loading surface\u2026</div>';
|
||||
try {
|
||||
// Load workflow-surfaces registry + dependencies
|
||||
await loadScript(BASE + '/js/ui-primitives.js');
|
||||
await loadScript(BASE + '/js/workflow-surfaces.js');
|
||||
// Load the package's surface JS (registers via WorkflowSurfaces.register())
|
||||
await loadScript(BASE + '/surfaces/' + SURFACE_PKG_ID + '/js/main.js');
|
||||
// Mount the custom surface
|
||||
var ctx = { channelId: CHAN_ID, sessionId: SESSION_ID, basePath: BASE,
|
||||
stageMode: STAGE_MODE, formTemplate: FORM_TPL,
|
||||
totalStages: TOTAL_STAGES, currentStage: CURRENT_STAGE };
|
||||
mount.innerHTML = '';
|
||||
if (typeof WorkflowSurfaces !== 'undefined') {
|
||||
WorkflowSurfaces.mount(mount, SURFACE_PKG_ID, ctx);
|
||||
} else {
|
||||
mount.innerHTML = '<div style="padding:24px;color:var(--danger)">Failed to load surface registry.</div>';
|
||||
}
|
||||
} catch(e) {
|
||||
mount.innerHTML = '<div style="padding:24px;color:var(--danger)">Failed to load surface: ' + escHtml(e.message) + '</div>';
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
function loadScript(src) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var s = document.createElement('script');
|
||||
s.src = src;
|
||||
s.onload = resolve;
|
||||
s.onerror = function() { reject(new Error('Failed to load ' + src)); };
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Review surface (v0.30.2) ──────────
|
||||
if (STAGE_MODE === 'review') {
|
||||
var reviewArea = document.getElementById('reviewArea');
|
||||
|
||||
Reference in New Issue
Block a user