@lvce-editor/chat-debug-view 10.22.0 → 10.23.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.
@@ -1138,6 +1138,7 @@ const Img = 17;
1138
1138
  const Section = 41;
1139
1139
  const Search = 42;
1140
1140
  const Li = 48;
1141
+ const A = 53;
1141
1142
  const Ul = 60;
1142
1143
  const TextArea = 62;
1143
1144
  const Reference = 100;
@@ -1469,6 +1470,7 @@ const i18nString = (key, placeholders = emptyObject) => {
1469
1470
  const All = 'All';
1470
1471
  const CloseDetails = 'Close details';
1471
1472
  const Copy = 'Copy';
1473
+ const CopyAsFetch = 'Copy As Fetch';
1472
1474
  const CachedTokens = 'Cached Tokens';
1473
1475
  const DetailSections = 'Detail sections';
1474
1476
  const Duration$1 = 'Time';
@@ -1526,6 +1528,9 @@ const WindowSummary = 'Window {PH1}-{PH2} of {PH3}';
1526
1528
  const copy = () => {
1527
1529
  return i18nString(Copy);
1528
1530
  };
1531
+ const copyAsFetch = () => {
1532
+ return i18nString(CopyAsFetch);
1533
+ };
1529
1534
  const openInNewTab = () => {
1530
1535
  return i18nString(OpenInNewTab);
1531
1536
  };
@@ -3469,6 +3474,12 @@ const getMenuEntriesTableBody = props => {
3469
3474
  flags: None$1,
3470
3475
  id: 'copy',
3471
3476
  label: copy()
3477
+ }, {
3478
+ args: [props.eventIndex],
3479
+ command: 'ChatDebug.handleTableRowCopyAsFetch',
3480
+ flags: None$1,
3481
+ id: 'copy-as-fetch',
3482
+ label: copyAsFetch()
3472
3483
  }, {
3473
3484
  args: [props.eventIndex],
3474
3485
  command: 'ChatDebug.handleTableRowOpenInNewTab',
@@ -5013,6 +5024,88 @@ const handleTableRowCopy = async (state, eventIndex) => {
5013
5024
  return state;
5014
5025
  };
5015
5026
 
5027
+ const indent = (value, count) => {
5028
+ const prefix = ' '.repeat(count);
5029
+ return value.split('\n').map(line => `${prefix}${line}`).join('\n');
5030
+ };
5031
+
5032
+ const escapeSingleQuotedString = value => {
5033
+ return value.replaceAll('\\', '\\\\').replaceAll("'", "\\'");
5034
+ };
5035
+
5036
+ const toSingleQuotedString = value => {
5037
+ return `'${escapeSingleQuotedString(value)}'`;
5038
+ };
5039
+
5040
+ const getBodyLine = value => {
5041
+ if (typeof value === 'string') {
5042
+ return ` body: ${toSingleQuotedString(value)},`;
5043
+ }
5044
+ if (typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint') {
5045
+ return ` body: ${toSingleQuotedString(String(value))},`;
5046
+ }
5047
+ let serializedBody;
5048
+ try {
5049
+ serializedBody = JSON.stringify(value, null, 2);
5050
+ } catch {
5051
+ return ` body: ${toSingleQuotedString(String(value))},`;
5052
+ }
5053
+ if (!serializedBody) {
5054
+ return ` body: ${toSingleQuotedString(String(value))},`;
5055
+ }
5056
+ return ` body: JSON.stringify(\n${indent(serializedBody, 4)}\n ),`;
5057
+ };
5058
+
5059
+ const getHeaderLines = value => {
5060
+ if (!isRecord(value)) {
5061
+ return [];
5062
+ }
5063
+ const lines = [];
5064
+ for (const [key, headerValue] of Object.entries(value)) {
5065
+ if (typeof headerValue === 'string' || typeof headerValue === 'number' || typeof headerValue === 'boolean') {
5066
+ lines.push(` ${toSingleQuotedString(key)}: ${toSingleQuotedString(String(headerValue))},`);
5067
+ }
5068
+ }
5069
+ if (lines.length === 0) {
5070
+ return [];
5071
+ }
5072
+ return [' headers: {', ...lines, ' },'];
5073
+ };
5074
+
5075
+ const getFetchCode = event => {
5076
+ if (typeof event.url !== 'string') {
5077
+ return undefined;
5078
+ }
5079
+ const lines = [];
5080
+ if (typeof event.method === 'string' && event.method !== 'GET') {
5081
+ lines.push(` method: ${toSingleQuotedString(event.method)},`);
5082
+ }
5083
+ lines.push(...getHeaderLines(event.headers));
5084
+ if (event.body !== undefined) {
5085
+ lines.push(getBodyLine(event.body));
5086
+ }
5087
+ if (lines.length === 0) {
5088
+ return `fetch(${toSingleQuotedString(event.url)})`;
5089
+ }
5090
+ return `fetch(${toSingleQuotedString(event.url)}, {\n${lines.join('\n')}\n})`;
5091
+ };
5092
+
5093
+ const handleTableRowCopyAsFetch = async (state, eventIndex) => {
5094
+ const currentEvents = getCurrentEvents$1(state);
5095
+ const event = currentEvents[eventIndex];
5096
+ if (!event) {
5097
+ return state;
5098
+ }
5099
+ const fetchCode = getFetchCode(event);
5100
+ if (fetchCode) {
5101
+ await writeClipBoardText(fetchCode);
5102
+ return state;
5103
+ }
5104
+ const text = JSON.stringify(event, null, 2);
5105
+ await writeClipBoardText(text);
5106
+ return state;
5107
+ };
5108
+
5016
5109
  const toDataUri$1 = text => {
5017
5110
  return `data:application/json,${encodeURIComponent(text)}`;
5018
5111
  };
@@ -6454,6 +6547,87 @@ const getNormalizedDetailTabs = (selectedEvent, detailTabs) => {
6454
6547
  return createDetailTabs(getSelectedDetailTab(detailTabs), selectedEvent);
6455
6548
  };
6456
6549
 
6550
+ const getHeaderRowNodes = (item, index) => {
6551
+ return [{
6552
+ childCount: 2,
6553
+ className: mergeClassNames(ChatDebugViewHeadersRow, index % 2 === 0 ? ChatDebugViewHeadersRowOdd : ChatDebugViewHeadersRowEven),
6554
+ type: Li
6555
+ }, {
6556
+ childCount: 1,
6557
+ className: mergeClassNames(ChatDebugViewHeadersCell, ChatDebugViewHeadersCellName),
6558
+ type: Div
6559
+ }, text(item.key), {
6560
+ childCount: 1,
6561
+ className: mergeClassNames(ChatDebugViewHeadersCell, ChatDebugViewHeadersCellValue),
6562
+ type: Div
6563
+ }, text(item.value)];
6564
+ };
6565
+
6566
+ const getHeadersTableNodes = items => {
6567
+ const headerRows = [];
6568
+ for (const [index, item] of items.entries()) {
6569
+ headerRows.push(...getHeaderRowNodes(item, index));
6570
+ }
6571
+ return [{
6572
+ childCount: items.length,
6573
+ className: ChatDebugViewHeadersTable,
6574
+ type: Ul
6575
+ }, ...headerRows];
6576
+ };
6577
+
6578
+ const accessControlExposeHeadersText = 'Access-Control-Expose-Headers';
6579
+ const accessControlExposeHeadersUrl = 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers';
6580
+ const getInfoNodes = section => {
6581
+ if (section.key !== ResponseHeaders) {
6582
+ return [text(section.info)];
6583
+ }
6584
+ const linkIndex = section.info.indexOf(accessControlExposeHeadersText);
6585
+ if (linkIndex === -1) {
6586
+ return [text(section.info)];
6587
+ }
6588
+ const infoNodes = [];
6589
+ const prefix = section.info.slice(0, linkIndex);
6590
+ const suffix = section.info.slice(linkIndex + accessControlExposeHeadersText.length);
6591
+ if (prefix) {
6592
+ infoNodes.push(text(prefix));
6593
+ }
6594
+ infoNodes.push({
6595
+ childCount: 1,
6596
+ href: accessControlExposeHeadersUrl,
6597
+ rel: 'noopener noreferrer',
6598
+ target: '_blank',
6599
+ type: A
6600
+ });
6601
+ infoNodes.push(text(accessControlExposeHeadersText));
6602
+ if (suffix) {
6603
+ infoNodes.push(text(suffix));
6604
+ }
6605
+ return infoNodes;
6606
+ };
6607
+ const getHeaderSectionNodes = section => {
6608
+ const hasInfoMessage = section.isExpanded && section.info !== '';
6609
+ const childCount = section.isExpanded ? 2 + Number(hasInfoMessage) : 1;
6610
+ const infoNodes = hasInfoMessage ? getInfoNodes(section) : [];
6611
+ return [{
6612
+ childCount,
6613
+ className: ChatDebugViewHeadersSection,
6614
+ type: Div
6615
+ }, {
6616
+ ariaExpanded: section.isExpanded,
6617
+ childCount: 1,
6618
+ className: ChatDebugViewHeadersSectionHeading,
6619
+ name: ToggleHeadersSection,
6620
+ onChange: HandleFilterInput,
6621
+ onClick: HandleFilterInput,
6622
+ type: Button$1,
6623
+ value: section.key
6624
+ }, text(section.heading), ...(section.isExpanded ? getHeadersTableNodes(section.items) : []), ...(hasInfoMessage ? [{
6625
+ childCount: infoNodes.length,
6626
+ className: ChatDebugViewHeadersSectionInfo,
6627
+ type: Div
6628
+ }, ...infoNodes] : [])];
6629
+ };
6630
+
6457
6631
  const httpStatusLabels = {
6458
6632
  100: 'Continue',
6459
6633
  101: 'Switching Protocols',
@@ -6629,74 +6803,43 @@ const getHeaderValueText = value => {
6629
6803
  return stringifyHeaderValue(value);
6630
6804
  };
6631
6805
 
6632
- const getHeaderRowNodes = (headerName, headerValue, index) => {
6633
- return [{
6634
- childCount: 2,
6635
- className: mergeClassNames(ChatDebugViewHeadersRow, index % 2 === 0 ? ChatDebugViewHeadersRowOdd : ChatDebugViewHeadersRowEven),
6636
- type: Li
6637
- }, {
6638
- childCount: 1,
6639
- className: mergeClassNames(ChatDebugViewHeadersCell, ChatDebugViewHeadersCellName),
6640
- type: Div
6641
- }, text(headerName), {
6642
- childCount: 1,
6643
- className: mergeClassNames(ChatDebugViewHeadersCell, ChatDebugViewHeadersCellValue),
6644
- type: Div
6645
- }, text(getHeaderValueText(headerValue))];
6646
- };
6647
-
6648
- const getHeadersTableNodes = headers => {
6649
- const headerRows = [];
6650
- for (const [index, [headerName, headerValue]] of headers.entries()) {
6651
- headerRows.push(...getHeaderRowNodes(headerName, headerValue, index));
6652
- }
6653
- return [{
6654
- childCount: headers.length,
6655
- className: ChatDebugViewHeadersTable,
6656
- type: Ul
6657
- }, ...headerRows];
6806
+ const toHeaderSectionItems = entries => {
6807
+ return entries.map(([key, value]) => ({
6808
+ key,
6809
+ value: getHeaderValueText(value)
6810
+ }));
6658
6811
  };
6659
-
6660
- const getHeaderSectionNodes = (section, label, headers, collapsedHeaderSections, infoMessage = '') => {
6661
- const isCollapsed = collapsedHeaderSections.includes(section);
6662
- const hasInfoMessage = !isCollapsed && infoMessage !== '';
6663
- const childCount = isCollapsed ? 1 : 2 + Number(hasInfoMessage);
6664
- return [{
6665
- childCount,
6666
- className: ChatDebugViewHeadersSection,
6667
- type: Div
6812
+ const getVisibleHeaderSections = (selectedEvent, collapsedHeaderSections = []) => {
6813
+ const sections = [{
6814
+ heading: general(),
6815
+ info: '',
6816
+ items: toHeaderSectionItems(getGeneralEntries(selectedEvent)),
6817
+ key: General
6668
6818
  }, {
6669
- ariaExpanded: !isCollapsed,
6670
- childCount: 1,
6671
- className: ChatDebugViewHeadersSectionHeading,
6672
- name: ToggleHeadersSection,
6673
- onChange: HandleFilterInput,
6674
- onClick: HandleFilterInput,
6675
- type: Button$1,
6676
- value: section
6677
- }, text(label), ...(isCollapsed ? [] : getHeadersTableNodes(headers)), ...(hasInfoMessage ? [{
6678
- childCount: 1,
6679
- className: ChatDebugViewHeadersSectionInfo,
6680
- type: Div
6681
- }, text(infoMessage)] : [])];
6819
+ heading: responseHeaders(),
6820
+ info: responseHeadersInfo(),
6821
+ items: toHeaderSectionItems(getHeaders(isHeadersRecord(selectedEvent?.endValue) ? selectedEvent.endValue.headers : undefined)),
6822
+ key: ResponseHeaders
6823
+ }, {
6824
+ heading: requestHeaders(),
6825
+ info: '',
6826
+ items: toHeaderSectionItems(getHeaders(selectedEvent?.headers)),
6827
+ key: RequestHeaders
6828
+ }];
6829
+ return sections.filter(section => section.items.length > 0).map(section => ({
6830
+ ...section,
6831
+ isExpanded: !collapsedHeaderSections.includes(section.key)
6832
+ }));
6682
6833
  };
6683
6834
 
6684
6835
  const getHeadersContentNodes = (responseEventNodes, selectedEvent, collapsedHeaderSections = []) => {
6685
- const generalEntries = getGeneralEntries(selectedEvent);
6686
- const requestHeaders$1 = getHeaders(selectedEvent?.headers);
6687
- const responseHeaders$1 = getHeaders(isHeadersRecord(selectedEvent?.endValue) ? selectedEvent.endValue.headers : undefined);
6688
- if (generalEntries.length === 0 && requestHeaders$1.length === 0 && responseHeaders$1.length === 0) {
6836
+ const sections = getVisibleHeaderSections(selectedEvent, collapsedHeaderSections);
6837
+ if (sections.length === 0) {
6689
6838
  return responseEventNodes;
6690
6839
  }
6691
6840
  const nodes = [];
6692
- if (generalEntries.length > 0) {
6693
- nodes.push(...getHeaderSectionNodes(General, general(), generalEntries, collapsedHeaderSections));
6694
- }
6695
- if (responseHeaders$1.length > 0) {
6696
- nodes.push(...getHeaderSectionNodes(ResponseHeaders, responseHeaders(), responseHeaders$1, collapsedHeaderSections, responseHeadersInfo()));
6697
- }
6698
- if (requestHeaders$1.length > 0) {
6699
- nodes.push(...getHeaderSectionNodes(RequestHeaders, requestHeaders(), requestHeaders$1, collapsedHeaderSections));
6841
+ for (const section of sections) {
6842
+ nodes.push(...getHeaderSectionNodes(section));
6700
6843
  }
6701
6844
  return nodes;
6702
6845
  };
@@ -8879,6 +9022,7 @@ const commandMap = {
8879
9022
  'ChatDebug.handleTableResizerPointerMove': wrapCommand(handleTableResizerPointerMove),
8880
9023
  'ChatDebug.handleTableResizerPointerUp': wrapCommand(handleTableResizerPointerUp),
8881
9024
  'ChatDebug.handleTableRowCopy': wrapCommand(handleTableRowCopy),
9025
+ 'ChatDebug.handleTableRowCopyAsFetch': wrapCommand(handleTableRowCopyAsFetch),
8882
9026
  'ChatDebug.handleTableRowDoubleClick': wrapCommand(handleTableRowDoubleClick),
8883
9027
  'ChatDebug.handleTableRowOpenInNewTab': wrapCommand(handleTableRowOpenInNewTab),
8884
9028
  'ChatDebug.handleTableScrollBarPointerDown': wrapCommand(handleTableScrollBarPointerDown),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-debug-view",
3
- "version": "10.22.0",
3
+ "version": "10.23.0",
4
4
  "description": "Chat Debug View Worker",
5
5
  "repository": {
6
6
  "type": "git",