@lvce-editor/chat-debug-view 5.5.0 → 6.0.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/chatDebugViewWorkerMain.js +349 -586
- package/package.json +1 -1
|
@@ -368,6 +368,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
368
368
|
listen: listen$6,
|
|
369
369
|
wrap: wrap$e
|
|
370
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
|
+
};
|
|
371
465
|
|
|
372
466
|
class CommandNotFoundError extends Error {
|
|
373
467
|
constructor(command) {
|
|
@@ -392,10 +486,10 @@ const execute = (command, ...args) => {
|
|
|
392
486
|
|
|
393
487
|
const Two$1 = '2.0';
|
|
394
488
|
const callbacks = Object.create(null);
|
|
395
|
-
const get$
|
|
489
|
+
const get$2 = id => {
|
|
396
490
|
return callbacks[id];
|
|
397
491
|
};
|
|
398
|
-
const remove = id => {
|
|
492
|
+
const remove$1 = id => {
|
|
399
493
|
delete callbacks[id];
|
|
400
494
|
};
|
|
401
495
|
class JsonRpcError extends Error {
|
|
@@ -541,14 +635,14 @@ const warn = (...args) => {
|
|
|
541
635
|
console.warn(...args);
|
|
542
636
|
};
|
|
543
637
|
const resolve = (id, response) => {
|
|
544
|
-
const fn = get$
|
|
638
|
+
const fn = get$2(id);
|
|
545
639
|
if (!fn) {
|
|
546
640
|
console.log(response);
|
|
547
641
|
warn(`callback ${id} may already be disposed`);
|
|
548
642
|
return;
|
|
549
643
|
}
|
|
550
644
|
fn(response);
|
|
551
|
-
remove(id);
|
|
645
|
+
remove$1(id);
|
|
552
646
|
};
|
|
553
647
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
554
648
|
const getErrorType = prettyError => {
|
|
@@ -604,7 +698,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
604
698
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
605
699
|
return create$1$1(id, errorProperty);
|
|
606
700
|
};
|
|
607
|
-
const create$
|
|
701
|
+
const create$a = (message, result) => {
|
|
608
702
|
return {
|
|
609
703
|
id: message.id,
|
|
610
704
|
jsonrpc: Two$1,
|
|
@@ -613,7 +707,7 @@ const create$6 = (message, result) => {
|
|
|
613
707
|
};
|
|
614
708
|
const getSuccessResponse = (message, result) => {
|
|
615
709
|
const resultProperty = result ?? null;
|
|
616
|
-
return create$
|
|
710
|
+
return create$a(message, resultProperty);
|
|
617
711
|
};
|
|
618
712
|
const getErrorResponseSimple = (id, error) => {
|
|
619
713
|
return {
|
|
@@ -707,7 +801,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
707
801
|
|
|
708
802
|
const Two = '2.0';
|
|
709
803
|
|
|
710
|
-
const create$
|
|
804
|
+
const create$9 = (method, params) => {
|
|
711
805
|
return {
|
|
712
806
|
jsonrpc: Two,
|
|
713
807
|
method,
|
|
@@ -715,7 +809,7 @@ const create$5 = (method, params) => {
|
|
|
715
809
|
};
|
|
716
810
|
};
|
|
717
811
|
|
|
718
|
-
const create$
|
|
812
|
+
const create$8 = (id, method, params) => {
|
|
719
813
|
const message = {
|
|
720
814
|
id,
|
|
721
815
|
jsonrpc: Two,
|
|
@@ -726,12 +820,12 @@ const create$4 = (id, method, params) => {
|
|
|
726
820
|
};
|
|
727
821
|
|
|
728
822
|
let id = 0;
|
|
729
|
-
const create$
|
|
823
|
+
const create$7 = () => {
|
|
730
824
|
return ++id;
|
|
731
825
|
};
|
|
732
826
|
|
|
733
827
|
const registerPromise = map => {
|
|
734
|
-
const id = create$
|
|
828
|
+
const id = create$7();
|
|
735
829
|
const {
|
|
736
830
|
promise,
|
|
737
831
|
resolve
|
|
@@ -748,7 +842,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
748
842
|
id,
|
|
749
843
|
promise
|
|
750
844
|
} = registerPromise(callbacks);
|
|
751
|
-
const message = create$
|
|
845
|
+
const message = create$8(id, method, params);
|
|
752
846
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
847
|
ipc.sendAndTransfer(message);
|
|
754
848
|
} else {
|
|
@@ -784,7 +878,7 @@ const createRpc = ipc => {
|
|
|
784
878
|
* @deprecated
|
|
785
879
|
*/
|
|
786
880
|
send(method, ...params) {
|
|
787
|
-
const message = create$
|
|
881
|
+
const message = create$9(method, params);
|
|
788
882
|
ipc.send(message);
|
|
789
883
|
}
|
|
790
884
|
};
|
|
@@ -824,7 +918,84 @@ const listen$1 = async (module, options) => {
|
|
|
824
918
|
return ipc;
|
|
825
919
|
};
|
|
826
920
|
|
|
827
|
-
const create$
|
|
921
|
+
const create$6 = async ({
|
|
922
|
+
commandMap,
|
|
923
|
+
isMessagePortOpen = true,
|
|
924
|
+
messagePort
|
|
925
|
+
}) => {
|
|
926
|
+
// TODO create a commandMap per rpc instance
|
|
927
|
+
register(commandMap);
|
|
928
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
929
|
+
isMessagePortOpen,
|
|
930
|
+
messagePort
|
|
931
|
+
});
|
|
932
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
933
|
+
handleIpc(ipc);
|
|
934
|
+
const rpc = createRpc(ipc);
|
|
935
|
+
messagePort.start();
|
|
936
|
+
return rpc;
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
const create$5 = async ({
|
|
940
|
+
commandMap,
|
|
941
|
+
isMessagePortOpen,
|
|
942
|
+
send
|
|
943
|
+
}) => {
|
|
944
|
+
const {
|
|
945
|
+
port1,
|
|
946
|
+
port2
|
|
947
|
+
} = new MessageChannel();
|
|
948
|
+
await send(port1);
|
|
949
|
+
return create$6({
|
|
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$4 = async ({
|
|
985
|
+
commandMap,
|
|
986
|
+
isMessagePortOpen,
|
|
987
|
+
send
|
|
988
|
+
}) => {
|
|
989
|
+
return createSharedLazyRpc(() => {
|
|
990
|
+
return create$5({
|
|
991
|
+
commandMap,
|
|
992
|
+
isMessagePortOpen,
|
|
993
|
+
send
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
const create$3 = async ({
|
|
828
999
|
commandMap
|
|
829
1000
|
}) => {
|
|
830
1001
|
// TODO create a commandMap per rpc instance
|
|
@@ -835,6 +1006,114 @@ const create$2 = async ({
|
|
|
835
1006
|
return rpc;
|
|
836
1007
|
};
|
|
837
1008
|
|
|
1009
|
+
const createMockRpc = ({
|
|
1010
|
+
commandMap
|
|
1011
|
+
}) => {
|
|
1012
|
+
const invocations = [];
|
|
1013
|
+
const invoke = (method, ...params) => {
|
|
1014
|
+
invocations.push([method, ...params]);
|
|
1015
|
+
const command = commandMap[method];
|
|
1016
|
+
if (!command) {
|
|
1017
|
+
throw new Error(`command ${method} not found`);
|
|
1018
|
+
}
|
|
1019
|
+
return command(...params);
|
|
1020
|
+
};
|
|
1021
|
+
const mockRpc = {
|
|
1022
|
+
invocations,
|
|
1023
|
+
invoke,
|
|
1024
|
+
invokeAndTransfer: invoke
|
|
1025
|
+
};
|
|
1026
|
+
return mockRpc;
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
const rpcs = Object.create(null);
|
|
1030
|
+
const set$3 = (id, rpc) => {
|
|
1031
|
+
rpcs[id] = rpc;
|
|
1032
|
+
};
|
|
1033
|
+
const get$1 = id => {
|
|
1034
|
+
return rpcs[id];
|
|
1035
|
+
};
|
|
1036
|
+
const remove = id => {
|
|
1037
|
+
delete rpcs[id];
|
|
1038
|
+
};
|
|
1039
|
+
|
|
1040
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1041
|
+
const create$2 = rpcId => {
|
|
1042
|
+
return {
|
|
1043
|
+
async dispose() {
|
|
1044
|
+
const rpc = get$1(rpcId);
|
|
1045
|
+
await rpc.dispose();
|
|
1046
|
+
},
|
|
1047
|
+
// @ts-ignore
|
|
1048
|
+
invoke(method, ...params) {
|
|
1049
|
+
const rpc = get$1(rpcId);
|
|
1050
|
+
// @ts-ignore
|
|
1051
|
+
return rpc.invoke(method, ...params);
|
|
1052
|
+
},
|
|
1053
|
+
// @ts-ignore
|
|
1054
|
+
invokeAndTransfer(method, ...params) {
|
|
1055
|
+
const rpc = get$1(rpcId);
|
|
1056
|
+
// @ts-ignore
|
|
1057
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1058
|
+
},
|
|
1059
|
+
registerMockRpc(commandMap) {
|
|
1060
|
+
const mockRpc = createMockRpc({
|
|
1061
|
+
commandMap
|
|
1062
|
+
});
|
|
1063
|
+
set$3(rpcId, mockRpc);
|
|
1064
|
+
// @ts-ignore
|
|
1065
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1066
|
+
remove(rpcId);
|
|
1067
|
+
};
|
|
1068
|
+
// @ts-ignore
|
|
1069
|
+
return mockRpc;
|
|
1070
|
+
},
|
|
1071
|
+
set(rpc) {
|
|
1072
|
+
set$3(rpcId, rpc);
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
const Button = 1;
|
|
1078
|
+
const Div = 4;
|
|
1079
|
+
const Input = 6;
|
|
1080
|
+
const Span = 8;
|
|
1081
|
+
const Table = 9;
|
|
1082
|
+
const TBody = 10;
|
|
1083
|
+
const Td = 11;
|
|
1084
|
+
const Text = 12;
|
|
1085
|
+
const Th = 13;
|
|
1086
|
+
const THead = 14;
|
|
1087
|
+
const Tr = 15;
|
|
1088
|
+
const Search = 42;
|
|
1089
|
+
const Label = 66;
|
|
1090
|
+
const Reference = 100;
|
|
1091
|
+
|
|
1092
|
+
const ClientX = 'event.clientX';
|
|
1093
|
+
const ClientY = 'event.clientY';
|
|
1094
|
+
const TargetName = 'event.target.name';
|
|
1095
|
+
const TargetValue = 'event.target.value';
|
|
1096
|
+
|
|
1097
|
+
const ChatStorageWorker = 6003;
|
|
1098
|
+
const RendererWorker = 1;
|
|
1099
|
+
|
|
1100
|
+
const SetCss = 'Viewlet.setCss';
|
|
1101
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
1102
|
+
const SetPatches = 'Viewlet.setPatches';
|
|
1103
|
+
|
|
1104
|
+
const {
|
|
1105
|
+
invoke,
|
|
1106
|
+
set: set$2
|
|
1107
|
+
} = create$2(ChatStorageWorker);
|
|
1108
|
+
|
|
1109
|
+
const {
|
|
1110
|
+
invokeAndTransfer,
|
|
1111
|
+
set: set$1
|
|
1112
|
+
} = create$2(RendererWorker);
|
|
1113
|
+
const sendMessagePortToChatStorageWorker$1 = async port => {
|
|
1114
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToChatStorageWorker', port, 'HandleMessagePort.handleMessagePort');
|
|
1115
|
+
};
|
|
1116
|
+
|
|
838
1117
|
const toCommandId = key => {
|
|
839
1118
|
const dotIndex = key.indexOf('.');
|
|
840
1119
|
return key.slice(dotIndex + 1);
|
|
@@ -1079,7 +1358,6 @@ const createDefaultState = () => {
|
|
|
1079
1358
|
eventStoreName: 'chat-view-events',
|
|
1080
1359
|
filterValue: '',
|
|
1081
1360
|
height: 0,
|
|
1082
|
-
indexedDbSupportOverride: undefined,
|
|
1083
1361
|
initial: false,
|
|
1084
1362
|
platform: 0,
|
|
1085
1363
|
selectedDetailTab: Response,
|
|
@@ -1194,7 +1472,7 @@ const handleDetailTab = (state, value) => {
|
|
|
1194
1472
|
};
|
|
1195
1473
|
};
|
|
1196
1474
|
|
|
1197
|
-
const hasMatchingToolName
|
|
1475
|
+
const hasMatchingToolName = (startedEvent, finishedEvent) => {
|
|
1198
1476
|
if (typeof startedEvent.toolName === 'string' && typeof finishedEvent.toolName === 'string') {
|
|
1199
1477
|
return startedEvent.toolName === finishedEvent.toolName;
|
|
1200
1478
|
}
|
|
@@ -1202,27 +1480,27 @@ const hasMatchingToolName$1 = (startedEvent, finishedEvent) => {
|
|
|
1202
1480
|
};
|
|
1203
1481
|
|
|
1204
1482
|
const isMatchingToolExecutionPair = (startedEvent, finishedEvent) => {
|
|
1205
|
-
return startedEvent.sessionId === finishedEvent.sessionId && hasMatchingToolName
|
|
1483
|
+
return startedEvent.sessionId === finishedEvent.sessionId && hasMatchingToolName(startedEvent, finishedEvent);
|
|
1206
1484
|
};
|
|
1207
1485
|
|
|
1208
|
-
const startedEventType
|
|
1209
|
-
const finishedEventType
|
|
1486
|
+
const startedEventType = 'tool-execution-started';
|
|
1487
|
+
const finishedEventType = 'tool-execution-finished';
|
|
1210
1488
|
const mergedEventType = 'tool-execution';
|
|
1211
1489
|
|
|
1212
1490
|
const isToolExecutionFinishedEvent = event => {
|
|
1213
|
-
return event.type === finishedEventType
|
|
1491
|
+
return event.type === finishedEventType;
|
|
1214
1492
|
};
|
|
1215
1493
|
|
|
1216
1494
|
const isToolExecutionStartedEvent = event => {
|
|
1217
|
-
return event.type === startedEventType
|
|
1495
|
+
return event.type === startedEventType;
|
|
1218
1496
|
};
|
|
1219
1497
|
|
|
1220
|
-
const getTimestamp
|
|
1498
|
+
const getTimestamp = value => {
|
|
1221
1499
|
return typeof value === 'string' || typeof value === 'number' ? value : undefined;
|
|
1222
1500
|
};
|
|
1223
1501
|
|
|
1224
1502
|
const getEndedTimestamp = event => {
|
|
1225
|
-
return getTimestamp
|
|
1503
|
+
return getTimestamp(event.ended) ?? getTimestamp(event.endTime) ?? getTimestamp(event.endTimestamp) ?? getTimestamp(event.timestamp);
|
|
1226
1504
|
};
|
|
1227
1505
|
|
|
1228
1506
|
const eventStableIds = new WeakMap();
|
|
@@ -1241,14 +1519,14 @@ const getOrCreateStableEventId = event => {
|
|
|
1241
1519
|
};
|
|
1242
1520
|
|
|
1243
1521
|
const getStartedTimestamp = event => {
|
|
1244
|
-
return getTimestamp
|
|
1522
|
+
return getTimestamp(event.started) ?? getTimestamp(event.startTime) ?? getTimestamp(event.startTimestamp) ?? getTimestamp(event.timestamp);
|
|
1245
1523
|
};
|
|
1246
1524
|
|
|
1247
1525
|
const setStableEventId = (event, stableEventId) => {
|
|
1248
1526
|
eventStableIds.set(event, stableEventId);
|
|
1249
1527
|
};
|
|
1250
1528
|
|
|
1251
|
-
const mergeToolExecutionEvents
|
|
1529
|
+
const mergeToolExecutionEvents = (startedEvent, finishedEvent) => {
|
|
1252
1530
|
const ended = getEndedTimestamp(finishedEvent);
|
|
1253
1531
|
const {
|
|
1254
1532
|
eventId
|
|
@@ -1284,7 +1562,7 @@ const collapseToolExecutionEvents = events => {
|
|
|
1284
1562
|
if (isToolExecutionStartedEvent(event)) {
|
|
1285
1563
|
const nextEvent = events[i + 1];
|
|
1286
1564
|
if (nextEvent && isToolExecutionFinishedEvent(nextEvent) && isMatchingToolExecutionPair(event, nextEvent)) {
|
|
1287
|
-
collapsedEvents.push(mergeToolExecutionEvents
|
|
1565
|
+
collapsedEvents.push(mergeToolExecutionEvents(event, nextEvent));
|
|
1288
1566
|
i++;
|
|
1289
1567
|
continue;
|
|
1290
1568
|
}
|
|
@@ -1575,383 +1853,18 @@ const handleEventCategoryFilter = (state, value) => {
|
|
|
1575
1853
|
return withPreservedSelection$1(state, nextState);
|
|
1576
1854
|
};
|
|
1577
1855
|
|
|
1578
|
-
let workerRpc;
|
|
1579
|
-
const setWorkerRpc = value => {
|
|
1580
|
-
workerRpc = value;
|
|
1581
|
-
};
|
|
1582
|
-
const invoke = async (method, ...params) => {
|
|
1583
|
-
if (!workerRpc) {
|
|
1584
|
-
throw new Error('worker rpc is not initialized');
|
|
1585
|
-
}
|
|
1586
|
-
return workerRpc.invoke(method, ...params);
|
|
1587
|
-
};
|
|
1588
|
-
|
|
1589
|
-
const chatStorageWorkerClientDependencies = {
|
|
1590
|
-
invoke: invoke
|
|
1591
|
-
};
|
|
1592
1856
|
const listChatViewEvents$1 = async sessionId => {
|
|
1593
|
-
return
|
|
1857
|
+
return invoke('ChatStorage.listChatViewEvents', sessionId);
|
|
1594
1858
|
};
|
|
1595
1859
|
const loadSelectedEvent$1 = async (sessionId, eventId, type) => {
|
|
1596
|
-
return
|
|
1597
|
-
};
|
|
1598
|
-
|
|
1599
|
-
// cspell:ignore IDBP
|
|
1600
|
-
|
|
1601
|
-
const startedEventType = 'tool-execution-started';
|
|
1602
|
-
const finishedEventType = 'tool-execution-finished';
|
|
1603
|
-
const getRawEventBySessionIdAndEventId = async (store, sessionId, sessionIdIndexName, eventId) => {
|
|
1604
|
-
if (eventId < 1) {
|
|
1605
|
-
return undefined;
|
|
1606
|
-
}
|
|
1607
|
-
if (store.indexNames.contains(sessionIdIndexName)) {
|
|
1608
|
-
const index = store.index(sessionIdIndexName);
|
|
1609
|
-
const keys = await index.getAllKeys(sessionId, eventId);
|
|
1610
|
-
if (keys.length < eventId) {
|
|
1611
|
-
return undefined;
|
|
1612
|
-
}
|
|
1613
|
-
const key = keys.at(-1);
|
|
1614
|
-
if (key === undefined) {
|
|
1615
|
-
return undefined;
|
|
1616
|
-
}
|
|
1617
|
-
const event = await store.get(key);
|
|
1618
|
-
return event;
|
|
1619
|
-
}
|
|
1620
|
-
const all = await store.getAll();
|
|
1621
|
-
const events = all.filter(event => event.sessionId === sessionId);
|
|
1622
|
-
return events[eventId - 1];
|
|
1623
|
-
};
|
|
1624
|
-
const getTimestamp = value => {
|
|
1625
|
-
return typeof value === 'string' || typeof value === 'number' ? value : undefined;
|
|
1626
|
-
};
|
|
1627
|
-
const hasMatchingToolName = (startedEvent, finishedEvent) => {
|
|
1628
|
-
if (typeof startedEvent.toolName === 'string' && typeof finishedEvent.toolName === 'string') {
|
|
1629
|
-
return startedEvent.toolName === finishedEvent.toolName;
|
|
1630
|
-
}
|
|
1631
|
-
return true;
|
|
1632
|
-
};
|
|
1633
|
-
const mergeToolExecutionEvents = (startedEvent, finishedEvent, eventId) => {
|
|
1634
|
-
const ended = getTimestamp(finishedEvent.ended) ?? getTimestamp(finishedEvent.endTime) ?? getTimestamp(finishedEvent.timestamp);
|
|
1635
|
-
const started = getTimestamp(startedEvent.started) ?? getTimestamp(startedEvent.startTime) ?? getTimestamp(startedEvent.timestamp);
|
|
1636
|
-
return {
|
|
1637
|
-
...startedEvent,
|
|
1638
|
-
...finishedEvent,
|
|
1639
|
-
...(ended === undefined ? {} : {
|
|
1640
|
-
ended
|
|
1641
|
-
}),
|
|
1642
|
-
eventId,
|
|
1643
|
-
...(started === undefined ? {} : {
|
|
1644
|
-
started
|
|
1645
|
-
}),
|
|
1646
|
-
type: 'tool-execution'
|
|
1647
|
-
};
|
|
1648
|
-
};
|
|
1649
|
-
const getEventDetailsBySessionIdAndEventId = async (store, sessionId, sessionIdIndexName, eventId, summaryType) => {
|
|
1650
|
-
const event = await getRawEventBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId);
|
|
1651
|
-
if (!event) {
|
|
1652
|
-
return undefined;
|
|
1653
|
-
}
|
|
1654
|
-
if (summaryType !== 'tool-execution') {
|
|
1655
|
-
return {
|
|
1656
|
-
...event,
|
|
1657
|
-
eventId
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
if (event.type !== startedEventType) {
|
|
1661
|
-
return {
|
|
1662
|
-
...event,
|
|
1663
|
-
eventId
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
|
-
const nextEvent = await getRawEventBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId + 1);
|
|
1667
|
-
if (!nextEvent || nextEvent.type !== finishedEventType || nextEvent.sessionId !== sessionId || !hasMatchingToolName(event, nextEvent)) {
|
|
1668
|
-
return {
|
|
1669
|
-
...event,
|
|
1670
|
-
eventId
|
|
1671
|
-
};
|
|
1672
|
-
}
|
|
1673
|
-
return mergeToolExecutionEvents(event, nextEvent, eventId);
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
|
|
1677
|
-
let idbProxyableTypes;
|
|
1678
|
-
let cursorAdvanceMethods;
|
|
1679
|
-
// This is a function to prevent it throwing up in node environments.
|
|
1680
|
-
function getIdbProxyableTypes() {
|
|
1681
|
-
return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
|
|
1682
|
-
}
|
|
1683
|
-
// This is a function to prevent it throwing up in node environments.
|
|
1684
|
-
function getCursorAdvanceMethods() {
|
|
1685
|
-
return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
|
|
1686
|
-
}
|
|
1687
|
-
const transactionDoneMap = new WeakMap();
|
|
1688
|
-
const transformCache = new WeakMap();
|
|
1689
|
-
const reverseTransformCache = new WeakMap();
|
|
1690
|
-
function promisifyRequest(request) {
|
|
1691
|
-
const promise = new Promise((resolve, reject) => {
|
|
1692
|
-
const unlisten = () => {
|
|
1693
|
-
request.removeEventListener('success', success);
|
|
1694
|
-
request.removeEventListener('error', error);
|
|
1695
|
-
};
|
|
1696
|
-
const success = () => {
|
|
1697
|
-
resolve(wrap(request.result));
|
|
1698
|
-
unlisten();
|
|
1699
|
-
};
|
|
1700
|
-
const error = () => {
|
|
1701
|
-
reject(request.error);
|
|
1702
|
-
unlisten();
|
|
1703
|
-
};
|
|
1704
|
-
request.addEventListener('success', success);
|
|
1705
|
-
request.addEventListener('error', error);
|
|
1706
|
-
});
|
|
1707
|
-
// This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
|
|
1708
|
-
// is because we create many promises from a single IDBRequest.
|
|
1709
|
-
reverseTransformCache.set(promise, request);
|
|
1710
|
-
return promise;
|
|
1711
|
-
}
|
|
1712
|
-
function cacheDonePromiseForTransaction(tx) {
|
|
1713
|
-
// Early bail if we've already created a done promise for this transaction.
|
|
1714
|
-
if (transactionDoneMap.has(tx)) return;
|
|
1715
|
-
const done = new Promise((resolve, reject) => {
|
|
1716
|
-
const unlisten = () => {
|
|
1717
|
-
tx.removeEventListener('complete', complete);
|
|
1718
|
-
tx.removeEventListener('error', error);
|
|
1719
|
-
tx.removeEventListener('abort', error);
|
|
1720
|
-
};
|
|
1721
|
-
const complete = () => {
|
|
1722
|
-
resolve();
|
|
1723
|
-
unlisten();
|
|
1724
|
-
};
|
|
1725
|
-
const error = () => {
|
|
1726
|
-
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
1727
|
-
unlisten();
|
|
1728
|
-
};
|
|
1729
|
-
tx.addEventListener('complete', complete);
|
|
1730
|
-
tx.addEventListener('error', error);
|
|
1731
|
-
tx.addEventListener('abort', error);
|
|
1732
|
-
});
|
|
1733
|
-
// Cache it for later retrieval.
|
|
1734
|
-
transactionDoneMap.set(tx, done);
|
|
1735
|
-
}
|
|
1736
|
-
let idbProxyTraps = {
|
|
1737
|
-
get(target, prop, receiver) {
|
|
1738
|
-
if (target instanceof IDBTransaction) {
|
|
1739
|
-
// Special handling for transaction.done.
|
|
1740
|
-
if (prop === 'done') return transactionDoneMap.get(target);
|
|
1741
|
-
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
1742
|
-
if (prop === 'store') {
|
|
1743
|
-
return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
// Else transform whatever we get back.
|
|
1747
|
-
return wrap(target[prop]);
|
|
1748
|
-
},
|
|
1749
|
-
set(target, prop, value) {
|
|
1750
|
-
target[prop] = value;
|
|
1751
|
-
return true;
|
|
1752
|
-
},
|
|
1753
|
-
has(target, prop) {
|
|
1754
|
-
if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
|
|
1755
|
-
return true;
|
|
1756
|
-
}
|
|
1757
|
-
return prop in target;
|
|
1758
|
-
}
|
|
1759
|
-
};
|
|
1760
|
-
function replaceTraps(callback) {
|
|
1761
|
-
idbProxyTraps = callback(idbProxyTraps);
|
|
1762
|
-
}
|
|
1763
|
-
function wrapFunction(func) {
|
|
1764
|
-
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
1765
|
-
// only create one new func per func.
|
|
1766
|
-
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
1767
|
-
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
1768
|
-
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
1769
|
-
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
1770
|
-
// undefined if the end of the cursor has been reached.
|
|
1771
|
-
if (getCursorAdvanceMethods().includes(func)) {
|
|
1772
|
-
return function (...args) {
|
|
1773
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
1774
|
-
// the original object.
|
|
1775
|
-
func.apply(unwrap(this), args);
|
|
1776
|
-
return wrap(this.request);
|
|
1777
|
-
};
|
|
1778
|
-
}
|
|
1779
|
-
return function (...args) {
|
|
1780
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
1781
|
-
// the original object.
|
|
1782
|
-
return wrap(func.apply(unwrap(this), args));
|
|
1783
|
-
};
|
|
1784
|
-
}
|
|
1785
|
-
function transformCachableValue(value) {
|
|
1786
|
-
if (typeof value === 'function') return wrapFunction(value);
|
|
1787
|
-
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
1788
|
-
// which is later returned for transaction.done (see idbObjectHandler).
|
|
1789
|
-
if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
|
|
1790
|
-
if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
|
|
1791
|
-
// Return the same value back if we're not going to transform it.
|
|
1792
|
-
return value;
|
|
1793
|
-
}
|
|
1794
|
-
function wrap(value) {
|
|
1795
|
-
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
1796
|
-
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
1797
|
-
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
1798
|
-
// If we've already transformed this value before, reuse the transformed value.
|
|
1799
|
-
// This is faster, but it also provides object equality.
|
|
1800
|
-
if (transformCache.has(value)) return transformCache.get(value);
|
|
1801
|
-
const newValue = transformCachableValue(value);
|
|
1802
|
-
// Not all types are transformed.
|
|
1803
|
-
// These may be primitive types, so they can't be WeakMap keys.
|
|
1804
|
-
if (newValue !== value) {
|
|
1805
|
-
transformCache.set(value, newValue);
|
|
1806
|
-
reverseTransformCache.set(newValue, value);
|
|
1807
|
-
}
|
|
1808
|
-
return newValue;
|
|
1809
|
-
}
|
|
1810
|
-
const unwrap = value => reverseTransformCache.get(value);
|
|
1811
|
-
|
|
1812
|
-
/**
|
|
1813
|
-
* Open a database.
|
|
1814
|
-
*
|
|
1815
|
-
* @param name Name of the database.
|
|
1816
|
-
* @param version Schema version.
|
|
1817
|
-
* @param callbacks Additional callbacks.
|
|
1818
|
-
*/
|
|
1819
|
-
function openDB(name, version, {
|
|
1820
|
-
blocked,
|
|
1821
|
-
upgrade,
|
|
1822
|
-
blocking,
|
|
1823
|
-
terminated
|
|
1824
|
-
} = {}) {
|
|
1825
|
-
const request = indexedDB.open(name, version);
|
|
1826
|
-
const openPromise = wrap(request);
|
|
1827
|
-
if (upgrade) {
|
|
1828
|
-
request.addEventListener('upgradeneeded', event => {
|
|
1829
|
-
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
1830
|
-
});
|
|
1831
|
-
}
|
|
1832
|
-
if (blocked) {
|
|
1833
|
-
request.addEventListener('blocked', event => blocked(
|
|
1834
|
-
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
1835
|
-
event.oldVersion, event.newVersion, event));
|
|
1836
|
-
}
|
|
1837
|
-
openPromise.then(db => {
|
|
1838
|
-
if (terminated) db.addEventListener('close', () => terminated());
|
|
1839
|
-
if (blocking) {
|
|
1840
|
-
db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
|
|
1841
|
-
}
|
|
1842
|
-
}).catch(() => {});
|
|
1843
|
-
return openPromise;
|
|
1844
|
-
}
|
|
1845
|
-
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
1846
|
-
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
1847
|
-
const cachedMethods = new Map();
|
|
1848
|
-
function getMethod(target, prop) {
|
|
1849
|
-
if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
|
|
1850
|
-
return;
|
|
1851
|
-
}
|
|
1852
|
-
if (cachedMethods.get(prop)) return cachedMethods.get(prop);
|
|
1853
|
-
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
1854
|
-
const useIndex = prop !== targetFuncName;
|
|
1855
|
-
const isWrite = writeMethods.includes(targetFuncName);
|
|
1856
|
-
if (
|
|
1857
|
-
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
1858
|
-
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
|
|
1859
|
-
return;
|
|
1860
|
-
}
|
|
1861
|
-
const method = async function (storeName, ...args) {
|
|
1862
|
-
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
1863
|
-
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
1864
|
-
let target = tx.store;
|
|
1865
|
-
if (useIndex) target = target.index(args.shift());
|
|
1866
|
-
// Must reject if op rejects.
|
|
1867
|
-
// If it's a write operation, must reject if tx.done rejects.
|
|
1868
|
-
// Must reject with op rejection first.
|
|
1869
|
-
// Must resolve with op value.
|
|
1870
|
-
// Must handle both promises (no unhandled rejections)
|
|
1871
|
-
return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
|
|
1872
|
-
};
|
|
1873
|
-
cachedMethods.set(prop, method);
|
|
1874
|
-
return method;
|
|
1875
|
-
}
|
|
1876
|
-
replaceTraps(oldTraps => ({
|
|
1877
|
-
...oldTraps,
|
|
1878
|
-
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
1879
|
-
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
|
|
1880
|
-
}));
|
|
1881
|
-
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
1882
|
-
const methodMap = {};
|
|
1883
|
-
const advanceResults = new WeakMap();
|
|
1884
|
-
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
1885
|
-
const cursorIteratorTraps = {
|
|
1886
|
-
get(target, prop) {
|
|
1887
|
-
if (!advanceMethodProps.includes(prop)) return target[prop];
|
|
1888
|
-
let cachedFunc = methodMap[prop];
|
|
1889
|
-
if (!cachedFunc) {
|
|
1890
|
-
cachedFunc = methodMap[prop] = function (...args) {
|
|
1891
|
-
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
1892
|
-
};
|
|
1893
|
-
}
|
|
1894
|
-
return cachedFunc;
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
async function* iterate(...args) {
|
|
1898
|
-
// tslint:disable-next-line:no-this-assignment
|
|
1899
|
-
let cursor = this;
|
|
1900
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
1901
|
-
cursor = await cursor.openCursor(...args);
|
|
1902
|
-
}
|
|
1903
|
-
if (!cursor) return;
|
|
1904
|
-
cursor = cursor;
|
|
1905
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
1906
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
1907
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
1908
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
1909
|
-
while (cursor) {
|
|
1910
|
-
yield proxiedCursor;
|
|
1911
|
-
// If one of the advancing methods was not called, call continue().
|
|
1912
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
1913
|
-
advanceResults.delete(proxiedCursor);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
function isIteratorProp(target, prop) {
|
|
1917
|
-
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
1918
|
-
}
|
|
1919
|
-
replaceTraps(oldTraps => ({
|
|
1920
|
-
...oldTraps,
|
|
1921
|
-
get(target, prop, receiver) {
|
|
1922
|
-
if (isIteratorProp(target, prop)) return iterate;
|
|
1923
|
-
return oldTraps.get(target, prop, receiver);
|
|
1924
|
-
},
|
|
1925
|
-
has(target, prop) {
|
|
1926
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
1927
|
-
}
|
|
1928
|
-
}));
|
|
1929
|
-
|
|
1930
|
-
const openDatabaseDependencies = {
|
|
1931
|
-
openDB: openDB
|
|
1932
|
-
};
|
|
1933
|
-
const openDatabase = async (databaseName, dataBaseVersion) => {
|
|
1934
|
-
return openDatabaseDependencies.openDB(databaseName, dataBaseVersion);
|
|
1860
|
+
return invoke('ChatStorage.loadSelectedEvent', sessionId, eventId, type);
|
|
1935
1861
|
};
|
|
1936
1862
|
|
|
1937
1863
|
const loadSelectedEventDependencies = {
|
|
1938
|
-
|
|
1939
|
-
loadSelectedEventFromWorker: loadSelectedEvent$1,
|
|
1940
|
-
openDatabase: openDatabase
|
|
1864
|
+
loadSelectedEventFromWorker: loadSelectedEvent$1
|
|
1941
1865
|
};
|
|
1942
|
-
const loadSelectedEvent = async (
|
|
1943
|
-
|
|
1944
|
-
try {
|
|
1945
|
-
if (!database.objectStoreNames.contains(eventStoreName)) {
|
|
1946
|
-
return null;
|
|
1947
|
-
}
|
|
1948
|
-
const transaction = database.transaction(eventStoreName, 'readonly');
|
|
1949
|
-
const store = transaction.objectStore(eventStoreName);
|
|
1950
|
-
const event = await loadSelectedEventDependencies.getEventDetailsBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId, type);
|
|
1951
|
-
return event ?? null;
|
|
1952
|
-
} finally {
|
|
1953
|
-
database.close();
|
|
1954
|
-
}
|
|
1866
|
+
const loadSelectedEvent = async (_databaseName, _dataBaseVersion, _eventStoreName, sessionId, _sessionIdIndexName, eventId, type) => {
|
|
1867
|
+
return loadSelectedEventDependencies.loadSelectedEventFromWorker(sessionId, eventId, type);
|
|
1955
1868
|
};
|
|
1956
1869
|
|
|
1957
1870
|
const getCurrentEvents$2 = state => {
|
|
@@ -2394,12 +2307,24 @@ const handleShowResponsePartEvents = (state, checked) => {
|
|
|
2394
2307
|
return withPreservedSelection$1(state, nextState);
|
|
2395
2308
|
};
|
|
2396
2309
|
|
|
2397
|
-
const
|
|
2398
|
-
|
|
2310
|
+
const getErrorMessage = error => {
|
|
2311
|
+
if (error instanceof Error) {
|
|
2312
|
+
return error.message;
|
|
2313
|
+
}
|
|
2314
|
+
if (typeof error === 'string') {
|
|
2315
|
+
return error;
|
|
2316
|
+
}
|
|
2317
|
+
if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string') {
|
|
2318
|
+
return error.message;
|
|
2319
|
+
}
|
|
2320
|
+
return undefined;
|
|
2399
2321
|
};
|
|
2400
|
-
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2322
|
+
const getFailedToLoadMessage = (sessionId, error) => {
|
|
2323
|
+
const errorMessage = getErrorMessage(error);
|
|
2324
|
+
if (errorMessage) {
|
|
2325
|
+
return `Failed to load chat debug session "${sessionId}": ${errorMessage}`;
|
|
2326
|
+
}
|
|
2327
|
+
return `Failed to load chat debug session "${sessionId}". Please try again.`;
|
|
2403
2328
|
};
|
|
2404
2329
|
|
|
2405
2330
|
const ParseChatDebugUriErrorCode = {
|
|
@@ -2420,135 +2345,12 @@ const getSessionNotFoundMessage = sessionId => {
|
|
|
2420
2345
|
return `No chat session found for sessionId "${sessionId}".`;
|
|
2421
2346
|
};
|
|
2422
2347
|
|
|
2423
|
-
const filterEventsBySessionId = (events, sessionId) => {
|
|
2424
|
-
return events.filter(event => event.sessionId === sessionId);
|
|
2425
|
-
};
|
|
2426
|
-
|
|
2427
|
-
// cspell:ignore IDBP
|
|
2428
|
-
|
|
2429
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2430
|
-
const getAllEvents = async store => {
|
|
2431
|
-
const all = await store.getAll();
|
|
2432
|
-
return all;
|
|
2433
|
-
};
|
|
2434
|
-
|
|
2435
|
-
const getEndTime = event => {
|
|
2436
|
-
return event.ended ?? event.endTime ?? event.timestamp;
|
|
2437
|
-
};
|
|
2438
|
-
|
|
2439
|
-
const getStartTime = event => {
|
|
2440
|
-
return event.started ?? event.startTime ?? event.timestamp;
|
|
2441
|
-
};
|
|
2442
|
-
|
|
2443
|
-
const getDuration = event => {
|
|
2444
|
-
const explicitDuration = event.durationMs ?? event.duration;
|
|
2445
|
-
if (typeof explicitDuration === 'number' && Number.isFinite(explicitDuration)) {
|
|
2446
|
-
return explicitDuration;
|
|
2447
|
-
}
|
|
2448
|
-
const start = toTimeNumber(getStartTime(event));
|
|
2449
|
-
const end = toTimeNumber(getEndTime(event));
|
|
2450
|
-
if (start === undefined || end === undefined || !Number.isFinite(start) || !Number.isFinite(end)) {
|
|
2451
|
-
return 0;
|
|
2452
|
-
}
|
|
2453
|
-
return Math.max(0, end - start);
|
|
2454
|
-
};
|
|
2455
|
-
|
|
2456
|
-
const isTimeValue = value => {
|
|
2457
|
-
return typeof value === 'number' || typeof value === 'string';
|
|
2458
|
-
};
|
|
2459
|
-
|
|
2460
|
-
const getLightweightEvent = (event, fallbackEventId) => {
|
|
2461
|
-
const startTime = getStartTime(event);
|
|
2462
|
-
const endTime = getEndTime(event);
|
|
2463
|
-
return {
|
|
2464
|
-
duration: getDuration(event),
|
|
2465
|
-
...(isTimeValue(endTime) ? {
|
|
2466
|
-
endTime
|
|
2467
|
-
} : {}),
|
|
2468
|
-
eventId: typeof event.eventId === 'number' ? event.eventId : fallbackEventId,
|
|
2469
|
-
...(isTimeValue(startTime) ? {
|
|
2470
|
-
startTime
|
|
2471
|
-
} : {}),
|
|
2472
|
-
type: event.type
|
|
2473
|
-
};
|
|
2474
|
-
};
|
|
2475
|
-
|
|
2476
|
-
// cspell:ignore IDBP
|
|
2477
|
-
|
|
2478
|
-
const toLightweightEvents = events => {
|
|
2479
|
-
const eventsWithIds = events.map((event, index) => {
|
|
2480
|
-
return {
|
|
2481
|
-
...event,
|
|
2482
|
-
eventId: index + 1
|
|
2483
|
-
};
|
|
2484
|
-
});
|
|
2485
|
-
return collapseToolExecutionEvents(eventsWithIds).map((event, index) => getLightweightEvent(event, index + 1));
|
|
2486
|
-
};
|
|
2487
|
-
const getEventsBySessionId = async (store, sessionId, sessionIdIndexName) => {
|
|
2488
|
-
if (store.indexNames.contains(sessionIdIndexName)) {
|
|
2489
|
-
const index = store.index(sessionIdIndexName);
|
|
2490
|
-
const events = await index.getAll(sessionId);
|
|
2491
|
-
return toLightweightEvents(filterEventsBySessionId(events, sessionId));
|
|
2492
|
-
}
|
|
2493
|
-
const all = await getAllEvents(store);
|
|
2494
|
-
return toLightweightEvents(filterEventsBySessionId(all, sessionId));
|
|
2495
|
-
};
|
|
2496
|
-
|
|
2497
|
-
let indexedDbSupportOverride;
|
|
2498
|
-
const getIndexedDbSupportOverride = () => {
|
|
2499
|
-
return indexedDbSupportOverride;
|
|
2500
|
-
};
|
|
2501
|
-
const setIndexedDbSupportOverride = supported => {
|
|
2502
|
-
indexedDbSupportOverride = supported;
|
|
2503
|
-
};
|
|
2504
|
-
|
|
2505
|
-
const isIndexedDbSupported = indexedDbSupportOverride => {
|
|
2506
|
-
if (typeof indexedDbSupportOverride === 'boolean') {
|
|
2507
|
-
return indexedDbSupportOverride;
|
|
2508
|
-
}
|
|
2509
|
-
const override = getIndexedDbSupportOverride();
|
|
2510
|
-
if (typeof override === 'boolean') {
|
|
2511
|
-
return override;
|
|
2512
|
-
}
|
|
2513
|
-
return globalThis.indexedDB !== undefined;
|
|
2514
|
-
};
|
|
2515
|
-
|
|
2516
2348
|
const listChatViewEventsDependencies = {
|
|
2517
|
-
|
|
2518
|
-
listChatViewEventsFromWorker: listChatViewEvents$1,
|
|
2519
|
-
openDatabase: openDatabase
|
|
2349
|
+
listChatViewEventsFromWorker: listChatViewEvents$1
|
|
2520
2350
|
};
|
|
2521
|
-
const listChatViewEvents = async (sessionId,
|
|
2522
|
-
if (!isIndexedDbSupported(indexedDbSupportOverride)) {
|
|
2523
|
-
return {
|
|
2524
|
-
type: 'not-supported'
|
|
2525
|
-
};
|
|
2526
|
-
}
|
|
2351
|
+
const listChatViewEvents = async (sessionId, _databaseName, _dataBaseVersion, _eventStoreName, _sessionIdIndexName) => {
|
|
2527
2352
|
try {
|
|
2528
|
-
|
|
2529
|
-
try {
|
|
2530
|
-
if (!database.objectStoreNames.contains(eventStoreName)) {
|
|
2531
|
-
return {
|
|
2532
|
-
events: [],
|
|
2533
|
-
type: 'success'
|
|
2534
|
-
};
|
|
2535
|
-
}
|
|
2536
|
-
const transaction = database.transaction(eventStoreName, 'readonly');
|
|
2537
|
-
const store = transaction.objectStore(eventStoreName);
|
|
2538
|
-
if (!sessionId) {
|
|
2539
|
-
return {
|
|
2540
|
-
events: [],
|
|
2541
|
-
type: 'success'
|
|
2542
|
-
};
|
|
2543
|
-
}
|
|
2544
|
-
const events = await listChatViewEventsDependencies.getEventsBySessionId(store, sessionId, sessionIdIndexName);
|
|
2545
|
-
return {
|
|
2546
|
-
events,
|
|
2547
|
-
type: 'success'
|
|
2548
|
-
};
|
|
2549
|
-
} finally {
|
|
2550
|
-
database.close();
|
|
2551
|
-
}
|
|
2353
|
+
return await listChatViewEventsDependencies.listChatViewEventsFromWorker(sessionId);
|
|
2552
2354
|
} catch (error) {
|
|
2553
2355
|
return {
|
|
2554
2356
|
error,
|
|
@@ -2670,26 +2472,13 @@ const loadEventsForSessionId = async (state, sessionId) => {
|
|
|
2670
2472
|
databaseName,
|
|
2671
2473
|
dataBaseVersion,
|
|
2672
2474
|
eventStoreName,
|
|
2673
|
-
indexedDbSupportOverride,
|
|
2674
2475
|
sessionIdIndexName
|
|
2675
2476
|
} = state;
|
|
2676
|
-
const result = await loadEventsDependencies.listChatViewEvents(sessionId, databaseName, dataBaseVersion, eventStoreName, sessionIdIndexName
|
|
2677
|
-
if (result.type === 'not-supported') {
|
|
2678
|
-
return {
|
|
2679
|
-
...state,
|
|
2680
|
-
errorMessage: getIndexedDbNotSupportedMessage(),
|
|
2681
|
-
events: [],
|
|
2682
|
-
initial: false,
|
|
2683
|
-
selectedEvent: null,
|
|
2684
|
-
selectedEventId: null,
|
|
2685
|
-
selectedEventIndex: null,
|
|
2686
|
-
sessionId
|
|
2687
|
-
};
|
|
2688
|
-
}
|
|
2477
|
+
const result = await loadEventsDependencies.listChatViewEvents(sessionId, databaseName, dataBaseVersion, eventStoreName, sessionIdIndexName);
|
|
2689
2478
|
if (result.type === 'error') {
|
|
2690
2479
|
return {
|
|
2691
2480
|
...state,
|
|
2692
|
-
errorMessage: getFailedToLoadMessage(sessionId),
|
|
2481
|
+
errorMessage: getFailedToLoadMessage(sessionId, result.error),
|
|
2693
2482
|
events: [],
|
|
2694
2483
|
initial: false,
|
|
2695
2484
|
selectedEvent: null,
|
|
@@ -2745,30 +2534,6 @@ const refresh = async state => {
|
|
|
2745
2534
|
return refreshEvents(state);
|
|
2746
2535
|
};
|
|
2747
2536
|
|
|
2748
|
-
const Button = 1;
|
|
2749
|
-
const Div = 4;
|
|
2750
|
-
const Input = 6;
|
|
2751
|
-
const Span = 8;
|
|
2752
|
-
const Table = 9;
|
|
2753
|
-
const TBody = 10;
|
|
2754
|
-
const Td = 11;
|
|
2755
|
-
const Text = 12;
|
|
2756
|
-
const Th = 13;
|
|
2757
|
-
const THead = 14;
|
|
2758
|
-
const Tr = 15;
|
|
2759
|
-
const Search = 42;
|
|
2760
|
-
const Label = 66;
|
|
2761
|
-
const Reference = 100;
|
|
2762
|
-
|
|
2763
|
-
const ClientX = 'event.clientX';
|
|
2764
|
-
const ClientY = 'event.clientY';
|
|
2765
|
-
const TargetName = 'event.target.name';
|
|
2766
|
-
const TargetValue = 'event.target.value';
|
|
2767
|
-
|
|
2768
|
-
const SetCss = 'Viewlet.setCss';
|
|
2769
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
2770
|
-
const SetPatches = 'Viewlet.setPatches';
|
|
2771
|
-
|
|
2772
2537
|
const getCss = state => {
|
|
2773
2538
|
const tableWidth = clampTableWidth(state.width, state.tableWidth);
|
|
2774
2539
|
const detailsWidth = getDetailsWidth(state.width, state.tableWidth);
|
|
@@ -4151,6 +3916,9 @@ const hasErrorStatus = event => {
|
|
|
4151
3916
|
if (isErrorStatusCode(result.status)) {
|
|
4152
3917
|
return true;
|
|
4153
3918
|
}
|
|
3919
|
+
if (isToolEvent(event) && 'error' in result && result.error !== undefined) {
|
|
3920
|
+
return true;
|
|
3921
|
+
}
|
|
4154
3922
|
if (typeof result.error === 'string' || typeof result.errorMessage === 'string' || typeof result.exception === 'string') {
|
|
4155
3923
|
return true;
|
|
4156
3924
|
}
|
|
@@ -4871,31 +4639,15 @@ const setEvents = (state, events) => {
|
|
|
4871
4639
|
};
|
|
4872
4640
|
};
|
|
4873
4641
|
|
|
4874
|
-
const setIndexedDbSupportForTest = supported => {
|
|
4875
|
-
return setIndexedDbSupportOverride(supported);
|
|
4876
|
-
};
|
|
4877
|
-
|
|
4878
4642
|
const setSessionIdDependencies = {
|
|
4879
4643
|
listChatViewEvents: listChatViewEvents
|
|
4880
4644
|
};
|
|
4881
4645
|
const setSessionId = async (state, sessionId) => {
|
|
4882
|
-
const result = await setSessionIdDependencies.listChatViewEvents(sessionId, state.databaseName, state.dataBaseVersion, state.eventStoreName, state.sessionIdIndexName
|
|
4883
|
-
if (result.type === 'not-supported') {
|
|
4884
|
-
return {
|
|
4885
|
-
...state,
|
|
4886
|
-
errorMessage: getIndexedDbNotSupportedMessage(),
|
|
4887
|
-
events: [],
|
|
4888
|
-
initial: false,
|
|
4889
|
-
selectedEvent: null,
|
|
4890
|
-
selectedEventId: null,
|
|
4891
|
-
selectedEventIndex: null,
|
|
4892
|
-
sessionId
|
|
4893
|
-
};
|
|
4894
|
-
}
|
|
4646
|
+
const result = await setSessionIdDependencies.listChatViewEvents(sessionId, state.databaseName, state.dataBaseVersion, state.eventStoreName, state.sessionIdIndexName);
|
|
4895
4647
|
if (result.type === 'error') {
|
|
4896
4648
|
return {
|
|
4897
4649
|
...state,
|
|
4898
|
-
errorMessage: getFailedToLoadMessage(sessionId),
|
|
4650
|
+
errorMessage: getFailedToLoadMessage(sessionId, result.error),
|
|
4899
4651
|
events: [],
|
|
4900
4652
|
initial: false,
|
|
4901
4653
|
selectedEvent: null,
|
|
@@ -4954,17 +4706,28 @@ const commandMap = {
|
|
|
4954
4706
|
'ChatDebug.resize': wrapCommand(resize),
|
|
4955
4707
|
'ChatDebug.saveState': wrapGetter(saveState),
|
|
4956
4708
|
'ChatDebug.setEvents': wrapCommand(setEvents),
|
|
4957
|
-
'ChatDebug.setIndexedDbSupportForTest': setIndexedDbSupportForTest,
|
|
4958
4709
|
'ChatDebug.setSessionId': wrapCommand(setSessionId),
|
|
4959
4710
|
'ChatDebug.terminate': terminate
|
|
4960
4711
|
};
|
|
4961
4712
|
|
|
4713
|
+
const sendMessagePortToChatStorageWorker = async port => {
|
|
4714
|
+
await sendMessagePortToChatStorageWorker$1(port);
|
|
4715
|
+
};
|
|
4716
|
+
const initializeChatStorageWorker = async () => {
|
|
4717
|
+
const rpc = await create$4({
|
|
4718
|
+
commandMap: {},
|
|
4719
|
+
send: sendMessagePortToChatStorageWorker
|
|
4720
|
+
});
|
|
4721
|
+
set$2(rpc);
|
|
4722
|
+
};
|
|
4723
|
+
|
|
4962
4724
|
const listen = async () => {
|
|
4963
4725
|
registerCommands(commandMap);
|
|
4964
|
-
const
|
|
4726
|
+
const r = await create$3({
|
|
4965
4727
|
commandMap: commandMap
|
|
4966
4728
|
});
|
|
4967
|
-
|
|
4729
|
+
set$1(r);
|
|
4730
|
+
await initializeChatStorageWorker();
|
|
4968
4731
|
};
|
|
4969
4732
|
|
|
4970
4733
|
const main = async () => {
|