@lvce-editor/chat-message-parsing-worker 1.6.0 → 1.7.0
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/chatMessageParsingWorkerMain.js +173 -17
- package/package.json +1 -1
|
@@ -486,10 +486,10 @@ const execute = (command, ...args) => {
|
|
|
486
486
|
|
|
487
487
|
const Two$1 = '2.0';
|
|
488
488
|
const callbacks = Object.create(null);
|
|
489
|
-
const get = id => {
|
|
489
|
+
const get$1 = id => {
|
|
490
490
|
return callbacks[id];
|
|
491
491
|
};
|
|
492
|
-
const remove = id => {
|
|
492
|
+
const remove$1 = id => {
|
|
493
493
|
delete callbacks[id];
|
|
494
494
|
};
|
|
495
495
|
class JsonRpcError extends Error {
|
|
@@ -635,14 +635,14 @@ const warn = (...args) => {
|
|
|
635
635
|
console.warn(...args);
|
|
636
636
|
};
|
|
637
637
|
const resolve = (id, response) => {
|
|
638
|
-
const fn = get(id);
|
|
638
|
+
const fn = get$1(id);
|
|
639
639
|
if (!fn) {
|
|
640
640
|
console.log(response);
|
|
641
641
|
warn(`callback ${id} may already be disposed`);
|
|
642
642
|
return;
|
|
643
643
|
}
|
|
644
644
|
fn(response);
|
|
645
|
-
remove(id);
|
|
645
|
+
remove$1(id);
|
|
646
646
|
};
|
|
647
647
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
648
648
|
const getErrorType = prettyError => {
|
|
@@ -698,7 +698,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
698
698
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
699
699
|
return create$1$1(id, errorProperty);
|
|
700
700
|
};
|
|
701
|
-
const create$
|
|
701
|
+
const create$8 = (message, result) => {
|
|
702
702
|
return {
|
|
703
703
|
id: message.id,
|
|
704
704
|
jsonrpc: Two$1,
|
|
@@ -707,7 +707,7 @@ const create$5 = (message, result) => {
|
|
|
707
707
|
};
|
|
708
708
|
const getSuccessResponse = (message, result) => {
|
|
709
709
|
const resultProperty = result ?? null;
|
|
710
|
-
return create$
|
|
710
|
+
return create$8(message, resultProperty);
|
|
711
711
|
};
|
|
712
712
|
const getErrorResponseSimple = (id, error) => {
|
|
713
713
|
return {
|
|
@@ -801,7 +801,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
801
801
|
|
|
802
802
|
const Two = '2.0';
|
|
803
803
|
|
|
804
|
-
const create$
|
|
804
|
+
const create$7 = (method, params) => {
|
|
805
805
|
return {
|
|
806
806
|
jsonrpc: Two,
|
|
807
807
|
method,
|
|
@@ -809,7 +809,7 @@ const create$4 = (method, params) => {
|
|
|
809
809
|
};
|
|
810
810
|
};
|
|
811
811
|
|
|
812
|
-
const create$
|
|
812
|
+
const create$6 = (id, method, params) => {
|
|
813
813
|
const message = {
|
|
814
814
|
id,
|
|
815
815
|
jsonrpc: Two,
|
|
@@ -820,12 +820,12 @@ const create$3 = (id, method, params) => {
|
|
|
820
820
|
};
|
|
821
821
|
|
|
822
822
|
let id = 0;
|
|
823
|
-
const create$
|
|
823
|
+
const create$5 = () => {
|
|
824
824
|
return ++id;
|
|
825
825
|
};
|
|
826
826
|
|
|
827
827
|
const registerPromise = map => {
|
|
828
|
-
const id = create$
|
|
828
|
+
const id = create$5();
|
|
829
829
|
const {
|
|
830
830
|
promise,
|
|
831
831
|
resolve
|
|
@@ -842,7 +842,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
842
842
|
id,
|
|
843
843
|
promise
|
|
844
844
|
} = registerPromise(callbacks);
|
|
845
|
-
const message = create$
|
|
845
|
+
const message = create$6(id, method, params);
|
|
846
846
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
847
847
|
ipc.sendAndTransfer(message);
|
|
848
848
|
} else {
|
|
@@ -878,7 +878,7 @@ const createRpc = ipc => {
|
|
|
878
878
|
* @deprecated
|
|
879
879
|
*/
|
|
880
880
|
send(method, ...params) {
|
|
881
|
-
const message = create$
|
|
881
|
+
const message = create$7(method, params);
|
|
882
882
|
ipc.send(message);
|
|
883
883
|
}
|
|
884
884
|
};
|
|
@@ -918,7 +918,7 @@ const listen$1 = async (module, options) => {
|
|
|
918
918
|
return ipc;
|
|
919
919
|
};
|
|
920
920
|
|
|
921
|
-
const create$
|
|
921
|
+
const create$4 = async ({
|
|
922
922
|
commandMap,
|
|
923
923
|
isMessagePortOpen = true,
|
|
924
924
|
messagePort
|
|
@@ -936,7 +936,66 @@ const create$1 = async ({
|
|
|
936
936
|
return rpc;
|
|
937
937
|
};
|
|
938
938
|
|
|
939
|
-
const create = async ({
|
|
939
|
+
const create$3 = async ({
|
|
940
|
+
commandMap,
|
|
941
|
+
isMessagePortOpen,
|
|
942
|
+
send
|
|
943
|
+
}) => {
|
|
944
|
+
const {
|
|
945
|
+
port1,
|
|
946
|
+
port2
|
|
947
|
+
} = new MessageChannel();
|
|
948
|
+
await send(port1);
|
|
949
|
+
return create$4({
|
|
950
|
+
commandMap,
|
|
951
|
+
isMessagePortOpen,
|
|
952
|
+
messagePort: port2
|
|
953
|
+
});
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
const createSharedLazyRpc = factory => {
|
|
957
|
+
let rpcPromise;
|
|
958
|
+
const getOrCreate = () => {
|
|
959
|
+
if (!rpcPromise) {
|
|
960
|
+
rpcPromise = factory();
|
|
961
|
+
}
|
|
962
|
+
return rpcPromise;
|
|
963
|
+
};
|
|
964
|
+
return {
|
|
965
|
+
async dispose() {
|
|
966
|
+
const rpc = await getOrCreate();
|
|
967
|
+
await rpc.dispose();
|
|
968
|
+
},
|
|
969
|
+
async invoke(method, ...params) {
|
|
970
|
+
const rpc = await getOrCreate();
|
|
971
|
+
return rpc.invoke(method, ...params);
|
|
972
|
+
},
|
|
973
|
+
async invokeAndTransfer(method, ...params) {
|
|
974
|
+
const rpc = await getOrCreate();
|
|
975
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
976
|
+
},
|
|
977
|
+
async send(method, ...params) {
|
|
978
|
+
const rpc = await getOrCreate();
|
|
979
|
+
rpc.send(method, ...params);
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
const create$2 = async ({
|
|
985
|
+
commandMap,
|
|
986
|
+
isMessagePortOpen,
|
|
987
|
+
send
|
|
988
|
+
}) => {
|
|
989
|
+
return createSharedLazyRpc(() => {
|
|
990
|
+
return create$3({
|
|
991
|
+
commandMap,
|
|
992
|
+
isMessagePortOpen,
|
|
993
|
+
send
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
const create$1 = async ({
|
|
940
999
|
commandMap
|
|
941
1000
|
}) => {
|
|
942
1001
|
// TODO create a commandMap per rpc instance
|
|
@@ -948,13 +1007,17 @@ const create = async ({
|
|
|
948
1007
|
};
|
|
949
1008
|
|
|
950
1009
|
const handleMessagePort = async port => {
|
|
951
|
-
await create$
|
|
1010
|
+
await create$4({
|
|
952
1011
|
commandMap: commandMap,
|
|
953
1012
|
isMessagePortOpen: true,
|
|
954
1013
|
messagePort: port
|
|
955
1014
|
});
|
|
956
1015
|
};
|
|
957
1016
|
|
|
1017
|
+
const initialize = async (_, port) => {
|
|
1018
|
+
await handleMessagePort(port);
|
|
1019
|
+
};
|
|
1020
|
+
|
|
958
1021
|
const windowsAbsolutePathRegex = /^[a-zA-Z]:[\\/]/;
|
|
959
1022
|
const pathSeparatorRegex$1 = /[\\/]/;
|
|
960
1023
|
const isPathTraversalAttempt = path => {
|
|
@@ -1917,13 +1980,106 @@ const commandMap = {
|
|
|
1917
1980
|
'ChatParser.parseMessageContent': parseMessageContent,
|
|
1918
1981
|
'ChatParser.parseMessageContents': parseMessageContents,
|
|
1919
1982
|
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
1920
|
-
initialize:
|
|
1983
|
+
initialize: initialize
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
const createMockRpc = ({
|
|
1987
|
+
commandMap
|
|
1988
|
+
}) => {
|
|
1989
|
+
const invocations = [];
|
|
1990
|
+
const invoke = (method, ...params) => {
|
|
1991
|
+
invocations.push([method, ...params]);
|
|
1992
|
+
const command = commandMap[method];
|
|
1993
|
+
if (!command) {
|
|
1994
|
+
throw new Error(`command ${method} not found`);
|
|
1995
|
+
}
|
|
1996
|
+
return command(...params);
|
|
1997
|
+
};
|
|
1998
|
+
const mockRpc = {
|
|
1999
|
+
invocations,
|
|
2000
|
+
invoke,
|
|
2001
|
+
invokeAndTransfer: invoke
|
|
2002
|
+
};
|
|
2003
|
+
return mockRpc;
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
const rpcs = Object.create(null);
|
|
2007
|
+
const set$1 = (id, rpc) => {
|
|
2008
|
+
rpcs[id] = rpc;
|
|
2009
|
+
};
|
|
2010
|
+
const get = id => {
|
|
2011
|
+
return rpcs[id];
|
|
2012
|
+
};
|
|
2013
|
+
const remove = id => {
|
|
2014
|
+
delete rpcs[id];
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2018
|
+
const create = rpcId => {
|
|
2019
|
+
return {
|
|
2020
|
+
async dispose() {
|
|
2021
|
+
const rpc = get(rpcId);
|
|
2022
|
+
await rpc.dispose();
|
|
2023
|
+
},
|
|
2024
|
+
// @ts-ignore
|
|
2025
|
+
invoke(method, ...params) {
|
|
2026
|
+
const rpc = get(rpcId);
|
|
2027
|
+
// @ts-ignore
|
|
2028
|
+
return rpc.invoke(method, ...params);
|
|
2029
|
+
},
|
|
2030
|
+
// @ts-ignore
|
|
2031
|
+
invokeAndTransfer(method, ...params) {
|
|
2032
|
+
const rpc = get(rpcId);
|
|
2033
|
+
// @ts-ignore
|
|
2034
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
2035
|
+
},
|
|
2036
|
+
registerMockRpc(commandMap) {
|
|
2037
|
+
const mockRpc = createMockRpc({
|
|
2038
|
+
commandMap
|
|
2039
|
+
});
|
|
2040
|
+
set$1(rpcId, mockRpc);
|
|
2041
|
+
// @ts-ignore
|
|
2042
|
+
mockRpc[Symbol.dispose] = () => {
|
|
2043
|
+
remove(rpcId);
|
|
2044
|
+
};
|
|
2045
|
+
// @ts-ignore
|
|
2046
|
+
return mockRpc;
|
|
2047
|
+
},
|
|
2048
|
+
set(rpc) {
|
|
2049
|
+
set$1(rpcId, rpc);
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
};
|
|
2053
|
+
|
|
2054
|
+
const {
|
|
2055
|
+
set
|
|
2056
|
+
} = create(6007);
|
|
2057
|
+
|
|
2058
|
+
const RendererWorker = 1;
|
|
2059
|
+
|
|
2060
|
+
const {
|
|
2061
|
+
invokeAndTransfer} = create(RendererWorker);
|
|
2062
|
+
const sendMessagePortToChatMathWorker$1 = async (port, rpcId) => {
|
|
2063
|
+
const command = 'HandleMessagePort.handleMessagePort';
|
|
2064
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToChatMathWorker', port, command, rpcId);
|
|
2065
|
+
};
|
|
2066
|
+
|
|
2067
|
+
const sendMessagePortToChatMathWorker = async port => {
|
|
2068
|
+
await sendMessagePortToChatMathWorker$1(port, 0);
|
|
2069
|
+
};
|
|
2070
|
+
const initializeChatMathWorker = async () => {
|
|
2071
|
+
const rpc = await create$2({
|
|
2072
|
+
commandMap: {},
|
|
2073
|
+
send: sendMessagePortToChatMathWorker
|
|
2074
|
+
});
|
|
2075
|
+
set(rpc);
|
|
1921
2076
|
};
|
|
1922
2077
|
|
|
1923
2078
|
const listen = async () => {
|
|
1924
|
-
await create({
|
|
2079
|
+
await create$1({
|
|
1925
2080
|
commandMap: commandMap
|
|
1926
2081
|
});
|
|
2082
|
+
await initializeChatMathWorker();
|
|
1927
2083
|
};
|
|
1928
2084
|
|
|
1929
2085
|
const main = async () => {
|