@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.js CHANGED
@@ -11223,6 +11223,46 @@ function tableRowTextFromCells(cells) {
11223
11223
  }).filter(Boolean).join(" | ");
11224
11224
  return text ? cleanText(text, text) : void 0;
11225
11225
  }
11226
+ function normalizeTableBoundaryDelimiters(value) {
11227
+ const text = cleanText(value, "");
11228
+ if (!text) return void 0;
11229
+ const normalized = text.replace(/\s+\|\s+\|/g, " | ").replace(/\s+\/\s+\|/g, " |").replace(/\s+[|/]\s*$/g, "").replace(/\s{2,}/g, " ").trim();
11230
+ return normalized || void 0;
11231
+ }
11232
+ function normalizeSourceTreeTableDisplayText(sourceTree) {
11233
+ const byParent = nodesByParent(sourceTree);
11234
+ const updates = /* @__PURE__ */ new Map();
11235
+ const currentNode = (node) => updates.get(node.id) ?? node;
11236
+ for (const node of sourceTree) {
11237
+ if (node.kind !== "table_cell") continue;
11238
+ const textExcerpt = normalizeTableBoundaryDelimiters(node.textExcerpt);
11239
+ const textChanged = textExcerpt !== void 0 && textExcerpt !== node.textExcerpt;
11240
+ const description = textChanged && textExcerpt ? normalizeTableBoundaryDelimiters([node.title, textExcerpt].filter(Boolean).join(" | ")) : normalizeTableBoundaryDelimiters(node.description);
11241
+ if (textExcerpt === node.textExcerpt && description === node.description) continue;
11242
+ updates.set(node.id, {
11243
+ ...node,
11244
+ ...textExcerpt !== void 0 ? { textExcerpt } : {},
11245
+ ...description !== void 0 ? { description } : {}
11246
+ });
11247
+ }
11248
+ for (const node of sourceTree) {
11249
+ if (node.kind !== "table_row") continue;
11250
+ const cells = (byParent.get(node.id) ?? []).filter((child) => child.kind === "table_cell").map(currentNode).sort(
11251
+ (left, right) => tableCellColumnIndex(left, 0) - tableCellColumnIndex(right, 0) || left.order - right.order || left.id.localeCompare(right.id)
11252
+ );
11253
+ const textExcerpt = cells.length ? tableRowTextFromCells(cells) : normalizeTableBoundaryDelimiters(node.textExcerpt);
11254
+ const textChanged = textExcerpt !== void 0 && textExcerpt !== node.textExcerpt;
11255
+ const description = textChanged && textExcerpt ? normalizeTableBoundaryDelimiters([node.title, textExcerpt].filter(Boolean).join(" | ")) : normalizeTableBoundaryDelimiters(node.description);
11256
+ if (textExcerpt === node.textExcerpt && description === node.description) continue;
11257
+ updates.set(node.id, {
11258
+ ...node,
11259
+ ...textExcerpt !== void 0 ? { textExcerpt } : {},
11260
+ ...description !== void 0 ? { description } : {}
11261
+ });
11262
+ }
11263
+ if (updates.size === 0) return sourceTree;
11264
+ return sourceTree.map((node) => updates.get(node.id) ?? node);
11265
+ }
11226
11266
  function tableRowTextForPrompt(row, cells) {
11227
11267
  return cleanText(
11228
11268
  cells.length ? cells.map(tableCellText).filter(Boolean).join(" | ") : row.textExcerpt ?? row.description ?? row.title,
@@ -12021,7 +12061,7 @@ async function runSourceTreeExtraction(params) {
12021
12061
  trackUsage: localTrack,
12022
12062
  log: params.log
12023
12063
  });
12024
- sourceTree = visualTableRepair.sourceTree;
12064
+ sourceTree = normalizeSourceTreeTableDisplayText(visualTableRepair.sourceTree);
12025
12065
  warnings.push(...visualTableRepair.warnings);
12026
12066
  const emptyProfile = emptyOperationalProfile();
12027
12067
  let operationalProfile = emptyProfile;