@lvce-editor/chat-debug-view 5.4.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 +351 -564
- 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,361 +1853,18 @@ const handleEventCategoryFilter = (state, value) => {
|
|
|
1575
1853
|
return withPreservedSelection$1(state, nextState);
|
|
1576
1854
|
};
|
|
1577
1855
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
const startedEventType = 'tool-execution-started';
|
|
1581
|
-
const finishedEventType = 'tool-execution-finished';
|
|
1582
|
-
const getRawEventBySessionIdAndEventId = async (store, sessionId, sessionIdIndexName, eventId) => {
|
|
1583
|
-
if (eventId < 1) {
|
|
1584
|
-
return undefined;
|
|
1585
|
-
}
|
|
1586
|
-
if (store.indexNames.contains(sessionIdIndexName)) {
|
|
1587
|
-
const index = store.index(sessionIdIndexName);
|
|
1588
|
-
const keys = await index.getAllKeys(sessionId, eventId);
|
|
1589
|
-
if (keys.length < eventId) {
|
|
1590
|
-
return undefined;
|
|
1591
|
-
}
|
|
1592
|
-
const key = keys.at(-1);
|
|
1593
|
-
if (key === undefined) {
|
|
1594
|
-
return undefined;
|
|
1595
|
-
}
|
|
1596
|
-
const event = await store.get(key);
|
|
1597
|
-
return event;
|
|
1598
|
-
}
|
|
1599
|
-
const all = await store.getAll();
|
|
1600
|
-
const events = all.filter(event => event.sessionId === sessionId);
|
|
1601
|
-
return events[eventId - 1];
|
|
1602
|
-
};
|
|
1603
|
-
const getTimestamp = value => {
|
|
1604
|
-
return typeof value === 'string' || typeof value === 'number' ? value : undefined;
|
|
1605
|
-
};
|
|
1606
|
-
const hasMatchingToolName = (startedEvent, finishedEvent) => {
|
|
1607
|
-
if (typeof startedEvent.toolName === 'string' && typeof finishedEvent.toolName === 'string') {
|
|
1608
|
-
return startedEvent.toolName === finishedEvent.toolName;
|
|
1609
|
-
}
|
|
1610
|
-
return true;
|
|
1611
|
-
};
|
|
1612
|
-
const mergeToolExecutionEvents = (startedEvent, finishedEvent, eventId) => {
|
|
1613
|
-
const ended = getTimestamp(finishedEvent.ended) ?? getTimestamp(finishedEvent.endTime) ?? getTimestamp(finishedEvent.timestamp);
|
|
1614
|
-
const started = getTimestamp(startedEvent.started) ?? getTimestamp(startedEvent.startTime) ?? getTimestamp(startedEvent.timestamp);
|
|
1615
|
-
return {
|
|
1616
|
-
...startedEvent,
|
|
1617
|
-
...finishedEvent,
|
|
1618
|
-
...(ended === undefined ? {} : {
|
|
1619
|
-
ended
|
|
1620
|
-
}),
|
|
1621
|
-
eventId,
|
|
1622
|
-
...(started === undefined ? {} : {
|
|
1623
|
-
started
|
|
1624
|
-
}),
|
|
1625
|
-
type: 'tool-execution'
|
|
1626
|
-
};
|
|
1627
|
-
};
|
|
1628
|
-
const getEventDetailsBySessionIdAndEventId = async (store, sessionId, sessionIdIndexName, eventId, summaryType) => {
|
|
1629
|
-
const event = await getRawEventBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId);
|
|
1630
|
-
if (!event) {
|
|
1631
|
-
return undefined;
|
|
1632
|
-
}
|
|
1633
|
-
if (summaryType !== 'tool-execution') {
|
|
1634
|
-
return {
|
|
1635
|
-
...event,
|
|
1636
|
-
eventId
|
|
1637
|
-
};
|
|
1638
|
-
}
|
|
1639
|
-
if (event.type !== startedEventType) {
|
|
1640
|
-
return {
|
|
1641
|
-
...event,
|
|
1642
|
-
eventId
|
|
1643
|
-
};
|
|
1644
|
-
}
|
|
1645
|
-
const nextEvent = await getRawEventBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId + 1);
|
|
1646
|
-
if (!nextEvent || nextEvent.type !== finishedEventType || nextEvent.sessionId !== sessionId || !hasMatchingToolName(event, nextEvent)) {
|
|
1647
|
-
return {
|
|
1648
|
-
...event,
|
|
1649
|
-
eventId
|
|
1650
|
-
};
|
|
1651
|
-
}
|
|
1652
|
-
return mergeToolExecutionEvents(event, nextEvent, eventId);
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
|
|
1656
|
-
let idbProxyableTypes;
|
|
1657
|
-
let cursorAdvanceMethods;
|
|
1658
|
-
// This is a function to prevent it throwing up in node environments.
|
|
1659
|
-
function getIdbProxyableTypes() {
|
|
1660
|
-
return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
|
|
1661
|
-
}
|
|
1662
|
-
// This is a function to prevent it throwing up in node environments.
|
|
1663
|
-
function getCursorAdvanceMethods() {
|
|
1664
|
-
return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
|
|
1665
|
-
}
|
|
1666
|
-
const transactionDoneMap = new WeakMap();
|
|
1667
|
-
const transformCache = new WeakMap();
|
|
1668
|
-
const reverseTransformCache = new WeakMap();
|
|
1669
|
-
function promisifyRequest(request) {
|
|
1670
|
-
const promise = new Promise((resolve, reject) => {
|
|
1671
|
-
const unlisten = () => {
|
|
1672
|
-
request.removeEventListener('success', success);
|
|
1673
|
-
request.removeEventListener('error', error);
|
|
1674
|
-
};
|
|
1675
|
-
const success = () => {
|
|
1676
|
-
resolve(wrap(request.result));
|
|
1677
|
-
unlisten();
|
|
1678
|
-
};
|
|
1679
|
-
const error = () => {
|
|
1680
|
-
reject(request.error);
|
|
1681
|
-
unlisten();
|
|
1682
|
-
};
|
|
1683
|
-
request.addEventListener('success', success);
|
|
1684
|
-
request.addEventListener('error', error);
|
|
1685
|
-
});
|
|
1686
|
-
// This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
|
|
1687
|
-
// is because we create many promises from a single IDBRequest.
|
|
1688
|
-
reverseTransformCache.set(promise, request);
|
|
1689
|
-
return promise;
|
|
1690
|
-
}
|
|
1691
|
-
function cacheDonePromiseForTransaction(tx) {
|
|
1692
|
-
// Early bail if we've already created a done promise for this transaction.
|
|
1693
|
-
if (transactionDoneMap.has(tx)) return;
|
|
1694
|
-
const done = new Promise((resolve, reject) => {
|
|
1695
|
-
const unlisten = () => {
|
|
1696
|
-
tx.removeEventListener('complete', complete);
|
|
1697
|
-
tx.removeEventListener('error', error);
|
|
1698
|
-
tx.removeEventListener('abort', error);
|
|
1699
|
-
};
|
|
1700
|
-
const complete = () => {
|
|
1701
|
-
resolve();
|
|
1702
|
-
unlisten();
|
|
1703
|
-
};
|
|
1704
|
-
const error = () => {
|
|
1705
|
-
reject(tx.error || new DOMException('AbortError', 'AbortError'));
|
|
1706
|
-
unlisten();
|
|
1707
|
-
};
|
|
1708
|
-
tx.addEventListener('complete', complete);
|
|
1709
|
-
tx.addEventListener('error', error);
|
|
1710
|
-
tx.addEventListener('abort', error);
|
|
1711
|
-
});
|
|
1712
|
-
// Cache it for later retrieval.
|
|
1713
|
-
transactionDoneMap.set(tx, done);
|
|
1714
|
-
}
|
|
1715
|
-
let idbProxyTraps = {
|
|
1716
|
-
get(target, prop, receiver) {
|
|
1717
|
-
if (target instanceof IDBTransaction) {
|
|
1718
|
-
// Special handling for transaction.done.
|
|
1719
|
-
if (prop === 'done') return transactionDoneMap.get(target);
|
|
1720
|
-
// Make tx.store return the only store in the transaction, or undefined if there are many.
|
|
1721
|
-
if (prop === 'store') {
|
|
1722
|
-
return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
// Else transform whatever we get back.
|
|
1726
|
-
return wrap(target[prop]);
|
|
1727
|
-
},
|
|
1728
|
-
set(target, prop, value) {
|
|
1729
|
-
target[prop] = value;
|
|
1730
|
-
return true;
|
|
1731
|
-
},
|
|
1732
|
-
has(target, prop) {
|
|
1733
|
-
if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
|
|
1734
|
-
return true;
|
|
1735
|
-
}
|
|
1736
|
-
return prop in target;
|
|
1737
|
-
}
|
|
1738
|
-
};
|
|
1739
|
-
function replaceTraps(callback) {
|
|
1740
|
-
idbProxyTraps = callback(idbProxyTraps);
|
|
1741
|
-
}
|
|
1742
|
-
function wrapFunction(func) {
|
|
1743
|
-
// Due to expected object equality (which is enforced by the caching in `wrap`), we
|
|
1744
|
-
// only create one new func per func.
|
|
1745
|
-
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
|
|
1746
|
-
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
|
|
1747
|
-
// cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
|
|
1748
|
-
// with real promises, so each advance methods returns a new promise for the cursor object, or
|
|
1749
|
-
// undefined if the end of the cursor has been reached.
|
|
1750
|
-
if (getCursorAdvanceMethods().includes(func)) {
|
|
1751
|
-
return function (...args) {
|
|
1752
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
1753
|
-
// the original object.
|
|
1754
|
-
func.apply(unwrap(this), args);
|
|
1755
|
-
return wrap(this.request);
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
return function (...args) {
|
|
1759
|
-
// Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
|
|
1760
|
-
// the original object.
|
|
1761
|
-
return wrap(func.apply(unwrap(this), args));
|
|
1762
|
-
};
|
|
1763
|
-
}
|
|
1764
|
-
function transformCachableValue(value) {
|
|
1765
|
-
if (typeof value === 'function') return wrapFunction(value);
|
|
1766
|
-
// This doesn't return, it just creates a 'done' promise for the transaction,
|
|
1767
|
-
// which is later returned for transaction.done (see idbObjectHandler).
|
|
1768
|
-
if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
|
|
1769
|
-
if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
|
|
1770
|
-
// Return the same value back if we're not going to transform it.
|
|
1771
|
-
return value;
|
|
1772
|
-
}
|
|
1773
|
-
function wrap(value) {
|
|
1774
|
-
// We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
|
|
1775
|
-
// IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
|
|
1776
|
-
if (value instanceof IDBRequest) return promisifyRequest(value);
|
|
1777
|
-
// If we've already transformed this value before, reuse the transformed value.
|
|
1778
|
-
// This is faster, but it also provides object equality.
|
|
1779
|
-
if (transformCache.has(value)) return transformCache.get(value);
|
|
1780
|
-
const newValue = transformCachableValue(value);
|
|
1781
|
-
// Not all types are transformed.
|
|
1782
|
-
// These may be primitive types, so they can't be WeakMap keys.
|
|
1783
|
-
if (newValue !== value) {
|
|
1784
|
-
transformCache.set(value, newValue);
|
|
1785
|
-
reverseTransformCache.set(newValue, value);
|
|
1786
|
-
}
|
|
1787
|
-
return newValue;
|
|
1788
|
-
}
|
|
1789
|
-
const unwrap = value => reverseTransformCache.get(value);
|
|
1790
|
-
|
|
1791
|
-
/**
|
|
1792
|
-
* Open a database.
|
|
1793
|
-
*
|
|
1794
|
-
* @param name Name of the database.
|
|
1795
|
-
* @param version Schema version.
|
|
1796
|
-
* @param callbacks Additional callbacks.
|
|
1797
|
-
*/
|
|
1798
|
-
function openDB(name, version, {
|
|
1799
|
-
blocked,
|
|
1800
|
-
upgrade,
|
|
1801
|
-
blocking,
|
|
1802
|
-
terminated
|
|
1803
|
-
} = {}) {
|
|
1804
|
-
const request = indexedDB.open(name, version);
|
|
1805
|
-
const openPromise = wrap(request);
|
|
1806
|
-
if (upgrade) {
|
|
1807
|
-
request.addEventListener('upgradeneeded', event => {
|
|
1808
|
-
upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
|
|
1809
|
-
});
|
|
1810
|
-
}
|
|
1811
|
-
if (blocked) {
|
|
1812
|
-
request.addEventListener('blocked', event => blocked(
|
|
1813
|
-
// Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
|
|
1814
|
-
event.oldVersion, event.newVersion, event));
|
|
1815
|
-
}
|
|
1816
|
-
openPromise.then(db => {
|
|
1817
|
-
if (terminated) db.addEventListener('close', () => terminated());
|
|
1818
|
-
if (blocking) {
|
|
1819
|
-
db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
|
|
1820
|
-
}
|
|
1821
|
-
}).catch(() => {});
|
|
1822
|
-
return openPromise;
|
|
1823
|
-
}
|
|
1824
|
-
const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
|
|
1825
|
-
const writeMethods = ['put', 'add', 'delete', 'clear'];
|
|
1826
|
-
const cachedMethods = new Map();
|
|
1827
|
-
function getMethod(target, prop) {
|
|
1828
|
-
if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
|
|
1829
|
-
return;
|
|
1830
|
-
}
|
|
1831
|
-
if (cachedMethods.get(prop)) return cachedMethods.get(prop);
|
|
1832
|
-
const targetFuncName = prop.replace(/FromIndex$/, '');
|
|
1833
|
-
const useIndex = prop !== targetFuncName;
|
|
1834
|
-
const isWrite = writeMethods.includes(targetFuncName);
|
|
1835
|
-
if (
|
|
1836
|
-
// Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
|
|
1837
|
-
!(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
|
|
1838
|
-
return;
|
|
1839
|
-
}
|
|
1840
|
-
const method = async function (storeName, ...args) {
|
|
1841
|
-
// isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
|
|
1842
|
-
const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
|
|
1843
|
-
let target = tx.store;
|
|
1844
|
-
if (useIndex) target = target.index(args.shift());
|
|
1845
|
-
// Must reject if op rejects.
|
|
1846
|
-
// If it's a write operation, must reject if tx.done rejects.
|
|
1847
|
-
// Must reject with op rejection first.
|
|
1848
|
-
// Must resolve with op value.
|
|
1849
|
-
// Must handle both promises (no unhandled rejections)
|
|
1850
|
-
return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
|
|
1851
|
-
};
|
|
1852
|
-
cachedMethods.set(prop, method);
|
|
1853
|
-
return method;
|
|
1854
|
-
}
|
|
1855
|
-
replaceTraps(oldTraps => ({
|
|
1856
|
-
...oldTraps,
|
|
1857
|
-
get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
|
|
1858
|
-
has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
|
|
1859
|
-
}));
|
|
1860
|
-
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
|
|
1861
|
-
const methodMap = {};
|
|
1862
|
-
const advanceResults = new WeakMap();
|
|
1863
|
-
const ittrProxiedCursorToOriginalProxy = new WeakMap();
|
|
1864
|
-
const cursorIteratorTraps = {
|
|
1865
|
-
get(target, prop) {
|
|
1866
|
-
if (!advanceMethodProps.includes(prop)) return target[prop];
|
|
1867
|
-
let cachedFunc = methodMap[prop];
|
|
1868
|
-
if (!cachedFunc) {
|
|
1869
|
-
cachedFunc = methodMap[prop] = function (...args) {
|
|
1870
|
-
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
|
|
1871
|
-
};
|
|
1872
|
-
}
|
|
1873
|
-
return cachedFunc;
|
|
1874
|
-
}
|
|
1875
|
-
};
|
|
1876
|
-
async function* iterate(...args) {
|
|
1877
|
-
// tslint:disable-next-line:no-this-assignment
|
|
1878
|
-
let cursor = this;
|
|
1879
|
-
if (!(cursor instanceof IDBCursor)) {
|
|
1880
|
-
cursor = await cursor.openCursor(...args);
|
|
1881
|
-
}
|
|
1882
|
-
if (!cursor) return;
|
|
1883
|
-
cursor = cursor;
|
|
1884
|
-
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
|
|
1885
|
-
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
|
|
1886
|
-
// Map this double-proxy back to the original, so other cursor methods work.
|
|
1887
|
-
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
|
|
1888
|
-
while (cursor) {
|
|
1889
|
-
yield proxiedCursor;
|
|
1890
|
-
// If one of the advancing methods was not called, call continue().
|
|
1891
|
-
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
|
|
1892
|
-
advanceResults.delete(proxiedCursor);
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
function isIteratorProp(target, prop) {
|
|
1896
|
-
return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
|
|
1897
|
-
}
|
|
1898
|
-
replaceTraps(oldTraps => ({
|
|
1899
|
-
...oldTraps,
|
|
1900
|
-
get(target, prop, receiver) {
|
|
1901
|
-
if (isIteratorProp(target, prop)) return iterate;
|
|
1902
|
-
return oldTraps.get(target, prop, receiver);
|
|
1903
|
-
},
|
|
1904
|
-
has(target, prop) {
|
|
1905
|
-
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
|
|
1906
|
-
}
|
|
1907
|
-
}));
|
|
1908
|
-
|
|
1909
|
-
const openDatabaseDependencies = {
|
|
1910
|
-
openDB: openDB
|
|
1856
|
+
const listChatViewEvents$1 = async sessionId => {
|
|
1857
|
+
return invoke('ChatStorage.listChatViewEvents', sessionId);
|
|
1911
1858
|
};
|
|
1912
|
-
const
|
|
1913
|
-
return
|
|
1859
|
+
const loadSelectedEvent$1 = async (sessionId, eventId, type) => {
|
|
1860
|
+
return invoke('ChatStorage.loadSelectedEvent', sessionId, eventId, type);
|
|
1914
1861
|
};
|
|
1915
1862
|
|
|
1916
1863
|
const loadSelectedEventDependencies = {
|
|
1917
|
-
|
|
1918
|
-
openDatabase: openDatabase
|
|
1864
|
+
loadSelectedEventFromWorker: loadSelectedEvent$1
|
|
1919
1865
|
};
|
|
1920
|
-
const loadSelectedEvent = async (
|
|
1921
|
-
|
|
1922
|
-
try {
|
|
1923
|
-
if (!database.objectStoreNames.contains(eventStoreName)) {
|
|
1924
|
-
return null;
|
|
1925
|
-
}
|
|
1926
|
-
const transaction = database.transaction(eventStoreName, 'readonly');
|
|
1927
|
-
const store = transaction.objectStore(eventStoreName);
|
|
1928
|
-
const event = await loadSelectedEventDependencies.getEventDetailsBySessionIdAndEventId(store, sessionId, sessionIdIndexName, eventId, type);
|
|
1929
|
-
return event ?? null;
|
|
1930
|
-
} finally {
|
|
1931
|
-
database.close();
|
|
1932
|
-
}
|
|
1866
|
+
const loadSelectedEvent = async (_databaseName, _dataBaseVersion, _eventStoreName, sessionId, _sessionIdIndexName, eventId, type) => {
|
|
1867
|
+
return loadSelectedEventDependencies.loadSelectedEventFromWorker(sessionId, eventId, type);
|
|
1933
1868
|
};
|
|
1934
1869
|
|
|
1935
1870
|
const getCurrentEvents$2 = state => {
|
|
@@ -2372,12 +2307,24 @@ const handleShowResponsePartEvents = (state, checked) => {
|
|
|
2372
2307
|
return withPreservedSelection$1(state, nextState);
|
|
2373
2308
|
};
|
|
2374
2309
|
|
|
2375
|
-
const
|
|
2376
|
-
|
|
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;
|
|
2377
2321
|
};
|
|
2378
|
-
|
|
2379
|
-
const
|
|
2380
|
-
|
|
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.`;
|
|
2381
2328
|
};
|
|
2382
2329
|
|
|
2383
2330
|
const ParseChatDebugUriErrorCode = {
|
|
@@ -2398,134 +2345,12 @@ const getSessionNotFoundMessage = sessionId => {
|
|
|
2398
2345
|
return `No chat session found for sessionId "${sessionId}".`;
|
|
2399
2346
|
};
|
|
2400
2347
|
|
|
2401
|
-
const filterEventsBySessionId = (events, sessionId) => {
|
|
2402
|
-
return events.filter(event => event.sessionId === sessionId);
|
|
2403
|
-
};
|
|
2404
|
-
|
|
2405
|
-
// cspell:ignore IDBP
|
|
2406
|
-
|
|
2407
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2408
|
-
const getAllEvents = async store => {
|
|
2409
|
-
const all = await store.getAll();
|
|
2410
|
-
return all;
|
|
2411
|
-
};
|
|
2412
|
-
|
|
2413
|
-
const getEndTime = event => {
|
|
2414
|
-
return event.ended ?? event.endTime ?? event.timestamp;
|
|
2415
|
-
};
|
|
2416
|
-
|
|
2417
|
-
const getStartTime = event => {
|
|
2418
|
-
return event.started ?? event.startTime ?? event.timestamp;
|
|
2419
|
-
};
|
|
2420
|
-
|
|
2421
|
-
const getDuration = event => {
|
|
2422
|
-
const explicitDuration = event.durationMs ?? event.duration;
|
|
2423
|
-
if (typeof explicitDuration === 'number' && Number.isFinite(explicitDuration)) {
|
|
2424
|
-
return explicitDuration;
|
|
2425
|
-
}
|
|
2426
|
-
const start = toTimeNumber(getStartTime(event));
|
|
2427
|
-
const end = toTimeNumber(getEndTime(event));
|
|
2428
|
-
if (start === undefined || end === undefined || !Number.isFinite(start) || !Number.isFinite(end)) {
|
|
2429
|
-
return 0;
|
|
2430
|
-
}
|
|
2431
|
-
return Math.max(0, end - start);
|
|
2432
|
-
};
|
|
2433
|
-
|
|
2434
|
-
const isTimeValue = value => {
|
|
2435
|
-
return typeof value === 'number' || typeof value === 'string';
|
|
2436
|
-
};
|
|
2437
|
-
|
|
2438
|
-
const getLightweightEvent = (event, fallbackEventId) => {
|
|
2439
|
-
const startTime = getStartTime(event);
|
|
2440
|
-
const endTime = getEndTime(event);
|
|
2441
|
-
return {
|
|
2442
|
-
duration: getDuration(event),
|
|
2443
|
-
...(isTimeValue(endTime) ? {
|
|
2444
|
-
endTime
|
|
2445
|
-
} : {}),
|
|
2446
|
-
eventId: typeof event.eventId === 'number' ? event.eventId : fallbackEventId,
|
|
2447
|
-
...(isTimeValue(startTime) ? {
|
|
2448
|
-
startTime
|
|
2449
|
-
} : {}),
|
|
2450
|
-
type: event.type
|
|
2451
|
-
};
|
|
2452
|
-
};
|
|
2453
|
-
|
|
2454
|
-
// cspell:ignore IDBP
|
|
2455
|
-
|
|
2456
|
-
const toLightweightEvents = events => {
|
|
2457
|
-
const eventsWithIds = events.map((event, index) => {
|
|
2458
|
-
return {
|
|
2459
|
-
...event,
|
|
2460
|
-
eventId: index + 1
|
|
2461
|
-
};
|
|
2462
|
-
});
|
|
2463
|
-
return collapseToolExecutionEvents(eventsWithIds).map((event, index) => getLightweightEvent(event, index + 1));
|
|
2464
|
-
};
|
|
2465
|
-
const getEventsBySessionId = async (store, sessionId, sessionIdIndexName) => {
|
|
2466
|
-
if (store.indexNames.contains(sessionIdIndexName)) {
|
|
2467
|
-
const index = store.index(sessionIdIndexName);
|
|
2468
|
-
const events = await index.getAll(sessionId);
|
|
2469
|
-
return toLightweightEvents(filterEventsBySessionId(events, sessionId));
|
|
2470
|
-
}
|
|
2471
|
-
const all = await getAllEvents(store);
|
|
2472
|
-
return toLightweightEvents(filterEventsBySessionId(all, sessionId));
|
|
2473
|
-
};
|
|
2474
|
-
|
|
2475
|
-
let indexedDbSupportOverride;
|
|
2476
|
-
const getIndexedDbSupportOverride = () => {
|
|
2477
|
-
return indexedDbSupportOverride;
|
|
2478
|
-
};
|
|
2479
|
-
const setIndexedDbSupportOverride = supported => {
|
|
2480
|
-
indexedDbSupportOverride = supported;
|
|
2481
|
-
};
|
|
2482
|
-
|
|
2483
|
-
const isIndexedDbSupported = indexedDbSupportOverride => {
|
|
2484
|
-
if (typeof indexedDbSupportOverride === 'boolean') {
|
|
2485
|
-
return indexedDbSupportOverride;
|
|
2486
|
-
}
|
|
2487
|
-
const override = getIndexedDbSupportOverride();
|
|
2488
|
-
if (typeof override === 'boolean') {
|
|
2489
|
-
return override;
|
|
2490
|
-
}
|
|
2491
|
-
return globalThis.indexedDB !== undefined;
|
|
2492
|
-
};
|
|
2493
|
-
|
|
2494
2348
|
const listChatViewEventsDependencies = {
|
|
2495
|
-
|
|
2496
|
-
openDatabase: openDatabase
|
|
2349
|
+
listChatViewEventsFromWorker: listChatViewEvents$1
|
|
2497
2350
|
};
|
|
2498
|
-
const listChatViewEvents = async (sessionId,
|
|
2499
|
-
if (!isIndexedDbSupported(indexedDbSupportOverride)) {
|
|
2500
|
-
return {
|
|
2501
|
-
type: 'not-supported'
|
|
2502
|
-
};
|
|
2503
|
-
}
|
|
2351
|
+
const listChatViewEvents = async (sessionId, _databaseName, _dataBaseVersion, _eventStoreName, _sessionIdIndexName) => {
|
|
2504
2352
|
try {
|
|
2505
|
-
|
|
2506
|
-
try {
|
|
2507
|
-
if (!database.objectStoreNames.contains(eventStoreName)) {
|
|
2508
|
-
return {
|
|
2509
|
-
events: [],
|
|
2510
|
-
type: 'success'
|
|
2511
|
-
};
|
|
2512
|
-
}
|
|
2513
|
-
const transaction = database.transaction(eventStoreName, 'readonly');
|
|
2514
|
-
const store = transaction.objectStore(eventStoreName);
|
|
2515
|
-
if (!sessionId) {
|
|
2516
|
-
return {
|
|
2517
|
-
events: [],
|
|
2518
|
-
type: 'success'
|
|
2519
|
-
};
|
|
2520
|
-
}
|
|
2521
|
-
const events = await listChatViewEventsDependencies.getEventsBySessionId(store, sessionId, sessionIdIndexName);
|
|
2522
|
-
return {
|
|
2523
|
-
events,
|
|
2524
|
-
type: 'success'
|
|
2525
|
-
};
|
|
2526
|
-
} finally {
|
|
2527
|
-
database.close();
|
|
2528
|
-
}
|
|
2353
|
+
return await listChatViewEventsDependencies.listChatViewEventsFromWorker(sessionId);
|
|
2529
2354
|
} catch (error) {
|
|
2530
2355
|
return {
|
|
2531
2356
|
error,
|
|
@@ -2647,26 +2472,13 @@ const loadEventsForSessionId = async (state, sessionId) => {
|
|
|
2647
2472
|
databaseName,
|
|
2648
2473
|
dataBaseVersion,
|
|
2649
2474
|
eventStoreName,
|
|
2650
|
-
indexedDbSupportOverride,
|
|
2651
2475
|
sessionIdIndexName
|
|
2652
2476
|
} = state;
|
|
2653
|
-
const result = await loadEventsDependencies.listChatViewEvents(sessionId, databaseName, dataBaseVersion, eventStoreName, sessionIdIndexName
|
|
2654
|
-
if (result.type === 'not-supported') {
|
|
2655
|
-
return {
|
|
2656
|
-
...state,
|
|
2657
|
-
errorMessage: getIndexedDbNotSupportedMessage(),
|
|
2658
|
-
events: [],
|
|
2659
|
-
initial: false,
|
|
2660
|
-
selectedEvent: null,
|
|
2661
|
-
selectedEventId: null,
|
|
2662
|
-
selectedEventIndex: null,
|
|
2663
|
-
sessionId
|
|
2664
|
-
};
|
|
2665
|
-
}
|
|
2477
|
+
const result = await loadEventsDependencies.listChatViewEvents(sessionId, databaseName, dataBaseVersion, eventStoreName, sessionIdIndexName);
|
|
2666
2478
|
if (result.type === 'error') {
|
|
2667
2479
|
return {
|
|
2668
2480
|
...state,
|
|
2669
|
-
errorMessage: getFailedToLoadMessage(sessionId),
|
|
2481
|
+
errorMessage: getFailedToLoadMessage(sessionId, result.error),
|
|
2670
2482
|
events: [],
|
|
2671
2483
|
initial: false,
|
|
2672
2484
|
selectedEvent: null,
|
|
@@ -2722,30 +2534,6 @@ const refresh = async state => {
|
|
|
2722
2534
|
return refreshEvents(state);
|
|
2723
2535
|
};
|
|
2724
2536
|
|
|
2725
|
-
const Button = 1;
|
|
2726
|
-
const Div = 4;
|
|
2727
|
-
const Input = 6;
|
|
2728
|
-
const Span = 8;
|
|
2729
|
-
const Table = 9;
|
|
2730
|
-
const TBody = 10;
|
|
2731
|
-
const Td = 11;
|
|
2732
|
-
const Text = 12;
|
|
2733
|
-
const Th = 13;
|
|
2734
|
-
const THead = 14;
|
|
2735
|
-
const Tr = 15;
|
|
2736
|
-
const Search = 42;
|
|
2737
|
-
const Label = 66;
|
|
2738
|
-
const Reference = 100;
|
|
2739
|
-
|
|
2740
|
-
const ClientX = 'event.clientX';
|
|
2741
|
-
const ClientY = 'event.clientY';
|
|
2742
|
-
const TargetName = 'event.target.name';
|
|
2743
|
-
const TargetValue = 'event.target.value';
|
|
2744
|
-
|
|
2745
|
-
const SetCss = 'Viewlet.setCss';
|
|
2746
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
2747
|
-
const SetPatches = 'Viewlet.setPatches';
|
|
2748
|
-
|
|
2749
2537
|
const getCss = state => {
|
|
2750
2538
|
const tableWidth = clampTableWidth(state.width, state.tableWidth);
|
|
2751
2539
|
const detailsWidth = getDetailsWidth(state.width, state.tableWidth);
|
|
@@ -4128,6 +3916,9 @@ const hasErrorStatus = event => {
|
|
|
4128
3916
|
if (isErrorStatusCode(result.status)) {
|
|
4129
3917
|
return true;
|
|
4130
3918
|
}
|
|
3919
|
+
if (isToolEvent(event) && 'error' in result && result.error !== undefined) {
|
|
3920
|
+
return true;
|
|
3921
|
+
}
|
|
4131
3922
|
if (typeof result.error === 'string' || typeof result.errorMessage === 'string' || typeof result.exception === 'string') {
|
|
4132
3923
|
return true;
|
|
4133
3924
|
}
|
|
@@ -4848,31 +4639,15 @@ const setEvents = (state, events) => {
|
|
|
4848
4639
|
};
|
|
4849
4640
|
};
|
|
4850
4641
|
|
|
4851
|
-
const setIndexedDbSupportForTest = supported => {
|
|
4852
|
-
return setIndexedDbSupportOverride(supported);
|
|
4853
|
-
};
|
|
4854
|
-
|
|
4855
4642
|
const setSessionIdDependencies = {
|
|
4856
4643
|
listChatViewEvents: listChatViewEvents
|
|
4857
4644
|
};
|
|
4858
4645
|
const setSessionId = async (state, sessionId) => {
|
|
4859
|
-
const result = await setSessionIdDependencies.listChatViewEvents(sessionId, state.databaseName, state.dataBaseVersion, state.eventStoreName, state.sessionIdIndexName
|
|
4860
|
-
if (result.type === 'not-supported') {
|
|
4861
|
-
return {
|
|
4862
|
-
...state,
|
|
4863
|
-
errorMessage: getIndexedDbNotSupportedMessage(),
|
|
4864
|
-
events: [],
|
|
4865
|
-
initial: false,
|
|
4866
|
-
selectedEvent: null,
|
|
4867
|
-
selectedEventId: null,
|
|
4868
|
-
selectedEventIndex: null,
|
|
4869
|
-
sessionId
|
|
4870
|
-
};
|
|
4871
|
-
}
|
|
4646
|
+
const result = await setSessionIdDependencies.listChatViewEvents(sessionId, state.databaseName, state.dataBaseVersion, state.eventStoreName, state.sessionIdIndexName);
|
|
4872
4647
|
if (result.type === 'error') {
|
|
4873
4648
|
return {
|
|
4874
4649
|
...state,
|
|
4875
|
-
errorMessage: getFailedToLoadMessage(sessionId),
|
|
4650
|
+
errorMessage: getFailedToLoadMessage(sessionId, result.error),
|
|
4876
4651
|
events: [],
|
|
4877
4652
|
initial: false,
|
|
4878
4653
|
selectedEvent: null,
|
|
@@ -4931,16 +4706,28 @@ const commandMap = {
|
|
|
4931
4706
|
'ChatDebug.resize': wrapCommand(resize),
|
|
4932
4707
|
'ChatDebug.saveState': wrapGetter(saveState),
|
|
4933
4708
|
'ChatDebug.setEvents': wrapCommand(setEvents),
|
|
4934
|
-
'ChatDebug.setIndexedDbSupportForTest': setIndexedDbSupportForTest,
|
|
4935
4709
|
'ChatDebug.setSessionId': wrapCommand(setSessionId),
|
|
4936
4710
|
'ChatDebug.terminate': terminate
|
|
4937
4711
|
};
|
|
4938
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
|
+
|
|
4939
4724
|
const listen = async () => {
|
|
4940
4725
|
registerCommands(commandMap);
|
|
4941
|
-
await create$
|
|
4726
|
+
const r = await create$3({
|
|
4942
4727
|
commandMap: commandMap
|
|
4943
4728
|
});
|
|
4729
|
+
set$1(r);
|
|
4730
|
+
await initializeChatStorageWorker();
|
|
4944
4731
|
};
|
|
4945
4732
|
|
|
4946
4733
|
const main = async () => {
|