@pulse-editor/react-api 0.1.1-alpha.36 → 0.1.1-alpha.37

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.
@@ -0,0 +1,16 @@
1
+ import { TypedVariable } from "@pulse-editor/shared-utils";
2
+ /**
3
+ * Register an app action to listen to IMC messages from the core,
4
+ * and pass to the action to handle.
5
+ *
6
+ * @param name Name of the command.
7
+ * @param description Description of the command.
8
+ * @param parameters Parameters of the command.
9
+ * @param returns Return values of the command.
10
+ * @param callbackHandler Callback handler function to handle the command.
11
+ * @param isExtReady Whether the extension is ready to receive commands.
12
+ *
13
+ */
14
+ export default function useRegisterAction(name: string, description: string, parameters: Record<string, TypedVariable>, returns: Record<string, TypedVariable>, callbackHandler?: (args: any) => Promise<string | void>, isExtReady?: boolean): {
15
+ isReady: boolean;
16
+ };
package/dist/main.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import useAgentTools from "./hooks/agent/use-agent-tools";
2
2
  import useAgents from "./hooks/agent/use-agents";
3
- import useCommand from "./hooks/editor/use-command";
3
+ import useRegisterAction from "./hooks/editor/use-register-action";
4
4
  import useFileView from "./hooks/editor/use-file-view";
5
5
  import useLoading from "./hooks/editor/use-loading";
6
6
  import useNotification from "./hooks/editor/use-notification";
@@ -14,4 +14,4 @@ import useTTS from "./hooks/ai-modality/use-tts";
14
14
  import useVideoGen from "./hooks/ai-modality/use-video-gen";
15
15
  import usePulseEnv from "./hooks/editor/use-env";
16
16
  import useTerminal from "./hooks/terminal/use-terminal";
