@apteva/apteva-kit 0.1.77 → 0.1.79

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/index.mjs CHANGED
@@ -606,14 +606,6 @@ function findMatchingBracket(text, startIndex) {
606
606
  }
607
607
  return -1;
608
608
  }
609
- function findOpeningBracket(text) {
610
- const squareIndex = text.indexOf("[");
611
- const curlyIndex = text.indexOf("{");
612
- if (squareIndex === -1 && curlyIndex === -1) return null;
613
- if (squareIndex === -1) return { index: curlyIndex, char: "{" };
614
- if (curlyIndex === -1) return { index: squareIndex, char: "[" };
615
- return squareIndex < curlyIndex ? { index: squareIndex, char: "[" } : { index: curlyIndex, char: "{" };
616
- }
617
609
  function parseWidgetsFromText(text) {
618
610
  const segments = [];
619
611
  let hasWidgets = false;
@@ -627,14 +619,13 @@ function parseWidgetsFromText(text) {
627
619
  const typeMatch = afterStart.match(/^@ui:(\w+)/);
628
620
  if (typeMatch) {
629
621
  const widgetType = typeMatch[1];
630
- const afterType = afterStart.slice(typeMatch[0].length);
631
- const bracketInfo = findOpeningBracket(afterType);
632
- if (!bracketInfo) {
622
+ const bracketOpenIndex = afterStart.indexOf("[");
623
+ if (bracketOpenIndex === -1) {
633
624
  processText = text.slice(0, lastWidgetStart);
634
625
  pendingWidgetType = widgetType;
635
626
  hasPendingWidget = true;
636
627
  } else {
637
- const fullBracketStart = lastWidgetStart + typeMatch[0].length + bracketInfo.index;
628
+ const fullBracketStart = lastWidgetStart + bracketOpenIndex;
638
629
  const bracketEnd = findMatchingBracket(text, fullBracketStart);
639
630
  if (bracketEnd === -1) {
640
631
  if (STREAMABLE_WIDGET_TYPES.includes(widgetType)) {
@@ -676,22 +667,16 @@ function parseWidgetsFromText(text) {
676
667
  if (hasPendingWidget) {
677
668
  processText = processText.replace(/[\s:;\-–—\.]+$/g, "");
678
669
  }
679
- const startPattern = /@ui:(\w+)([\[{])/g;
670
+ const startPattern = /@ui:(\w+)\[/g;
680
671
  let match;
681
672
  while ((match = startPattern.exec(processText)) !== null) {
682
673
  const widgetType = match[1];
683
- const openingBracket = match[2];
684
674
  const bracketStart = match.index + match[0].length - 1;
685
675
  const bracketEnd = findMatchingBracket(processText, bracketStart);
686
676
  if (bracketEnd === -1) {
687
677
  continue;
688
678
  }
689
- let jsonContent;
690
- if (openingBracket === "[") {
691
- jsonContent = processText.slice(bracketStart + 1, bracketEnd);
692
- } else {
693
- jsonContent = processText.slice(bracketStart, bracketEnd + 1);
694
- }
679
+ const jsonContent = processText.slice(bracketStart + 1, bracketEnd);
695
680
  if (match.index > currentIndex) {
696
681
  const textContent = processText.slice(currentIndex, match.index).trim();
697
682
  if (textContent) {
@@ -782,7 +767,11 @@ function generateWidgetContext(enabledWidgets) {
782
767
  const widgets = enabledWidgets || ALL_WIDGET_TYPES;
783
768
  let context = `
784
769
  ## UI Widgets
785
- Render widgets: @ui:type[{props}]. "meta" field (at root level, NOT inside items) holds extended data captured by UI.
770
+ SYNTAX: @ui:type[{json}] - MUST use SQUARE BRACKETS [] around the JSON object.
771
+ CORRECT: @ui:list[{"items": [...]}]
772
+ WRONG: @ui:list{"items": [...]} (missing square brackets)
773
+
774
+ "meta" field (at root level, NOT inside items) holds extended data captured by UI.
786
775
 
787
776
  `;
788
777
  for (const type of widgets) {
@@ -792,14 +781,14 @@ Render widgets: @ui:type[{props}]. "meta" field (at root level, NOT inside items
792
781
  `;
793
782
  }
794
783
  context += `
795
- Meta: @ui:list[{"items": [{"id": "1", "title": "X"}], "meta": {"items": [{"id": "1", "title": "X", "extra": "..."}]}}]
784
+ Meta example: @ui:list[{"items": [{"id": "1", "title": "X"}], "meta": {"items": [{"id": "1", "title": "X", "extra": "..."}]}}]
796
785
  `;
797
786
  return context;
798
787
  }
799
788
  function generateCompactWidgetContext(enabledWidgets) {
800
789
  const widgets = enabledWidgets || ALL_WIDGET_TYPES;
801
790
  return `
802
- Widgets: @ui:type[{props}]. Types: ${widgets.join(", ")}. Add "meta" at root (not inside items) for extended data.
791
+ Widgets: @ui:type[{json}] - MUST use square brackets []. Example: @ui:list[{"items": [...]}]. Types: ${widgets.join(", ")}. Add "meta" at root for extended data.
803
792
  `;
804
793
  }
805
794