@pulse-editor/shared-utils 0.1.1-alpha.4 → 0.1.1-alpha.40
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/inter-module-communication.d.ts +14 -6
- package/dist/imc/message-receiver.d.ts +2 -4
- package/dist/imc/message-sender.d.ts +6 -4
- package/dist/imc/poly-imc.d.ts +37 -0
- package/dist/main.d.ts +5 -4
- package/dist/main.js +1 -1
- package/dist/types/types.d.ts +91 -48
- package/package.json +4 -2
|
@@ -2,17 +2,25 @@ import { IMCMessageTypeEnum, ReceiverHandlerMap } from "../types/types";
|
|
|
2
2
|
export declare class InterModuleCommunication {
|
|
3
3
|
private thisWindow;
|
|
4
4
|
private otherWindow;
|
|
5
|
-
private thisPendingTasks;
|
|
6
|
-
private otherPendingMessages;
|
|
7
5
|
private receiver;
|
|
8
6
|
private sender;
|
|
9
|
-
private
|
|
7
|
+
private thisWindowId;
|
|
8
|
+
private otherWindowId;
|
|
10
9
|
private receiverHandlerMap;
|
|
11
10
|
private listener;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
private messageRecords;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize a receiver to receive message.
|
|
14
|
+
* @param window The current window.
|
|
15
|
+
* @param otherWindowId The ID of the other window. This is optional and can be undefined.
|
|
16
|
+
* When defined, the receiver will only receive messages from window with the ID.
|
|
17
|
+
*/
|
|
18
|
+
initThisWindow(window: Window, otherWindowId?: string): void;
|
|
19
|
+
initOtherWindow(window: Window): Promise<void>;
|
|
15
20
|
close(): void;
|
|
16
21
|
sendMessage(type: IMCMessageTypeEnum, payload?: any, abortSignal?: AbortSignal): Promise<any>;
|
|
17
22
|
updateReceiverHandlerMap(receiverHandlerMap: ReceiverHandlerMap): void;
|
|
23
|
+
getThisWindowId(): string;
|
|
24
|
+
getOtherWindowId(): string;
|
|
25
|
+
private setBaseHandler;
|
|
18
26
|
}
|
|
@@ -2,10 +2,8 @@ import { IMCMessage, ReceiverHandlerMap } from "../types/types";
|
|
|
2
2
|
export declare class MessageReceiver {
|
|
3
3
|
private handlerMap;
|
|
4
4
|
private pendingTasks;
|
|
5
|
-
private
|
|
6
|
-
constructor(listenerMap: ReceiverHandlerMap,
|
|
7
|
-
controller: AbortController;
|
|
8
|
-
}>, moduleInfo: string);
|
|
5
|
+
private windowId;
|
|
6
|
+
constructor(listenerMap: ReceiverHandlerMap, windowId: string);
|
|
9
7
|
receiveMessage(senderWindow: Window, message: IMCMessage): void;
|
|
10
8
|
private acknowledgeSender;
|
|
11
9
|
}
|
|
@@ -3,10 +3,12 @@ export declare class MessageSender {
|
|
|
3
3
|
private targetWindow;
|
|
4
4
|
private timeout;
|
|
5
5
|
private pendingMessages;
|
|
6
|
-
private
|
|
7
|
-
constructor(targetWindow: Window, timeout: number,
|
|
6
|
+
private moduleId;
|
|
7
|
+
constructor(targetWindow: Window, timeout: number, moduleId: string);
|
|
8
|
+
sendMessage(handlingType: IMCMessageTypeEnum, payload?: any, abortSignal?: AbortSignal): Promise<any>;
|
|
9
|
+
getPendingMessage(id: string): {
|
|
8
10
|
resolve: (result: any) => void;
|
|
9
11
|
reject: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
+
} | undefined;
|
|
13
|
+
removePendingMessage(id: string): void;
|
|
12
14
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IMCMessage, IMCMessageTypeEnum, ReceiverHandlerMap } from "../types/types";
|
|
2
|
+
/**
|
|
3
|
+
* Poly IMC establishes two-way inter-module communication channels,
|
|
4
|
+
* where each channel consists of a sender and a receiver to send and
|
|
5
|
+
* receive messages between host window and the other module's window.
|
|
6
|
+
*
|
|
7
|
+
* This assumes the other window has IMC or Poly-IMC setup.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PolyIMC {
|
|
10
|
+
private channels;
|
|
11
|
+
private baseReceiverHandlerMap;
|
|
12
|
+
private channelReceiverHandlerMapMap;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param baseReceiverHandlerMap A base receiver handler map for universal handlers.
|
|
16
|
+
* E.g. Pulse Editor API handler
|
|
17
|
+
*/
|
|
18
|
+
constructor(baseReceiverHandlerMap: ReceiverHandlerMap);
|
|
19
|
+
sendMessage(targetWindowId: string, handlingType: IMCMessageTypeEnum, payload?: any, abortSignal?: AbortSignal): Promise<any>;
|
|
20
|
+
updateBaseReceiverHandlerMap(handlerMap: ReceiverHandlerMap): void;
|
|
21
|
+
updateChannelReceiverHandlerMap(targetWindowId: string, handlerMap: ReceiverHandlerMap): void;
|
|
22
|
+
createChannel(targetWindow: Window, targetWindowId: string, receiverHandlerMap?: ReceiverHandlerMap): Promise<void>;
|
|
23
|
+
removeChannel(targetWindowId: string): void;
|
|
24
|
+
hasChannel(targetWindowId: string): boolean;
|
|
25
|
+
close(): void;
|
|
26
|
+
private getCombinedHandlerMap;
|
|
27
|
+
}
|
|
28
|
+
export declare class ConnectionListener {
|
|
29
|
+
private polyIMC;
|
|
30
|
+
private newConnectionReceiverHandlerMap;
|
|
31
|
+
private onConnection?;
|
|
32
|
+
private listener;
|
|
33
|
+
constructor(polyIMC: PolyIMC, newConnectionReceiverHandlerMap: ReceiverHandlerMap, onConnection?: (senderWindow: Window, message: IMCMessage) => void);
|
|
34
|
+
close(): void;
|
|
35
|
+
updateReceiverHandlerMap(newReceiverHandlerMap: ReceiverHandlerMap): void;
|
|
36
|
+
private handleExtReady;
|
|
37
|
+
}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InterModuleCommunication } from "./imc/inter-module-communication";
|
|
2
|
-
import { MessageSender } from "./imc/message-sender";
|
|
3
2
|
import { MessageReceiver } from "./imc/message-receiver";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
export
|
|
3
|
+
import { MessageSender } from "./imc/message-sender";
|
|
4
|
+
import { ConnectionListener, PolyIMC } from "./imc/poly-imc";
|
|
5
|
+
export * from "./types/constants";
|
|
6
|
+
export * from "./types/types";
|
|
7
|
+
export { ConnectionListener, InterModuleCommunication, MessageReceiver, MessageSender, PolyIMC, };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t,s
|
|
1
|
+
var e,i,n,t,s;function r(e){return Array.isArray(e)&&1===e.length}function o(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.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"}(e||(e={})),function(e){e.App="app",e.Canvas="canvas",e.Home="home"}(i||(i={})),function(e){e.Success="success",e.Error="error",e.Info="info",e.Warning="warning"}(n||(n={})),function(e){e.Generic="generic",e.FileView="file-view",e.ConsoleView="console-view"}(t||(t={})),function(e){e.public="public",e.private="private"}(s||(s={}));const a=3e5;class d{constructor(e,i){this.handlerMap=e,this.pendingTasks=new Map,this.windowId=i}receiveMessage(i,n){if(this.windowId===n.from)return;if(n.type===e.SignalAbort){const e=n.id,i=this.pendingTasks.get(e);return void(i&&(console.log("Aborting task",e),i.controller.abort(),this.pendingTasks.delete(e)))}const t=this.handlerMap.get(n.type);if(t){const s=new AbortController,r=s.signal;this.pendingTasks.set(n.id,{controller:s});t(i,n,r).then(t=>{r.aborted||n.type!==e.SignalAcknowledge&&this.acknowledgeSender(i,n.id,t)}).catch(t=>{const s={id:n.id,type:e.SignalError,payload:t.message,from:this.windowId};console.error("Error handling message:",t),i.postMessage(s,"*")}).finally(()=>{this.pendingTasks.delete(n.id)})}}acknowledgeSender(i,n,t){const s={id:n,type:e.SignalAcknowledge,payload:t,from:this.windowId};i.postMessage(s,"*")}}class l{constructor(e,i,n){this.targetWindow=e,this.timeout=i,this.pendingMessages=new Map,this.moduleId=n}async sendMessage(i,n,t){const s=(new Date).getTime().toString(),r={id:s,type:i,payload:n,from:this.moduleId};return new Promise((i,n)=>{if(t?.aborted)return n(new Error("Request aborted"));const o=()=>{this.pendingMessages.delete(s),this.targetWindow.postMessage({id:s,type:e.SignalAbort,payload:JSON.stringify({status:"Task aborted",data:null})},"*"),n(new Error("Request aborted"))};t?.addEventListener("abort",o),this.pendingMessages.set(s,{resolve:i,reject:n}),this.targetWindow.postMessage(r,"*");const a=setTimeout(()=>{this.pendingMessages.delete(s),t?.removeEventListener("abort",o),n(new Error("Communication with Pulse Editor timeout."))},this.timeout),d=this.pendingMessages.get(s);d&&(d.resolve=e=>{clearTimeout(a),t?.removeEventListener("abort",o),i(e)},d.reject=()=>{clearTimeout(a),t?.removeEventListener("abort",o),n()})})}getPendingMessage(e){return this.pendingMessages.get(e)}removePendingMessage(e){this.pendingMessages.delete(e)}}class h{initThisWindow(i,n){this.thisWindow=i;const t=i.viewId;if(!t)throw new Error("Current window's ID is not defined.");this.thisWindowId=t,this.receiverHandlerMap=new Map;const s=new d(this.receiverHandlerMap,this.thisWindowId);this.receiver=s,this.messageRecords=new Map,this.listener=i=>{const t=i.data.id,r=i.data.type;if(this.messageRecords?.has(t)&&r!==e.SignalGetWindowId)return void console.warn(`Duplicate message received with message ID: ${t}. Ignoring this message. Message: ${JSON.stringify(i.data)}`);if(this.messageRecords?.set(t,i.data),!s)throw new Error("Receiver not initialized at module "+this.thisWindowId);const o=i.data;if("development"===process.env.NODE_ENV&&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=i.source;s.receiveMessage(a,o)},i.addEventListener("message",this.listener),console.log("Adding IMC listener in "+this.thisWindowId),this.setBaseHandler()}async initOtherWindow(i){return new Promise(n=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");this.thisWindow.addEventListener("message",e=>{if(!this.thisWindow||!this.thisWindowId)throw new Error("You must initialize the current window first.");const t=e.data.windowId;this.otherWindowId=t;const s=new l(i,a,this.thisWindowId);if(this.sender=s,!this.receiverHandlerMap)throw new Error("You must initialize the current window first.");this.setBaseHandler(),n()},{once:!0}),this.otherWindow=i,this.otherWindow.postMessage({type:e.SignalGetWindowId,from:this.thisWindowId},"*")})}close(){this.listener&&window.removeEventListener("message",this.listener)}async sendMessage(e,i,n){const t=this.sender;if(!t)throw new Error("Sender not initialized");return await t.sendMessage(e,i,n)}updateReceiverHandlerMap(e){if(!this.receiver)throw new Error("Receiver not initialized");this.receiverHandlerMap?.clear(),this.setBaseHandler(),e.forEach((e,i)=>{this.receiverHandlerMap?.set(i,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(e.SignalAcknowledge,async(e,i)=>{const n=this.sender?.getPendingMessage(i.id);n&&(n.resolve(i.payload),this.sender?.removePendingMessage(i.id))}),this.receiverHandlerMap?.set(e.SignalGetWindowId,async(i,n)=>{console.log("Received window ID request. Sending current window ID to other window: ");const t=this.thisWindowId;if(!t)throw new Error("This window ID is not defined.");const s={id:n.id,type:e.SignalReturnWindowId,payload:{windowId:t},from:t};i.postMessage(s,"*")})}}class c{constructor(e){this.channels=new Map,this.baseReceiverHandlerMap=e,this.channelReceiverHandlerMapMap=new Map}async sendMessage(e,i,n,t){const s=this.channels.get(e);if(!s)throw new Error("Channel not found for window ID "+e);return await s.sendMessage(i,n,t)}updateBaseReceiverHandlerMap(e){this.baseReceiverHandlerMap=e,this.channels.forEach((e,i)=>{const n=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,this.channelReceiverHandlerMapMap.get(i));e.updateReceiverHandlerMap(n)})}updateChannelReceiverHandlerMap(e,i){const n=this.channels.get(e);if(!n)throw new Error("Channel not found for window ID "+e);const t=this.getCombinedHandlerMap(this.baseReceiverHandlerMap,i);n.updateReceiverHandlerMap(t),this.channelReceiverHandlerMapMap.set(e,i)}async createChannel(e,i,n){console.log("Creating channel for window ID: "+i);const t=new h;t.initThisWindow(window,i),await t.initOtherWindow(e),this.channels.set(i,t),n?this.updateChannelReceiverHandlerMap(i,n):t.updateReceiverHandlerMap(this.baseReceiverHandlerMap)}removeChannel(e){const i=this.channels.get(e);if(!i)throw new Error("Channel not found for window ID "+e);i.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,i){if(e&&i){return new Map([...e,...i])}return e||(i||new Map)}}class w{constructor(i,n,t){this.polyIMC=i,this.newConnectionReceiverHandlerMap=n,this.onConnection=t;const s=new h;this.listener=s,s.initThisWindow(window),s.updateReceiverHandlerMap(new Map([[e.AppReady,async(e,i,n)=>{this.handleExtReady(e,i,n)}]]))}close(){this.listener?.close()}updateReceiverHandlerMap(e){this.newConnectionReceiverHandlerMap=e}async handleExtReady(e,i,n){const t=i.from;this.polyIMC.hasChannel(t)?console.log("Channel already exists for window ID "+t+". Re-using the existing channel."):(await this.polyIMC.createChannel(e,t,this.newConnectionReceiverHandlerMap),this.onConnection&&this.onConnection(e,i))}}export{s as AccessEnum,t as AppTypeEnum,w as ConnectionListener,e as IMCMessageTypeEnum,h as InterModuleCommunication,d as MessageReceiver,l as MessageSender,n as NotificationTypeEnum,c as PolyIMC,i as ViewModeEnum,r as isArrayType,o as isObjectType,a as messageTimeout};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
export declare enum IMCMessageTypeEnum {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
ModalityVAD = "modality-vad",
|
|
3
|
+
ModalitySTT = "modality-stt",
|
|
4
|
+
ModalityLLM = "modality-llm",
|
|
5
|
+
ModalityTTS = "modality-tts",
|
|
6
|
+
ModalitySpeech2Speech = "modality-speech-to-speech",
|
|
7
|
+
ModalityImageGen = "modality-image-gen",
|
|
8
|
+
ModalityVideoGen = "modality-video-gen",
|
|
9
|
+
ModalityOCR = "modality-ocr",
|
|
10
|
+
ModalityMusicGen = "modality-music-gen",
|
|
11
|
+
AppReady = "app-ready",
|
|
12
|
+
AppClose = "app-close",
|
|
13
|
+
EditorLoadingApp = "editor-loading-app",
|
|
14
|
+
EditorRegisterAction = "editor-register-action",
|
|
15
|
+
EditorRunAppAction = "editor-run-app-action",
|
|
16
|
+
EditorRunAgentMethod = "editor-run-agent-method",
|
|
17
|
+
EditorThemeUpdate = "editor-theme-update",
|
|
18
|
+
EditorShowNotification = "editor-show-notification",
|
|
19
|
+
EditorGetEnv = "editor-get-env",
|
|
20
|
+
PlatformCreateTerminal = "platform-create-terminal",
|
|
21
|
+
PlatformWriteFile = "platform-write-file",
|
|
22
|
+
PlatformReadFile = "platform-read-file",
|
|
23
|
+
SignalGetWindowId = "signal-get-window-id",
|
|
24
|
+
SignalReturnWindowId = "signal-return-window-id",
|
|
25
|
+
SignalAcknowledge = "signal-acknowledge",
|
|
26
|
+
SignalAbort = "signal-abort",
|
|
27
|
+
SignalError = "signal-error"
|
|
17
28
|
}
|
|
18
29
|
export type IMCMessage = {
|
|
19
30
|
id: string;
|
|
@@ -21,20 +32,22 @@ export type IMCMessage = {
|
|
|
21
32
|
type: IMCMessageTypeEnum;
|
|
22
33
|
payload?: any;
|
|
23
34
|
};
|
|
24
|
-
export type
|
|
25
|
-
|
|
26
|
-
}>;
|
|
35
|
+
export type ReceiverHandler = (senderWindow: Window, message: IMCMessage, abortSignal?: AbortSignal) => Promise<any>;
|
|
36
|
+
export type ReceiverHandlerMap = Map<IMCMessageTypeEnum, ReceiverHandler>;
|
|
27
37
|
export type TextFileSelection = {
|
|
28
38
|
lineStart: number;
|
|
29
39
|
lineEnd: number;
|
|
30
40
|
text: string;
|
|
31
41
|
};
|
|
32
|
-
export type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
selections?: TextFileSelection[];
|
|
36
|
-
isActive: boolean;
|
|
42
|
+
export type ViewModel = {
|
|
43
|
+
viewId: string;
|
|
44
|
+
appConfig?: AppConfig;
|
|
37
45
|
};
|
|
46
|
+
export declare enum ViewModeEnum {
|
|
47
|
+
App = "app",
|
|
48
|
+
Canvas = "canvas",
|
|
49
|
+
Home = "home"
|
|
50
|
+
}
|
|
38
51
|
export type FetchPayload = {
|
|
39
52
|
uri: string;
|
|
40
53
|
options?: RequestInit;
|
|
@@ -45,31 +58,44 @@ export declare enum NotificationTypeEnum {
|
|
|
45
58
|
Info = "info",
|
|
46
59
|
Warning = "warning"
|
|
47
60
|
}
|
|
48
|
-
export declare enum
|
|
61
|
+
export declare enum AppTypeEnum {
|
|
49
62
|
Generic = "generic",
|
|
50
63
|
FileView = "file-view",
|
|
51
64
|
ConsoleView = "console-view"
|
|
52
65
|
}
|
|
53
|
-
export type
|
|
66
|
+
export type AppConfig = {
|
|
54
67
|
id: string;
|
|
55
68
|
version: string;
|
|
69
|
+
libVersion: string;
|
|
56
70
|
author?: string;
|
|
57
71
|
displayName?: string;
|
|
58
72
|
description?: string;
|
|
59
73
|
materialIcon?: string;
|
|
60
|
-
|
|
74
|
+
appType?: AppTypeEnum;
|
|
61
75
|
fileTypes?: string[];
|
|
62
|
-
|
|
76
|
+
thumbnail?: string;
|
|
63
77
|
enabledPlatforms?: Record<string, boolean>;
|
|
78
|
+
agents?: Agent[];
|
|
79
|
+
preRegisteredActions?: Action[];
|
|
80
|
+
visibility: string;
|
|
81
|
+
recommendedHeight?: number;
|
|
82
|
+
recommendedWidth?: number;
|
|
83
|
+
};
|
|
84
|
+
export type Action = {
|
|
85
|
+
name: string;
|
|
86
|
+
description: string;
|
|
87
|
+
parameters: Record<string, TypedVariable>;
|
|
88
|
+
returns: Record<string, TypedVariable>;
|
|
89
|
+
handler?: (args: any) => Promise<any>;
|
|
64
90
|
};
|
|
65
91
|
export type Agent = {
|
|
66
92
|
name: string;
|
|
67
93
|
version: string;
|
|
68
94
|
systemPrompt: string;
|
|
69
95
|
availableMethods: AgentMethod[];
|
|
70
|
-
LLMConfig: LLMConfig;
|
|
71
96
|
description: string;
|
|
72
97
|
tools?: AgentTool[];
|
|
98
|
+
LLMConfig?: LLMConfig;
|
|
73
99
|
};
|
|
74
100
|
/**
|
|
75
101
|
* An agent method is a sub task that an agent can perform.
|
|
@@ -77,43 +103,60 @@ export type Agent = {
|
|
|
77
103
|
export type AgentMethod = {
|
|
78
104
|
access: AccessEnum;
|
|
79
105
|
name: string;
|
|
80
|
-
parameters: Record<string,
|
|
106
|
+
parameters: Record<string, TypedVariable>;
|
|
81
107
|
prompt: string;
|
|
82
|
-
returns: Record<string,
|
|
108
|
+
returns: Record<string, TypedVariable>;
|
|
83
109
|
LLMConfig?: LLMConfig;
|
|
84
110
|
};
|
|
85
|
-
export type
|
|
86
|
-
type:
|
|
111
|
+
export type TypedVariable = {
|
|
112
|
+
type: TypedVariableType;
|
|
87
113
|
description: string;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
type AgentVariableTypeArray = {
|
|
91
|
-
size: number;
|
|
92
|
-
elementType: AgentVariableType;
|
|
114
|
+
optional?: boolean;
|
|
115
|
+
defaultValue?: any;
|
|
93
116
|
};
|
|
94
117
|
/**
|
|
95
118
|
* A tool that agent can use during method execution.
|
|
96
119
|
*
|
|
97
|
-
* This is linked to a callback function created by user,
|
|
98
|
-
* tool developer, or extension.
|
|
99
120
|
*
|
|
100
|
-
* The tool may optionally return a value to
|
|
101
|
-
* agent method.
|
|
121
|
+
* The tool may optionally return a value to the agent.
|
|
102
122
|
*/
|
|
103
123
|
export type AgentTool = {
|
|
104
124
|
access: AccessEnum;
|
|
105
125
|
name: string;
|
|
106
126
|
description: string;
|
|
107
|
-
parameters: Record<string,
|
|
108
|
-
returns: Record<string,
|
|
127
|
+
parameters: Record<string, TypedVariable>;
|
|
128
|
+
returns: Record<string, TypedVariable>;
|
|
109
129
|
};
|
|
110
|
-
export type
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
temperature: number;
|
|
130
|
+
export type TypedVariableType = "string" | "number" | "boolean" | "any" | TypedVariableObjectType | TypedVariableArrayType;
|
|
131
|
+
export type TypedVariableObjectType = {
|
|
132
|
+
[key: string]: TypedVariable;
|
|
114
133
|
};
|
|
134
|
+
export type TypedVariableArrayType = [TypedVariableType];
|
|
135
|
+
export declare function isArrayType(value: TypedVariableType): value is TypedVariableArrayType;
|
|
136
|
+
export declare function isObjectType(value: TypedVariableType): value is TypedVariableObjectType;
|
|
115
137
|
export declare enum AccessEnum {
|
|
116
138
|
public = "public",
|
|
117
139
|
private = "private"
|
|
118
140
|
}
|
|
119
|
-
export {
|
|
141
|
+
export type STTConfig = {
|
|
142
|
+
provider: string;
|
|
143
|
+
modelName: string;
|
|
144
|
+
};
|
|
145
|
+
export type LLMConfig = {
|
|
146
|
+
provider: string;
|
|
147
|
+
modelName: string;
|
|
148
|
+
temperature: number;
|
|
149
|
+
};
|
|
150
|
+
export type TTSConfig = {
|
|
151
|
+
provider: string;
|
|
152
|
+
modelName: string;
|
|
153
|
+
voice: string;
|
|
154
|
+
};
|
|
155
|
+
export type ImageModelConfig = {
|
|
156
|
+
provider: string;
|
|
157
|
+
modelName: string;
|
|
158
|
+
};
|
|
159
|
+
export type VideoModelConfig = {
|
|
160
|
+
provider: string;
|
|
161
|
+
modelName: string;
|
|
162
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-editor/shared-utils",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.40",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"files": [
|
|
7
6
|
"dist"
|
|
8
7
|
],
|
|
9
8
|
"publishConfig": {
|
|
10
9
|
"access": "public"
|
|
11
10
|
},
|
|
11
|
+
"types": "dist/main.d.ts",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"scripts": {
|
|
13
14
|
"build": "npm run clean && rollup -c",
|
|
14
15
|
"lint": "eslint .",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
"@babel/preset-env": "^7.26.9",
|
|
20
21
|
"@eslint/js": "^9.25.0",
|
|
21
22
|
"@rollup/plugin-babel": "^6.0.4",
|
|
23
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
22
24
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
23
25
|
"@rollup/plugin-terser": "^0.4.4",
|
|
24
26
|
"@rollup/plugin-typescript": "^12.1.2",
|