Add environment containers and system tags

This commit is contained in:
2026-11-05 22:48:20 +00:00
parent e056837232
commit cac5ef37e5
4 changed files with 64 additions and 17 deletions
+24 -9
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 DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type LandscapeModel, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
import { cloneCapabilities, demoLandscape, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ConnectionModel, type DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type LandscapeModel, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
const STORAGE_KEY = 'dumas-system-landscape-v1'
const PRESET_STORAGE_KEY = 'dumas-system-presets-v1'
@@ -11,7 +11,7 @@ const canvasEl = ref<HTMLCanvasElement | null>(null)
const selectedSystemId = ref('')
const selectedConnectionId = ref('')
const selectedScenarioId = ref(landscape.value.scenarios[0]?.id || '')
const activeTab = ref<'systems' | 'scenarios' | 'presets'>('scenarios')
const activeTab = ref<'systems' | 'scenarios' | 'presets' | 'containers'>('scenarios')
const graph = new LGraph()
let graphCanvas: any
let animationFrame = 0
@@ -26,6 +26,7 @@ const minimapEl = ref<HTMLCanvasElement | null>(null)
const searchQuery = ref('')
const categoryFilter = ref('all')
const dataTypeFilter = ref('all')
const tagFilter = ref('all')
const placingPreset = ref<SystemPreset | null>(null)
const selectedCapabilityIds = ref<string[]>([])
const presentationMode = ref(false)
@@ -41,6 +42,9 @@ interface TransferChange { key: string; status: 'added' | 'removed' | 'changed'
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 }
const transferHistory = ref<TransferRecord[]>([])
const dataTab = ref<TransferKind>('received')
const selectedContainerId = ref('')
const selectedContainer = computed(() => landscape.value.containers.find((item) => item.id === selectedContainerId.value))
const allTags = computed(() => [...new Set(landscape.value.systems.flatMap((system) => system.tags || []))].sort())
function loadLandscape(): LandscapeModel {
try { return validateLandscape(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null')) } catch { return demoLandscape() }
@@ -56,10 +60,14 @@ const isRunning = computed(() => playing.value || stepIndex.value >= 0)
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
function persistPresets() { localStorage.setItem(PRESET_STORAGE_KEY, JSON.stringify(customPresets.value)) }
function selectSystem(id: string) { selectedSystemId.value = id; selectedConnectionId.value = '' }
function selectContainer(id: string) { selectedContainerId.value = id; selectedSystemId.value = ''; selectedConnectionId.value = '' }
function selectConnection(id: string) { selectedConnectionId.value = id; selectedSystemId.value = ''; const connection = landscape.value.connections.find((item) => item.id === id); if (connection) { connection.transformation ||= { incoming: connection.payload, outgoing: connection.payload, note: '' }; connection.protocol ||= 'HTTPS'; connection.dataType ||= 'JSON'; connection.deliveryMethod ||= 'immediate'; connection.exchangeType ||= 'event-transfer'; connection.responsePayload ||= '{}'; connection.responseStatus ||= 200; connection.showCableLabel ??= true } }
function addSystem() {
const id = uid('system'); landscape.value.systems.push({ id, name: 'New system', description: 'Describe this system.', category: 'service', color: '#6d7cff', position: [160, 160], capabilities: [] }); selectSystem(id); persist(); rebuildGraph()
const id = uid('system'); landscape.value.systems.push({ id, name: 'New system', description: 'Describe this system.', category: 'service', color: '#6d7cff', position: [160, 160], containerId: landscape.value.containers[0]?.id, tags: ['Test'], capabilities: [] }); selectSystem(id); persist(); rebuildGraph()
}
function addContainer() { const id = uid('container'); landscape.value.containers.push({ id, name: 'New environment', color: '#2879d0', position: [80, 80], size: [500, 320] }); selectContainer(id); persist(); rebuildGraph() }
function moveContainer(container: EnvironmentContainerModel, dx: number, dy: number) { container.position = [container.position[0] + dx, container.position[1] + dy]; for (const system of landscape.value.systems.filter((item) => item.containerId === container.id)) system.position = [system.position[0] + dx, system.position[1] + dy]; for (const child of landscape.value.containers.filter((item) => item.parentId === container.id)) child.position = [child.position[0] + dx, child.position[1] + dy]; persist(); rebuildGraph() }
function deleteContainer(id: string) { landscape.value.systems.forEach((system) => { if (system.containerId === id) delete system.containerId }); landscape.value.containers = landscape.value.containers.filter((item) => item.id !== id && item.parentId !== id); selectedContainerId.value = ''; persist(); rebuildGraph() }
function openPreset(preset: SystemPreset) { placingPreset.value = preset; selectedCapabilityIds.value = preset.capabilities.map((capability) => capability.id) }
function placePreset() { if (!placingPreset.value) return; const position: [number, number] = [120 + (landscape.value.systems.length % 3) * 280, 120 + (landscape.value.systems.length % 3) * 150]; const system = systemFromPreset(placingPreset.value, selectedCapabilityIds.value, position); landscape.value.systems.push(system); selectSystem(system.id); placingPreset.value = null; persist(); rebuildGraph() }
function definitionCapabilities(definition: SystemDefinition): CapabilityModel[] { return definition.actions.map((item) => ({ id: `action-${item.id}`, name: item.name, description: item.description, inputs: item.trigger === 'incoming' ? [{ id: `${item.id}-input`, name: 'Incoming request', description: 'Request handled by this action.' }] : [], outputs: item.outputs.map((output) => ({ id: output.id, name: output.name, description: output.condition || 'Action output.' })), actions: [{ id: item.id, name: item.name, description: item.description, payload: item.outputs[0]?.payload || item.input || '{}' }], payload: item.input || item.outputs[0]?.payload || '{}' })) }
@@ -148,7 +156,7 @@ function enableTransformation() { if (selectedConnection.value && !selectedConne
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) }
function systemName(id: string) { return landscape.value.systems.find((system) => system.id === id)?.name || id }
const latestSelectedRecord = computed(() => selectedSystem.value ? transferHistory.value.filter((record) => record.destinationId === selectedSystem.value?.id).slice(-1)[0] : undefined)
const matchesSystem = (system: SystemModel) => { const query = searchQuery.value.trim().toLowerCase(); const queryMatch = !query || `${system.name} ${system.description}`.toLowerCase().includes(query); const categoryMatch = categoryFilter.value === 'all' || system.category === categoryFilter.value; const dataMatch = dataTypeFilter.value === 'all' || landscape.value.connections.some((connection) => connection.dataType === dataTypeFilter.value && (connection.sourceId === system.id || connection.targetId === system.id)); return queryMatch && categoryMatch && dataMatch }
const matchesSystem = (system: SystemModel) => { const query = searchQuery.value.trim().toLowerCase(); const queryMatch = !query || `${system.name} ${system.description}`.toLowerCase().includes(query); const categoryMatch = categoryFilter.value === 'all' || system.category === categoryFilter.value; const dataMatch = dataTypeFilter.value === 'all' || landscape.value.connections.some((connection) => connection.dataType === dataTypeFilter.value && (connection.sourceId === system.id || connection.targetId === system.id)); const tagMatch = tagFilter.value === 'all' || (system.tags || []).includes(tagFilter.value); return queryMatch && categoryMatch && dataMatch && tagMatch }
function isSystemDimmed(system: SystemModel) { if (!matchesSystem(system)) return true; if (!playing.value || !currentConnections.value.length) return false; return !currentConnections.value.some((connection) => connection.sourceId === system.id || connection.targetId === system.id) }
function animatePacket(duration: number) {
stopAnimation(); const started = performance.now()
@@ -166,7 +174,10 @@ function finishStep() {
function stopAnimation() { if (animationFrame) cancelAnimationFrame(animationFrame); animationFrame = 0 }
function togglePlay() { if (!selectedScenario.value) return; if (playing.value) { playing.value = false; stopAnimation() } else { playing.value = true; if (stepIndex.value < 0) advanceStep(); else animatePacket(currentStep.value?.delayMs || 1000) } }
function collapsedContainerFor(systemId: string) { const system = landscape.value.systems.find((item) => item.id === systemId); const container = system?.containerId ? landscape.value.containers.find((item) => item.id === system.containerId) : undefined; return container?.collapsed ? container : undefined }
function visualNodeId(systemId: string) { return collapsedContainerFor(systemId)?.id || systemId }
function buildNode(system: SystemModel) {
if (collapsedContainerFor(system.id)) return null
const node = LiteGraph.createNode('Landscape/System')
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
@@ -179,9 +190,11 @@ function buildNode(system: SystemModel) {
}
function connectionLabel(connection: ConnectionModel) { return connection.showCableLabel === false ? '' : `${connection.label} · ${connection.protocol || 'HTTPS'} · ${connection.dataType || 'JSON'} · ${connection.deliveryMethod || 'immediate'}` }
function rebuildGraph() {
graph.clear(); landscape.value.systems.forEach(buildNode)
graph.clear(); for (const container of landscape.value.containers.filter((item) => !item.collapsed)) { const group = new LiteGraph.LGraphGroup(container.name); group.pos = [...container.position]; group.size = [...container.size]; group.color = container.color; group.font_size = 18; group._dumasContainerId = container.id; graph.add(group) }
for (const container of landscape.value.containers.filter((item) => item.collapsed)) { const node = LiteGraph.createNode('Landscape/Container'); node.id = container.id; node.title = `CONTAINER · ${container.name}`; node.pos = [...container.position]; node.color = container.color; node.bgcolor = '#172a43'; node.size = [210, 90]; node.addOutput('external', 'EXTERNAL'); node.onDblClick = () => { container.collapsed = false; persist(); rebuildGraph() }; graph.add(node) }
landscape.value.systems.forEach(buildNode)
for (const connection of landscape.value.connections) {
const source = graph.getNodeById(connection.sourceId); const target = graph.getNodeById(connection.targetId)
const source = graph.getNodeById(visualNodeId(connection.sourceId)); const target = graph.getNodeById(visualNodeId(connection.targetId))
if (source && target) source.connect(0, target, 0)
}
nextTick(() => { graphCanvas?.draw(true, true); drawPackets() })
@@ -196,12 +209,12 @@ function drawPackets() {
const ctx = graphCanvas.ctx as CanvasRenderingContext2D
for (const connection of landscape.value.connections) {
if (!connection.showCableLabel) continue
const from = graph.getNodeById(connection.sourceId); const to = graph.getNodeById(connection.targetId)
const from = graph.getNodeById(visualNodeId(connection.sourceId)); const to = graph.getNodeById(visualNodeId(connection.targetId))
if (!from || !to) continue
ctx.save(); ctx.fillStyle = '#7887a2'; ctx.font = '10px Inter, sans-serif'; ctx.fillText(connectionLabel(connection), (from.pos[0] + to.pos[0]) / 2, (from.pos[1] + to.pos[1]) / 2 - 8); ctx.restore()
}
for (const connection of currentConnections.value) {
const from = graph.getNodeById(connection.sourceId); const to = graph.getNodeById(connection.targetId)
const from = graph.getNodeById(visualNodeId(connection.sourceId)); const to = graph.getNodeById(visualNodeId(connection.targetId))
if (!from || !to) continue
const x = from.pos[0] + from.size[0] + (to.pos[0] - from.pos[0] - from.size[0]) * packetProgress.value
const y = from.pos[1] + 50 + (to.pos[1] + 50 - from.pos[1] - 50) * packetProgress.value
@@ -229,7 +242,7 @@ onUnmounted(stopAnimation)
<section v-if="importError" class="import-error">{{ importError }} <button @click="importError = ''">Dismiss</button></section>
<div class="workspace">
<aside class="sidebar panel">
<div class="tabs"><button :class="{active: activeTab === 'scenarios'}" @click="activeTab = 'scenarios'">Scenarios</button><button :class="{active: activeTab === 'systems'}" @click="activeTab = 'systems'">Systems</button><button :class="{active: activeTab === 'presets'}" @click="activeTab = 'presets'">Presets</button></div>
<div class="tabs"><button :class="{active: activeTab === 'scenarios'}" @click="activeTab = 'scenarios'">Scenarios</button><button :class="{active: activeTab === 'systems'}" @click="activeTab = 'systems'">Systems</button><button :class="{active: activeTab === 'containers'}" @click="activeTab = 'containers'">Environments</button><button :class="{active: activeTab === 'presets'}" @click="activeTab = 'presets'">Presets</button></div>
<div v-if="activeTab === 'scenarios'" class="list-area"><div class="section-heading"><span>Journeys</span><button class="icon-button" @click="addScenario">+</button></div><div v-for="scenario in landscape.scenarios" :key="scenario.id" class="list-item" :class="{selected: selectedScenarioId === scenario.id}" @dblclick="selectedScenarioId = scenario.id; startScenario()"><span class="status-dot"></span><span class="list-copy" @click="selectedScenarioId = scenario.id; resetPlayback()"><strong>{{ scenario.name }}</strong><small>{{ scenario.steps.length }} steps · {{ scenario.description }}</small></span><button class="run-mini" title="Run scenario" @click.stop="selectedScenarioId = scenario.id; startScenario()">▶</button></div></div>
<div v-else-if="activeTab === 'systems'" class="list-area"><div class="section-heading"><span>Systems</span><button class="icon-button" @click="addSystem">+</button></div><button v-for="system in landscape.systems" :key="system.id" class="list-item" :class="{selected: selectedSystemId === system.id}" @click="selectSystem(system.id)"><span class="system-dot" :style="{background: system.color}"></span><span><strong>{{ system.name }}</strong><small>{{ system.category }} · {{ system.capabilities.length }} capabilities</small></span></button><div class="section-heading connections-heading"><span>Connections</span><button class="icon-button" @click="addConnection">+</button></div><button v-for="connection in landscape.connections" :key="connection.id" class="list-item compact" :class="{selected: selectedConnectionId === connection.id}" @click="selectConnection(connection.id)"><span class="arrow">↗</span><span><strong>{{ connection.label }}</strong><small>{{ landscape.systems.find(s => s.id === connection.sourceId)?.name }} → {{ landscape.systems.find(s => s.id === connection.targetId)?.name }}</small></span></button></div>
<div v-else class="list-area"><div class="section-heading"><span>Built-in library</span></div><div v-for="preset in SYSTEM_PRESETS" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div><div class="section-heading connections-heading"><span>Your presets</span></div><div v-if="!customPresets.length" class="muted">Save a customised system from its inspector.</div><div v-for="preset in customPresets" :key="preset.id" class="preset-item" :title="preset.description"><span class="system-dot" :style="{background: preset.color}"></span><span class="list-copy"><strong>{{ preset.name }}</strong><small>{{ preset.capabilities.length }} capabilities</small></span><button class="run-mini" @click="openPreset(preset)">Place</button></div></div>
@@ -257,5 +270,7 @@ onUnmounted(stopAnimation)
<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>
<div v-if="customBuilderOpen" class="modal-backdrop" @click.self="customBuilderOpen = false"><section class="custom-builder panel"><div class="inspector-header"><div><span class="eyebrow">CUSTOM SYSTEM BUILDER</span><h2>Reusable system definition</h2><p class="muted">Definitions are saved to the local preset library. Placed instances remain independent.</p></div><button class="danger-icon" @click="customBuilderOpen = false">×</button></div><div class="builder-meta"><label>Name<input v-model="customDraft.name" /></label><label>Category<select v-model="customDraft.category"><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="human">Human / role</option><option value="external">External</option></select></label><label>Colour<input v-model="customDraft.color" type="color" /></label><label>Description<textarea v-model="customDraft.description" rows="2"></textarea></label></div><div class="builder-section"><div class="steps-head"><span>Actions</span><button class="icon-button" @click="addCustomAction">+</button></div><article v-for="action in customDraft.definition.actions" :key="action.id" class="definition-card"><div class="definition-grid"><label>Name<input v-model="action.name" /></label><label>Trigger<select v-model="action.trigger"><option value="button">Button</option><option value="incoming">Incoming request / event</option><option value="schedule">Simulated schedule</option></select></label></div><label>Description<input v-model="action.description" /></label><label>Example input JSON<textarea v-model="action.input" rows="2" class="code"></textarea></label><div class="steps-head"><span>Outputs</span><button class="icon-button" @click="addCustomOutput(action)">+</button></div><div v-for="output in action.outputs" :key="output.id" class="nested-row"><input v-model="output.name" placeholder="Output name" /><textarea v-model="output.payload" rows="2" class="code" placeholder="Example JSON"></textarea><input v-model="output.condition" placeholder="Outcome condition (optional)" /><label class="checkbox-label"><input v-model="output.parallel" type="checkbox" /> Parallel output</label></div></article></div><div class="builder-section"><div class="steps-head"><span>Endpoints</span><button class="icon-button" @click="addCustomEndpoint">+</button></div><article v-for="endpoint in customDraft.definition.endpoints" :key="endpoint.id" class="definition-card"><div class="definition-grid"><label>Name<input v-model="endpoint.name" /></label><label>Protocol<select v-model="endpoint.protocol"><option>HTTPS</option><option>HTTP</option><option>GraphQL</option><option>Webhook</option><option>Message queue</option></select></label><label>Method<input v-model="endpoint.method" /></label><label>Path<input v-model="endpoint.path" /></label></div><label>Example request JSON<textarea v-model="endpoint.request" rows="2" class="code"></textarea></label><label>Triggers action<select v-model="endpoint.triggersActionId"><option value="">No action</option><option v-for="action in customDraft.definition.actions" :key="action.id" :value="action.id">{{ action.name }}</option></select></label><div class="steps-head"><span>Responses</span><button class="icon-button" @click="addCustomResponse(endpoint)">+</button></div><div v-for="response in endpoint.responses" :key="response.id" class="nested-row response-row"><label>Status<input v-model.number="response.status" type="number" /></label><label>Delay ms<input v-model.number="response.delayMs" type="number" min="0" /></label><textarea v-model="response.body" rows="2" class="code" placeholder="Response body JSON"></textarea></div></article></div><div class="modal-actions"><button class="ghost" @click="customBuilderOpen = false">Cancel</button><button class="primary" @click="saveCustomBuilder">Save reusable preset</button></div></section></div>
<section v-if="activeTab === 'containers'" class="container-editor panel"><div class="section-heading"><span>Environment containers</span><button class="primary" @click="addContainer">Add container</button></div><div class="container-list"><button v-for="container in landscape.containers" :key="container.id" class="list-item" :class="{selected: selectedContainerId === container.id}" @click="selectContainer(container.id)"><span class="system-dot" :style="{background: container.color}"></span><span><strong>{{ container.name }}</strong><small>{{ container.collapsed ? 'Collapsed' : 'Expanded' }} · {{ landscape.systems.filter((system) => system.containerId === container.id).length }} systems</small></span></button></div><div v-if="selectedContainer" class="container-form"><label>Name<input v-model="selectedContainer.name" @change="rebuildGraph" /></label><label>Colour<input v-model="selectedContainer.color" type="color" @change="rebuildGraph" /></label><label>Parent<select v-model="selectedContainer.parentId" @change="rebuildGraph"><option value="">No parent</option><option v-for="parent in landscape.containers.filter((item) => item.id !== selectedContainer.id)" :key="parent.id" :value="parent.id">{{ parent.name }}</option></select></label><label>Position X<input v-model.number="selectedContainer.position[0]" type="number" @change="rebuildGraph" /></label><label>Position Y<input v-model.number="selectedContainer.position[1]" type="number" @change="rebuildGraph" /></label><label>Width<input v-model.number="selectedContainer.size[0]" type="number" min="180" @change="rebuildGraph" /></label><label>Height<input v-model.number="selectedContainer.size[1]" type="number" min="120" @change="rebuildGraph" /></label><label class="checkbox-label"><input v-model="selectedContainer.collapsed" type="checkbox" @change="rebuildGraph" /> Collapse to summary</label><div class="container-move"><button class="ghost" @click="moveContainer(selectedContainer, -20, 0)">← Move</button><button class="ghost" @click="moveContainer(selectedContainer, 20, 0)">Move →</button><button class="ghost" @click="moveContainer(selectedContainer, 0, -20)">↑ Move</button><button class="ghost" @click="moveContainer(selectedContainer, 0, 20)">↓ Move</button></div><button class="text-danger" @click="deleteContainer(selectedContainer.id)">Delete container</button></div></section>
<section class="tag-panel panel"><label>Filter by system tag<select v-model="tagFilter"><option value="all">All tags</option><option v-for="tag in allTags" :key="tag">{{ tag }}</option></select></label><label v-if="selectedSystem">Selected system tags<input :value="(selectedSystem.tags || []).join(', ')" @change="selectedSystem.tags = $event.target.value.split(',').map((tag) => tag.trim()).filter(Boolean); persist()" /></label></section>
</main>
</template>