wu-framework 1.1.7 → 1.1.9

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 (95) hide show
  1. package/LICENSE +19 -1
  2. package/README.md +257 -1122
  3. package/dist/wu-framework.cjs.js +3 -1
  4. package/dist/wu-framework.cjs.js.map +1 -0
  5. package/dist/wu-framework.dev.js +9867 -3183
  6. package/dist/wu-framework.dev.js.map +1 -1
  7. package/dist/wu-framework.esm.js +3 -0
  8. package/dist/wu-framework.esm.js.map +1 -0
  9. package/dist/wu-framework.umd.js +3 -1
  10. package/dist/wu-framework.umd.js.map +1 -0
  11. package/integrations/astro/README.md +127 -0
  12. package/integrations/astro/WuApp.astro +63 -0
  13. package/integrations/astro/WuShell.astro +39 -0
  14. package/integrations/astro/index.js +68 -0
  15. package/integrations/astro/package.json +38 -0
  16. package/integrations/astro/types.d.ts +53 -0
  17. package/package.json +96 -72
  18. package/src/adapters/angular/ai.js +30 -0
  19. package/src/adapters/angular/index.d.ts +154 -0
  20. package/src/adapters/angular/index.js +932 -0
  21. package/src/adapters/angular.d.ts +3 -154
  22. package/src/adapters/angular.js +3 -813
  23. package/src/adapters/index.js +35 -24
  24. package/src/adapters/lit/ai.js +20 -0
  25. package/src/adapters/lit/index.d.ts +120 -0
  26. package/src/adapters/lit/index.js +721 -0
  27. package/src/adapters/lit.d.ts +3 -120
  28. package/src/adapters/lit.js +3 -726
  29. package/src/adapters/preact/ai.js +33 -0
  30. package/src/adapters/preact/index.d.ts +108 -0
  31. package/src/adapters/preact/index.js +661 -0
  32. package/src/adapters/preact.d.ts +3 -108
  33. package/src/adapters/preact.js +3 -665
  34. package/src/adapters/react/ai.js +135 -0
  35. package/src/adapters/react/index.d.ts +246 -0
  36. package/src/adapters/react/index.js +694 -0
  37. package/src/adapters/react.d.ts +3 -212
  38. package/src/adapters/react.js +3 -513
  39. package/src/adapters/shared.js +64 -0
  40. package/src/adapters/solid/ai.js +32 -0
  41. package/src/adapters/solid/index.d.ts +101 -0
  42. package/src/adapters/solid/index.js +586 -0
  43. package/src/adapters/solid.d.ts +3 -101
  44. package/src/adapters/solid.js +3 -591
  45. package/src/adapters/svelte/ai.js +31 -0
  46. package/src/adapters/svelte/index.d.ts +166 -0
  47. package/src/adapters/svelte/index.js +798 -0
  48. package/src/adapters/svelte.d.ts +3 -166
  49. package/src/adapters/svelte.js +3 -803
  50. package/src/adapters/vanilla/ai.js +30 -0
  51. package/src/adapters/vanilla/index.d.ts +179 -0
  52. package/src/adapters/vanilla/index.js +785 -0
  53. package/src/adapters/vanilla.d.ts +3 -179
  54. package/src/adapters/vanilla.js +3 -791
  55. package/src/adapters/vue/ai.js +52 -0
  56. package/src/adapters/vue/index.d.ts +299 -0
  57. package/src/adapters/vue/index.js +608 -0
  58. package/src/adapters/vue.d.ts +3 -299
  59. package/src/adapters/vue.js +3 -611
  60. package/src/ai/wu-ai-actions.js +261 -0
  61. package/src/ai/wu-ai-agent.js +546 -0
  62. package/src/ai/wu-ai-browser-primitives.js +354 -0
  63. package/src/ai/wu-ai-browser.js +380 -0
  64. package/src/ai/wu-ai-context.js +332 -0
  65. package/src/ai/wu-ai-conversation.js +613 -0
  66. package/src/ai/wu-ai-orchestrate.js +1021 -0
  67. package/src/ai/wu-ai-permissions.js +381 -0
  68. package/src/ai/wu-ai-provider.js +700 -0
  69. package/src/ai/wu-ai-schema.js +225 -0
  70. package/src/ai/wu-ai-triggers.js +396 -0
  71. package/src/ai/wu-ai.js +804 -0
  72. package/src/core/wu-app.js +50 -8
  73. package/src/core/wu-cache.js +2 -3
  74. package/src/core/wu-core.js +648 -681
  75. package/src/core/wu-html-parser.js +121 -211
  76. package/src/core/wu-iframe-sandbox.js +328 -0
  77. package/src/core/wu-mcp-bridge.js +431 -0
  78. package/src/core/wu-overrides.js +510 -0
  79. package/src/core/wu-plugin.js +4 -1
  80. package/src/core/wu-prefetch.js +414 -0
  81. package/src/core/wu-proxy-sandbox.js +398 -75
  82. package/src/core/wu-sandbox.js +86 -268
  83. package/src/core/wu-script-executor.js +79 -182
  84. package/src/core/wu-snapshot-sandbox.js +149 -106
  85. package/src/core/wu-strategies.js +13 -0
  86. package/src/core/wu-style-bridge.js +23 -23
  87. package/src/index.js +162 -665
  88. package/dist/wu-framework.hex.js +0 -23
  89. package/dist/wu-framework.min.js +0 -1
  90. package/dist/wu-framework.obf.js +0 -1
  91. package/scripts/build-protected.js +0 -366
  92. package/scripts/build.js +0 -212
  93. package/scripts/rollup-plugin-hex.js +0 -143
  94. package/src/core/wu-registry.js +0 -60
  95. package/src/core/wu-sandbox-pool.js +0 -390
@@ -0,0 +1,380 @@
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.