@lvce-editor/chat-message-parsing-worker 1.4.0 → 1.6.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 +105 -42
- package/package.json +1 -1
|
@@ -267,45 +267,6 @@ const readyMessage = 'ready';
|
|
|
267
267
|
const getData$2 = event => {
|
|
268
268
|
return event.data;
|
|
269
269
|
};
|
|
270
|
-
const listen$8 = ({
|
|
271
|
-
port
|
|
272
|
-
}) => {
|
|
273
|
-
return port;
|
|
274
|
-
};
|
|
275
|
-
const signal$9 = port => {
|
|
276
|
-
port.postMessage(readyMessage);
|
|
277
|
-
};
|
|
278
|
-
class IpcChildWithMessagePort extends Ipc {
|
|
279
|
-
getData(event) {
|
|
280
|
-
return getData$2(event);
|
|
281
|
-
}
|
|
282
|
-
send(message) {
|
|
283
|
-
this._rawIpc.postMessage(message);
|
|
284
|
-
}
|
|
285
|
-
sendAndTransfer(message) {
|
|
286
|
-
const transfer = getTransferrables(message);
|
|
287
|
-
this._rawIpc.postMessage(message, transfer);
|
|
288
|
-
}
|
|
289
|
-
dispose() {
|
|
290
|
-
// ignore
|
|
291
|
-
}
|
|
292
|
-
onClose(callback) {
|
|
293
|
-
// ignore
|
|
294
|
-
}
|
|
295
|
-
onMessage(callback) {
|
|
296
|
-
this._rawIpc.addEventListener('message', callback);
|
|
297
|
-
this._rawIpc.start();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const wrap$g = port => {
|
|
301
|
-
return new IpcChildWithMessagePort(port);
|
|
302
|
-
};
|
|
303
|
-
const IpcChildWithMessagePort$1 = {
|
|
304
|
-
__proto__: null,
|
|
305
|
-
listen: listen$8,
|
|
306
|
-
signal: signal$9,
|
|
307
|
-
wrap: wrap$g
|
|
308
|
-
};
|
|
309
270
|
const listen$7 = () => {
|
|
310
271
|
// @ts-ignore
|
|
311
272
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
@@ -407,6 +368,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
407
368
|
listen: listen$6,
|
|
408
369
|
wrap: wrap$e
|
|
409
370
|
};
|
|
371
|
+
const addListener = (emitter, type, callback) => {
|
|
372
|
+
if ('addEventListener' in emitter) {
|
|
373
|
+
emitter.addEventListener(type, callback);
|
|
374
|
+
} else {
|
|
375
|
+
emitter.on(type, callback);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const removeListener = (emitter, type, callback) => {
|
|
379
|
+
if ('removeEventListener' in emitter) {
|
|
380
|
+
emitter.removeEventListener(type, callback);
|
|
381
|
+
} else {
|
|
382
|
+
emitter.off(type, callback);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
386
|
+
const {
|
|
387
|
+
promise,
|
|
388
|
+
resolve
|
|
389
|
+
} = Promise.withResolvers();
|
|
390
|
+
const listenerMap = Object.create(null);
|
|
391
|
+
const cleanup = value => {
|
|
392
|
+
for (const event of Object.keys(eventMap)) {
|
|
393
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
394
|
+
}
|
|
395
|
+
resolve(value);
|
|
396
|
+
};
|
|
397
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
398
|
+
const listener = event => {
|
|
399
|
+
cleanup({
|
|
400
|
+
event,
|
|
401
|
+
type
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
addListener(eventEmitter, event, listener);
|
|
405
|
+
listenerMap[event] = listener;
|
|
406
|
+
}
|
|
407
|
+
return promise;
|
|
408
|
+
};
|
|
409
|
+
const Message$1 = 3;
|
|
410
|
+
const create$5$1 = async ({
|
|
411
|
+
isMessagePortOpen,
|
|
412
|
+
messagePort
|
|
413
|
+
}) => {
|
|
414
|
+
if (!isMessagePort(messagePort)) {
|
|
415
|
+
throw new IpcError('port must be of type MessagePort');
|
|
416
|
+
}
|
|
417
|
+
if (isMessagePortOpen) {
|
|
418
|
+
return messagePort;
|
|
419
|
+
}
|
|
420
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
421
|
+
message: Message$1
|
|
422
|
+
});
|
|
423
|
+
messagePort.start();
|
|
424
|
+
const {
|
|
425
|
+
event,
|
|
426
|
+
type
|
|
427
|
+
} = await eventPromise;
|
|
428
|
+
if (type !== Message$1) {
|
|
429
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
430
|
+
}
|
|
431
|
+
if (event.data !== readyMessage) {
|
|
432
|
+
throw new IpcError('unexpected first message');
|
|
433
|
+
}
|
|
434
|
+
return messagePort;
|
|
435
|
+
};
|
|
436
|
+
const signal$1 = messagePort => {
|
|
437
|
+
messagePort.start();
|
|
438
|
+
};
|
|
439
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
440
|
+
getData = getData$2;
|
|
441
|
+
send(message) {
|
|
442
|
+
this._rawIpc.postMessage(message);
|
|
443
|
+
}
|
|
444
|
+
sendAndTransfer(message) {
|
|
445
|
+
const transfer = getTransferrables(message);
|
|
446
|
+
this._rawIpc.postMessage(message, transfer);
|
|
447
|
+
}
|
|
448
|
+
dispose() {
|
|
449
|
+
this._rawIpc.close();
|
|
450
|
+
}
|
|
451
|
+
onMessage(callback) {
|
|
452
|
+
this._rawIpc.addEventListener('message', callback);
|
|
453
|
+
}
|
|
454
|
+
onClose(callback) {}
|
|
455
|
+
}
|
|
456
|
+
const wrap$5 = messagePort => {
|
|
457
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
458
|
+
};
|
|
459
|
+
const IpcParentWithMessagePort$1 = {
|
|
460
|
+
__proto__: null,
|
|
461
|
+
create: create$5$1,
|
|
462
|
+
signal: signal$1,
|
|
463
|
+
wrap: wrap$5
|
|
464
|
+
};
|
|
410
465
|
|
|
411
466
|
class CommandNotFoundError extends Error {
|
|
412
467
|
constructor(command) {
|
|
@@ -865,15 +920,19 @@ const listen$1 = async (module, options) => {
|
|
|
865
920
|
|
|
866
921
|
const create$1 = async ({
|
|
867
922
|
commandMap,
|
|
923
|
+
isMessagePortOpen = true,
|
|
868
924
|
messagePort
|
|
869
925
|
}) => {
|
|
870
926
|
// TODO create a commandMap per rpc instance
|
|
871
927
|
register(commandMap);
|
|
872
|
-
const
|
|
873
|
-
|
|
928
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
929
|
+
isMessagePortOpen,
|
|
930
|
+
messagePort
|
|
874
931
|
});
|
|
932
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
875
933
|
handleIpc(ipc);
|
|
876
934
|
const rpc = createRpc(ipc);
|
|
935
|
+
messagePort.start();
|
|
877
936
|
return rpc;
|
|
878
937
|
};
|
|
879
938
|
|
|
@@ -891,6 +950,7 @@ const create = async ({
|
|
|
891
950
|
const handleMessagePort = async port => {
|
|
892
951
|
await create$1({
|
|
893
952
|
commandMap: commandMap,
|
|
953
|
+
isMessagePortOpen: true,
|
|
894
954
|
messagePort: port
|
|
895
955
|
});
|
|
896
956
|
};
|
|
@@ -1852,9 +1912,12 @@ const parseMessageContents = rawMessages => {
|
|
|
1852
1912
|
};
|
|
1853
1913
|
|
|
1854
1914
|
const commandMap = {
|
|
1915
|
+
'ChatMessageParsing.parseMessageContent': parseMessageContent,
|
|
1916
|
+
'ChatMessageParsing.parseMessageContents': parseMessageContents,
|
|
1855
1917
|
'ChatParser.parseMessageContent': parseMessageContent,
|
|
1856
1918
|
'ChatParser.parseMessageContents': parseMessageContents,
|
|
1857
|
-
'HandleMessagePort.handleMessagePort': handleMessagePort
|
|
1919
|
+
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
1920
|
+
initialize: (_, port) => handleMessagePort(port)
|
|
1858
1921
|
};
|
|
1859
1922
|
|
|
1860
1923
|
const listen = async () => {
|