wu-framework 1.1.6 → 1.1.8

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 (90) hide show
  1. package/README.md +511 -977
  2. package/dist/wu-framework.cjs.js +3 -1
  3. package/dist/wu-framework.cjs.js.map +1 -0
  4. package/dist/wu-framework.dev.js +7533 -2761
  5. package/dist/wu-framework.dev.js.map +1 -1
  6. package/dist/wu-framework.esm.js +3 -0
  7. package/dist/wu-framework.esm.js.map +1 -0
  8. package/dist/wu-framework.umd.js +3 -1
  9. package/dist/wu-framework.umd.js.map +1 -0
  10. package/integrations/astro/README.md +127 -0
  11. package/integrations/astro/WuApp.astro +63 -0
  12. package/integrations/astro/WuShell.astro +39 -0
  13. package/integrations/astro/index.js +68 -0
  14. package/integrations/astro/package.json +38 -0
  15. package/integrations/astro/types.d.ts +53 -0
  16. package/package.json +94 -74
  17. package/src/adapters/angular/ai.js +30 -0
  18. package/src/adapters/angular/index.d.ts +154 -0
  19. package/src/adapters/angular/index.js +932 -0
  20. package/src/adapters/angular.d.ts +3 -154
  21. package/src/adapters/angular.js +3 -813
  22. package/src/adapters/index.js +35 -24
  23. package/src/adapters/lit/ai.js +20 -0
  24. package/src/adapters/lit/index.d.ts +120 -0
  25. package/src/adapters/lit/index.js +721 -0
  26. package/src/adapters/lit.d.ts +3 -120
  27. package/src/adapters/lit.js +3 -726
  28. package/src/adapters/preact/ai.js +33 -0
  29. package/src/adapters/preact/index.d.ts +108 -0
  30. package/src/adapters/preact/index.js +661 -0
  31. package/src/adapters/preact.d.ts +3 -108
  32. package/src/adapters/preact.js +3 -665
  33. package/src/adapters/react/ai.js +135 -0
  34. package/src/adapters/react/index.d.ts +246 -0
  35. package/src/adapters/react/index.js +689 -0
  36. package/src/adapters/react.d.ts +3 -212
  37. package/src/adapters/react.js +3 -513
  38. package/src/adapters/shared.js +64 -0
  39. package/src/adapters/solid/ai.js +32 -0
  40. package/src/adapters/solid/index.d.ts +101 -0
  41. package/src/adapters/solid/index.js +586 -0
  42. package/src/adapters/solid.d.ts +3 -101
  43. package/src/adapters/solid.js +3 -591
  44. package/src/adapters/svelte/ai.js +31 -0
  45. package/src/adapters/svelte/index.d.ts +166 -0
  46. package/src/adapters/svelte/index.js +798 -0
  47. package/src/adapters/svelte.d.ts +3 -166
  48. package/src/adapters/svelte.js +3 -803
  49. package/src/adapters/vanilla/ai.js +30 -0
  50. package/src/adapters/vanilla/index.d.ts +179 -0
  51. package/src/adapters/vanilla/index.js +785 -0
  52. package/src/adapters/vanilla.d.ts +3 -179
  53. package/src/adapters/vanilla.js +3 -791
  54. package/src/adapters/vue/ai.js +52 -0
  55. package/src/adapters/vue/index.d.ts +299 -0
  56. package/src/adapters/vue/index.js +608 -0
  57. package/src/adapters/vue.d.ts +3 -299
  58. package/src/adapters/vue.js +3 -611
  59. package/src/ai/wu-ai-actions.js +261 -0
  60. package/src/ai/wu-ai-browser.js +663 -0
  61. package/src/ai/wu-ai-context.js +332 -0
  62. package/src/ai/wu-ai-conversation.js +554 -0
  63. package/src/ai/wu-ai-permissions.js +381 -0
  64. package/src/ai/wu-ai-provider.js +605 -0
  65. package/src/ai/wu-ai-schema.js +225 -0
  66. package/src/ai/wu-ai-triggers.js +396 -0
  67. package/src/ai/wu-ai.js +474 -0
  68. package/src/core/wu-app.js +50 -8
  69. package/src/core/wu-cache.js +1 -1
  70. package/src/core/wu-core.js +645 -677
  71. package/src/core/wu-html-parser.js +121 -211
  72. package/src/core/wu-iframe-sandbox.js +328 -0
  73. package/src/core/wu-mcp-bridge.js +647 -0
  74. package/src/core/wu-overrides.js +510 -0
  75. package/src/core/wu-prefetch.js +414 -0
  76. package/src/core/wu-proxy-sandbox.js +398 -75
  77. package/src/core/wu-sandbox.js +86 -268
  78. package/src/core/wu-script-executor.js +79 -182
  79. package/src/core/wu-snapshot-sandbox.js +149 -106
  80. package/src/core/wu-strategies.js +13 -0
  81. package/src/core/wu-style-bridge.js +0 -2
  82. package/src/index.js +139 -665
  83. package/dist/wu-framework.hex.js +0 -23
  84. package/dist/wu-framework.min.js +0 -1
  85. package/dist/wu-framework.obf.js +0 -1
  86. package/scripts/build-protected.js +0 -366
  87. package/scripts/build.js +0 -212
  88. package/scripts/rollup-plugin-hex.js +0 -143
  89. package/src/core/wu-registry.js +0 -60
  90. package/src/core/wu-sandbox-pool.js +0 -390
