@decido/shell 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/.turbo/turbo-build.log +13 -0
  2. package/package.json +65 -0
  3. package/src/AgentPlayer.tsx +105 -0
  4. package/src/DecidoPlayer.tsx +117 -0
  5. package/src/bridge/BridgeAgent.ts +443 -0
  6. package/src/components/DecidoIcon.tsx +56 -0
  7. package/src/components/JsonTreeEditor.tsx +117 -0
  8. package/src/components/PanelSplitter.tsx +71 -0
  9. package/src/components/PluginErrorBoundary.tsx +69 -0
  10. package/src/components/SafeLiquidUI.tsx +114 -0
  11. package/src/components/TransientLayer.tsx +92 -0
  12. package/src/components/agent/AgentChat.tsx +134 -0
  13. package/src/components/chat-extensions/IntentCatalogPanel.tsx +81 -0
  14. package/src/components/chat-extensions/chatSlashCommands.ts +101 -0
  15. package/src/components/controls/CreatorInputBar.tsx +144 -0
  16. package/src/components/controls/OSToolbar.tsx +90 -0
  17. package/src/components/controls/TimelineTape.tsx +43 -0
  18. package/src/components/debug/ActionTimelineTab.tsx +111 -0
  19. package/src/components/debug/CSSInspectorTab.tsx +436 -0
  20. package/src/components/debug/ExportTab.tsx +192 -0
  21. package/src/components/debug/FlowHealthTab.tsx +86 -0
  22. package/src/components/debug/LogsTab.tsx +110 -0
  23. package/src/components/debug/MorphStackTab.tsx +241 -0
  24. package/src/components/debug/NetworkTab.tsx +173 -0
  25. package/src/components/debug/PerformanceTab.tsx +171 -0
  26. package/src/components/debug/ProfilesTab.tsx +238 -0
  27. package/src/components/debug/ReplayTab.tsx +70 -0
  28. package/src/components/debug/StoresTab.tsx +255 -0
  29. package/src/components/debug/TopologyTab.tsx +59 -0
  30. package/src/components/debug/debugConfig.tsx +66 -0
  31. package/src/components/playground/DebugPanel.tsx +112 -0
  32. package/src/components/playground/HeaderCenterControls.tsx +92 -0
  33. package/src/components/playground/KeyframeListItem.tsx +70 -0
  34. package/src/components/playground/PlaygroundAppSidebar.tsx +171 -0
  35. package/src/components/playground/PlaygroundBottomControls.tsx +132 -0
  36. package/src/components/playground/PlaygroundCanvas.tsx +87 -0
  37. package/src/components/playground/PlaygroundChat.tsx +236 -0
  38. package/src/components/playground/PlaygroundErrorBoundary.tsx +63 -0
  39. package/src/components/playground/PlaygroundFloatingInput.tsx +352 -0
  40. package/src/components/playground/PlaygroundHeader.tsx +222 -0
  41. package/src/components/playground/PlaygroundSidebar.tsx +136 -0
  42. package/src/components/playground/PlaygroundTerminal.tsx +44 -0
  43. package/src/components/playground/SuggestionCards.tsx +29 -0
  44. package/src/components/playground/demos/ClinicaAINode.tsx +221 -0
  45. package/src/components/playground/demos/FinanceAINode.tsx +226 -0
  46. package/src/components/playground/demos/KiaAcademyNode.tsx +250 -0
  47. package/src/components/playground/demos/KiaBotNode.tsx +207 -0
  48. package/src/components/playground/demos/KiaCampaignNode.tsx +191 -0
  49. package/src/components/playground/demos/KiaComplianceNode.tsx +140 -0
  50. package/src/components/playground/demos/KiaCustomerJourneyNode.tsx +220 -0
  51. package/src/components/playground/demos/KiaCyberNode.tsx +203 -0
  52. package/src/components/playground/demos/KiaDashboardNode.tsx +399 -0
  53. package/src/components/playground/demos/KiaEmbudoOverviewNode.tsx +168 -0
  54. package/src/components/playground/demos/KiaExecutiveNode.tsx +169 -0
  55. package/src/components/playground/demos/KiaGamificationNode.tsx +229 -0
  56. package/src/components/playground/demos/KiaIntelligenceHubNode.tsx +165 -0
  57. package/src/components/playground/demos/KiaInventoryNode.tsx +183 -0
  58. package/src/components/playground/demos/KiaLeadScoringNode.tsx +226 -0
  59. package/src/components/playground/demos/KiaLiveSimulationNode.tsx +177 -0
  60. package/src/components/playground/demos/KiaMultiDealerNode.tsx +223 -0
  61. package/src/components/playground/demos/KiaNPSVoiceNode.tsx +214 -0
  62. package/src/components/playground/demos/KiaOmnichannelNode.tsx +162 -0
  63. package/src/components/playground/demos/KiaPBIBudgetNode.tsx +152 -0
  64. package/src/components/playground/demos/KiaPBIConversionNode.tsx +206 -0
  65. package/src/components/playground/demos/KiaPBIFunnelNode.tsx +184 -0
  66. package/src/components/playground/demos/KiaPBIOwnershipNode.tsx +113 -0
  67. package/src/components/playground/demos/KiaPBIPartnerNode.tsx +143 -0
  68. package/src/components/playground/demos/KiaPBIPreciosNode.tsx +120 -0
  69. package/src/components/playground/demos/KiaPBIRuntNode.tsx +205 -0
  70. package/src/components/playground/demos/KiaPartnerScoreNode.tsx +206 -0
  71. package/src/components/playground/demos/KiaPredictiveNode.tsx +226 -0
  72. package/src/components/playground/demos/KiaShowroomNode.tsx +194 -0
  73. package/src/components/playground/demos/KiaStoreNode.tsx +215 -0
  74. package/src/components/playground/demos/KiaSustainabilityNode.tsx +173 -0
  75. package/src/components/playground/demos/KiaUsedVehiclesNode.tsx +163 -0
  76. package/src/components/playground/demos/KiaWorkshopNode.tsx +221 -0
  77. package/src/components/playground/demos/SmartCityNode.tsx +205 -0
  78. package/src/components/playground/demos/kia_campaign_manifest.json +112 -0
  79. package/src/components/playground/input-parts/AIModelSelector.tsx +156 -0
  80. package/src/components/playground/input-parts/InputActions.tsx +80 -0
  81. package/src/components/playground/input-parts/InputToolbar.tsx +245 -0
  82. package/src/components/playground/input-parts/ResourceLibraryPanel.tsx +287 -0
  83. package/src/components/playground/sidebarDsdIO.ts +82 -0
  84. package/src/components/settings/SettingsPanel.tsx +267 -0
  85. package/src/components/shell/AppHeader.tsx +9 -0
  86. package/src/components/shell/AppShell.tsx +139 -0
  87. package/src/components/shell/ArtifactBar.tsx +97 -0
  88. package/src/components/shell/BootScreen.tsx +19 -0
  89. package/src/components/shell/CenterComposite.tsx +87 -0
  90. package/src/components/shell/CodeEditorPanel.tsx +88 -0
  91. package/src/components/shell/GlobalOverlays.tsx +228 -0
  92. package/src/components/shell/LayoutConfigurator.tsx +209 -0
  93. package/src/components/shell/LayoutGrid.tsx +178 -0
  94. package/src/components/shell/MorphShell.tsx +368 -0
  95. package/src/components/shell/PluginViewer.tsx +147 -0
  96. package/src/components/shell/ShellNexusPreview.tsx +458 -0
  97. package/src/components/shell/SlotRenderer.tsx +115 -0
  98. package/src/components/shell/TabBar.tsx +94 -0
  99. package/src/components/shell/TemplateLibrary.tsx +195 -0
  100. package/src/components/shell/layoutConstants.ts +35 -0
  101. package/src/components/shell/morphStageMeta.ts +15 -0
  102. package/src/components/shell/shells/BuiltInShells.tsx +443 -0
  103. package/src/components/shell/shells/DatawayChatShell.tsx +42 -0
  104. package/src/components/shell/shells/TokenPreview.tsx +339 -0
  105. package/src/components/shell/shells/bootShells.ts +31 -0
  106. package/src/components/shells/CreatorShell.tsx +37 -0
  107. package/src/components/shells/DecidoShell.tsx +447 -0
  108. package/src/components/shells/ExperimentalChatShell.tsx +245 -0
  109. package/src/components/shells/UserCanvas.tsx +44 -0
  110. package/src/components/studio/BlueprintManagerPanel.tsx +137 -0
  111. package/src/components/studio/DependencyTreePanel.tsx +192 -0
  112. package/src/components/studio/NodePalette.tsx +92 -0
  113. package/src/components/studio/NodePropertiesPanel.tsx +81 -0
  114. package/src/components/studio/ReactFlowEditor.tsx +242 -0
  115. package/src/components/studio/TimelineEditor.tsx +122 -0
  116. package/src/components/studio/TimelineKeyframeCard.tsx +99 -0
  117. package/src/components/studio/VariablePanel.tsx +181 -0
  118. package/src/components/studio/blueprint/BlueprintCard.tsx +82 -0
  119. package/src/components/studio/editor/CanvasContextMenu.tsx +107 -0
  120. package/src/components/studio/editor/EditorToolbar.tsx +80 -0
  121. package/src/components/studio/editor/StageContentRenderer.tsx +134 -0
  122. package/src/components/studio/editor/TrackPropertyEditors.tsx +133 -0
  123. package/src/components/studio/editor/TreeNodeItem.tsx +91 -0
  124. package/src/components/studio/editor/edgeStyles.ts +43 -0
  125. package/src/components/studio/editor/editorKeyHandler.ts +95 -0
  126. package/src/components/studio/editor/nodeTypeRegistry.ts +137 -0
  127. package/src/components/studio/editor/paletteCatalog.tsx +84 -0
  128. package/src/components/studio/nodes/shell/InteractionNodes.tsx +82 -0
  129. package/src/components/studio/nodes/shell/LayoutControlNodes.tsx +69 -0
  130. package/src/components/studio/nodes/shell/RegisterActionNode.tsx +20 -0
  131. package/src/components/studio/nodes/shell/RegisterButtonNode.tsx +22 -0
  132. package/src/components/studio/nodes/shell/RegisterPanelNode.tsx +19 -0
  133. package/src/components/studio/nodes/shell/RegisterSidebarNode.tsx +19 -0
  134. package/src/components/studio/nodes/shell/RegisterStatusBarNode.tsx +22 -0
  135. package/src/components/studio/nodes/shell/RegisterTabNode.tsx +21 -0
  136. package/src/components/studio/nodes/shell/RegisterTopBarNode.tsx +22 -0
  137. package/src/components/studio/nodes/shell/ShellConfigNode.tsx +51 -0
  138. package/src/components/studio/nodes/shell/ShellNodeBase.tsx +100 -0
  139. package/src/components/studio/nodes/shell/ThemeNodes.tsx +51 -0
  140. package/src/components/studio/nodes/shell/index.ts +12 -0
  141. package/src/components/widgets/BroadcastWidget.tsx +93 -0
  142. package/src/components/widgets/MarketplaceWidget.tsx +298 -0
  143. package/src/components/widgets/McpToolsWidget.tsx +231 -0
  144. package/src/components/widgets/OpsDashboard.tsx +59 -0
  145. package/src/components/widgets/QuickActionsWidget.tsx +60 -0
  146. package/src/components/widgets/UsageWidget.tsx +112 -0
  147. package/src/components/widgets/WidgetRenderer.tsx +892 -0
  148. package/src/components/widgets/WidgetSlotPanel.tsx +213 -0
  149. package/src/config/IconRegistry.ts +126 -0
  150. package/src/contexts/NetworkProvider.tsx +162 -0
  151. package/src/core/AIDirector.ts +71 -0
  152. package/src/core/EventBus.ts +37 -0
  153. package/src/core/PluginContext.tsx +141 -0
  154. package/src/hooks/listeners/useUIStateListener.ts +59 -0
  155. package/src/hooks/listeners/useWhatsAppListener.ts +110 -0
  156. package/src/hooks/morphBridge.ts +82 -0
  157. package/src/hooks/useAIModelSelector.ts +144 -0
  158. package/src/hooks/useAgentStream.ts +220 -0
  159. package/src/hooks/useAutoUpdater.ts +89 -0
  160. package/src/hooks/useBootSequence.ts +20 -0
  161. package/src/hooks/useExportDSD.ts +53 -0
  162. package/src/hooks/useFullscreen.ts +35 -0
  163. package/src/hooks/useGeminiStream.ts +282 -0
  164. package/src/hooks/useIntentLens.ts +224 -0
  165. package/src/hooks/useKeyboardShortcuts.ts +69 -0
  166. package/src/hooks/useLoggerBridge.ts +32 -0
  167. package/src/hooks/useMcpClient.ts +112 -0
  168. package/src/hooks/useNexusaiDeploy.ts +118 -0
  169. package/src/hooks/usePlaybackEngine.ts +21 -0
  170. package/src/hooks/usePlaygroundCommander.ts +475 -0
  171. package/src/hooks/usePluginEngine.ts +165 -0
  172. package/src/hooks/useScreenRecorder.ts +73 -0
  173. package/src/hooks/useShellKeyboard.ts +40 -0
  174. package/src/hooks/useShellShortcuts.ts +118 -0
  175. package/src/hooks/useSoundEffects.ts +35 -0
  176. package/src/hooks/useStudioConfig.ts +72 -0
  177. package/src/hooks/useSystemBoot.ts +84 -0
  178. package/src/hooks/useSystemTelemetry.ts +62 -0
  179. package/src/index.ts +97 -0
  180. package/src/lib/debugLogger.ts +80 -0
  181. package/src/lib/networkInterceptor.ts +100 -0
  182. package/src/mocks/decido.tsx +41 -0
  183. package/src/plugins/pluginAPI.ts +190 -0
  184. package/src/store/McpStore.ts +69 -0
  185. package/src/store/UpdaterStore.ts +60 -0
  186. package/src/store/engine.ts +392 -0
  187. package/src/store/index.ts +4 -0
  188. package/src/store/layoutPresets.ts +66 -0
  189. package/src/store/playgroundTypes.ts +98 -0
  190. package/src/store/useActionTimelineStore.ts +48 -0
  191. package/src/store/useDebugPanelStore.ts +98 -0
  192. package/src/store/useDebugProfileStore.ts +130 -0
  193. package/src/store/useLayoutStore.ts +205 -0
  194. package/src/store/useMorphInstanceStore.ts +289 -0
  195. package/src/store/useMorphologyStore.ts +103 -0
  196. package/src/store/usePlaygroundStore.ts +236 -0
  197. package/src/store/useShellRegistry.ts +123 -0
  198. package/src/store/useSuggestionsStore.ts +57 -0
  199. package/src/store/useThemeStore.ts +399 -0
  200. package/src/store/useUIComponentStore.ts +179 -0
  201. package/src/types/DecidoStoryDefinition.ts +43 -0
  202. package/src/utils/ai/ai-architect.ts +92 -0
  203. package/src/utils/ai/ai-code.ts +187 -0
  204. package/src/utils/ai/ai-core.ts +50 -0
  205. package/src/utils/ai/ai-media.ts +292 -0
  206. package/src/utils/layoutGraph.ts +67 -0
  207. package/tsconfig.json +17 -0
  208. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,98 @@
