@lvce-editor/chat-debug-view 3.0.0 → 3.2.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 +74 -23
- package/package.json +2 -2
|
@@ -1074,12 +1074,20 @@ const requestToPromise = async createRequest => {
|
|
|
1074
1074
|
reject,
|
|
1075
1075
|
resolve
|
|
1076
1076
|
} = Promise.withResolvers();
|
|
1077
|
-
|
|
1077
|
+
const onSuccess = () => {
|
|
1078
|
+
cleanup();
|
|
1078
1079
|
resolve(request.result);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1080
|
+
};
|
|
1081
|
+
const onError = () => {
|
|
1082
|
+
cleanup();
|
|
1081
1083
|
reject(request.error || new Error('IndexedDB request failed'));
|
|
1082
|
-
}
|
|
1084
|
+
};
|
|
1085
|
+
const cleanup = () => {
|
|
1086
|
+
request.removeEventListener('success', onSuccess);
|
|
1087
|
+
request.removeEventListener('error', onError);
|
|
1088
|
+
};
|
|
1089
|
+
request.addEventListener('success', onSuccess);
|
|
1090
|
+
request.addEventListener('error', onError);
|
|
1083
1091
|
return promise;
|
|
1084
1092
|
};
|
|
1085
1093
|
|
|
@@ -1126,29 +1134,46 @@ const listChatViewEvents = async (sessionId, databaseName, dataBaseVersion, even
|
|
|
1126
1134
|
};
|
|
1127
1135
|
|
|
1128
1136
|
const chatDebugUriPattern = /^chat-debug:\/\/([^/?#]+)$/;
|
|
1137
|
+
const invalidSessionIdPattern = /[/?#]/;
|
|
1138
|
+
const ParseChatDebugUriErrorCode = {
|
|
1139
|
+
InvalidSessionId: 'invalid-session-id',
|
|
1140
|
+
InvalidUriEncoding: 'invalid-uri-encoding',
|
|
1141
|
+
InvalidUriFormat: 'invalid-uri-format',
|
|
1142
|
+
MissingUri: 'missing-uri'
|
|
1143
|
+
};
|
|
1144
|
+
const createErrorResult = (code, message) => {
|
|
1145
|
+
return {
|
|
1146
|
+
code,
|
|
1147
|
+
message,
|
|
1148
|
+
type: 'error'
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1129
1151
|
const parseChatDebugUri = uri => {
|
|
1130
1152
|
if (!uri) {
|
|
1131
|
-
|
|
1153
|
+
return createErrorResult(ParseChatDebugUriErrorCode.MissingUri, 'Missing URI');
|
|
1132
1154
|
}
|
|
1133
1155
|
const match = uri.match(chatDebugUriPattern);
|
|
1134
1156
|
if (!match) {
|
|
1135
|
-
|
|
1157
|
+
return createErrorResult(ParseChatDebugUriErrorCode.InvalidUriFormat, 'Invalid URI format');
|
|
1136
1158
|
}
|
|
1137
1159
|
const encodedSessionId = match[1];
|
|
1138
1160
|
let sessionId;
|
|
1139
1161
|
try {
|
|
1140
1162
|
sessionId = decodeURIComponent(encodedSessionId);
|
|
1141
1163
|
} catch {
|
|
1142
|
-
|
|
1164
|
+
return createErrorResult(ParseChatDebugUriErrorCode.InvalidUriEncoding, 'Invalid URI encoding');
|
|
1143
1165
|
}
|
|
1144
|
-
if (!sessionId ||
|
|
1145
|
-
|
|
1166
|
+
if (!sessionId || invalidSessionIdPattern.test(sessionId)) {
|
|
1167
|
+
return createErrorResult(ParseChatDebugUriErrorCode.InvalidSessionId, 'Invalid session id');
|
|
1146
1168
|
}
|
|
1147
|
-
return
|
|
1169
|
+
return {
|
|
1170
|
+
sessionId,
|
|
1171
|
+
type: 'success'
|
|
1172
|
+
};
|
|
1148
1173
|
};
|
|
1149
1174
|
|
|
1150
|
-
const getInvalidUriMessage = uri => {
|
|
1151
|
-
if (
|
|
1175
|
+
const getInvalidUriMessage = (uri, code) => {
|
|
1176
|
+
if (code === ParseChatDebugUriErrorCode.MissingUri) {
|
|
1152
1177
|
return 'Unable to load debug session: missing URI. Expected format: chat-debug://<sessionId>.';
|
|
1153
1178
|
}
|
|
1154
1179
|
return `Unable to load debug session: invalid URI "${uri}". Expected format: chat-debug://<sessionId>.`;
|
|
@@ -1167,18 +1192,19 @@ const loadContent = async state => {
|
|
|
1167
1192
|
sessionIdIndexName,
|
|
1168
1193
|
uri
|
|
1169
1194
|
} = state;
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
sessionId = parseChatDebugUri(uri);
|
|
1173
|
-
} catch {
|
|
1195
|
+
const parsed = parseChatDebugUri(uri);
|
|
1196
|
+
if (parsed.type === 'error') {
|
|
1174
1197
|
return {
|
|
1175
1198
|
...state,
|
|
1176
|
-
errorMessage: getInvalidUriMessage(uri),
|
|
1199
|
+
errorMessage: getInvalidUriMessage(uri, parsed.code),
|
|
1177
1200
|
events: [],
|
|
1178
1201
|
initial: false,
|
|
1179
|
-
sessionId
|
|
1202
|
+
sessionId: ''
|
|
1180
1203
|
};
|
|
1181
1204
|
}
|
|
1205
|
+
const {
|
|
1206
|
+
sessionId
|
|
1207
|
+
} = parsed;
|
|
1182
1208
|
try {
|
|
1183
1209
|
const events = await listChatViewEvents(sessionId, databaseName, dataBaseVersion, eventStoreName, sessionIdIndexName);
|
|
1184
1210
|
if (events.length === 0) {
|
|
@@ -1253,6 +1279,12 @@ const getCss = () => {
|
|
|
1253
1279
|
white-space: nowrap;
|
|
1254
1280
|
}
|
|
1255
1281
|
|
|
1282
|
+
.ChatDebugViewToggleLabel {
|
|
1283
|
+
display: inline-flex;
|
|
1284
|
+
align-items: center;
|
|
1285
|
+
gap: 4px;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1256
1288
|
.ChatDebugViewSession {
|
|
1257
1289
|
font-size: 12px;
|
|
1258
1290
|
opacity: 0.8;
|
|
@@ -1363,6 +1395,7 @@ const Input = 6;
|
|
|
1363
1395
|
const Span = 8;
|
|
1364
1396
|
const Text = 12;
|
|
1365
1397
|
const Pre = 51;
|
|
1398
|
+
const Label = 66;
|
|
1366
1399
|
|
|
1367
1400
|
const text = data => {
|
|
1368
1401
|
return {
|
|
@@ -1376,6 +1409,7 @@ const HandleInput = 4;
|
|
|
1376
1409
|
const HandleFilterInput = 5;
|
|
1377
1410
|
|
|
1378
1411
|
const numberRegex = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
1412
|
+
const whitespaceRegex = /\s/u;
|
|
1379
1413
|
const getTokenSegments = json => {
|
|
1380
1414
|
const segments = [];
|
|
1381
1415
|
const pushToken = (className, value) => {
|
|
@@ -1416,7 +1450,7 @@ const getTokenSegments = json => {
|
|
|
1416
1450
|
}
|
|
1417
1451
|
const tokenValue = json.slice(start, i);
|
|
1418
1452
|
let lookAheadIndex = i;
|
|
1419
|
-
while (lookAheadIndex < json.length &&
|
|
1453
|
+
while (lookAheadIndex < json.length && whitespaceRegex.test(json[lookAheadIndex])) {
|
|
1420
1454
|
lookAheadIndex++;
|
|
1421
1455
|
}
|
|
1422
1456
|
const className = json[lookAheadIndex] === ':' ? 'TokenKey' : 'TokenString';
|
|
@@ -1489,7 +1523,11 @@ const getChatDebugViewDom = (sessionId, errorMessage, filterValue, showEventStre
|
|
|
1489
1523
|
}, text(errorMessage)];
|
|
1490
1524
|
}
|
|
1491
1525
|
const eventNodes = events.flatMap(getEventNode);
|
|
1492
|
-
const
|
|
1526
|
+
const trimmedFilterValue = filterValue.trim();
|
|
1527
|
+
const hasFilterValue = trimmedFilterValue.length > 0;
|
|
1528
|
+
const noFilteredEventsMessage = `no events found matching ${trimmedFilterValue}`;
|
|
1529
|
+
const eventCountText = events.length === 0 && hasFilterValue ? noFilteredEventsMessage : `${events.length} event${events.length === 1 ? '' : 's'}`;
|
|
1530
|
+
const emptyMessage = events.length === 0 && hasFilterValue ? noFilteredEventsMessage : 'No events';
|
|
1493
1531
|
return [{
|
|
1494
1532
|
childCount: 4,
|
|
1495
1533
|
className: 'ChatDebugView',
|
|
@@ -1501,15 +1539,20 @@ const getChatDebugViewDom = (sessionId, errorMessage, filterValue, showEventStre
|
|
|
1501
1539
|
}, {
|
|
1502
1540
|
childCount: 0,
|
|
1503
1541
|
className: 'InputBox',
|
|
1542
|
+
inputType: 'search',
|
|
1504
1543
|
name: Filter,
|
|
1505
1544
|
onInput: HandleFilterInput,
|
|
1506
1545
|
placeholder: 'Filter events',
|
|
1507
1546
|
type: Input,
|
|
1508
1547
|
value: filterValue
|
|
1509
1548
|
}, {
|
|
1510
|
-
childCount:
|
|
1549
|
+
childCount: 3,
|
|
1511
1550
|
className: 'ChatDebugViewToggle',
|
|
1512
1551
|
type: Div
|
|
1552
|
+
}, {
|
|
1553
|
+
childCount: 2,
|
|
1554
|
+
className: 'ChatDebugViewToggleLabel',
|
|
1555
|
+
type: Label
|
|
1513
1556
|
}, {
|
|
1514
1557
|
checked: showEventStreamFinishedEvents,
|
|
1515
1558
|
childCount: 0,
|
|
@@ -1518,6 +1561,10 @@ const getChatDebugViewDom = (sessionId, errorMessage, filterValue, showEventStre
|
|
|
1518
1561
|
onChange: HandleInput,
|
|
1519
1562
|
type: Input
|
|
1520
1563
|
}, text('Show event stream finished events'), {
|
|
1564
|
+
childCount: 2,
|
|
1565
|
+
className: 'ChatDebugViewToggleLabel',
|
|
1566
|
+
type: Label
|
|
1567
|
+
}, {
|
|
1521
1568
|
checked: showInputEvents,
|
|
1522
1569
|
childCount: 0,
|
|
1523
1570
|
inputType: 'checkbox',
|
|
@@ -1525,6 +1572,10 @@ const getChatDebugViewDom = (sessionId, errorMessage, filterValue, showEventStre
|
|
|
1525
1572
|
onChange: HandleInput,
|
|
1526
1573
|
type: Input
|
|
1527
1574
|
}, text('Show input events'), {
|
|
1575
|
+
childCount: 2,
|
|
1576
|
+
className: 'ChatDebugViewToggleLabel',
|
|
1577
|
+
type: Label
|
|
1578
|
+
}, {
|
|
1528
1579
|
checked: showResponsePartEvents,
|
|
1529
1580
|
childCount: 0,
|
|
1530
1581
|
inputType: 'checkbox',
|
|
@@ -1547,12 +1598,12 @@ const getChatDebugViewDom = (sessionId, errorMessage, filterValue, showEventStre
|
|
|
1547
1598
|
childCount: 1,
|
|
1548
1599
|
className: errorMessage ? 'ChatDebugViewError' : 'ChatDebugViewEmpty',
|
|
1549
1600
|
type: Div
|
|
1550
|
-
}, text(errorMessage ||
|
|
1601
|
+
}, text(errorMessage || emptyMessage)] : eventNodes)];
|
|
1551
1602
|
};
|
|
1552
1603
|
|
|
1553
1604
|
const getVisibleEvents = (events, showInputEvents, showResponsePartEvents, showEventStreamFinishedEvents) => {
|
|
1554
1605
|
return events.filter(event => {
|
|
1555
|
-
if (!showInputEvents && event.type === 'handle-input') {
|
|
1606
|
+
if (!showInputEvents && (event.type === 'handle-input' || event.type === 'handle-submit')) {
|
|
1556
1607
|
return false;
|
|
1557
1608
|
}
|
|
1558
1609
|
if (!showResponsePartEvents && event.type === 'sse-response-part') {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/chat-debug-view",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Chat Debug View Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/lvce-editor/chat-view.git"
|
|
7
|
+
"url": "git+https://github.com/lvce-editor/chat-debug-view.git"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "Lvce Editor",
|