package/src/index.js CHANGED
@@ -1,174 +1,136 @@
1
1
  /**
2
- * 🚀 WU-FRAMEWORK: UNIVERSAL MICROFRONTENDS
2
+ * WU-FRAMEWORK: UNIVERSAL MICROFRONTENDS
3
3
  *
4
- * Framework puro para microfrontends con sistemas esenciales
5
- * - Framework Agnostic: React, Vue, Angular, Svelte, Vanilla JS
6
- * - Zero Config: npm install wu-framework y funciona
7
- * - Shadow DOM: Aislamiento real sin hacks CSS
8
- * - Runtime Loading: Apps dinámicas sin rebuild
9
- * - Style Sharing: Comparte estilos de node_modules automáticamente
10
- * - Internal Cache: Cacheo inteligente de manifests y módulos (interno)
11
- * - Event Bus: Comunicación pub/sub entre microfrontends
12
- * - Performance Monitor: Monitoreo de lifecycle del framework (mount/unmount)
13
- * - Health Monitoring: Sistema de auto-healing para microfrontends
4
+ * Framework agnostic microfrontends with Shadow DOM isolation.
5
+ * Supports React, Vue, Angular, Svelte, Solid, Preact, Lit, Vanilla.
14
6
  *
15
7
  * @example
16
- * ```js
17
8
  * import { wu, emit, on } from 'wu-framework';
18
9
  *
19
- * // API SIMPLIFICADA
20
- * const canvas = wu.app('canvas', {
21
- * url: 'http://localhost:5178',
22
- * container: '#canvas-container'
23
- * });
10
+ * const canvas = wu.app('canvas', { url: 'http://localhost:5178', container: '#canvas' });
11
+ * await canvas.mount();
24
12
  *
25
- * await canvas.mount(); // Monta la app
26
- * canvas.isMounted; // Verifica estado
27
- * await canvas.unmount(); // Desmonta
28
- *
29
- * // 📡 EVENT BUS (Comunicación entre microfrontends)
30
- * import { emit, on, once } from 'wu-framework';
31
- *
32
- * // Emitir evento
33
- * emit('user:login', { userId: 123, name: 'John' });
34
- *
35
- * // Escuchar eventos (soporta wildcards)
36
- * on('user:*', (event) => {
37
- * console.log('User event:', event.data);
38
- * });
39
- *
40
- * // Escuchar una sola vez
41
- * once('app:ready', () => console.log('App is ready!'));
42
- *
43
- * // ⚡ PERFORMANCE MONITORING (Framework lifecycle)
44
- * import { startMeasure, endMeasure, generatePerformanceReport } from 'wu-framework';
45
- *
46
- * // Medir tiempos de mount/unmount
47
- * startMeasure('custom-operation', 'canvas');
48
- * await doSomething();
49
- * const duration = endMeasure('custom-operation', 'canvas');
50
- * console.log(`Operation took ${duration}ms`);
51
- *
52
- * // Generar reporte
53
- * const report = generatePerformanceReport();
54
- * console.log('Framework performance:', report);
55
- *
56
- * // 🔄 API CLÁSICA (también disponible)
57
- * wu.init({
58
- * apps: [{ name: 'header', url: 'http://localhost:3001' }]
59
- * });
60
- * await wu.mount('header', '#header-container');
61
- *
62
- * // Micro app (cualquier framework)
63
- * wu.define('header', {
64
- * mount: (container) => {
65
- * // React: ReactDOM.render(<HeaderApp />, container);
66
- * // Vue: createApp(HeaderApp).mount(container);
67
- * // Vanilla: container.innerHTML = '<h1>Header</h1>';
68
- * },
69
- * unmount: (container) => {
70
- * // Cleanup logic aquí
71
- * }
72
- * });
73
- * ```
13
+ * emit('user:login', { userId: 123 });
14
+ * on('user:*', (e) => console.log(e.data));
74
15
  */
75
16
 
76
17
  import { WuCore } from './core/wu-core.js';
18
+ import { WuAI } from './ai/wu-ai.js';
77
19
 
