@claritylabs/cl-sdk 3.1.15 → 3.1.16

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
@@ -10855,6 +10855,46 @@ function tableRowTextFromCells(cells) {
10855
10855
  }).filter(Boolean).join(" | ");
10856
10856
  return text ? cleanText(text, text) : void 0;
10857
10857
  }
10858
+ function normalizeTableBoundaryDelimiters(value) {
10859
+ const text = cleanText(value, "");
10860
+ if (!text) return void 0;
10861
+ const normalized = text.replace(/\s+\|\s+\|/g, " | ").replace(/\s+\/\s+\|/g, " |").replace(/\s+[|/]\s*$/g, "").replace(/\s{2,}/g, " ").trim();
10862
+ return normalized || void 0;
10863
+ }
10864
+ function normalizeSourceTreeTableDisplayText(sourceTree) {
10865
+ const byParent = nodesByParent(sourceTree);
10866
+ const updates = /* @__PURE__ */ new Map();
10867
+ const currentNode = (node) => updates.get(node.id) ?? node;
10868
+ for (const node of sourceTree) {
10869
+ if (node.kind !== "table_cell") continue;
10870
+ const textExcerpt = normalizeTableBoundaryDelimiters(node.textExcerpt);
10871
+ const textChanged = textExcerpt !== void 0 && textExcerpt !== node.textExcerpt;
10872
+ const description = textChanged && textExcerpt ? normalizeTableBoundaryDelimiters([node.title, textExcerpt].filter(Boolean).join(" | ")) : normalizeTableBoundaryDelimiters(node.description);
10873
+ if (textExcerpt === node.textExcerpt && description === node.description) continue;
10874
+ updates.set(node.id, {
10875
+ ...node,
10876
+ ...textExcerpt !== void 0 ? { textExcerpt } : {},
10877
+ ...description !== void 0 ? { description } : {}
10878
+ });
10879
+ }
10880
+ for (const node of sourceTree) {
10881
+ if (node.kind !== "table_row") continue;
10882
+ const cells = (byParent.get(node.id) ?? []).filter((child) => child.kind === "table_cell").map(currentNode).sort(
10883
+ (left, right) => tableCellColumnIndex(left, 0) - tableCellColumnIndex(right, 0) || left.order - right.order || left.id.localeCompare(right.id)
10884
+ );
10885
+ const textExcerpt = cells.length ? tableRowTextFromCells(cells) : normalizeTableBoundaryDelimiters(node.textExcerpt);
10886
+ const textChanged = textExcerpt !== void 0 && textExcerpt !== node.textExcerpt;
10887
+ const description = textChanged && textExcerpt ? normalizeTableBoundaryDelimiters([node.title, textExcerpt].filter(Boolean).join(" | ")) : normalizeTableBoundaryDelimiters(node.description);
10888
+ if (textExcerpt === node.textExcerpt && description === node.description) continue;
10889
+ updates.set(node.id, {
10890
+ ...node,
10891
+ ...textExcerpt !== void 0 ? { textExcerpt } : {},
10892
+ ...description !== void 0 ? { description } : {}
10893
+ });
10894
+ }
10895
+ if (updates.size === 0) return sourceTree;
10896
+ return sourceTree.map((node) => updates.get(node.id) ?? node);
10897
+ }
10858
10898
  function tableRowTextForPrompt(row, cells) {
10859
10899
  return cleanText(
10860
10900
  cells.length ? cells.map(tableCellText).filter(Boolean).join(" | ") : row.textExcerpt ?? row.description ?? row.title,
@@ -11653,7 +11693,7 @@ async function runSourceTreeExtraction(params) {
11653
11693
  trackUsage: localTrack,
11654
11694
  log: params.log
11655
11695
  });
11656
- sourceTree = visualTableRepair.sourceTree;
11696
+ sourceTree = normalizeSourceTreeTableDisplayText(visualTableRepair.sourceTree);
11657
11697
  warnings.push(...visualTableRepair.warnings);
11658
11698
  const emptyProfile = emptyOperationalProfile();
11659
11699
  let operationalProfile = emptyProfile;