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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU-AI React Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides AI integration using React hooks.
|
|
5
|
+
* Factory pattern: createUseWuAI(React) returns useWuAI().
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { createUseWuAI } from 'wu-framework/adapters/react';
|
|
9
|
+
* import React from 'react';
|
|
10
|
+
*
|
|
11
|
+
* const useWuAI = createUseWuAI(React);
|
|
12
|
+
* const { messages, send, isStreaming } = useWuAI();
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { getWuInstance } from '../shared.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Factory that creates the useWuAI hook for React.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} React - React object with hooks (useState, useCallback, useRef, useEffect)
|
|
21
|
+
* @returns {Function} useWuAI(options)
|
|
22
|
+
*/
|
|
23
|
+
export function createUseWuAI(React) {
|
|
24
|
+
const { useState, useCallback, useRef, useEffect } = React;
|
|
25
|
+
|
|
26
|
+
return function useWuAI(options = {}) {
|
|
27
|
+
const { namespace = 'default', onActionExecuted = null } = options;
|
|
28
|
+
|
|
29
|
+
const [messages, setMessages] = useState([]);
|
|
30
|
+
const [isStreaming, setIsStreaming] = useState(false);
|
|
31
|
+
const [error, setError] = useState(null);
|
|
32
|
+
const actionListenerRef = useRef(null);
|
|
33
|
+
|
|
34
|
+
// Listen for action execution events to provide visual feedback
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const wu = getWuInstance();
|
|
37
|
+
if (!wu?.eventBus) return;
|
|
38
|
+
|
|
39
|
+
const unsub = wu.eventBus.on('ai:action:executed', (event) => {
|
|
40
|
+
const actionMsg = {
|
|
41
|
+
id: `action-${Date.now()}`,
|
|
42
|
+
role: 'action',
|
|
43
|
+
content: event.data?.action || 'action',
|
|
44
|
+
result: event.data?.result,
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
setMessages((prev) => [...prev, actionMsg]);
|
|
48
|
+
if (onActionExecuted) onActionExecuted(event.data);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
actionListenerRef.current = unsub;
|
|
52
|
+
return () => { if (unsub) unsub(); };
|
|
53
|
+
}, [onActionExecuted]);
|
|
54
|
+
|
|
55
|
+
const send = useCallback(async (text) => {
|
|
56
|
+
if (!text?.trim()) return;
|
|
57
|
+
const wu = getWuInstance();
|
|
58
|
+
if (!wu?.ai) { setError('Wu AI not available'); return; }
|
|
59
|
+
|
|
60
|
+
setMessages((prev) => [...prev, {
|
|
61
|
+
id: `user-${Date.now()}`, role: 'user', content: text, timestamp: Date.now(),
|
|
62
|
+
}]);
|
|
63
|
+
setError(null);
|
|
64
|
+
setIsStreaming(true);
|
|
65
|
+
|
|
66
|
+
const assistantId = `assistant-${Date.now()}`;
|
|
67
|
+
setMessages((prev) => [...prev, {
|
|
68
|
+
id: assistantId, role: 'assistant', content: '', timestamp: Date.now(),
|
|
69
|
+
}]);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
let fullContent = '';
|
|
73
|
+
for await (const chunk of wu.ai.stream(text, { namespace })) {
|
|
74
|
+
if (chunk.type === 'text') {
|
|
75
|
+
fullContent += chunk.content;
|
|
76
|
+
const captured = fullContent;
|
|
77
|
+
setMessages((prev) =>
|
|
78
|
+
prev.map((m) =>
|
|
79
|
+
m.id === assistantId ? { ...m, content: captured } : m,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (chunk.type === 'error') {
|
|
84
|
+
setError(chunk.error?.message || 'AI request failed');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
setError(err.message || 'AI request failed');
|
|
89
|
+
setMessages((prev) => prev.filter((m) => m.id !== assistantId || m.content));
|
|
90
|
+
} finally {
|
|
91
|
+
setIsStreaming(false);
|
|
92
|
+
}
|
|
93
|
+
}, [namespace]);
|
|
94
|
+
|
|
95
|
+
const sendSync = useCallback(async (text) => {
|
|
96
|
+
if (!text?.trim()) return null;
|
|
97
|
+
const wu = getWuInstance();
|
|
98
|
+
if (!wu?.ai) { setError('Wu AI not available'); return null; }
|
|
99
|
+
|
|
100
|
+
setMessages((prev) => [...prev, {
|
|
101
|
+
id: `user-${Date.now()}`, role: 'user', content: text, timestamp: Date.now(),
|
|
102
|
+
}]);
|
|
103
|
+
setError(null);
|
|
104
|
+
setIsStreaming(true);
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const response = await wu.ai.send(text, { namespace });
|
|
108
|
+
setMessages((prev) => [...prev, {
|
|
109
|
+
id: `assistant-${Date.now()}`, role: 'assistant', content: response.content, timestamp: Date.now(),
|
|
110
|
+
}]);
|
|
111
|
+
return response;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
setError(err.message || 'AI request failed');
|
|
114
|
+
return null;
|
|
115
|
+
} finally {
|
|
116
|
+
setIsStreaming(false);
|
|
117
|
+
}
|
|
118
|
+
}, [namespace]);
|
|
119
|
+
|
|
120
|
+
const abort = useCallback(() => {
|
|
121
|
+
const wu = getWuInstance();
|
|
122
|
+
if (wu?.ai) wu.ai.abort(namespace);
|
|
123
|
+
setIsStreaming(false);
|
|
124
|
+
}, [namespace]);
|
|
125
|
+
|
|
126
|
+
const clear = useCallback(() => {
|
|
127
|
+
setMessages([]);
|
|
128
|
+
setError(null);
|
|
129
|
+
const wu = getWuInstance();
|
|
130
|
+
if (wu?.ai) wu.ai.conversation.clear(namespace);
|
|
131
|
+
}, [namespace]);
|
|
132
|
+
|
|
133
|
+
return { messages, isStreaming, error, send, sendSync, abort, clear };
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wu Framework React Adapter - TypeScript Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ComponentType, ReactElement, CSSProperties, RefObject } from 'react';
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Core Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
export interface WuInstance {
|
|
12
|
+
init: (config: WuConfig) => Promise<void>;
|
|
13
|
+
mount: (appName: string, container: string) => Promise<void>;
|
|
14
|
+
unmount: (appName: string) => Promise<void>;
|
|
15
|
+
define: (appName: string, lifecycle: WuLifecycle) => void;
|
|
16
|
+
app: (name: string, config: WuAppConfig) => WuApp;
|
|
17
|
+
eventBus: WuEventBus;
|
|
18
|
+
store: WuStore;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WuConfig {
|
|
22
|
+
apps: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
url: string;
|
|
25
|
+
strategy?: 'lazy' | 'eager' | 'preload' | 'idle';
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface WuLifecycle {
|
|
30
|
+
mount: (container: HTMLElement) => void | Promise<void>;
|
|
31
|
+
unmount: (container?: HTMLElement) => void | Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface WuAppConfig {
|
|
35
|
+
url: string;
|
|
36
|
+
container: string;
|
|
37
|
+
autoInit?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface WuApp {
|
|
41
|
+
mount: (container?: string) => Promise<void>;
|
|
42
|
+
unmount: () => Promise<void>;
|
|
43
|
+
remount: () => Promise<void>;
|
|
44
|
+
reload: () => Promise<void>;
|
|
45
|
+
destroy: () => Promise<void>;
|
|
46
|
+
isMounted: boolean;
|
|
47
|
+
info: WuAppInfo;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface WuAppInfo {
|
|
51
|
+
name: string;
|
|
52
|
+
url: string;
|
|
53
|
+
mounted: boolean;
|
|
54
|
+
status: 'stable' | 'refreshed' | 'unstable';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface WuEventBus {
|
|
58
|
+
emit: (event: string, data?: any, options?: EmitOptions) => void;
|
|
59
|
+
on: (event: string, callback: EventCallback) => () => void;
|
|
60
|
+
once: (event: string, callback: EventCallback) => () => void;
|
|
61
|
+
off: (event: string, callback?: EventCallback) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WuStore {
|
|
65
|
+
get: (path?: string) => any;
|
|
66
|
+
set: (path: string, value: any) => number;
|
|
67
|
+
on: (pattern: string, callback: StoreCallback) => () => void;
|
|
68
|
+
batch: (updates: Record<string, any>) => number[];
|
|
69
|
+
clear: () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type EventCallback = (event: WuEvent) => void;
|
|
73
|
+
export type StoreCallback = (change: { path: string; value: any }) => void;
|
|
74
|
+
|
|
75
|
+
export interface WuEvent {
|
|
76
|
+
name: string;
|
|
77
|
+
data: any;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
source?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface EmitOptions {
|
|
83
|
+
appName?: string;
|
|
84
|
+
timestamp?: number;
|
|
85
|
+
meta?: Record<string, any>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// React Adapter Types
|
|
90
|
+
// ============================================================================
|
|
91
|
+
|
|
92
|
+
export interface RegisterOptions {
|
|
93
|
+
/** Wrap component in StrictMode (default: true) */
|
|
94
|
+
strictMode?: boolean;
|
|
95
|
+
/** Initial props for the component */
|
|
96
|
+
props?: Record<string, any>;
|
|
97
|
+
/** Callback after mounting */
|
|
98
|
+
onMount?: (container: HTMLElement) => void;
|
|
99
|
+
/** Callback before unmounting */
|
|
100
|
+
onUnmount?: (container: HTMLElement) => void;
|
|
101
|
+
/** Allow standalone execution (default: true) */
|
|
102
|
+
standalone?: boolean;
|
|
103
|
+
/** Selector for standalone mode (default: '#root') */
|
|
104
|
+
standaloneContainer?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Register a React component as a microfrontend
|
|
109
|
+
*/
|
|
110
|
+
export function register<P = {}>(
|
|
111
|
+
appName: string,
|
|
112
|
+
Component: ComponentType<P>,
|
|
113
|
+
options?: RegisterOptions
|
|
114
|
+
): Promise<boolean>;
|
|
115
|
+
|
|
116
|
+
// ============================================================================
|
|
117
|
+
// WuSlot Component Types
|
|
118
|
+
// ============================================================================
|
|
119
|
+
|
|
120
|
+
export interface WuSlotProps {
|
|
121
|
+
/** Display name for the microfrontend */
|
|
122
|
+
name: string;
|
|
123
|
+
/** URL where the microfrontend is hosted */
|
|
124
|
+
url: string;
|
|
125
|
+
/** App name from wu.json (defaults to name if not provided) */
|
|
126
|
+
appName?: string;
|
|
127
|
+
/** Custom fallback while loading */
|
|
128
|
+
fallback?: ReactElement | null;
|
|
129
|
+
/** Callback when microfrontend loads successfully */
|
|
130
|
+
onLoad?: (info: { name: string; url: string }) => void;
|
|
131
|
+
/** Callback when loading fails */
|
|
132
|
+
onError?: (error: Error) => void;
|
|
133
|
+
/** Callback when microfrontend mounts */
|
|
134
|
+
onMount?: (info: { name: string; container: HTMLElement }) => void;
|
|
135
|
+
/** Callback when microfrontend unmounts */
|
|
136
|
+
onUnmount?: (info: { name: string }) => void;
|
|
137
|
+
/** Additional CSS class */
|
|
138
|
+
className?: string;
|
|
139
|
+
/** Inline styles */
|
|
140
|
+
style?: CSSProperties;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Create a WuSlot component for loading microfrontends
|
|
145
|
+
* @param React - React instance
|
|
146
|
+
*/
|
|
147
|
+
export function createWuSlot(React: any): ComponentType<WuSlotProps>;
|
|
148
|
+
|
|
149
|
+
// ============================================================================
|
|
150
|
+
// Hooks Types
|
|
151
|
+
// ============================================================================
|
|
152
|
+
|
|
153
|
+
export interface UseWuEventsReturn {
|
|
154
|
+
/** Emit an event to the event bus */
|
|
155
|
+
emit: (event: string, data?: any, options?: EmitOptions) => void;
|
|
156
|
+
/** Subscribe to an event */
|
|
157
|
+
on: (event: string, callback: EventCallback) => () => void;
|
|
158
|
+
/** Subscribe to an event once */
|
|
159
|
+
once: (event: string, callback: EventCallback) => () => void;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create the useWuEvents hook
|
|
164
|
+
* @param React - React instance
|
|
165
|
+
*/
|
|
166
|
+
export function createUseWuEvents(React: any): () => UseWuEventsReturn;
|
|
167
|
+
|
|
168
|
+
export interface UseWuStoreReturn<T = any> {
|
|
169
|
+
/** Current state value (reactive) */
|
|
170
|
+
state: T | null;
|
|
171
|
+
/** Set a value in the store */
|
|
172
|
+
setState: (path: string, value: any) => void;
|
|
173
|
+
/** Get a value from the store */
|
|
174
|
+
getState: (path?: string) => any;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Create the useWuStore hook
|
|
179
|
+
* @param React - React instance
|
|
180
|
+
*/
|
|
181
|
+
export function createUseWuStore(React: any): <T = any>(namespace?: string) => UseWuStoreReturn<T>;
|
|
182
|
+
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// AI Hook Types (Paradigma C: IA como Director de Orquesta)
|
|
185
|
+
// ============================================================================
|
|
186
|
+
|
|
187
|
+
export interface AIMessage {
|
|
188
|
+
id: string;
|
|
189
|
+
role: 'user' | 'assistant' | 'action';
|
|
190
|
+
content: string;
|
|
191
|
+
result?: any;
|
|
192
|
+
timestamp: number;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface UseWuAIOptions {
|
|
196
|
+
namespace?: string;
|
|
197
|
+
onActionExecuted?: (data: { action: string; result: any }) => void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface UseWuAIReturn {
|
|
201
|
+
messages: AIMessage[];
|
|
202
|
+
isStreaming: boolean;
|
|
203
|
+
error: string | null;
|
|
204
|
+
send: (text: string) => Promise<void>;
|
|
205
|
+
sendSync: (text: string) => Promise<any | null>;
|
|
206
|
+
abort: () => void;
|
|
207
|
+
clear: () => void;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Create the useWuAI hook for AI integration
|
|
212
|
+
* @param React - React instance
|
|
213
|
+
*/
|
|
214
|
+
export function createUseWuAI(React: any): (options?: UseWuAIOptions) => UseWuAIReturn;
|
|
215
|
+
|
|
216
|
+
// ============================================================================
|
|
217
|
+
// Utility Functions
|
|
218
|
+
// ============================================================================
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get the Wu Framework instance
|
|
222
|
+
*/
|
|
223
|
+
export function getWuInstance(): WuInstance | null;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Wait for Wu Framework to be available
|
|
227
|
+
* @param timeout - Maximum time to wait in ms (default: 5000)
|
|
228
|
+
*/
|
|
229
|
+
export function waitForWu(timeout?: number): Promise<WuInstance>;
|
|
230
|
+
|
|
231
|
+
// ============================================================================
|
|
232
|
+
// Main Export
|
|
233
|
+
// ============================================================================
|
|
234
|
+
|
|
235
|
+
export interface WuReactAdapter {
|
|
236
|
+
register: typeof register;
|
|
237
|
+
createWuSlot: typeof createWuSlot;
|
|
238
|
+
createUseWuEvents: typeof createUseWuEvents;
|
|
239
|
+
createUseWuStore: typeof createUseWuStore;
|
|
240
|
+
createUseWuAI: typeof createUseWuAI;
|
|
241
|
+
getWuInstance: typeof getWuInstance;
|
|
242
|
+
waitForWu: typeof waitForWu;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const wuReact: WuReactAdapter;
|
|
246
|
+
export default wuReact;
|