@pulse-editor/shared-utils 0.1.1-alpha.3 → 0.1.1-alpha.5
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/main.d.ts +6 -5
- package/dist/main.js +1 -1
- package/package.json +2 -3
- package/dist/main.es.js +0 -1
- package/src/main.ts +0 -6
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InterModuleCommunication } from "./imc/inter-module-communication";
|
|
2
|
+
import { MessageSender } from "./imc/message-sender";
|
|
3
|
+
import { MessageReceiver } from "./imc/message-receiver";
|
|
4
|
+
import { AccessEnum, Agent, AgentMethod, AgentTool, AgentVariable, AgentVariableType, ExtensionConfig, ExtensionTypeEnum, FetchPayload, FileViewModel, IMCMessage, IMCMessageTypeEnum, LLMConfig, NotificationTypeEnum, ReceiverHandlerMap, TextFileSelection } from "./types/types";
|
|
5
|
+
import { messageTimeout } from "./types/constants";
|
|
6
|
+
export { InterModuleCommunication, MessageSender, MessageReceiver, AccessEnum, Agent, AgentMethod, AgentTool, AgentVariable, AgentVariableType, ExtensionConfig, ExtensionTypeEnum, FetchPayload, FileViewModel, IMCMessage, IMCMessageTypeEnum, LLMConfig, NotificationTypeEnum, ReceiverHandlerMap, TextFileSelection, messageTimeout, };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e,t,s,i;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(t||(t={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(s||(s={})),function(e){e.public="public",e.private="private"}(i||(i={}));const n=3e5;class r{constructor(e,t,s){this.handlerMap=e,this.pendingTasks=t,this.moduleName=s}receiveMessage(t,s){if(this.moduleName===s.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${s.from}:\n ${JSON.stringify(s)}`),s.type===e.Abort){const e=s.id,t=this.pendingTasks.get(e);return void(t&&(console.log("Aborting task",e),t.controller.abort(),this.pendingTasks.delete(e)))}const i=this.handlerMap.get(s.type);if(i){const n=new AbortController,r=n.signal;this.pendingTasks.set(s.id,{controller:n});i(t,s,r).then((i=>{r.aborted||s.type!==e.Acknowledge&&this.acknowledgeSender(t,s.id,i)})).catch((i=>{const n={id:s.id,type:e.Error,payload:i.message,from:this.moduleName};t.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(s.id)}))}}acknowledgeSender(t,s,i){const n={id:s,type:e.Acknowledge,payload:i,from:this.moduleName};t.postMessage(n,"*")}}class o{constructor(e,t,s,i){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=i}async sendMessage(t,s,i){const n=(new Date).getTime().toString(),r={id:n,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(i?.aborted)return s(new Error("Request aborted"));const o=()=>{this.pendingMessages.delete(n),this.targetWindow.postMessage({id:n,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};i?.addEventListener("abort",o),this.pendingMessages.set(n,{resolve:t,reject:s}),this.targetWindow.postMessage(r,"*");const a=setTimeout((()=>{this.pendingMessages.delete(n),i?.removeEventListener("abort",o),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(n);d&&(d.resolve=e=>{clearTimeout(a),i?.removeEventListener("abort",o),t(e)},d.reject=()=>{clearTimeout(a),i?.removeEventListener("abort",o),s()})}))}}class a{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const t=new r(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=t,this.listener=e=>{if(!t)throw new Error("Receiver not initialized at module "+this.moduleName);const s=e.data,i=e.source;t.receiveMessage(i,s)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(t){this.otherWindow=t,this.otherPendingMessages=new Map;const s=new o(t,n,this.otherPendingMessages,this.moduleName);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,t)=>{const s=this.otherPendingMessages?.get(t.id);s&&(s.resolve(t.payload),this.otherPendingMessages?.delete(t.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,s){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,t,s)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,t)=>{this.receiverHandlerMap?.set(t,e)}))}}export{i as AccessEnum,s as ExtensionTypeEnum,e as IMCMessageTypeEnum,a as InterModuleCommunication,r as MessageReceiver,o as MessageSender,t as NotificationTypeEnum,n as messageTimeout};
|
package/package.json
CHANGED
package/dist/main.es.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,t,s,i;!function(e){e.WriteViewFile="write-view-file",e.RequestViewFile="request-view-file",e.Fetch="fetch",e.Notification="notification",e.ThemeChange="theme-change",e.InstallAgent="install-agent",e.RunAgentMethod="run-agent-method",e.InstallAgentTool="install-agent-tool",e.OCR="ocr",e.RequestTerminal="request-terminal",e.Ready="ready",e.Loaded="loaded",e.Acknowledge="acknowledge",e.Abort="abort",e.Error="error"}(e||(e={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(t||(t={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(s||(s={})),function(e){e.public="public",e.private="private"}(i||(i={}));const n=3e5;class r{constructor(e,t,s){this.handlerMap=e,this.pendingTasks=t,this.moduleName=s}receiveMessage(t,s){if(this.moduleName===s.from)return;if("development"===process.env.NODE_ENV&&console.log(`Module ${this.moduleName} received message from module ${s.from}:\n ${JSON.stringify(s)}`),s.type===e.Abort){const e=s.id,t=this.pendingTasks.get(e);return void(t&&(console.log("Aborting task",e),t.controller.abort(),this.pendingTasks.delete(e)))}const i=this.handlerMap.get(s.type);if(i){const n=new AbortController,r=n.signal;this.pendingTasks.set(s.id,{controller:n});i(t,s,r).then((i=>{r.aborted||s.type!==e.Acknowledge&&this.acknowledgeSender(t,s.id,i)})).catch((i=>{const n={id:s.id,type:e.Error,payload:i.message,from:this.moduleName};t.postMessage(n,"*")})).finally((()=>{this.pendingTasks.delete(s.id)}))}}acknowledgeSender(t,s,i){const n={id:s,type:e.Acknowledge,payload:i,from:this.moduleName};t.postMessage(n,"*")}}class o{constructor(e,t,s,i){this.targetWindow=e,this.timeout=t,this.pendingMessages=s,this.moduleName=i}async sendMessage(t,s,i){const n=(new Date).getTime().toString(),r={id:n,type:t,payload:s,from:this.moduleName};return new Promise(((t,s)=>{if(i?.aborted)return s(new Error("Request aborted"));const o=()=>{this.pendingMessages.delete(n),this.targetWindow.postMessage({id:n,type:e.Abort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),s(new Error("Request aborted"))};i?.addEventListener("abort",o),this.pendingMessages.set(n,{resolve:t,reject:s}),this.targetWindow.postMessage(r,"*");const a=setTimeout((()=>{this.pendingMessages.delete(n),i?.removeEventListener("abort",o),s(new Error("Communication with Pulse Editor timeout."))}),this.timeout),d=this.pendingMessages.get(n);d&&(d.resolve=e=>{clearTimeout(a),i?.removeEventListener("abort",o),t(e)},d.reject=()=>{clearTimeout(a),i?.removeEventListener("abort",o),s()})}))}}class a{constructor(e){this.moduleName=e}initThisWindow(e){this.thisWindow=e,this.receiverHandlerMap=new Map,this.thisPendingTasks=new Map;const t=new r(this.receiverHandlerMap,this.thisPendingTasks,this.moduleName);this.receiver=t,this.listener=e=>{if(!t)throw new Error("Receiver not initialized at module "+this.moduleName);const s=e.data,i=e.source;t.receiveMessage(i,s)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.moduleName)}initOtherWindow(t){this.otherWindow=t,this.otherPendingMessages=new Map;const s=new o(t,n,this.otherPendingMessages,this.moduleName);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.receiverHandlerMap.set(e.Acknowledge,(async(e,t)=>{const s=this.otherPendingMessages?.get(t.id);s&&(s.resolve(t.payload),this.otherPendingMessages?.delete(t.id))}))}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,s){if(!this.sender)throw new Error("Sender not initialized");return await this.sender.sendMessage(e,t,s)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),e.forEach(((e,t)=>{this.receiverHandlerMap?.set(t,e)}))}}export{i as AccessEnum,s as ExtensionTypeEnum,e as IMCMessageTypeEnum,a as InterModuleCommunication,r as MessageReceiver,o as MessageSender,t as NotificationTypeEnum,n as messageTimeout};
|