@pulse-editor/react-api 0.1.1-alpha.47 → 0.1.1-alpha.49

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.
@@ -1,5 +1,5 @@
1
1
  import { LLMConfig } from "@pulse-editor/shared-utils";
2
2
  export default function useAgents(): {
3
- runAgentMethod: (agentName: string, methodName: string, parameters: Record<string, any>, abortSignal?: AbortSignal, llmConfig?: LLMConfig) => Promise<any>;
3
+ runAgentMethod: (agentName: string, methodName: string, args: Record<string, any>, abortSignal?: AbortSignal, llmConfig?: LLMConfig) => Promise<any>;
4
4
  isReady: boolean;
5
5
  };
@@ -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,3 @@
1
+ export default function useReceiveFile(): {
2
+ receivedFileUri: string | undefined;
3
+ };
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 useFileView from "./hooks/editor/use-file-view";
3
+ import useFile from "./hooks/editor/use-file";
4
4
  import useLoading from "./hooks/editor/use-loading";
5
5
  import useNotification from "./hooks/editor/use-notification";
6
6
  import useRegisterAction from "./hooks/editor/use-register-action";
@@ -13,7 +13,9 @@ 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
15
  import usePulseEnv from "./hooks/editor/use-env";
16
+ import useReceiveFile from "./hooks/editor/use-receive-file";
16
17
  import useSnapshotState from "./hooks/editor/use-snapshot-state";
17
18
  import useTerminal from "./hooks/terminal/use-terminal";
19
+ import ReceiveFileProvider from "./providers/receive-file-provider";
18
20
  import SnapshotProvider from "./providers/snapshot-provider";
19
- export { SnapshotProvider, useAgentTools, useAgents, useFileView, useImageGen, useLLM, useLoading, useNotification, useOCR, usePulseEnv, useRegisterAction, useSTT, useSnapshotState, useTTS, useTerminal, useTheme, useToolbar, useVideoGen, };
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 t}from"@pulse-editor/shared-utils";import n,{useState as r,useEffect as i,useRef as o,createContext as a,useContext as s}from"react";function c(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 d(){return c(new Map),{}}function u(){const e=new Map,{imc:n,isReady:r}=c(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,parameters:i,llmConfig:a},o).then(e=>e)},isReady:r}}function p(){const[e,n]=r(void 0),o=new Map,{imc:a,isReady:s}=c(o);return i(()=>{s&&a?.sendMessage(t.PlatformReadFile).then(e=>{n(e)})},[s]),{viewModel:e,updateViewModel:function(e){a?.sendMessage(t.PlatformWriteFile,e)}}}function f(){const e=new Map,{imc:n,isReady:o}=c(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}=c(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,a,s=!0){const{isReady:d,imc:u}=c(l()),p=o([]),[f,m]=r({name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n});async function w(e){if(!f.handler)return;return await f.handler(e)}function l(){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 w(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 w(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(l())}()},[f,u,s]),i(()=>{m(t=>({...t,name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n}))},[...a]),{isReady:d}}function l(){const[e,n]=r("light"),i=new Map;return i.set(t.EditorThemeUpdate,async(e,t)=>{const r=t.payload;n(e=>r)}),c(i),{theme:e}}function y(){return{}}function M(){const e=new Map,{imc:n,isReady:r}=c(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 h(){const e=new Map,{imc:n,isReady:r}=c(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 g(){const e=new Map,{imc:n}=c(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}=c(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 v(){const e=new Map,{imc:n,isReady:r}=c(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 E(){const e=new Map,{imc:n,isReady:r}=c(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}=c(e),[a,s]=r({});return i(()=>{o&&n?.sendMessage(t.EditorGetEnv).then(e=>{s(e)})},[o]),{isReady:o,envs:a}}const P=a(void 0);function C({children:e}){const o=new Map([[t.EditorAppStateSnapshotRestore,async(e,t)=>{const{states:n}=t.payload;u(e=>({...n}))}],[t.EditorAppStateSnapshotSave,async(e,t)=>({states:d})]]),{imc:a,isReady:s}=c(o),[d,u]=r({});return i(()=>{s&&a?.updateReceiverHandlerMap(o)},[s,d]),n.createElement(P.Provider,{value:{states:d,setStates:u}},e)}function I(e,t,n){const a=s(P);if(!a)throw new Error("useSnapShotState must be used within a SnapshotProvider");const{states:c,setStates:d}=a,[u,p]=r(void 0!==c[e]?c[e]:t),f=o(!1);return i(()=>{void 0===c[e]&&void 0!==t&&d(n=>({...n,[e]:t}))},[]),i(()=>{const t=c[e];void 0!==t&&(f.current?f.current=!1:t!==u&&(console.log("Restoring state for key:",e,t),p(t),n?.(t)))},[c[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 T(){const e=new Map,{imc:n,isReady:o}=c(e),[a,s]=r(void 0),[d,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:d}}export{C as SnapshotProvider,d as useAgentTools,u as useAgents,p as useFileView,M as useImageGen,h as useLLM,f as useLoading,m as useNotification,g as useOCR,S as usePulseEnv,w as useRegisterAction,R as useSTT,I as useSnapshotState,v as useTTS,T as useTerminal,l as useTheme,y as useToolbar,E as useVideoGen};
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/react-api",
3
- "version": "0.1.1-alpha.47",
3
+ "version": "0.1.1-alpha.49",
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.47",
41
+ "@pulse-editor/shared-utils": "0.1.1-alpha.49",
42
42
  "react": "^19.0.0",
43
43
  "react-dom": "^19.0.0"
44
44
  }
@@ -1,5 +0,0 @@
1
- import { ViewModel } from "@pulse-editor/shared-utils";
2
- export default function useFileView(): {
3
- viewModel: ViewModel | undefined;
4
- updateViewModel: (viewModel: ViewModel) => void;
5
- };
File without changes