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

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.
@@ -7,6 +7,6 @@ import { CommandInfo } from "@pulse-editor/shared-utils";
7
7
  * @param callbackHandler Callback handler function to handle the command.
8
8
  *
9
9
  */
10
- export default function useCommand(commandInfo: CommandInfo, callbackHandler?: (args: any) => Promise<string | void>): {
10
+ export default function useCommand(commandInfo: CommandInfo, callbackHandler?: (args: any) => Promise<string | void>, isExtReady?: boolean): {
11
11
  isReady: boolean;
12
12
  };
@@ -0,0 +1,4 @@
1
+ export default function usePulseEnv(): {
2
+ isReady: boolean;
3
+ envs: Record<string, string>;
4
+ };
package/dist/main.d.ts CHANGED
@@ -1,16 +1,17 @@
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
4
  import useFileView from "./hooks/editor/use-file-view";
4
5
  import useLoading from "./hooks/editor/use-loading";
5
6
  import useNotification from "./hooks/editor/use-notification";
6
7
  import useTheme from "./hooks/editor/use-theme";
7
8
  import useToolbar from "./hooks/editor/use-toolbar";
8
- import useCommand from "./hooks/editor/use-command";
9
9
  import useImageGen from "./hooks/ai-modality/use-image-gen";
10
10
  import useLLM from "./hooks/ai-modality/use-llm";
11
11
  import useOCR from "./hooks/ai-modality/use-ocr";
12
12
  import useSTT from "./hooks/ai-modality/use-stt";
13
13
  import useTTS from "./hooks/ai-modality/use-tts";
14
14
  import useVideoGen from "./hooks/ai-modality/use-video-gen";
15
+ import usePulseEnv from "./hooks/editor/use-env";
15
16
  import useTerminal from "./hooks/terminal/use-terminal";
16
- export { useAgentTools, useAgents, useFileView, useNotification, useTheme, useToolbar, useImageGen, useVideoGen, useLLM, useOCR, useSTT, useTTS, useCommand, useTerminal, useLoading, };
17
+ export { useAgentTools, useAgents, 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 t}from"@pulse-editor/shared-utils";import{useState as n,useEffect as i}from"react";function r(r){const[o,a]=n(void 0),[s,d]=n(!1),[c,u]=n(!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 n=new e;n.initThisWindow(window),n.updateReceiverHandlerMap(r),await n.initOtherWindow(f),a(n),n.sendMessage(t.ExtReady).then(()=>{d(!0)})}()},[c,o]),{imc:o,isReady:s}}function o(){return r(new Map),{}}function a(){const e=new Map,{imc:n,isReady:i}=r(e);return{runAgentMethod:async function(e,i,r,o,a){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.EditorRunAgentMethod,{agentName:e,methodName:i,parameters:r,llmConfig:a},o).then(e=>e)},isReady:i}}function s(){const[e,o]=n(void 0),a=new Map,{imc:s,isReady:d}=r(a);return i(()=>{d&&s?.sendMessage(t.PlatformReadFile).then(e=>{o(e)})},[d]),{viewModel:e,updateViewModel:function(e){s?.sendMessage(t.PlatformWriteFile,e)}}}function d(){const e=new Map,{imc:o,isReady:a}=r(e),[s,d]=n(!0);return i(()=>{a&&o?.sendMessage(t.EditorLoadingExt,{isLoading:s})},[s]),{isReady:a,toggleLoading:function(e){d(t=>e)}}}function c(){const e=new Map,{imc:n}=r(e);return{openNotification:function(e,i){if(!n)throw new Error("IMC is not initialized.");n.sendMessage(t.EditorShowNotification,{text:e,type:i})}}}function u(){const[e,i]=n("light"),o=new Map;return o.set(t.EditorThemeUpdate,async(e,t)=>{const n=t.payload;i(e=>n)}),r(o),{theme:e}}function f(){return{}}function w(e,o){const{isReady:a,imc:s}=r(u()),[d,c]=n(void 0);function u(){return new Map([[t.EditorRunExtCommand,async(t,n)=>{if(!e)throw new Error("Extension command is not available");const{name:i,args:r}=n.payload;if(i===e.name){const t=e.parameters;if(Object.keys(r).length!==Object.keys(t).length)throw new Error(`Invalid number of parameters: expected ${Object.keys(t).length}, got ${Object.keys(r).length}`);for(const[t,n]of Object.entries(r)){if(void 0===e.parameters[t])throw new Error(`Invalid parameter: ${t}`);if(typeof n!==e.parameters[t].type)throw new Error(`Invalid type for parameter ${t}: expected ${e.parameters[t].type}, got ${typeof n}. Value received: ${n}`)}if(d){const e=await d(r);if(e)return e}}}]])}return i(()=>{s?.updateReceiverHandlerMap(u())},[d,s]),i(()=>{c(()=>o)},[o]),{isReady:a}}function m(){const e=new Map,{imc:n,isReady:i}=r(e);return{runImageGen:async function(e,i,r){if(!n)throw new Error("IMC not initialized.");if(!e&&!i)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityImageGen,{textPrompt:e,imagePrompt:i,imageModelConfig:r}).then(e=>e)},isReady:i}}function p(){const e=new Map,{imc:n,isReady:i}=r(e);return{runLLM:async function(e,i){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityLLM,{prompt:e,llmConfig:i}).then(e=>e)},isReady:i}}function l(){const e=new Map,{imc:n}=r(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 M(){const e=new Map,{imc:n,isReady:i}=r(e);return{runSTT:async function(e,i){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalitySTT,{audio:e,sttConfig:i}).then(e=>e)},isReady:i}}function y(){const e=new Map,{imc:n,isReady:i}=r(e);return{runTTS:async function(e,i){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityTTS,{text:e,ttsConfig:i}).then(e=>e)},isReady:i}}function g(){const e=new Map,{imc:n,isReady:i}=r(e);return{runVideoGen:async function(e,i,r,o){if(!n)throw new Error("IMC not initialized.");if(!i&&!r)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityVideoGen,{duration:e,textPrompt:i,imagePrompt:r,videoModelConfig:o}).then(e=>e)},isReady:i}}function h(){const e=new Map,{imc:o,isReady:a}=r(e),[s,d]=n(void 0),[c,u]=n(void 0);return i(()=>{a&&o?.sendMessage(t.PlatformCreateTerminal).then(e=>{const{websocketUrl:t,projectHomePath:n}=e;d(t),u(n)})},[a]),{websocketUrl:s,projectHomePath:c}}export{o as useAgentTools,a as useAgents,w as useCommand,s as useFileView,m as useImageGen,p as useLLM,d as useLoading,c as useNotification,l as useOCR,M as useSTT,y as useTTS,h as useTerminal,u as useTheme,f as useToolbar,g 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.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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/react-api",
3
- "version": "0.1.1-alpha.34",
3
+ "version": "0.1.1-alpha.36",
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.34",
41
+ "@pulse-editor/shared-utils": "0.1.1-alpha.36",
42
42
  "react": "^19.0.0",
43
43
  "react-dom": "^19.0.0"
44
44
  }