@pulse-editor/react-api 0.1.1-alpha.5 → 0.1.1-alpha.50
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/hooks/agent/use-agent-tools.d.ts +6 -0
- package/dist/hooks/agent/use-agents.d.ts +5 -0
- package/dist/hooks/ai-modality/use-image-gen.d.ts +8 -0
- package/dist/hooks/ai-modality/use-llm.d.ts +5 -0
- package/dist/hooks/ai-modality/use-ocr.d.ts +3 -0
- package/dist/hooks/ai-modality/use-speech2speech.d.ts +10 -0
- package/dist/hooks/ai-modality/use-stt.d.ts +5 -0
- package/dist/hooks/ai-modality/use-tts.d.ts +5 -0
- package/dist/hooks/ai-modality/use-video-gen.d.ts +8 -0
- package/dist/hooks/editor/use-env.d.ts +4 -0
- package/dist/hooks/editor/use-file.d.ts +4 -0
- package/dist/hooks/editor/use-loading.d.ts +4 -0
- package/dist/hooks/editor/use-mic.d.ts +4 -0
- package/dist/hooks/{use-notification.d.ts → editor/use-notification.d.ts} +1 -1
- package/dist/hooks/editor/use-receive-file.d.ts +3 -0
- package/dist/hooks/editor/use-register-action.d.ts +24 -0
- package/dist/hooks/editor/use-snapshot-state.d.ts +1 -0
- package/dist/hooks/editor/use-theme.d.ts +3 -0
- package/dist/hooks/editor/use-toolbar.d.ts +1 -0
- package/dist/hooks/imc/use-imc.d.ts +5 -0
- package/dist/hooks/terminal/use-terminal.d.ts +4 -0
- package/dist/main.d.ts +21 -7
- package/dist/main.js +1 -1
- package/dist/providers/receive-file-provider.d.ts +8 -0
- package/dist/providers/snapshot-provider.d.ts +13 -0
- package/package.json +5 -3
- package/dist/hooks/use-agent-tools.d.ts +0 -4
- package/dist/hooks/use-agents.d.ts +0 -6
- package/dist/hooks/use-fetch.d.ts +0 -3
- package/dist/hooks/use-file-view.d.ts +0 -6
- package/dist/hooks/use-orc.d.ts +0 -3
- package/dist/hooks/use-terminal.d.ts +0 -3
- package/dist/hooks/use-theme.d.ts +0 -3
- package/dist/lib/hooks/use-imc.d.ts +0 -6
|
@@ -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,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,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,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 @@
|
|
|
1
|
+
export default function useToolbar(): {};
|
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
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 useToolbar from "./hooks/editor/use-toolbar";
|
|
9
|
+
import useImageGen from "./hooks/ai-modality/use-image-gen";
|
|
10
|
+
import useLLM from "./hooks/ai-modality/use-llm";
|
|
11
|
+
import useOCR from "./hooks/ai-modality/use-ocr";
|
|
12
|
+
import useSTT from "./hooks/ai-modality/use-stt";
|
|
13
|
+
import useTTS from "./hooks/ai-modality/use-tts";
|
|
14
|
+
import useVideoGen from "./hooks/ai-modality/use-video-gen";
|
|
15
|
+
import usePulseEnv from "./hooks/editor/use-env";
|
|
16
|
+
import useReceiveFile from "./hooks/editor/use-receive-file";
|
|
17
|
+
import useSnapshotState from "./hooks/editor/use-snapshot-state";
|
|
18
|
+
import useTerminal from "./hooks/terminal/use-terminal";
|
|
19
|
+
import ReceiveFileProvider from "./providers/receive-file-provider";
|
|
20
|
+
import SnapshotProvider from "./providers/snapshot-provider";
|
|
21
|
+
export { ReceiveFileProvider, SnapshotProvider, useAgentTools, useAgents, useFile, useImageGen, useLLM, useLoading, useNotification, useOCR, usePulseEnv, useReceiveFile, useRegisterAction, useSTT, useSnapshotState, useTTS, useTerminal, useTheme, useToolbar, useVideoGen, };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InterModuleCommunication as e,IMCMessageTypeEnum as
|
|
1
|
+
import{InterModuleCommunication as e,IMCMessageTypeEnum as t}from"@pulse-editor/shared-utils";import n,{useState as r,useEffect as i,useCallback as o,useRef as a,createContext as s,useContext as c}from"react";function d(n){const[o,a]=r(void 0),[s,c]=r(!1),[d,u]=r(!1),p=window.parent;return i(()=>(u(!0),()=>{u(!1),o?.close(),a(void 0)}),[]),i(()=>{!async function(){if(!d)return;if(void 0!==o)return;const r=new e;r.initThisWindow(window),r.updateReceiverHandlerMap(n),await r.initOtherWindow(p),a(r),await r.sendMessage(t.AppReady),c(!0)}()},[d,o]),{imc:o,isReady:s}}function u(){return d(new Map),{}}function p(){const e=new Map,{imc:n,isReady:r}=d(e);return{runAgentMethod:async function(e,r,i,o,a){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.EditorRunAgentMethod,{agentName:e,methodName:r,args:i,llmConfig:a},o).then(e=>e)},isReady:r}}function f(e){const[n,a]=r(void 0),s=new Map([[t.PlatformFileUpdate,async(e,t)=>{const n=t.payload;a(n)}]]),{imc:c,isReady:u}=d(s),p=o(r=>{if(!e)return;if(!n)return;const i=new File([r],n.name,{type:n.type,lastModified:Date.now()});a(i),u&&e&&c?.sendMessage(t.PlatformWriteFile,{uri:e,file:i})},[e,n,u]);return i(()=>{u&&c?.sendMessage(t.PlatformReadFile,{uri:e}).then(e=>{a(e)})},[u,e]),{file:n,saveFile:p}}function l(){const e=new Map,{imc:n,isReady:o}=d(e),[a,s]=r(!0);return i(()=>{o&&n?.sendMessage(t.EditorLoadingApp,{isLoading:a})},[a]),{isReady:o,toggleLoading:function(e){s(t=>e)}}}function m(){const e=new Map,{imc:n}=d(e);return{openNotification:function(e,r){if(!n)throw new Error("IMC is not initialized.");n.sendMessage(t.EditorShowNotification,{text:e,type:r})}}}function w(e,n,o,s=!0){const{isReady:c,imc:u}=d(w()),p=a([]),[f,l]=r({name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n});async function m(e){if(!f.handler)return;return await f.handler(e)}function w(){return new Map([[t.EditorRunAppAction,async(t,n)=>{const{name:r,args:i}=n.payload;if(e.name===r){const t=e.parameters??{};if(Object.keys(i).length!==Object.keys(t).length)throw new Error(`Invalid number of parameters: expected ${Object.keys(t).length}, got ${Object.keys(i).length}`);for(const[e,n]of Object.entries(i)){if(void 0===t[e])throw new Error(`Invalid parameter: ${e}`);if(typeof n!==t[e].type)throw new Error(`Invalid type for parameter ${e}: expected ${t[e].type}, got ${typeof n}. Value received: ${n}`)}return s?await m(i):new Promise(e=>{p.current.push({args:i,resolve:e})})}}]])}return i(()=>{if(s&&p.current.length>0){const e=[...p.current];p.current=[],e.forEach(async({args:e,resolve:t})=>{t(await m(e))})}},[s]),i(()=>{s&&async function(){await(u?.sendMessage(t.EditorRegisterAction,{name:f.name,description:f.description,parameters:f.parameters,returns:f.returns})),u?.updateReceiverHandlerMap(w())}()},[f,u,s]),i(()=>{l(t=>({...t,name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n}))},[...o]),{isReady:c}}function y(){const[e,n]=r("light"),o=new Map;o.set(t.EditorThemeUpdate,async(e,t)=>{const r=t.payload;n(e=>r)});const{imc:a,isReady:s}=d(o);return i(()=>{s&&a?.sendMessage(t.EditorAppRequestTheme).then(e=>{n(t=>e)})},[s]),{theme:e}}function h(){return{}}function M(){const e=new Map,{imc:n,isReady:r}=d(e);return{runImageGen:async function(e,r,i){if(!n)throw new Error("IMC not initialized.");if(!e&&!r)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityImageGen,{textPrompt:e,imagePrompt:r,imageModelConfig:i}).then(e=>e)},isReady:r}}function g(){const e=new Map,{imc:n,isReady:r}=d(e);return{runLLM:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityLLM,{prompt:e,llmConfig:r}).then(e=>e)},isReady:r}}function v(){const e=new Map,{imc:n}=d(e);return{recognizeText:async function(e){if(!n)throw new Error("IMC is not initialized.");return(await n.sendMessage(t.ModalityOCR,{image:e})).payload.text}}}function R(){const e=new Map,{imc:n,isReady:r}=d(e);return{runSTT:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalitySTT,{audio:e,sttConfig:r}).then(e=>e)},isReady:r}}function E(){const e=new Map,{imc:n,isReady:r}=d(e);return{runTTS:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityTTS,{text:e,ttsConfig:r}).then(e=>e)},isReady:r}}function P(){const e=new Map,{imc:n,isReady:r}=d(e);return{runVideoGen:async function(e,r,i,o){if(!n)throw new Error("IMC not initialized.");if(!r&&!i)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityVideoGen,{duration:e,textPrompt:r,imagePrompt:i,videoModelConfig:o}).then(e=>e)},isReady:r}}function S(){const e=new Map,{imc:n,isReady:o}=d(e),[a,s]=r({});return i(()=>{o&&n?.sendMessage(t.EditorGetEnv).then(e=>{s(e)})},[o]),{isReady:o,envs:a}}const C=s(void 0);function A({children:e}){const[i,o]=r(void 0);return d(new Map([[t.EditorAppReceiveFileUri,async(e,t)=>{const{uri:n}=t.payload;o(e=>n)}]])),n.createElement(C.Provider,{value:{selectedFileUri:i}},e)}function I(){const e=c(C);if(!e)throw new Error("useReceiveFile must be used within a ReceiveFileProvider");return{receivedFileUri:e.selectedFileUri}}const T=s(void 0);function x({children:e}){const[o,a]=r({}),s=new Map([[t.EditorAppStateSnapshotRestore,async(e,t)=>{const{states:n}=t.payload;console.log("Restoring snapshot states:",n),a(e=>({...n}))}],[t.EditorAppStateSnapshotSave,async(e,t)=>({states:o})]]),{imc:c,isReady:u}=d(s);return i(()=>{u&&c?.updateReceiverHandlerMap(s)},[u,o]),n.createElement(T.Provider,{value:{states:o,setStates:a}},e)}function F(e,t,n){const o=c(T);if(!o)throw new Error("useSnapShotState must be used within a SnapshotProvider");const{states:s,setStates:d}=o,[u,p]=r(void 0!==s[e]?s[e]:t),f=a(!1);return i(()=>{void 0===s[e]&&void 0!==t&&d(n=>({...n,[e]:t}))},[]),i(()=>{const t=s[e];void 0!==t&&(f.current?f.current=!1:t!==u&&(console.log("Restoring state for key:",e,t),p(t),n?.(t)))},[s[e]]),[u,t=>{p(n=>{const r="function"==typeof t?t(n):t;return f.current=!0,Promise.resolve().then(()=>{d(t=>({...t,[e]:r}))}),r})}]}function b(){const e=new Map,{imc:n,isReady:o}=d(e),[a,s]=r(void 0),[c,u]=r(void 0);return i(()=>{o&&n?.sendMessage(t.PlatformCreateTerminal).then(e=>{const{websocketUrl:t,projectHomePath:n}=e;s(t),u(n)})},[o]),{websocketUrl:a,projectHomePath:c}}export{A as ReceiveFileProvider,x as SnapshotProvider,u as useAgentTools,p as useAgents,f as useFile,M as useImageGen,g as useLLM,l as useLoading,m as useNotification,v as useOCR,S as usePulseEnv,I as useReceiveFile,w as useRegisterAction,R as useSTT,F as useSnapshotState,E as useTTS,b as useTerminal,y as useTheme,h as useToolbar,P as useVideoGen};
|
|
@@ -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,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-editor/react-api",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.1-alpha.50",
|
|
4
|
+
"main": "dist/main.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"types": "dist/main.d.ts",
|
|
12
|
+
"type": "module",
|
|
11
13
|
"scripts": {
|
|
12
14
|
"build": "npm run clean && rollup -c",
|
|
13
15
|
"lint": "eslint .",
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
"typescript-eslint": "^8.30.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
|
-
"@pulse-editor/shared-utils": "0.1.1-alpha.
|
|
41
|
+
"@pulse-editor/shared-utils": "0.1.1-alpha.50",
|
|
40
42
|
"react": "^19.0.0",
|
|
41
43
|
"react-dom": "^19.0.0"
|
|
42
44
|
}
|
|
@@ -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,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
|
-
};
|
package/dist/hooks/use-orc.d.ts
DELETED
|
@@ -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
|
-
};
|