wu-framework 1.2.1 → 2.1.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 (155) hide show
  1. package/README.md +99 -18
  2. package/dist/adapters/alpine/index.js +2 -0
  3. package/dist/adapters/alpine/index.js.map +1 -0
  4. package/dist/adapters/angular/index.js +2 -0
  5. package/dist/adapters/angular/index.js.map +1 -0
  6. package/dist/adapters/htmx/index.js +2 -0
  7. package/dist/adapters/htmx/index.js.map +1 -0
  8. package/dist/adapters/index.js +2 -0
  9. package/dist/adapters/index.js.map +1 -0
  10. package/dist/adapters/lit/index.js +44 -0
  11. package/dist/adapters/lit/index.js.map +1 -0
  12. package/dist/adapters/preact/index.js +2 -0
  13. package/dist/adapters/preact/index.js.map +1 -0
  14. package/dist/adapters/qwik/index.js +2 -0
  15. package/dist/adapters/qwik/index.js.map +1 -0
  16. package/dist/adapters/react/index.js +2 -0
  17. package/dist/adapters/react/index.js.map +1 -0
  18. package/dist/adapters/shared.js +2 -0
  19. package/dist/adapters/shared.js.map +1 -0
  20. package/dist/adapters/solid/index.js +2 -0
  21. package/dist/adapters/solid/index.js.map +1 -0
  22. package/dist/adapters/stencil/index.js +2 -0
  23. package/dist/adapters/stencil/index.js.map +1 -0
  24. package/dist/adapters/stimulus/index.js +2 -0
  25. package/dist/adapters/stimulus/index.js.map +1 -0
  26. package/dist/adapters/svelte/index.js +2 -0
  27. package/dist/adapters/svelte/index.js.map +1 -0
  28. package/dist/adapters/vanilla/index.js +2 -0
  29. package/dist/adapters/vanilla/index.js.map +1 -0
  30. package/dist/adapters/vue/index.js +2 -0
  31. package/dist/adapters/vue/index.js.map +1 -0
  32. package/dist/ai/wu-ai.js +2 -0
  33. package/dist/ai/wu-ai.js.map +1 -0
  34. package/dist/core/wu-mcp-bridge.js +2 -0
  35. package/dist/core/wu-mcp-bridge.js.map +1 -0
  36. package/{src → dist}/index.d.ts +445 -317
  37. package/dist/wu-ai-browser-primitives-BDKXJlwc.js +2 -0
  38. package/dist/wu-ai-browser-primitives-BDKXJlwc.js.map +1 -0
  39. package/dist/wu-framework.cjs.js +2 -2
  40. package/dist/wu-framework.cjs.js.map +1 -1
  41. package/dist/wu-framework.dev.js +2640 -9197
  42. package/dist/wu-framework.dev.js.map +1 -1
  43. package/dist/wu-framework.esm.js +2 -2
  44. package/dist/wu-framework.esm.js.map +1 -1
  45. package/dist/wu-framework.umd.js +2 -2
  46. package/dist/wu-framework.umd.js.map +1 -1
  47. package/dist/wu-html-parser.js +2 -0
  48. package/dist/wu-html-parser.js.map +1 -0
  49. package/dist/wu-iframe-sandbox.js +2 -0
  50. package/dist/wu-iframe-sandbox.js.map +1 -0
  51. package/dist/wu-logger-fJfUHBGA.js +2 -0
  52. package/dist/wu-logger-fJfUHBGA.js.map +1 -0
  53. package/dist/wu-script-executor.js +2 -0
  54. package/dist/wu-script-executor.js.map +1 -0
  55. package/package.json +43 -34
  56. package/src/adapters/alpine/index.js +0 -231
  57. package/src/adapters/alpine.js +0 -3
  58. package/src/adapters/angular/ai.js +0 -30
  59. package/src/adapters/angular/index.js +0 -932
  60. package/src/adapters/angular.js +0 -3
  61. package/src/adapters/htmx/index.js +0 -242
  62. package/src/adapters/htmx.js +0 -3
  63. package/src/adapters/index.js +0 -225
  64. package/src/adapters/lit/ai.js +0 -20
  65. package/src/adapters/lit/index.js +0 -721
  66. package/src/adapters/lit.js +0 -3
  67. package/src/adapters/preact/ai.js +0 -33
  68. package/src/adapters/preact/index.js +0 -661
  69. package/src/adapters/preact.js +0 -3
  70. package/src/adapters/qwik/index.js +0 -108
  71. package/src/adapters/qwik.js +0 -3
  72. package/src/adapters/react/ai.js +0 -135
  73. package/src/adapters/react/index.js +0 -695
  74. package/src/adapters/react.js +0 -3
  75. package/src/adapters/shared.js +0 -64
  76. package/src/adapters/solid/ai.js +0 -32
  77. package/src/adapters/solid/index.js +0 -586
  78. package/src/adapters/solid.js +0 -3
  79. package/src/adapters/stencil/index.js +0 -228
  80. package/src/adapters/stencil.js +0 -3
  81. package/src/adapters/stimulus/index.js +0 -255
  82. package/src/adapters/stimulus.js +0 -3
  83. package/src/adapters/svelte/ai.js +0 -31
  84. package/src/adapters/svelte/index.js +0 -798
  85. package/src/adapters/svelte.js +0 -3
  86. package/src/adapters/vanilla/ai.js +0 -30
  87. package/src/adapters/vanilla/index.js +0 -785
  88. package/src/adapters/vanilla.js +0 -3
  89. package/src/adapters/vue/ai.js +0 -52
  90. package/src/adapters/vue/index.js +0 -618
  91. package/src/adapters/vue.js +0 -3
  92. package/src/ai/wu-ai-actions.js +0 -261
  93. package/src/ai/wu-ai-agent.js +0 -546
  94. package/src/ai/wu-ai-browser-primitives.js +0 -354
  95. package/src/ai/wu-ai-browser.js +0 -380
  96. package/src/ai/wu-ai-context.js +0 -332
  97. package/src/ai/wu-ai-conversation.js +0 -613
  98. package/src/ai/wu-ai-orchestrate.js +0 -1021
  99. package/src/ai/wu-ai-permissions.js +0 -381
  100. package/src/ai/wu-ai-provider.js +0 -700
  101. package/src/ai/wu-ai-schema.js +0 -225
  102. package/src/ai/wu-ai-triggers.js +0 -396
  103. package/src/ai/wu-ai.js +0 -804
  104. package/src/core/wu-app.js +0 -236
  105. package/src/core/wu-cache.js +0 -498
  106. package/src/core/wu-core.js +0 -1412
  107. package/src/core/wu-error-boundary.js +0 -396
  108. package/src/core/wu-event-bus.js +0 -390
  109. package/src/core/wu-hooks.js +0 -350
  110. package/src/core/wu-html-parser.js +0 -199
  111. package/src/core/wu-iframe-sandbox.js +0 -328
  112. package/src/core/wu-loader.js +0 -450
  113. package/src/core/wu-logger.js +0 -143
  114. package/src/core/wu-manifest.js +0 -533
  115. package/src/core/wu-mcp-bridge.js +0 -432
  116. package/src/core/wu-overrides.js +0 -510
  117. package/src/core/wu-performance.js +0 -228
  118. package/src/core/wu-plugin.js +0 -401
  119. package/src/core/wu-prefetch.js +0 -414
  120. package/src/core/wu-proxy-sandbox.js +0 -477
  121. package/src/core/wu-sandbox.js +0 -779
  122. package/src/core/wu-script-executor.js +0 -161
  123. package/src/core/wu-sentinel-client.js +0 -311
  124. package/src/core/wu-snapshot-sandbox.js +0 -227
  125. package/src/core/wu-store.js +0 -307
  126. package/src/core/wu-strategies.js +0 -256
  127. package/src/core/wu-style-bridge.js +0 -477
  128. package/src/index.js +0 -234
  129. package/src/utils/dependency-resolver.js +0 -328
  130. /package/{src → dist}/adapters/alpine/index.d.ts +0 -0
  131. /package/{src → dist}/adapters/alpine.d.ts +0 -0
  132. /package/{src → dist}/adapters/angular/index.d.ts +0 -0
  133. /package/{src → dist}/adapters/angular.d.ts +0 -0
  134. /package/{src → dist}/adapters/htmx/index.d.ts +0 -0
  135. /package/{src → dist}/adapters/htmx.d.ts +0 -0
  136. /package/{src → dist}/adapters/lit/index.d.ts +0 -0
  137. /package/{src → dist}/adapters/lit.d.ts +0 -0
  138. /package/{src → dist}/adapters/preact/index.d.ts +0 -0
  139. /package/{src → dist}/adapters/preact.d.ts +0 -0
  140. /package/{src → dist}/adapters/qwik/index.d.ts +0 -0
  141. /package/{src → dist}/adapters/qwik.d.ts +0 -0
  142. /package/{src → dist}/adapters/react/index.d.ts +0 -0
  143. /package/{src → dist}/adapters/react.d.ts +0 -0
  144. /package/{src → dist}/adapters/solid/index.d.ts +0 -0
  145. /package/{src → dist}/adapters/solid.d.ts +0 -0
  146. /package/{src → dist}/adapters/stencil/index.d.ts +0 -0
  147. /package/{src → dist}/adapters/stencil.d.ts +0 -0
  148. /package/{src → dist}/adapters/stimulus/index.d.ts +0 -0
  149. /package/{src → dist}/adapters/stimulus.d.ts +0 -0
  150. /package/{src → dist}/adapters/svelte/index.d.ts +0 -0
  151. /package/{src → dist}/adapters/svelte.d.ts +0 -0
  152. /package/{src → dist}/adapters/vanilla/index.d.ts +0 -0
  153. /package/{src → dist}/adapters/vanilla.d.ts +0 -0
  154. /package/{src → dist}/adapters/vue/index.d.ts +0 -0
  155. /package/{src → dist}/adapters/vue.d.ts +0 -0