1
+ import { create } from 'zustand';
2
+
3
+ export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
4
+ export type DebugTab = 'logs' | 'flow-health' | 'topology' | 'replay' | 'stores' | 'morph-stack' | 'network' | 'profiles' | 'timeline' | 'performance' | 'export' | 'css-inspector';
5
+
6
+ export interface DebugLogEntry {
7
+ id: number;
8
+ timestamp: string;
9
+ level: LogLevel;
10
+ categories: string[];
11
+ message: string;
12
+ data?: any;
13
+ source?: { fileName: string; line: string };
14
+ }
15
+
16
+ interface LogFilters {
17
+ levels: Set<LogLevel>;
18
+ categories: Set<string>;
19
+ }
20
+
21
+ interface DebugPanelState {
22
+ isOpen: boolean;
23
+ activeTab: DebugTab;
24
+ logEntries: DebugLogEntry[];
25
+ logFilters: LogFilters;
26
+ allCategories: Set<string>;
27
+ errorCount: number;
28
+
29
+ // Actions
30
+ togglePanel: () => void;
31
+ setOpen: (open: boolean) => void;
32
+ setActiveTab: (tab: DebugTab) => void;
33
+ addLogEntry: (entry: Omit<DebugLogEntry, 'id'>) => void;
34
+ clearLogs: () => void;
35
+ toggleLevel: (level: LogLevel) => void;
36
+ toggleCategory: (category: string) => void;
37
+ resetFilters: () => void;
38
+ }
39
+
40
+ const MAX_LOG_ENTRIES = 500;
41
+ let _logId = 0;
42
+
43
+ export const useDebugPanelStore = create<DebugPanelState>((set, get) => ({
44
+ isOpen: false,
45
+ activeTab: 'logs',
46
+ logEntries: [],
47
+ logFilters: {
48
+ levels: new Set<LogLevel>(['info', 'warn', 'error', 'debug']),
49
+ categories: new Set<string>(),
50
+ },
51
+ allCategories: new Set<string>(),
52
+ errorCount: 0,
53
+
54
+ togglePanel: () => set(s => ({ isOpen: !s.isOpen })),
55
+ setOpen: (open) => set({ isOpen: open }),
56
+ setActiveTab: (tab) => set({ activeTab: tab }),
57
+
58
+ addLogEntry: (entry) => {
59
+ const id = ++_logId;
60
+ const newEntry: DebugLogEntry = { ...entry, id };
61
+ set(s => {
62
+ const entries = [...s.logEntries, newEntry];
63
+ if (entries.length > MAX_LOG_ENTRIES) entries.splice(0, entries.length - MAX_LOG_ENTRIES);
64
+
65
+ const allCats = new Set(s.allCategories);
66
+ entry.categories.forEach(c => allCats.add(c));
67
+
68
+ return {
69
+ logEntries: entries,
70
+ allCategories: allCats,
71
+ errorCount: entry.level === 'error' ? s.errorCount + 1 : s.errorCount,
72
+ };
73
+ });
74
+ },
75
+
76
+ clearLogs: () => set({ logEntries: [], errorCount: 0 }),
77
+
78
+ toggleLevel: (level) => set(s => {
79
+ const levels = new Set(s.logFilters.levels);
80
+ if (levels.has(level)) levels.delete(level);
81
+ else levels.add(level);
82
+ return { logFilters: { ...s.logFilters, levels } };
83
+ }),
84
+
85
+ toggleCategory: (category) => set(s => {
86
+ const categories = new Set(s.logFilters.categories);
87
+ if (categories.has(category)) categories.delete(category);
88
+ else categories.add(category);
89
+ return { logFilters: { ...s.logFilters, categories } };
90
+ }),
91
+
92
+ resetFilters: () => set({
93
+ logFilters: {
94
+ levels: new Set<LogLevel>(['info', 'warn', 'error', 'debug']),
95
+ categories: new Set<string>(),
96
+ }
97
+ }),
98
+ }));
@@ -0,0 +1,130 @@
1
+ /**
2
+ * useDebugProfileStore — Persistent debug profiles with watch list, quick actions, log filters.
3
+ * Sprint AQ: Allows creating custom debugging views.
4
+ */
5
+
6
+ import { create } from 'zustand';
7
+ import { persist } from 'zustand/middleware';
8
+ import type { LogLevel } from './useDebugPanelStore';
9
+
10
+ export interface WatchEntry {
11
+ /** Store name (e.g. 'Morphology') */
12
+ storeName: string;
13
+ /** Property path (e.g. 'activeStage.type') */
14
+ path: string;
15
+ /** Friendly label */
16
+ label?: string;
17
+ }
18
+
19
+ export interface PinnedAction {
20
+ storeName: string;
21
+ actionName: string;
22
+ }
23
+
24
+ export interface DebugProfile {
25
+ id: string;
26
+ name: string;
27
+ watchList: WatchEntry[];
28
+ pinnedActions: PinnedAction[];
29
+ logCategories: string[];
30
+ logLevels: LogLevel[];
31
+ notes: string;
32
+ createdAt: number;
33
+ }
34
+
35
+ interface DebugProfileState {
36
+ profiles: DebugProfile[];
37
+ activeProfileId: string | null;
38
+
39
+ createProfile: (name: string) => void;
40
+ updateProfile: (id: string, partial: Partial<DebugProfile>) => void;
41
+ deleteProfile: (id: string) => void;
42
+ activateProfile: (id: string | null) => void;
43
+ getActiveProfile: () => DebugProfile | undefined;
44
+
45
+ // Watch list helpers
46
+ addWatch: (profileId: string, entry: WatchEntry) => void;
47
+ removeWatch: (profileId: string, index: number) => void;
48
+
49
+ // Pinned action helpers
50
+ addPinnedAction: (profileId: string, action: PinnedAction) => void;
51
+ removePinnedAction: (profileId: string, index: number) => void;
52
+ }
53
+
54
+ export const useDebugProfileStore = create<DebugProfileState>()(
55
+ persist(
56
+ (set, get) => ({
57
+ profiles: [],
58
+ activeProfileId: null,
59
+
60
+ createProfile: (name) => {
61
+ const profile: DebugProfile = {
62
+ id: Date.now().toString(36),
63
+ name,
64
+ watchList: [],
65
+ pinnedActions: [],
66
+ logCategories: [],
67
+ logLevels: ['info', 'warn', 'error', 'debug'],
68
+ notes: '',
69
+ createdAt: Date.now(),
70
+ };
71
+ set(s => ({ profiles: [...s.profiles, profile], activeProfileId: profile.id }));
72
+ },
73
+
74
+ updateProfile: (id, partial) => {
75
+ set(s => ({
76
+ profiles: s.profiles.map(p => p.id === id ? { ...p, ...partial } : p),
77
+ }));
78
+ },
79
+
80
+ deleteProfile: (id) => {
81
+ set(s => ({
82
+ profiles: s.profiles.filter(p => p.id !== id),
83
+ activeProfileId: s.activeProfileId === id ? null : s.activeProfileId,
84
+ }));
85
+ },
86
+
87
+ activateProfile: (id) => set({ activeProfileId: id }),
88
+
89
+ getActiveProfile: () => {
90
+ const { profiles, activeProfileId } = get();
91
+ return profiles.find(p => p.id === activeProfileId);
92
+ },
93
+
94
+ addWatch: (profileId, entry) => {
95
+ set(s => ({
96
+ profiles: s.profiles.map(p =>
97
+ p.id === profileId ? { ...p, watchList: [...p.watchList, entry] } : p
98
+ ),
99
+ }));
100
+ },
101
+
102
+ removeWatch: (profileId, index) => {
103
+ set(s => ({
104
+ profiles: s.profiles.map(p =>
105
+ p.id === profileId ? { ...p, watchList: p.watchList.filter((_, i) => i !== index) } : p
106
+ ),
107
+ }));
108
+ },
109
+
110
+ addPinnedAction: (profileId, action) => {
111
+ set(s => ({
112
+ profiles: s.profiles.map(p =>
113
+ p.id === profileId ? { ...p, pinnedActions: [...p.pinnedActions, action] } : p
114
+ ),
115
+ }));
116
+ },
117
+
118
+ removePinnedAction: (profileId, index) => {
119
+ set(s => ({
120
+ profiles: s.profiles.map(p =>
121
+ p.id === profileId ? { ...p, pinnedActions: p.pinnedActions.filter((_, i) => i !== index) } : p
122
+ ),
123
+ }));
124
+ },
125
+ }),
126
+ {
127
+ name: 'decido-debug-profiles-v1',
128
+ }
129
+ )
130
+ );
@@ -0,0 +1,205 @@
1
+ import { create } from 'zustand';
2
+ import { persist, createJSONStorage, StateStorage } from 'zustand/middleware';
3
+ import { get, set as idbSet, del } from 'idb-keyval';
4
+ import { BUILT_IN_PRESETS } from './layoutPresets';
5
+ import { dlog } from '../lib/debugLogger';
6
+
7
+ // Re-export all types for backward compat
8
+ export type { SlotComponentId, RegionId, MorphStageType, MorphStage, LayoutTab, LayoutPreset } from './layoutPresets';
9
+ export { BUILT_IN_PRESETS } from './layoutPresets';
10
+ import type { SlotComponentId, RegionId, MorphStage, LayoutTab, LayoutPreset } from './layoutPresets';
11
+
12
+ // ── IDB Storage ──
13
+ const idbStorage: StateStorage = {
14
+ getItem: async (name: string): Promise<string | null> => (await get(name)) || null,
15
+ setItem: async (name: string, value: string): Promise<void> => { await idbSet(name, value); },
16
+ removeItem: async (name: string): Promise<void> => { await del(name); },
17
+ };
18
+
19
+ // ── State Interface ──
20
+
21
+ interface LayoutState {
22
+ // ── Slot assignment ──
23
+ slots: Record<RegionId, SlotComponentId>;
24
+ setSlot: (region: RegionId, componentId: SlotComponentId) => void;
25
+ swapSlots: (r1: RegionId, r2: RegionId) => void;
26
+ resetLayout: (preset: string) => void;
27
+
28
+ // ── UI toggles (absorbed from usePlaygroundStore) ──
29
+ isCreatorMode: boolean;
30
+ setIsCreatorMode: (val: boolean) => void;
31
+ showCanvas: boolean;
32
+ setShowCanvas: (val: boolean) => void;
33
+ showChat: boolean;
34
+ setShowChat: (val: boolean) => void;
35
+ isSidebarOpen: boolean;
36
+ setIsSidebarOpen: (val: boolean) => void;
37
+ isImmersive: boolean;
38
+ setIsImmersive: (val: boolean) => void;
39
+
40
+ // ── Morph stages (absorbed from useMorphologyStore) ──
41
+ activeStage: MorphStage | null;
42
+ stageHistory: MorphStage[];
43
+ setStage: (stage: MorphStage | null) => void;
44
+ pushStage: (stage: MorphStage) => void;
45
+ popStage: () => void;
46
+ clearStages: () => void;
47
+
48
+ // ── T2 Tabs ──
49
+ tabs: LayoutTab[];
50
+ activeTabId: string | null;
51
+ addTab: (tab: LayoutTab) => void;
52
+ removeTab: (tabId: string) => void;
53
+ setActiveTab: (tabId: string) => void;
54
+
55
+ // ── Presets ──
56
+ savedPresets: LayoutPreset[];
57
+ savePreset: (name: string) => void;
58
+ loadPreset: (presetId: string) => void;
59
+ deletePreset: (presetId: string) => void;
60
+ }
61
+
62
+ export const useLayoutStore = create<LayoutState>()(
63
+ persist(
64
+ (set, get) => ({
65
+ // ── Slot assignment ──
66
+ slots: { ...BUILT_IN_PRESETS['player'] },
67
+
68
+ setSlot: (region, componentId) =>
69
+ set((s) => ({ slots: { ...s.slots, [region]: componentId } })),
70
+
71
+ swapSlots: (r1, r2) =>
72
+ set((s) => ({
73
+ slots: { ...s.slots, [r1]: s.slots[r2], [r2]: s.slots[r1] }
74
+ })),
75
+
76
+ resetLayout: (preset) => {
77
+ const p = BUILT_IN_PRESETS[preset];
78
+ if (p) set({ slots: { ...p } });
79
+ },
80
+
81
+ // ── UI toggles ──
82
+ isCreatorMode: false,
83
+ setIsCreatorMode: (val) => {
84
+ set({ isCreatorMode: val });
85
+ // Auto-switch layout preset when toggling mode
86
+ const preset = val ? BUILT_IN_PRESETS['creator'] : BUILT_IN_PRESETS['player'];
87
+ set({ slots: { ...preset } });
88
+ },
89
+ showCanvas: false,
90
+ setShowCanvas: (val) => set({ showCanvas: val }),
91
+ showChat: true,
92
+ setShowChat: (val) => set({ showChat: val }),
93
+ isSidebarOpen: false,
94
+ setIsSidebarOpen: (val) => set({ isSidebarOpen: val }),
95
+ isImmersive: false,
96
+ setIsImmersive: (val) => set({ isImmersive: val }),
97
+
98
+ // ── Morph stages ──
99
+ activeStage: null,
100
+ stageHistory: [],
101
+
102
+ setStage: (stage) => {
103
+ dlog.layout(`setStage → ${stage?.type || 'null'}`, stage);
104
+ set({ activeStage: stage });
105
+ },
106
+
107
+ pushStage: (stage) => {
108
+ const { activeStage, stageHistory } = get();
109
+ dlog.layout(`pushStage → ${stage.type}${stage.label ? ` (${stage.label})` : ''} | depth: ${stageHistory.length + 1}`, { stage, previousStage: activeStage?.type });
110
+ const newHistory = activeStage
111
+ ? [...stageHistory, activeStage]
112
+ : stageHistory;
113
+ set({ activeStage: stage, stageHistory: newHistory });
114
+ },
115
+
116
+ popStage: () => {
117
+ const { stageHistory, activeStage } = get();
118
+ if (stageHistory.length === 0) {
119
+ dlog.layout('popStage → null (history empty)', { poppedStage: activeStage?.type }, 'warn');
120
+ set({ activeStage: null });
121
+ return;
122
+ }
123
+ const prev = stageHistory[stageHistory.length - 1];
124
+ dlog.layout(`popStage → ${prev.type}${prev.label ? ` (${prev.label})` : ''} | depth: ${stageHistory.length - 1}`, { poppedStage: activeStage?.type, restoredStage: prev.type });
125
+ set({
126
+ activeStage: prev,
127
+ stageHistory: stageHistory.slice(0, -1),
128
+ });
129
+ },
130
+
131
+ clearStages: () => {
132
+ dlog.layout('clearStages → all cleared', { previousDepth: get().stageHistory.length });
133
+ set({ activeStage: null, stageHistory: [] });
134
+ },
135
+
136
+ // ── T2 Tabs ──
137
+ tabs: [],
138
+ activeTabId: null,
139
+
140
+ addTab: (tab) => {
141
+ const { tabs } = get();
142
+ // Don't add duplicate tabs
143
+ if (tabs.some((t) => t.id === tab.id)) {
144
+ set({ activeTabId: tab.id });
145
+ return;
146
+ }
147
+ set({ tabs: [...tabs, tab], activeTabId: tab.id });
148
+ },
149
+
150
+ removeTab: (tabId) => {
151
+ const { tabs, activeTabId } = get();
152
+ const newTabs = tabs.filter((t) => t.id !== tabId);
153
+ const newActive =
154
+ activeTabId === tabId
155
+ ? newTabs.length > 0
156
+ ? newTabs[newTabs.length - 1].id
157
+ : null
158
+ : activeTabId;
159
+ set({ tabs: newTabs, activeTabId: newActive });
160
+ },
161
+
162
+ setActiveTab: (tabId) => set({ activeTabId: tabId }),
163
+
164
+ // ── Presets ──
165
+ savedPresets: [],
166
+
167
+ savePreset: (name) => {
168
+ const { slots, savedPresets } = get();
169
+ const preset: LayoutPreset = {
170
+ id: Date.now().toString(36),
171
+ name,
172
+ slots: { ...slots },
173
+ createdAt: Date.now(),
174
+ };
175
+ set({ savedPresets: [...savedPresets, preset] });
176
+ },
177
+
178
+ loadPreset: (presetId) => {
179
+ const { savedPresets } = get();
180
+ const preset = savedPresets.find((p) => p.id === presetId);
181
+ if (preset) set({ slots: { ...preset.slots } });
182
+ },
183
+
184
+ deletePreset: (presetId) => {
185
+ set((s) => ({
186
+ savedPresets: s.savedPresets.filter((p) => p.id !== presetId),
187
+ }));
188
+ },
189
+ }),
190
+ {
191
+ name: 'decido-layout-v4', // v4 forces eviction to clear corrupted react-resizable-panels flex ratios
192
+ storage: createJSONStorage(() => idbStorage),
193
+ partialize: (state) => ({
194
+ slots: state.slots,
195
+ isCreatorMode: state.isCreatorMode,
196
+ isSidebarOpen: state.isSidebarOpen,
197
+ showCanvas: state.showCanvas,
198
+ showChat: state.showChat,
199
+ tabs: state.tabs,
200
+ activeTabId: state.activeTabId,
201
+ savedPresets: state.savedPresets,
202
+ }),
203
+ }
204
+ )
205
+ );