78
- // 🔑 SINGLETON PATTERN: Reusar instancia global si existe
79
- // Esto permite que los microfrontends importen wu-framework y usen la misma instancia del host
20
+ // --- Singleton: reuse host instance if it exists ---
80
21
  let wu;
81
22
 
82
23
  if (typeof window !== 'undefined' && window.wu && window.wu._isWuFramework) {
83
- // Ya existe una instancia del host - reutilizarla
84
24
  wu = window.wu;
85
- console.log('🔗 Wu Framework - Reusing existing instance from host');
86
25
  } else {
87
- // Primera carga - crear nueva instancia
88
- wu = new WuCore({
89
- healthMonitoring: true,
90
- autoHeal: true,
91
- agingThreshold: Infinity,
92
- healthCheckInterval: 60000
93
- });
94
-
95
- // Marcar como instancia de wu-framework
26
+ wu = new WuCore();
96
27
  wu._isWuFramework = true;
97
28
  }
98
29
 
99
- // Hacer wu disponible globalmente
30
+ // Expose globally for microfrontends
100
31
  if (typeof window !== 'undefined') {
101
- // SIEMPRE configurar window.wu con la instancia real (puede haber un objeto vacío)
102
32
  window.wu = wu;
103
33
 
104
- // Configurar propiedades si no existen
105
34
  if (!wu.version) {
106
- wu.version = '1.0.6';
107
- console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
35
+ wu.version = '1.1.8';
108
36
  wu.info = {
109
37
  name: 'Wu Framework',
110
38
  description: 'Universal Microfrontends',
111
- features: [
112
- 'Framework Agnostic',
113
- 'Zero Config',
114
- 'Shadow DOM Isolation',
115
- 'Runtime Loading',
116
- 'Component Sharing'
117
- ]
39
+ features: ['Framework Agnostic', 'Zero Config', 'Shadow DOM Isolation', 'Runtime Loading']
118
40
  };
119
41
  }
120
42
 
121
- // 📡 Exponer Event Bus API globalmente para microfrontends
122
- // Esto permite: window.wu.emit() Y import { emit } from 'wu-framework'
43
+ // Event Bus shortcuts on window.wu
123
44
  if (!wu.emit) {
124
- wu.emit = (eventName, data, options) => wu.eventBus.emit(eventName, data, options);
125
- wu.on = (eventName, callback) => wu.eventBus.on(eventName, callback);
126
- wu.once = (eventName, callback) => wu.eventBus.once(eventName, callback);
127
- wu.off = (eventName, callback) => wu.eventBus.off(eventName, callback);
45
+ wu.emit = (event, data, opts) => wu.eventBus.emit(event, data, opts);
46
+ wu.on = (event, cb) => wu.eventBus.on(event, cb);
47
+ wu.once = (event, cb) => wu.eventBus.once(event, cb);
48
+ wu.off = (event, cb) => wu.eventBus.off(event, cb);
49
+ }
50
+
51
+ // Prefetch shortcuts on window.wu
52
+ if (!wu.prefetch) {
53
+ wu.prefetch = (appNames, opts) => wu.prefetcher.prefetch(appNames, opts);
54
+ wu.prefetchAll = (opts) => wu.prefetcher.prefetchAll(opts);
55
+ }
56
+
57
+ // Override shortcuts on window.wu
58
+ if (!wu.override) {
59
+ wu.override = (name, url, opts) => wu.overrides.set(name, url, opts);
60
+ wu.removeOverride = (name) => wu.overrides.remove(name);
61
+ wu.getOverrides = () => wu.overrides.getAll();
62
+ wu.clearOverrides = () => wu.overrides.clearAll();
128
63
  }
129
64
 
130
- // 🔇 Exponer funciones de control de logs
131
- // window.wu.silence() para silenciar, window.wu.verbose() para debug
65
+ // Log control: window.wu.silence() / window.wu.verbose()
132
66
  if (!wu.silence) {
133
- wu.silence = async () => {
134
- const { silenceAllLogs } = await import('./core/wu-logger.js');
135
- silenceAllLogs();
136
- };
137
- wu.verbose = async () => {
138
- const { enableAllLogs } = await import('./core/wu-logger.js');
139
- enableAllLogs();
67
+ wu.silence = async () => { const { silenceAllLogs } = await import('./core/wu-logger.js'); silenceAllLogs(); };
68
+ wu.verbose = async () => { const { enableAllLogs } = await import('./core/wu-logger.js'); enableAllLogs(); };
69
+ }
70
+
71
+ // AI integration lazy instantiated on first access
72
+ if (!wu.ai) {
73
+ let _aiInstance = null;
74
+ Object.defineProperty(wu, 'ai', {
75
+ get() {
76
+ if (!_aiInstance) {
77
+ _aiInstance = new WuAI({
78
+ eventBus: wu.eventBus,
79
+ store: wu.store,
80
+ core: wu,
81
+ });
82
+ }
83
+ return _aiInstance;
84
+ },
85
+ configurable: true,
86
+ });
87
+ }
88
+
89
+ // MCP bridge — connects to wu-mcp-server for AI agent control
90
+ if (!wu.mcp) {
91
+ let _mcpBridge = null;
92
+ wu.mcp = {
93
+ async connect(url = 'ws://localhost:19100') {
94
+ if (!_mcpBridge) {
95
+ const { createMcpBridge } = await import('./core/wu-mcp-bridge.js');
96
+ _mcpBridge = createMcpBridge(wu);
97
+ }
98
+ _mcpBridge.connect(url);
99
+ },
100
+ disconnect() {
101
+ _mcpBridge?.disconnect();
102
+ },
103
+ isConnected() {
104
+ return _mcpBridge?.isConnected() || false;
105
+ },
140
106
  };
141
107
  }
142
108
  }
143
109
 
144
- // Exportar API principal
110
+ // --- Primary exports ---
145
111
  export { wu };
146
112
  export default wu;
147
113
 
148
- // Exportar clases individuales para uso avanzado
114
+ // --- Core classes (advanced usage) ---
149
115
  export { WuCore } from './core/wu-core.js';
150
116
  export { WuLoader } from './core/wu-loader.js';
151
117
  export { WuSandbox } from './core/wu-sandbox.js';
152
118
  export { WuManifest } from './core/wu-manifest.js';
153
- export { WuStore } from './core/wu-store.js';
119
+ export { WuStore, default as store } from './core/wu-store.js';
154
120
  export { WuApp } from './core/wu-app.js';
155
121
  export { WuStyleBridge } from './core/wu-style-bridge.js';
156
- export { default as store } from './core/wu-store.js';
157
-
158
- // 🚀 NUEVOS SISTEMAS DE AISLAMIENTO (basados en video-code)
159
- export { WuProxySandbox } from './core/wu-proxy-sandbox.js';
160
- export { WuSnapshotSandbox } from './core/wu-snapshot-sandbox.js';
161
- export { WuScriptExecutor, executeScript, executeScripts } from './core/wu-script-executor.js';
162
- export { WuHtmlParser, parseHtml, parseHtmlFromUrl } from './core/wu-html-parser.js';
163
-
164
- // 🚀 Exportar sistemas esenciales
165
122
  export { WuCache } from './core/wu-cache.js';
166
123
  export { WuEventBus } from './core/wu-event-bus.js';
167
124
  export { WuPerformance } from './core/wu-performance.js';
168
-
169
- // 🎯 Exportar advanced systems
125
+ export { WuProxySandbox } from './core/wu-proxy-sandbox.js';
126
+ export { WuSnapshotSandbox } from './core/wu-snapshot-sandbox.js';
127
+ export { WuHtmlParser } from './core/wu-html-parser.js';
128
+ export { WuScriptExecutor } from './core/wu-script-executor.js';
129
+ export { WuIframeSandbox } from './core/wu-iframe-sandbox.js';
170
130
  export { WuPluginSystem, createPlugin } from './core/wu-plugin.js';
171
131
  export { WuLoadingStrategy } from './core/wu-strategies.js';
132
+ export { WuPrefetch } from './core/wu-prefetch.js';
133
+ export { WuOverrides } from './core/wu-overrides.js';
172
134
  export { WuErrorBoundary } from './core/wu-error-boundary.js';
173
135
  export {
174
136
  WuLifecycleHooks,
@@ -178,550 +140,62 @@ export {
178
140
  createTransformHook,
179
141
  createTimedHook
180
142
  } from './core/wu-hooks.js';
181
- export { WuSandboxPool } from './core/wu-sandbox-pool.js';
182
- export { WuRegistry } from './core/wu-registry.js';
183
143
  export { silenceAllLogs, enableAllLogs } from './core/wu-logger.js';
184
144
 
185
- /**
186
- * Utilidades de conveniencia para uso común
187
- */
188
-
189
- /**
190
- * Inicializar wu-framework con configuración simple
191
- * @param {Array} apps - Lista de apps: [{ name, url }, ...]
192
- * @returns {Promise} Promesa de inicialización
193
- */
194
- export const init = async (apps) => {
195
- return await wu.init({ apps });
196
- };
197
-
198
- /**
199
- * Montar app en contenedor
200
- * @param {string} appName - Nombre de la app
201
- * @param {string} containerSelector - Selector del contenedor
202
- * @returns {Promise} Promesa de montaje
203
- */
204
- export const mount = async (appName, containerSelector) => {
205
- return await wu.mount(appName, containerSelector);
206
- };
207
-
208
- /**
209
- * Definir lifecycle de micro-app
210
- * @param {string} appName - Nombre de la app
211
- * @param {Object} lifecycle - { mount, unmount }
212
- */
213
- export const define = (appName, lifecycle) => {
214
- return wu.define(appName, lifecycle);
215
- };
216
-
217
- /**
218
- * Desmontar app
219
- * @param {string} appName - Nombre de la app
220
- * @returns {Promise} Promesa de desmontaje
221
- */
222
- export const unmount = async (appName) => {
223
- return await wu.unmount(appName);
224
- };
225
-
226
- /**
227
- * Crear instancia de WuApp (API simplificada)
228
- * @param {string} name - Nombre de la app
229
- * @param {Object} config - Configuración { url, container, autoInit }
230
- * @returns {WuApp} Instancia de WuApp
231
- */
232
- export const app = (name, config) => {
233
- return wu.app(name, config);
234
- };
235
-
236
- /**
237
- * Usar componente compartido
238
- * @param {string} componentPath - Ruta del componente (ej: "shared.Button")
239
- * @returns {Promise} Componente cargado
240
- */
241
- export const use = async (componentPath) => {
242
- return await wu.use(componentPath);
243
- };
244
-
245
-
246
- /**
247
- * Obtener información de una app
248
- * @param {string} appName - Nombre de la app
249
- * @returns {Object} Información de la app
250
- */
251
- export const getAppInfo = (appName) => {
252
- return wu.getAppInfo(appName);
253
- };
254
-
255
- /**
256
- * Obtener estadísticas del framework
257
- * @returns {Object} Estadísticas
258
- */
259
- export const getStats = () => {
260
- return wu.getStats();
261
- };
262
-
263
- /**
264
- * 🏪 STORE CONVENIENCE METHODS
265
- */
266
-
267
- /**
268
- * Get value from global store
269
- * @param {string} path - Dot notation path
270
- * @returns {*} Value at path
271
- */
272
- export const getState = (path) => {
273
- return wu.getState(path);
274
- };
275
-
276
- /**
277
- * Set value in global store
278
- * @param {string} path - Dot notation path
279
- * @param {*} value - Value to set
280
- * @returns {number} Sequence number
281
- */
282
- export const setState = (path, value) => {
283
- return wu.setState(path, value);
284
- };
285
-
286
- /**
287
- * Subscribe to state changes
288
- * @param {string} pattern - Path or pattern
289
- * @param {Function} callback - Callback function
290
- * @returns {Function} Unsubscribe function
291
- */
292
- export const onStateChange = (pattern, callback) => {
293
- return wu.onStateChange(pattern, callback);
294
- };
295
-
296
- /**
297
- * Batch set multiple state values
298
- * @param {Object} updates - Object with path:value pairs
299
- * @returns {Array} Sequence numbers
300
- */
301
- export const batchState = (updates) => {
302
- return wu.batchState(updates);
303
- };
304
-
305
- /**
306
- * Get store metrics
307
- * @returns {Object} Performance metrics
308
- */
309
- export const getStoreMetrics = () => {
310
- return wu.getStoreMetrics();
311
- };
312
-
313
- /**
314
- * Clear all state
315
- */
316
- export const clearState = () => {
317
- wu.clearState();
318
- };
319
-
320
- /**
321
- * Limpiar y destruir framework
322
- * @returns {Promise} Promesa de destrucción
323
- */
324
- export const destroy = async () => {
325
- return await wu.destroy();
326
- };
327
-
328
- /**
329
- * 🎨 STYLE SHARING: Configurar compartición de estilos en Shadow DOM
330
- * @param {Object} config - Configuración del StyleBridge
331
- */
332
- export const configureStyleSharing = (config) => {
333
- return wu.sandbox.configureStyleSharing(config);
334
- };
335
-
336
- /**
337
- * 🔄 RE-INYECTAR ESTILOS: Vuelve a inyectar estilos en una app
338
- * @param {string} appName - Nombre de la app
339
- * @returns {Promise}
340
- */
341
- export const reinjectStyles = async (appName) => {
342
- return await wu.sandbox.reinjectStyles(appName);
343
- };
344
-
345
- /**
346
- * 📊 ESTADÍSTICAS DE ESTILOS: Información sobre estilos compartidos
347
- * @returns {Object}
348
- */
349
- export const getStyleStats = () => {
350
- return wu.sandbox.getStyleStats();
351
- };
352
-
353
- /**
354
- * 📡 EVENT BUS: Sistema de eventos avanzado
355
- */
356
-
357
- /**
358
- * Emitir evento
359
- * @param {string} eventName - Nombre del evento
360
- * @param {*} data - Datos del evento
361
- * @param {Object} options - Opciones { appName, timestamp, meta }
362
- */
363
- export const emit = (eventName, data, options) => {
364
- wu.eventBus.emit(eventName, data, options);
365
- };
366
-
367
- /**
368
- * Suscribirse a evento
369
- * @param {string} eventName - Nombre del evento (soporta wildcards: 'app.*')
370
- * @param {Function} callback - Función callback
371
- * @returns {Function} Función para desuscribirse
372
- */
373
- export const on = (eventName, callback) => {
374
- return wu.eventBus.on(eventName, callback);
375
- };
376
-
377
- /**
378
- * Suscribirse a evento una sola vez
379
- * @param {string} eventName - Nombre del evento
380
- * @param {Function} callback - Función callback
381
- * @returns {Function} Función para desuscribirse
382
- */
383
- export const once = (eventName, callback) => {
384
- return wu.eventBus.once(eventName, callback);
385
- };
386
-
387
- /**
388
- * Desuscribirse de evento
389
- * @param {string} eventName - Nombre del evento
390
- * @param {Function} callback - Función callback
391
- */
392
- export const off = (eventName, callback) => {
393
- wu.eventBus.off(eventName, callback);
394
- };
395
-
396
- /**
397
- * Reproducir eventos del historial
398
- * @param {string} eventNameOrPattern - Nombre o patrón de eventos
399
- * @param {Function} callback - Callback para cada evento
400
- */
401
- export const replayEvents = (eventNameOrPattern, callback) => {
402
- wu.eventBus.replay(eventNameOrPattern, callback);
403
- };
404
-
405
- /**
406
- * Obtener estadísticas del event bus
407
- * @returns {Object}
408
- */
409
- export const getEventBusStats = () => {
410
- return wu.eventBus.getStats();
411
- };
412
-
413
- /**
414
- * ⚡ PERFORMANCE: Monitoreo de lifecycle del framework
415
- */
416
-
417
- /**
418
- * Iniciar medición de performance
419
- * @param {string} name - Nombre de la medición
420
- * @param {string} appName - Nombre de la app (opcional)
421
- */
422
- export const startMeasure = (name, appName) => {
423
- wu.performance.startMeasure(name, appName);
424
- };
425
-
426
- /**
427
- * Finalizar medición de performance
428
- * @param {string} name - Nombre de la medición
429
- * @param {string} appName - Nombre de la app (opcional)
430
- * @returns {number} Duración en ms
431
- */
432
- export const endMeasure = (name, appName) => {
433
- return wu.performance.endMeasure(name, appName);
434
- };
435
-
436
- /**
437
- * Obtener métricas de performance de una app
438
- * @param {string} appName - Nombre de la app
439
- * @returns {Object}
440
- */
441
- export const getPerformanceMetrics = (appName) => {
442
- return wu.performance.getMetrics(appName);
443
- };
444
-
445
- /**
446
- * Obtener todas las métricas de performance
447
- * @returns {Object}
448
- */
449
- export const getAllPerformanceMetrics = () => {
450
- return wu.performance.getAllMetrics();
451
- };
452
-
453
- /**
454
- * Generar reporte de performance del framework
455
- * @returns {Object}
456
- */
457
- export const generatePerformanceReport = () => {
458
- return wu.performance.generateReport();
459
- };
460
-
461
- /**
462
- * Limpiar métricas de performance
463
- * @param {string} appName - Nombre de la app (opcional, si no se pasa limpia todas)
464
- */
465
- export const clearPerformanceMetrics = (appName) => {
466
- wu.performance.clearMetrics(appName);
467
- };
468
-
469
- /**
470
- * 🔌 PLUGINS: Sistema de plugins extensible
471
- */
472
-
473
- /**
474
- * Instalar plugin en el framework
475
- * @param {Object|Function} plugin - Plugin o factory function
476
- * @param {Object} options - Opciones del plugin
477
- */
478
- export const usePlugin = (plugin, options) => {
479
- wu.pluginSystem.use(plugin, options);
480
- };
481
-
482
- /**
483
- * Desinstalar plugin
484
- * @param {string} pluginName - Nombre del plugin
485
- */
486
- export const uninstallPlugin = (pluginName) => {
487
- wu.pluginSystem.uninstall(pluginName);
488
- };
489
-
490
- /**
491
- * Obtener estadísticas de plugins
492
- * @returns {Object}
493
- */
494
- export const getPluginStats = () => {
495
- return wu.pluginSystem.getStats();
496
- };
497
-
498
- /**
499
- * 🪝 HOOKS: Sistema de lifecycle hooks
500
- */
501
-
502
- /**
503
- * Registrar lifecycle hook
504
- * @param {string} phase - Fase del lifecycle
505
- * @param {Function} middleware - Función middleware
506
- * @param {Object} options - Opciones { priority, name }
507
- * @returns {Function} Función para desregistrar
508
- */
509
- export const useHook = (phase, middleware, options) => {
510
- return wu.hooks.use(phase, middleware, options);
511
- };
512
-
513
- /**
514
- * Remover lifecycle hook
515
- * @param {string} phase - Fase del lifecycle
516
- * @param {string} name - Nombre del hook
517
- */
518
- export const removeHook = (phase, name) => {
519
- wu.hooks.remove(phase, name);
520
- };
521
-
522
- /**
523
- * Obtener estadísticas de hooks
524
- * @returns {Object}
525
- */
526
- export const getHookStats = () => {
527
- return wu.hooks.getStats();
528
- };
529
-
530
- /**
531
- * 🎯 STRATEGIES: Sistema de loading strategies
532
- */
533
-
534
- /**
535
- * Registrar loading strategy personalizada
536
- * @param {string} name - Nombre de la estrategia
537
- * @param {Object} strategy - Configuración de la estrategia
538
- */
539
- export const registerStrategy = (name, strategy) => {
540
- wu.strategies.register(name, strategy);
541
- };
542
-
543
- /**
544
- * Obtener estadísticas de strategies
545
- * @returns {Object}
546
- */
547
- export const getStrategyStats = () => {
548
- return wu.strategies.getStats();
549
- };
550
-
551
- /**
552
- * 🛡️ ERROR BOUNDARY: Sistema de error handling
553
- */
554
-
555
- /**
556
- * Registrar error handler personalizado
557
- * @param {Object} handler - Error handler { name, canHandle, handle }
558
- */
559
- export const registerErrorHandler = (handler) => {
560
- wu.errorBoundary.register(handler);
561
- };
562
-
563
- /**
564
- * Configurar error boundary
565
- * @param {Object} config - Nueva configuración
566
- */
567
- export const configureErrorBoundary = (config) => {
568
- wu.errorBoundary.configure(config);
569
- };
570
-
571
- /**
572
- * Obtener log de errores
573
- * @param {number} limit - Límite de errores a retornar
574
- * @returns {Array}
575
- */
576
- export const getErrorLog = (limit) => {
577
- return wu.errorBoundary.getErrorLog(limit);
578
- };
579
-
580
- /**
581
- * Obtener estadísticas de error boundary
582
- * @returns {Object}
583
- */
584
- export const getErrorBoundaryStats = () => {
585
- return wu.errorBoundary.getStats();
586
- };
587
-
588
- /**
589
- * 🏊 SANDBOX POOL: Sistema de sandbox pooling
590
- */
591
-
592
- /**
593
- * Configurar sandbox pool
594
- * @param {Object} config - Nueva configuración
595
- */
596
- export const configureSandboxPool = (config) => {
597
- wu.sandboxPool.configure(config);
598
- };
599
-
600
- /**
601
- * Obtener estadísticas de sandbox pool
602
- * @returns {Object}
603
- */
604
- export const getSandboxPoolStats = () => {
605
- return wu.sandboxPool.getStats();
606
- };
607
-
608
- /**
609
- * Presets comunes para configuración rápida
610
- */
611
- export const presets = {
612
- /**
613
- * Configuración para desarrollo local
614
- * @param {Array} apps - Apps con puertos locales
615
- */
616
- development: (apps) => {
617
- const devApps = apps.map(app => ({
618
- ...app,
619
- url: app.url || `http://localhost:${app.port || 3001}`
620
- }));
621
-
622
- return {
623
- apps: devApps,
624
- debug: true,
625
- hotReload: true
626
- };
627
- },
628
-
629
- /**
630
- * Configuración para producción
631
- * @param {Array} apps - Apps con URLs de producción
632
- */
633
- production: (apps) => {
634
- return {
635
- apps,
636
- debug: false,
637
- cache: true,
638
- preload: true
639
- };
640
- },
641
-
642
- /**
643
- * Configuración para single page application
644
- * @param {Object} config - Configuración SPA
645
- */
646
- spa: (config) => {
647
- return {
648
- apps: [
649
- {
650
- name: 'main',
651
- url: config.url || window.location.origin,
652
- container: config.container || '#app'
653
- }
654
- ]
655
- };
656
- }
657
- };
658
-
659
- /**
660
- * Helpers para desarrollo
661
- */
662
- export const dev = {
663
- /**
664
- * Activar modo debug
665
- */
666
- enableDebug: () => {
667
- wu.debug = true;
668
- console.log('🐛 Wu Framework debug mode enabled');
669
- },
670
-
671
- /**
672
- * Desactivar modo debug
673
- */
674
- disableDebug: () => {
675
- wu.debug = false;
676
- console.log('🐛 Wu Framework debug mode disabled');
677
- },
678
-
679
- /**
680
- * Inspeccionar estado del framework
681
- */
682
- inspect: () => {
683
- return {
684
- version: wu.version,
685
- stats: wu.getStats(),
686
- apps: Array.from(wu.apps.keys()).map(name => wu.getAppInfo(name))
687
- };
688
- },
689
-
690
- /**
691
- * Recargar app específica (útil para desarrollo)
692
- * @param {string} appName - Nombre de la app
693
- */
694
- reload: async (appName) => {
695
- console.log(`🔄 Reloading app: ${appName}`);
696
- await wu.unmount(appName);
697
-
698
- // Limpiar caches
699
- wu.loader.clearCache(appName);
700
- wu.manifest.clearCache(appName);
701
-
702
- await wu.mount(appName);
703
- console.log(`✅ App reloaded: ${appName}`);
704
- }
705
- };
706
-
707
- /**
708
- * Eventos del framework
709
- */
710
- export const events = {
711
- // Event listeners para el ciclo de vida de las apps
712
- onAppMounted: (callback) => {
713
- document.addEventListener('wu:app:mounted', callback);
714
- },
715
-
716
- onAppUnmounted: (callback) => {
717
- document.addEventListener('wu:app:unmounted', callback);
718
- },
719
-
720
- onAppError: (callback) => {
721
- document.addEventListener('wu:app:error', callback);
722
- },
723
-
724
- onFrameworkReady: (callback) => {
725
- document.addEventListener('wu:framework:ready', callback);
726
- }
727
- };
145
+ // --- Convenience API (most-used shortcuts) ---
146
+ export const init = (apps) => wu.init({ apps });
147
+ export const mount = (name, container) => wu.mount(name, container);
148
+ export const unmount = (name, opts) => wu.unmount(name, opts);
149
+ export const define = (name, lifecycle) => wu.define(name, lifecycle);
150
+ export const app = (name, config) => wu.app(name, config);
151
+ export const destroy = () => wu.destroy();
152
+
153
+ // Keep-alive
154
+ export const hide = (name) => wu.hide(name);
155
+ export const show = (name) => wu.show(name);
156
+ export const isHidden = (name) => wu.isHidden(name);
157
+
158
+ // Event Bus
159
+ export const emit = (event, data, opts) => wu.eventBus.emit(event, data, opts);
160
+ export const on = (event, cb) => wu.eventBus.on(event, cb);
161
+ export const once = (event, cb) => wu.eventBus.once(event, cb);
162
+ export const off = (event, cb) => wu.eventBus.off(event, cb);
163
+
164
+ // Store
165
+ export const getState = (path) => wu.store.get(path);
166
+ export const setState = (path, value) => wu.store.set(path, value);
167
+ export const onStateChange = (pattern, cb) => wu.store.on(pattern, cb);
168
+
169
+ // Performance
170
+ export const startMeasure = (name, app) => wu.performance.startMeasure(name, app);
171
+ export const endMeasure = (name, app) => wu.performance.endMeasure(name, app);
172
+ export const generatePerformanceReport = () => wu.performance.generateReport();
173
+
174
+ // Prefetch
175
+ export const prefetch = (appNames, opts) => wu.prefetch(appNames, opts);
176
+ export const prefetchAll = (opts) => wu.prefetchAll(opts);
177
+
178
+ // Overrides (QA/testing)
179
+ export const override = (name, url, opts) => wu.override(name, url, opts);
180
+ export const removeOverride = (name) => wu.removeOverride(name);
181
+ export const getOverrides = () => wu.getOverrides();
182
+ export const clearOverrides = () => wu.clearOverrides();
183
+
184
+ // Plugins & Hooks
185
+ export const usePlugin = (plugin, opts) => wu.pluginSystem.use(plugin, opts);
186
+ export const useHook = (phase, middleware, opts) => wu.hooks.use(phase, middleware, opts);
187
+
188
+ // --- AI classes (advanced usage) ---
189
+ export { WuAI } from './ai/wu-ai.js';
190
+ export { WuAIProvider } from './ai/wu-ai-provider.js';
191
+ export { WuAIPermissions } from './ai/wu-ai-permissions.js';
192
+ export { WuAIContext } from './ai/wu-ai-context.js';
193
+ export { WuAIActions } from './ai/wu-ai-actions.js';
194
+ export { WuAIConversation } from './ai/wu-ai-conversation.js';
195
+ export { WuAITriggers } from './ai/wu-ai-triggers.js';
196
+
197
+ // --- MCP Bridge (browser-side connection to wu-mcp-server) ---
198
+ export { createMcpBridge } from './core/wu-mcp-bridge.js';
199
+
200
+ // --- AI Browser Actions (autonomous agent control) ---
201
+ export { registerBrowserActions } from './ai/wu-ai-browser.js';