@pulse-editor/react-api 0.1.1-beta.2 → 0.1.1-beta.56

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 (44) hide show
  1. package/dist/hooks/agent/use-agent-tools.d.ts +6 -0
  2. package/dist/hooks/agent/use-agents.d.ts +5 -0
  3. package/dist/hooks/ai-modality/use-image-gen.d.ts +8 -0
  4. package/dist/hooks/ai-modality/use-llm.d.ts +5 -0
  5. package/dist/hooks/ai-modality/use-ocr.d.ts +3 -0
  6. package/dist/hooks/ai-modality/use-speech2speech.d.ts +10 -0
  7. package/dist/hooks/ai-modality/use-stt.d.ts +5 -0
  8. package/dist/hooks/ai-modality/use-tts.d.ts +5 -0
  9. package/dist/hooks/ai-modality/use-video-gen.d.ts +8 -0
  10. package/dist/hooks/editor/use-env.d.ts +4 -0
  11. package/dist/hooks/editor/use-file.d.ts +4 -0
  12. package/dist/hooks/editor/use-loading.d.ts +4 -0
  13. package/dist/hooks/editor/use-mic.d.ts +4 -0
  14. package/dist/hooks/{use-notification.d.ts → editor/use-notification.d.ts} +1 -1
  15. package/dist/hooks/editor/use-owned-app-view.d.ts +4 -0
  16. package/dist/hooks/editor/use-receive-file.d.ts +3 -0
  17. package/dist/hooks/editor/use-register-action.d.ts +24 -0
  18. package/dist/hooks/editor/use-snapshot-state.d.ts +1 -0
  19. package/dist/hooks/editor/use-theme.d.ts +3 -0
  20. package/dist/hooks/editor/use-workspace.d.ts +3 -0
  21. package/dist/hooks/imc/use-imc.d.ts +5 -0
  22. package/dist/hooks/terminal/use-terminal.d.ts +4 -0
  23. package/dist/main.d.ts +22 -7
  24. package/dist/main.js +709 -1
  25. package/dist/main.js.map +1 -0
  26. package/dist/providers/receive-file-provider.d.ts +8 -0
  27. package/dist/providers/snapshot-provider.d.ts +13 -0
  28. package/package.json +9 -7
  29. package/dist/hooks/use-agent-tools.d.ts +0 -4
  30. package/dist/hooks/use-agents.d.ts +0 -6
  31. package/dist/hooks/use-agents.js +0 -1
  32. package/dist/hooks/use-fetch.d.ts +0 -3
  33. package/dist/hooks/use-file-view.d.ts +0 -6
  34. package/dist/hooks/use-file-view.js +0 -1
  35. package/dist/hooks/use-notification.js +0 -1
  36. package/dist/hooks/use-orc.d.ts +0 -3
  37. package/dist/hooks/use-orc.js +0 -1
  38. package/dist/hooks/use-terminal.d.ts +0 -3
  39. package/dist/hooks/use-terminal.js +0 -1
  40. package/dist/hooks/use-theme.d.ts +0 -3
  41. package/dist/hooks/use-theme.js +0 -1
  42. package/dist/lib/hooks/use-imc.d.ts +0 -6
  43. package/dist/lib/hooks/use-imc.js +0 -1
  44. package/dist/main.es.js +0 -1
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Add or use agent tools in the editor.
3
+ * @param moduleName
4
+ * @returns
5
+ */
6
+ export default function useAgentTools(): {};
@@ -0,0 +1,5 @@
1
+ import { LLMConfig } from "@pulse-editor/shared-utils";
2
+ export default function useAgents(): {
3
+ runAgentMethod: (agentName: string, methodName: string, args: Record<string, any>, abortSignal?: AbortSignal, llmConfig?: LLMConfig) => Promise<any>;
4
+ isReady: boolean;
5
+ };
@@ -0,0 +1,8 @@
1
+ import { ImageModelConfig } from "@pulse-editor/shared-utils";
2
+ export default function useImageGen(): {
3
+ runImageGen: (textPrompt?: string, imagePrompt?: string | ArrayBuffer, imageModelConfig?: ImageModelConfig) => Promise<{
4
+ arrayBuffer?: ArrayBuffer;
5
+ url?: string;
6
+ }>;
7
+ isReady: boolean;
8
+ };
@@ -0,0 +1,5 @@
1
+ import { LLMConfig } from "@pulse-editor/shared-utils";
2
+ export default function useLLM(): {
3
+ runLLM: (prompt: string, llmConfig?: LLMConfig) => Promise<string>;
4
+ isReady: boolean;
5
+ };
@@ -0,0 +1,3 @@
1
+ export default function useOCR(): {
2
+ recognizeText: (image: string) => Promise<string>;
3
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Use speech-to-speech API to listen to user input and read the output
3
+ * provided by you.
4
+ */
5
+ export default function useSpeech2Speech(): {
6
+ isReady: boolean;
7
+ userInput: string;
8
+ isUserStopped: boolean;
9
+ respondAndRead: (text: string) => Promise<void>;
10
+ };
@@ -0,0 +1,5 @@
1
+ import { STTConfig } from "@pulse-editor/shared-utils";
2
+ export default function useSTT(): {
3
+ runSTT: (audio: Uint8Array, sttConfig?: STTConfig) => Promise<string>;
4
+ isReady: boolean;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { TTSConfig } from "@pulse-editor/shared-utils";
2
+ export default function useTTS(): {
3
+ runTTS: (text: string, ttsConfig?: TTSConfig) => Promise<Uint8Array>;
4
+ isReady: boolean;
5
+ };
@@ -0,0 +1,8 @@
1
+ import { VideoModelConfig } from "@pulse-editor/shared-utils";
2
+ export default function useVideoGen(): {
3
+ runVideoGen: (duration: number, textPrompt?: string, imagePrompt?: string | ArrayBuffer, videoModelConfig?: VideoModelConfig) => Promise<{
4
+ url?: string;
5
+ arrayBuffer?: ArrayBuffer;
6
+ }>;
7
+ isReady: boolean;
8
+ };
@@ -0,0 +1,4 @@
1
+ export default function usePulseEnv(): {
2
+ isReady: boolean;
3
+ envs: Record<string, string>;
4
+ };
@@ -0,0 +1,4 @@
1
+ export default function useFile(uri: string | undefined): {
2
+ file: File | undefined;
3
+ saveFile: (fileContent: string) => void;
4
+ };
@@ -0,0 +1,4 @@
1
+ export default function useLoading(): {
2
+ isReady: boolean;
3
+ toggleLoading: (isLoading: boolean) => void;
4
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Use the microphone to record audio. (WIP)
3
+ */
4
+ export default function useMic(): void;
@@ -1,4 +1,4 @@
1
1
  import { NotificationTypeEnum } from "@pulse-editor/shared-utils";
2
- export default function useNotification(moduleName: string): {
2
+ export default function useNotification(): {
3
3
  openNotification: (text: string, type: NotificationTypeEnum) => void;
4
4
  };
@@ -0,0 +1,4 @@
1
+ import { ViewModel } from "@pulse-editor/shared-utils";
2
+ export default function useOwnedAppView(): {
3
+ runAppAction: (ownedAppViewModel: ViewModel, actionName: string, args: any) => Promise<any>;
4
+ };
@@ -0,0 +1,3 @@
1
+ export default function useReceiveFile(): {
2
+ receivedFileUri: string | undefined;
3
+ };
@@ -0,0 +1,24 @@
1
+ import { TypedVariable } from "@pulse-editor/shared-utils";
2
+ import { DependencyList } from "react";
3
+ /**
4
+ * Register an app action to listen to IMC messages from the core,
5
+ * and pass to the action to handle.
6
+ *
7
+ * @param name Name of the command.
8
+ * @param description Description of the command.
9
+ * @param parameters Parameters of the command.
10
+ * @param returns Return values of the command.
11
+ * @param callbackHandler Callback handler function to handle the command.
12
+ * @param deps Dependency list to re-register the action when changed.
13
+ * @param isExtReady Whether the extension is ready to receive commands.
14
+ * Useful for actions that need to wait for some certain app state to be ready.
15
+ *
16
+ */
17
+ export default function useRegisterAction(actionInfo: {
18
+ name: string;
19
+ description: string;
20
+ parameters?: Record<string, TypedVariable>;
21
+ returns?: Record<string, TypedVariable>;
22
+ }, callbackHandler: (args: any) => Promise<any>, deps: DependencyList, isExtReady?: boolean): {
23
+ isReady: boolean;
24
+ };
@@ -0,0 +1 @@
1
+ export default function useSnapShotState<T>(key: string, initialValue?: T, onRestore?: (value: T) => void): readonly [T, import("react").Dispatch<import("react").SetStateAction<T>>];
@@ -0,0 +1,3 @@
1
+ export default function useTheme(): {
2
+ theme: string;
3
+ };
@@ -0,0 +1,3 @@
1
+ export default function useWorkspace(): {
2
+ workspaceId: string | undefined;
3
+ };
@@ -0,0 +1,5 @@
1
+ import { InterModuleCommunication, ReceiverHandlerMap } from "@pulse-editor/shared-utils";
2
+ export default function useIMC(handlerMap: ReceiverHandlerMap, intent: string): {
3
+ imc: InterModuleCommunication | undefined;
4
+ isReady: boolean;
5
+ };
@@ -0,0 +1,4 @@
1
+ export default function useTerminal(): {
2
+ websocketUrl: string | undefined;
3
+ projectHomePath: string | undefined;
4
+ };
package/dist/main.d.ts CHANGED
@@ -1,7 +1,22 @@
1
- import useFileView from "./hooks/use-file-view";
2
- import useTheme from "./hooks/use-theme";
3
- import useNotification from "./hooks/use-notification";
4
- import useAgents from "./hooks/use-agents";
5
- import useOCR from "./hooks/use-orc";
6
- import useTerminal from "./hooks/use-terminal";
7
- export { useFileView, useTheme, useNotification, useAgents, useOCR, useTerminal, };
1
+ import useAgentTools from "./hooks/agent/use-agent-tools";
2
+ import useAgents from "./hooks/agent/use-agents";
3
+ import useFile from "./hooks/editor/use-file";
4
+ import useLoading from "./hooks/editor/use-loading";
5
+ import useNotification from "./hooks/editor/use-notification";
6
+ import useRegisterAction from "./hooks/editor/use-register-action";
7
+ import useTheme from "./hooks/editor/use-theme";
8
+ import useImageGen from "./hooks/ai-modality/use-image-gen";
9
+ import useLLM from "./hooks/ai-modality/use-llm";
10
+ import useOCR from "./hooks/ai-modality/use-ocr";
11
+ import useSTT from "./hooks/ai-modality/use-stt";
12
+ import useTTS from "./hooks/ai-modality/use-tts";
13
+ import useVideoGen from "./hooks/ai-modality/use-video-gen";
14
+ import usePulseEnv from "./hooks/editor/use-env";
15
+ import useOwnedAppView from "./hooks/editor/use-owned-app-view";
16
+ import useReceiveFile from "./hooks/editor/use-receive-file";
17
+ import useSnapshotState from "./hooks/editor/use-snapshot-state";
18
+ import useWorkspace from "./hooks/editor/use-workspace";
19
+ import useTerminal from "./hooks/terminal/use-terminal";
20
+ import ReceiveFileProvider from "./providers/receive-file-provider";
21
+ import SnapshotProvider from "./providers/snapshot-provider";
22
+ export { ReceiveFileProvider, SnapshotProvider, useAgentTools, useAgents, useFile, useImageGen, useLLM, useLoading, useNotification, useOCR, useOwnedAppView, usePulseEnv, useReceiveFile, useRegisterAction, useSTT, useSnapshotState, useTTS, useTerminal, useTheme, useVideoGen, useWorkspace, };
package/dist/main.js CHANGED
@@ -1 +1,709 @@
1
- export{default as useFileView}from"./hooks/use-file-view.js";export{default as useTheme}from"./hooks/use-theme.js";export{default as useNotification}from"./hooks/use-notification.js";export{default as useAgents}from"./hooks/use-agents.js";export{default as useOCR}from"./hooks/use-orc.js";export{default as useTerminal}from"./hooks/use-terminal.js";
1
+ import { InterModuleCommunication, IMCMessageTypeEnum } from '@pulse-editor/shared-utils';
2
+ import React, { useState, useEffect, useCallback, useRef, createContext, useContext } from 'react';
3
+
4
+ var byteToHex = [];
5
+ for (var i = 0; i < 256; ++i) {
6
+ byteToHex.push((i + 0x100).toString(16).slice(1));
7
+ }
8
+ function unsafeStringify(arr) {
9
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
10
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
11
+ }
12
+
13
+ var getRandomValues;
14
+ var rnds8 = new Uint8Array(16);
15
+ function rng() {
16
+ if (!getRandomValues) {
17
+ if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
18
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
19
+ }
20
+ getRandomValues = crypto.getRandomValues.bind(crypto);
21
+ }
22
+ return getRandomValues(rnds8);
23
+ }
24
+
25
+ var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
26
+ var _native = {
27
+ randomUUID: randomUUID
28
+ };
29
+
30
+ function _v4(options, buf, offset) {
31
+ var _ref, _options$random, _options$rng, _options;
32
+ options = options || {};
33
+ var rnds = (_ref = (_options$random = options.random) !== null && _options$random !== void 0 ? _options$random : (_options$rng = (_options = options).rng) === null || _options$rng === void 0 ? void 0 : _options$rng.call(_options)) !== null && _ref !== void 0 ? _ref : rng();
34
+ if (rnds.length < 16) {
35
+ throw new Error('Random bytes length must be >= 16');
36
+ }
37
+ rnds[6] = rnds[6] & 0x0f | 0x40;
38
+ rnds[8] = rnds[8] & 0x3f | 0x80;
39
+ return unsafeStringify(rnds);
40
+ }
41
+ function v4(options, buf, offset) {
42
+ if (_native.randomUUID && true && !options) {
43
+ return _native.randomUUID();
44
+ }
45
+ return _v4(options);
46
+ }
47
+
48
+ function useIMC(handlerMap, intent) {
49
+ const [imc, setImc] = useState(undefined);
50
+ const [isReady, setIsReady] = useState(false);
51
+ const [isMounted, setIsMounted] = useState(false);
52
+ const targetWindow = window.parent;
53
+ useEffect(() => {
54
+ setIsMounted(true);
55
+ return () => {
56
+ setIsMounted(false);
57
+ imc?.close();
58
+ setImc(undefined);
59
+ };
60
+ }, []);
61
+ useEffect(() => {
62
+ async function initIMC() {
63
+ if (!isMounted)
64
+ return;
65
+ else if (imc !== undefined)
66
+ return;
67
+ const newImc = new InterModuleCommunication(intent, v4());
68
+ newImc.initThisWindow(window);
69
+ newImc.updateReceiverHandlerMap(handlerMap);
70
+ await newImc.initOtherWindow(targetWindow);
71
+ setImc(newImc);
72
+ await newImc.sendMessage(IMCMessageTypeEnum.AppReady, {
73
+ intent,
74
+ channelId: newImc.channelId,
75
+ });
76
+ setIsReady(true);
77
+ }
78
+ initIMC();
79
+ }, [isMounted, imc]);
80
+ return {
81
+ imc,
82
+ isReady,
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Add or use agent tools in the editor.
88
+ * @param moduleName
89
+ * @returns
90
+ */
91
+ function useAgentTools() {
92
+ const receiverHandlerMap = new Map();
93
+ useIMC(receiverHandlerMap, "agent-tools");
94
+ return {};
95
+ }
96
+
97
+ function useAgents() {
98
+ const receiverHandlerMap = new Map();
99
+ const { imc, isReady } = useIMC(receiverHandlerMap, "agents");
100
+ async function runAgentMethod(agentName, methodName, args, abortSignal, llmConfig) {
101
+ if (!imc) {
102
+ throw new Error("IMC not initialized.");
103
+ }
104
+ const result = await imc
105
+ .sendMessage(IMCMessageTypeEnum.EditorRunAgentMethod, {
106
+ agentName,
107
+ methodName,
108
+ args,
109
+ llmConfig,
110
+ }, abortSignal)
111
+ .then((response) => {
112
+ return response;
113
+ });
114
+ return result;
115
+ }
116
+ return {
117
+ runAgentMethod,
118
+ isReady,
119
+ };
120
+ }
121
+
122
+ function useFile(uri) {
123
+ const [file, setFile] = useState(undefined);
124
+ const receiverHandlerMap = new Map([
125
+ [
126
+ IMCMessageTypeEnum.PlatformFileUpdate,
127
+ async (senderWindow, message) => {
128
+ const updatedFile = message.payload;
129
+ setFile(updatedFile);
130
+ },
131
+ ],
132
+ ]);
133
+ const { imc, isReady } = useIMC(receiverHandlerMap, "file");
134
+ const saveFile = useCallback((fileContent) => {
135
+ if (!uri)
136
+ return;
137
+ else if (!file)
138
+ return;
139
+ // Update file content
140
+ const newFile = new File([fileContent], file.name, {
141
+ type: file.type,
142
+ lastModified: Date.now(),
143
+ });
144
+ setFile(newFile);
145
+ if (isReady && uri) {
146
+ imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {
147
+ uri,
148
+ file: newFile,
149
+ });
150
+ }
151
+ }, [uri, file, isReady]);
152
+ // Read file when uri changes
153
+ useEffect(() => {
154
+ if (isReady && uri) {
155
+ imc
156
+ ?.sendMessage(IMCMessageTypeEnum.PlatformReadFile, {
157
+ uri,
158
+ })
159
+ .then((f) => {
160
+ setFile(f);
161
+ });
162
+ }
163
+ }, [isReady, uri]);
164
+ return {
165
+ file,
166
+ saveFile,
167
+ };
168
+ }
169
+
170
+ function useLoading() {
171
+ const receiverHandlerMap = new Map();
172
+ const { imc, isReady } = useIMC(receiverHandlerMap, "loading");
173
+ const [isLoading, setIsLoading] = useState(true);
174
+ useEffect(() => {
175
+ if (isReady) {
176
+ imc?.sendMessage(IMCMessageTypeEnum.EditorLoadingApp, {
177
+ isLoading,
178
+ });
179
+ }
180
+ }, [isLoading]);
181
+ function toggleLoading(isLoading) {
182
+ setIsLoading((prev) => isLoading);
183
+ }
184
+ return {
185
+ isReady,
186
+ toggleLoading,
187
+ };
188
+ }
189
+
190
+ function useNotification() {
191
+ const receiverHandlerMap = new Map();
192
+ const { imc } = useIMC(receiverHandlerMap, "notification");
193
+ function openNotification(text, type) {
194
+ if (!imc) {
195
+ throw new Error("IMC is not initialized.");
196
+ }
197
+ imc.sendMessage(IMCMessageTypeEnum.EditorShowNotification, {
198
+ text,
199
+ type,
200
+ });
201
+ }
202
+ return { openNotification };
203
+ }
204
+
205
+ /**
206
+ * Register an app action to listen to IMC messages from the core,
207
+ * and pass to the action to handle.
208
+ *
209
+ * @param name Name of the command.
210
+ * @param description Description of the command.
211
+ * @param parameters Parameters of the command.
212
+ * @param returns Return values of the command.
213
+ * @param callbackHandler Callback handler function to handle the command.
214
+ * @param deps Dependency list to re-register the action when changed.
215
+ * @param isExtReady Whether the extension is ready to receive commands.
216
+ * Useful for actions that need to wait for some certain app state to be ready.
217
+ *
218
+ */
219
+ function useRegisterAction(actionInfo, callbackHandler, deps, isExtReady = true) {
220
+ const { isReady, imc } = useIMC(getReceiverHandlerMap(), "register-action");
221
+ // Queue to hold commands until extension is ready
222
+ const commandQueue = useRef([]);
223
+ const isCommandExecuting = useRef(false);
224
+ const [action, setAction] = useState({
225
+ name: actionInfo.name,
226
+ description: actionInfo.description,
227
+ parameters: actionInfo.parameters ?? {},
228
+ returns: actionInfo.returns ?? {},
229
+ handler: callbackHandler,
230
+ });
231
+ // Flush queued commands when isExtReady becomes true
232
+ useEffect(() => {
233
+ async function runQueuedCommands() {
234
+ const pendingCMDs = [...commandQueue.current];
235
+ commandQueue.current = [];
236
+ for (const cmd of pendingCMDs) {
237
+ const { args, resolve } = cmd;
238
+ if (isCommandExecuting.current) {
239
+ return;
240
+ }
241
+ isCommandExecuting.current = true;
242
+ const res = await executeAction(args);
243
+ isCommandExecuting.current = false;
244
+ resolve(res);
245
+ }
246
+ }
247
+ if (isExtReady && commandQueue.current.length > 0) {
248
+ runQueuedCommands();
249
+ }
250
+ }, [isExtReady]);
251
+ useEffect(() => {
252
+ async function updateAction() {
253
+ // Register or update action.
254
+ // This will only pass signature info to the editor.
255
+ // The actual handler is stored in this hook,
256
+ // so the execution happens inside the extension app.
257
+ await imc?.sendMessage(IMCMessageTypeEnum.EditorRegisterAction, {
258
+ name: action.name,
259
+ description: action.description,
260
+ parameters: action.parameters,
261
+ returns: action.returns,
262
+ });
263
+ // Update receiver
264
+ imc?.updateReceiverHandlerMap(getReceiverHandlerMap());
265
+ }
266
+ if (isExtReady) {
267
+ updateAction();
268
+ }
269
+ }, [action, imc, isExtReady]);
270
+ useEffect(() => {
271
+ setAction((prev) => ({
272
+ ...prev,
273
+ name: actionInfo.name,
274
+ description: actionInfo.description,
275
+ parameters: actionInfo.parameters ?? {},
276
+ returns: actionInfo.returns ?? {},
277
+ handler: callbackHandler,
278
+ }));
279
+ }, [...deps]);
280
+ async function executeAction(args) {
281
+ if (!action.handler)
282
+ return;
283
+ const res = await action.handler(args);
284
+ return res;
285
+ }
286
+ function getReceiverHandlerMap() {
287
+ const receiverHandlerMap = new Map([
288
+ [
289
+ IMCMessageTypeEnum.EditorRunAppAction,
290
+ async (_senderWindow, message) => {
291
+ const { name: requestedName, args } = message.payload;
292
+ if (actionInfo.name !== requestedName) {
293
+ throw new Error("Message ignored by receiver");
294
+ }
295
+ // Validate parameters
296
+ const actionParams = actionInfo.parameters ?? {};
297
+ if (Object.keys(args).length !== Object.keys(actionParams).length) {
298
+ throw new Error(`Invalid number of parameters: expected ${Object.keys(actionParams).length}, got ${Object.keys(args).length}`);
299
+ }
300
+ // Check types
301
+ for (const [key, value] of Object.entries(args)) {
302
+ if (actionParams[key] === undefined) {
303
+ throw new Error(`Invalid parameter: ${key}`);
304
+ }
305
+ if (typeof value !== actionParams[key].type &&
306
+ // Allow object for "app-instance"
307
+ (actionParams[key].type !== "app-instance" ||
308
+ typeof value !== "object")) {
309
+ throw new Error(`Invalid type for parameter ${key}: expected ${actionParams[key].type}, got ${typeof value}. Value received: ${value}`);
310
+ }
311
+ }
312
+ // If extension is ready, execute immediately
313
+ if (isExtReady) {
314
+ const result = await executeAction(args);
315
+ return result;
316
+ }
317
+ // Otherwise, queue the command and return when executed
318
+ return new Promise((resolve) => {
319
+ commandQueue.current.push({ args, resolve });
320
+ });
321
+ },
322
+ ],
323
+ ]);
324
+ return receiverHandlerMap;
325
+ }
326
+ return {
327
+ isReady,
328
+ };
329
+ }
330
+
331
+ function useTheme() {
332
+ const [theme, setTheme] = useState("light");
333
+ const receiverHandlerMap = new Map();
334
+ receiverHandlerMap.set(IMCMessageTypeEnum.EditorThemeUpdate, async (senderWindow, message) => {
335
+ const theme = message.payload;
336
+ setTheme((prev) => theme);
337
+ });
338
+ const { imc, isReady } = useIMC(receiverHandlerMap, "theme");
339
+ // Upon initial load, request theme from main app
340
+ useEffect(() => {
341
+ if (isReady) {
342
+ imc
343
+ ?.sendMessage(IMCMessageTypeEnum.EditorAppRequestTheme)
344
+ .then((result) => {
345
+ setTheme((prev) => result);
346
+ });
347
+ }
348
+ }, [isReady]);
349
+ return {
350
+ theme,
351
+ };
352
+ }
353
+
354
+ function useImageGen() {
355
+ const receiverHandlerMap = new Map();
356
+ const { imc, isReady } = useIMC(receiverHandlerMap, "image-gen");
357
+ /**
358
+ *
359
+ * @param textPrompt The text prompt to generate the image.
360
+ * @param imagePrompt A URL to an image or an image in an ArrayBuffer.
361
+ * @param imageModelConfig (optional) The image model config to use.
362
+ * @returns The generated image in an ArrayBuffer.
363
+ */
364
+ async function runImageGen(textPrompt, imagePrompt,
365
+ // LLM config is optional, if not provided, the default config will be used.
366
+ imageModelConfig) {
367
+ if (!imc) {
368
+ throw new Error("IMC not initialized.");
369
+ }
370
+ if (!textPrompt && !imagePrompt) {
371
+ throw new Error("At least one of textPrompt or imagePrompt is required.");
372
+ }
373
+ const result = await imc
374
+ .sendMessage(IMCMessageTypeEnum.ModalityImageGen, {
375
+ textPrompt,
376
+ imagePrompt,
377
+ imageModelConfig,
378
+ })
379
+ .then((response) => {
380
+ return response;
381
+ });
382
+ return result;
383
+ }
384
+ return {
385
+ runImageGen,
386
+ isReady,
387
+ };
388
+ }
389
+
390
+ function useLLM() {
391
+ const receiverHandlerMap = new Map();
392
+ const { imc, isReady } = useIMC(receiverHandlerMap, "llm");
393
+ async function runLLM(prompt,
394
+ // LLM config is optional, if not provided, the default config will be used.
395
+ llmConfig) {
396
+ if (!imc) {
397
+ throw new Error("IMC not initialized.");
398
+ }
399
+ const result = await imc
400
+ .sendMessage(IMCMessageTypeEnum.ModalityLLM, {
401
+ prompt,
402
+ llmConfig,
403
+ })
404
+ .then((response) => {
405
+ return response;
406
+ });
407
+ return result;
408
+ }
409
+ return {
410
+ runLLM,
411
+ isReady,
412
+ };
413
+ }
414
+
415
+ function useOCR() {
416
+ const receiverHandlerMap = new Map();
417
+ const { imc } = useIMC(receiverHandlerMap, "ocr");
418
+ /**
419
+ *
420
+ * @param image The image to be recognized. This is a base64 encoded string.
421
+ * @returns
422
+ */
423
+ async function recognizeText(image) {
424
+ if (!imc) {
425
+ throw new Error("IMC is not initialized.");
426
+ }
427
+ // Send the message to the extension
428
+ const result = await imc.sendMessage(IMCMessageTypeEnum.ModalityOCR, { image });
429
+ return result.payload.text;
430
+ }
431
+ return {
432
+ recognizeText,
433
+ };
434
+ }
435
+
436
+ function useSTT() {
437
+ const receiverHandlerMap = new Map();
438
+ const { imc, isReady } = useIMC(receiverHandlerMap, "stt");
439
+ async function runSTT(audio,
440
+ // Config is optional, if not provided, the default config will be used.
441
+ sttConfig) {
442
+ if (!imc) {
443
+ throw new Error("IMC not initialized.");
444
+ }
445
+ const result = await imc
446
+ .sendMessage(IMCMessageTypeEnum.ModalitySTT, {
447
+ audio,
448
+ sttConfig,
449
+ })
450
+ .then((response) => {
451
+ return response;
452
+ });
453
+ return result;
454
+ }
455
+ return {
456
+ runSTT,
457
+ isReady,
458
+ };
459
+ }
460
+
461
+ function useTTS() {
462
+ const receiverHandlerMap = new Map();
463
+ const { imc, isReady } = useIMC(receiverHandlerMap, "tts");
464
+ async function runTTS(text,
465
+ // Config is optional, if not provided, the default config will be used.
466
+ ttsConfig) {
467
+ if (!imc) {
468
+ throw new Error("IMC not initialized.");
469
+ }
470
+ const result = await imc
471
+ .sendMessage(IMCMessageTypeEnum.ModalityTTS, {
472
+ text,
473
+ ttsConfig,
474
+ })
475
+ .then((response) => {
476
+ return response;
477
+ });
478
+ return result;
479
+ }
480
+ return {
481
+ runTTS,
482
+ isReady,
483
+ };
484
+ }
485
+
486
+ function useVideoGen() {
487
+ const receiverHandlerMap = new Map();
488
+ const { imc, isReady } = useIMC(receiverHandlerMap, "video-gen");
489
+ /**
490
+ *
491
+ * @param textPrompt The text prompt to generate the video.
492
+ * @param imagePrompt A URL to an image or an image in an ArrayBuffer.
493
+ * @param videoModelConfig (optional) The video model config to use.
494
+ * @returns The generated video in an ArrayBuffer.
495
+ */
496
+ async function runVideoGen(duration, textPrompt, imagePrompt,
497
+ // LLM config is optional, if not provided, the default config will be used.
498
+ videoModelConfig) {
499
+ if (!imc) {
500
+ throw new Error("IMC not initialized.");
501
+ }
502
+ if (!textPrompt && !imagePrompt) {
503
+ throw new Error("At least one of textPrompt or imagePrompt is required.");
504
+ }
505
+ const result = await imc
506
+ .sendMessage(IMCMessageTypeEnum.ModalityVideoGen, {
507
+ duration,
508
+ textPrompt,
509
+ imagePrompt,
510
+ videoModelConfig,
511
+ })
512
+ .then((response) => {
513
+ return response;
514
+ });
515
+ return result;
516
+ }
517
+ return {
518
+ runVideoGen,
519
+ isReady,
520
+ };
521
+ }
522
+
523
+ function usePulseEnv() {
524
+ const receiverHandlerMap = new Map();
525
+ const { imc, isReady } = useIMC(receiverHandlerMap, "env");
526
+ const [envs, setEnvs] = useState({});
527
+ useEffect(() => {
528
+ if (isReady) {
529
+ imc?.sendMessage(IMCMessageTypeEnum.EditorGetEnv).then((env) => {
530
+ setEnvs(env);
531
+ });
532
+ }
533
+ }, [isReady]);
534
+ return {
535
+ isReady,
536
+ envs,
537
+ };
538
+ }
539
+
540
+ function useOwnedAppView() {
541
+ const receiverHandlerMap = new Map([]);
542
+ const { imc, isReady } = useIMC(receiverHandlerMap, "owned-app");
543
+ const runAppAction = useCallback(async (ownedAppViewModel, actionName, args) => {
544
+ if (isReady) {
545
+ const appViewId = ownedAppViewModel.viewId;
546
+ const preRegisteredActions = ownedAppViewModel.appConfig.preRegisteredActions || [];
547
+ const action = preRegisteredActions.find((a) => a.name === actionName);
548
+ if (!action) {
549
+ throw new Error(`Action ${actionName} not found in owned app ${ownedAppViewModel.appConfig.id}`);
550
+ }
551
+ const result = await imc?.sendMessage(IMCMessageTypeEnum.EditorAppUseOwnedApp, {
552
+ viewId: appViewId,
553
+ actionName,
554
+ args,
555
+ });
556
+ return result;
557
+ }
558
+ return undefined;
559
+ }, [imc, isReady]);
560
+ return {
561
+ runAppAction,
562
+ };
563
+ }
564
+
565
+ const ReceiveFileContext = createContext(undefined);
566
+ function ReceiveFileProvider({ children, }) {
567
+ const [receivedFileUri, setReceivedFileUri] = useState(undefined);
568
+ const receiverHandlerMap = new Map([
569
+ [
570
+ IMCMessageTypeEnum.EditorAppReceiveFileUri,
571
+ async (senderWindow, message) => {
572
+ const { uri } = message.payload;
573
+ setReceivedFileUri((prev) => uri);
574
+ },
575
+ ],
576
+ ]);
577
+ useIMC(receiverHandlerMap, "receive-file-provider");
578
+ return (React.createElement(ReceiveFileContext.Provider, { value: { selectedFileUri: receivedFileUri } }, children));
579
+ }
580
+
581
+ function useReceiveFile() {
582
+ const context = useContext(ReceiveFileContext);
583
+ if (!context) {
584
+ throw new Error("useReceiveFile must be used within a ReceiveFileProvider");
585
+ }
586
+ return { receivedFileUri: context.selectedFileUri };
587
+ }
588
+
589
+ const SnapshotContext = createContext(undefined);
590
+ function SnapshotProvider({ children, }) {
591
+ const [states, setStates] = useState({});
592
+ const receiverHandlerMap = new Map([
593
+ [
594
+ IMCMessageTypeEnum.EditorAppStateSnapshotRestore,
595
+ async (senderWindow, message) => {
596
+ const { states } = message.payload;
597
+ // Update all states in the context
598
+ console.log("Restoring snapshot states:", states);
599
+ setStates((prev) => ({ ...states }));
600
+ },
601
+ ],
602
+ [
603
+ IMCMessageTypeEnum.EditorAppStateSnapshotSave,
604
+ async (senderWindow, message) => {
605
+ // Return current states in the context
606
+ return { states };
607
+ },
608
+ ],
609
+ ]);
610
+ const { imc, isReady } = useIMC(receiverHandlerMap, "snapshot-provider");
611
+ useEffect(() => {
612
+ if (isReady) {
613
+ imc?.updateReceiverHandlerMap(receiverHandlerMap);
614
+ }
615
+ }, [isReady, states]);
616
+ return (React.createElement(SnapshotContext.Provider, { value: { states, setStates } }, children));
617
+ }
618
+
619
+ function useSnapShotState(key, initialValue, onRestore) {
620
+ const snapshotContext = useContext(SnapshotContext);
621
+ if (!snapshotContext) {
622
+ throw new Error("useSnapShotState must be used within a SnapshotProvider");
623
+ }
624
+ const { states, setStates } = snapshotContext;
625
+ const [state, setState] = useState(states[key] !== undefined ? states[key] : initialValue);
626
+ const isLocalUpdate = useRef(false);
627
+ const setSnapshotState = (value) => {
628
+ setState((prev) => {
629
+ const newValue = typeof value === "function" ? value(prev) : value;
630
+ isLocalUpdate.current = true; // mark as local
631
+ Promise.resolve().then(() => {
632
+ setStates((prevStates) => ({
633
+ ...prevStates,
634
+ [key]: newValue,
635
+ }));
636
+ });
637
+ return newValue;
638
+ });
639
+ };
640
+ // Initialize context with initial value
641
+ useEffect(() => {
642
+ if (states[key] === undefined && initialValue !== undefined) {
643
+ setStates((prev) => ({
644
+ ...prev,
645
+ [key]: initialValue,
646
+ }));
647
+ }
648
+ }, []);
649
+ // Only restore when external changes occur
650
+ useEffect(() => {
651
+ const contextValue = states[key];
652
+ if (contextValue === undefined)
653
+ return;
654
+ if (isLocalUpdate.current) {
655
+ // skip this run because we caused it ourselves
656
+ isLocalUpdate.current = false;
657
+ return;
658
+ }
659
+ if (contextValue !== state) {
660
+ console.log("Restoring state for key:", key, contextValue);
661
+ setState(contextValue);
662
+ onRestore?.(contextValue);
663
+ }
664
+ }, [states[key]]);
665
+ return [state, setSnapshotState];
666
+ }
667
+
668
+ function useWorkspace() {
669
+ const [workspaceId, setWorkspaceId] = useState(undefined);
670
+ const receiverHandlerMap = new Map();
671
+ const { imc, isReady } = useIMC(receiverHandlerMap, "theme");
672
+ // Upon initial load, request theme from main app
673
+ useEffect(() => {
674
+ if (isReady) {
675
+ imc
676
+ ?.sendMessage(IMCMessageTypeEnum.EditorAppRequestWorkspace)
677
+ .then((result) => {
678
+ const { id } = result;
679
+ setWorkspaceId((prev) => id);
680
+ });
681
+ }
682
+ }, [isReady]);
683
+ return {
684
+ workspaceId,
685
+ };
686
+ }
687
+
688
+ function useTerminal() {
689
+ const receiverHandlerMap = new Map();
690
+ const { imc, isReady } = useIMC(receiverHandlerMap, "terminal");
691
+ const [websocketUrl, setWebsocketUrl] = useState(undefined);
692
+ const [projectHomePath, setProjectHomePath] = useState(undefined);
693
+ useEffect(() => {
694
+ if (isReady) {
695
+ imc?.sendMessage(IMCMessageTypeEnum.PlatformCreateTerminal).then((response) => {
696
+ const { websocketUrl, projectHomePath, } = response;
697
+ setWebsocketUrl(websocketUrl);
698
+ setProjectHomePath(projectHomePath);
699
+ });
700
+ }
701
+ }, [isReady]);
702
+ return {
703
+ websocketUrl,
704
+ projectHomePath,
705
+ };
706
+ }
707
+
708
+ export { ReceiveFileProvider, SnapshotProvider, useAgentTools, useAgents, useFile, useImageGen, useLLM, useLoading, useNotification, useOCR, useOwnedAppView, usePulseEnv, useReceiveFile, useRegisterAction, useSTT, useSnapShotState as useSnapshotState, useTTS, useTerminal, useTheme, useVideoGen, useWorkspace };
709
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sources":["../../../node_modules/uuid/dist/stringify.js","../../../node_modules/uuid/dist/rng.js","../../../node_modules/uuid/dist/native.js","../../../node_modules/uuid/dist/v4.js","../src/hooks/imc/use-imc.tsx","../src/hooks/agent/use-agent-tools.ts","../src/hooks/agent/use-agents.ts","../src/hooks/editor/use-file.ts","../src/hooks/editor/use-loading.ts","../src/hooks/editor/use-notification.ts","../src/hooks/editor/use-register-action.ts","../src/hooks/editor/use-theme.ts","../src/hooks/ai-modality/use-image-gen.ts","../src/hooks/ai-modality/use-llm.ts","../src/hooks/ai-modality/use-ocr.ts","../src/hooks/ai-modality/use-stt.ts","../src/hooks/ai-modality/use-tts.ts","../src/hooks/ai-modality/use-video-gen.ts","../src/hooks/editor/use-env.ts","../src/hooks/editor/use-owned-app-view.ts","../src/providers/receive-file-provider.tsx","../src/hooks/editor/use-receive-file.ts","../src/providers/snapshot-provider.tsx","../src/hooks/editor/use-snapshot-state.ts","../src/hooks/editor/use-workspace.ts","../src/hooks/terminal/use-terminal.ts"],"sourcesContent":["import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","let getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n if (!getRandomValues) {\n if (typeof crypto === 'undefined' || !crypto.getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n getRandomValues = crypto.getRandomValues.bind(crypto);\n }\n return getRandomValues(rnds8);\n}\n","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction _v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n return _v4(options, buf, offset);\n}\nexport default v4;\n","import {\r\n IMCMessageTypeEnum,\r\n InterModuleCommunication,\r\n ReceiverHandlerMap,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport { useEffect, useState } from \"react\";\r\nimport { v4 } from \"uuid\";\r\n\r\nexport default function useIMC(handlerMap: ReceiverHandlerMap, intent: string) {\r\n const [imc, setImc] = useState<InterModuleCommunication | undefined>(\r\n undefined\r\n );\r\n const [isReady, setIsReady] = useState(false);\r\n const [isMounted, setIsMounted] = useState(false);\r\n\r\n const targetWindow = window.parent;\r\n\r\n useEffect(() => {\r\n setIsMounted(true);\r\n\r\n return () => {\r\n setIsMounted(false);\r\n imc?.close();\r\n setImc(undefined);\r\n };\r\n }, []);\r\n\r\n useEffect(() => {\r\n async function initIMC() {\r\n if (!isMounted) return;\r\n else if (imc !== undefined) return;\r\n\r\n const newImc = new InterModuleCommunication(intent, v4());\r\n newImc.initThisWindow(window);\r\n newImc.updateReceiverHandlerMap(handlerMap);\r\n await newImc.initOtherWindow(targetWindow);\r\n setImc(newImc);\r\n\r\n await newImc.sendMessage(IMCMessageTypeEnum.AppReady, {\r\n intent,\r\n channelId: newImc.channelId,\r\n });\r\n setIsReady(true);\r\n }\r\n\r\n initIMC();\r\n }, [isMounted, imc]);\r\n\r\n return {\r\n imc,\r\n isReady,\r\n };\r\n}\r\n","import { AgentTool, IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\n/**\r\n * Add or use agent tools in the editor.\r\n * @param moduleName \r\n * @returns \r\n */\r\nexport default function useAgentTools() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc } = useIMC(receiverHandlerMap, \"agent-tools\");\r\n\r\n return { };\r\n}\r\n","import {\r\n Agent,\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n LLMConfig,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useAgents() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"agents\");\r\n\r\n async function runAgentMethod(\r\n agentName: string,\r\n methodName: string,\r\n args: Record<string, any>,\r\n abortSignal?: AbortSignal,\r\n llmConfig?: LLMConfig\r\n ): Promise<any> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(\r\n IMCMessageTypeEnum.EditorRunAgentMethod,\r\n {\r\n agentName,\r\n methodName,\r\n args,\r\n llmConfig,\r\n },\r\n abortSignal\r\n )\r\n .then((response) => {\r\n return response as any;\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runAgentMethod,\r\n isReady,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport { useCallback, useEffect, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useFile(uri: string | undefined) {\r\n const [file, setFile] = useState<File | undefined>(undefined);\r\n\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >([\r\n [\r\n IMCMessageTypeEnum.PlatformFileUpdate,\r\n async (senderWindow: Window, message: IMCMessage) => {\r\n const updatedFile = message.payload as File;\r\n setFile(updatedFile);\r\n },\r\n ],\r\n ]);\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"file\");\r\n\r\n const saveFile = useCallback(\r\n (fileContent: string) => {\r\n if (!uri) return;\r\n else if (!file) return;\r\n\r\n // Update file content\r\n const newFile = new File([fileContent], file.name, {\r\n type: file.type,\r\n lastModified: Date.now(),\r\n });\r\n setFile(newFile);\r\n\r\n if (isReady && uri) {\r\n imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {\r\n uri,\r\n file: newFile,\r\n });\r\n }\r\n },\r\n [uri, file, isReady],\r\n );\r\n\r\n // Read file when uri changes\r\n useEffect(() => {\r\n if (isReady && uri) {\r\n imc\r\n ?.sendMessage(IMCMessageTypeEnum.PlatformReadFile, {\r\n uri,\r\n })\r\n .then((f: File | undefined) => {\r\n setFile(f);\r\n });\r\n }\r\n }, [isReady, uri]);\r\n\r\n return {\r\n file,\r\n saveFile,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport { useEffect, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useLoading() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<any>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"loading\");\r\n const [isLoading, setIsLoading] = useState(true);\r\n\r\n useEffect(() => {\r\n if (isReady) {\r\n imc?.sendMessage(IMCMessageTypeEnum.EditorLoadingApp, {\r\n isLoading,\r\n });\r\n }\r\n }, [isLoading]);\r\n\r\n function toggleLoading(isLoading: boolean) {\r\n setIsLoading((prev) => isLoading);\r\n }\r\n\r\n return {\r\n isReady,\r\n toggleLoading,\r\n };\r\n}\r\n","import {\r\n NotificationTypeEnum,\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n} from \"@pulse-editor/shared-utils\";\r\n\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useNotification() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc } = useIMC(receiverHandlerMap, \"notification\");\r\n\r\n function openNotification(text: string, type: NotificationTypeEnum) {\r\n if (!imc) {\r\n throw new Error(\"IMC is not initialized.\");\r\n }\r\n imc.sendMessage(IMCMessageTypeEnum.EditorShowNotification, {\r\n text,\r\n type,\r\n });\r\n }\r\n\r\n return { openNotification };\r\n}\r\n","import {\r\n Action,\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n ReceiverHandler,\r\n TypedVariable,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport { DependencyList, useEffect, useRef, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\n/**\r\n * Register an app action to listen to IMC messages from the core,\r\n * and pass to the action to handle.\r\n *\r\n * @param name Name of the command.\r\n * @param description Description of the command.\r\n * @param parameters Parameters of the command.\r\n * @param returns Return values of the command.\r\n * @param callbackHandler Callback handler function to handle the command.\r\n * @param deps Dependency list to re-register the action when changed.\r\n * @param isExtReady Whether the extension is ready to receive commands.\r\n * Useful for actions that need to wait for some certain app state to be ready.\r\n *\r\n */\r\nexport default function useRegisterAction(\r\n actionInfo: {\r\n name: string;\r\n description: string;\r\n parameters?: Record<string, TypedVariable>;\r\n returns?: Record<string, TypedVariable>;\r\n },\r\n callbackHandler: (args: any) => Promise<any>,\r\n deps: DependencyList,\r\n isExtReady: boolean = true,\r\n) {\r\n const { isReady, imc } = useIMC(getReceiverHandlerMap(), \"register-action\");\r\n\r\n // Queue to hold commands until extension is ready\r\n const commandQueue = useRef<{ args: any; resolve: (v: any) => void }[]>([]);\r\n const isCommandExecuting = useRef(false);\r\n\r\n const [action, setAction] = useState<Action>({\r\n name: actionInfo.name,\r\n description: actionInfo.description,\r\n parameters: actionInfo.parameters ?? {},\r\n returns: actionInfo.returns ?? {},\r\n handler: callbackHandler,\r\n });\r\n\r\n // Flush queued commands when isExtReady becomes true\r\n useEffect(() => {\r\n async function runQueuedCommands() {\r\n const pendingCMDs = [...commandQueue.current];\r\n commandQueue.current = [];\r\n for (const cmd of pendingCMDs) {\r\n const { args, resolve } = cmd;\r\n if (isCommandExecuting.current) {\r\n return;\r\n }\r\n isCommandExecuting.current = true;\r\n const res = await executeAction(args);\r\n isCommandExecuting.current = false;\r\n resolve(res);\r\n }\r\n }\r\n\r\n if (isExtReady && commandQueue.current.length > 0) {\r\n runQueuedCommands();\r\n }\r\n }, [isExtReady]);\r\n\r\n useEffect(() => {\r\n async function updateAction() {\r\n // Register or update action.\r\n // This will only pass signature info to the editor.\r\n // The actual handler is stored in this hook,\r\n // so the execution happens inside the extension app.\r\n await imc?.sendMessage(IMCMessageTypeEnum.EditorRegisterAction, {\r\n name: action.name,\r\n description: action.description,\r\n parameters: action.parameters,\r\n returns: action.returns,\r\n });\r\n\r\n // Update receiver\r\n imc?.updateReceiverHandlerMap(getReceiverHandlerMap());\r\n }\r\n\r\n if (isExtReady) {\r\n updateAction();\r\n }\r\n }, [action, imc, isExtReady]);\r\n\r\n useEffect(() => {\r\n setAction((prev) => ({\r\n ...prev,\r\n name: actionInfo.name,\r\n description: actionInfo.description,\r\n parameters: actionInfo.parameters ?? {},\r\n returns: actionInfo.returns ?? {},\r\n handler: callbackHandler,\r\n }));\r\n }, [...deps]);\r\n\r\n async function executeAction(args: any) {\r\n if (!action.handler) return;\r\n\r\n const res = await action.handler(args);\r\n\r\n return res;\r\n }\r\n\r\n function getReceiverHandlerMap() {\r\n const receiverHandlerMap = new Map<IMCMessageTypeEnum, ReceiverHandler>([\r\n [\r\n IMCMessageTypeEnum.EditorRunAppAction,\r\n async (_senderWindow: Window, message: IMCMessage) => {\r\n const { name: requestedName, args }: { name: string; args: any } =\r\n message.payload;\r\n\r\n if (actionInfo.name !== requestedName) {\r\n throw new Error(\"Message ignored by receiver\");\r\n }\r\n // Validate parameters\r\n const actionParams = actionInfo.parameters ?? {};\r\n if (Object.keys(args).length !== Object.keys(actionParams).length) {\r\n throw new Error(\r\n `Invalid number of parameters: expected ${\r\n Object.keys(actionParams).length\r\n }, got ${Object.keys(args).length}`,\r\n );\r\n }\r\n\r\n // Check types\r\n for (const [key, value] of Object.entries(args)) {\r\n if (actionParams[key] === undefined) {\r\n throw new Error(`Invalid parameter: ${key}`);\r\n }\r\n if (\r\n typeof value !== actionParams[key].type &&\r\n // Allow object for \"app-instance\"\r\n (actionParams[key].type !== \"app-instance\" ||\r\n typeof value !== \"object\")\r\n ) {\r\n throw new Error(\r\n `Invalid type for parameter ${key}: expected ${\r\n actionParams[key].type\r\n }, got ${typeof value}. Value received: ${value}`,\r\n );\r\n }\r\n }\r\n\r\n // If extension is ready, execute immediately\r\n if (isExtReady) {\r\n const result = await executeAction(args);\r\n return result;\r\n }\r\n\r\n // Otherwise, queue the command and return when executed\r\n return new Promise((resolve) => {\r\n commandQueue.current.push({ args, resolve });\r\n });\r\n },\r\n ],\r\n ]);\r\n return receiverHandlerMap;\r\n }\r\n\r\n return {\r\n isReady,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport { useEffect, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useTheme() {\r\n const [theme, setTheme] = useState<string>(\"light\");\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n receiverHandlerMap.set(\r\n IMCMessageTypeEnum.EditorThemeUpdate,\r\n async (senderWindow: Window, message: IMCMessage) => {\r\n const theme = message.payload;\r\n setTheme((prev) => theme);\r\n }\r\n );\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"theme\");\r\n\r\n // Upon initial load, request theme from main app\r\n useEffect(() => {\r\n if (isReady) {\r\n imc\r\n ?.sendMessage(IMCMessageTypeEnum.EditorAppRequestTheme)\r\n .then((result) => {\r\n setTheme((prev) => result);\r\n });\r\n }\r\n }, [isReady]);\r\n\r\n return {\r\n theme,\r\n };\r\n}\r\n","import {\r\n ImageModelConfig,\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useImageGen() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"image-gen\");\r\n\r\n /**\r\n *\r\n * @param textPrompt The text prompt to generate the image.\r\n * @param imagePrompt A URL to an image or an image in an ArrayBuffer.\r\n * @param imageModelConfig (optional) The image model config to use.\r\n * @returns The generated image in an ArrayBuffer.\r\n */\r\n async function runImageGen(\r\n textPrompt?: string,\r\n imagePrompt?: string | ArrayBuffer,\r\n // LLM config is optional, if not provided, the default config will be used.\r\n imageModelConfig?: ImageModelConfig\r\n ): Promise<{\r\n arrayBuffer?: ArrayBuffer;\r\n url?: string;\r\n }> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n if (!textPrompt && !imagePrompt) {\r\n throw new Error(\"At least one of textPrompt or imagePrompt is required.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(IMCMessageTypeEnum.ModalityImageGen, {\r\n textPrompt,\r\n imagePrompt,\r\n imageModelConfig,\r\n })\r\n .then((response) => {\r\n return response as {\r\n arrayBuffer?: ArrayBuffer;\r\n url?: string;\r\n };\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runImageGen,\r\n isReady,\r\n };\r\n}\r\n","import {\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n LLMConfig,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useLLM() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"llm\");\r\n\r\n async function runLLM(\r\n prompt: string,\r\n // LLM config is optional, if not provided, the default config will be used.\r\n llmConfig?: LLMConfig\r\n ): Promise<string> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(IMCMessageTypeEnum.ModalityLLM, {\r\n prompt,\r\n llmConfig,\r\n })\r\n .then((response) => {\r\n return response as string;\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runLLM,\r\n isReady,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\n\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useOCR() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc } = useIMC(receiverHandlerMap, \"ocr\");\r\n\r\n /**\r\n * \r\n * @param image The image to be recognized. This is a base64 encoded string.\r\n * @returns \r\n */\r\n async function recognizeText(image: string): Promise<string> {\r\n if (!imc) {\r\n throw new Error(\"IMC is not initialized.\");\r\n }\r\n\r\n // Send the message to the extension\r\n const result = await imc.sendMessage(IMCMessageTypeEnum.ModalityOCR, { image });\r\n\r\n return result.payload.text;\r\n }\r\n\r\n return {\r\n recognizeText,\r\n };\r\n}\r\n","import {\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n STTConfig,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useSTT() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"stt\");\r\n\r\n async function runSTT(\r\n audio: Uint8Array,\r\n // Config is optional, if not provided, the default config will be used.\r\n sttConfig?: STTConfig\r\n ): Promise<string> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(IMCMessageTypeEnum.ModalitySTT, {\r\n audio,\r\n sttConfig,\r\n })\r\n .then((response) => {\r\n return response as string;\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runSTT,\r\n isReady,\r\n };\r\n}\r\n","import {\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n TTSConfig,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useTTS() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"tts\");\r\n\r\n async function runTTS(\r\n text: string,\r\n // Config is optional, if not provided, the default config will be used.\r\n ttsConfig?: TTSConfig\r\n ): Promise<Uint8Array> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(IMCMessageTypeEnum.ModalityTTS, {\r\n text,\r\n ttsConfig,\r\n })\r\n .then((response) => {\r\n return response as Uint8Array;\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runTTS,\r\n isReady,\r\n };\r\n}\r\n","import {\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n VideoModelConfig,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useVideoGen() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"video-gen\");\r\n\r\n /**\r\n *\r\n * @param textPrompt The text prompt to generate the video.\r\n * @param imagePrompt A URL to an image or an image in an ArrayBuffer.\r\n * @param videoModelConfig (optional) The video model config to use.\r\n * @returns The generated video in an ArrayBuffer.\r\n */\r\n async function runVideoGen(\r\n duration: number,\r\n textPrompt?: string,\r\n imagePrompt?: string | ArrayBuffer,\r\n // LLM config is optional, if not provided, the default config will be used.\r\n videoModelConfig?: VideoModelConfig\r\n ): Promise<{\r\n url?: string;\r\n arrayBuffer?: ArrayBuffer;\r\n }> {\r\n if (!imc) {\r\n throw new Error(\"IMC not initialized.\");\r\n }\r\n\r\n if (!textPrompt && !imagePrompt) {\r\n throw new Error(\"At least one of textPrompt or imagePrompt is required.\");\r\n }\r\n\r\n const result = await imc\r\n .sendMessage(IMCMessageTypeEnum.ModalityVideoGen, {\r\n duration,\r\n textPrompt,\r\n imagePrompt,\r\n videoModelConfig,\r\n })\r\n .then((response) => {\r\n return response as {\r\n url?: string;\r\n arrayBuffer?: ArrayBuffer;\r\n };\r\n });\r\n\r\n return result;\r\n }\r\n\r\n return {\r\n runVideoGen,\r\n isReady,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport { useEffect, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function usePulseEnv() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"env\");\r\n const [envs, setEnvs] = useState<Record<string, string>>({});\r\n\r\n useEffect(() => {\r\n if (isReady) {\r\n imc?.sendMessage(IMCMessageTypeEnum.EditorGetEnv).then((env) => {\r\n setEnvs(env);\r\n });\r\n }\r\n }, [isReady]);\r\n\r\n return {\r\n isReady,\r\n envs,\r\n };\r\n}\r\n","import {\r\n IMCMessage,\r\n IMCMessageTypeEnum,\r\n ViewModel,\r\n} from \"@pulse-editor/shared-utils\";\r\nimport { useCallback } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useOwnedAppView() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >([]);\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"owned-app\");\r\n\r\n const runAppAction = useCallback(\r\n async (ownedAppViewModel: ViewModel, actionName: string, args: any) => {\r\n if (isReady) {\r\n const appViewId = ownedAppViewModel.viewId;\r\n const preRegisteredActions =\r\n ownedAppViewModel.appConfig.preRegisteredActions || [];\r\n\r\n const action = preRegisteredActions.find((a) => a.name === actionName);\r\n if (!action) {\r\n throw new Error(\r\n `Action ${actionName} not found in owned app ${ownedAppViewModel.appConfig.id}`,\r\n );\r\n }\r\n\r\n const result = await imc?.sendMessage(\r\n IMCMessageTypeEnum.EditorAppUseOwnedApp,\r\n {\r\n viewId: appViewId,\r\n actionName,\r\n args,\r\n },\r\n );\r\n return result;\r\n }\r\n return undefined;\r\n },\r\n [imc, isReady],\r\n );\r\n\r\n return {\r\n runAppAction,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport React, { createContext, ReactNode, useState } from \"react\";\r\nimport useIMC from \"../hooks/imc/use-imc\";\r\n\r\nexport const ReceiveFileContext = createContext<\r\n ReceiveFileContextType | undefined\r\n>(undefined);\r\n\r\nexport type ReceiveFileContextType = {\r\n // Define any state or functions you want to provide here\r\n selectedFileUri: string | undefined;\r\n};\r\n\r\nexport default function ReceiveFileProvider({\r\n children,\r\n}: {\r\n children: ReactNode;\r\n}) {\r\n const [receivedFileUri, setReceivedFileUri] = useState<string | undefined>(\r\n undefined\r\n );\r\n\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<any>\r\n >([\r\n [\r\n IMCMessageTypeEnum.EditorAppReceiveFileUri,\r\n async (senderWindow: Window, message: IMCMessage) => {\r\n const { uri } = message.payload;\r\n setReceivedFileUri((prev) => uri);\r\n },\r\n ],\r\n ]);\r\n useIMC(receiverHandlerMap, \"receive-file-provider\");\r\n\r\n return (\r\n <ReceiveFileContext.Provider value={{ selectedFileUri: receivedFileUri }}>\r\n {children}\r\n </ReceiveFileContext.Provider>\r\n );\r\n}\r\n","import { useContext } from \"react\";\r\nimport { ReceiveFileContext } from \"../../providers/receive-file-provider\";\r\n\r\nexport default function useReceiveFile() {\r\n const context = useContext(ReceiveFileContext);\r\n\r\n if (!context) {\r\n throw new Error(\"useReceiveFile must be used within a ReceiveFileProvider\");\r\n }\r\n\r\n return { receivedFileUri: context.selectedFileUri };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport React, {\r\n createContext,\r\n Dispatch,\r\n ReactNode,\r\n SetStateAction,\r\n useEffect,\r\n useState,\r\n} from \"react\";\r\nimport useIMC from \"../hooks/imc/use-imc\";\r\n\r\nexport const SnapshotContext = createContext<SnapshotContextType | undefined>(\r\n undefined\r\n);\r\n\r\nexport type SnapshotContextType = {\r\n states: { [key: string]: any };\r\n setStates: Dispatch<SetStateAction<{ [key: string]: any }>>;\r\n};\r\n\r\nexport default function SnapshotProvider({\r\n children,\r\n}: {\r\n children: ReactNode;\r\n}) {\r\n const [states, setStates] = useState<{ [key: string]: any }>({});\r\n \r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<any>\r\n >([\r\n [\r\n IMCMessageTypeEnum.EditorAppStateSnapshotRestore,\r\n async (senderWindow: Window, message: IMCMessage) => {\r\n const { states } = message.payload;\r\n\r\n // Update all states in the context\r\n console.log(\"Restoring snapshot states:\", states);\r\n setStates((prev) => ({ ...states }));\r\n },\r\n ],\r\n [\r\n IMCMessageTypeEnum.EditorAppStateSnapshotSave,\r\n async (senderWindow: Window, message: IMCMessage) => {\r\n // Return current states in the context\r\n return { states };\r\n },\r\n ],\r\n ]);\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"snapshot-provider\");\r\n\r\n useEffect(() => {\r\n if (isReady) {\r\n imc?.updateReceiverHandlerMap(receiverHandlerMap);\r\n }\r\n }, [isReady, states]);\r\n\r\n return (\r\n <SnapshotContext.Provider value={{ states, setStates }}>\r\n {children}\r\n </SnapshotContext.Provider>\r\n );\r\n}\r\n","import { useContext, useEffect, useRef, useState } from \"react\";\r\nimport { SnapshotContext } from \"../../providers/snapshot-provider\";\r\n\r\nexport default function useSnapShotState<T>(\r\n key: string,\r\n initialValue?: T,\r\n onRestore?: (value: T) => void\r\n) {\r\n const snapshotContext = useContext(SnapshotContext);\r\n if (!snapshotContext) {\r\n throw new Error(\"useSnapShotState must be used within a SnapshotProvider\");\r\n }\r\n\r\n const { states, setStates } = snapshotContext;\r\n const [state, setState] = useState<T>(\r\n states[key] !== undefined ? states[key] : initialValue\r\n );\r\n\r\n const isLocalUpdate = useRef(false);\r\n\r\n const setSnapshotState: React.Dispatch<React.SetStateAction<T>> = (value) => {\r\n setState((prev) => {\r\n const newValue =\r\n typeof value === \"function\" ? (value as (prev: T) => T)(prev) : value;\r\n\r\n isLocalUpdate.current = true; // mark as local\r\n Promise.resolve().then(() => {\r\n setStates((prevStates) => ({\r\n ...prevStates,\r\n [key]: newValue,\r\n }));\r\n });\r\n\r\n return newValue;\r\n });\r\n };\r\n\r\n // Initialize context with initial value\r\n useEffect(() => {\r\n if (states[key] === undefined && initialValue !== undefined) {\r\n setStates((prev) => ({\r\n ...prev,\r\n [key]: initialValue,\r\n }));\r\n }\r\n }, []);\r\n\r\n // Only restore when external changes occur\r\n useEffect(() => {\r\n const contextValue = states[key];\r\n if (contextValue === undefined) return;\r\n\r\n if (isLocalUpdate.current) {\r\n // skip this run because we caused it ourselves\r\n isLocalUpdate.current = false;\r\n return;\r\n }\r\n\r\n if (contextValue !== state) {\r\n console.log(\"Restoring state for key:\", key, contextValue);\r\n setState(contextValue);\r\n onRestore?.(contextValue);\r\n }\r\n }, [states[key]]);\r\n\r\n return [state, setSnapshotState] as const;\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport { useEffect, useState } from \"react\";\r\nimport useIMC from \"../imc/use-imc\";\r\n\r\nexport default function useWorkspace() {\r\n const [workspaceId, setWorkspaceId] = useState<string | undefined>(undefined);\r\n\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"theme\");\r\n\r\n // Upon initial load, request theme from main app\r\n useEffect(() => {\r\n if (isReady) {\r\n imc\r\n ?.sendMessage(IMCMessageTypeEnum.EditorAppRequestWorkspace)\r\n .then((result) => {\r\n const { id }: { id: string } = result;\r\n setWorkspaceId((prev) => id);\r\n });\r\n }\r\n }, [isReady]);\r\n\r\n return {\r\n workspaceId,\r\n };\r\n}\r\n","import { IMCMessage, IMCMessageTypeEnum } from \"@pulse-editor/shared-utils\";\r\nimport useIMC from \"../imc/use-imc\";\r\nimport { useEffect, useState } from \"react\";\r\n\r\nexport default function useTerminal() {\r\n const receiverHandlerMap = new Map<\r\n IMCMessageTypeEnum,\r\n (senderWindow: Window, message: IMCMessage) => Promise<void>\r\n >();\r\n\r\n const { imc, isReady } = useIMC(receiverHandlerMap, \"terminal\");\r\n const [websocketUrl, setWebsocketUrl] = useState<string | undefined>(\r\n undefined\r\n );\r\n const [projectHomePath, setProjectHomePath] = useState<string | undefined>(\r\n undefined\r\n );\r\n\r\n useEffect(() => {\r\n if (isReady) {\r\n imc?.sendMessage(IMCMessageTypeEnum.PlatformCreateTerminal).then((response) => {\r\n const {\r\n websocketUrl,\r\n projectHomePath,\r\n }: {\r\n websocketUrl: string;\r\n projectHomePath: string;\r\n } = response;\r\n\r\n setWebsocketUrl(websocketUrl);\r\n setProjectHomePath(projectHomePath);\r\n });\r\n }\r\n }, [isReady]);\r\n\r\n return {\r\n websocketUrl,\r\n projectHomePath,\r\n };\r\n}\r\n"],"names":["byteToHex","i","push","toString","slice","unsafeStringify","arr","offset","arguments","length","undefined","toLowerCase","getRandomValues","rnds8","Uint8Array","rng","crypto","Error","bind","randomUUID","_v4","options","buf","_ref","_options$random","_options$rng","_options","rnds","random","call","v4","native"],"mappings":";;;AACA,IAAMA,SAAS,GAAG,EAAE;AACpB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,GAAG,EAAE,EAAEA,CAAC,EAAE;AAC1BD,EAAAA,SAAS,CAACE,IAAI,CAAC,CAACD,CAAC,GAAG,KAAK,EAAEE,QAAQ,CAAC,EAAE,CAAC,CAACC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrD;AACO,SAASC,eAAeA,CAACC,GAAG,EAAc;AAAA,EAAA,IAAZC,MAAM,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,CAAC;AAC3C,EAAA,OAAO,CAACR,SAAS,CAACM,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAC,GAC9BP,SAAS,CAACM,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAC,GAC1BP,SAAS,CAACM,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAC,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,CAAC;gBAC7B,kBAAkB,CAAC,eAAe,CAAC;AACrC,YAAA,CAAC,CAAC;QACJ;AACF,IAAA,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAEb,OAAO;QACL,YAAY;QACZ,eAAe;KAChB;AACH;;;;","x_google_ignoreList":[0,1,2,3]}
@@ -0,0 +1,8 @@
1
+ import React, { ReactNode } from "react";
2
+ export declare const ReceiveFileContext: React.Context<ReceiveFileContextType | undefined>;
3
+ export type ReceiveFileContextType = {
4
+ selectedFileUri: string | undefined;
5
+ };
6
+ export default function ReceiveFileProvider({ children, }: {
7
+ children: ReactNode;
8
+ }): React.JSX.Element;
@@ -0,0 +1,13 @@
1
+ import React, { Dispatch, ReactNode, SetStateAction } from "react";
2
+ export declare const SnapshotContext: React.Context<SnapshotContextType | undefined>;
3
+ export type SnapshotContextType = {
4
+ states: {
5
+ [key: string]: any;
6
+ };
7
+ setStates: Dispatch<SetStateAction<{
8
+ [key: string]: any;
9
+ }>>;
10
+ };
11
+ export default function SnapshotProvider({ children, }: {
12
+ children: ReactNode;
13
+ }): React.JSX.Element;
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@pulse-editor/react-api",
3
- "version": "0.1.1-beta.2",
3
+ "version": "0.1.1-beta.56",
4
4
  "main": "dist/main.js",
5
- "type": "module",
6
5
  "files": [
7
6
  "dist"
8
7
  ],
9
8
  "publishConfig": {
10
9
  "access": "public"
11
10
  },
11
+ "types": "dist/main.d.ts",
12
+ "type": "module",
12
13
  "scripts": {
13
- "build": "rollup -c",
14
- "lint": "eslint ."
14
+ "build": "npm run clean && rollup -c",
15
+ "lint": "eslint .",
16
+ "clean": "rimraf dist"
15
17
  },
16
18
  "devDependencies": {
17
19
  "@babel/core": "^7.26.10",
@@ -19,7 +21,6 @@
19
21
  "@eslint/js": "^9.25.0",
20
22
  "@rollup/plugin-babel": "^6.0.4",
21
23
  "@rollup/plugin-node-resolve": "^16.0.1",
22
- "@rollup/plugin-terser": "^0.4.4",
23
24
  "@rollup/plugin-typescript": "^12.1.2",
24
25
  "@types/react": "^19.1.2",
25
26
  "eslint": "^9.25.0",
@@ -29,14 +30,15 @@
29
30
  "npm": "^11.3.0",
30
31
  "react": "^19.1.0",
31
32
  "react-dom": "^19.1.0",
33
+ "rimraf": "^3.0.2",
32
34
  "rollup": "^4.40.0",
33
35
  "rollup-plugin-peer-deps-external": "^2.2.4",
34
36
  "typescript": "^5.8.3",
35
37
  "typescript-eslint": "^8.30.1"
36
38
  },
37
39
  "peerDependencies": {
38
- "@pulse-editor/shared-utils": "0.1.1-beta.1",
40
+ "@pulse-editor/shared-utils": "0.1.1-beta.56",
39
41
  "react": "^19.0.0",
40
42
  "react-dom": "^19.0.0"
41
43
  }
42
- }
44
+ }
@@ -1,4 +0,0 @@
1
- import { AgentTool } from "@pulse-editor/shared-utils";
2
- export default function useAgentTools(moduleName: string): {
3
- installAgentTool: (tool: AgentTool) => Promise<void>;
4
- };
@@ -1,6 +0,0 @@
1
- import { Agent } from "@pulse-editor/shared-utils";
2
- export default function useAgents(moduleName: string): {
3
- installAgent: (config: Agent) => Promise<void>;
4
- runAgentMethod: (agentName: string, methodName: string, parameters: Record<string, any>, abortSignal?: AbortSignal) => Promise<Record<string, any>>;
5
- isReady: boolean;
6
- };
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as e}from"@pulse-editor/shared-utils";import t from"../lib/hooks/use-imc.js";function n(n){const r=new Map,{imc:i,isReady:a}=t(n,r);return{installAgent:async function(t){if(!i)throw new Error("IMC not initialized.");await i.sendMessage(e.InstallAgent,t).catch((e=>{throw new Error(e)}))},runAgentMethod:async function(t,n,r,a){if(!i)throw new Error("IMC not initialized.");return await i.sendMessage(e.RunAgentMethod,{agentName:t,methodName:n,parameters:r},a).then((e=>e))},isReady:a}}export{n as default};
@@ -1,3 +0,0 @@
1
- export default function useFetch(moduleName: string): {
2
- fetch: (uri: string, options?: RequestInit) => Promise<Response>;
3
- };
@@ -1,6 +0,0 @@
1
- import { FileViewModel } from "@pulse-editor/shared-utils";
2
- export default function useFileView(moduleName: string): {
3
- viewFile: FileViewModel | undefined;
4
- updateViewFile: (file: FileViewModel) => void;
5
- setIsLoaded: import("react").Dispatch<import("react").SetStateAction<boolean>>;
6
- };
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as e}from"@pulse-editor/shared-utils";import{useState as i,useEffect as s}from"react";import t from"../lib/hooks/use-imc.js";function o(o){const[d,r]=i(void 0),[a,n]=i(!1),u=new Map,{imc:l,isReady:m}=t(o,u);return s((()=>{m&&l?.sendMessage(e.RequestViewFile).then((e=>{r(e)}))}),[m]),s((()=>{a&&l?.sendMessage(e.Loaded)}),[a,l]),{viewFile:d,updateViewFile:function(i){l?.sendMessage(e.WriteViewFile,i)},setIsLoaded:n}}export{o as default};
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as i}from"@pulse-editor/shared-utils";import t from"../lib/hooks/use-imc.js";function o(o){const e=new Map,{imc:n}=t(o,e);return{openNotification:function(t,o){if(!n)throw new Error("IMC is not initialized.");n.sendMessage(i.Notification,{text:t,type:o})}}}export{o as default};
@@ -1,3 +0,0 @@
1
- export default function useOCR(moduleName: string): {
2
- recognizeText: (uri: string) => Promise<string>;
3
- };
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as e}from"@pulse-editor/shared-utils";import i from"../lib/hooks/use-imc.js";function t(t){const r=new Map,{imc:o}=i(t,r);return{recognizeText:async function(i){if(!o)throw new Error("IMC is not initialized.");return(await o.sendMessage(e.OCR,{uri:i})).payload.text}}}export{t as default};
@@ -1,3 +0,0 @@
1
- export default function useTerminal(moduleName: string): {
2
- websocketUrl: string | undefined;
3
- };
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as e}from"@pulse-editor/shared-utils";import s from"../lib/hooks/use-imc.js";import{useState as o,useEffect as t}from"react";function r(r){const i=new Map,{imc:a,isReady:n}=s(r,i),[d,m]=o(void 0);return t((()=>{n&&a?.sendMessage(e.RequestTerminal).then((s=>{const{websocketUrl:o}=s;m(o),a.sendMessage(e.Loaded)}))}),[n]),{websocketUrl:d}}export{r as default};
@@ -1,3 +0,0 @@
1
- export default function useTheme(moduleName: string): {
2
- theme: string;
3
- };
@@ -1 +0,0 @@
1
- import{IMCMessageTypeEnum as e}from"@pulse-editor/shared-utils";import{useState as t}from"react";import o from"../lib/hooks/use-imc.js";function r(r){const[s,a]=t("light"),i=new Map;return i.set(e.ThemeChange,(async(e,t)=>{const o=t.payload;a((e=>o))})),o(r,i),{theme:s}}export{r as default};
@@ -1,6 +0,0 @@
1
- import { InterModuleCommunication } from "@pulse-editor/shared-utils";
2
- import { ReceiverHandlerMap } from "@pulse-editor/shared-utils";
3
- export default function useIMC(moduleName: string, handlerMap: ReceiverHandlerMap): {
4
- imc: InterModuleCommunication | undefined;
5
- isReady: boolean;
6
- };
@@ -1 +0,0 @@
1
- import{InterModuleCommunication as e,IMCMessageTypeEnum as i}from"@pulse-editor/shared-utils";import{useState as t,useEffect as n}from"react";function r(r,o){const[d,s]=t(void 0),[a,c]=t(!1),p=window.parent;return n((()=>{const t=new e(r);return t.initThisWindow(window),t.updateReceiverHandlerMap(o),t.initOtherWindow(p),s(t),t.sendMessage(i.Ready).then((()=>{c(!0)})),()=>{t.close()}}),[]),{imc:d,isReady:a}}export{r as default};
package/dist/main.es.js DELETED
@@ -1 +0,0 @@
1
- import{InterModuleCommunication as e,IMCMessageTypeEnum as n}from"@pulse-editor/shared-utils";import{useState as t,useEffect as i}from"react";function o(o,s){const[a,r]=t(void 0),[d,c]=t(!1),w=window.parent;return i((()=>{const t=new e(o);return t.initThisWindow(window),t.updateReceiverHandlerMap(s),t.initOtherWindow(w),r(t),t.sendMessage(n.Ready).then((()=>{c(!0)})),()=>{t.close()}}),[]),{imc:a,isReady:d}}function s(e){const[s,a]=t(void 0),[r,d]=t(!1),c=new Map,{imc:w,isReady:u}=o(e,c);return i((()=>{u&&w?.sendMessage(n.RequestViewFile).then((e=>{a(e)}))}),[u]),i((()=>{r&&w?.sendMessage(n.Loaded)}),[r,w]),{viewFile:s,updateViewFile:function(e){w?.sendMessage(n.WriteViewFile,e)},setIsLoaded:d}}function a(e){const[i,s]=t("light"),a=new Map;return a.set(n.ThemeChange,(async(e,n)=>{const t=n.payload;s((e=>t))})),o(e,a),{theme:i}}function r(e){const t=new Map,{imc:i}=o(e,t);return{openNotification:function(e,t){if(!i)throw new Error("IMC is not initialized.");i.sendMessage(n.Notification,{text:e,type:t})}}}function d(e){const t=new Map,{imc:i,isReady:s}=o(e,t);return{installAgent:async function(e){if(!i)throw new Error("IMC not initialized.");await i.sendMessage(n.InstallAgent,e).catch((e=>{throw new Error(e)}))},runAgentMethod:async function(e,t,o,s){if(!i)throw new Error("IMC not initialized.");return await i.sendMessage(n.RunAgentMethod,{agentName:e,methodName:t,parameters:o},s).then((e=>e))},isReady:s}}function c(e){const t=new Map,{imc:i}=o(e,t);return{recognizeText:async function(e){if(!i)throw new Error("IMC is not initialized.");return(await i.sendMessage(n.OCR,{uri:e})).payload.text}}}function w(e){const s=new Map,{imc:a,isReady:r}=o(e,s),[d,c]=t(void 0);return i((()=>{r&&a?.sendMessage(n.RequestTerminal).then((e=>{const{websocketUrl:t}=e;c(t),a.sendMessage(n.Loaded)}))}),[r]),{websocketUrl:d}}export{d as useAgents,s as useFileView,r as useNotification,c as useOCR,w as useTerminal,a as useTheme};