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.
- package/README.md +511 -977
- package/dist/wu-framework.cjs.js +3 -1
- package/dist/wu-framework.cjs.js.map +1 -0
- package/dist/wu-framework.dev.js +7533 -2761
- package/dist/wu-framework.dev.js.map +1 -1
- package/dist/wu-framework.esm.js +3 -0
- package/dist/wu-framework.esm.js.map +1 -0
- package/dist/wu-framework.umd.js +3 -1
- package/dist/wu-framework.umd.js.map +1 -0
- package/integrations/astro/README.md +127 -0
- package/integrations/astro/WuApp.astro +63 -0
- package/integrations/astro/WuShell.astro +39 -0
- package/integrations/astro/index.js +68 -0
- package/integrations/astro/package.json +38 -0
- package/integrations/astro/types.d.ts +53 -0
- package/package.json +94 -74
- package/src/adapters/angular/ai.js +30 -0
- package/src/adapters/angular/index.d.ts +154 -0
- package/src/adapters/angular/index.js +932 -0
- package/src/adapters/angular.d.ts +3 -154
- package/src/adapters/angular.js +3 -813
- package/src/adapters/index.js +35 -24
- package/src/adapters/lit/ai.js +20 -0
- package/src/adapters/lit/index.d.ts +120 -0
- package/src/adapters/lit/index.js +721 -0
- package/src/adapters/lit.d.ts +3 -120
- package/src/adapters/lit.js +3 -726
- package/src/adapters/preact/ai.js +33 -0
- package/src/adapters/preact/index.d.ts +108 -0
- package/src/adapters/preact/index.js +661 -0
- package/src/adapters/preact.d.ts +3 -108
- package/src/adapters/preact.js +3 -665
- package/src/adapters/react/ai.js +135 -0
- package/src/adapters/react/index.d.ts +246 -0
- package/src/adapters/react/index.js +689 -0
- package/src/adapters/react.d.ts +3 -212
- package/src/adapters/react.js +3 -513
- package/src/adapters/shared.js +64 -0
- package/src/adapters/solid/ai.js +32 -0
- package/src/adapters/solid/index.d.ts +101 -0
- package/src/adapters/solid/index.js +586 -0
- package/src/adapters/solid.d.ts +3 -101
- package/src/adapters/solid.js +3 -591
- package/src/adapters/svelte/ai.js +31 -0
- package/src/adapters/svelte/index.d.ts +166 -0
- package/src/adapters/svelte/index.js +798 -0
- package/src/adapters/svelte.d.ts +3 -166
- package/src/adapters/svelte.js +3 -803
- package/src/adapters/vanilla/ai.js +30 -0
- package/src/adapters/vanilla/index.d.ts +179 -0
- package/src/adapters/vanilla/index.js +785 -0
- package/src/adapters/vanilla.d.ts +3 -179
- package/src/adapters/vanilla.js +3 -791
- package/src/adapters/vue/ai.js +52 -0
- package/src/adapters/vue/index.d.ts +299 -0
- package/src/adapters/vue/index.js +608 -0
- package/src/adapters/vue.d.ts +3 -299
- package/src/adapters/vue.js +3 -611
- package/src/ai/wu-ai-actions.js +261 -0
- package/src/ai/wu-ai-browser.js +663 -0
- package/src/ai/wu-ai-context.js +332 -0
- package/src/ai/wu-ai-conversation.js +554 -0
- package/src/ai/wu-ai-permissions.js +381 -0
- package/src/ai/wu-ai-provider.js +605 -0
- package/src/ai/wu-ai-schema.js +225 -0
- package/src/ai/wu-ai-triggers.js +396 -0
- package/src/ai/wu-ai.js +474 -0
- package/src/core/wu-app.js +50 -8
- package/src/core/wu-cache.js +1 -1
- package/src/core/wu-core.js +645 -677
- package/src/core/wu-html-parser.js +121 -211
- package/src/core/wu-iframe-sandbox.js +328 -0
- package/src/core/wu-mcp-bridge.js +647 -0
- package/src/core/wu-overrides.js +510 -0
- package/src/core/wu-prefetch.js +414 -0
- package/src/core/wu-proxy-sandbox.js +398 -75
- package/src/core/wu-sandbox.js +86 -268
- package/src/core/wu-script-executor.js +79 -182
- package/src/core/wu-snapshot-sandbox.js +149 -106
- package/src/core/wu-strategies.js +13 -0
- package/src/core/wu-style-bridge.js +0 -2
- package/src/index.js +139 -665
- package/dist/wu-framework.hex.js +0 -23
- package/dist/wu-framework.min.js +0 -1
- package/dist/wu-framework.obf.js +0 -1
- package/scripts/build-protected.js +0 -366
- package/scripts/build.js +0 -212
- package/scripts/rollup-plugin-hex.js +0 -143
- package/src/core/wu-registry.js +0 -60
- package/src/core/wu-sandbox-pool.js +0 -390
|
@@ -0,0 +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
|
+
}
|