17
- export { useAgentTools, useAgents, useCommand, useFileView, useImageGen, useLLM, useLoading, useNotification, useOCR, usePulseEnv, useSTT, useTTS, useTerminal, useTheme, useToolbar, useVideoGen, };
17
+ export { useAgentTools, useAgents, useRegisterAction as useCommand, useFileView, useImageGen, useLLM, useLoading, useNotification, useOCR, usePulseEnv, useSTT, useTTS, useTerminal, useTheme, useToolbar, useVideoGen, };
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- import{InterModuleCommunication as e,IMCMessageTypeEnum as n}from"@pulse-editor/shared-utils";import{useState as t,useEffect as i,useRef as r}from"react";function o(r){const[o,a]=t(void 0),[s,d]=t(!1),[c,u]=t(!1),f=window.parent;return i(()=>(u(!0),()=>{u(!1),o?.close(),a(void 0)}),[]),i(()=>{!async function(){if(!c)return;if(void 0!==o)return;const t=new e;t.initThisWindow(window),t.updateReceiverHandlerMap(r),await t.initOtherWindow(f),a(t),t.sendMessage(n.ExtReady).then(()=>{d(!0)})}()},[c,o]),{imc:o,isReady:s}}function a(){return o(new Map),{}}function s(){const e=new Map,{imc:t,isReady:i}=o(e);return{runAgentMethod:async function(e,i,r,o,a){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.EditorRunAgentMethod,{agentName:e,methodName:i,parameters:r,llmConfig:a},o).then(e=>e)},isReady:i}}function d(e,a,s=!0){const{isReady:d,imc:c}=o(p()),[u,f]=t(void 0),w=r([]);async function m(e){if(!u)return;return await u(e)}function p(){return new Map([[n.EditorRunExtCommand,async(n,t)=>{if(!e)throw new Error("Extension command is not available");const{name:i,args:r}=t.payload;if(i===e.name){const n=e.parameters;if(Object.keys(r).length!==Object.keys(n).length)throw new Error(`Invalid number of parameters: expected ${Object.keys(n).length}, got ${Object.keys(r).length}`);for(const[n,t]of Object.entries(r)){if(void 0===e.parameters[n])throw new Error(`Invalid parameter: ${n}`);if(typeof t!==e.parameters[n].type)throw new Error(`Invalid type for parameter ${n}: expected ${e.parameters[n].type}, got ${typeof t}. Value received: ${t}`)}return s?await m(r):new Promise(e=>{w.current.push({args:r,resolve:e})})}}]])}return i(()=>{if(s&&w.current.length>0){const e=[...w.current];w.current=[],e.forEach(async({args:e,resolve:n})=>{n(await m(e))})}},[s]),i(()=>{c?.updateReceiverHandlerMap(p())},[u,c,s]),i(()=>{f(()=>a)},[a]),{isReady:d}}function c(){const[e,r]=t(void 0),a=new Map,{imc:s,isReady:d}=o(a);return i(()=>{d&&s?.sendMessage(n.PlatformReadFile).then(e=>{r(e)})},[d]),{viewModel:e,updateViewModel:function(e){s?.sendMessage(n.PlatformWriteFile,e)}}}function u(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t(!0);return i(()=>{a&&r?.sendMessage(n.EditorLoadingExt,{isLoading:s})},[s]),{isReady:a,toggleLoading:function(e){d(n=>e)}}}function f(){const e=new Map,{imc:t}=o(e);return{openNotification:function(e,i){if(!t)throw new Error("IMC is not initialized.");t.sendMessage(n.EditorShowNotification,{text:e,type:i})}}}function w(){const[e,i]=t("light"),r=new Map;return r.set(n.EditorThemeUpdate,async(e,n)=>{const t=n.payload;i(e=>t)}),o(r),{theme:e}}function m(){return{}}function p(){const e=new Map,{imc:t,isReady:i}=o(e);return{runImageGen:async function(e,i,r){if(!t)throw new Error("IMC not initialized.");if(!e&&!i)throw new Error("At least one of textPrompt or imagePrompt is required.");return await t.sendMessage(n.ModalityImageGen,{textPrompt:e,imagePrompt:i,imageModelConfig:r}).then(e=>e)},isReady:i}}function l(){const e=new Map,{imc:t,isReady:i}=o(e);return{runLLM:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalityLLM,{prompt:e,llmConfig:i}).then(e=>e)},isReady:i}}function y(){const e=new Map,{imc:t}=o(e);return{recognizeText:async function(e){if(!t)throw new Error("IMC is not initialized.");return(await t.sendMessage(n.ModalityOCR,{image:e})).payload.text}}}function M(){const e=new Map,{imc:t,isReady:i}=o(e);return{runSTT:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalitySTT,{audio:e,sttConfig:i}).then(e=>e)},isReady:i}}function g(){const e=new Map,{imc:t,isReady:i}=o(e);return{runTTS:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalityTTS,{text:e,ttsConfig:i}).then(e=>e)},isReady:i}}function h(){const e=new Map,{imc:t,isReady:i}=o(e);return{runVideoGen:async function(e,i,r,o){if(!t)throw new Error("IMC not initialized.");if(!i&&!r)throw new Error("At least one of textPrompt or imagePrompt is required.");return await t.sendMessage(n.ModalityVideoGen,{duration:e,textPrompt:i,imagePrompt:r,videoModelConfig:o}).then(e=>e)},isReady:i}}function R(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t({});return i(()=>{a&&r?.sendMessage(n.EditorGetEnv).then(e=>{d(e)})},[a]),{isReady:a,envs:s}}function E(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t(void 0),[c,u]=t(void 0);return i(()=>{a&&r?.sendMessage(n.PlatformCreateTerminal).then(e=>{const{websocketUrl:n,projectHomePath:t}=e;d(n),u(t)})},[a]),{websocketUrl:s,projectHomePath:c}}export{a as useAgentTools,s as useAgents,d as useCommand,c as useFileView,p as useImageGen,l as useLLM,u as useLoading,f as useNotification,y as useOCR,R as usePulseEnv,M as useSTT,g as useTTS,E as useTerminal,w as useTheme,m as useToolbar,h as useVideoGen};
1
+ import{InterModuleCommunication as e,IMCMessageTypeEnum as n}from"@pulse-editor/shared-utils";import{useState as t,useEffect as i,useRef as r}from"react";function o(r){const[o,a]=t(void 0),[s,d]=t(!1),[c,u]=t(!1),f=window.parent;return i(()=>(u(!0),()=>{u(!1),o?.close(),a(void 0)}),[]),i(()=>{!async function(){if(!c)return;if(void 0!==o)return;const t=new e;t.initThisWindow(window),t.updateReceiverHandlerMap(r),await t.initOtherWindow(f),a(t),t.sendMessage(n.AppReady).then(()=>{d(!0)})}()},[c,o]),{imc:o,isReady:s}}function a(){return o(new Map),{}}function s(){const e=new Map,{imc:t,isReady:i}=o(e);return{runAgentMethod:async function(e,i,r,o,a){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.EditorRunAgentMethod,{agentName:e,methodName:i,parameters:r,llmConfig:a},o).then(e=>e)},isReady:i}}function d(e,a,s,d,c,u=!0){const{isReady:f,imc:p}=o(M()),w=r([]),[m,l]=t({name:e,description:a,parameters:s,returns:d,handler:c});async function y(e){if(!m.handler)return;return await m.handler(e)}function M(){return new Map([[n.EditorRunAppAction,async(n,t)=>{const{name:i,args:r}=t.payload;if(e===i){const e=s;if(Object.keys(r).length!==Object.keys(e).length)throw new Error(`Invalid number of parameters: expected ${Object.keys(e).length}, got ${Object.keys(r).length}`);for(const[e,n]of Object.entries(r)){if(void 0===s[e])throw new Error(`Invalid parameter: ${e}`);if(typeof n!==s[e].type)throw new Error(`Invalid type for parameter ${e}: expected ${s[e].type}, got ${typeof n}. Value received: ${n}`)}return u?await y(r):new Promise(e=>{w.current.push({args:r,resolve:e})})}}]])}return i(()=>{if(u&&w.current.length>0){const e=[...w.current];w.current=[],e.forEach(async({args:e,resolve:n})=>{n(await y(e))})}},[u]),i(()=>{u&&async function(){await(p?.sendMessage(n.EditorRegisterAction,{name:m.name,description:m.description,parameters:m.parameters,returns:m.returns})),p?.updateReceiverHandlerMap(M())}()},[m,p,u]),i(()=>{l(n=>({...n,name:e,description:a,parameters:s,returns:d}))},[c]),{isReady:f}}function c(){const[e,r]=t(void 0),a=new Map,{imc:s,isReady:d}=o(a);return i(()=>{d&&s?.sendMessage(n.PlatformReadFile).then(e=>{r(e)})},[d]),{viewModel:e,updateViewModel:function(e){s?.sendMessage(n.PlatformWriteFile,e)}}}function u(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t(!0);return i(()=>{a&&r?.sendMessage(n.EditorLoadingApp,{isLoading:s})},[s]),{isReady:a,toggleLoading:function(e){d(n=>e)}}}function f(){const e=new Map,{imc:t}=o(e);return{openNotification:function(e,i){if(!t)throw new Error("IMC is not initialized.");t.sendMessage(n.EditorShowNotification,{text:e,type:i})}}}function p(){const[e,i]=t("light"),r=new Map;return r.set(n.EditorThemeUpdate,async(e,n)=>{const t=n.payload;i(e=>t)}),o(r),{theme:e}}function w(){return{}}function m(){const e=new Map,{imc:t,isReady:i}=o(e);return{runImageGen:async function(e,i,r){if(!t)throw new Error("IMC not initialized.");if(!e&&!i)throw new Error("At least one of textPrompt or imagePrompt is required.");return await t.sendMessage(n.ModalityImageGen,{textPrompt:e,imagePrompt:i,imageModelConfig:r}).then(e=>e)},isReady:i}}function l(){const e=new Map,{imc:t,isReady:i}=o(e);return{runLLM:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalityLLM,{prompt:e,llmConfig:i}).then(e=>e)},isReady:i}}function y(){const e=new Map,{imc:t}=o(e);return{recognizeText:async function(e){if(!t)throw new Error("IMC is not initialized.");return(await t.sendMessage(n.ModalityOCR,{image:e})).payload.text}}}function M(){const e=new Map,{imc:t,isReady:i}=o(e);return{runSTT:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalitySTT,{audio:e,sttConfig:i}).then(e=>e)},isReady:i}}function g(){const e=new Map,{imc:t,isReady:i}=o(e);return{runTTS:async function(e,i){if(!t)throw new Error("IMC not initialized.");return await t.sendMessage(n.ModalityTTS,{text:e,ttsConfig:i}).then(e=>e)},isReady:i}}function h(){const e=new Map,{imc:t,isReady:i}=o(e);return{runVideoGen:async function(e,i,r,o){if(!t)throw new Error("IMC not initialized.");if(!i&&!r)throw new Error("At least one of textPrompt or imagePrompt is required.");return await t.sendMessage(n.ModalityVideoGen,{duration:e,textPrompt:i,imagePrompt:r,videoModelConfig:o}).then(e=>e)},isReady:i}}function R(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t({});return i(()=>{a&&r?.sendMessage(n.EditorGetEnv).then(e=>{d(e)})},[a]),{isReady:a,envs:s}}function E(){const e=new Map,{imc:r,isReady:a}=o(e),[s,d]=t(void 0),[c,u]=t(void 0);return i(()=>{a&&r?.sendMessage(n.PlatformCreateTerminal).then(e=>{const{websocketUrl:n,projectHomePath:t}=e;d(n),u(t)})},[a]),{websocketUrl:s,projectHomePath:c}}export{a as useAgentTools,s as useAgents,d as useCommand,c as useFileView,m as useImageGen,l as useLLM,u as useLoading,f as useNotification,y as useOCR,R as usePulseEnv,M as useSTT,g as useTTS,E as useTerminal,p as useTheme,w as useToolbar,h as useVideoGen};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/react-api",
3
- "version": "0.1.1-alpha.36",
3
+ "version": "0.1.1-alpha.37",
4
4
  "main": "dist/main.js",
5
5
  "files": [
6
6
  "dist"
@@ -38,7 +38,7 @@
38
38
  "typescript-eslint": "^8.30.1"
39
39
  },
40
40
  "peerDependencies": {
41
- "@pulse-editor/shared-utils": "0.1.1-alpha.36",
41
+ "@pulse-editor/shared-utils": "0.1.1-alpha.37",
42
42
  "react": "^19.0.0",
43
43
  "react-dom": "^19.0.0"
44
44
  }
@@ -1,12 +0,0 @@
1
- import { CommandInfo } from "@pulse-editor/shared-utils";
2
- /**
3
- * Register an extension command to listen to IMC messages from the core,
4
- * and pass to the extension to handle.
5
- *
6
- * @param commandInfo Command information to register.
7
- * @param callbackHandler Callback handler function to handle the command.
8
- *
9
- */
10
- export default function useCommand(commandInfo: CommandInfo, callbackHandler?: (args: any) => Promise<string | void>, isExtReady?: boolean): {
11
- isReady: boolean;
12
- };