@claritylabs/cl-sdk 3.1.6 → 3.1.7

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.js CHANGED
@@ -11757,7 +11757,6 @@ Return JSON for the operational profile.`;
11757
11757
  var VISUAL_TABLE_REPAIR_MAX_TABLES = 4;
11758
11758
  var VISUAL_TABLE_REPAIR_MAX_ROWS = 28;
11759
11759
  var VISUAL_TABLE_REPAIR_MAX_CELLS = 140;
11760
- var VISUAL_TABLE_REPAIR_KEYWORDS = /\b(coverage|limit|limits?|deductible|retroactive|premium|tax|fee|sublimit|sub-limit|aggregate|claim|occurrence|retention|declarations?)\b/i;
11761
11760
  function isSourceTreeHeaderRow(row) {
11762
11761
  return row.metadata?.isHeader === true || row.metadata?.isHeader === "true";
11763
11762
  }
@@ -11803,13 +11802,11 @@ function primaryHeaderColumnCount(rows) {
11803
11802
  if (header) return header.cells.length;
11804
11803
  return Math.max(0, ...rows.map(({ cells }) => cells.length));
11805
11804
  }
11806
- function shouldRepairVisualTable(candidate) {
11805
+ function visualTableRepairScore(candidate) {
11807
11806
  const rows = candidate.rows;
11808
- if (rows.length < 3) return false;
11809
- const tableText = rows.map(({ row, cells }) => tableRowTextForPrompt(row, cells)).join(" ");
11810
- if (!VISUAL_TABLE_REPAIR_KEYWORDS.test(tableText)) return false;
11807
+ if (rows.length < 3) return 0;
11811
11808
  const headerCount = primaryHeaderColumnCount(rows);
11812
- if (headerCount < 2) return false;
11809
+ if (headerCount < 2) return 0;
11813
11810
  const firstHeaderIndex = rows.findIndex(({ row, cells }) => isSourceTreeHeaderRow(row) && cells.length > 1);
11814
11811
  const repeatedHeader = firstHeaderIndex >= 0 && rows.some(({ row }, index) => index > firstHeaderIndex && isSourceTreeHeaderRow(row));
11815
11812
  const shortContinuation = rows.some(
@@ -11821,7 +11818,7 @@ function shouldRepairVisualTable(candidate) {
11821
11818
  const danglingSlash = rows.some(
11822
11819
  ({ row, cells }) => !isSourceTreeHeaderRow(row) && /\/\s*$/.test(tableRowTextForPrompt(row, cells))
11823
11820
  );
11824
- return repeatedHeader || shortContinuation || genericDataLabels || danglingSlash;
11821
+ return (repeatedHeader ? 4 : 0) + (danglingSlash ? 3 : 0) + (shortContinuation ? 3 : 0) + (genericDataLabels ? 2 : 0);
11825
11822
  }
11826
11823
  function visualTableCandidates(sourceTree) {
11827
11824
  const byParent = nodesByParent(sourceTree);
@@ -11829,9 +11826,9 @@ function visualTableCandidates(sourceTree) {
11829
11826
  table,
11830
11827
  page: table.pageStart,
11831
11828
  rows: tableRowsWithCells(table, byParent)
11832
- })).filter(shouldRepairVisualTable).sort(
11833
- (left, right) => left.page - right.page || left.table.order - right.table.order || left.table.id.localeCompare(right.table.id)
11834
- ).slice(0, VISUAL_TABLE_REPAIR_MAX_TABLES);
11829
+ })).map((candidate) => ({ ...candidate, repairScore: visualTableRepairScore(candidate) })).filter((candidate) => candidate.repairScore > 0).sort(
11830
+ (left, right) => right.repairScore - left.repairScore || left.page - right.page || left.table.order - right.table.order || left.table.id.localeCompare(right.table.id)
11831
+ ).slice(0, VISUAL_TABLE_REPAIR_MAX_TABLES).map(({ repairScore: _repairScore, ...candidate }) => candidate);
11835
11832
  }
11836
11833
  function compactVisualTableCandidate(candidate) {
11837
11834
  let cellCount = 0;