@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,213 @@
1
+ import React from 'react';
2
+ import { WidgetRenderer, type WidgetDef, type ServerDrivenNode } from './WidgetRenderer';
3
+ import { useLayoutStore } from '../../store/useLayoutStore';
4
+
5
+ /**
6
+ * WidgetSlotPanel — Reads active widgets and renders them.
7
+ *
8
+ * This is the "slot consumer" that bridges widget data → LayoutGrid.
9
+ * When a plugin registers a widget (via sidebar click or SDK),
10
+ * this panel shows it using WidgetRenderer.
11
+ *
12
+ * Supports side-by-side comparison of Option A (SDUI) and Option B (iframe).
13
+ */
14
+
15
+ // ── Widget Store with localStorage persistence ──
16
+
17
+ const PERSISTENCE_KEY = 'decido:activeWidgets';
18
+ type Listener = () => void;
19
+
20
+ interface PersistedWidget {
21
+ id: string; pluginId: string; title: string; icon?: string;
22
+ slot: string; url?: string; order?: number;
23
+ }
24
+
25
+ class WidgetStore {
26
+ private widgets = new Map<string, WidgetDef>();
27
+ private listeners = new Set<Listener>();
28
+ private _activeId: string | null = null;
29
+ private persistTimer: ReturnType<typeof setTimeout> | null = null;
30
+
31
+ register(widget: WidgetDef): void {
32
+ this.widgets.set(widget.id, { ...widget, visible: widget.visible ?? true });
33
+ this.notify();
34
+ this.persist();
35
+ }
36
+
37
+ remove(id: string): void {
38
+ this.widgets.delete(id);
39
+ if (this._activeId === id) this._activeId = null;
40
+ this.notify();
41
+ this.persist();
42
+ }
43
+
44
+ clear(): void {
45
+ this.widgets.clear();
46
+ this._activeId = null;
47
+ this.notify();
48
+ this.persist();
49
+ }
50
+
51
+ setActive(id: string | null): void {
52
+ this._activeId = id;
53
+ this.notify();
54
+ this.persist();
55
+ }
56
+
57
+ get activeId() { return this._activeId; }
58
+ get size() { return this.widgets.size; }
59
+
60
+ getVisible(): WidgetDef[] {
61
+ return Array.from(this.widgets.values())
62
+ .filter(w => w.visible !== false)
63
+ .sort((a, b) => (a.order ?? 100) - (b.order ?? 100));
64
+ }
65
+
66
+ /** Restore from localStorage (call on mount with schema resolver) */
67
+ restoreFromPersistence(schemaResolver: (widgetId: string) => ServerDrivenNode | undefined): boolean {
68
+ try {
69
+ const raw = localStorage.getItem(PERSISTENCE_KEY);
70
+ if (!raw) return false;
71
+ const snapshot = JSON.parse(raw) as { widgets: PersistedWidget[]; activeId: string | null };
72
+ if (!snapshot?.widgets?.length) return false;
73
+
74
+ for (const pw of snapshot.widgets) {
75
+ const schema = schemaResolver(pw.id);
76
+ this.widgets.set(pw.id, {
77
+ ...pw,
78
+ visible: true,
79
+ schema,
80
+ });
81
+ }
82
+ this._activeId = snapshot.activeId;
83
+ this.notify();
84
+ console.log(`[WidgetStore] Restored ${snapshot.widgets.length} widgets from persistence`);
85
+ return true;
86
+ } catch (e) {
87
+ console.warn('[WidgetStore] Restore failed:', e);
88
+ return false;
89
+ }
90
+ }
91
+
92
+ subscribe(fn: Listener): () => void {
93
+ this.listeners.add(fn);
94
+ return () => this.listeners.delete(fn);
95
+ }
96
+
97
+ private notify() {
98
+ this.listeners.forEach(fn => fn());
99
+ }
100
+
101
+ /** Debounced write to localStorage (excludes schema which can't be serialized) */
102
+ private persist() {
103
+ if (this.persistTimer) clearTimeout(this.persistTimer);
104
+ this.persistTimer = setTimeout(() => {
105
+ try {
106
+ const snapshot = {
107
+ widgets: Array.from(this.widgets.values()).map(w => ({
108
+ id: w.id, pluginId: w.pluginId, title: w.title,
109
+ icon: w.icon, slot: w.slot, url: w.url, order: w.order,
110
+ })),
111
+ activeId: this._activeId,
112
+ };
113
+ localStorage.setItem(PERSISTENCE_KEY, JSON.stringify(snapshot));
114
+ } catch { /* quota exceeded — silently fail */ }
115
+ }, 300);
116
+ }
117
+ }
118
+
119
+ export const pluginWidgetStore = new WidgetStore();
120
+
121
+ // Expose on window for PluginBridge's getWidgets handler (avoids circular import)
122
+ (window as any).__pluginWidgetStore = pluginWidgetStore;
123
+
124
+ // ── React Hook ──
125
+ function useWidgetStore() {
126
+ const [, forceUpdate] = React.useReducer(x => x + 1, 0);
127
+ React.useEffect(() => pluginWidgetStore.subscribe(forceUpdate), []);
128
+ return {
129
+ widgets: pluginWidgetStore.getVisible(),
130
+ activeId: pluginWidgetStore.activeId,
131
+ };
132
+ }
133
+
134
+ // ── Component ──
135
+
136
+ export function WidgetSlotPanel() {
137
+ const { widgets, activeId } = useWidgetStore();
138
+
139
+ const activeWidget = activeId
140
+ ? widgets.find(w => w.id === activeId) || widgets[0]
141
+ : widgets[0];
142
+
143
+ /** Close widget and restore R3 if no widgets remain */
144
+ const handleClose = React.useCallback((widgetId: string) => {
145
+ pluginWidgetStore.remove(widgetId);
146
+ // If removing the last widget, restore R3 to null
147
+ if (pluginWidgetStore.size === 0) {
148
+ useLayoutStore.getState().setSlot('R3', null);
149
+ }
150
+ }, []);
151
+
152
+ /** Close ALL widgets (button in tab bar) */
153
+ const handleCloseAll = React.useCallback(() => {
154
+ pluginWidgetStore.clear();
155
+ useLayoutStore.getState().setSlot('R3', null);
156
+ }, []);
157
+
158
+ if (widgets.length === 0) {
159
+ return (
160
+ <div className="w-full h-full flex flex-col items-center justify-center text-text-muted gap-3 bg-surface-primary">
161
+ <div className="w-12 h-12 rounded-xl bg-cyan-500/5 border border-cyan-500/10 flex items-center justify-center">
162
+ <span className="text-xl">🧩</span>
163
+ </div>
164
+ <p className="text-sm font-medium">No widgets activos</p>
165
+ <p className="text-xs opacity-60 max-w-[200px] text-center">
166
+ Selecciona un plugin del sidebar para ver widgets aquí
167
+ </p>
168
+ </div>
169
+ );
170
+ }
171
+
172
+ return (
173
+ <div className="w-full h-full flex flex-col bg-surface-primary overflow-hidden">
174
+ {/* Widget tab bar */}
175
+ <div className="flex-none flex items-center gap-1 px-2 py-1 bg-surface-secondary border-b border-border-subtle overflow-x-auto">
176
+ {widgets.map(w => (
177
+ <button
178
+ key={w.id}
179
+ onClick={() => pluginWidgetStore.setActive(w.id)}
180
+ className={`px-2.5 py-1 rounded-md text-[10px] font-medium transition-all whitespace-nowrap ${
181
+ activeWidget?.id === w.id
182
+ ? 'bg-surface-glass text-text-primary border border-border-default'
183
+ : 'text-text-muted hover:text-text-secondary hover:bg-surface-glass/50'
184
+ }`}
185
+ >
186
+ {w.icon && <span className="mr-1">{w.icon}</span>}
187
+ {w.title}
188
+ </button>
189
+ ))}
190
+ {/* Close All button */}
191
+ {widgets.length > 1 && (
192
+ <button
193
+ onClick={handleCloseAll}
194
+ className="ml-auto px-2 py-1 rounded-md text-[10px] text-text-muted hover:text-red-400 hover:bg-red-500/10 transition-all"
195
+ title="Close all widgets"
196
+ >
197
+ ✕ All
198
+ </button>
199
+ )}
200
+ </div>
201
+
202
+ {/* Active widget content */}
203
+ {activeWidget && (
204
+ <div className="flex-1 min-h-0 min-w-0 overflow-hidden">
205
+ <WidgetRenderer
206
+ widget={activeWidget}
207
+ onClose={() => handleClose(activeWidget.id)}
208
+ />
209
+ </div>
210
+ )}
211
+ </div>
212
+ );
213
+ }
@@ -0,0 +1,126 @@
1
+ import {
2
+ Search, Workflow, Zap, Terminal, BrainCircuit, Command,
3
+ FileText, Cpu, ShoppingCart, Building2, Activity,
4
+ Thermometer, AlertTriangle, TrendingUp, PackageCheck,
5
+ Network, Home, Settings, MessageSquare, Globe, Lock,
6
+ Shield, Database, HardDrive, Wifi, Cloud, Server,
7
+ BarChart3, PieChart, Gauge, Bell, Mail, Users,
8
+ FolderOpen, Code, Layers, Box, Rocket, Sparkles,
9
+ type LucideIcon
10
+ } from 'lucide-react';
11
+
12
+ /**
13
+ * IconRegistry — Resuelve nombres de iconos (strings del JSON) a componentes Lucide.
14
+ *
15
+ * Uso:
16
+ * const Icon = resolveIcon("Thermometer"); // → Lucide Thermometer component
17
+ * <Icon size={16} />
18
+ *
19
+ * Si el icono no existe, retorna `Command` como fallback.
20
+ */
21
+ const ICON_MAP: Record<string, LucideIcon> = {
22
+ // Communication & AI
23
+ 'Search': Search,
24
+ 'MessageSquare': MessageSquare,
25
+ 'BrainCircuit': BrainCircuit,
26
+ 'Sparkles': Sparkles,
27
+ 'Command': Command,
28
+ 'Terminal': Terminal,
29
+
30
+ // Actions & Flow
31
+ 'Workflow': Workflow,
32
+ 'Zap': Zap,
33
+ 'Rocket': Rocket,
34
+ 'Network': Network,
35
+
36
+ // Data & Files
37
+ 'FileText': FileText,
38
+ 'FolderOpen': FolderOpen,
39
+ 'Code': Code,
40
+ 'Database': Database,
41
+
42
+ // Business & Commerce
43
+ 'ShoppingCart': ShoppingCart,
44
+ 'Building2': Building2,
45
+ 'Users': Users,
46
+
47
+ // Monitoring & Metrics
48
+ 'Activity': Activity,
49
+ 'Thermometer': Thermometer,
50
+ 'AlertTriangle': AlertTriangle,
51
+ 'TrendingUp': TrendingUp,
52
+ 'BarChart3': BarChart3,
53
+ 'PieChart': PieChart,
54
+ 'Gauge': Gauge,
55
+ 'Bell': Bell,
56
+
57
+ // Infrastructure
58
+ 'Cpu': Cpu,
59
+ 'HardDrive': HardDrive,
60
+ 'Server': Server,
61
+ 'Cloud': Cloud,
62
+ 'Wifi': Wifi,
63
+ 'PackageCheck': PackageCheck,
64
+
65
+ // Security & Settings
66
+ 'Lock': Lock,
67
+ 'Shield': Shield,
68
+ 'Settings': Settings,
69
+
70
+ // Misc
71
+ 'Globe': Globe,
72
+ 'Mail': Mail,
73
+ 'Home': Home,
74
+ 'Layers': Layers,
75
+ 'Box': Box
76
+ };
77
+
78
+ /**
79
+ * Resolve a string icon name to a Lucide component.
80
+ * Returns Command icon as fallback for unknown names.
81
+ */
82
+ export function resolveIcon(name: string): LucideIcon {
83
+ return ICON_MAP[name] || Command;
84
+ }
85
+
86
+ /**
87
+ * Color token resolver — maps color names to Tailwind text classes.
88
+ */
89
+ const COLOR_MAP: Record<string, string> = {
90
+ 'emerald': 'text-emerald-400',
91
+ 'cyan': 'text-cyan-400',
92
+ 'purple': 'text-purple-400',
93
+ 'orange': 'text-orange-400',
94
+ 'yellow': 'text-yellow-400',
95
+ 'rose': 'text-rose-400',
96
+ 'red': 'text-red-400',
97
+ 'blue': 'text-blue-400',
98
+ 'indigo': 'text-indigo-400',
99
+ 'pink': 'text-pink-400',
100
+ 'amber': 'text-amber-400',
101
+ 'teal': 'text-teal-400',
102
+ 'lime': 'text-lime-400',
103
+ 'sky': 'text-sky-400',
104
+ 'violet': 'text-violet-400',
105
+ 'fuchsia': 'text-fuchsia-400',
106
+ 'white': 'text-white'
107
+ };
108
+
109
+ /**
110
+ * Resolve a color token name to a Tailwind text class.
111
+ * Returns "text-white" as fallback.
112
+ */
113
+ export function resolveColor(name: string): string {
114
+ return COLOR_MAP[name] || 'text-white';
115
+ }
116
+
117
+ /**
118
+ * Generate bg/border classes from a color token.
119
+ */
120
+ export function resolveColorClasses(color: string): { bg: string; border: string; text: string } {
121
+ return {
122
+ text: COLOR_MAP[color] || 'text-white',
123
+ bg: `bg-${color}-500/10`,
124
+ border: `border-${color}-500/20`
125
+ };
126
+ }
@@ -0,0 +1,162 @@
1
+ import React, { createContext, useContext, ReactNode, useEffect, useRef, useCallback } from 'react';
2
+
3
+ // Tauri APIs are loaded DYNAMICALLY to avoid Vite resolution errors
4
+ // in non-Tauri (web-only) environments where @tauri-apps/api doesn't exist.
5
+ // Type-only import for UnlistenFn (erased at runtime)
6
+ type UnlistenFn = () => void;
7
+
8
+ // Detección segura del entorno Tauri
9
+ const isTauri = typeof window !== 'undefined' && (window as any).__TAURI_INTERNALS__ !== undefined;
10
+
11
+ // Lazy-loaded Tauri modules (only resolved at runtime when isTauri === true)
12
+ // @ts-ignore — @tauri-apps/api only exists inside the Tauri binary
13
+ const getTauriEvent = () => import(/* @vite-ignore */ '@tauri-apps/api/event');
14
+ // @ts-ignore
15
+ const getTauriCore = () => import(/* @vite-ignore */ '@tauri-apps/api/core');
16
+
17
+ interface NetworkContextType {
18
+ socket: any | null;
19
+ isConnected: boolean;
20
+ isNativeOS: boolean; // Nos dice si estamos corriendo en el binario de Rust
21
+ emitEvent: (event: string, payload: any) => void;
22
+ onEvent: (event: string, callback: (payload: any) => void) => void;
23
+ offEvent: (event: string, callback: (payload: any) => void) => void;
24
+ }
25
+
26
+ const NetworkContext = createContext<NetworkContextType>({
27
+ socket: null,
28
+ isConnected: false,
29
+ isNativeOS: false,
30
+ emitEvent: () => {},
31
+ onEvent: () => {},
32
+ offEvent: () => {}
33
+ });
34
+
35
+ export const useNetwork = () => useContext(NetworkContext);
36
+
37
+ export const useNetworkEvent = (eventName: string, callback: (payload: any) => void) => {
38
+ const { onEvent, offEvent } = useNetwork();
39
+ useEffect(() => {
40
+ onEvent(eventName, callback);
41
+ return () => offEvent(eventName, callback);
42
+ }, [eventName, callback, onEvent, offEvent]);
43
+ };
44
+
45
+ interface NetworkProviderProps {
46
+ children: ReactNode;
47
+ socketInstance?: any;
48
+ isConnected?: boolean;
49
+ }
50
+
51
+ export const NetworkProvider = ({ children, socketInstance = null, isConnected = false }: NetworkProviderProps) => {
52
+ // Referencias para limpiar listeners de WebSocket nativo
53
+ const nativeListeners = useRef(new Map<string, Array<{originalCallback: any, wrappedCallback: any}>>());
54
+ // Referencias para limpiar listeners asíncronos de Tauri
55
+ const tauriListeners = useRef(new Map<string, Array<{originalCallback: any, unlistenPromise: Promise<UnlistenFn>}>>());
56
+
57
+ const emitEvent = useCallback(async (event: string, payload: any) => {
58
+ if (isTauri) {
59
+ // 🦀 RUTA TAURI: Enviar al Daemon en Rust
60
+ try {
61
+ const { emit } = await getTauriEvent();
62
+ await emit(event, payload);
63
+ } catch (err) {
64
+ console.error(`[Tauri IPC] Error emitiendo ${event}:`, err);
65
+ }
66
+ return;
67
+ }
68
+
69
+ // 🌐 RUTA WEB: Socket.io o WebSocket Nativo
70
+ if (!socketInstance) {
71
+ console.warn(`[NetworkProvider] Emit '${event}' ignorado: No hay red disponible.`);
72
+ return;
73
+ }
74
+
75
+ if (typeof socketInstance.emit === 'function') {
76
+ socketInstance.emit(event, payload);
77
+ } else if (typeof socketInstance.send === 'function') {
78
+ socketInstance.send(JSON.stringify({ event, payload }));
79
+ }
80
+ }, [socketInstance]);
81
+
82
+ const onEvent = useCallback((event: string, callback: (payload: any) => void) => {
83
+ if (isTauri) {
84
+ // 🦀 RUTA TAURI: Escuchar eventos desde Rust
85
+ const unlistenPromise = getTauriEvent().then(({ listen }) =>
86
+ listen(event, (tauriEvent: any) => {
87
+ callback(tauriEvent.payload);
88
+ })
89
+ );
90
+
91
+ if (!tauriListeners.current.has(event)) {
92
+ tauriListeners.current.set(event,[]);
93
+ }
94
+ tauriListeners.current.get(event)?.push({ originalCallback: callback, unlistenPromise });
95
+ return;
96
+ }
97
+
98
+ // 🌐 RUTA WEB
99
+ if (!socketInstance) return;
100
+
101
+ if (typeof socketInstance.on === 'function') {
102
+ socketInstance.on(event, callback);
103
+ } else if (typeof socketInstance.addEventListener === 'function') {
104
+ const wrappedCallback = (messageEvent: MessageEvent) => {
105
+ try {
106
+ const data = JSON.parse(messageEvent.data);
107
+ if (data.event === event) callback(data.payload);
108
+ } catch(e) {}
109
+ };
110
+ socketInstance.addEventListener('message', wrappedCallback);
111
+
112
+ if (!nativeListeners.current.has(event)) {
113
+ nativeListeners.current.set(event,[]);
114
+ }
115
+ nativeListeners.current.get(event)?.push({ originalCallback: callback, wrappedCallback });
116
+ }
117
+ }, [socketInstance]);
118
+
119
+ const offEvent = useCallback((event: string, callback: (payload: any) => void) => {
120
+ if (isTauri) {
121
+ // 🦀 RUTA TAURI: Desuscribir
122
+ const listeners = tauriListeners.current.get(event) ||[];
123
+ const index = listeners.findIndex(l => l.originalCallback === callback);
124
+ if (index > -1) {
125
+ listeners[index].unlistenPromise.then(unlisten => unlisten());
126
+ listeners.splice(index, 1);
127
+ }
128
+ return;
129
+ }
130
+
131
+ // 🌐 RUTA WEB
132
+ if (!socketInstance) return;
133
+
134
+ if (typeof socketInstance.off === 'function') {
135
+ socketInstance.off(event, callback);
136
+ } else if (typeof socketInstance.removeEventListener === 'function') {
137
+ const listeners = nativeListeners.current.get(event) ||[];
138
+ const foundIndex = listeners.findIndex(l => l.originalCallback === callback);
139
+ if (foundIndex > -1) {
140
+ const { wrappedCallback } = listeners[foundIndex];
141
+ socketInstance.removeEventListener('message', wrappedCallback);
142
+ listeners.splice(foundIndex, 1);
143
+ }
144
+ }
145
+ },[socketInstance]);
146
+
147
+ // En Tauri, estamos nativamente conectados al SO local
148
+ const effectiveConnection = isTauri ? true : isConnected;
149
+
150
+ return (
151
+ <NetworkContext.Provider value={{
152
+ socket: socketInstance,
153
+ isConnected: effectiveConnection,
154
+ isNativeOS: isTauri,
155
+ emitEvent,
156
+ onEvent,
157
+ offEvent
158
+ }}>
159
+ {children}
160
+ </NetworkContext.Provider>
161
+ );
162
+ };
@@ -0,0 +1,71 @@
1
+ import { useShellStore } from '../store/engine';
2
+ import { MaciaIntent } from '@decido/plugin-engine';
3
+
4
+ export class AIDirector {
5
+ /**
6
+ * Scans all active plugins to match a natural language query against their intents.
7
+ * If a match is found, the specific plugin's handler is executed.
8
+ * Otherwise, the query is delegated to a general AI fallback.
9
+ */
10
+ static async processQuery(query: string): Promise<boolean> {
11
+ const { plugins } = useShellStore.getState();
12
+
13
+ // Gather all intents across all registered plugins
14
+ const allIntents: MaciaIntent[] = [];
15
+ plugins.forEach(plugin => {
16
+ if (plugin.intents) {
17
+ allIntents.push(...plugin.intents);
18
+ }
19
+ });
20
+
21
+ // Test the query against intent patterns
22
+ for (const intent of allIntents) {
23
+ const match = query.match(intent.match.pattern);
24
+ if (match) {
25
+ console.log(`[AIDirector] Intent Matched: ${intent.name}`);
26
+ try {
27
+ await intent.handler(match);
28
+ return true; // Match found and handled
29
+ } catch (error) {
30
+ console.error(`[AIDirector] Error handling intent ${intent.name}:`, error);
31
+ throw error;
32
+ }
33
+ }
34
+ }
35
+
36
+ // Fallback: No specific intent matched, delegate to general AI
37
+ console.log(`[AIDirector] No specific intent matched for: "${query}". Delegating to general AI layer.`);
38
+ await this.delegateToGeneralAI(query);
39
+ return false;
40
+ }
41
+
42
+ /**
43
+ * Discovery API: Gathers all available intents from registered plugins
44
+ * Returns a simplified list intended for UI suggestions (like the Command Palette)
45
+ */
46
+ static getSuggestedIntents(): { pluginName: string; intentName: string; description: string; examples: string[] }[] {
47
+ const { plugins } = useShellStore.getState();
48
+ const suggestions: { pluginName: string; intentName: string; description: string; examples: string[] }[] = [];
49
+
50
+ plugins.forEach(plugin => {
51
+ if (plugin.intents) {
52
+ plugin.intents.forEach(intent => {
53
+ suggestions.push({
54
+ pluginName: plugin.name || plugin.manifest?.name || 'Unknown Plugin',
55
+ intentName: intent.name,
56
+ description: intent.match.description,
57
+ examples: intent.match.examples || []
58
+ });
59
+ });
60
+ }
61
+ });
62
+
63
+ return suggestions;
64
+ }
65
+
66
+ private static async delegateToGeneralAI(query: string) {
67
+ // Implementation placeholder for general knowledge routing, LLM generation, etc.
68
+ // This could optionally be wired to AgentManager via a fallback standard plugin context intent.
69
+ console.log(`[AIDirector Fallback] Processing general request: ${query}`);
70
+ }
71
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * EventBus.ts
3
+ *
4
+ * Provides a lightweight, globally accessible cross-plugin Event Engine.
5
+ * Enables the "Any-Flow" Architecture: isolated plugin logic sending
6
+ * uncoupled messaging to UI widgets or Engine evaluations.
7
+ */
8
+
9
+ import { probe } from '@decido/logger';
10
+
11
+ type EventHandler = (payload: any) => void;
12
+
13
+ export const EventBus = {
14
+ listeners: new Map<string, Set<EventHandler>>(),
15
+
16
+ emit(event: string, payload?: any) {
17
+ const listenerCount = this.listeners.get(event)?.size ?? 0;
18
+ probe('eventbus.emit', { event, listenerCount }, { level: 'debug', context: { module: 'shell', component: 'EventBus' } });
19
+ this.listeners.get(event)?.forEach(cb => cb(payload));
20
+ },
21
+
22
+ subscribe(event: string, callback: EventHandler) {
23
+ if (!this.listeners.has(event)) {
24
+ this.listeners.set(event, new Set());
25
+ }
26
+ this.listeners.get(event)!.add(callback);
27
+ probe('eventbus.subscribe', { event, totalListeners: this.listeners.get(event)!.size }, { level: 'debug', context: { module: 'shell', component: 'EventBus' } });
28
+
29
+ // Return an unsubscribe function
30
+ return () => {
31
+ const evListeners = this.listeners.get(event);
32
+ if (evListeners) {
33
+ evListeners.delete(callback);
34
+ }
35
+ };
36
+ }
37
+ };