Add human role decision nodes

This commit is contained in:
2026-11-05 22:33:28 +00:00
parent c8a81eba08
commit 36111a3166
5 changed files with 37 additions and 12 deletions
+16 -8
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
import { LGraph, LGraphCanvas, LiteGraph } from 'litegraph.js'
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ConnectionModel, type LandscapeModel, type ScenarioModel, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ConnectionModel, type LandscapeModel, type ScenarioModel, type ScenarioStep, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
const STORAGE_KEY = 'dumas-system-landscape-v1'
const PRESET_STORAGE_KEY = 'dumas-system-presets-v1'
@@ -31,6 +31,9 @@ const selectedCapabilityIds = ref<string[]>([])
const presentationMode = ref(false)
const failureState = ref<'none' | 'rejected' | 'timeout'>('none')
const retryAttempts = ref<Record<string, number>>({})
const pendingDecision = ref<ScenarioStep['humanDecision'] | null>(null)
const runtimeConnectionIds = ref<string[]>([])
const runtimePayload = ref('')
type TransferKind = 'received' | 'sent' | 'stored'
interface TransferChange { key: string; status: 'added' | 'removed' | 'changed' | 'same'; incoming?: unknown; outgoing?: unknown }
interface TransferRecord { id: string; kind: TransferKind; scenarioName: string; stepNumber: number; stepExplanation: string; senderId: string; destinationId: string; payload: string; incoming: string; outgoing: string; changes: TransferChange[]; timestamp: string }
@@ -45,7 +48,7 @@ const selectedSystem = computed(() => landscape.value.systems.find((item) => ite
const selectedConnection = computed(() => landscape.value.connections.find((item) => item.id === selectedConnectionId.value))
const selectedScenario = computed(() => landscape.value.scenarios.find((item) => item.id === selectedScenarioId.value))
const currentStep = computed(() => selectedScenario.value?.steps[stepIndex.value])
const currentConnections = computed(() => currentStep.value?.connectionIds.map((id) => landscape.value.connections.find((item) => item.id === id)).filter(Boolean) as ConnectionModel[] || [])
const currentConnections = computed(() => { const ids = runtimeConnectionIds.value.length ? runtimeConnectionIds.value : currentStep.value?.connectionIds || []; return ids.map((id) => landscape.value.connections.find((item) => item.id === id)).filter(Boolean) as ConnectionModel[] })
const isRunning = computed(() => playing.value || stepIndex.value >= 0)
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
@@ -88,7 +91,7 @@ function addStep() {
}
function deleteStep(index: number) { selectedScenario.value?.steps.splice(index, 1); persist() }
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; failureState.value = 'none'; retryAttempts.value = {}; stopAnimation() }
function resetPlayback() { playing.value = false; stepIndex.value = -1; packetProgress.value = 0; eventLog.value = []; transferHistory.value = []; failureState.value = 'none'; retryAttempts.value = {}; pendingDecision.value = null; runtimeConnectionIds.value = []; runtimePayload.value = ''; stopAnimation() }
function startScenario(systemId?: string) {
if (systemId) {
const candidate = landscape.value.scenarios.find((scenario) => scenario.startSystemId === systemId)
@@ -100,20 +103,23 @@ function advanceStep() {
if (!selectedScenario.value || stepIndex.value + 1 >= selectedScenario.value.steps.length) { playing.value = false; return }
stepIndex.value += 1; packetProgress.value = 0
const step = selectedScenario.value.steps[stepIndex.value]
runtimeConnectionIds.value = []
runtimePayload.value = ''
if (step.humanDecision) { pendingDecision.value = structuredClone(step.humanDecision); playing.value = false; eventLog.value.unshift(`${new Date().toLocaleTimeString()} · Waiting for ${systemName(step.humanDecision.roleSystemId)} decision`); drawPackets(); return }
recordTransfers(step)
failureState.value = step.outcome && step.outcome !== 'success' ? step.outcome : 'none'
if (failureState.value !== 'none') eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.outcome === 'timeout' ? 'TIMEOUT' : 'REJECTED'} · ${step.explanation}`)
eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${step.explanation}`)
animatePacket(step.delayMs / speed.value)
}
function recordTransfers(step: ScenarioModel['steps'][number]) {
function recordTransfers(step: ScenarioModel['steps'][number], selectedConnectionIds = step.connectionIds, selectedPayload = '') {
if (!selectedScenario.value) return
const now = new Date().toLocaleTimeString()
for (const connectionId of step.connectionIds) {
for (const connectionId of selectedConnectionIds) {
const connection = landscape.value.connections.find((item) => item.id === connectionId)
if (!connection) continue
const incoming = connection.transformation?.incoming || step.payload || connection.payload
const outgoing = connection.transformation?.outgoing || incoming
const incoming = connection.transformation?.incoming || selectedPayload || step.payload || connection.payload
const outgoing = selectedPayload || connection.transformation?.outgoing || incoming
const changes = comparePayloads(incoming, outgoing)
const payload = outgoing
transferHistory.value.push(
@@ -121,6 +127,7 @@ function recordTransfers(step: ScenarioModel['steps'][number]) {
)
}
}
function chooseHumanAction(action: NonNullable<ScenarioStep['humanDecision']>['actions'][number]) { if (!selectedScenario.value || !pendingDecision.value) return; const step = selectedScenario.value.steps[stepIndex.value]; let payload = action.payload; try { const parsed = JSON.parse(action.payload); Object.assign(parsed, pendingDecision.value.editableFields); payload = JSON.stringify(parsed) } catch { /* Keep non-JSON simulated payloads unchanged. */ } runtimeConnectionIds.value = [action.connectionId]; runtimePayload.value = payload; pendingDecision.value = null; playing.value = true; failureState.value = 'none'; eventLog.value.unshift(`${new Date().toLocaleTimeString()} · ${systemName(step.humanDecision!.roleSystemId)} chose ${action.name}`); recordTransfers(step, [action.connectionId], payload); animatePacket(step.delayMs / speed.value) }
function comparePayloads(incoming: string, outgoing: string): TransferChange[] { try { const before = JSON.parse(incoming); const after = JSON.parse(outgoing); const keys = new Set([...Object.keys(before || {}), ...Object.keys(after || {})]); return [...keys].sort().map((key) => ({ key, status: !(key in before) ? 'added' : !(key in after) ? 'removed' : JSON.stringify(before[key]) !== JSON.stringify(after[key]) ? 'changed' : 'same', incoming: before[key], outgoing: after[key] })) } catch { return [] } }
function enableTransformation() { if (selectedConnection.value && !selectedConnection.value.transformation) selectedConnection.value.transformation = { incoming: selectedConnection.value.payload, outgoing: selectedConnection.value.payload, note: '' } }
function recordsForSelectedSystem(kind: TransferKind) { if (!selectedSystem.value) return []; return transferHistory.value.filter((record) => kind === 'sent' ? record.senderId === selectedSystem.value?.id : record.destinationId === selectedSystem.value?.id) }
@@ -146,7 +153,7 @@ function togglePlay() { if (!selectedScenario.value) return; if (playing.value)
function buildNode(system: SystemModel) {
const node = LiteGraph.createNode('Landscape/System')
node.id = system.id; node.title = system.name; node.pos = [...system.position]; node.color = system.color; node.bgcolor = '#111827'; node.size = [190, 100]
node.id = system.id; node.title = system.category === 'human' ? `ROLE · ${system.name}` : system.name; node.pos = [...system.position]; node.color = system.color; node.bgcolor = system.category === 'human' ? '#38213b' : '#111827'; node.shape = system.category === 'human' ? LiteGraph.ROUND : LiteGraph.BOX; node.size = [190, 100]
node.addInput('in', 'SYSTEM'); node.addOutput('out', 'SYSTEM'); node.systemId = system.id; node.showActions = false
for (const capability of system.capabilities) { for (const input of capability.inputs) node.addInput(`${capability.id}:${input.id}`, input.name); for (const output of capability.outputs) node.addOutput(`${capability.id}:${output.id}`, output.name) }
if (system.capabilities.length) node.addWidget('button', 'Actions ▸', null, () => { node.showActions = !node.showActions; node.widgets[0].name = node.showActions ? 'Actions ▾' : 'Actions ▸'; graphCanvas?.draw(true, true) })
@@ -232,5 +239,6 @@ onUnmounted(stopAnimation)
<section class="navigation-panel panel"><div class="nav-fields"><label>Search systems<input v-model="searchQuery" placeholder="Name or description" /></label><label>Category<select v-model="categoryFilter"><option value="all">All categories</option><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="external">External</option></select></label><label>Data type<select v-model="dataTypeFilter"><option value="all">All data types</option><option>JSON</option><option>Form data</option><option>CSV</option><option>Event</option><option>Binary</option></select></label><button class="ghost" @click="fitToScreen">Fit to screen</button></div><div class="minimap-wrap"><span class="eyebrow">MINIMAP</span><canvas ref="minimapEl" width="220" height="120"></canvas></div></section>
<section v-if="selectedScenario" class="scenario-builder panel"><div><span class="eyebrow">EASY SCENARIO BUILDER</span><strong>Start with an action, then build the journey</strong><p class="muted">Connections remain reusable destinations; parallel branches share one step.</p></div><label>Starting system<select v-model="selectedScenario.startSystemId"><option v-for="system in landscape.systems" :key="system.id" :value="system.id">{{ system.name }}</option></select></label><label>Starting action<select v-model="selectedScenario.startActionId"><option value="">Choose an action</option><option v-for="action in actionsForSystem(selectedScenario.startSystemId)" :key="action.id" :value="action.id">{{ action.capabilityName }} · {{ action.name }}</option></select></label><div class="builder-actions"><button class="ghost" @click="addJourneyStep">+ Sequential step</button><button class="ghost" @click="addParallelBranch">+ Parallel branch</button></div><div class="builder-steps"><article v-for="(step, index) in selectedScenario.steps" :key="step.id"><b>{{ index + 1 }}</b><span>{{ step.explanation }}</span><input v-model="step.payload" class="code" title="Editable sample payload" /></article></div></section>
<section class="demo-guide panel"><span class="eyebrow">MONDAY DEMO / START HERE</span><strong>Try a journey in three clicks</strong><ol><li>Open <b>Scenarios</b> and choose Contact enquiry, Sample request or Commercial order.</li><li>Press <b>▶</b> in the journey list, then use pause, next or speed controls.</li><li>Try <b>Order retry and recovery</b> to see a rejection, automatic retry and recovery message. Select a system to inspect its data history.</li></ol></section>
<section v-if="pendingDecision" class="decision-panel panel"><div><span class="eyebrow">HUMAN DECISION REQUIRED</span><strong>{{ systemName(pendingDecision.roleSystemId) }}</strong><p>{{ pendingDecision.task }}</p></div><div class="decision-data"><div><b>Information received</b><pre>{{ pendingDecision.receivedData }}</pre></div><div><b>Editable fields</b><label v-for="(_, key) in pendingDecision.editableFields" :key="key">{{ key }}<input v-model="pendingDecision.editableFields[key]" /></label></div></div><div class="decision-actions"><button v-for="action in pendingDecision.actions" :key="action.id" class="decision-button" :class="action.name.toLowerCase()" :title="action.description" @click="chooseHumanAction(action)"><b>{{ action.name }}</b><small>{{ action.description }}</small></button></div></section>
</main>
</template>