wu-framework 1.1.14 → 1.1.16

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/LICENSE +39 -39
  2. package/README.md +408 -408
  3. package/dist/wu-framework.cjs.js.map +1 -1
  4. package/dist/wu-framework.dev.js +15151 -15151
  5. package/dist/wu-framework.dev.js.map +1 -1
  6. package/dist/wu-framework.esm.js.map +1 -1
  7. package/dist/wu-framework.umd.js.map +1 -1
  8. package/integrations/astro/README.md +127 -127
  9. package/integrations/astro/WuApp.astro +63 -63
  10. package/integrations/astro/WuShell.astro +39 -39
  11. package/integrations/astro/index.js +68 -68
  12. package/integrations/astro/package.json +38 -38
  13. package/integrations/astro/types.d.ts +53 -53
  14. package/package.json +161 -161
  15. package/src/adapters/angular/ai.js +30 -30
  16. package/src/adapters/angular/index.d.ts +154 -154
  17. package/src/adapters/angular/index.js +932 -932
  18. package/src/adapters/angular.d.ts +3 -3
  19. package/src/adapters/angular.js +3 -3
  20. package/src/adapters/index.js +168 -168
  21. package/src/adapters/lit/ai.js +20 -20
  22. package/src/adapters/lit/index.d.ts +120 -120
  23. package/src/adapters/lit/index.js +721 -721
  24. package/src/adapters/lit.d.ts +3 -3
  25. package/src/adapters/lit.js +3 -3
  26. package/src/adapters/preact/ai.js +33 -33
  27. package/src/adapters/preact/index.d.ts +108 -108
  28. package/src/adapters/preact/index.js +661 -661
  29. package/src/adapters/preact.d.ts +3 -3
  30. package/src/adapters/preact.js +3 -3
  31. package/src/adapters/react/index.js +48 -54
  32. package/src/adapters/react.d.ts +3 -3
  33. package/src/adapters/react.js +3 -3
  34. package/src/adapters/shared.js +64 -64
  35. package/src/adapters/solid/ai.js +32 -32
  36. package/src/adapters/solid/index.d.ts +101 -101
  37. package/src/adapters/solid/index.js +586 -586
  38. package/src/adapters/solid.d.ts +3 -3
  39. package/src/adapters/solid.js +3 -3
  40. package/src/adapters/svelte/ai.js +31 -31
  41. package/src/adapters/svelte/index.d.ts +166 -166
  42. package/src/adapters/svelte/index.js +798 -798
  43. package/src/adapters/svelte.d.ts +3 -3
  44. package/src/adapters/svelte.js +3 -3
  45. package/src/adapters/vanilla/ai.js +30 -30
  46. package/src/adapters/vanilla/index.d.ts +179 -179
  47. package/src/adapters/vanilla/index.js +785 -785
  48. package/src/adapters/vanilla.d.ts +3 -3
  49. package/src/adapters/vanilla.js +3 -3
  50. package/src/adapters/vue/ai.js +52 -52
  51. package/src/adapters/vue/index.d.ts +299 -299
  52. package/src/adapters/vue/index.js +610 -610
  53. package/src/adapters/vue.d.ts +3 -3
  54. package/src/adapters/vue.js +3 -3
  55. package/src/ai/wu-ai-actions.js +261 -261
  56. package/src/ai/wu-ai-agent.js +546 -546
  57. package/src/ai/wu-ai-browser-primitives.js +354 -354
  58. package/src/ai/wu-ai-browser.js +380 -380
  59. package/src/ai/wu-ai-context.js +332 -332
  60. package/src/ai/wu-ai-conversation.js +613 -613
  61. package/src/ai/wu-ai-orchestrate.js +1021 -1021
  62. package/src/ai/wu-ai-permissions.js +381 -381
  63. package/src/ai/wu-ai-provider.js +700 -700
  64. package/src/ai/wu-ai-schema.js +225 -225
  65. package/src/ai/wu-ai-triggers.js +396 -396
  66. package/src/ai/wu-ai.js +804 -804
  67. package/src/core/wu-app.js +236 -236
  68. package/src/core/wu-cache.js +477 -477
  69. package/src/core/wu-core.js +1398 -1398
  70. package/src/core/wu-error-boundary.js +382 -382
  71. package/src/core/wu-event-bus.js +348 -348
  72. package/src/core/wu-hooks.js +350 -350
  73. package/src/core/wu-html-parser.js +190 -190
  74. package/src/core/wu-iframe-sandbox.js +328 -328
  75. package/src/core/wu-loader.js +272 -272
  76. package/src/core/wu-logger.js +134 -134
  77. package/src/core/wu-manifest.js +509 -509
  78. package/src/core/wu-mcp-bridge.js +432 -432
  79. package/src/core/wu-overrides.js +510 -510
  80. package/src/core/wu-performance.js +228 -228
  81. package/src/core/wu-plugin.js +348 -348
  82. package/src/core/wu-prefetch.js +414 -414
  83. package/src/core/wu-proxy-sandbox.js +476 -476
  84. package/src/core/wu-sandbox.js +779 -779
  85. package/src/core/wu-script-executor.js +113 -113
  86. package/src/core/wu-snapshot-sandbox.js +227 -227
  87. package/src/core/wu-strategies.js +256 -256
  88. package/src/core/wu-style-bridge.js +477 -477
  89. package/src/index.js +224 -224
  90. package/src/utils/dependency-resolver.js +327 -327
