@pulse-editor/shared-utils 0.1.1-alpha.48 → 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.
- package/dist/imc/poly-imc.d.ts +3 -3
- package/dist/main.js +1 -1
- package/dist/types/types.d.ts +5 -2
- package/package.json +1 -1
package/dist/imc/poly-imc.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { IMCMessage, IMCMessageTypeEnum, ReceiverHandlerMap } from "../types/typ
|
|
|
7
7
|
* This assumes the other window has IMC or Poly-IMC setup.
|
|
8
8
|
*/
|
|
9
9
|
export declare class PolyIMC {
|
|
10
|
-
private
|
|
10
|
+
private channelsMap;
|
|
11
11
|
private baseReceiverHandlerMap;
|
|
12
12
|
private channelReceiverHandlerMapMap;
|
|
13
13
|
/**
|
|
@@ -16,11 +16,11 @@ export declare class PolyIMC {
|
|
|
16
16
|
* E.g. Pulse Editor API handler
|
|
17
17
|
*/
|
|
18
18
|
constructor(baseReceiverHandlerMap: ReceiverHandlerMap);
|
|
19
|
-
sendMessage(targetWindowId: string, handlingType: IMCMessageTypeEnum, payload?: any, abortSignal?: AbortSignal): Promise<any>;
|
|
19
|
+
sendMessage(targetWindowId: string, handlingType: IMCMessageTypeEnum, payload?: any, abortSignal?: AbortSignal): Promise<any[]>;
|
|
20
20
|
updateBaseReceiverHandlerMap(handlerMap: ReceiverHandlerMap): void;
|
|
21
21
|
updateChannelReceiverHandlerMap(targetWindowId: string, handlerMap: ReceiverHandlerMap): void;
|
|
22
22
|
createChannel(targetWindow: Window, targetWindowId: string, receiverHandlerMap?: ReceiverHandlerMap): Promise<void>;
|
|
23
|
-
|
|
23
|
+
removeWindowChannels(targetWindowId: string): void;
|
|
24
24
|
hasChannel(targetWindowId: string): boolean;
|
|
25
25
|
close(): void;
|
|
26
26
|
private getCombinedHandlerMap;
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=3e5;var t,n,i,r,s;function o(e){return Array.isArray(e)&&1===e.length}function a(e){return"object"==typeof e&&!Array.isArray(e)}!function(e){e.ModalityVAD="modality-vad",e.ModalitySTT="modality-stt",e.ModalityLLM="modality-llm",e.ModalityTTS="modality-tts",e.ModalitySpeech2Speech="modality-speech-to-speech",e.ModalityImageGen="modality-image-gen",e.ModalityVideoGen="modality-video-gen",e.ModalityOCR="modality-ocr",e.ModalityMusicGen="modality-music-gen",e.AppReady="app-ready",e.AppClose="app-close",e.EditorLoadingApp="editor-loading-app",e.EditorRegisterAction="editor-register-action",e.EditorRunAppAction="editor-run-app-action",e.EditorRunAgentMethod="editor-run-agent-method",e.EditorThemeUpdate="editor-theme-update",e.EditorShowNotification="editor-show-notification",e.EditorGetEnv="editor-get-env",e.EditorAppStateSnapshotRestore="editor-app-state-snapshot-restore",e.EditorAppStateSnapshotSave="editor-app-state-snapshot-save",e.PlatformCreateTerminal="platform-create-terminal",e.PlatformWriteFile="platform-write-file",e.PlatformReadFile="platform-read-file",e.SignalGetWindowId="signal-get-window-id",e.SignalReturnWindowId="signal-return-window-id",e.SignalAcknowledge="signal-acknowledge",e.SignalAbort="signal-abort",e.SignalError="signal-error"}(t||(t={})),function(e){e.App="app",e.Canvas="canvas",e.Home="home"}(n||(n={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(i||(i={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(r||(r={})),function(e){e.public="public",e.private="private"}(s||(s={}));class d{constructor(e,t){this.handlerMap=e,this.pendingTasks=new Map,this.windowId=t}receiveMessage(e,n){if(this.windowId===n.from)return;if(n.type===t.SignalAbort){const e=n.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(n.type);if(i){const r=new AbortController,s=r.signal;this.pendingTasks.set(n.id,{controller:r});i(e,n,s).then(i=>{s.aborted||n.type!==t.SignalAcknowledge&&this.acknowledgeSender(e,n.id,i)}).catch(i=>{const r={id:n.id,type:t.SignalError,payload:i.message,from:this.windowId};console.error("Error handling message:",i),e.postMessage(r,"*")}).finally(()=>{this.pendingTasks.delete(n.id)})}}acknowledgeSender(e,n,i){const r={id:n,type:t.SignalAcknowledge,payload:i,from:this.windowId};e.postMessage(r,"*")}}for(var l,h=[],c=0;c<256;++c)h.push((c+256).toString(16).slice(1));var w=new Uint8Array(16);var p={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function g(e,t,n){var i,r,s,o,a=null!==(i=null!==(r=(e=e||{}).random)&&void 0!==r?r:null===(s=(o=e).rng)||void 0===s?void 0:s.call(o))&&void 0!==i?i:function(){if(!l){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");l=crypto.getRandomValues.bind(crypto)}return l(w)}();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=15&a[6]|64,a[8]=63&a[8]|128,function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}(a)}class u{constructor(e,t,n){this.targetWindow=e,this.timeout=t,this.pendingMessages=new Map,this.moduleId=n}async sendMessage(e,n,i){const r=(p.randomUUID&&!s?p.randomUUID():g(s))+(new Date).getTime().toString();var s;const o={id:r,type:e,payload:n,from:this.moduleId};return new Promise((e,n)=>{if(i?.aborted)return n(new Error("Request aborted"));const s=()=>{this.pendingMessages.delete(r),this.targetWindow.postMessage({id:r,type:t.SignalAbort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),n(new Error("Request aborted"))};i?.addEventListener("abort",s);const a=setTimeout(()=>{this.pendingMessages.delete(r),i?.removeEventListener("abort",s),n(new Error("Communication with Pulse Editor timeout."))},this.timeout);this.pendingMessages.set(r,{resolve:t=>{clearTimeout(a),i?.removeEventListener("abort",s),this.pendingMessages.delete(r),e(t)},reject:e=>{clearTimeout(a),i?.removeEventListener("abort",s),this.pendingMessages.delete(r),n(e)}}),this.targetWindow.postMessage(o,"*")})}getPendingMessage(e){return this.pendingMessages.get(e)}}class M{initThisWindow(e,n){this.thisWindow=e;const i=e.viewId;if(!i)throw new Error("Current window's ID is not defined.");this.thisWindowId=i,this.receiverHandlerMap=new Map;const r=new d(this.receiverHandlerMap,this.thisWindowId);this.receiver=r,this.messageRecords=new Map,this.listener=e=>{const i=e.data.id,s=e.data.type;if(this.messageRecords?.has(i)&&s!==t.SignalGetWindowId)return void console.warn(`[${this.thisWindowId}]: Duplicate message received with message ID: ${i}. Ignoring this message. Message: ${JSON.stringify(e.data)}`);if(this.messageRecords?.set(i,e.data),!r)throw new Error("Receiver not initialized at module "+this.thisWindowId);const o=e.data;if(void 0!==o.from&&console.log(`Module ${this.thisWindowId} received message from module ${o.from}:\n ${JSON.stringify(o)}`),n&&o.from!==n)return;const a=e.source;r.receiveMessage(a,o)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.thisWindowId),this.setBaseHandler()}async initOtherWindow(n){return new Promise(i=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");this.thisWindow.addEventListener("message",t=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");const r=t.data.windowId;this.otherWindowId=r;const s=new u(n,e,this.thisWindowId);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.setBaseHandler(),i()},{once:!0}),this.otherWindow=n,this.otherWindow.postMessage({type:t.SignalGetWindowId,from:this.thisWindowId},"*")})}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,n){const i=this.sender;if(!i)throw new Error("Sender not initialized");return await i.sendMessage(e,t,n)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),this.setBaseHandler(),e.forEach((e,t)=>{this.receiverHandlerMap?.set(t,e)})}getThisWindowId(){if(!this.thisWindowId)throw new Error("This window ID is not defined.");return this.thisWindowId}getOtherWindowId(){if(!this.otherWindowId)throw new Error("Other window ID is not defined.");return this.otherWindowId}setBaseHandler(){this.receiverHandlerMap?.set(t.SignalAcknowledge,async(e,t)=>{const n=this.sender?.getPendingMessage(t.id);n&&n.resolve(t.payload)}),this.receiverHandlerMap?.set(t.SignalError,async(e,t)=>{const n=this.sender?.getPendingMessage(t.id);n&&n.reject(new Error(t.payload))}),this.receiverHandlerMap?.set(t.SignalGetWindowId,async(e,n)=>{console.log("Received window ID request. Sending current window ID to other window: ");const i=this.thisWindowId;if(!i)throw new Error("This window ID is not defined.");const r={id:n.id,type:t.SignalReturnWindowId,payload:{windowId:i},from:i};e.postMessage(r,"*")})}}class m{constructor(e){this.channels=new Map,this.baseReceiverHandlerMap=e,this.channelReceiverHandlerMapMap=new Map}async sendMessage(e,t,n,i){const r=this.channels.get(e);if(!r)throw new Error("Channel not found for window ID "+e);return await r.sendMessage(t,n,i)}updateBaseReceiverHandlerMap(e){this.baseReceiverHandlerMap=e,this.channels.forEach((e,t)=>{const n=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,this.channelReceiverHandlerMapMap.get(t));e.updateReceiverHandlerMap(n)})}updateChannelReceiverHandlerMap(e,t){const n=this.channels.get(e);if(!n)throw new Error("Channel not found for window ID "+e);const i=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,t);n.updateReceiverHandlerMap(i),this.channelReceiverHandlerMapMap.set(e,t)}async createChannel(e,t,n){console.log("Creating channel for window ID: "+t);const i=new M;i.initThisWindow(window,t),await i.initOtherWindow(e),this.channels.set(t,i),n?this.updateChannelReceiverHandlerMap(t,n):i.updateReceiverHandlerMap(this.baseReceiverHandlerMap)}removeChannel(e){const t=this.channels.get(e);if(!t)throw new Error("Channel not found for window ID "+e);t.close(),this.channels.delete(e),this.channelReceiverHandlerMapMap.delete(e)}hasChannel(e){return this.channels.has(e)}close(){this.channels.forEach(e=>{e.close()}),this.channels.clear(),this.channelReceiverHandlerMapMap.clear()}getCombinedHandlerMap(e,t){if(e&&t){return new Map([...e,...t])}return e||(t||new Map)}}class f{constructor(e,n,i,r){this.polyIMC=e,this.newConnectionReceiverHandlerMap=n,this.onConnection=i;const s=new M;this.listener=s,s.initThisWindow(window,r),s.updateReceiverHandlerMap(new Map([[t.AppReady,async(e,t,n)=>{this.handleExtReady(e,t,n)}]]))}close(){this.listener?.close()}updateReceiverHandlerMap(e){this.newConnectionReceiverHandlerMap=e}async handleExtReady(e,t,n){const i=t.from;this.polyIMC.hasChannel(i)?console.log("Channel already exists for window ID "+i+". Re-using the existing channel."):(await this.polyIMC.createChannel(e,i,this.newConnectionReceiverHandlerMap),this.onConnection&&this.onConnection(e,t))}}export{s as AccessEnum,r as AppTypeEnum,f as ConnectionListener,t as IMCMessageTypeEnum,M as InterModuleCommunication,d as MessageReceiver,u as MessageSender,i as NotificationTypeEnum,m as PolyIMC,n as ViewModeEnum,o as isArrayType,a as isObjectType,e as messageTimeout};
|
|
1
|
+
const e=3e5;var t,n,i,r,s;function o(e){return Array.isArray(e)&&1===e.length}function a(e){return"object"==typeof e&&!Array.isArray(e)}!function(e){e.ModalityVAD="modality-vad",e.ModalitySTT="modality-stt",e.ModalityLLM="modality-llm",e.ModalityTTS="modality-tts",e.ModalitySpeech2Speech="modality-speech-to-speech",e.ModalityImageGen="modality-image-gen",e.ModalityVideoGen="modality-video-gen",e.ModalityOCR="modality-ocr",e.ModalityMusicGen="modality-music-gen",e.AppReady="app-ready",e.AppClose="app-close",e.EditorLoadingApp="editor-loading-app",e.EditorRegisterAction="editor-register-action",e.EditorRunAppAction="editor-run-app-action",e.EditorRunAgentMethod="editor-run-agent-method",e.EditorThemeUpdate="editor-theme-update",e.EditorAppRequestTheme="editor-app-request-theme",e.EditorShowNotification="editor-show-notification",e.EditorGetEnv="editor-get-env",e.EditorAppStateSnapshotRestore="editor-app-state-snapshot-restore",e.EditorAppStateSnapshotSave="editor-app-state-snapshot-save",e.EditorAppReceiveFileUri="editor-app-receive-file-uri",e.PlatformCreateTerminal="platform-create-terminal",e.PlatformWriteFile="platform-write-file",e.PlatformReadFile="platform-read-file",e.PlatformFileUpdate="platform-file-update",e.SignalGetWindowId="signal-get-window-id",e.SignalReturnWindowId="signal-return-window-id",e.SignalAcknowledge="signal-acknowledge",e.SignalAbort="signal-abort",e.SignalError="signal-error"}(t||(t={})),function(e){e.App="app",e.Canvas="canvas",e.Home="home"}(n||(n={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(i||(i={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(r||(r={})),function(e){e.public="public",e.private="private"}(s||(s={}));class d{constructor(e,t){this.handlerMap=e,this.pendingTasks=new Map,this.windowId=t}receiveMessage(e,n){if(this.windowId===n.from)return;if(n.type===t.SignalAbort){const e=n.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(n.type);if(i){const r=new AbortController,s=r.signal;this.pendingTasks.set(n.id,{controller:r});i(e,n,s).then(i=>{s.aborted||n.type!==t.SignalAcknowledge&&this.acknowledgeSender(e,n.id,i)}).catch(i=>{const r={id:n.id,type:t.SignalError,payload:i.message,from:this.windowId};console.error("Error handling message:",i),e.postMessage(r,"*")}).finally(()=>{this.pendingTasks.delete(n.id)})}}acknowledgeSender(e,n,i){const r={id:n,type:t.SignalAcknowledge,payload:i,from:this.windowId};e.postMessage(r,"*")}}for(var l,h=[],c=0;c<256;++c)h.push((c+256).toString(16).slice(1));var p=new Uint8Array(16);var w={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function g(e,t,n){var i,r,s,o,a=null!==(i=null!==(r=(e=e||{}).random)&&void 0!==r?r:null===(s=(o=e).rng)||void 0===s?void 0:s.call(o))&&void 0!==i?i:function(){if(!l){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");l=crypto.getRandomValues.bind(crypto)}return l(p)}();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=15&a[6]|64,a[8]=63&a[8]|128,function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}(a)}class u{constructor(e,t,n){this.targetWindow=e,this.timeout=t,this.pendingMessages=new Map,this.moduleId=n}async sendMessage(e,n,i){const r=(w.randomUUID&&!s?w.randomUUID():g(s))+(new Date).getTime().toString();var s;const o={id:r,type:e,payload:n,from:this.moduleId};return new Promise((e,n)=>{if(i?.aborted)return n(new Error("Request aborted"));const s=()=>{this.pendingMessages.delete(r),this.targetWindow.postMessage({id:r,type:t.SignalAbort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),n(new Error("Request aborted"))};i?.addEventListener("abort",s);const a=setTimeout(()=>{this.pendingMessages.delete(r),i?.removeEventListener("abort",s),n(new Error("Communication with Pulse Editor timeout."))},this.timeout);this.pendingMessages.set(r,{resolve:t=>{clearTimeout(a),i?.removeEventListener("abort",s),this.pendingMessages.delete(r),e(t)},reject:e=>{clearTimeout(a),i?.removeEventListener("abort",s),this.pendingMessages.delete(r),n(e)}}),this.targetWindow.postMessage(o,"*")})}getPendingMessage(e){return this.pendingMessages.get(e)}}class M{initThisWindow(e,n){this.thisWindow=e;const i=e.viewId;if(!i)throw new Error("Current window's ID is not defined.");this.thisWindowId=i,this.receiverHandlerMap=new Map;const r=new d(this.receiverHandlerMap,this.thisWindowId);this.receiver=r,this.messageRecords=new Map,this.listener=e=>{const i=e.data.id,s=e.data.type;if(this.messageRecords?.has(i)&&s!==t.SignalGetWindowId)return void console.warn(`[${this.thisWindowId}]: Duplicate message received with message ID: ${i}. Ignoring this message. Message: ${JSON.stringify(e.data)}`);if(this.messageRecords?.set(i,e.data),!r)throw new Error("Receiver not initialized at module "+this.thisWindowId);const o=e.data;if(void 0!==o.from&&console.log(`Module ${this.thisWindowId} received message from module ${o.from}:\n ${o}`),n&&o.from!==n)return;const a=e.source;r.receiveMessage(a,o)},e.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.thisWindowId),this.setBaseHandler()}async initOtherWindow(n){return new Promise(i=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");this.thisWindow.addEventListener("message",t=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");const r=t.data.windowId;this.otherWindowId=r;const s=new u(n,e,this.thisWindowId);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.setBaseHandler(),i()},{once:!0}),this.otherWindow=n,this.otherWindow.postMessage({type:t.SignalGetWindowId,from:this.thisWindowId},"*")})}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,t,n){const i=this.sender;if(!i)throw new Error("Sender not initialized");return await i.sendMessage(e,t,n)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),this.setBaseHandler(),e.forEach((e,t)=>{this.receiverHandlerMap?.set(t,e)})}getThisWindowId(){if(!this.thisWindowId)throw new Error("This window ID is not defined.");return this.thisWindowId}getOtherWindowId(){if(!this.otherWindowId)throw new Error("Other window ID is not defined.");return this.otherWindowId}setBaseHandler(){this.receiverHandlerMap?.set(t.SignalAcknowledge,async(e,t)=>{const n=this.sender?.getPendingMessage(t.id);n&&n.resolve(t.payload)}),this.receiverHandlerMap?.set(t.SignalError,async(e,t)=>{const n=this.sender?.getPendingMessage(t.id);n&&n.reject(new Error(t.payload))}),this.receiverHandlerMap?.set(t.SignalGetWindowId,async(e,n)=>{console.log("Received window ID request. Sending current window ID to other window: ");const i=this.thisWindowId;if(!i)throw new Error("This window ID is not defined.");const r={id:n.id,type:t.SignalReturnWindowId,payload:{windowId:i},from:i};e.postMessage(r,"*")})}}class m{constructor(e){this.channelsMap=new Map,this.baseReceiverHandlerMap=e,this.channelReceiverHandlerMapMap=new Map}async sendMessage(e,t,n,i){const r=this.channelsMap.get(e);if(!r)throw new Error("Channel not found for window ID "+e);return await Promise.all(r.map(async e=>await e.sendMessage(t,n,i)))}updateBaseReceiverHandlerMap(e){this.baseReceiverHandlerMap=e,this.channelsMap.forEach((e,t)=>{const n=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,this.channelReceiverHandlerMapMap.get(t));e.forEach(e=>{e.updateReceiverHandlerMap(n)})})}updateChannelReceiverHandlerMap(e,t){const n=this.channelsMap.get(e);if(!n)throw new Error("Channel not found for window ID "+e);const i=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,t);n.forEach(e=>{e.updateReceiverHandlerMap(i)}),this.channelReceiverHandlerMapMap.set(e,t)}async createChannel(e,t,n){console.log("Creating channel for window ID: "+t);const i=new M;i.initThisWindow(window,t),await i.initOtherWindow(e);const r=this.channelsMap.get(t)??[];r.push(i),this.channelsMap.set(t,r),n?this.updateChannelReceiverHandlerMap(t,n):i.updateReceiverHandlerMap(this.baseReceiverHandlerMap)}removeWindowChannels(e){const t=this.channelsMap.get(e);if(!t)throw new Error("Channel not found for window ID "+e);t.forEach(e=>{e.close()}),this.channelsMap.delete(e),this.channelReceiverHandlerMapMap.delete(e)}hasChannel(e){return this.channelsMap.has(e)}close(){this.channelsMap.forEach(e=>e.forEach(e=>e.close())),this.channelsMap.clear(),this.channelReceiverHandlerMapMap.clear()}getCombinedHandlerMap(e,t){if(e&&t){return new Map([...e,...t])}return e||(t||new Map)}}class f{constructor(e,n,i,r){this.polyIMC=e,this.newConnectionReceiverHandlerMap=n,this.onConnection=i;const s=new M;this.listener=s,s.initThisWindow(window,r),s.updateReceiverHandlerMap(new Map([[t.AppReady,async(e,t,n)=>{this.handleExtReady(e,t,n)}]]))}close(){this.listener?.close()}updateReceiverHandlerMap(e){this.newConnectionReceiverHandlerMap=e}async handleExtReady(e,t,n){const i=t.from;this.polyIMC.hasChannel(i)?console.log("Channel already exists for window ID "+i+". Re-using the existing channel."):(await this.polyIMC.createChannel(e,i,this.newConnectionReceiverHandlerMap),this.onConnection&&this.onConnection(e,t))}}export{s as AccessEnum,r as AppTypeEnum,f as ConnectionListener,t as IMCMessageTypeEnum,M as InterModuleCommunication,d as MessageReceiver,u as MessageSender,i as NotificationTypeEnum,m as PolyIMC,n as ViewModeEnum,o as isArrayType,a as isObjectType,e as messageTimeout};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -15,13 +15,16 @@ export declare enum IMCMessageTypeEnum {
|
|
|
15
15
|
EditorRunAppAction = "editor-run-app-action",
|
|
16
16
|
EditorRunAgentMethod = "editor-run-agent-method",
|
|
17
17
|
EditorThemeUpdate = "editor-theme-update",
|
|
18
|
+
EditorAppRequestTheme = "editor-app-request-theme",
|
|
18
19
|
EditorShowNotification = "editor-show-notification",
|
|
19
20
|
EditorGetEnv = "editor-get-env",
|
|
20
21
|
EditorAppStateSnapshotRestore = "editor-app-state-snapshot-restore",
|
|
21
22
|
EditorAppStateSnapshotSave = "editor-app-state-snapshot-save",
|
|
23
|
+
EditorAppReceiveFileUri = "editor-app-receive-file-uri",
|
|
22
24
|
PlatformCreateTerminal = "platform-create-terminal",
|
|
23
25
|
PlatformWriteFile = "platform-write-file",
|
|
24
26
|
PlatformReadFile = "platform-read-file",
|
|
27
|
+
PlatformFileUpdate = "platform-file-update",
|
|
25
28
|
SignalGetWindowId = "signal-get-window-id",
|
|
26
29
|
SignalReturnWindowId = "signal-return-window-id",
|
|
27
30
|
SignalAcknowledge = "signal-acknowledge",
|
|
@@ -69,7 +72,7 @@ export type AppConfig = {
|
|
|
69
72
|
id: string;
|
|
70
73
|
version: string;
|
|
71
74
|
libVersion?: string;
|
|
72
|
-
visibility?:
|
|
75
|
+
visibility?: "public" | "private" | "unlisted";
|
|
73
76
|
author?: string;
|
|
74
77
|
displayName?: string;
|
|
75
78
|
description?: string;
|
|
@@ -129,7 +132,7 @@ export type AgentTool = {
|
|
|
129
132
|
parameters: Record<string, TypedVariable>;
|
|
130
133
|
returns: Record<string, TypedVariable>;
|
|
131
134
|
};
|
|
132
|
-
export type TypedVariableType = "string" | "number" | "boolean" | "any" | TypedVariableObjectType | TypedVariableArrayType;
|
|
135
|
+
export type TypedVariableType = "string" | "number" | "boolean" | "any" | "app-instance" | TypedVariableObjectType | TypedVariableArrayType;
|
|
133
136
|
export type TypedVariableObjectType = {
|
|
134
137
|
[key: string]: TypedVariable;
|
|
135
138
|
};
|