Add layered preset library and starter kits

This commit is contained in:
2026-11-05 23:19:08 +00:00
parent f7a06f487c
commit c6c38101a4
5 changed files with 108 additions and 5 deletions
+15 -1
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, executePipeline, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ComponentRole, type ConnectionModel, type DefinitionActionModel, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type EnvironmentModel, type InfrastructureComponent, type LandscapeModel, type PipelineTrace, type ScenarioModel, type ScenarioStep, type SystemDefinition, type SystemModel, type SystemPreset, uid, validateLandscape } from './model'
import { CAPABILITY_PRESETS, CATALOG_SYSTEM_PRESETS, DEPLOYMENT_TEMPLATES, STARTER_KITS, cloneCapabilities, demoLandscape, executePipeline, SYSTEM_PRESETS, systemFromPreset, type CapabilityModel, type ComponentRole, type ConnectionModel, type DefinitionActionModel, type DeploymentTemplate, type EndpointModel, type EndpointResponseModel, type EnvironmentContainerModel, type EnvironmentModel, type InfrastructureComponent, type LandscapeModel, type PipelineTrace, 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'
@@ -38,6 +38,9 @@ const runtimeConnectionIds = ref<string[]>([])
const runtimePayload = ref('')
const customBuilderOpen = ref(false)
const customDraft = ref<{ name: string; description: string; category: SystemModel['category']; color: string; definition: SystemDefinition }>({ name: 'Custom system', description: 'Describe this reusable system.', category: 'service', color: '#6d7cff', definition: { actions: [], endpoints: [] } })
const presetQuery = ref('')
const presetLayer = ref<'all' | 'system' | 'capability' | 'template' | 'kit'>('all')
const favouritePresetIds = ref<string[]>(loadFavouritePresets())
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 }
@@ -54,15 +57,22 @@ function loadLandscape(): LandscapeModel {
try { return validateLandscape(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null')) } catch { return demoLandscape() }
}
function loadCustomPresets(): SystemPreset[] { try { const value = JSON.parse(localStorage.getItem(PRESET_STORAGE_KEY) || '[]'); return Array.isArray(value) ? value : [] } catch { return [] } }
function loadFavouritePresets(): string[] { try { const value = JSON.parse(localStorage.getItem('dumas-system-favourites-v1') || '[]'); return Array.isArray(value) ? value : [] } catch { return [] } }
const selectedSystem = computed(() => landscape.value.systems.find((item) => item.id === selectedSystemId.value))
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(() => { 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)
const libraryPresets = computed(() => [...SYSTEM_PRESETS, ...customPresets.value.filter((preset) => !SYSTEM_PRESETS.some((item) => item.id === preset.id))])
const filteredLibraryPresets = computed(() => { const query = presetQuery.value.trim().toLowerCase(); return libraryPresets.value.filter((preset) => { const haystack = `${preset.name} ${preset.description} ${(preset.tags || []).join(' ')}`.toLowerCase(); return !query || haystack.includes(query) }) })
const filteredCapabilityPresets = computed(() => { const query = presetQuery.value.trim().toLowerCase(); return CAPABILITY_PRESETS.filter((preset) => !query || `${preset.name} ${preset.description} ${preset.tags.join(' ')}`.toLowerCase().includes(query)) })
const filteredTemplates = computed(() => { const query = presetQuery.value.trim().toLowerCase(); return DEPLOYMENT_TEMPLATES.filter((template) => !query || `${template.name} ${template.description} ${template.tags.join(' ')}`.toLowerCase().includes(query)) })
const filteredKits = computed(() => { const query = presetQuery.value.trim().toLowerCase(); return STARTER_KITS.filter((kit) => !query || `${kit.name} ${kit.description} ${kit.tags.join(' ')}`.toLowerCase().includes(query)) })
function persist() { localStorage.setItem(STORAGE_KEY, JSON.stringify(landscape.value)) }
function persistPresets() { localStorage.setItem(PRESET_STORAGE_KEY, JSON.stringify(customPresets.value)) }
function togglePresetFavourite(id: string) { favouritePresetIds.value = favouritePresetIds.value.includes(id) ? favouritePresetIds.value.filter((item) => item !== id) : [...favouritePresetIds.value, id]; localStorage.setItem('dumas-system-favourites-v1', JSON.stringify(favouritePresetIds.value)) }
function selectSystem(id: string) { selectedSystemId.value = id; selectedConnectionId.value = ''; selectedEnvironmentId.value = landscape.value.systems.find((item) => item.id === id)?.environments?.[0]?.id || '' }
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 } }
@@ -79,6 +89,9 @@ function moveContainer(container: EnvironmentContainerModel, dx: number, dy: num
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 placeDeploymentTemplate(template: DeploymentTemplate) { const placed = template.systems.map((item, index) => { const preset = getPresetForLibrary(item.presetId); if (!preset) return null; const system = systemFromPreset(preset, preset.capabilities.map((capability) => capability.id), item.position); system.name = item.name || system.name; landscape.value.systems.push(system); return system }).filter(Boolean) as SystemModel[]; template.connections.forEach((connection) => { const source = placed[connection.sourceIndex]; const target = placed[connection.targetIndex]; if (source && target) landscape.value.connections.push({ id: uid('connection'), sourceId: source.id, targetId: target.id, label: connection.label, description: `${connection.label} in ${template.name}.`, payload: '{}', connectionType: connection.connectionType || 'dependency', exchangeType: 'event-transfer', showCableLabel: true }) }); persist(); rebuildGraph() }
function getPresetForLibrary(id: string) { return libraryPresets.value.find((preset) => preset.id === id) }
function placeStarterKit(kit: typeof STARTER_KITS[number]) { kit.systemPresetIds.forEach((id, index) => { const preset = getPresetForLibrary(id); if (preset) { const system = systemFromPreset(preset, preset.capabilities.map((capability) => capability.id), [120 + (index % 4) * 260, 140 + Math.floor(index / 4) * 180]); landscape.value.systems.push(system) } }); 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 || '{}' })) }
function saveCustomPreset(preset: SystemPreset) { customPresets.value.push(preset); persistPresets(); activeTab.value = 'presets' }
function saveSelectedAsPreset() { if (!selectedSystem.value) return; saveCustomPreset({ id: `custom-${uid('preset')}`, name: `${selectedSystem.value.name} custom`, description: selectedSystem.value.description, category: selectedSystem.value.category, color: selectedSystem.value.color, capabilities: cloneCapabilities(selectedSystem.value.capabilities), definition: structuredClone(selectedSystem.value.definition || { actions: [], endpoints: [] }) }) }
@@ -293,5 +306,6 @@ onUnmounted(stopAnimation)
<section v-if="selectedScenario" class="scenario-environment panel"><span class="eyebrow">SCENARIO ENVIRONMENT</span><label>Environment<select v-model="selectedScenario.environmentId"><option value="">Logical system view</option><option v-for="system in landscape.systems" :key="system.id" :value="system.environments?.[0]?.id" :disabled="!system.environments?.length">{{ system.name }} · {{ system.environments?.[0]?.name || 'No environment' }}</option></select></label><label class="checkbox-label"><input v-model="selectedScenario.traceInternal" type="checkbox" /> Trace internal component connections when available</label></section>
<section v-if="pipelineTrace.length" class="pipeline-inspector panel"><div class="steps-head"><span>Middleware pipeline trace</span><small>Simulated restricted mappings</small></div><article v-for="trace in pipelineTrace" :key="trace.stepId" class="pipeline-trace-row"><div><b>{{ trace.name }}</b><small>{{ trace.type.toUpperCase() }} · {{ trace.explanation }}</small></div><div class="json-columns"><pre>{{ trace.input }}</pre><span>→</span><pre>{{ trace.output }}</pre></div><p v-if="trace.changedFields.length" class="changed-fields">Changed: {{ trace.changedFields.join(', ') }}</p></article></section>
<section v-if="customBuilderOpen" class="pipeline-builder-overlay"><div class="pipeline-builder panel"><div class="inspector-header"><div><span class="eyebrow">ACTION PIPELINES</span><h2>Middleware mapping editor</h2><p class="muted">Optional restricted pipelines are saved inside each action definition. No arbitrary JavaScript is executed.</p></div><button class="danger-icon" @click="customBuilderOpen = false">×</button></div><article v-for="action in customDraft.definition.actions" :key="action.id" class="definition-card"><div class="steps-head"><span>{{ action.name }}</span><button v-if="!action.pipeline" class="ghost" @click="attachPipeline(action)">Add pipeline</button></div><p v-if="!action.pipeline" class="muted">Add Receive, Validate, Transform, Route and Send stages to this action.</p><div v-else><label>Pipeline name<input v-model="action.pipeline.name" /></label><label>Pipeline JSON<textarea :value="JSON.stringify(action.pipeline, null, 2)" @change="updatePipeline(action, $event)" rows="14" class="code"></textarea></label><small class="muted">Mapping ops: copy, rename, fixed, default, type-conversion, object-construction and array-item-mapping. Use <code>$ref:key</code> in a fixed value for a reference lookup.</small></div></article><div class="modal-actions"><button class="ghost" @click="customBuilderOpen = false">Continue editing</button><button class="primary" @click="saveCustomBuilder">Save reusable preset</button></div></div></section>
<section v-if="activeTab === 'presets'" class="catalog-panel panel"><div class="section-heading"><div><span class="eyebrow">LAYERED PRESET LIBRARY</span><strong>Search → choose → review → insert</strong><small>Versioned fictional definitions with official documentation sources.</small></div><button class="ghost" @click="openCustomBuilder">Custom preset</button></div><div class="catalog-controls"><input v-model="presetQuery" placeholder="Search products, capabilities or tags" /><select v-model="presetLayer"><option value="all">All layers</option><option value="system">Systems</option><option value="capability">Capabilities</option><option value="template">Deployments</option><option value="kit">Starter kits</option></select></div><div v-if="presetLayer === 'all' || presetLayer === 'system'" class="catalog-section"><div class="steps-head"><span>Systems</span><small>{{ filteredLibraryPresets.length }} results · favourites are local</small></div><div class="catalog-grid"><article v-for="preset in filteredLibraryPresets" :key="preset.id" class="catalog-card"><div class="catalog-title"><span class="system-dot" :style="{background: preset.color}"></span><strong>{{ preset.name }}</strong><button class="favourite" @click="togglePresetFavourite(preset.id)">{{ favouritePresetIds.includes(preset.id) ? '★' : '☆' }}</button></div><p>{{ preset.description }}</p><div class="catalog-tags"><span v-for="tag in (preset.tags || []).slice(0, 4)" :key="tag">{{ tag }}</span></div><small>{{ preset.capabilities.length }} shared capabilities · v{{ preset.version || 1 }}</small><div class="catalog-actions"><button class="run-mini" @click="openPreset(preset)">Review & place</button><a v-if="preset.sources?.[0]" :href="preset.sources[0].url" target="_blank" rel="noreferrer">Official docs ↗</a></div></article></div></div><div v-if="presetLayer === 'all' || presetLayer === 'capability'" class="catalog-section"><div class="steps-head"><span>Shared capabilities</span><small>{{ filteredCapabilityPresets.length }} reusable definitions</small></div><div class="catalog-grid compact"><article v-for="preset in filteredCapabilityPresets" :key="preset.id" class="catalog-card"><strong>{{ preset.name }}</strong><p>{{ preset.description }}</p><div class="catalog-tags"><span v-for="tag in preset.tags" :key="tag">{{ tag }}</span></div><small>{{ preset.capability.inputs.length }} inputs · {{ preset.capability.outputs.length }} outputs · editable after placement</small></article></div></div><div v-if="presetLayer === 'all' || presetLayer === 'template'" class="catalog-section"><div class="steps-head"><span>Deployment templates</span><small>{{ filteredTemplates.length }} editable layouts</small></div><div class="catalog-grid compact"><article v-for="template in filteredTemplates" :key="template.id" class="catalog-card"><strong>{{ template.name }}</strong><p>{{ template.description }}</p><div class="catalog-tags"><span v-for="tag in template.tags" :key="tag">{{ tag }}</span></div><button class="run-mini" @click="placeDeploymentTemplate(template)">Insert layout</button></article></div></div><div v-if="presetLayer === 'all' || presetLayer === 'kit'" class="catalog-section"><div class="steps-head"><span>Starter kits</span><small>{{ filteredKits.length }} connected journeys</small></div><div class="catalog-grid compact"><article v-for="kit in filteredKits" :key="kit.id" class="catalog-card"><strong>{{ kit.name }}</strong><p>{{ kit.description }}</p><div class="catalog-tags"><span v-for="tag in kit.tags" :key="tag">{{ tag }}</span></div><button class="run-mini" @click="placeStarterKit(kit)">Insert kit systems</button></article></div></div></section>
</main>
</template>