@@ -1,3 +1,3 @@
1
- // Re-export from folder structure — backward compatibility
2
- export * from './vue/index';
3
- export { default } from './vue/index';
1
+ // Re-export from folder structure — backward compatibility
2
+ export * from './vue/index';
3
+ export { default } from './vue/index';
@@ -1,3 +1,3 @@
1
- // Re-export from folder structure — backward compatibility
2
- export * from './vue/index.js';
3
- export { default } from './vue/index.js';
1
+ // Re-export from folder structure — backward compatibility
2
+ export * from './vue/index.js';
3
+ export { default } from './vue/index.js';
@@ -1,261 +1,261 @@
1
- /**
2
- * WU-AI-ACTIONS: Action registry and executor
3
- *
4
- * Actions are capabilities that the LLM can invoke via tool_use / function_call.
5
- * Each action has:
6
- * - A handler function (sandboxed API, not raw wu access)
7
- * - JSON Schema parameters
8
- * - Permission requirements
9
- * - Optional confirmation flow
10
- *
11
- * Security: Actions receive a sandboxed API, not the full wu object.
12
- * The LLM cannot do anything the developer didn't explicitly expose.
13
- */
14
-
15
- import { logger } from '../core/wu-logger.js';
16
- import { validateParams, normalizeParameters, buildToolSchemas } from './wu-ai-schema.js';
17
-
18
- export class WuAIActions {
19
- constructor({ eventBus, store, permissions }) {
20
- this._eventBus = eventBus;
21
- this._store = store;
22
- this._permissions = permissions;
23
- this._actions = new Map();
24
- this._executionLog = [];
25
- this._maxLogSize = 100;
26
- this._pendingConfirms = new Map(); // callId → { resolve, reject, timeout }
27
- }
28
-
29
- /**
30
- * Register an action that the LLM can invoke.
31
- *
32
- * @param {string} name - Action name (used in tool_call)
33
- * @param {object} config
34
- * @param {string} config.description - Human-readable description (sent to LLM)
35
- * @param {object} [config.parameters] - JSON Schema or shorthand for params
36
- * @param {Function} config.handler - async (params, sandboxedApi) => result
37
- * @param {boolean} [config.confirm=false] - Require user confirmation before executing
38
- * @param {string[]} [config.permissions=[]] - Required permission flags
39
- * @param {boolean} [config.dangerous=false] - Mark as dangerous in logs
40
- */
41
- register(name, config) {
42
- if (!config.handler || typeof config.handler !== 'function') {
43
- throw new Error(`[wu-ai] Action '${name}' must have a handler function`);
44
- }
45
-
46
- this._actions.set(name, {
47
- description: config.description || `Execute: ${name}`,
48
- parameters: normalizeParameters(config.parameters),
49
- handler: config.handler,
50
- confirm: config.confirm || false,
51
- permissions: config.permissions || [],
52
- dangerous: config.dangerous || false,
53
- });
54
-
55
- logger.wuDebug(`[wu-ai] Action registered: '${name}'${config.dangerous ? ' [DANGEROUS]' : ''}`);
56
- }
57
-
58
- /**
59
- * Unregister an action.
60
- */
61
- unregister(name) {
62
- this._actions.delete(name);
63
- }
64
-
65
- /**
66
- * Execute an action (called when LLM returns tool_call).
67
- *
68
- * @param {string} name - Action name
69
- * @param {object} params - Parameters from LLM
70
- * @param {object} [meta] - { traceId, depth, callId }
71
- * @returns {Promise<{ success: boolean, result?: any, reason?: string }>}
72
- */
73
- async execute(name, params, meta = {}) {
74
- const action = this._actions.get(name);
75
- if (!action) {
76
- return { success: false, reason: `Action '${name}' not registered` };
77
- }
78
-
79
- // 1. Check permissions
80
- for (const perm of action.permissions) {
81
- if (!this._permissions.check(perm)) {
82
- this._emitDenied(name, params, `Missing permission: ${perm}`);
83
- return { success: false, reason: `Permission denied: ${perm}` };
84
- }
85
- }
86
-
87
- // 2. Validate params
88
- const validation = validateParams(params || {}, action.parameters);
89
- if (!validation.valid) {
90
- return { success: false, reason: `Invalid params: ${validation.errors.join(', ')}` };
91
- }
92
-
93
- // 3. Confirmation (if required)
94
- if (action.confirm) {
95
- const confirmed = await this._requestConfirmation(name, params, meta.callId);
96
- if (!confirmed) {
97
- return { success: false, reason: 'User denied action' };
98
- }
99
- }
100
-
101
- // 4. Execute with sandboxed API
102
- try {
103
- if (action.dangerous) {
104
- logger.wuWarn(`[wu-ai] Executing DANGEROUS action: '${name}' with params: ${JSON.stringify(params)}`);
105
- }
106
-
107
- const api = this._createSandboxedApi(action.permissions);
108
- const result = await action.handler(params, api);
109
-
110
- // Audit log
111
- this._log(name, params, result, meta);
112
-
113
- // Emit success event
114
- this._eventBus.emit('ai:action:executed', {
115
- action: name,
116
- params,
117
- result,
118
- traceId: meta.traceId,
119
- }, { appName: 'wu-ai' });
120
-
121
- return { success: true, result };
122
- } catch (err) {
123
- this._eventBus.emit('ai:action:error', {
124
- action: name,
125
- params,
126
- error: err.message,
127
- traceId: meta.traceId,
128
- }, { appName: 'wu-ai' });
129
-
130
- return { success: false, reason: err.message };
131
- }
132
- }
133
-
134
- /**
135
- * Get tool schemas for the LLM (function calling format).
136
- */
137
- getToolSchemas() {
138
- return buildToolSchemas(this._actions);
139
- }
140
-
141
- /**
142
- * Check if an action is registered.
143
- */
144
- has(name) {
145
- return this._actions.has(name);
146
- }
147
-
148
- /**
149
- * Get registered action names.
150
- */
151
- getNames() {
152
- return [...this._actions.keys()];
153
- }
154
-
155
- /**
156
- * Get execution log.
157
- */
158
- getLog() {
159
- return [...this._executionLog];
160
- }
161
-
162
- /**
163
- * Confirm a pending tool call (called by developer/UI).
164
- */
165
- confirmTool(callId) {
166
- const pending = this._pendingConfirms.get(callId);
167
- if (pending) {
168
- clearTimeout(pending.timeout);
169
- this._pendingConfirms.delete(callId);
170
- pending.resolve(true);
171
- }
172
- }
173
-
174
- /**
175
- * Reject a pending tool call.
176
- */
177
- rejectTool(callId) {
178
- const pending = this._pendingConfirms.get(callId);
179
- if (pending) {
180
- clearTimeout(pending.timeout);
181
- this._pendingConfirms.delete(callId);
182
- pending.resolve(false);
183
- }
184
- }
185
-
186
- // ── Private: Sandboxed API ──
187
-
188
- _createSandboxedApi(requiredPermissions) {
189
- const api = {};
190
- const perms = new Set(requiredPermissions);
191
-
192
- // Store access (read)
193
- if (this._permissions.check('readStore')) {
194
- api.getState = (path) => this._store.get(path);
195
- }
196
-
197
- // Store access (write) — only if explicitly permitted
198
- if (this._permissions.check('writeStore') && perms.has('writeStore')) {
199
- api.setState = (path, value) => this._store.set(path, value);
200
- }
201
-
202
- // Event emission
203
- if (this._permissions.check('emitEvents')) {
204
- api.emit = (event, data) => this._eventBus.emit(event, data, { appName: 'wu-ai' });
205
- }
206
-
207
- return api;
208
- }
209
-
210
- // ── Private: Confirmation Flow ──
211
-
212
- _requestConfirmation(actionName, params, callId) {
213
- const id = callId || `confirm_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
214
-
215
- return new Promise((resolve) => {
216
- const timeoutHandle = setTimeout(() => {
217
- this._pendingConfirms.delete(id);
218
- resolve(false); // Timeout = deny
219
- logger.wuDebug(`[wu-ai] Confirmation timeout for action '${actionName}'`);
220
- }, 30000);
221
-
222
- this._pendingConfirms.set(id, { resolve, timeout: timeoutHandle });
223
-
224
- this._eventBus.emit('ai:tool:confirm', {
225
- callId: id,
226
- action: actionName,
227
- params,
228
- message: `AI wants to execute: ${actionName}`,
229
- }, { appName: 'wu-ai' });
230
- });
231
- }
232
-
233
- // ── Private: Logging ──
234
-
235
- _log(action, params, result, meta) {
236
- this._executionLog.push({
237
- action,
238
- params,
239
- result: typeof result === 'object' ? { ...result } : result,
240
- timestamp: Date.now(),
241
- traceId: meta.traceId,
242
- });
243
-
244
- if (this._executionLog.length > this._maxLogSize) {
245
- this._executionLog.shift();
246
- }
247
- }
248
-
249
- _emitDenied(action, params, reason) {
250
- this._eventBus.emit('ai:action:denied', { action, params, reason }, { appName: 'wu-ai' });
251
- logger.wuWarn(`[wu-ai] Action denied: '${action}' — ${reason}`);
252
- }
253
-
254
- getStats() {
255
- return {
256
- registeredActions: [...this._actions.keys()],
257
- executionLogSize: this._executionLog.length,
258
- pendingConfirmations: this._pendingConfirms.size,
259
- };
260
- }
261
- }
1
+ /**
2
+ * WU-AI-ACTIONS: Action registry and executor
3
+ *
4
+ * Actions are capabilities that the LLM can invoke via tool_use / function_call.
5
+ * Each action has:
6
+ * - A handler function (sandboxed API, not raw wu access)
7
+ * - JSON Schema parameters
8
+ * - Permission requirements
9
+ * - Optional confirmation flow
10
+ *
11
+ * Security: Actions receive a sandboxed API, not the full wu object.
12
+ * The LLM cannot do anything the developer didn't explicitly expose.
13
+ */
14
+
15
+ import { logger } from '../core/wu-logger.js';
16
+ import { validateParams, normalizeParameters, buildToolSchemas } from './wu-ai-schema.js';
17
+
18
+ export class WuAIActions {
19
+ constructor({ eventBus, store, permissions }) {
20
+ this._eventBus = eventBus;
21
+ this._store = store;
22
+ this._permissions = permissions;
23
+ this._actions = new Map();
24
+ this._executionLog = [];
25
+ this._maxLogSize = 100;
26
+ this._pendingConfirms = new Map(); // callId → { resolve, reject, timeout }
27
+ }
28
+
29
+ /**
30
+ * Register an action that the LLM can invoke.
31
+ *
32
+ * @param {string} name - Action name (used in tool_call)
33
+ * @param {object} config
34
+ * @param {string} config.description - Human-readable description (sent to LLM)
35
+ * @param {object} [config.parameters] - JSON Schema or shorthand for params
36
+ * @param {Function} config.handler - async (params, sandboxedApi) => result
37
+ * @param {boolean} [config.confirm=false] - Require user confirmation before executing
38
+ * @param {string[]} [config.permissions=[]] - Required permission flags
39
+ * @param {boolean} [config.dangerous=false] - Mark as dangerous in logs
40
+ */
41
+ register(name, config) {
42
+ if (!config.handler || typeof config.handler !== 'function') {
43
+ throw new Error(`[wu-ai] Action '${name}' must have a handler function`);
44
+ }
45
+
46
+ this._actions.set(name, {
47
+ description: config.description || `Execute: ${name}`,
48
+ parameters: normalizeParameters(config.parameters),
49
+ handler: config.handler,
50
+ confirm: config.confirm || false,
51
+ permissions: config.permissions || [],
52
+ dangerous: config.dangerous || false,
53
+ });
54
+
55
+ logger.wuDebug(`[wu-ai] Action registered: '${name}'${config.dangerous ? ' [DANGEROUS]' : ''}`);
56
+ }
57
+
58
+ /**
59
+ * Unregister an action.
60
+ */
61
+ unregister(name) {
62
+ this._actions.delete(name);
63
+ }
64
+
65
+ /**
66
+ * Execute an action (called when LLM returns tool_call).
67
+ *
68
+ * @param {string} name - Action name
69
+ * @param {object} params - Parameters from LLM
70
+ * @param {object} [meta] - { traceId, depth, callId }
71
+ * @returns {Promise<{ success: boolean, result?: any, reason?: string }>}
72
+ */
73
+ async execute(name, params, meta = {}) {
74
+ const action = this._actions.get(name);
75
+ if (!action) {
76
+ return { success: false, reason: `Action '${name}' not registered` };
77
+ }
78
+
79
+ // 1. Check permissions
80
+ for (const perm of action.permissions) {
81
+ if (!this._permissions.check(perm)) {
82
+ this._emitDenied(name, params, `Missing permission: ${perm}`);
83
+ return { success: false, reason: `Permission denied: ${perm}` };
84
+ }
85
+ }
86
+
87
+ // 2. Validate params
88
+ const validation = validateParams(params || {}, action.parameters);
89
+ if (!validation.valid) {
90
+ return { success: false, reason: `Invalid params: ${validation.errors.join(', ')}` };
91
+ }
92
+
93
+ // 3. Confirmation (if required)
94
+ if (action.confirm) {
95
+ const confirmed = await this._requestConfirmation(name, params, meta.callId);
96
+ if (!confirmed) {
97
+ return { success: false, reason: 'User denied action' };
98
+ }
99
+ }
100
+
101
+ // 4. Execute with sandboxed API
102
+ try {
103
+ if (action.dangerous) {
104
+ logger.wuWarn(`[wu-ai] Executing DANGEROUS action: '${name}' with params: ${JSON.stringify(params)}`);
105
+ }
106
+
107
+ const api = this._createSandboxedApi(action.permissions);
108
+ const result = await action.handler(params, api);
109
+
110
+ // Audit log
111
+ this._log(name, params, result, meta);
112
+
113
+ // Emit success event
114
+ this._eventBus.emit('ai:action:executed', {
115
+ action: name,
116
+ params,
117
+ result,
118
+ traceId: meta.traceId,
119
+ }, { appName: 'wu-ai' });
120
+
121
+ return { success: true, result };
122
+ } catch (err) {
123
+ this._eventBus.emit('ai:action:error', {
124
+ action: name,
125
+ params,
126
+ error: err.message,
127
+ traceId: meta.traceId,
128
+ }, { appName: 'wu-ai' });
129
+
130
+ return { success: false, reason: err.message };
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Get tool schemas for the LLM (function calling format).
136
+ */
137
+ getToolSchemas() {
138
+ return buildToolSchemas(this._actions);
139
+ }
140
+
141
+ /**
142
+ * Check if an action is registered.
143
+ */
144
+ has(name) {
145
+ return this._actions.has(name);
146
+ }
147
+
148
+ /**
149
+ * Get registered action names.
150
+ */
151
+ getNames() {
152
+ return [...this._actions.keys()];
153
+ }
154
+
155
+ /**
156
+ * Get execution log.
157
+ */
158
+ getLog() {
159
+ return [...this._executionLog];
160
+ }
161
+
162
+ /**
163
+ * Confirm a pending tool call (called by developer/UI).
164
+ */
165
+ confirmTool(callId) {
166
+ const pending = this._pendingConfirms.get(callId);
167
+ if (pending) {
168
+ clearTimeout(pending.timeout);
169
+ this._pendingConfirms.delete(callId);
170
+ pending.resolve(true);
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Reject a pending tool call.
176
+ */
177
+ rejectTool(callId) {
178
+ const pending = this._pendingConfirms.get(callId);
179
+ if (pending) {
180
+ clearTimeout(pending.timeout);
181
+ this._pendingConfirms.delete(callId);
182
+ pending.resolve(false);
183
+ }
184
+ }
185
+
186
+ // ── Private: Sandboxed API ──
187
+
188
+ _createSandboxedApi(requiredPermissions) {
189
+ const api = {};
190
+ const perms = new Set(requiredPermissions);
191
+
192
+ // Store access (read)
193
+ if (this._permissions.check('readStore')) {
194
+ api.getState = (path) => this._store.get(path);
195
+ }
196
+
197
+ // Store access (write) — only if explicitly permitted
198
+ if (this._permissions.check('writeStore') && perms.has('writeStore')) {
199
+ api.setState = (path, value) => this._store.set(path, value);
200
+ }
201
+
202
+ // Event emission
203
+ if (this._permissions.check('emitEvents')) {
204
+ api.emit = (event, data) => this._eventBus.emit(event, data, { appName: 'wu-ai' });
205
+ }
206
+
207
+ return api;
208
+ }
209
+
210
+ // ── Private: Confirmation Flow ──
211
+
212
+ _requestConfirmation(actionName, params, callId) {
213
+ const id = callId || `confirm_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
214
+
215
+ return new Promise((resolve) => {
216
+ const timeoutHandle = setTimeout(() => {
217
+ this._pendingConfirms.delete(id);
218
+ resolve(false); // Timeout = deny
219
+ logger.wuDebug(`[wu-ai] Confirmation timeout for action '${actionName}'`);
220
+ }, 30000);
221
+
222
+ this._pendingConfirms.set(id, { resolve, timeout: timeoutHandle });
223
+
224
+ this._eventBus.emit('ai:tool:confirm', {
225
+ callId: id,
226
+ action: actionName,
227
+ params,
228
+ message: `AI wants to execute: ${actionName}`,
229
+ }, { appName: 'wu-ai' });
230
+ });
231
+ }
232
+
233
+ // ── Private: Logging ──
234
+
235
+ _log(action, params, result, meta) {
236
+ this._executionLog.push({
237
+ action,
238
+ params,
239
+ result: typeof result === 'object' ? { ...result } : result,
240
+ timestamp: Date.now(),
241
+ traceId: meta.traceId,
242
+ });
243
+
244
+ if (this._executionLog.length > this._maxLogSize) {
245
+ this._executionLog.shift();
246
+ }
247
+ }
248
+
249
+ _emitDenied(action, params, reason) {
250
+ this._eventBus.emit('ai:action:denied', { action, params, reason }, { appName: 'wu-ai' });
251
+ logger.wuWarn(`[wu-ai] Action denied: '${action}' — ${reason}`);
252
+ }
253
+
254
+ getStats() {
255
+ return {
256
+ registeredActions: [...this._actions.keys()],
257
+ executionLogSize: this._executionLog.length,
258
+ pendingConfirmations: this._pendingConfirms.size,
259
+ };
260
+ }
261
+ }