@auroraview/sdk 0.3.21
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/dist/bridge-CRwRGPq-.d.cts +306 -0
- package/dist/bridge-CRwRGPq-.d.ts +306 -0
- package/dist/index.cjs +227 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +222 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +399 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +169 -0
- package/dist/react.d.ts +169 -0
- package/dist/react.js +391 -0
- package/dist/react.js.map +1 -0
- package/dist/vue.cjs +389 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +132 -0
- package/dist/vue.d.ts +132 -0
- package/dist/vue.js +381 -0
- package/dist/vue.js.map +1 -0
- package/package.json +80 -0
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { A as AuroraViewClient, E as EventHandler, p as ProcessOutput, q as ProcessExit } from './bridge-CRwRGPq-.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AuroraView SDK React Adapter
|
|
5
|
+
*
|
|
6
|
+
* Provides React hooks for the AuroraView bridge API.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook to get the AuroraView client
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function App() {
|
|
15
|
+
* const { client, isReady } = useAuroraView();
|
|
16
|
+
*
|
|
17
|
+
* const handleClick = async () => {
|
|
18
|
+
* const result = await client.call('api.echo', { message: 'Hello' });
|
|
19
|
+
* console.log(result);
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* return <button onClick={handleClick} disabled={!isReady}>Call API</button>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function useAuroraView(): {
|
|
27
|
+
client: AuroraViewClient;
|
|
28
|
+
isReady: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Hook to subscribe to an event
|
|
32
|
+
*
|
|
33
|
+
* @param event - Event name to subscribe to
|
|
34
|
+
* @param handler - Event handler function
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* function MyComponent() {
|
|
39
|
+
* useAuroraEvent('custom:event', (data) => {
|
|
40
|
+
* console.log('Received:', data);
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* return <div>Listening for events...</div>;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function useAuroraEvent<T = unknown>(event: string, handler: EventHandler<T>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Hook to subscribe to multiple events
|
|
50
|
+
*
|
|
51
|
+
* @param events - Map of event names to handlers
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* function MyComponent() {
|
|
56
|
+
* useAuroraEvents({
|
|
57
|
+
* 'user:login': (data) => console.log('Login:', data),
|
|
58
|
+
* 'user:logout': () => console.log('Logged out'),
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* return <div>Listening...</div>;
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function useAuroraEvents(events: Record<string, EventHandler>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Options for useProcessEvents hook
|
|
68
|
+
*/
|
|
69
|
+
interface ProcessEventsOptions {
|
|
70
|
+
/** Handler for stdout data */
|
|
71
|
+
onStdout?: (data: ProcessOutput) => void;
|
|
72
|
+
/** Handler for stderr data */
|
|
73
|
+
onStderr?: (data: ProcessOutput) => void;
|
|
74
|
+
/** Handler for process exit */
|
|
75
|
+
onExit?: (data: ProcessExit) => void;
|
|
76
|
+
/** Filter by specific process ID */
|
|
77
|
+
pid?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hook to subscribe to process events
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* function ProcessMonitor() {
|
|
85
|
+
* const [output, setOutput] = useState<string[]>([]);
|
|
86
|
+
*
|
|
87
|
+
* useProcessEvents({
|
|
88
|
+
* onStdout: (data) => setOutput(prev => [...prev, data.data]),
|
|
89
|
+
* onStderr: (data) => setOutput(prev => [...prev, `[ERR] ${data.data}`]),
|
|
90
|
+
* onExit: (data) => console.log(`Process ${data.pid} exited with code ${data.code}`),
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* return <pre>{output.join('')}</pre>;
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function useProcessEvents(options?: ProcessEventsOptions): void;
|
|
98
|
+
/**
|
|
99
|
+
* Hook to call an API method
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* function MyComponent() {
|
|
104
|
+
* const { execute, loading, error, data } = useAuroraCall<string>('api.greet');
|
|
105
|
+
*
|
|
106
|
+
* return (
|
|
107
|
+
* <div>
|
|
108
|
+
* <button onClick={() => execute({ name: 'World' })} disabled={loading}>
|
|
109
|
+
* Greet
|
|
110
|
+
* </button>
|
|
111
|
+
* {error && <p>Error: {error.message}</p>}
|
|
112
|
+
* {data && <p>Result: {data}</p>}
|
|
113
|
+
* </div>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function useAuroraCall<T = unknown>(method: string): {
|
|
119
|
+
execute: (params?: unknown) => Promise<T>;
|
|
120
|
+
loading: boolean;
|
|
121
|
+
error: Error | null;
|
|
122
|
+
data: T | null;
|
|
123
|
+
reset: () => void;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Hook to invoke a plugin command
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* function FileReader() {
|
|
131
|
+
* const { execute, loading, data } = useAuroraInvoke<string>('plugin:fs|read_file');
|
|
132
|
+
*
|
|
133
|
+
* return (
|
|
134
|
+
* <div>
|
|
135
|
+
* <button onClick={() => execute({ path: '/tmp/test.txt' })}>
|
|
136
|
+
* Read File
|
|
137
|
+
* </button>
|
|
138
|
+
* {data && <pre>{data}</pre>}
|
|
139
|
+
* </div>
|
|
140
|
+
* );
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function useAuroraInvoke<T = unknown>(cmd: string): {
|
|
145
|
+
execute: (args?: Record<string, unknown>) => Promise<T>;
|
|
146
|
+
loading: boolean;
|
|
147
|
+
error: Error | null;
|
|
148
|
+
data: T | null;
|
|
149
|
+
reset: () => void;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Hook to access shared state
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```tsx
|
|
156
|
+
* function ThemeToggle() {
|
|
157
|
+
* const [theme, setTheme] = useAuroraState<string>('theme', 'light');
|
|
158
|
+
*
|
|
159
|
+
* return (
|
|
160
|
+
* <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
|
161
|
+
* Current: {theme}
|
|
162
|
+
* </button>
|
|
163
|
+
* );
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function useAuroraState<T>(key: string, defaultValue?: T): [T | undefined, (value: T) => void];
|
|
168
|
+
|
|
169
|
+
export { AuroraViewClient, type ProcessEventsOptions, ProcessExit, ProcessOutput, useAuroraCall, useAuroraEvent, useAuroraEvents, useAuroraInvoke, useAuroraState, useAuroraView, useProcessEvents };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { useState, useMemo, useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/adapters/react.ts
|
|
4
|
+
|
|
5
|
+
// src/core/events.ts
|
|
6
|
+
var EventEmitter = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Subscribe to an event
|
|
12
|
+
* @param event - Event name
|
|
13
|
+
* @param handler - Event handler function
|
|
14
|
+
* @returns Unsubscribe function
|
|
15
|
+
*/
|
|
16
|
+
on(event, handler) {
|
|
17
|
+
if (!this.handlers.has(event)) {
|
|
18
|
+
this.handlers.set(event, /* @__PURE__ */ new Set());
|
|
19
|
+
}
|
|
20
|
+
const handlers = this.handlers.get(event);
|
|
21
|
+
handlers.add(handler);
|
|
22
|
+
return () => {
|
|
23
|
+
handlers.delete(handler);
|
|
24
|
+
if (handlers.size === 0) {
|
|
25
|
+
this.handlers.delete(event);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to an event once
|
|
31
|
+
* @param event - Event name
|
|
32
|
+
* @param handler - Event handler function
|
|
33
|
+
* @returns Unsubscribe function
|
|
34
|
+
*/
|
|
35
|
+
once(event, handler) {
|
|
36
|
+
const wrapper = (data) => {
|
|
37
|
+
unsubscribe();
|
|
38
|
+
handler(data);
|
|
39
|
+
};
|
|
40
|
+
const unsubscribe = this.on(event, wrapper);
|
|
41
|
+
return unsubscribe;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Emit an event to all handlers
|
|
45
|
+
* @param event - Event name
|
|
46
|
+
* @param data - Event data
|
|
47
|
+
*/
|
|
48
|
+
emit(event, data) {
|
|
49
|
+
const handlers = this.handlers.get(event);
|
|
50
|
+
if (!handlers) return;
|
|
51
|
+
handlers.forEach((handler) => {
|
|
52
|
+
try {
|
|
53
|
+
handler(data);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error(`[AuroraView] Error in event handler for "${event}":`, e);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Remove event handler(s)
|
|
61
|
+
* @param event - Event name
|
|
62
|
+
* @param handler - Optional specific handler to remove
|
|
63
|
+
*/
|
|
64
|
+
off(event, handler) {
|
|
65
|
+
if (handler) {
|
|
66
|
+
this.handlers.get(event)?.delete(handler);
|
|
67
|
+
} else {
|
|
68
|
+
this.handlers.delete(event);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if event has handlers
|
|
73
|
+
* @param event - Event name
|
|
74
|
+
*/
|
|
75
|
+
hasHandlers(event) {
|
|
76
|
+
const handlers = this.handlers.get(event);
|
|
77
|
+
return handlers !== void 0 && handlers.size > 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get handler count for an event
|
|
81
|
+
* @param event - Event name
|
|
82
|
+
*/
|
|
83
|
+
handlerCount(event) {
|
|
84
|
+
return this.handlers.get(event)?.size ?? 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove all handlers
|
|
88
|
+
*/
|
|
89
|
+
clear() {
|
|
90
|
+
this.handlers.clear();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var globalEmitter = null;
|
|
94
|
+
function getGlobalEmitter() {
|
|
95
|
+
if (!globalEmitter) {
|
|
96
|
+
globalEmitter = new EventEmitter();
|
|
97
|
+
}
|
|
98
|
+
return globalEmitter;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/core/bridge.ts
|
|
102
|
+
var AuroraViewClientImpl = class {
|
|
103
|
+
constructor() {
|
|
104
|
+
this.interceptInstalled = false;
|
|
105
|
+
this.events = getGlobalEmitter();
|
|
106
|
+
this.installTriggerIntercept();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Install intercept on window.auroraview.trigger to forward events
|
|
110
|
+
*/
|
|
111
|
+
installTriggerIntercept() {
|
|
112
|
+
if (this.interceptInstalled) return;
|
|
113
|
+
if (typeof window === "undefined") return;
|
|
114
|
+
const install = () => {
|
|
115
|
+
const bridge = window.auroraview;
|
|
116
|
+
if (!bridge) return;
|
|
117
|
+
const originalTrigger = bridge.trigger;
|
|
118
|
+
bridge.trigger = (event, detail) => {
|
|
119
|
+
originalTrigger?.call(bridge, event, detail);
|
|
120
|
+
this.events.emit(event, detail);
|
|
121
|
+
};
|
|
122
|
+
this.interceptInstalled = true;
|
|
123
|
+
};
|
|
124
|
+
if (window.auroraview) {
|
|
125
|
+
install();
|
|
126
|
+
} else {
|
|
127
|
+
const checkInterval = setInterval(() => {
|
|
128
|
+
if (window.auroraview) {
|
|
129
|
+
clearInterval(checkInterval);
|
|
130
|
+
install();
|
|
131
|
+
}
|
|
132
|
+
}, 10);
|
|
133
|
+
setTimeout(() => clearInterval(checkInterval), 1e4);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
call(method, params) {
|
|
137
|
+
const bridge = window.auroraview;
|
|
138
|
+
if (!bridge) {
|
|
139
|
+
return Promise.reject(new Error("AuroraView bridge not available"));
|
|
140
|
+
}
|
|
141
|
+
return bridge.call(method, params);
|
|
142
|
+
}
|
|
143
|
+
invoke(cmd, args) {
|
|
144
|
+
const bridge = window.auroraview;
|
|
145
|
+
if (!bridge) {
|
|
146
|
+
return Promise.reject(new Error("AuroraView bridge not available"));
|
|
147
|
+
}
|
|
148
|
+
return bridge.invoke(cmd, args);
|
|
149
|
+
}
|
|
150
|
+
emit(event, data) {
|
|
151
|
+
const bridge = window.auroraview;
|
|
152
|
+
if (bridge) {
|
|
153
|
+
bridge.send_event(event, data);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
on(event, handler) {
|
|
157
|
+
return this.events.on(event, handler);
|
|
158
|
+
}
|
|
159
|
+
once(event, handler) {
|
|
160
|
+
return this.events.once(event, handler);
|
|
161
|
+
}
|
|
162
|
+
off(event, handler) {
|
|
163
|
+
this.events.off(event, handler);
|
|
164
|
+
}
|
|
165
|
+
isReady() {
|
|
166
|
+
return window.auroraview?._ready === true;
|
|
167
|
+
}
|
|
168
|
+
whenReady() {
|
|
169
|
+
return new Promise((resolve) => {
|
|
170
|
+
if (this.isReady()) {
|
|
171
|
+
resolve(this);
|
|
172
|
+
} else if (window.auroraview) {
|
|
173
|
+
window.auroraview.whenReady().then(() => {
|
|
174
|
+
this.installTriggerIntercept();
|
|
175
|
+
resolve(this);
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
const checkInterval = setInterval(() => {
|
|
179
|
+
if (window.auroraview) {
|
|
180
|
+
clearInterval(checkInterval);
|
|
181
|
+
window.auroraview.whenReady().then(() => {
|
|
182
|
+
this.installTriggerIntercept();
|
|
183
|
+
resolve(this);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}, 10);
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
clearInterval(checkInterval);
|
|
189
|
+
resolve(this);
|
|
190
|
+
}, 3e4);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
getRawBridge() {
|
|
195
|
+
return window.auroraview;
|
|
196
|
+
}
|
|
197
|
+
get fs() {
|
|
198
|
+
return window.auroraview?.fs;
|
|
199
|
+
}
|
|
200
|
+
get dialog() {
|
|
201
|
+
return window.auroraview?.dialog;
|
|
202
|
+
}
|
|
203
|
+
get clipboard() {
|
|
204
|
+
return window.auroraview?.clipboard;
|
|
205
|
+
}
|
|
206
|
+
get shell() {
|
|
207
|
+
return window.auroraview?.shell;
|
|
208
|
+
}
|
|
209
|
+
get state() {
|
|
210
|
+
return window.auroraview?.state;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var clientInstance = null;
|
|
214
|
+
function createAuroraView() {
|
|
215
|
+
if (!clientInstance) {
|
|
216
|
+
clientInstance = new AuroraViewClientImpl();
|
|
217
|
+
}
|
|
218
|
+
return clientInstance;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/adapters/react.ts
|
|
222
|
+
function useAuroraView() {
|
|
223
|
+
const [isReady, setIsReady] = useState(false);
|
|
224
|
+
const client = useMemo(() => createAuroraView(), []);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (client.isReady()) {
|
|
227
|
+
setIsReady(true);
|
|
228
|
+
} else {
|
|
229
|
+
client.whenReady().then(() => setIsReady(true));
|
|
230
|
+
}
|
|
231
|
+
}, [client]);
|
|
232
|
+
return { client, isReady };
|
|
233
|
+
}
|
|
234
|
+
function useAuroraEvent(event, handler) {
|
|
235
|
+
const handlerRef = useRef(handler);
|
|
236
|
+
handlerRef.current = handler;
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
const client = createAuroraView();
|
|
239
|
+
const unsubscribe = client.on(event, (data) => {
|
|
240
|
+
handlerRef.current(data);
|
|
241
|
+
});
|
|
242
|
+
return unsubscribe;
|
|
243
|
+
}, [event]);
|
|
244
|
+
}
|
|
245
|
+
function useAuroraEvents(events) {
|
|
246
|
+
const eventsRef = useRef(events);
|
|
247
|
+
eventsRef.current = events;
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
const client = createAuroraView();
|
|
250
|
+
const unsubscribers = [];
|
|
251
|
+
Object.entries(eventsRef.current).forEach(([event]) => {
|
|
252
|
+
const unsub = client.on(event, (data) => {
|
|
253
|
+
eventsRef.current[event]?.(data);
|
|
254
|
+
});
|
|
255
|
+
unsubscribers.push(unsub);
|
|
256
|
+
});
|
|
257
|
+
return () => {
|
|
258
|
+
unsubscribers.forEach((unsub) => unsub());
|
|
259
|
+
};
|
|
260
|
+
}, [Object.keys(events).join(",")]);
|
|
261
|
+
}
|
|
262
|
+
function useProcessEvents(options = {}) {
|
|
263
|
+
const optionsRef = useRef(options);
|
|
264
|
+
optionsRef.current = options;
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const client = createAuroraView();
|
|
267
|
+
const unsubscribers = [];
|
|
268
|
+
if (optionsRef.current.onStdout) {
|
|
269
|
+
const unsub = client.on("process:stdout", (data) => {
|
|
270
|
+
if (optionsRef.current.pid === void 0 || optionsRef.current.pid === data.pid) {
|
|
271
|
+
optionsRef.current.onStdout?.(data);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
unsubscribers.push(unsub);
|
|
275
|
+
}
|
|
276
|
+
if (optionsRef.current.onStderr) {
|
|
277
|
+
const unsub = client.on("process:stderr", (data) => {
|
|
278
|
+
if (optionsRef.current.pid === void 0 || optionsRef.current.pid === data.pid) {
|
|
279
|
+
optionsRef.current.onStderr?.(data);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
unsubscribers.push(unsub);
|
|
283
|
+
}
|
|
284
|
+
if (optionsRef.current.onExit) {
|
|
285
|
+
const unsub = client.on("process:exit", (data) => {
|
|
286
|
+
if (optionsRef.current.pid === void 0 || optionsRef.current.pid === data.pid) {
|
|
287
|
+
optionsRef.current.onExit?.(data);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
unsubscribers.push(unsub);
|
|
291
|
+
}
|
|
292
|
+
return () => {
|
|
293
|
+
unsubscribers.forEach((unsub) => unsub());
|
|
294
|
+
};
|
|
295
|
+
}, []);
|
|
296
|
+
}
|
|
297
|
+
function useAuroraCall(method) {
|
|
298
|
+
const [loading, setLoading] = useState(false);
|
|
299
|
+
const [error, setError] = useState(null);
|
|
300
|
+
const [data, setData] = useState(null);
|
|
301
|
+
const execute = useCallback(
|
|
302
|
+
async (params) => {
|
|
303
|
+
const client = createAuroraView();
|
|
304
|
+
setLoading(true);
|
|
305
|
+
setError(null);
|
|
306
|
+
try {
|
|
307
|
+
const result = await client.call(method, params);
|
|
308
|
+
setData(result);
|
|
309
|
+
return result;
|
|
310
|
+
} catch (e) {
|
|
311
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
312
|
+
setError(err);
|
|
313
|
+
throw err;
|
|
314
|
+
} finally {
|
|
315
|
+
setLoading(false);
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
[method]
|
|
319
|
+
);
|
|
320
|
+
const reset = useCallback(() => {
|
|
321
|
+
setLoading(false);
|
|
322
|
+
setError(null);
|
|
323
|
+
setData(null);
|
|
324
|
+
}, []);
|
|
325
|
+
return { execute, loading, error, data, reset };
|
|
326
|
+
}
|
|
327
|
+
function useAuroraInvoke(cmd) {
|
|
328
|
+
const [loading, setLoading] = useState(false);
|
|
329
|
+
const [error, setError] = useState(null);
|
|
330
|
+
const [data, setData] = useState(null);
|
|
331
|
+
const execute = useCallback(
|
|
332
|
+
async (args) => {
|
|
333
|
+
const client = createAuroraView();
|
|
334
|
+
setLoading(true);
|
|
335
|
+
setError(null);
|
|
336
|
+
try {
|
|
337
|
+
const result = await client.invoke(cmd, args);
|
|
338
|
+
setData(result);
|
|
339
|
+
return result;
|
|
340
|
+
} catch (e) {
|
|
341
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
342
|
+
setError(err);
|
|
343
|
+
throw err;
|
|
344
|
+
} finally {
|
|
345
|
+
setLoading(false);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
[cmd]
|
|
349
|
+
);
|
|
350
|
+
const reset = useCallback(() => {
|
|
351
|
+
setLoading(false);
|
|
352
|
+
setError(null);
|
|
353
|
+
setData(null);
|
|
354
|
+
}, []);
|
|
355
|
+
return { execute, loading, error, data, reset };
|
|
356
|
+
}
|
|
357
|
+
function useAuroraState(key, defaultValue) {
|
|
358
|
+
const client = useMemo(() => createAuroraView(), []);
|
|
359
|
+
const [value, setValue] = useState(() => {
|
|
360
|
+
const state = client.state;
|
|
361
|
+
return state ? state[key] ?? defaultValue : defaultValue;
|
|
362
|
+
});
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
const state = client.state;
|
|
365
|
+
if (!state) return;
|
|
366
|
+
if (state[key] !== void 0) {
|
|
367
|
+
setValue(state[key]);
|
|
368
|
+
}
|
|
369
|
+
const unsubscribe = state.onChange((changedKey, newValue) => {
|
|
370
|
+
if (changedKey === key) {
|
|
371
|
+
setValue(newValue);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
return unsubscribe;
|
|
375
|
+
}, [client, key]);
|
|
376
|
+
const setStateValue = useCallback(
|
|
377
|
+
(newValue) => {
|
|
378
|
+
const state = client.state;
|
|
379
|
+
if (state) {
|
|
380
|
+
state[key] = newValue;
|
|
381
|
+
}
|
|
382
|
+
setValue(newValue);
|
|
383
|
+
},
|
|
384
|
+
[client, key]
|
|
385
|
+
);
|
|
386
|
+
return [value, setStateValue];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export { useAuroraCall, useAuroraEvent, useAuroraEvents, useAuroraInvoke, useAuroraState, useAuroraView, useProcessEvents };
|
|
390
|
+
//# sourceMappingURL=react.js.map
|
|
391
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/events.ts","../src/core/bridge.ts","../src/adapters/react.ts"],"names":[],"mappings":";;;;;AAWO,IAAM,eAAN,MAAmB;AAAA,EAAnB,WAAA,GAAA;AACL,IAAA,IAAA,CAAQ,QAAA,uBAAe,GAAA,EAA+B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtD,EAAA,CAAgB,OAAe,OAAA,EAAuC;AACpE,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAK,CAAA,EAAG;AAC7B,MAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAA,kBAAO,IAAI,KAAK,CAAA;AAAA,IACpC;AACA,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAK,CAAA;AACxC,IAAA,QAAA,CAAS,IAAI,OAAuB,CAAA;AAGpC,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,CAAS,OAAO,OAAuB,CAAA;AACvC,MAAA,IAAI,QAAA,CAAS,SAAS,CAAA,EAAG;AACvB,QAAA,IAAA,CAAK,QAAA,CAAS,OAAO,KAAK,CAAA;AAAA,MAC5B;AAA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aAAA,GAAgB,WAAA;AAAA,IACpB,CAAC,QAAA,KAAgB;AACf,MAAA,MAAM,QAAQ,MAAA,CAAO,KAAA;AACrB,MAAA,IAAI,KAAA,EAAO;AACT,QAAA,KAAA,CAAM,GAAG,CAAA,GAAI,QAAA;AAAA,MACf;AACA,MAAA,QAAA,CAAS,QAAQ,CAAA;AAAA,IACnB,CAAA;AAAA,IACA,CAAC,QAAQ,GAAG;AAAA,GACd;AAEA,EAAA,OAAO,CAAC,OAAO,aAAa,CAAA;AAC9B","file":"react.js","sourcesContent":["/**\n * AuroraView SDK Event System\n *\n * Provides a type-safe event emitter with proper unsubscribe support.\n */\n\nimport type { EventHandler, Unsubscribe } from './types';\n\n/**\n * Event emitter with unsubscribe support\n */\nexport class EventEmitter {\n private handlers = new Map<string, Set<EventHandler>>();\n\n /**\n * Subscribe to an event\n * @param event - Event name\n * @param handler - Event handler function\n * @returns Unsubscribe function\n */\n on<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe {\n if (!this.handlers.has(event)) {\n this.handlers.set(event, new Set());\n }\n const handlers = this.handlers.get(event)!;\n handlers.add(handler as EventHandler);\n\n // Return unsubscribe function\n return () => {\n handlers.delete(handler as EventHandler);\n if (handlers.size === 0) {\n this.handlers.delete(event);\n }\n };\n }\n\n /**\n * Subscribe to an event once\n * @param event - Event name\n * @param handler - Event handler function\n * @returns Unsubscribe function\n */\n once<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe {\n const wrapper: EventHandler<T> = (data) => {\n unsubscribe();\n handler(data);\n };\n const unsubscribe = this.on(event, wrapper);\n return unsubscribe;\n }\n\n /**\n * Emit an event to all handlers\n * @param event - Event name\n * @param data - Event data\n */\n emit<T = unknown>(event: string, data: T): void {\n const handlers = this.handlers.get(event);\n if (!handlers) return;\n\n handlers.forEach((handler) => {\n try {\n handler(data);\n } catch (e) {\n console.error(`[AuroraView] Error in event handler for \"${event}\":`, e);\n }\n });\n }\n\n /**\n * Remove event handler(s)\n * @param event - Event name\n * @param handler - Optional specific handler to remove\n */\n off(event: string, handler?: EventHandler): void {\n if (handler) {\n this.handlers.get(event)?.delete(handler);\n } else {\n this.handlers.delete(event);\n }\n }\n\n /**\n * Check if event has handlers\n * @param event - Event name\n */\n hasHandlers(event: string): boolean {\n const handlers = this.handlers.get(event);\n return handlers !== undefined && handlers.size > 0;\n }\n\n /**\n * Get handler count for an event\n * @param event - Event name\n */\n handlerCount(event: string): number {\n return this.handlers.get(event)?.size ?? 0;\n }\n\n /**\n * Remove all handlers\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n/** Singleton event emitter instance */\nlet globalEmitter: EventEmitter | null = null;\n\n/**\n * Get the global event emitter instance\n */\nexport function getGlobalEmitter(): EventEmitter {\n if (!globalEmitter) {\n globalEmitter = new EventEmitter();\n }\n return globalEmitter;\n}\n","/**\n * AuroraView SDK Bridge Client\n *\n * Provides a type-safe wrapper around the native bridge API.\n */\n\nimport { EventEmitter, getGlobalEmitter } from './events';\nimport type {\n EventHandler,\n Unsubscribe,\n AuroraViewBridge,\n FileSystemAPI,\n DialogAPI,\n ClipboardAPI,\n ShellAPI,\n AuroraViewState,\n} from './types';\n\n/**\n * AuroraView client interface\n */\nexport interface AuroraViewClient {\n /** Call a Python method (RPC-style) */\n call<T = unknown>(method: string, params?: unknown): Promise<T>;\n\n /** Invoke a plugin command */\n invoke<T = unknown>(cmd: string, args?: Record<string, unknown>): Promise<T>;\n\n /** Send an event to Python (fire-and-forget) */\n emit(event: string, data?: unknown): void;\n\n /** Subscribe to an event from Python */\n on<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe;\n\n /** Subscribe to an event once */\n once<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe;\n\n /** Unsubscribe from an event */\n off(event: string, handler?: EventHandler): void;\n\n /** Check if bridge is ready */\n isReady(): boolean;\n\n /** Wait for bridge to be ready */\n whenReady(): Promise<AuroraViewClient>;\n\n /** Get the raw bridge object */\n getRawBridge(): AuroraViewBridge | undefined;\n\n /** File system API */\n readonly fs: FileSystemAPI | undefined;\n\n /** Dialog API */\n readonly dialog: DialogAPI | undefined;\n\n /** Clipboard API */\n readonly clipboard: ClipboardAPI | undefined;\n\n /** Shell API */\n readonly shell: ShellAPI | undefined;\n\n /** Shared state */\n readonly state: AuroraViewState | undefined;\n}\n\n/**\n * Internal client implementation\n */\nclass AuroraViewClientImpl implements AuroraViewClient {\n private events: EventEmitter;\n private interceptInstalled = false;\n\n constructor() {\n this.events = getGlobalEmitter();\n this.installTriggerIntercept();\n }\n\n /**\n * Install intercept on window.auroraview.trigger to forward events\n */\n private installTriggerIntercept(): void {\n if (this.interceptInstalled) return;\n if (typeof window === 'undefined') return;\n\n const install = () => {\n const bridge = window.auroraview;\n if (!bridge) return;\n\n const originalTrigger = bridge.trigger;\n bridge.trigger = (event: string, detail?: unknown) => {\n // Call original trigger first\n originalTrigger?.call(bridge, event, detail);\n // Forward to our event system\n this.events.emit(event, detail);\n };\n\n this.interceptInstalled = true;\n };\n\n // Try to install immediately\n if (window.auroraview) {\n install();\n } else {\n // Wait for bridge to be available\n const checkInterval = setInterval(() => {\n if (window.auroraview) {\n clearInterval(checkInterval);\n install();\n }\n }, 10);\n\n // Stop checking after 10 seconds\n setTimeout(() => clearInterval(checkInterval), 10000);\n }\n }\n\n call<T = unknown>(method: string, params?: unknown): Promise<T> {\n const bridge = window.auroraview;\n if (!bridge) {\n return Promise.reject(new Error('AuroraView bridge not available'));\n }\n return bridge.call<T>(method, params);\n }\n\n invoke<T = unknown>(cmd: string, args?: Record<string, unknown>): Promise<T> {\n const bridge = window.auroraview;\n if (!bridge) {\n return Promise.reject(new Error('AuroraView bridge not available'));\n }\n return bridge.invoke<T>(cmd, args);\n }\n\n emit(event: string, data?: unknown): void {\n const bridge = window.auroraview;\n if (bridge) {\n bridge.send_event(event, data);\n }\n }\n\n on<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe {\n return this.events.on(event, handler);\n }\n\n once<T = unknown>(event: string, handler: EventHandler<T>): Unsubscribe {\n return this.events.once(event, handler);\n }\n\n off(event: string, handler?: EventHandler): void {\n this.events.off(event, handler);\n }\n\n isReady(): boolean {\n return window.auroraview?._ready === true;\n }\n\n whenReady(): Promise<AuroraViewClient> {\n return new Promise((resolve) => {\n if (this.isReady()) {\n resolve(this);\n } else if (window.auroraview) {\n window.auroraview.whenReady().then(() => {\n this.installTriggerIntercept();\n resolve(this);\n });\n } else {\n // Wait for bridge to appear\n const checkInterval = setInterval(() => {\n if (window.auroraview) {\n clearInterval(checkInterval);\n window.auroraview.whenReady().then(() => {\n this.installTriggerIntercept();\n resolve(this);\n });\n }\n }, 10);\n\n // Timeout after 30 seconds\n setTimeout(() => {\n clearInterval(checkInterval);\n resolve(this);\n }, 30000);\n }\n });\n }\n\n getRawBridge(): AuroraViewBridge | undefined {\n return window.auroraview;\n }\n\n get fs(): FileSystemAPI | undefined {\n return window.auroraview?.fs;\n }\n\n get dialog(): DialogAPI | undefined {\n return window.auroraview?.dialog;\n }\n\n get clipboard(): ClipboardAPI | undefined {\n return window.auroraview?.clipboard;\n }\n\n get shell(): ShellAPI | undefined {\n return window.auroraview?.shell;\n }\n\n get state(): AuroraViewState | undefined {\n return window.auroraview?.state;\n }\n}\n\n/** Singleton client instance */\nlet clientInstance: AuroraViewClient | null = null;\n\n/**\n * Create or get the AuroraView client instance\n */\nexport function createAuroraView(): AuroraViewClient {\n if (!clientInstance) {\n clientInstance = new AuroraViewClientImpl();\n }\n return clientInstance;\n}\n\n/**\n * Get the AuroraView client instance (alias for createAuroraView)\n */\nexport function getAuroraView(): AuroraViewClient {\n return createAuroraView();\n}\n","/**\n * AuroraView SDK React Adapter\n *\n * Provides React hooks for the AuroraView bridge API.\n */\n\nimport { useEffect, useState, useRef, useCallback, useMemo } from 'react';\nimport { createAuroraView, type AuroraViewClient } from '../core/bridge';\nimport type {\n EventHandler,\n Unsubscribe,\n ProcessOutput,\n ProcessExit,\n} from '../core/types';\n\n/**\n * Hook to get the AuroraView client\n *\n * @example\n * ```tsx\n * function App() {\n * const { client, isReady } = useAuroraView();\n *\n * const handleClick = async () => {\n * const result = await client.call('api.echo', { message: 'Hello' });\n * console.log(result);\n * };\n *\n * return <button onClick={handleClick} disabled={!isReady}>Call API</button>;\n * }\n * ```\n */\nexport function useAuroraView(): {\n client: AuroraViewClient;\n isReady: boolean;\n} {\n const [isReady, setIsReady] = useState(false);\n const client = useMemo(() => createAuroraView(), []);\n\n useEffect(() => {\n // Check initial state\n if (client.isReady()) {\n setIsReady(true);\n } else {\n client.whenReady().then(() => setIsReady(true));\n }\n }, [client]);\n\n return { client, isReady };\n}\n\n/**\n * Hook to subscribe to an event\n *\n * @param event - Event name to subscribe to\n * @param handler - Event handler function\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * useAuroraEvent('custom:event', (data) => {\n * console.log('Received:', data);\n * });\n *\n * return <div>Listening for events...</div>;\n * }\n * ```\n */\nexport function useAuroraEvent<T = unknown>(\n event: string,\n handler: EventHandler<T>\n): void {\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n\n useEffect(() => {\n const client = createAuroraView();\n\n const unsubscribe = client.on<T>(event, (data) => {\n handlerRef.current(data);\n });\n\n return unsubscribe;\n }, [event]);\n}\n\n/**\n * Hook to subscribe to multiple events\n *\n * @param events - Map of event names to handlers\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * useAuroraEvents({\n * 'user:login': (data) => console.log('Login:', data),\n * 'user:logout': () => console.log('Logged out'),\n * });\n *\n * return <div>Listening...</div>;\n * }\n * ```\n */\nexport function useAuroraEvents(\n events: Record<string, EventHandler>\n): void {\n const eventsRef = useRef(events);\n eventsRef.current = events;\n\n useEffect(() => {\n const client = createAuroraView();\n const unsubscribers: Unsubscribe[] = [];\n\n Object.entries(eventsRef.current).forEach(([event]) => {\n const unsub = client.on(event, (data) => {\n eventsRef.current[event]?.(data);\n });\n unsubscribers.push(unsub);\n });\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n };\n }, [Object.keys(events).join(',')]);\n}\n\n/**\n * Options for useProcessEvents hook\n */\nexport interface ProcessEventsOptions {\n /** Handler for stdout data */\n onStdout?: (data: ProcessOutput) => void;\n /** Handler for stderr data */\n onStderr?: (data: ProcessOutput) => void;\n /** Handler for process exit */\n onExit?: (data: ProcessExit) => void;\n /** Filter by specific process ID */\n pid?: number;\n}\n\n/**\n * Hook to subscribe to process events\n *\n * @example\n * ```tsx\n * function ProcessMonitor() {\n * const [output, setOutput] = useState<string[]>([]);\n *\n * useProcessEvents({\n * onStdout: (data) => setOutput(prev => [...prev, data.data]),\n * onStderr: (data) => setOutput(prev => [...prev, `[ERR] ${data.data}`]),\n * onExit: (data) => console.log(`Process ${data.pid} exited with code ${data.code}`),\n * });\n *\n * return <pre>{output.join('')}</pre>;\n * }\n * ```\n */\nexport function useProcessEvents(options: ProcessEventsOptions = {}): void {\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n const client = createAuroraView();\n const unsubscribers: Unsubscribe[] = [];\n\n if (optionsRef.current.onStdout) {\n const unsub = client.on<ProcessOutput>('process:stdout', (data) => {\n if (\n optionsRef.current.pid === undefined ||\n optionsRef.current.pid === data.pid\n ) {\n optionsRef.current.onStdout?.(data);\n }\n });\n unsubscribers.push(unsub);\n }\n\n if (optionsRef.current.onStderr) {\n const unsub = client.on<ProcessOutput>('process:stderr', (data) => {\n if (\n optionsRef.current.pid === undefined ||\n optionsRef.current.pid === data.pid\n ) {\n optionsRef.current.onStderr?.(data);\n }\n });\n unsubscribers.push(unsub);\n }\n\n if (optionsRef.current.onExit) {\n const unsub = client.on<ProcessExit>('process:exit', (data) => {\n if (\n optionsRef.current.pid === undefined ||\n optionsRef.current.pid === data.pid\n ) {\n optionsRef.current.onExit?.(data);\n }\n });\n unsubscribers.push(unsub);\n }\n\n return () => {\n unsubscribers.forEach((unsub) => unsub());\n };\n }, []);\n}\n\n/**\n * Hook to call an API method\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { execute, loading, error, data } = useAuroraCall<string>('api.greet');\n *\n * return (\n * <div>\n * <button onClick={() => execute({ name: 'World' })} disabled={loading}>\n * Greet\n * </button>\n * {error && <p>Error: {error.message}</p>}\n * {data && <p>Result: {data}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useAuroraCall<T = unknown>(method: string): {\n execute: (params?: unknown) => Promise<T>;\n loading: boolean;\n error: Error | null;\n data: T | null;\n reset: () => void;\n} {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<T | null>(null);\n\n const execute = useCallback(\n async (params?: unknown): Promise<T> => {\n const client = createAuroraView();\n setLoading(true);\n setError(null);\n\n try {\n const result = await client.call<T>(method, params);\n setData(result);\n return result;\n } catch (e) {\n const err = e instanceof Error ? e : new Error(String(e));\n setError(err);\n throw err;\n } finally {\n setLoading(false);\n }\n },\n [method]\n );\n\n const reset = useCallback(() => {\n setLoading(false);\n setError(null);\n setData(null);\n }, []);\n\n return { execute, loading, error, data, reset };\n}\n\n/**\n * Hook to invoke a plugin command\n *\n * @example\n * ```tsx\n * function FileReader() {\n * const { execute, loading, data } = useAuroraInvoke<string>('plugin:fs|read_file');\n *\n * return (\n * <div>\n * <button onClick={() => execute({ path: '/tmp/test.txt' })}>\n * Read File\n * </button>\n * {data && <pre>{data}</pre>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useAuroraInvoke<T = unknown>(cmd: string): {\n execute: (args?: Record<string, unknown>) => Promise<T>;\n loading: boolean;\n error: Error | null;\n data: T | null;\n reset: () => void;\n} {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<T | null>(null);\n\n const execute = useCallback(\n async (args?: Record<string, unknown>): Promise<T> => {\n const client = createAuroraView();\n setLoading(true);\n setError(null);\n\n try {\n const result = await client.invoke<T>(cmd, args);\n setData(result);\n return result;\n } catch (e) {\n const err = e instanceof Error ? e : new Error(String(e));\n setError(err);\n throw err;\n } finally {\n setLoading(false);\n }\n },\n [cmd]\n );\n\n const reset = useCallback(() => {\n setLoading(false);\n setError(null);\n setData(null);\n }, []);\n\n return { execute, loading, error, data, reset };\n}\n\n/**\n * Hook to access shared state\n *\n * @example\n * ```tsx\n * function ThemeToggle() {\n * const [theme, setTheme] = useAuroraState<string>('theme', 'light');\n *\n * return (\n * <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>\n * Current: {theme}\n * </button>\n * );\n * }\n * ```\n */\nexport function useAuroraState<T>(\n key: string,\n defaultValue?: T\n): [T | undefined, (value: T) => void] {\n const client = useMemo(() => createAuroraView(), []);\n const [value, setValue] = useState<T | undefined>(() => {\n const state = client.state;\n return state ? (state[key] as T) ?? defaultValue : defaultValue;\n });\n\n useEffect(() => {\n const state = client.state;\n if (!state) return;\n\n // Initial value\n if (state[key] !== undefined) {\n setValue(state[key] as T);\n }\n\n // Subscribe to changes\n const unsubscribe = state.onChange((changedKey: string, newValue: unknown) => {\n if (changedKey === key) {\n setValue(newValue as T);\n }\n });\n\n return unsubscribe;\n }, [client, key]);\n\n const setStateValue = useCallback(\n (newValue: T) => {\n const state = client.state;\n if (state) {\n state[key] = newValue;\n }\n setValue(newValue);\n },\n [client, key]\n );\n\n return [value, setStateValue];\n}\n\n// Re-export types for convenience\nexport type { ProcessOutput, ProcessExit } from '../core/types';\nexport type { AuroraViewClient } from '../core/bridge';\n"]}
|