@@ -1,380 +0,0 @@
1
- /**
2
- * WU-AI Browser Actions
3
- *
4
- * Registers browser automation tools into wu.ai so any LLM provider
5
- * (OpenAI, Claude, Gemini, Ollama, etc.) can autonomously see and
6
- * control the page — no human intervention required.
7
- *
8
- * Tools registered:
9
- * browser_screenshot — Capture page/element as PNG (Canvas API)
10
- * browser_click — Click element by selector or visible text
11
- * browser_type — Type into inputs (React/Vue/framework compatible)
12
- * browser_snapshot — Get accessibility tree of the DOM
13
- * browser_navigate — Navigate SPA routes
14
- * browser_network — View captured HTTP requests (fetch + XHR)
15
- * browser_console — View captured console messages
16
- * browser_info — Get page state: apps, store, URL, viewport
17
- * browser_select — Select option in dropdowns
18
- * browser_scroll — Scroll page or element
19
- *
20
- * @example
21
- * // Auto-registered when wu.ai initializes
22
- * // Any LLM connected via wu.ai.provider can now use these tools:
23
- * const tools = wu.ai.tools();
24
- * // → includes browser_screenshot, browser_click, etc.
25
- */
26
-
27
- import {
28
- ensureInterceptors,
29
- networkLog,
30
- consoleLog,
31
- captureScreenshot,
32
- buildA11yTree,
33
- clickElement,
34
- typeIntoElement,
35
- getFilteredNetwork,
36
- getFilteredConsole,
37
- } from './wu-ai-browser-primitives.js';
38
-
39
- /**
40
- * Register all browser automation actions into a WuAI instance.
41
- *
42
- * @param {object} ai - The WuAI instance (wu.ai)
43
- * @param {object} wu - The Wu Framework instance (window.wu)
44
- */
45
- export function registerBrowserActions(ai, wu) {
46
- ensureInterceptors();
47
-
48
- // ════════════════════════════════════════════
49
- // SCREENSHOT — Canvas API (SVG foreignObject)
50
- // ════════════════════════════════════════════
51
-
52
- ai.action('browser_screenshot', {
53
- description: 'Take a screenshot of the current page or a specific element. Returns a base64 PNG image. Use this to SEE what the user sees.',
54
- parameters: {
55
- selector: {
56
- type: 'string',
57
- description: 'CSS selector of the element to capture. Empty = full visible page.',
58
- required: false,
59
- },
60
- },
61
- handler: async (params) => captureScreenshot(params.selector),
62
- permissions: [],
63
- });
64
-
65
- // ════════════════════════════════════════════
66
- // CLICK
67
- // ════════════════════════════════════════════
68
-
69
- ai.action('browser_click', {
70
- description: 'Click an element on the page. Find by CSS selector or by visible text content. Use this to interact with buttons, links, tabs, etc.',
71
- parameters: {
72
- selector: {
73
- type: 'string',
74
- description: 'CSS selector (e.g. "#submit-btn", ".nav-link", "button[type=submit]")',
75
- required: false,
76
- },
77
- text: {
78
- type: 'string',
79
- description: 'Visible text to find and click (e.g. "Submit", "Next", "Guardar"). Searches buttons, links, and clickable elements.',
80
- required: false,
81
- },
82
- },
83
- handler: async (params, api) => {
84
- const result = clickElement(params.selector, params.text);
85
- if (!result.error) {
86
- api.emit?.('browser:clicked', { selector: params.selector, text: params.text });
87
- }
88
- return result;
89
- },
90
- permissions: ['emitEvents'],
91
- });
92
-
93
- // ════════════════════════════════════════════
94
- // TYPE
95
- // ════════════════════════════════════════════
96
-
97
- ai.action('browser_type', {
98
- description: 'Type text into an input, textarea, or contenteditable element. Works with React, Vue, Angular, and other frameworks. Can optionally clear existing text first and submit the form.',
99
- parameters: {
100
- selector: {
101
- type: 'string',
102
- description: 'CSS selector of the input (e.g. "#email", "input[name=search]", "textarea.comment")',
103
- required: true,
104
- },
105
- text: {
106
- type: 'string',
107
- description: 'Text to type into the element',
108
- required: true,
109
- },
110
- clear: {
111
- type: 'boolean',
112
- description: 'Clear existing value before typing (default: false)',
113
- required: false,
114
- },
115
- submit: {
116
- type: 'boolean',
117
- description: 'Submit the form or press Enter after typing (default: false)',
118
- required: false,
119
- },
120
- },
121
- handler: async (params, api) => {
122
- const result = typeIntoElement(params.selector, params.text, {
123
- clear: params.clear,
124
- submit: params.submit,
125
- });
126
- if (!result.error) {
127
- api.emit?.('browser:typed', { selector: params.selector, length: params.text.length });
128
- }
129
- return result;
130
- },
131
- permissions: ['emitEvents'],
132
- });
133
-
134
- // ════════════════════════════════════════════
135
- // SELECT (dropdowns)
136
- // ════════════════════════════════════════════
137
-
138
- ai.action('browser_select', {
139
- description: 'Select an option in a <select> dropdown or a custom dropdown component.',
140
- parameters: {
141
- selector: {
142
- type: 'string',
143
- description: 'CSS selector of the <select> element',
144
- required: true,
145
- },
146
- value: {
147
- type: 'string',
148
- description: 'The value attribute of the option to select. Use "text:" prefix to match by visible text (e.g. "text:Mexico")',
149
- required: true,
150
- },
151
- },
152
- handler: async (params, api) => {
153
- const el = document.querySelector(params.selector);
154
- if (!el) return { error: `Element not found: ${params.selector}` };
155
-
156
- if (el.tagName?.toLowerCase() === 'select') {
157
- const options = Array.from(el.options);
158
- let option;
159
-
160
- if (params.value.startsWith('text:')) {
161
- const searchText = params.value.slice(5).toLowerCase();
162
- option = options.find((o) => o.textContent.trim().toLowerCase().includes(searchText));
163
- } else {
164
- option = options.find((o) => o.value === params.value);
165
- }
166
-
167
- if (!option) return { error: `Option not found: ${params.value}` };
168
-
169
- el.value = option.value;
170
- el.dispatchEvent(new Event('change', { bubbles: true }));
171
- el.dispatchEvent(new Event('input', { bubbles: true }));
172
-
173
- api.emit?.('browser:selected', { selector: params.selector, value: option.value });
174
- return { selected: option.value, text: option.textContent.trim() };
175
- }
176
-
177
- // Custom dropdown: try clicking the trigger, then the option
178
- el.click();
179
- return { clicked: params.selector, note: 'Custom dropdown — clicked trigger. Use browser_click to select an option from the opened menu.' };
180
- },
181
- permissions: ['emitEvents'],
182
- });
183
-
184
- // ════════════════════════════════════════════
185
- // SCROLL
186
- // ════════════════════════════════════════════
187
-
188
- ai.action('browser_scroll', {
189
- description: 'Scroll the page or a specific element. Use to reveal content that is not visible.',
190
- parameters: {
191
- direction: {
192
- type: 'string',
193
- description: 'Direction: "up", "down", "top", "bottom"',
194
- required: true,
195
- },
196
- selector: {
197
- type: 'string',
198
- description: 'CSS selector of scrollable container (empty = page)',
199
- required: false,
200
- },
201
- amount: {
202
- type: 'number',
203
- description: 'Pixels to scroll (default: 500). Ignored for "top"/"bottom".',
204
- required: false,
205
- },
206
- },
207
- handler: async (params) => {
208
- const target = params.selector
209
- ? document.querySelector(params.selector)
210
- : window;
211
- const amount = params.amount || 500;
212
-
213
- if (params.selector && !target) return { error: `Element not found: ${params.selector}` };
214
-
215
- const scrollEl = target === window ? document.documentElement : target;
216
-
217
- switch (params.direction) {
218
- case 'up': scrollEl.scrollBy({ top: -amount, behavior: 'smooth' }); break;
219
- case 'down': scrollEl.scrollBy({ top: amount, behavior: 'smooth' }); break;
220
- case 'top': scrollEl.scrollTo({ top: 0, behavior: 'smooth' }); break;
221
- case 'bottom': scrollEl.scrollTo({ top: scrollEl.scrollHeight, behavior: 'smooth' }); break;
222
- default: return { error: `Invalid direction: ${params.direction}` };
223
- }
224
-
225
- return {
226
- scrolled: params.direction,
227
- amount: params.direction === 'top' || params.direction === 'bottom' ? 'max' : amount,
228
- currentScroll: scrollEl.scrollTop,
229
- };
230
- },
231
- permissions: [],
232
- });
233
-
234
- // ════════════════════════════════════════════
235
- // SNAPSHOT — Accessibility tree
236
- // ════════════════════════════════════════════
237
-
238
- ai.action('browser_snapshot', {
239
- description: 'Get a text representation of the visible DOM structure (accessibility tree). Use this to understand what elements are on the page, their roles, IDs, and text content. Cheaper and faster than a screenshot.',
240
- parameters: {
241
- selector: {
242
- type: 'string',
243
- description: 'CSS selector to snapshot (empty = full page). Use "[data-wu-app=appName]" for a specific micro-app.',
244
- required: false,
245
- },
246
- depth: {
247
- type: 'number',
248
- description: 'Max depth to traverse (default: 5)',
249
- required: false,
250
- },
251
- },
252
- handler: async (params) => {
253
- const target = params.selector
254
- ? document.querySelector(params.selector)
255
- : document.body;
256
-
257
- if (!target) return { error: `Element not found: ${params.selector}` };
258
-
259
- const tree = buildA11yTree(target, 0, params.depth || 5);
260
- return { snapshot: tree };
261
- },
262
- permissions: [],
263
- });
264
-
265
- // ════════════════════════════════════════════
266
- // NAVIGATE
267
- // ════════════════════════════════════════════
268
-
269
- ai.action('browser_navigate', {
270
- description: 'Navigate to a route within the SPA application. Emits a shell:navigate event and updates the store.',
271
- parameters: {
272
- route: {
273
- type: 'string',
274
- description: 'Route path (e.g. "/dashboard", "/users", "/pos/cotizador")',
275
- required: true,
276
- },
277
- },
278
- handler: async (params, api) => {
279
- api.emit?.('shell:navigate', { route: params.route });
280
- api.setState?.('currentPath', params.route);
281
- return { navigated: params.route };
282
- },
283
- permissions: ['emitEvents', 'writeStore'],
284
- });
285
-
286
- // ════════════════════════════════════════════
287
- // NETWORK — Captured HTTP requests
288
- // ════════════════════════════════════════════
289
-
290
- ai.action('browser_network', {
291
- description: 'View captured HTTP network requests (fetch and XHR). Shows URL, method, status code, duration, and size. Use to debug API calls, check for errors, or monitor performance.',
292
- parameters: {
293
- method: {
294
- type: 'string',
295
- description: 'Filter by HTTP method: GET, POST, PUT, DELETE (empty = all)',
296
- required: false,
297
- },
298
- status: {
299
- type: 'string',
300
- description: 'Filter: "2" (2xx success), "4" (4xx errors), "5" (5xx errors), "error" (all failures)',
301
- required: false,
302
- },
303
- limit: {
304
- type: 'number',
305
- description: 'Max requests to return (default: 30)',
306
- required: false,
307
- },
308
- },
309
- handler: async (params) => getFilteredNetwork(params.method, params.status, params.limit),
310
- permissions: [],
311
- });
312
-
313
- // ════════════════════════════════════════════
314
- // CONSOLE — Captured logs
315
- // ════════════════════════════════════════════
316
-
317
- ai.action('browser_console', {
318
- description: 'View captured browser console messages (log, warn, error). Use to check for errors, warnings, or debug output.',
319
- parameters: {
320
- level: {
321
- type: 'string',
322
- description: 'Filter by level: "log", "warn", "error" (empty = all)',
323
- required: false,
324
- },
325
- limit: {
326
- type: 'number',
327
- description: 'Max messages to return (default: 30)',
328
- required: false,
329
- },
330
- },
331
- handler: async (params) => getFilteredConsole(params.level, params.limit),
332
- permissions: [],
333
- });
334
-
335
- // ════════════════════════════════════════════
336
- // INFO — Page state overview
337
- // ════════════════════════════════════════════
338
-
339
- ai.action('browser_info', {
340
- description: 'Get an overview of the current page state: URL, viewport size, mounted micro-apps, store keys, visible elements summary. Use this FIRST to understand the page before taking actions.',
341
- parameters: {},
342
- handler: async (params, api) => {
343
- const apps = [];
344
-
345
- // Discover mounted apps
346
- if (wu._apps) {
347
- for (const [name, app] of Object.entries(wu._apps)) {
348
- apps.push({
349
- name,
350
- mounted: app.mounted || app.isMounted || false,
351
- status: app.status || 'unknown',
352
- });
353
- }
354
- }
355
- if (apps.length === 0) {
356
- document.querySelectorAll('[data-wu-app]').forEach((el) => {
357
- apps.push({ name: el.getAttribute('data-wu-app'), mounted: true });
358
- });
359
- }
360
-
361
- const storeData = api.getState?.('') || {};
362
- const storeKeys = typeof storeData === 'object' ? Object.keys(storeData) : [];
363
-
364
- return {
365
- url: window.location.href,
366
- title: document.title,
367
- viewport: { width: window.innerWidth, height: window.innerHeight },
368
- apps,
369
- storeKeys,
370
- networkRequests: networkLog.length,
371
- consoleMessages: consoleLog.length,
372
- consoleErrors: consoleLog.filter((m) => m.level === 'error').length,
373
- };
374
- },
375
- permissions: ['readStore'],
376
- });
377
- }
378
-
379
- // All private helpers (buildA11yTree, inlineComputedStyles, interceptors)
380
- // are now in wu-ai-browser-primitives.js — single source of truth.